/
hybrispressureadaptor.cpp
83 lines (75 loc) · 2.5 KB
/
hybrispressureadaptor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/****************************************************************************
**
** 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 "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 = SensorFrameworkConfig::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 (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris HybrisPressureAdaptor start\n";
return true;
}
void HybrisPressureAdaptor::stopSensor()
{
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris HybrisPressureAdaptor stop\n";
}
void HybrisPressureAdaptor::processSample(const sensors_event_t& data)
{
TimedUnsigned *d = buffer->nextSlot();
d->timestamp_ = quint64(data.timestamp * .001);
#ifdef USE_BINDER
d->value_ = data.u.scalar * 100;//From hPa to Pa
#else
d->value_ = data.pressure * 100;//From hPa to Pa
#endif
buffer->commit();
buffer->wakeUpReaders();
}
void HybrisPressureAdaptor::init()
{
}