Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'newsensors' into 'master'
Newsensors This adds new sensors and adaptors: - lidsensor - humidity - temperature - pressure and iio interface adaptor with the following sensors: - accelerometer - magnetometer - gyroscope - light See merge request !7
- Loading branch information
Showing
80 changed files
with
5,102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
@file alsevdevadaptor.cpp | ||
@brief Plugin for HumidityAdaptor | ||
<p> | ||
Copyright (C) 2016 Canonical LTD. | ||
@author Lorn Potter <lorn.potter@canonical.com> | ||
This file is part of Sensorfw. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#include "humidityadaptor.h" | ||
#include "config.h" | ||
#include "logging.h" | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <linux/input.h> | ||
#include <unistd.h> | ||
#include <QMap> | ||
|
||
#include "datatypes/utils.h" | ||
|
||
HumidityAdaptor::HumidityAdaptor(const QString& id) : | ||
InputDevAdaptor(id, 1) | ||
{ | ||
humidityBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(1); | ||
setAdaptedSensor("humidity", "Relative Humidity values", humidityBuffer_); | ||
setDescription("Input device humidity adaptor"); | ||
powerStatePath_ = Config::configuration()->value("humidity/powerstate_path").toByteArray(); | ||
introduceAvailableDataRange(DataRange(0, 4095, 1)); | ||
setDefaultInterval(10); | ||
} | ||
|
||
HumidityAdaptor::~HumidityAdaptor() | ||
{ | ||
} | ||
|
||
void HumidityAdaptor::interpretEvent(int src, struct input_event *ev) | ||
{ | ||
Q_UNUSED(src); | ||
|
||
switch (ev->type) { | ||
case EV_ABS: | ||
switch (ev->code) { | ||
case ABS_X: | ||
case ABS_MISC: | ||
humidityValue_ = ev->value; | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
void HumidityAdaptor::interpretSync(int src, struct input_event *ev) | ||
{ | ||
Q_UNUSED(src); | ||
commitOutput(ev); | ||
} | ||
|
||
void HumidityAdaptor::commitOutput(struct input_event *ev) | ||
{ | ||
TimedUnsigned* rh = humidityBuffer_->nextSlot(); | ||
rh->value_ = humidityValue_; | ||
|
||
rh->timestamp_ = Utils::getTimeStamp(&(ev->time)); | ||
|
||
humidityBuffer_->commit(); | ||
humidityBuffer_->wakeUpReaders(); | ||
} | ||
|
||
unsigned int HumidityAdaptor::evaluateIntervalRequests(int& sessionId) const | ||
{ | ||
unsigned int highestValue = 0; | ||
int winningSessionId = -1; | ||
|
||
if (m_intervalMap.size() == 0) { | ||
sessionId = winningSessionId; | ||
return defaultInterval(); | ||
} | ||
|
||
// Get the smallest positive request, 0 is reserved for HW wakeup | ||
QMap<int, unsigned int>::const_iterator it; | ||
it = m_intervalMap.begin(); | ||
highestValue = it.value(); | ||
winningSessionId = it.key(); | ||
|
||
for (++it; it != m_intervalMap.constEnd(); ++it) { | ||
if ((it.value() < highestValue) && (it.value() > 0)) { | ||
highestValue = it.value(); | ||
winningSessionId = it.key(); | ||
} | ||
} | ||
|
||
sessionId = winningSessionId; | ||
return highestValue > 0 ? highestValue : defaultInterval(); | ||
} | ||
|
||
bool HumidityAdaptor::startSensor() | ||
{ | ||
if (!powerStatePath_.isEmpty()) { | ||
writeToFile(powerStatePath_, "1"); | ||
} | ||
if (SysfsAdaptor::startSensor()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void HumidityAdaptor::stopSensor() | ||
{ | ||
if (!powerStatePath_.isEmpty()) { | ||
writeToFile(powerStatePath_, "0"); | ||
} | ||
|
||
SysfsAdaptor::stopSensor(); | ||
} | ||
|
||
bool HumidityAdaptor::standby() | ||
{ | ||
stopSensor(); | ||
return true; | ||
} | ||
|
||
bool HumidityAdaptor::resume() | ||
{ | ||
startSensor(); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
@file humidityadaptor.h | ||
@brief Contains HumidityAdaptorPlugin. | ||
<p> | ||
Copyright (C) 2016 Canonical LTD. | ||
@author Lorn Potter <lorn.potter@canonical.com> | ||
This file is part of Sensorfw. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
#ifndef HUMIDITYEVDEVADAPTOR_H | ||
#define HUMIDITYEVDEVADAPTOR_H | ||
|
||
#include "inputdevadaptor.h" | ||
#include "deviceadaptorringbuffer.h" | ||
#include "datatypes/orientationdata.h" | ||
#include <QTime> | ||
|
||
class HumidityAdaptor : public InputDevAdaptor | ||
{ | ||
Q_OBJECT | ||
public: | ||
/** | ||
* Factory method for gaining a new instance of AccelerometerAdaptor class. | ||
* @param id Identifier for the adaptor. | ||
*/ | ||
static DeviceAdaptor* factoryMethod(const QString& id) | ||
{ | ||
return new HumidityAdaptor(id); | ||
} | ||
|
||
virtual bool startSensor(); | ||
|
||
virtual void stopSensor(); | ||
|
||
virtual bool standby(); | ||
|
||
virtual bool resume(); | ||
|
||
protected: | ||
/** | ||
* Constructor. | ||
* @param id Identifier for the adaptor. | ||
*/ | ||
HumidityAdaptor(const QString& id); | ||
~HumidityAdaptor(); | ||
|
||
/** | ||
* Reimplement to allow for 0 interval to be the slowest entry. | ||
*/ | ||
virtual unsigned int evaluateIntervalRequests(int& sessionId) const; | ||
|
||
private: | ||
DeviceAdaptorRingBuffer<TimedUnsigned>* humidityBuffer_; | ||
|
||
unsigned humidityValue_; | ||
|
||
void interpretEvent(int src, struct input_event *ev); | ||
void commitOutput(struct input_event *ev); | ||
void interpretSync(int src, struct input_event *ev); | ||
QByteArray powerStatePath_; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
TARGET = humidityadaptor | ||
|
||
HEADERS += humidityadaptor.h \ | ||
humidityadaptorplugin.h | ||
|
||
SOURCES += humidityadaptor.cpp \ | ||
humidityadaptorplugin.cpp | ||
|
||
include( ../adaptor-config.pri ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
@file humidityadaptor.cpp | ||
@brief Plugin for HumidityAdaptorPlugin | ||
<p> | ||
Copyright (C) 2016 Canonical LTD. | ||
@author Lorn Potter <lorn.potter@canonical.com> | ||
This file is part of Sensorfw. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#include "humidityadaptorplugin.h" | ||
#include "humidityadaptor.h" | ||
#include "sensormanager.h" | ||
#include "logging.h" | ||
|
||
void HumidityAdaptorPlugin::Register(class Loader&) | ||
{ | ||
sensordLogD() << "registering humidityadaptor"; | ||
SensorManager& sm = SensorManager::instance(); | ||
sm.registerDeviceAdaptor<HumidityAdaptor>("humidityadaptor"); | ||
} | ||
|
||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) | ||
Q_EXPORT_PLUGIN2(humidityadaptor, HumidityAdaptorPlugin) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
@file alsadaptor-evdevplugin.h | ||
@brief Plugin for HumidityAdaptorPlugin | ||
<p> | ||
Copyright (C) 2016 Canonical LTD. | ||
@author Lorn Potter <lorn.potter@canonical.com> | ||
This file is part of Sensorfw. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#ifndef HUMIDITYADAPTOR_PLUGIN_H | ||
#define HUMIDITYADAPTOR_PLUGIN_H | ||
|
||
#include "plugin.h" | ||
|
||
class HumidityAdaptorPlugin : public Plugin | ||
{ | ||
Q_OBJECT | ||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) | ||
Q_PLUGIN_METADATA(IID "com.nokia.SensorService.Plugin/1.0") | ||
#endif | ||
|
||
private: | ||
void Register(class Loader& l); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sensorfw-iioadaptor | ||
=================== | ||
|
||
Industrial I/O plugin for SensorFW | ||
|
||
WIP. | ||
* working accelerometer | ||
- data is wrong | ||
|
Oops, something went wrong.