Skip to content

Commit

Permalink
[sensorfw] initial hybris adaptors
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorn Potter committed Aug 21, 2013
1 parent d3ccfc9 commit 287f09a
Show file tree
Hide file tree
Showing 35 changed files with 1,951 additions and 0 deletions.
10 changes: 10 additions & 0 deletions adaptors/adaptors.pro
Expand Up @@ -26,3 +26,13 @@ SUDBIRS += oemtabletgyroscopeadaptor
SUBDIRS += steaccelerometeradaptor
SUBDIRS += mpu6050accelerometer

contains(CONFIG,hybris) {
SUBDIRS += hybrisaccelerometer
SUBDIRS += hybrisalsadaptor
SUBDIRS += hybrisgyroscopeadaptor
SUBDIRS += hybrismagnetometeradaptor
SUBDIRS += hybrisproximityadaptor
SUBDIRS += hybrisorientationadaptor
}


9 changes: 9 additions & 0 deletions adaptors/hybrisaccelerometer/hybrisaccelerometer.pro
@@ -0,0 +1,9 @@
TARGET = hybrisaccelerometeradaptor

HEADERS += hybrisaccelerometeradaptor.h \
hybrisaccelerometeradaptorplugin.h

SOURCES += hybrisaccelerometeradaptor.cpp \
hybrisaccelerometeradaptorplugin.cpp

include( ../adaptor-config.pri )
75 changes: 75 additions & 0 deletions adaptors/hybrisaccelerometer/hybrisaccelerometeradaptor.cpp
@@ -0,0 +1,75 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.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 "hybrisaccelerometeradaptor.h"
#include "logging.h"
#include "datatypes/utils.h"
#include <android/hardware/sensors.h>

HybrisAccelerometerAdaptor::HybrisAccelerometerAdaptor(const QString& id) :
HybrisAdaptor(id,SENSOR_TYPE_ACCELEROMETER)
{
buffer = new DeviceAdaptorRingBuffer<AccelerationData>(1);
setAdaptedSensor("accelerometer", "Internal accelerometer coordinates", buffer);

setDescription("Hybris accelerometer");
// setDefaultInterval(50);
}

HybrisAccelerometerAdaptor::~HybrisAccelerometerAdaptor()
{
delete buffer;
}

bool HybrisAccelerometerAdaptor::startSensor()
{
if (!(HybrisAdaptor::startSensor()))
return false;

sensordLogD() << "Hybris AccelAdaptor start\n";
return true;
}

void HybrisAccelerometerAdaptor::stopSensor()
{
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris AccelAdaptor stop\n";
}

void HybrisAccelerometerAdaptor::processSample(const sensors_event_t& data)
{

AccelerationData *d = buffer->nextSlot();
d->timestamp_ = quint64(data.timestamp * .001);
// sensorfw wants milli-G'
d->x_ = -(data.data[0] / 9.80665 * 1000);
d->y_ = -(data.data[1] / 9.80665 * 1000);
d->z_ = -(data.data[2] / 9.80665 * 1000);
// qt's sensorfw plugin expects G == 9.81286, but it should be
//9.80665
buffer->commit();
buffer->wakeUpReaders();
}

//void HybrisAccelerometerAdaptor::init()
//{
//// introduceAvailableDataRange(DataRange(-HybrisAdaptor::maxRange, HybrisAdaptor::maxRange , 1));
//// introduceAvailableInterval(DataRange(10, 586, 0));
//}
54 changes: 54 additions & 0 deletions adaptors/hybrisaccelerometer/hybrisaccelerometeradaptor.h
@@ -0,0 +1,54 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.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 HYBRISACCELEROMETERADPTOR_H
#define HYBRISACCELEROMETERADPTOR_H

#include "hybrisadaptor.h"

#include <QString>
#include <QStringList>
#include "deviceadaptorringbuffer.h"
#include "datatypes/orientationdata.h"

class HybrisAccelerometerAdaptor : public HybrisAdaptor
{
Q_OBJECT

public:
static DeviceAdaptor* factoryMethod(const QString& id) {
return new HybrisAccelerometerAdaptor(id);
}
HybrisAccelerometerAdaptor(const QString& id);
~HybrisAccelerometerAdaptor();

bool startSensor();
void stopSensor();

protected:
void processSample(const sensors_event_t& data);
// void init();

private:
DeviceAdaptorRingBuffer<AccelerationData>* buffer;
int sensorType;

};
#endif
35 changes: 35 additions & 0 deletions adaptors/hybrisaccelerometer/hybrisaccelerometeradaptorplugin.cpp
@@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.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 "hybrisaccelerometeradaptorplugin.h"
#include "hybrisaccelerometeradaptor.h"
#include "sensormanager.h"
#include "logging.h"

void HybrisAccelerometerAdaptorPlugin::Register(class Loader&)
{
sensordLogD() << "registering hybrisaccelerometeradaptor";
SensorManager& sm = SensorManager::instance();
sm.registerDeviceAdaptor<HybrisAccelerometerAdaptor>("accelerometeradaptor");
}

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Q_EXPORT_PLUGIN2(hybrisaccelerometeradaptor, HybrisAccelerometerAdaptorPlugin)
#endif
37 changes: 37 additions & 0 deletions adaptors/hybrisaccelerometer/hybrisaccelerometeradaptorplugin.h
@@ -0,0 +1,37 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.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 HYBRISACCELEROMETERADAPTORPLUGIN_H
#define HYBRISACCELEROMETERADAPTORPLUGIN_H

#include "plugin.h"

class HybrisAccelerometerAdaptorPlugin : 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
67 changes: 67 additions & 0 deletions adaptors/hybrisalsadaptor/hybrisalsadaptor.cpp
@@ -0,0 +1,67 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.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 "hybrisalsadaptor.h"
#include "logging.h"
#include "datatypes/utils.h"
#include <android/hardware/sensors.h>

HybrisAlsAdaptor::HybrisAlsAdaptor(const QString& id) :
HybrisAdaptor(id,SENSOR_TYPE_LIGHT)
{
buffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1);
setAdaptedSensor("als", "Internal ambient light sensor lux values", buffer);
// setDefaultInterval(50);
setDescription("Hybris als");
}

HybrisAlsAdaptor::~HybrisAlsAdaptor()
{
delete buffer;
}

bool HybrisAlsAdaptor::startSensor()
{
if (!(HybrisAdaptor::startSensor()))
return false;

sensordLogD() << "Hybris HybrisAlsAdaptor start\n";
return true;
}

void HybrisAlsAdaptor::stopSensor()
{
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris HybrisAlsAdaptor stop\n";
}

void HybrisAlsAdaptor::processSample(const sensors_event_t& data)
{
TimedUnsigned *d = buffer->nextSlot();
d->timestamp_ = quint64(data.timestamp * .0001);
d->value_ = data.light;

buffer->commit();
buffer->wakeUpReaders();
}

void HybrisAlsAdaptor::init()
{
}
55 changes: 55 additions & 0 deletions adaptors/hybrisalsadaptor/hybrisalsadaptor.h
@@ -0,0 +1,55 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.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 HYBRISALSADAPTOR_H
#define HYBRISALSADAPTOR_H
#include "hybrisadaptor.h"

#include <QString>
#include <QStringList>
#include <linux/input.h>
#include "deviceadaptorringbuffer.h"
#include "datatypes/orientationdata.h"
#include <QTime>

class HybrisAlsAdaptor : public HybrisAdaptor
{
Q_OBJECT

public:
static DeviceAdaptor* factoryMethod(const QString& id) {
return new HybrisAlsAdaptor(id);
}
HybrisAlsAdaptor(const QString& id);
~HybrisAlsAdaptor();

bool startSensor();
void stopSensor();

protected:
void processSample(const sensors_event_t& data);
void init();

private:
DeviceAdaptorRingBuffer<TimedUnsigned>* buffer;


};
#endif
9 changes: 9 additions & 0 deletions adaptors/hybrisalsadaptor/hybrisalsadaptor.pro
@@ -0,0 +1,9 @@
TARGET = hybrisalsadaptor

HEADERS += hybrisalsadaptor.h \
hybrisalsadaptorplugin.h

SOURCES += hybrisalsadaptor.cpp \
hybrisalsadaptorplugin.cpp

include(../adaptor-config.pri )
35 changes: 35 additions & 0 deletions adaptors/hybrisalsadaptor/hybrisalsadaptorplugin.cpp
@@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.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 "hybrisalsadaptorplugin.h"
#include "hybrisalsadaptor.h"
#include "sensormanager.h"
#include "logging.h"

void HybrisAlsAdaptorPlugin::Register(class Loader&)
{
sensordLogD() << "registering hybrisalsadaptor";
SensorManager& sm = SensorManager::instance();
sm.registerDeviceAdaptor<HybrisAlsAdaptor>("alsadaptor");
}

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Q_EXPORT_PLUGIN2(hybrisalsadaptor, HybrisAlsAdaptorPlugin)
#endif

0 comments on commit 287f09a

Please sign in to comment.