Search
SailfishOS Open Build Service
>
Projects
>
home:wonko
:
pa4
:
addons
>
sensorfw
> add-mpu6050-accelerometer.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File add-mpu6050-accelerometer.patch of Package sensorfw
diff --git a/adaptors/adaptors.pro b/adaptors/adaptors.pro index 6754c9d..2c2a194 100644 --- a/adaptors/adaptors.pro +++ b/adaptors/adaptors.pro @@ -23,5 +23,6 @@ SUBDIRS += oemtabletalsadaptor-ascii SUBDIRS += oaktrailaccelerometer SUBDIRS += oemtabletaccelerometer SUDBIRS += oemtabletgyroscopeadaptor -SUBDIRS += steaccelerometeradaptor +SUBDIRS += steaccelerometeradaptor +SUBDIRS += mpu6050accelerometer diff --git a/adaptors/mpu6050accelerometer/mpu6050accelerometer.pro b/adaptors/mpu6050accelerometer/mpu6050accelerometer.pro new file mode 100644 index 0000000..7003bb8 --- /dev/null +++ b/adaptors/mpu6050accelerometer/mpu6050accelerometer.pro @@ -0,0 +1,9 @@ +TARGET = mpu6050accelerometeradaptor + +HEADERS += mpu6050accelerometeradaptor.h \ + mpu6050accelerometeradaptorplugin.h + +SOURCES += mpu6050accelerometeradaptor.cpp \ + mpu6050accelerometeradaptorplugin.cpp + +include( ../adaptor-config.pri ) diff --git a/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptor.cpp b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptor.cpp new file mode 100644 index 0000000..06b2663 --- /dev/null +++ b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptor.cpp @@ -0,0 +1,129 @@ +/** + Copyright 2013 Ruediger Gad <r.c.g@gmx.de> + + The Mpu6050AccelAdaptor was created based on the OemTabletAccelAdaptor. + + 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/>. +*/ + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdio.h> + +#include "config.h" +#include "mpu6050accelerometeradaptor.h" +#include "logging.h" +#include "datatypes/utils.h" + +#define EARTH_GRAVITY 9.81 +/* + * 165.8 is the result of a reference measurement. + * We are going to correct it such that we get the correct acceleration in m/s^2 + */ +#define CORRECTION_FACTOR (165.8 / EARTH_GRAVITY) + +Mpu6050AccelAdaptor::Mpu6050AccelAdaptor (const QString& id) : + SysfsAdaptor (id, SysfsAdaptor::IntervalMode) +{ + struct stat st; + + QString xAxisPath = Config::configuration()->value("accelerometer/x_axis_path").toString (); + if ( lstat (xAxisPath.toLatin1().constData(), &st) < 0 ) { + sensordLogW () << "x_axis_path: " << xAxisPath << " not found"; + return; + } + addPath(xAxisPath, X_AXIS); + + QString yAxisPath = Config::configuration()->value("accelerometer/y_axis_path").toString (); + if ( lstat (yAxisPath.toLatin1().constData(), &st) < 0 ) { + sensordLogW () << "y_axis_path: " << yAxisPath << " not found"; + return; + } + addPath(yAxisPath, Y_AXIS); + + QString zAxisPath = Config::configuration()->value("accelerometer/z_axis_path").toString (); + if ( lstat (zAxisPath.toLatin1().constData(), &st) < 0 ) { + sensordLogW () << "z_axis_path: " << zAxisPath << " not found"; + return; + } + addPath(zAxisPath, Z_AXIS); + + buffer = new DeviceAdaptorRingBuffer<OrientationData>(128); + setAdaptedSensor("accelerometer", "MPU6050 accelerometer", buffer); + + setDescription("MPU 6050 accelerometer"); +// introduceAvailableDataRange(DataRange(-16384, 16384, 1)); +// introduceAvailableInterval(DataRange(10, 586, 0)); +// setDefaultInterval(100); +} + +Mpu6050AccelAdaptor::~Mpu6050AccelAdaptor () { + delete buffer; +} + +bool Mpu6050AccelAdaptor::startSensor () { + if ( !(SysfsAdaptor::startSensor ()) ) + return false; + + sensordLogD() << "MPU6050 AccelAdaptor start\n"; + return true; +} + +void Mpu6050AccelAdaptor::stopSensor () { + SysfsAdaptor::stopSensor(); + sensordLogD() << "MPU6050 AccelAdaptor stop\n"; +} + +void Mpu6050AccelAdaptor::processSample (int pathId, int fd) { + char buf[32]; + int val; + + if ( pathId < X_AXIS || pathId > Z_AXIS ) { + sensordLogW() << "Wrong pathId: " << pathId; + return; + } + + lseek (fd, 0, SEEK_SET); + if (read (fd, buf, sizeof(buf)) < 0) { + sensordLogW() << "Read failed"; + return; + } + + if (sscanf (buf, "%d", &val) == 0 ) { + sensordLogW() << "Wrong data format: " << buf; + return; + } + + switch (pathId) { + case X_AXIS: + currentData = buffer->nextSlot(); + currentData->timestamp_ = Utils::getTimeStamp(); + currentData->x_ = qRound(val / CORRECTION_FACTOR); + break; + case Y_AXIS: + currentData->y_ = qRound(val / CORRECTION_FACTOR); + break; + case Z_AXIS: + currentData->z_ = qRound(val / CORRECTION_FACTOR); + buffer->commit(); + buffer->wakeUpReaders(); + break; + default: + sensordLogW() << "Invalid pathId: " << pathId; + break; + } +} + diff --git a/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptor.h b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptor.h new file mode 100644 index 0000000..a41c558 --- /dev/null +++ b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptor.h @@ -0,0 +1,55 @@ +/** + Copyright 2013 Ruediger Gad <r.c.g@gmx.de> + + The Mpu6050AccelAdaptor was created based on the OemTabletAccelAdaptor. + + 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/>. +*/ + +#ifndef MPU6050ACCELEROMETERADPTOR_H +#define MPU6050ACCELEROMETERADPTOR_H +#include "sysfsadaptor.h" +#include <QString> +#include <QStringList> +#include <linux/input.h> +#include "deviceadaptorringbuffer.h" +#include "datatypes/orientationdata.h" +#include <QTime> + +#define X_AXIS 1 +#define Y_AXIS 2 +#define Z_AXIS 3 + +class Mpu6050AccelAdaptor : public SysfsAdaptor { + Q_OBJECT + + public: + static DeviceAdaptor* factoryMethod (const QString& id) { + return new Mpu6050AccelAdaptor (id); + } + Mpu6050AccelAdaptor (const QString& id); + ~Mpu6050AccelAdaptor (); + + bool startSensor (); + void stopSensor (); + + protected: + void processSample (int pathId, int fd); + + private: + DeviceAdaptorRingBuffer<OrientationData>* buffer; + OrientationData *currentData; +}; +#endif diff --git a/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptorplugin.cpp b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptorplugin.cpp new file mode 100644 index 0000000..28f0071 --- /dev/null +++ b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptorplugin.cpp @@ -0,0 +1,35 @@ +/** + Copyright 2013 Ruediger Gad <r.c.g@gmx.de> + + The Mpu6050AccelAdaptor was created based on the OemTabletAccelAdaptor. + + 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/>. +*/ + +#include "mpu6050accelerometeradaptorplugin.h" +#include "mpu6050accelerometeradaptor.h" +#include "sensormanager.h" +#include "logging.h" + +void Mpu6050AccelerometerAdaptorPlugin::Register(class Loader&) +{ + sensordLogD() << "registering mpu6050accelerometeradaptor"; + SensorManager& sm = SensorManager::instance(); + sm.registerDeviceAdaptor<Mpu6050AccelAdaptor>("accelerometeradaptor"); +} + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +Q_EXPORT_PLUGIN2(mpu6050accelerometeradaptor, Mpu6050AccelerometerAdaptorPlugin) +#endif diff --git a/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptorplugin.h b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptorplugin.h new file mode 100644 index 0000000..aaed19a --- /dev/null +++ b/adaptors/mpu6050accelerometer/mpu6050accelerometeradaptorplugin.h @@ -0,0 +1,37 @@ +/** + Copyright 2013 Ruediger Gad <r.c.g@gmx.de> + + The Mpu6050AccelAdaptor was created based on the OemTabletAccelAdaptor. + + 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/>. +*/ + +#ifndef MPU6050ACCELEROMETERADAPTORPLUGIN_H +#define MPU6050ACCELEROMETERADAPTORPLUGIN_H + +#include "plugin.h" + +class Mpu6050AccelerometerAdaptorPlugin : 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 diff --git a/config/sensord-arm_grouper_0000.conf b/config/sensord-arm_grouper_0000.conf new file mode 100644 index 0000000..5833bde --- /dev/null +++ b/config/sensord-arm_grouper_0000.conf @@ -0,0 +1,12 @@ +[plugins] +accelerometeradaptor = mpu6050accelerometeradaptor + +[accelerometer] +x_axis_path = "/sys/devices/platform/tegra-i2c.2/i2c-2/2-0068/iio:device0/in_accel_x_raw" +y_axis_path = "/sys/devices/platform/tegra-i2c.2/i2c-2/2-0068/iio:device0/in_accel_y_raw" +z_axis_path = "/sys/devices/platform/tegra-i2c.2/i2c-2/2-0068/iio:device0/in_accel_z_raw" +dataranges = "-32000=>32000" +intervals = "10,50,100,200,500" +default_interval = 50 +transformation_matrix = "-1,0,0,0,-1,0,0,0,-1" +