Hi Timo,
I modified the adaptors as you suggested, and removed the
setStandbyOverride function. All of the sensor drivers on Medfield can
output data correctly when the screen is blanked.

Magnetometer adaptor is also added. It seems that libcompasschain.so is
needed when testing the magnetometer in clientapitest, where can I get
it?

Please check all of them~:)~

Thanks,
Leo Yan


On Thu, 2010-09-16 at 19:35 +0800, Rongas Timo wrote:
> >-----Original Message-----
> >From: Yan Leo [mailto:[email protected]] 
> >Sent: Thursday, September 16, 2010 5:55 AM
> >To: Rongas Timo
> >Cc: [email protected]
> >Subject: [patch] ALS and Proximity Adaptors of sensor 
> >framework on Medfield
> >
> >Hi Timo,
> >I think we can use the basic input device
> >accelerometer(adaptors/accelerometeradaptor) on Medfield.
> >
> >Here are the patches for ALS and Proximity. Both of them are different
> >from the basic adaptors because of the output format of driver.Please
> >check and give your opinion.
> 
> Hi Leo,
> 
> These look good! I actually think that these can be generalised for use by 
> others as well. If possible, could you do the following modifications please:
> 
> * Rename from mfldXXadaptor to XXadaptor-ascii. If another driver with ascii 
> interface appears, these plugins can probably be patched to support both. We 
> came up with this <pluginname>-<interfacetype>-[<additional detail>] naming 
> scheme a while back, but I haven't written it down anywhere yet.
> 
> * Add LGPL disclaimer (copy from any other file and place your credentials 
> there)
> 
> * Use smaller buffersize. This is an evolving issue, but having a buffer of 
> e.g. 16 samples should be more than enough for proximity and als. Perhaps 
> this gets automatic someday.
> 
> * Use sensordLog<T|D|W|C>() for errors. I would consider being unable to open 
> a driver interface worth a warning. I know, our code might be slacky on this 
> in parts as well, but I can try to prevent any new qDebugs() from seeping in 
> ;)
> 
> * Please use spaces for indent (not tabs)
> 
> * This final point is actually something that should be turned into a 
> configuration option (more of a note than request, my job to implement):
> 
> Can your drivers provide sane data when the display is blanked? In both 
> adaptors, you have overwritten the default setStandbyOverride() to always 
> reject requests to keep sensors on while display is off. I think you should 
> allow (*crossing fingers for users thinking about power saving*) users to 
> keep the sensors on with display off, if it's possible. For various reasons, 
> the "default" als adaptor does not allow display off usage.
> 
> But as said, that should be turned into option, so the same plugin could use 
> different behavior upon different drivers. 
> 
> Providing these as generic plugins for cases where data is read as ascii 
> might need some more stuff (paths etc) to go into config file. But those mods 
> can be done when the need arises.
> 
> Thank you!
> 
> // Timo
> 

diff --git a/adaptors/adaptors.pro b/adaptors/adaptors.pro
index efb4bbf..d922ad3 100644
--- a/adaptors/adaptors.pro
+++ b/adaptors/adaptors.pro
@@ -5,6 +5,7 @@ include( ../common-config.pri )
 internal {
     SUBDIRS = alsadaptor \
               alsadaptor-sysfs \
+              alsadaptor-ascii \
               tapadaptor \
               accelerometeradaptor \
               magnetometeradaptor \
diff --git a/adaptors/alsadaptor-ascii/alsadaptor-ascii.cpp b/adaptors/alsadaptor-ascii/alsadaptor-ascii.cpp
new file mode 100644
index 0000000..b490d62
--- /dev/null
+++ b/adaptors/alsadaptor-ascii/alsadaptor-ascii.cpp
@@ -0,0 +1,94 @@
+/**
+   @file alsadaptor-ascii.cpp
+   @brief ALSAdaptor that reads lux value from ascii interface
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 <fcntl.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include "logging.h"
+#include "config.h"
+#include "alsadaptor-ascii.h"
+#include "filters/utils.h"
+
+#define SYSFS_RANGE_PATH "/sys/bus/i2c/devices/5-0029/apds9802als/sensing_range"
+#define SYSFS_LUX_PATH	"/sys/bus/i2c/devices/5-0029/apds9802als/lux_output"
+
+ALSAdaptorAscii::ALSAdaptorAscii(const QString& id) : SysfsAdaptor(id, SysfsAdaptor::IntervalMode)
+{
+    int fd, range;
+
+    fd = open(SYSFS_RANGE_PATH, O_RDONLY);
+    if (fd < 0) {
+        sensordLogW() << "open():" << strerror(errno);
+        return;
+    }
+    if (read(fd, buf, sizeof(buf)) <= 0) {
+        sensordLogW() << "read():" << strerror(errno);
+        close(fd);
+        return;
+    }
+    close(fd);
+
+    sscanf(buf, "%d", &range);
+    introduceAvailableDataRange(DataRange(0, range, 1));
+    sensordLogT() << "Ambient light range: " << range;
+
+    devId = 0;
+    addPath(SYSFS_LUX_PATH, devId);
+    alsBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(16);
+    addAdaptedSensor("als", "apds9802als ascii", alsBuffer_);
+}
+
+ALSAdaptorAscii::~ALSAdaptorAscii()
+{
+    delete alsBuffer_;
+}
+
+void ALSAdaptorAscii::processSample(int pathId, int fd)
+{
+    if (pathId != devId) {
+        sensordLogW() << "pathId != devId";
+        return;
+    }
+
+    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();
+}
diff --git a/adaptors/alsadaptor-ascii/alsadaptor-ascii.h b/adaptors/alsadaptor-ascii/alsadaptor-ascii.h
new file mode 100644
index 0000000..8ff4a86
--- /dev/null
+++ b/adaptors/alsadaptor-ascii/alsadaptor-ascii.h
@@ -0,0 +1,62 @@
+/**
+   @file alsadaptor-ascii.h
+   @brief ALSAdaptor that reads lux value from ascii interface
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 ALSADAPTOR_ASCII_H
+#define ALSADAPTOR_ASCII_H
+
+#include "sysfsadaptor.h"
+#include "sensord/deviceadaptorringbuffer.h"
+#include "filters/timedunsigned.h"
+#include <QTime>
+
+
+class ALSAdaptorAscii : public SysfsAdaptor
+{
+    Q_OBJECT;
+public:
+    static DeviceAdaptor* factoryMethod(const QString& id)
+    {
+        return new ALSAdaptorAscii(id);
+    }
+
+protected:
+    ALSAdaptorAscii(const QString& id);
+    ~ALSAdaptorAscii();
+
+private:
+    void processSample(int pathId, int fd);
+    int devId;
+    char buf[16];
+
+    DeviceAdaptorRingBuffer<TimedUnsigned>* alsBuffer_;
+};
+
+#endif
+
diff --git a/adaptors/alsadaptor-ascii/alsadaptor-ascii.pro b/adaptors/alsadaptor-ascii/alsadaptor-ascii.pro
new file mode 100644
index 0000000..4c2fcb1
--- /dev/null
+++ b/adaptors/alsadaptor-ascii/alsadaptor-ascii.pro
@@ -0,0 +1,27 @@
+TEMPLATE     = lib
+CONFIG      += plugin
+
+TARGET       = alsadaptor-ascii
+
+include( ../../common-config.pri )
+
+HEADERS += alsadaptor-ascii.h \
+           alsadaptor-asciiplugin.h
+
+SOURCES += alsadaptor-ascii.cpp \
+           alsadaptor-asciiplugin.cpp
+
+SENSORFW_INCLUDEPATHS = ../.. \
+                        ../../include \
+                        ../../sensord \
+                        ../../datatypes \
+                        ../../filters
+
+DEPENDPATH  += $$SENSORFW_INCLUDEPATHS
+INCLUDEPATH += $$SENSORFW_INCLUDEPATHS
+
+include(../../common-install.pri)
+publicheaders.files += $$HEADERS
+target.path = $$PLUGINPATH
+
+INSTALLS += target
diff --git a/adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.cpp b/adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.cpp
new file mode 100644
index 0000000..13973ae
--- /dev/null
+++ b/adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.cpp
@@ -0,0 +1,43 @@
+/**
+   @file alsadaptor-asciiplugin.cpp
+   @brief Plugin for ALSAdaptorAscii
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 "alsadaptor-asciiplugin.h"
+#include "alsadaptor-ascii.h"
+#include "sensormanager.h"
+
+void ALSAdaptorAsciiPlugin::Register(class Loader&)
+{
+    sensordLogW() << "registering alsadaptor-ascii";
+    SensorManager& sm = SensorManager::instance();
+    sm.registerDeviceAdaptor<ALSAdaptorAscii>("alsadaptor");
+}
+
+Q_EXPORT_PLUGIN2(alsadaptor, ALSAdaptorAsciiPlugin)
+
diff --git a/adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.h b/adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.h
new file mode 100644
index 0000000..5f22792
--- /dev/null
+++ b/adaptors/alsadaptor-ascii/alsadaptor-asciiplugin.h
@@ -0,0 +1,42 @@
+/**
+   @file alsadaptor-asciiplugin.h
+   @brief Plugin for ALSAdaptorAscii
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 ALSADAPTOR_ASCIIPLUGIN_H
+#define ALSADAPTOR_ASCIIPLUGIN_H
+
+#include "plugin.h"
+
+class ALSAdaptorAsciiPlugin : public Plugin
+{
+private: 
+    void Register(class Loader& l);
+};
+
+#endif
diff --git a/adaptors/adaptors.pro b/adaptors/adaptors.pro
index efb4bbf..5264ef1 100644
--- a/adaptors/adaptors.pro
+++ b/adaptors/adaptors.pro
@@ -8,6 +8,7 @@ internal {
               tapadaptor \
               accelerometeradaptor \
               magnetometeradaptor \
+              magnetometeradaptor-ascii \
               touchadaptor \
               kbslideradaptor \
               proximityadaptor \
diff --git a/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.cpp b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.cpp
new file mode 100644
index 0000000..69d4c68
--- /dev/null
+++ b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.cpp
@@ -0,0 +1,83 @@
+/**
+   @file magnetometeradaptor-ascii.cpp
+   @brief MagnetometerAdaptor that reads magnetic value in X-axis, Y-axis, and Z-axis from ascii interface
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 <errno.h>
+#include "logging.h"
+#include "config.h"
+#include "magnetometeradaptor-ascii.h"
+#include "filters/utils.h"
+
+#define SYSFS_MAGNET_PATH "/sys/bus/i2c/devices/5-000f/ak8974/curr_pos"
+
+MagnetometerAdaptorAscii::MagnetometerAdaptorAscii(const QString& id) : 
+    SysfsAdaptor(id, SysfsAdaptor::IntervalMode)
+{
+    if (access(SYSFS_MAGNET_PATH, R_OK) < 0) {
+        sensordLogW() << SYSFS_MAGNET_PATH << ": "<< strerror(errno);
+        return;
+    }
+    introduceAvailableDataRange(DataRange(-2048, 2048, 1));
+    devId = 0;
+    addPath(SYSFS_MAGNET_PATH, devId);
+    magnetBuffer_ = new DeviceAdaptorRingBuffer<TimedXyzData>(16);
+    addAdaptedSensor("magnetometer", "ak8974 ascii", magnetBuffer_);
+}
+
+MagnetometerAdaptorAscii::~MagnetometerAdaptorAscii()
+{
+    delete magnetBuffer_;
+}
+
+void MagnetometerAdaptorAscii::processSample(int pathId, int fd)
+{
+    unsigned short x, y, z;
+
+    if (pathId != devId) {
+        sensordLogW() << "pathId != devId";
+        return;
+    }
+    lseek(fd, 0, SEEK_SET);
+    if (read(fd, buf, sizeof(buf)) <= 0) {
+        sensordLogW() << "read():" << strerror(errno);
+        return;
+    }
+    sensordLogT() << "Magnetometer output value: " << buf;
+
+    sscanf(buf, "%hx:%hx:%hx\n", &x, &y, &z);
+
+    TimedXyzData* pos = magnetBuffer_->nextSlot();
+    pos->x_ = (short)x;
+    pos->y_ = (short)y;
+    pos->z_ = (short)z;
+    pos->timestamp_ = Utils::getTimeStamp();
+
+    magnetBuffer_->commit();
+    magnetBuffer_->wakeUpReaders();
+}
diff --git a/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.h b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.h
new file mode 100644
index 0000000..507e4cd
--- /dev/null
+++ b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.h
@@ -0,0 +1,61 @@
+/**
+   @file magnetometeradaptor-ascii.h
+   @brief MagnetometerAdaptor that reads magnetic value in X-axis, Y-axis, and Z-axis from ascii interface
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 MAGNETOMETERADAPTOR_ASCII_H
+#define MAGNETOMETERADAPTOR_ASCII_H
+
+#include "sysfsadaptor.h"
+#include "sensord/deviceadaptorringbuffer.h"
+#include "filters/timedunsigned.h"
+#include <QTime>
+
+class MagnetometerAdaptorAscii : public SysfsAdaptor
+{
+    Q_OBJECT;
+public:
+    static DeviceAdaptor* factoryMethod(const QString& id)
+    {
+        return new MagnetometerAdaptorAscii(id);
+    }
+
+protected:
+    MagnetometerAdaptorAscii(const QString& id);
+    ~MagnetometerAdaptorAscii();
+
+private:
+    void processSample(int pathId, int fd);
+    int devId;
+    char buf[32];
+
+    DeviceAdaptorRingBuffer<TimedXyzData>* magnetBuffer_;
+};
+
+#endif
+
diff --git a/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.pro b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.pro
new file mode 100644
index 0000000..cedbc80
--- /dev/null
+++ b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-ascii.pro
@@ -0,0 +1,27 @@
+TEMPLATE     = lib
+CONFIG      += plugin
+
+TARGET       = magnetometeradaptor-ascii
+
+include( ../../common-config.pri )
+
+HEADERS += magnetometeradaptor-ascii.h \
+           magnetometeradaptor-asciiplugin.h
+
+SOURCES += magnetometeradaptor-ascii.cpp \
+           magnetometeradaptor-asciiplugin.cpp
+
+SENSORFW_INCLUDEPATHS = ../.. \
+                        ../../include \
+                        ../../sensord \
+                        ../../datatypes \
+                        ../../filters
+
+DEPENDPATH  += $$SENSORFW_INCLUDEPATHS
+INCLUDEPATH += $$SENSORFW_INCLUDEPATHS
+
+include(../../common-install.pri)
+publicheaders.files += $$HEADERS
+target.path = $$PLUGINPATH
+
+INSTALLS += target
diff --git a/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-asciiplugin.cpp b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-asciiplugin.cpp
new file mode 100644
index 0000000..e3d5a2e
--- /dev/null
+++ b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-asciiplugin.cpp
@@ -0,0 +1,42 @@
+/**
+   @file magnetometeradaptor-asciiplugin.cpp
+   @brief plugin for MagnetometerAdaptorAscii
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 "magnetometeradaptor-asciiplugin.h"
+#include "magnetometeradaptor-ascii.h"
+#include "sensormanager.h"
+
+void MagnetometerAdaptorAsciiPlugin::Register(class Loader&)
+{
+    sensordLogW() << "registering MagnetometerAdaptorAscii";
+    SensorManager& sm = SensorManager::instance();
+    sm.registerDeviceAdaptor<MagnetometerAdaptorAscii>("magnetometeradaptor");
+}
+
+Q_EXPORT_PLUGIN2(magnetometeradaptor, MagnetometerAdaptorAsciiPlugin)
diff --git a/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-asciiplugin.h b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-asciiplugin.h
new file mode 100644
index 0000000..0d9b76b
--- /dev/null
+++ b/adaptors/magnetometeradaptor-ascii/magnetometeradaptor-asciiplugin.h
@@ -0,0 +1,42 @@
+/**
+   @file magnetometeradaptor-asciiplugin.h
+   @brief plugin for MagnetometerAdaptorAscii
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 MAGNETOMETERADAPTOR_ASCII_PLUGIN_H
+#define MAGNETOMETERADAPTOR_ASCII_PLUGIN_H
+
+#include "plugin.h"
+
+class MagnetometerAdaptorAsciiPlugin : public Plugin
+{
+private:
+    void Register(class Loader& l);
+};
+
+#endif
diff --git a/adaptors/adaptors.pro b/adaptors/adaptors.pro
index efb4bbf..40b658d 100644
--- a/adaptors/adaptors.pro
+++ b/adaptors/adaptors.pro
@@ -12,5 +12,6 @@ internal {
               kbslideradaptor \
               proximityadaptor \
               proximityadaptor-evdev \
+              proximityadaptor-ascii \
               mrstaccelerometer
 }
diff --git a/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.cpp b/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.cpp
new file mode 100644
index 0000000..409807c
--- /dev/null
+++ b/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.cpp
@@ -0,0 +1,77 @@
+/**
+   @file proximityadaptor-ascii.cpp
+   @brief ProximityAdaptor that reads proximity value from ascii interface
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 <errno.h>
+#include "logging.h"
+#include "config.h"
+#include "proximityadaptor-ascii.h"
+#include "filters/utils.h"
+
+#define SYSFS_PROXIMITY_PATH "/sys/bus/i2c/devices/5-0055/apds9802ps/proximity_output"
+
+ProximityAdaptorAscii::ProximityAdaptorAscii(const QString& id) : 
+                        SysfsAdaptor(id, SysfsAdaptor::IntervalMode)
+{
+    if (access(SYSFS_PROXIMITY_PATH, R_OK) < 0) {
+        sensordLogW() << SYSFS_PROXIMITY_PATH << ": "<< strerror(errno);
+        return;
+    }
+    introduceAvailableDataRange(DataRange(0, 4096, 1));
+    devId = 0;
+    addPath(SYSFS_PROXIMITY_PATH, devId);
+    proximityBuffer_ = new DeviceAdaptorRingBuffer<TimedUnsigned>(16);
+    addAdaptedSensor("proximity", "apds9802ps ascii", proximityBuffer_);
+}
+
+ProximityAdaptorAscii::~ProximityAdaptorAscii()
+{
+    delete proximityBuffer_;
+}
+
+void ProximityAdaptorAscii::processSample(int pathId, int fd)
+{
+    if (pathId != devId) {
+        sensordLogW() << "pathId != devId";
+        return;
+    }
+    lseek(fd, 0, SEEK_SET);
+    if (read(fd, buf, sizeof(buf)) <= 0) {
+        sensordLogW() << "read():" << strerror(errno);
+        return;
+    }
+    sensordLogT() << "Proximity output value: " << buf;
+
+    TimedUnsigned* proximity = proximityBuffer_->nextSlot();
+    sscanf(buf, "%d", &proximity->value_);
+
+    proximity->timestamp_ = Utils::getTimeStamp();
+    proximityBuffer_->commit();
+    proximityBuffer_->wakeUpReaders();
+}
diff --git a/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.h b/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.h
new file mode 100644
index 0000000..31dacd4
--- /dev/null
+++ b/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.h
@@ -0,0 +1,62 @@
+/**
+   @file proximityadaptor-ascii.h
+   @brief ProximityAdaptor that reads proximity value from ascii interface
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 PROXIMITYADAPTOR_ASCII_H
+#define PROXIMITYADAPTOR_ASCII_H
+
+#include "sysfsadaptor.h"
+#include "sensord/deviceadaptorringbuffer.h"
+#include "filters/timedunsigned.h"
+#include <QTime>
+
+
+class ProximityAdaptorAscii : public SysfsAdaptor
+{
+    Q_OBJECT;
+public:
+    static DeviceAdaptor* factoryMethod(const QString& id)
+    {
+        return new ProximityAdaptorAscii(id);
+    }
+
+protected:
+    ProximityAdaptorAscii(const QString& id);
+    ~ProximityAdaptorAscii();
+
+private:
+    void processSample(int pathId, int fd);
+    int devId;
+    char buf[16];
+
+    DeviceAdaptorRingBuffer<TimedUnsigned>* proximityBuffer_;
+};
+
+#endif
+
diff --git a/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.pro b/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.pro
new file mode 100644
index 0000000..03ff412
--- /dev/null
+++ b/adaptors/proximityadaptor-ascii/proximityadaptor-ascii.pro
@@ -0,0 +1,27 @@
+TEMPLATE     = lib
+CONFIG      += plugin
+
+TARGET       = proximityadaptor-ascii
+
+include( ../../common-config.pri )
+
+HEADERS += proximityadaptor-ascii.h \
+           proximityadaptor-asciiplugin.h
+
+SOURCES += proximityadaptor-ascii.cpp \
+           proximityadaptor-asciiplugin.cpp
+
+SENSORFW_INCLUDEPATHS = ../.. \
+                        ../../include \
+                        ../../sensord \
+                        ../../datatypes \
+                        ../../filters
+
+DEPENDPATH  += $$SENSORFW_INCLUDEPATHS
+INCLUDEPATH += $$SENSORFW_INCLUDEPATHS
+
+include(../../common-install.pri)
+publicheaders.files += $$HEADERS
+target.path = $$PLUGINPATH
+
+INSTALLS += target
diff --git a/adaptors/proximityadaptor-ascii/proximityadaptor-asciiplugin.cpp b/adaptors/proximityadaptor-ascii/proximityadaptor-asciiplugin.cpp
new file mode 100644
index 0000000..7e952c0
--- /dev/null
+++ b/adaptors/proximityadaptor-ascii/proximityadaptor-asciiplugin.cpp
@@ -0,0 +1,42 @@
+/**
+   @file proximityadaptor-asciiplugin.cpp
+   @brief plugin for ProximityAdaptorAscii
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 "proximityadaptor-asciiplugin.h"
+#include "proximityadaptor-ascii.h"
+#include "sensormanager.h"
+
+void ProximityAdaptorAsciiPlugin::Register(class Loader&)
+{
+    sensordLogW() << "registering proximityadaptor-ascii";
+    SensorManager& sm = SensorManager::instance();
+    sm.registerDeviceAdaptor<ProximityAdaptorAscii>("proximityadaptor");
+}
+
+Q_EXPORT_PLUGIN2(proximityadaptor, ProximityAdaptorAsciiPlugin)
diff --git a/adaptors/proximityadaptor-ascii/proximityadaptor-asciiplugin.h b/adaptors/proximityadaptor-ascii/proximityadaptor-asciiplugin.h
new file mode 100644
index 0000000..8a6232e
--- /dev/null
+++ b/adaptors/proximityadaptor-ascii/proximityadaptor-asciiplugin.h
@@ -0,0 +1,42 @@
+/**
+   @file proximityadaptor-asciiplugin.cpp
+   @brief plugin for ProximityAdaptorAscii
+
+   <p>
+   Copyright (C) 2009-2010 Intel Corporation
+   Copyright (C) 2009-2010 Nokia Corporation
+
+   @author Leo Yan <[email protected]>
+   @author Timo Rongas <[email protected]>
+   @author Ustun Ergenoglu <[email protected]>
+   @author Matias Muhonen <[email protected]>
+   @author Tapio Rantala <[email protected]>
+
+   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 PROXIMITYADAPTOR_ASCII_PLUGIN_H
+#define PROXIMITYADAPTOR_ASCII_PLUGIN_H
+
+#include "plugin.h"
+
+class ProximityAdaptorAsciiPlugin : public Plugin
+{
+private:
+    void Register(class Loader& l);
+};
+
+#endif
_______________________________________________
MeeGo-dev mailing list
[email protected]
http://lists.meego.com/listinfo/meego-dev

Reply via email to