Skip to content

Commit

Permalink
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
lpotter committed Feb 6, 2017
2 parents 9efd97d + a1941c1 commit 28f826f
Show file tree
Hide file tree
Showing 18 changed files with 877 additions and 3 deletions.
2 changes: 2 additions & 0 deletions adaptors/adaptors.pro
Expand Up @@ -9,6 +9,7 @@ contains(CONFIG,hybris) {
SUBDIRS += hybrismagnetometeradaptor
SUBDIRS += hybrisproximityadaptor
SUBDIRS += hybrisorientationadaptor
SUBDIRS += hybrisstepcounteradaptor

} else {

Expand Down Expand Up @@ -52,6 +53,7 @@ config_hybris {
SUBDIRS += hybrismagnetometeradaptor
SUBDIRS += hybrisproximityadaptor
SUBDIRS += hybrisorientationadaptor
SUBDIRS += hybrisstepcounteradaptor
}
}

Expand Down
73 changes: 73 additions & 0 deletions adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptor.cpp
@@ -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 adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptor.h
@@ -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 adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptor.pro
@@ -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
}
@@ -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 adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptorplugin.h
@@ -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
1 change: 1 addition & 0 deletions config/sensord-hybris.conf
Expand Up @@ -5,6 +5,7 @@ proximityadaptor = hybrisproximityadaptor
magnetometeradaptor = hybrismagnetometeradaptor
gyroscopeadaptor = hybrisgyroscopeadaptor
orientationadaptor = hybrisorientationadaptor
stepcounteradaptor = hybrisstepcounteradaptor

[magnetometer]
scale_coefficient = 1
Expand Down
6 changes: 4 additions & 2 deletions qt-api/qt-api.pro
Expand Up @@ -21,7 +21,8 @@ SOURCES += sensormanagerinterface.cpp \
lidsensor_i.cpp \
humiditysensor_i.cpp \
pressuresensor_i.cpp \
temperaturesensor_i.cpp
temperaturesensor_i.cpp \
stepcountersensor_i.cpp

HEADERS += sensormanagerinterface.h \
sensormanager_i.h \
Expand All @@ -39,7 +40,8 @@ HEADERS += sensormanagerinterface.h \
lidsensor_i.h \
humiditysensor_i.h \
pressuresensor_i.h \
temperaturesensor_i.h
temperaturesensor_i.h \
stepcountersensor_i.h

SENSORFW_INCLUDEPATHS = .. \
../include \
Expand Down
80 changes: 80 additions & 0 deletions qt-api/stepcountersensor_i.cpp
@@ -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");
}

0 comments on commit 28f826f

Please sign in to comment.