Skip to content

Commit

Permalink
[sensorfw] Add hybrispressureadaptor. Contributes to MER#1649.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlehtima committed Aug 6, 2017
1 parent 35aa0f7 commit 98460c6
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 0 deletions.
2 changes: 2 additions & 0 deletions adaptors/adaptors.pro
Expand Up @@ -7,6 +7,7 @@ contains(CONFIG,hybris) {
SUBDIRS += hybrisalsadaptor
SUBDIRS += hybrisgyroscopeadaptor
SUBDIRS += hybrismagnetometeradaptor
SUBDIRS += hybrispressureadaptor
SUBDIRS += hybrisproximityadaptor
SUBDIRS += hybrisorientationadaptor
SUBDIRS += hybrisstepcounteradaptor
Expand Down Expand Up @@ -51,6 +52,7 @@ config_hybris {
SUBDIRS += hybrisalsadaptor
SUBDIRS += hybrisgyroscopeadaptor
SUBDIRS += hybrismagnetometeradaptor
SUBDIRS += hybrispressureadaptor
SUBDIRS += hybrisproximityadaptor
SUBDIRS += hybrisorientationadaptor
SUBDIRS += hybrisstepcounteradaptor
Expand Down
81 changes: 81 additions & 0 deletions adaptors/hybrispressureadaptor/hybrispressureadaptor.cpp
@@ -0,0 +1,81 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.com
**
** Copyright (C) 2017 Matti Lehtimäki
** Contact: matti.lehtimaki@gmail.com
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QFile>
#include <QTextStream>

#include "hybrispressureadaptor.h"
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"

HybrisPressureAdaptor::HybrisPressureAdaptor(const QString& id) :
HybrisAdaptor(id,SENSOR_TYPE_PRESSURE)
{
buffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1);
setAdaptedSensor("pressure", "Internal ambient pressure sensor values", buffer);
setDescription("Hybris pressure");
powerStatePath = Config::configuration()->value("pressure/powerstate_path").toByteArray();
if (!powerStatePath.isEmpty() && !QFile::exists(powerStatePath))
{
sensordLogW() << "Path does not exists: " << powerStatePath;
powerStatePath.clear();
}
}

HybrisPressureAdaptor::~HybrisPressureAdaptor()
{
delete buffer;
}

bool HybrisPressureAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

sensordLogD() << "Hybris HybrisPressureAdaptor start\n";
return true;
}

void HybrisPressureAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris HybrisPressureAdaptor stop\n";
}

void HybrisPressureAdaptor::processSample(const sensors_event_t& data)
{
TimedUnsigned *d = buffer->nextSlot();
d->timestamp_ = quint64(data.timestamp * .001);
d->value_ = data.pressure * 100;//From hPa to Pa
buffer->commit();
buffer->wakeUpReaders();
}

void HybrisPressureAdaptor::init()
{
}
67 changes: 67 additions & 0 deletions adaptors/hybrispressureadaptor/hybrispressureadaptor.h
@@ -0,0 +1,67 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.com
**
** Copyright (C) 2017 Matti Lehtimäki
** Contact: matti.lehtimaki@gmail.com
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef HYBRISPRESSUREADAPTOR_H
#define HYBRISPRESSUREADAPTOR_H
#include "hybrisadaptor.h"

#include <QString>
#include <QStringList>
#include <linux/input.h>
#include "datatypes/timedunsigned.h"
#include "deviceadaptorringbuffer.h"
#include <QTime>

/**
* @brief Adaptor for hybris pressure sensor.
*
* Adaptor for internal pressure sensor. Provides the amount of ambient
* pressure detected by the device. Uses hybris sensor daemon driver interface.
*
* Value output frequency depends on driver decision - only changed values
* are pushed out of driver.
*
*/
class HybrisPressureAdaptor : public HybrisAdaptor
{
Q_OBJECT

public:
static DeviceAdaptor* factoryMethod(const QString& id) {
return new HybrisPressureAdaptor(id);
}
HybrisPressureAdaptor(const QString& id);
~HybrisPressureAdaptor();

bool startSensor();
void stopSensor();

protected:
void processSample(const sensors_event_t& data);
void init();

private:
DeviceAdaptorRingBuffer<TimedUnsigned>* buffer;
QByteArray powerStatePath;

};
#endif
13 changes: 13 additions & 0 deletions adaptors/hybrispressureadaptor/hybrispressureadaptor.pro
@@ -0,0 +1,13 @@
TARGET = hybrispressureadaptor

HEADERS += hybrispressureadaptor.h \
hybrispressureadaptorplugin.h

SOURCES += hybrispressureadaptor.cpp \
hybrispressureadaptorplugin.cpp
LIBS+= -L../../core -lhybrissensorfw-qt5

include(../adaptor-config.pri )
config_hybris {
INCLUDEPATH+=/usr/include/android
}
37 changes: 37 additions & 0 deletions adaptors/hybrispressureadaptor/hybrispressureadaptorplugin.cpp
@@ -0,0 +1,37 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.com
**
** Copyright (C) 2017 Matti Lehtimäki
** Contact: matti.lehtimaki@gmail.com
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "hybrispressureadaptorplugin.h"
#include "hybrispressureadaptor.h"
#include "sensormanager.h"
#include "logging.h"

void HybrisPressureAdaptorPlugin::Register(class Loader&)
{
sensordLogD() << "registering hybrispressureadaptor";
SensorManager& sm = SensorManager::instance();
sm.registerDeviceAdaptor<HybrisPressureAdaptor>("pressureadaptor");
}

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Q_EXPORT_PLUGIN2(hybrispressureadaptor, HybrisPressureAdaptorPlugin)
#endif
39 changes: 39 additions & 0 deletions adaptors/hybrispressureadaptor/hybrispressureadaptorplugin.h
@@ -0,0 +1,39 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.com
**
** Copyright (C) 2017 Matti Lehtimäki
** Contact: matti.lehtimaki@gmail.com
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef HYBRISPRESSUREADAPTORPLUGIN_H
#define HYBRISPRESSUREADAPTORPLUGIN_H

#include "plugin.h"

class HybrisPressureAdaptorPlugin : 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
1 change: 1 addition & 0 deletions config/sensord-hybris.conf
Expand Up @@ -6,6 +6,7 @@ magnetometeradaptor = hybrismagnetometeradaptor
gyroscopeadaptor = hybrisgyroscopeadaptor
orientationadaptor = hybrisorientationadaptor
stepcounteradaptor = hybrisstepcounteradaptor
pressureadaptor = hybrispressureadaptor

[magnetometer]
scale_coefficient = 1
Expand Down

0 comments on commit 98460c6

Please sign in to comment.