Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'stepcounter' into 'master'
[sensorfw] add step counter sensor See merge request !10
- Loading branch information
Showing
18 changed files
with
877 additions
and
3 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
73 changes: 73 additions & 0 deletions
73
adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptor.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,73 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2013 Jolla Ltd | ||
** Contact: lorn.potter@jollamobile.com | ||
** | ||
** Copyright (C) 2016 kimmoli | ||
** Contact: kimmo.lindholm@eke.fi | ||
** | ||
** | ||
** $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 "hybrisstepcounteradaptor.h" | ||
#include "logging.h" | ||
#include "datatypes/utils.h" | ||
#include <hardware/sensors.h> | ||
|
||
HybrisStepCounterAdaptor::HybrisStepCounterAdaptor(const QString& id) : | ||
HybrisAdaptor(id, SENSOR_TYPE_STEP_COUNTER) | ||
{ | ||
buffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1); | ||
setAdaptedSensor("stepcounter", "Internal step counter steps since reboot", buffer); | ||
setDescription("Hybris step counter"); | ||
} | ||
|
||
HybrisStepCounterAdaptor::~HybrisStepCounterAdaptor() | ||
{ | ||
delete buffer; | ||
} | ||
|
||
bool HybrisStepCounterAdaptor::startSensor() | ||
{ | ||
if (!(HybrisAdaptor::startSensor())) | ||
return false; | ||
|
||
sensordLogD() << "Hybris HybrisStepCounterAdaptor start\n"; | ||
return true; | ||
} | ||
|
||
void HybrisStepCounterAdaptor::sendInitialData() | ||
{ | ||
sensordLogW() << "No initial data for step counter"; | ||
} | ||
|
||
void HybrisStepCounterAdaptor::stopSensor() | ||
{ | ||
HybrisAdaptor::stopSensor(); | ||
sensordLogD() << "Hybris HybrisStepCounterAdaptor stop\n"; | ||
} | ||
|
||
void HybrisStepCounterAdaptor::processSample(const sensors_event_t& data) | ||
{ | ||
TimedUnsigned *d = buffer->nextSlot(); | ||
d->timestamp_ = quint64(data.timestamp * .001); | ||
d->value_ = data.u64.step_counter; | ||
buffer->commit(); | ||
buffer->wakeUpReaders(); | ||
} | ||
|
||
void HybrisStepCounterAdaptor::init() | ||
{ | ||
} |
69 changes: 69 additions & 0 deletions
69
adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptor.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,69 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2013 Jolla Ltd | ||
** Contact: lorn.potter@jollamobile.com | ||
** | ||
** Copyright (C) 2016 kimmoli | ||
** Contact: kimmo.lindholm@eke.fi | ||
** | ||
** | ||
** $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 HYBRISSTEPCOUNTERADAPTOR_H | ||
#define HYBRISSTEPCOUNTERADAPTOR_H | ||
#include "hybrisadaptor.h" | ||
|
||
#include <QString> | ||
#include <QStringList> | ||
#include <linux/input.h> | ||
#include "deviceadaptorringbuffer.h" | ||
#include "datatypes/orientationdata.h" | ||
#include <QTime> | ||
|
||
/** | ||
* @brief Adaptor for hybris step counter sensor. | ||
* | ||
* Adaptor for step counter sensor. | ||
* | ||
* Returns the number of steps taken by the user since | ||
* the last reboot while activated. The value is returned as a uint64_t and is | ||
* reset to zero only on a system reboot. | ||
* | ||
*/ | ||
class HybrisStepCounterAdaptor : public HybrisAdaptor | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
static DeviceAdaptor* factoryMethod(const QString& id) { | ||
return new HybrisStepCounterAdaptor(id); | ||
} | ||
HybrisStepCounterAdaptor(const QString& id); | ||
~HybrisStepCounterAdaptor(); | ||
|
||
bool startSensor(); | ||
void stopSensor(); | ||
|
||
void sendInitialData(); | ||
|
||
protected: | ||
void processSample(const sensors_event_t& data); | ||
void init(); | ||
|
||
private: | ||
DeviceAdaptorRingBuffer<TimedUnsigned>* buffer; | ||
|
||
}; | ||
#endif |
13 changes: 13 additions & 0 deletions
13
adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptor.pro
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 = hybrisstepcounteradaptor | ||
|
||
HEADERS += hybrisstepcounteradaptor.h \ | ||
hybrisstepcounteradaptorplugin.h | ||
|
||
SOURCES += hybrisstepcounteradaptor.cpp \ | ||
hybrisstepcounteradaptorplugin.cpp | ||
LIBS+= -L../../core -lhybrissensorfw-qt5 | ||
|
||
include(../adaptor-config.pri ) | ||
config_hybris { | ||
INCLUDEPATH+=/usr/include/android | ||
} |
38 changes: 38 additions & 0 deletions
38
adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptorplugin.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,38 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2013 Jolla Ltd | ||
** Contact: lorn.potter@jollamobile.com | ||
** | ||
** Copyright (C) 2016 kimmoli | ||
** Contact: kimmo.lindholm@eke.fi | ||
** | ||
** | ||
** $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 "hybrisstepcounteradaptorplugin.h" | ||
#include "hybrisstepcounteradaptor.h" | ||
#include "sensormanager.h" | ||
#include "logging.h" | ||
|
||
void HybrisStepCounterAdaptorPlugin::Register(class Loader&) | ||
{ | ||
sensordLogD() << "registering hybrisstepcounteradaptor"; | ||
SensorManager& sm = SensorManager::instance(); | ||
sm.registerDeviceAdaptor<HybrisStepCounterAdaptor>("stepcounteradaptor"); | ||
} | ||
|
||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) | ||
Q_EXPORT_PLUGIN2(hybrisstepcounteradaptor, HybrisStepCounterAdaptorPlugin) | ||
#endif |
40 changes: 40 additions & 0 deletions
40
adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptorplugin.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,40 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2013 Jolla Ltd | ||
** Contact: lorn.potter@jollamobile.com | ||
** | ||
** Copyright (C) 2016 kimmoli | ||
** Contact: kimmo.lindholm@eke.fi | ||
** | ||
** | ||
** $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 HYBRISSTEPCOUNTERADAPTORPLUGIN_H | ||
#define HYBRISSTEPCOUNTERADAPTORPLUGIN_H | ||
|
||
#include "plugin.h" | ||
|
||
class HybrisStepCounterAdaptorPlugin : 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
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,80 @@ | ||
/** | ||
@file stepcountersensor_i.cpp | ||
@brief Interface for stepcounter sensor | ||
<p> | ||
Copyright (C) 2009-2010 Nokia Corporation | ||
Copyright (C) 2016 kimmoli | ||
@author Kimmo Lindholm <kimmo.lindholm@eke.fi> | ||
@author Timo Rongas <ext-timo.2.rongas@nokia.com> | ||
@author Antti Virtanen <antti.i.virtanen@nokia.com> | ||
This file is part of Sensord. | ||
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 "sensormanagerinterface.h" | ||
#include "stepcountersensor_i.h" | ||
#include "socketreader.h" | ||
|
||
const char* StepCounterSensorChannelInterface::staticInterfaceName = "local.StepCounterSensor"; | ||
|
||
AbstractSensorChannelInterface* StepCounterSensorChannelInterface::factoryMethod(const QString& id, int sessionId) | ||
{ | ||
return new StepCounterSensorChannelInterface(OBJECT_PATH + "/" + id, sessionId); | ||
} | ||
|
||
StepCounterSensorChannelInterface::StepCounterSensorChannelInterface(const QString& path, int sessionId) | ||
: AbstractSensorChannelInterface(path, StepCounterSensorChannelInterface::staticInterfaceName, sessionId) | ||
{ | ||
} | ||
|
||
const StepCounterSensorChannelInterface* StepCounterSensorChannelInterface::listenInterface(const QString& id) | ||
{ | ||
return dynamic_cast<const StepCounterSensorChannelInterface*> (interface(id)); | ||
} | ||
|
||
StepCounterSensorChannelInterface* StepCounterSensorChannelInterface::controlInterface(const QString& id) | ||
{ | ||
return interface(id); | ||
} | ||
|
||
|
||
StepCounterSensorChannelInterface* StepCounterSensorChannelInterface::interface(const QString& id) | ||
{ | ||
SensorManagerInterface& sm = SensorManagerInterface::instance(); | ||
if ( !sm.registeredAndCorrectClassName( id, StepCounterSensorChannelInterface::staticMetaObject.className() ) ) | ||
{ | ||
return 0; | ||
} | ||
|
||
return dynamic_cast<StepCounterSensorChannelInterface*>(sm.interface(id)); | ||
} | ||
|
||
bool StepCounterSensorChannelInterface::dataReceivedImpl() | ||
{ | ||
QVector<TimedUnsigned> values; | ||
if(!read<TimedUnsigned>(values)) | ||
return false; | ||
foreach(const TimedUnsigned& data, values) | ||
emit StepCounterChanged(data); | ||
return true; | ||
} | ||
|
||
Unsigned StepCounterSensorChannelInterface::steps() | ||
{ | ||
return getAccessor<Unsigned>("steps"); | ||
} |
Oops, something went wrong.