Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add steals adaptor
  • Loading branch information
Lorn Potter committed Feb 9, 2013
1 parent db850e5 commit ad05ed1
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 3 deletions.
4 changes: 2 additions & 2 deletions adaptors/adaptors.pro
Expand Up @@ -23,5 +23,5 @@ SUBDIRS += oemtabletalsadaptor-ascii
SUBDIRS += oaktrailaccelerometer
SUBDIRS += oemtabletaccelerometer
SUDBIRS += oemtabletgyroscopeadaptor
SUBDIRS += steaccelerometeradaptor

SUBDIRS += steaccelerometeradaptor
SUBDIRS += stealsadaptor
100 changes: 100 additions & 0 deletions adaptors/stealsadaptor/stealsadaptor-sysfs.cpp
@@ -0,0 +1,100 @@
/**
@file alsadaptor-sysfs.cpp
@brief ALSAdaptor that reads lux values from a sysfs node
<p>
Copyright (C) 2009-2010 Nokia Corporation
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@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 Markus Lehtonen <markus.lehtonen@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 "logging.h"
#include "config.h"
#include "stealsadaptor-sysfs.h"
#include <errno.h>
#include <stdlib.h>
#include "datatypes/utils.h"
#include <linux/types.h>
#include <QDebug>

SteAlsAdaptorSysfs::SteAlsAdaptorSysfs(const QString& id) :
SysfsAdaptor(id, SysfsAdaptor::IntervalMode)
{
sensordLogC() << Q_FUNC_INFO;

alsBuffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1);
setAdaptedSensor("als", "Internal ambient light sensor lux values", alsBuffer);
setDescription("Ambient light");

powerStatePath = Config::configuration()->value<QByteArray>("als/powerstate_path", "");
powerMode = Config::configuration()->value<QByteArray>("als/mode","");
}

SteAlsAdaptorSysfs::~SteAlsAdaptorSysfs()
{
delete alsBuffer;
}

void SteAlsAdaptorSysfs::processSample(int pathId, int fd)
{
sensordLogC() << Q_FUNC_INFO;
Q_UNUSED(pathId);

char buf[16];
lseek(fd, 0, SEEK_SET);
if (read(fd, buf, sizeof(buf)) <= 0) {
sensordLogW() << "read():" << strerror(errno);
return;
}

sensordLogT() << "Ambient light value: " << buf;

TimedUnsigned* lux = alsBuffer->nextSlot();
sscanf(buf, "%d", &lux->value_);
lux->timestamp_ = Utils::getTimeStamp();
alsBuffer->commit();
alsBuffer->wakeUpReaders();
}

bool SteAlsAdaptorSysfs::startSensor()
{
sensordLogC() << Q_FUNC_INFO;
if(!powerStatePath.isEmpty()) {
writeToFile(powerStatePath, powerMode);
}

if (!(SysfsAdaptor::startSensor()))
return false;

return true;
}

void SteAlsAdaptorSysfs::stopSensor()
{
sensordLogC() << Q_FUNC_INFO;
if(!powerStatePath.isEmpty()) {
writeToFile(powerStatePath, "0");
}
SysfsAdaptor::stopSensor();
}

61 changes: 61 additions & 0 deletions adaptors/stealsadaptor/stealsadaptor-sysfs.h
@@ -0,0 +1,61 @@
/**
@file alsadaptor-sysfs.h
@brief ALSAdaptor that reads lux values from a sysfs node
<p>
Copyright (C) 2009-2010 Nokia Corporation
@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.
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>
*/

#ifndef STEALSADAPTOR_SYSFS_H
#define STEALSADAPTOR_SYSFS_H

#include "sysfsadaptor.h"
#include "deviceadaptorringbuffer.h"
#include "datatypes/timedunsigned.h"


class SteAlsAdaptorSysfs : public SysfsAdaptor
{
Q_OBJECT
public:
static DeviceAdaptor* factoryMethod(const QString& id)
{
return new SteAlsAdaptorSysfs(id);
}
SteAlsAdaptorSysfs(const QString& id);
~SteAlsAdaptorSysfs();

bool startSensor();
void stopSensor();

protected:
void processSample(int pathId, int fd);

private:
DeviceAdaptorRingBuffer<TimedUnsigned>* alsBuffer;

QByteArray powerStatePath;
QByteArray powerMode;
};

#endif
39 changes: 39 additions & 0 deletions adaptors/stealsadaptor/stealsadaptor-sysfsplugin.cpp
@@ -0,0 +1,39 @@
/**
@file alsadaptorplugin-sysfs.cpp
@brief Plugin for ALSAdaptorSysfs
<p>
Copyright (C) 2009-2010 Nokia Corporation
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Markus Lehtonen <markus.lehtonen@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 "stealsadaptor-sysfsplugin.h"
#include "stealsadaptor-sysfs.h"
#include "sensormanager.h"
#include "logging.h"

void SteAlsAdaptorSysfsPlugin::Register(class Loader&)
{
sensordLogD() << "registering stealsadaptor";
SensorManager& sm = SensorManager::instance();
sm.registerDeviceAdaptor<SteAlsAdaptorSysfs>("stealsadaptor");
}

Q_EXPORT_PLUGIN2(stealsadaptor, SteAlsAdaptorSysfsPlugin)
38 changes: 38 additions & 0 deletions adaptors/stealsadaptor/stealsadaptor-sysfsplugin.h
@@ -0,0 +1,38 @@
/**
@file alsadaptor-sysfsplugin.h
@brief Plugin for ALSAdaptorSysfs
<p>
Copyright (C) 2009-2010 Nokia Corporation
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Markus Lehtonen <markus.lehtonen@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>
*/

#ifndef STEALSADAPTOR_SYSFSPLUGIN_H
#define STEALSADAPTOR_SYSFSPLUGIN_H

#include "plugin.h"

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

#endif
10 changes: 10 additions & 0 deletions adaptors/stealsadaptor/stealsadaptor.pro
@@ -0,0 +1,10 @@
TEMPLATE = lib
CONFIG += plugin
TARGET = stealsadaptor
HEADERS += stealsadaptor-sysfs.h \
stealsadaptor-sysfsplugin.h

SOURCES += stealsadaptor-sysfs.cpp \
stealsadaptor-sysfsplugin.cpp

include( ../adaptor-config.pri )
2 changes: 1 addition & 1 deletion config/sensord-u8500.conf
Expand Up @@ -30,7 +30,7 @@ calibration_timeout = 60000

[als]
driver_type = 3
mode = 1
mode = 3
seek = 1
path = /sys/bus/i2c/drivers/bh1780/2-0029/lux
powerstate_path = /sys/bus/i2c/drivers/bh1780/2-0029/power_state
Expand Down

0 comments on commit ad05ed1

Please sign in to comment.