2 * Copyright (C) 2010-2012 Intel Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef ANDROID_SENSOR_IIO_DEV_H
18 #define ANDROID_SENSOR_IIO_DEV_H
34 #include "SensorBase.h"
37 // Used by SensorIIO device containers
38 struct SensorIIOChannel{
52 * Input device based sensors must inherit this class.
53 * The readEvents loop is already defined by this base class,
54 * inheritors need to define only processEvent for doing sensor-specific
57 class SensorIIODev: public SensorBase{
62 std::stringstream dev_device_name;
63 std::stringstream scan_el_dir;
64 std::stringstream buffer_dir_name;
65 std::vector < SensorIIOChannel > info_array;
71 std::string unit_expo_str;
73 std::string device_name;
74 std::string channel_prefix_str;
78 unsigned char *raw_buffer;
81 int EnableIIODevice();
82 int GetDir(const std::string& dir, std::vector < std::string >& files);
83 void ListFiles(const std::string& dir);
84 int FindDeviceNumberFromName(const std::string& name, const std::string& prefix);
86 int BuildChannelList();
87 int SetUpTrigger(int dev_num);
88 int SetUpBufferLen(int len);
89 int GetSizeFromChannels();
90 int ParseIIODirectory(const std::string& name);
92 int AllocateRxBuffer();
96 bool IsDeviceInitialized();
97 int GetDeviceNumber();
98 int SetDataReadyTrigger(int dev_num, bool status);
99 int EnableBuffer(int status);
100 int SetSampleDelay(int dev_num, int rate);
101 int DeviceActivate(int dev_num, int state);
102 int DeviceSetSensitivity(int dev_num, int value);
104 long GetExponentValue();
105 int ReadHIDMeasurmentUnit(long *unit);
106 int ReadHIDExponentValue(long *exponent);
107 int GetChannelBytesUsedSize(unsigned int channel_no);
108 virtual int processEvent(unsigned char *raw_data, size_t raw_data_len)
110 virtual int readEvents(sensors_event_t *data, int count);
111 virtual int enable(int enabled);
112 virtual int setDelay(int64_t delay_ns);
113 virtual int setInitialState();
116 SensorIIODev(const std::string& dev_name, const std::string& units, const std::string& exponent, const std::string& channel_prefix);
117 SensorIIODev(const std::string& dev_name, const std::string& units, const std::string& exponent, const std::string& channel_prefix, int retry_cnt);