Navigation Menu

Skip to content

Commit

Permalink
- Removed possibility of having multiple sensors inside single Devic…
Browse files Browse the repository at this point in the history
…eAdaptor. This feature was never used.

 - DeviceAdaptor::init() added. Subclasses can implement this to initialize themselves.
 - SysfsAdaptor and InputDevAdaptor init() implemented. They try to find adaptor configuration from section which is named after the adaptor type.
 - Removed hardcoded metadata definitions from adaptors. This will now come from config file.
  • Loading branch information
Antti Virtanen committed Feb 3, 2011
1 parent 8005e55 commit c6f135a
Show file tree
Hide file tree
Showing 48 changed files with 386 additions and 578 deletions.
20 changes: 3 additions & 17 deletions adaptors/accelerometeradaptor/accelerometeradaptor.cpp
Expand Up @@ -7,6 +7,7 @@
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand All @@ -32,31 +33,16 @@
#include <fcntl.h>
#include <linux/input.h>
#include <QMap>
#include "config.h"

#include "datatypes/utils.h"

#define DEVICE_MATCH_STRING "accelerometer"

AccelerometerAdaptor::AccelerometerAdaptor(const QString& id) :
InputDevAdaptor(id, 1)
{
//This was previously in the base class, but it's not
//possible call virtual methods from base class constructor.
//TODO: find a way to get rid of all child classes calling this
//manually.
if (!getInputDevices(DEVICE_MATCH_STRING)) {
sensordLogW() << "Input device not found.";
}

accelerometerBuffer_ = new DeviceAdaptorRingBuffer<OrientationData>(128);
addAdaptedSensor("accelerometer", "Internal accelerometer coordinates", accelerometerBuffer_);

// Set Metadata
setAdaptedSensor("accelerometer", "Internal accelerometer coordinates", accelerometerBuffer_);
setDescription("Input device accelerometer adaptor (lis302d)");
introduceAvailableDataRange(DataRange(-2048, 2048, 1));
introduceAvailableInterval(DataRange(0, 0, 0));
introduceAvailableInterval(DataRange(10, 1000, 0)); // -> [1,100] Hz
setDefaultInterval(0);
}

AccelerometerAdaptor::~AccelerometerAdaptor()
Expand Down
4 changes: 2 additions & 2 deletions adaptors/accelerometeradaptor/accelerometeradaptor.h
Expand Up @@ -9,6 +9,7 @@
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
Sensord is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License
Expand All @@ -30,12 +31,11 @@
#include "inputdevadaptor.h"
#include "deviceadaptorringbuffer.h"
#include "datatypes/orientationdata.h"
#include <QTime>

/**
* @brief Adaptor for internal accelerometer.
*
* Adaptor for internal accelerometer. Uses SysFs driver interface in interval
* Adaptor for internal accelerometer. Uses SysFs driver interface in interval
* polling mode, i.e. values are read with given constant interval.
*
* Driver interface is located in @e /sys/class/i2c-adapter/i2c-3/3-001d/ .
Expand Down
31 changes: 2 additions & 29 deletions adaptors/alsadaptor-ascii/alsadaptor-ascii.cpp
Expand Up @@ -11,6 +11,7 @@
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Tapio Rantala <ext-tapio.rantala@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down Expand Up @@ -42,37 +43,9 @@

ALSAdaptorAscii::ALSAdaptorAscii(const QString& id) : SysfsAdaptor(id, SysfsAdaptor::IntervalMode)
{
const unsigned int DEFAULT_RANGE = 65535;

int range = DEFAULT_RANGE;
QFile sysFile(Config::configuration()->value("als-ascii_range_sysfs_path").toString());

if (!(sysFile.open(QIODevice::ReadOnly))) {
sensordLogW() << "Unable to config ALS range from sysfs, using default value: " << DEFAULT_RANGE;
} else {
sysFile.readLine(buf, sizeof(buf));
range = QString(buf).toInt();
}

sensordLogT() << "Ambient light range: " << range;

// Locate the actual handle
QString devPath = Config::configuration()->value("als-ascii_sysfs_path").toString();

if (devPath.isEmpty())
{
sensordLogW() << "No driver handle found for ALS. Data not available.";
return;
}

addPath(devPath);
alsBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(16);
addAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer_);

setAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer_);
setDescription("Ambient light");
introduceAvailableDataRange(DataRange(0, range, 1));
introduceAvailableInterval(DataRange(50, 2000, 0));
setDefaultInterval(1000);
}

ALSAdaptorAscii::~ALSAdaptorAscii()
Expand Down
1 change: 1 addition & 0 deletions adaptors/alsadaptor-ascii/alsadaptor-ascii.h
Expand Up @@ -11,6 +11,7 @@
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Tapio Rantala <ext-tapio.rantala@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down
3 changes: 2 additions & 1 deletion adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.cpp
Expand Up @@ -11,6 +11,7 @@
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Tapio Rantala <ext-tapio.rantala@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand All @@ -34,7 +35,7 @@

void ALSAdaptorAsciiPlugin::Register(class Loader&)
{
sensordLogW() << "registering alsadaptor-ascii";
sensordLogD() << "registering alsadaptor-ascii";
SensorManager& sm = SensorManager::instance();
sm.registerDeviceAdaptor<ALSAdaptorAscii>("alsadaptor");
}
Expand Down
5 changes: 3 additions & 2 deletions adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.h
Expand Up @@ -11,6 +11,7 @@
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Tapio Rantala <ext-tapio.rantala@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand All @@ -35,8 +36,8 @@

class ALSAdaptorAsciiPlugin : public Plugin
{
private:
void Register(class Loader& l);
private:
void Register(class Loader& l);
};

#endif
9 changes: 3 additions & 6 deletions adaptors/alsadaptor-sysfs/alsadaptor-sysfs.cpp
Expand Up @@ -10,6 +10,7 @@
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Tapio Rantala <ext-tapio.rantala@nokia.com>
@author Markus Lehtonen <markus.lehtonen@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down Expand Up @@ -38,12 +39,8 @@
ALSAdaptorSysfs::ALSAdaptorSysfs(const QString& id) :
SysfsAdaptor(id, SysfsAdaptor::IntervalMode, true, Config::configuration()->value("als-sysfs_path").toString())
{
alsBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(1024);
addAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer_);

introduceAvailableDataRange(DataRange(0, 65535, 1));
introduceAvailableInterval(DataRange(0, 0, 0));
setDefaultInterval(0);
alsBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(16);
setAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer_);
}

ALSAdaptorSysfs::~ALSAdaptorSysfs()
Expand Down
3 changes: 1 addition & 2 deletions adaptors/alsadaptor-sysfs/alsadaptor-sysfs.h
Expand Up @@ -8,6 +8,7 @@
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Markus Lehtonen <markus.lehtonen@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand All @@ -31,7 +32,6 @@
#include "sysfsadaptor.h"
#include "deviceadaptorringbuffer.h"
#include "datatypes/timedunsigned.h"
#include <QTime>

/**
* @brief Adaptor for internal ambient light sensor of Nokia Sysfs.
Expand Down Expand Up @@ -88,4 +88,3 @@ class ALSAdaptorSysfs : public SysfsAdaptor
};

#endif

57 changes: 5 additions & 52 deletions adaptors/alsadaptor/alsadaptor.cpp
Expand Up @@ -10,6 +10,7 @@
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Tapio Rantala <ext-tapio.rantala@nokia.com>
@author Lihan Guo <lihan.guo@digia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand All @@ -35,16 +36,6 @@
#include <linux/types.h>
#include <QFile>

#define RM680_ALS "/dev/bh1770glc_als"
#define RM696_ALS "/dev/apds990x0"

#define APDS990X_ALS_SATURATED 0x1 /* ADC overflow. result unreliable */
#define APDS990X_PS_ENABLED 0x2 /* Proximity sensor active */
#define APDS990X_ALS_UPDATED 0x4 /* ALS result updated in the response */
#define APDS990X_PS_UPDATED 0x8 /* Prox result updated in the response */

#define APDS990X_ALS_OUTPUT_SCALE 10

/* Device name: /dev/apds990x0 */
struct apds990x_data {
__u32 lux; /* 10x scale */
Expand All @@ -62,56 +53,22 @@ struct bh1770glc_als {
ALSAdaptor::ALSAdaptor(const QString& id):
SysfsAdaptor(id, SysfsAdaptor::SelectMode, false)
{
device = DeviceUnknown;

QString rm680_als = Config::configuration()->value("als_dev_path_rm680").toString();
QString rm696_als = Config::configuration()->value("als_dev_path_rm696").toString();

if (QFile::exists(rm680_als))
{
device = RM680;
addPath(rm680_als);
} else if (QFile::exists(RM680_ALS))
{
device = RM680;
addPath(RM680_ALS);
} else if (QFile::exists(rm696_als))
{
device = RM696;
addPath(rm696_als);
} else if (QFile::exists(RM696_ALS))
{
device = RM696;
addPath(RM696_ALS);
}

if (device == DeviceUnknown)
{
sensordLogW() << "Other HW except RM680 and RM696";
}

alsBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(32);
addAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer_);

setAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer_);
setDescription("Ambient light");
introduceAvailableDataRange(DataRange(0, 65535, 1));
introduceAvailableInterval(DataRange(0, 0, 0));
setDefaultInterval(0);

deviceType_ = (DeviceType)Config::configuration()->value("als/driver_type", "0").toInt();
}


ALSAdaptor::~ALSAdaptor()
{
delete alsBuffer_;
}


void ALSAdaptor::processSample(int pathId, int fd)
{
Q_UNUSED(pathId);

if(device == RM680)
if(deviceType_ == RM680)
{
struct bh1770glc_als als_data;
als_data.lux = 0;
Expand All @@ -128,11 +85,9 @@ void ALSAdaptor::processSample(int pathId, int fd)
lux->value_ = als_data.lux;
lux->timestamp_ = Utils::getTimeStamp();
}

if (device == RM696)
else if (deviceType_ == RM696)
{
struct apds990x_data als_data;

als_data.lux = 0;

int bytesRead = read(fd, &als_data, sizeof(als_data));
Expand All @@ -147,8 +102,6 @@ void ALSAdaptor::processSample(int pathId, int fd)
lux->value_ = als_data.lux;
lux->timestamp_ = Utils::getTimeStamp();
}

alsBuffer_->commit();
alsBuffer_->wakeUpReaders();

}
6 changes: 2 additions & 4 deletions adaptors/alsadaptor/alsadaptor.h
Expand Up @@ -8,6 +8,7 @@
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Lihan Guo <lihan.guo@digia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down Expand Up @@ -48,7 +49,6 @@ class ALSAdaptor : public SysfsAdaptor
{
Q_OBJECT;
public:

enum DeviceType
{
DeviceUnknown = 0,
Expand Down Expand Up @@ -95,9 +95,7 @@ class ALSAdaptor : public SysfsAdaptor
void processSample(int pathId, int fd);

DeviceAdaptorRingBuffer<TimedUnsigned>* alsBuffer_;
ALSAdaptor::DeviceType device;

DeviceType deviceType_;
};

#endif

11 changes: 2 additions & 9 deletions adaptors/gyroscopeadaptor/gyroscopeadaptor.cpp
Expand Up @@ -7,6 +7,7 @@
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Samuli Piippo <ext-samuli.1.piippo@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down Expand Up @@ -34,16 +35,8 @@
GyroscopeAdaptor::GyroscopeAdaptor(const QString& id) :
SysfsAdaptor(id, SysfsAdaptor::SelectMode)
{
QString path = Config::configuration()->value("gyroscope_sysfs_path").toString();
if ( !addPath(path, 0) ) {
setValid(false);
}

gyroscopeBuffer_ = new DeviceAdaptorRingBuffer<AngularVelocityData>(32);

addAdaptedSensor("gyroscope", "l3g4200dh", gyroscopeBuffer_);

introduceAvailableDataRange(DataRange(-250000, 250000, 1));
setAdaptedSensor("gyroscope", "l3g4200dh", gyroscopeBuffer_);
}

GyroscopeAdaptor::~GyroscopeAdaptor()
Expand Down
16 changes: 1 addition & 15 deletions adaptors/kbslideradaptor/kbslideradaptor.cpp
Expand Up @@ -33,29 +33,15 @@

#include "kbslideradaptor.h"

#define DEVICE_MATCH_STRING "gpio-keys"
#define SELFDEF_EV_KB 5
#define SELFDEF_EV_KBSLIDE 10

KeyboardSliderAdaptor::KeyboardSliderAdaptor(const QString& id) :
InputDevAdaptor(id, 1), newKbEventRecorded_(false), currentState_(KeyboardSliderStateUnknown)
{

//This was previously in the base class, but it's not
//possible call virtual methods from base class constructor.
//TODO: find a way to get rid of all child classes calling this
//manually.
if (!getInputDevices(DEVICE_MATCH_STRING)) {
sensordLogW() << "Input device not found.";
}

kbstateBuffer_ = new DeviceAdaptorRingBuffer<KeyboardSliderState>(3);
addAdaptedSensor("keyboardslider", "Device keyboard slider state", kbstateBuffer_);

setAdaptedSensor("keyboardslider", "Device keyboard slider state", kbstateBuffer_);
setDescription("Keyboard slider events (via input device)");
introduceAvailableDataRange(DataRange(0, 2, 1));
introduceAvailableInterval(DataRange(0, 0, 0));
setDefaultInterval(0);
}

KeyboardSliderAdaptor::~KeyboardSliderAdaptor()
Expand Down

0 comments on commit c6f135a

Please sign in to comment.