Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sensorfw] Add hybrispressureadaptor. Contributes to MER#1649.
- Loading branch information
Showing
7 changed files
with
240 additions
and
0 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,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() | ||
{ | ||
} |
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,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 |
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,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
37
adaptors/hybrispressureadaptor/hybrispressureadaptorplugin.cpp
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,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
39
adaptors/hybrispressureadaptor/hybrispressureadaptorplugin.h
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,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 |
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