sensorfw: adaptors/iioadaptor/iioadaptor.h Source File

sensorfw

iioadaptor.h
Go to the documentation of this file.
1
27 #ifndef IIOADAPTOR_H
28 #define IIOADAPTOR_H
29
30 #include <sysfsadaptor.h>
31 #include <datatypes/orientationdata.h>
32
33 // FIXME: shouldn't assume any number of channels per device
34 #define IIO_MAX_DEVICE_CHANNELS 20
35
36 // FIXME: no idea what would be reasonable length
37 #define IIO_BUFFER_LEN 256
38
49 class IioAdaptor : public SysfsAdaptor
50 {
51 Q_OBJECT
52 enum IioSensorType {
53 IIO_ACCELEROMETER = 1, // accel_3d
54 IIO_GYROSCOPE, // gyro_3d
55 IIO_MAGNETOMETER, // magn_3d
56 IIO_ROTATION, // dev_rotation, quaternion
57 IIO_ALS, // als
58 IIO_TILT, // incli_3d
59 IIO_PROXIMITY // proximity als
60 };
61
62 struct iio_device {
63 QString name;
64 int channels;
65 int channel_bytes[IIO_MAX_DEVICE_CHANNELS];
66 qreal scale;
67 qreal offset;
68 int frequency;
69 QString devicePath;
70 int index;
71 IioSensorType sensorType;
72 QString channelTypeName;
73 };
74
75 public:
82 static DeviceAdaptor *factoryMethod(const QString& id)
83 {
84 return new IioAdaptor(id);
85 }
86
87 virtual bool startSensor();
88 virtual void stopSensor();
89 // virtual bool standby();
90 // virtual bool resume();
91
92 protected:
93
99 IioAdaptor(const QString &id);
100
104 ~IioAdaptor();
105
106
107 bool setInterval(const unsigned int value, const int sessionId);
108 // unsigned int interval() const;
109
110 private:
111
120 void processSample(int pathId, int fd);
121
122 int findSensor(const QString &name);
123 bool deviceEnable(int device, int enable);
124
125 bool sysfsWriteInt(QString filename, int val);
126 QString sysfsReadString(QString filename);
127 int sysfsReadInt(QString filename);
128 int scanElementsEnable(int device, int enable);
129 int deviceChannelParseBytes(QString filename);
130
131 // Device number for the sensor (-1 if not found)
132 int devNodeNumber;
133
134 int proximityThreshold;
135
136 DeviceAdaptorRingBuffer<TimedXyzData>* iioXyzBuffer_;
137 DeviceAdaptorRingBuffer<TimedUnsigned>* alsBuffer_;
138 DeviceAdaptorRingBuffer<CalibratedMagneticFieldData>* magnetometerBuffer_;
139 DeviceAdaptorRingBuffer<ProximityData>* proximityBuffer_;
140
141 iio_device iioDevice;
142
143 QString deviceId;
144
145 TimedXyzData* timedData;
146 CalibratedMagneticFieldData *calData;
147 TimedUnsigned *uData;
148 ProximityData *proximityData;
149
150 private slots:
151 void setup();
152 };
153
154 #endif
CalibratedMagneticFieldData
Datatype for calibrated magnetometer measurements.
Definition: orientationdata.h:59
IioAdaptor
Adaptor for Industrial I/O.
Definition: iioadaptor.h:50
IioAdaptor::stopSensor
virtual void stopSensor()
IioAdaptor::~IioAdaptor
~IioAdaptor()
Destructor.
IioAdaptor::factoryMethod
static DeviceAdaptor * factoryMethod(const QString &id)
Factory method for gaining a new instance of this adaptor class.
Definition: iioadaptor.h:82
IioAdaptor::setInterval
bool setInterval(const unsigned int value, const int sessionId)
IioAdaptor::IioAdaptor
IioAdaptor(const QString &id)
Constructor.
IioAdaptor::startSensor
virtual bool startSensor()
ProximityData
Datatype for proximity measurements.
Definition: orientationdata.h:151
TimedUnsigned
Datatype for unsigned integer value with timestamp.
Definition: timedunsigned.h:34
TimedXyzData
Class for vector type measurement data (timestamp, x, y, z).
Definition: genericdata.h:53
IIO_MAX_DEVICE_CHANNELS
#define IIO_MAX_DEVICE_CHANNELS
Definition: iioadaptor.h:34
orientationdata.h
Datatypes for different filters.