Skip to content

Commit 5d30d48

Browse files
authored
Merge pull request #29 from spiiroin/jb62083_wakeup_sensor
[sensorfw] Add wakeup sensor with hybrisadaptor
2 parents 8055468 + 9fce91f commit 5d30d48

26 files changed

+1050
-104
lines changed

adaptors/adaptors.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ HYBRIS_SUBDIRS = hybrisaccelerometer \
77
hybrisgyroscopeadaptor \
88
hybrismagnetometeradaptor \
99
hybrispressureadaptor \
10+
hybriswakeupadaptor \
1011
hybrisproximityadaptor \
1112
hybrisorientationadaptor \
1213
hybrisrotationadaptor \
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (c) 2025 Jollyboys Ltd.
4+
**
5+
** $QT_BEGIN_LICENSE:LGPL$
6+
**
7+
** GNU Lesser General Public License Usage
8+
** Alternatively, this file may be used under the terms of the GNU Lesser
9+
** General Public License version 2.1 as published by the Free Software
10+
** Foundation and appearing in the file LICENSE.LGPL included in the
11+
** packaging of this file. Please review the following information to
12+
** ensure the GNU Lesser General Public License version 2.1 requirements
13+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
14+
**
15+
** $QT_END_LICENSE$
16+
**
17+
****************************************************************************/
18+
19+
#include <QFile>
20+
#include <QTextStream>
21+
22+
#include "hybriswakeupadaptor.h"
23+
#include "logging.h"
24+
#include "datatypes/utils.h"
25+
#include "config.h"
26+
27+
namespace {
28+
int wakeupSensorType()
29+
{
30+
QVariant setting(SensorFrameworkConfig::configuration()->value("wakeup/sensor_type"));
31+
bool ok = false;
32+
int sensorType = setting.toInt(&ok);
33+
if (!ok)
34+
sensorType = SENSOR_TYPE_WAKE_GESTURE;
35+
qCInfo(lcSensorFw) << "wakeupSensorType:" << sensorType;
36+
return sensorType;
37+
}
38+
}
39+
40+
HybrisWakeupAdaptor::HybrisWakeupAdaptor(const QString &id)
41+
: HybrisAdaptor(id, wakeupSensorType())
42+
{
43+
m_buffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1);
44+
setAdaptedSensor("wakeup", "Wakeup sensor events", m_buffer);
45+
setDescription("Hybris wakeup");
46+
m_powerStatePath = SensorFrameworkConfig::configuration()->value("wakeup/powerstate_path").toByteArray();
47+
if (!m_powerStatePath.isEmpty() && !QFile::exists(m_powerStatePath)) {
48+
qCWarning(lcSensorFw) << NodeBase::id() << "Path does not exists: " << m_powerStatePath;
49+
m_powerStatePath.clear();
50+
}
51+
}
52+
53+
HybrisWakeupAdaptor::~HybrisWakeupAdaptor()
54+
{
55+
delete m_buffer;
56+
}
57+
58+
bool HybrisWakeupAdaptor::startSensor()
59+
{
60+
if (!(HybrisAdaptor::startSensor()))
61+
return false;
62+
if (isRunning() && !m_powerStatePath.isEmpty())
63+
writeToFile(m_powerStatePath, "1");
64+
qCInfo(lcSensorFw) << id() << "HybrisWakeupAdaptor start";
65+
return true;
66+
}
67+
68+
void HybrisWakeupAdaptor::stopSensor()
69+
{
70+
HybrisAdaptor::stopSensor();
71+
if (!isRunning() && !m_powerStatePath.isEmpty())
72+
writeToFile(m_powerStatePath, "0");
73+
qCInfo(lcSensorFw) << id() << "HybrisWakeupAdaptor stop";
74+
}
75+
76+
void HybrisWakeupAdaptor::processSample(const sensors_event_t &data)
77+
{
78+
TimedUnsigned *d = m_buffer->nextSlot();
79+
d->timestamp_ = quint64(data.timestamp * 0.001);
80+
81+
#ifdef USE_BINDER
82+
d->value_ = unsigned(data.u.scalar);
83+
#else
84+
d->value_ = unsigned(data.data[0]);
85+
#endif
86+
87+
qCInfo(lcSensorFw) << id() << "HybrisWakeupAdaptor event" << d->timestamp_ << d->value_;
88+
89+
m_buffer->commit();
90+
m_buffer->wakeUpReaders();
91+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (c) 2025 Jollyboys Ltd.
4+
**
5+
** $QT_BEGIN_LICENSE:LGPL$
6+
**
7+
** GNU Lesser General Public License Usage
8+
** Alternatively, this file may be used under the terms of the GNU Lesser
9+
** General Public License version 2.1 as published by the Free Software
10+
** Foundation and appearing in the file LICENSE.LGPL included in the
11+
** packaging of this file. Please review the following information to
12+
** ensure the GNU Lesser General Public License version 2.1 requirements
13+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
14+
**
15+
** $QT_END_LICENSE$
16+
**
17+
****************************************************************************/
18+
19+
#ifndef HYBRISWAKEUPADAPTOR_H
20+
#define HYBRISWAKEUPADAPTOR_H
21+
#include "hybrisadaptor.h"
22+
23+
#include <QString>
24+
#include <QStringList>
25+
#include <QTime>
26+
#include <linux/input.h>
27+
#include "datatypes/timedunsigned.h"
28+
#include "deviceadaptorringbuffer.h"
29+
30+
/** Adaptor for hybris wakeup sensor.
31+
*
32+
* Adaptor for wakeup sensor. Provides wakeup events that can be used
33+
* for example for triggering SneakPeek mode. Sensor value of one means
34+
* wakeup condition was met. Other values should be ignored. Uses hybris
35+
* sensor daemon driver interface.
36+
*/
37+
class HybrisWakeupAdaptor : public HybrisAdaptor
38+
{
39+
Q_OBJECT
40+
41+
public:
42+
static DeviceAdaptor *factoryMethod(const QString &id) {
43+
return new HybrisWakeupAdaptor(id);
44+
}
45+
HybrisWakeupAdaptor(const QString &id);
46+
~HybrisWakeupAdaptor();
47+
48+
bool startSensor();
49+
void stopSensor();
50+
51+
protected:
52+
void processSample(const sensors_event_t &data);
53+
54+
private:
55+
DeviceAdaptorRingBuffer<TimedUnsigned> *m_buffer;
56+
QByteArray m_powerStatePath;
57+
};
58+
#endif // HYBRISWAKEUPADAPTOR_H
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
TARGET = hybriswakeupadaptor
2+
3+
HEADERS += hybriswakeupadaptor.h \
4+
hybriswakeupadaptorplugin.h
5+
6+
SOURCES += hybriswakeupadaptor.cpp \
7+
hybriswakeupadaptorplugin.cpp
8+
LIBS += -L../../core -lhybrissensorfw-qt$${QT_MAJOR_VERSION}
9+
10+
include( ../adaptor-config.pri )
11+
config_hybris {
12+
PKGCONFIG += android-headers
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (c) 2025 Jollyboys Ltd.
4+
**
5+
** $QT_BEGIN_LICENSE:LGPL$
6+
**
7+
** GNU Lesser General Public License Usage
8+
** Alternatively, this file may be used under the terms of the GNU Lesser
9+
** General Public License version 2.1 as published by the Free Software
10+
** Foundation and appearing in the file LICENSE.LGPL included in the
11+
** packaging of this file. Please review the following information to
12+
** ensure the GNU Lesser General Public License version 2.1 requirements
13+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
14+
**
15+
** $QT_END_LICENSE$
16+
**
17+
****************************************************************************/
18+
19+
#include "hybriswakeupadaptorplugin.h"
20+
#include "hybriswakeupadaptor.h"
21+
#include "sensormanager.h"
22+
#include "logging.h"
23+
24+
void HybrisWakeupAdaptorPlugin::Register(class Loader &l)
25+
{
26+
Q_UNUSED(l);
27+
qCDebug(lcSensorFw) << "registering hybriswakeupadaptor";
28+
SensorManager &sm = SensorManager::instance();
29+
sm.registerDeviceAdaptor<HybrisWakeupAdaptor>("wakeupadaptor");
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (c) 2025 Jollyboys Ltd.
4+
**
5+
** $QT_BEGIN_LICENSE:LGPL$
6+
**
7+
** GNU Lesser General Public License Usage
8+
** Alternatively, this file may be used under the terms of the GNU Lesser
9+
** General Public License version 2.1 as published by the Free Software
10+
** Foundation and appearing in the file LICENSE.LGPL included in the
11+
** packaging of this file. Please review the following information to
12+
** ensure the GNU Lesser General Public License version 2.1 requirements
13+
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
14+
**
15+
** $QT_END_LICENSE$
16+
**
17+
****************************************************************************/
18+
19+
#ifndef HYBRISWAKEUPADAPTORPLUGIN_H
20+
#define HYBRISWAKEUPADAPTORPLUGIN_H
21+
22+
#include "plugin.h"
23+
24+
class HybrisWakeupAdaptorPlugin : public Plugin
25+
{
26+
Q_OBJECT
27+
Q_PLUGIN_METADATA(IID "com.nokia.SensorService.Plugin/1.0")
28+
29+
private:
30+
void Register(class Loader &l);
31+
};
32+
#endif // HYBRISWAKEUPADAPTORPLUGIN_H

config/20-sensors-default.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ rotationsensor=True
4646
; To avoid revisiting config files for all old ports in the future, the
4747
; defaults for added sensors should be set "False" by default here, and
4848
; to "True" in device specific override config as appropriate.
49+
50+
wakeupsensor=False

config/60-sensors-DEVICE.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
;stepcountersensor=True
1515
;tapsensor=True
1616
;temperaturesensor=True
17+
;wakeupsensor=True
1718

1819
; Sensors that should/can be enabled/disabled based on
1920
; hw settings config - or are enabled if sensorfwd is

config/sensord-hybris.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ gyroscopeadaptor = hybrisgyroscopeadaptor
77
orientationadaptor = hybrisorientationadaptor
88
stepcounteradaptor = hybrisstepcounteradaptor
99
pressureadaptor = hybrispressureadaptor
10+
wakeupadaptor = hybriswakeupadaptor
1011

1112
[magnetometer]
1213
scale_coefficient = 1

0 commit comments

Comments
 (0)