Commit 67e7bb7d authored by Matti Lehtimäki's avatar Matti Lehtimäki

Merge branch 'dmard06' into 'master'

[iioadaptor] Detect correct offset, scale and number of used channels

See merge request !40
parents ff2d99c7 7e54e813
......@@ -45,6 +45,7 @@
#include <QTimer>
#include <QDirIterator>
#include <qmath.h>
#include <QRegularExpression>
#include <deviceadaptor.h>
#include "datatypes/orientationdata.h"
......@@ -84,6 +85,7 @@ void IioAdaptor::setup()
const QString inputMatch = SensorFrameworkConfig::configuration()->value<QString>(name + "/input_match");
qDebug() << "input_match" << inputMatch;
iioDevice.channelTypeName = "accel";
devNodeNumber = findSensor(inputMatch);
if (devNodeNumber!= -1) {
const QString desc = "Industrial I/O accelerometer (" + iioDevice.name +")";
......@@ -99,6 +101,7 @@ void IioAdaptor::setup()
const QString inputMatch = SensorFrameworkConfig::configuration()->value<QString>(name + "/input_match");
qDebug() << "input_match" << inputMatch;
iioDevice.channelTypeName = "anglvel";
devNodeNumber = findSensor(inputMatch);
if (devNodeNumber!= -1) {
const QString desc = "Industrial I/O gyroscope (" + iioDevice.name +")";
......@@ -113,8 +116,8 @@ void IioAdaptor::setup()
const QString inputMatch = SensorFrameworkConfig::configuration()->value<QString>(name + "/input_match");
qDebug() << "input_match" << inputMatch;
iioDevice.channelTypeName = "magn";
devNodeNumber = findSensor(inputMatch);
if (devNodeNumber!= -1) {
const QString desc = "Industrial I/O magnetometer (" + iioDevice.name +")";
magnetometerBuffer_ = new DeviceAdaptorRingBuffer<CalibratedMagneticFieldData>(1);
......@@ -127,6 +130,7 @@ void IioAdaptor::setup()
const QString name = "als";
const QString inputMatch = SensorFrameworkConfig::configuration()->value<QString>(name + "/input_match");
iioDevice.channelTypeName = "illuminance";
devNodeNumber = findSensor(inputMatch);
if (devNodeNumber!= -1) {
QString desc = "Industrial I/O light sensor (" + iioDevice.name +")";
......@@ -142,8 +146,11 @@ void IioAdaptor::setup()
// setValid(false);
return;
}
iioDevice.channels = scanElementsEnable(devNodeNumber,1);
scanElementsEnable(devNodeNumber,0);
if (mode() != SysfsAdaptor::IntervalMode) {
scanElementsEnable(devNodeNumber,1);
scanElementsEnable(devNodeNumber,0);
}
/* Override the scaling factor if asked */
bool ok;
......@@ -203,13 +210,13 @@ int IioAdaptor::findSensor(const QString &sensorName)
qDebug() << "attr" << name << value;
QString attributeName(name);
if (attributeName.endsWith("scale")) {
if (attributeName.contains(QRegularExpression(iioDevice.channelTypeName + ".*scale$"))) {
iioDevice.scale = QString(value).toDouble(&ok);
if (ok) {
// scale = num;
qDebug() << "scale is" << iioDevice.scale;
}
} else if (attributeName.endsWith("offset")) {
} else if (attributeName.contains(QRegularExpression(iioDevice.channelTypeName + ".*offset$"))) {
iioDevice.offset = QString(value).toDouble(&ok);
if (ok)
qDebug() << "offset is" << value;
......@@ -218,13 +225,14 @@ int IioAdaptor::findSensor(const QString &sensorName)
if (ok)
// frequency = num;
qDebug() << "frequency is" << iioDevice.frequency;
} else if (attributeName.endsWith("raw")) {
} else if (attributeName.contains(QRegularExpression(iioDevice.channelTypeName + ".*raw$"))) {
qDebug() << "adding to paths:" << iioDevice.devicePath
<< attributeName << iioDevice.index;
addPath(iioDevice.devicePath + attributeName, j);
j++;
}
}
iioDevice.channels = j;
// in_rot_from_north_magnetic_tilt_comp_raw ?
......@@ -271,7 +279,7 @@ bool IioAdaptor::deviceEnable(int device, int enable)
if (enable == 1) {
// FIXME: should enable sensors for this device? Assuming enabled already
iioDevice.channels = scanElementsEnable(device, enable);
scanElementsEnable(device, enable);
sysfsWriteInt(pathLength, IIO_BUFFER_LEN);
sysfsWriteInt(pathEnable, enable);
} else {
......@@ -347,7 +355,7 @@ int IioAdaptor::scanElementsEnable(int device, int enable)
// Find all the *_en file and write 0/1 to it
QStringList filters;
filters << "*_en";
filters << ("*" + iioDevice.channelTypeName + "*_en");
dir.setNameFilters(filters);
QFileInfoList list = dir.entryInfoList();
......@@ -516,7 +524,8 @@ bool IioAdaptor::startSensor()
return false;
qDebug() << Q_FUNC_INFO;
deviceEnable(devNodeNumber, true);
if (mode() != SysfsAdaptor::IntervalMode)
deviceEnable(devNodeNumber, true);
return SysfsAdaptor::startSensor();
}
......@@ -525,6 +534,7 @@ void IioAdaptor::stopSensor()
if (devNodeNumber == -1)
return;
qDebug() << Q_FUNC_INFO;
deviceEnable(devNodeNumber, false);
if (mode() != SysfsAdaptor::IntervalMode)
deviceEnable(devNodeNumber, false);
SysfsAdaptor::stopSensor();
}
......@@ -68,6 +68,7 @@ class IioAdaptor : public SysfsAdaptor
QString devicePath;
int index;
IioSensorType sensorType;
QString channelTypeName;
};
public:
......
TARGET = iioaccelerometeradaptor
#TARGET = iiosensorsadaptor
TARGET = iiosensorsadaptor
HEADERS += iioadaptor.h \
iioadaptorplugin.h
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment