Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
7 changed files
with
251 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters