Skip to content

Commit

Permalink
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
lpotter committed Nov 20, 2016
2 parents 075ce4b + aef102e commit 6620b4d
Show file tree
Hide file tree
Showing 80 changed files with 5,102 additions and 10 deletions.
8 changes: 7 additions & 1 deletion adaptors/adaptors.pro
Expand Up @@ -30,14 +30,20 @@ SUBDIRS = alsadaptor \
mrstaccelerometer \
gyroscopeadaptor \
gyroscopeadaptor-evdev

SUDBIRS += oemtabletmagnetometeradaptor
SUBDIRS += pegatronaccelerometeradaptor
SUBDIRS += pegatronaccelerometeradaptor
SUBDIRS += oemtabletalsadaptor-ascii
SUBDIRS += oaktrailaccelerometer
SUBDIRS += oemtabletaccelerometer
SUDBIRS += oemtabletgyroscopeadaptor
SUBDIRS += steaccelerometeradaptor
SUBDIRS += mpu6050accelerometer
SUBDIRS += lidsensoradaptor-evdev
SUBDIRS += iioadaptor
SUBDIRS += humidityadaptor
SUBDIRS += pressureadaptor
SUBDIRS += temperatureadaptor

config_hybris {
SUBDIRS += hybrisaccelerometer
Expand Down
142 changes: 142 additions & 0 deletions adaptors/humidityadaptor/humidityadaptor.cpp
@@ -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;
}
79 changes: 79 additions & 0 deletions adaptors/humidityadaptor/humidityadaptor.h
@@ -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
9 changes: 9 additions & 0 deletions adaptors/humidityadaptor/humidityadaptor.pro
@@ -0,0 +1,9 @@
TARGET = humidityadaptor

HEADERS += humidityadaptor.h \
humidityadaptorplugin.h

SOURCES += humidityadaptor.cpp \
humidityadaptorplugin.cpp

include( ../adaptor-config.pri )
40 changes: 40 additions & 0 deletions adaptors/humidityadaptor/humidityadaptorplugin.cpp
@@ -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
42 changes: 42 additions & 0 deletions adaptors/humidityadaptor/humidityadaptorplugin.h
@@ -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
9 changes: 9 additions & 0 deletions adaptors/iioadaptor/README.md
@@ -0,0 +1,9 @@
sensorfw-iioadaptor
===================

Industrial I/O plugin for SensorFW

WIP.
* working accelerometer
- data is wrong

0 comments on commit 6620b4d

Please sign in to comment.