Skip to content

Commit

Permalink
magenetometeradaptor for ncdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Shenghua committed Feb 9, 2011
1 parent 5b91d2d commit e4244d8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions adaptors/adaptors.pro
Expand Up @@ -9,6 +9,7 @@ SUBDIRS = alsadaptor \
accelerometeradaptor \
magnetometeradaptor \
magnetometeradaptor-ascii \
magnetometeradaptor-ncdk \
touchadaptor \
kbslideradaptor \
proximityadaptor \
Expand Down
6 changes: 4 additions & 2 deletions adaptors/magnetometeradaptor/magnetometeradaptor.pro
@@ -1,9 +1,11 @@
TARGET = magnetometeradaptor

HEADERS += magnetometeradaptor.h \
magnetometeradaptorplugin.h
magnetometeradaptorplugin.h \


SOURCES += magnetometeradaptor.cpp \
magnetometeradaptorplugin.cpp
magnetometeradaptorplugin.cpp \


include( ../adaptor-config.pri )
2 changes: 2 additions & 0 deletions config/sensord-ncdk.conf
Expand Up @@ -24,6 +24,8 @@ dataranges = "0=>4096"

[magnetometer]
path = /dev/ak89750
path_power_state = /sys/devices/power_state
path_sens_adjust = /sys/devices/sens_adjust
dataranges = "-4096=>4096"
intervals = "25=>1000"
default_interval = 1000
Expand Down
20 changes: 3 additions & 17 deletions core/inputdevadaptor.cpp
Expand Up @@ -159,31 +159,16 @@ bool InputDevAdaptor::checkInputDevice(const QString& path, const QString& match
return check;
}

bool InputDevAdaptor::openPollFile(QFile& pollFile, QIODevice::OpenMode mode) const
{
pollFile.setFileName(usedDevicePollFilePath_);
if (!(pollFile.exists() && pollFile.open(mode))) {
sensordLogW() << "Unable to locate poll interval setting for " << deviceString_;
return false;
}
return true;
}

unsigned int InputDevAdaptor::interval() const
{
if (deviceNumber_ < 0) {
return -1;
}

QFile pollFile;
if(!openPollFile(pollFile, QIODevice::ReadOnly))
return 0;

char buf[16];
if (pollFile.readLine(buf, sizeof(buf)) > 0) {
return QString(buf).toUInt();
}
return 0;
QString str = readFromFile(usedDevicePollFilePath_, buf);
return str.isEmpty() ? 0 : str.toUInt();
}

bool InputDevAdaptor::setInterval(const unsigned int value, const int sessionId)
Expand All @@ -203,6 +188,7 @@ bool InputDevAdaptor::setInterval(const unsigned int value, const int sessionId)
return false;
}
return true;

}

void InputDevAdaptor::init()
Expand Down
3 changes: 0 additions & 3 deletions core/inputdevadaptor.h
Expand Up @@ -32,7 +32,6 @@
#include "sysfsadaptor.h"
#include <QString>
#include <QStringList>
#include <QFile>
#include <linux/input.h>
#include "filterproperty.h"

Expand Down Expand Up @@ -111,8 +110,6 @@ class InputDevAdaptor : public SysfsAdaptor {
*/
int getEvents(int fd);

bool openPollFile(QFile& pollFile, QIODevice::OpenMode mode) const;

QString deviceSysPathString_;
QString devicePollFilePath_;
QString usedDevicePollFilePath_;
Expand Down
22 changes: 22 additions & 0 deletions core/sysfsadaptor.cpp
Expand Up @@ -349,6 +349,28 @@ bool SysfsAdaptor::writeToFile(QString path, QString content)
return true;
}

bool SysfsAdaptor::openPollFile(QFile& pollFile, QIODevice::OpenMode mode) const
{
if (!(pollFile.exists() && pollFile.open(mode)))
{
sensordLogW() << "Unable to locate poll interval setting for " << deviceString_;
return false;
}
return true;
}

QString SysfsAdaptor::readFromFile(QString path, char* buf)
{
QFile pollFile;
pollFile.setFileName(path);
if(!openPollFile(pollFile, QIODevice::ReadOnly) && pollFile.readLine(buf, sizeof(buf)) > 0)
{
return QString(buf);
}

return QString();
}

void SysfsAdaptor::dataAvailable(int pathId, int fd)
{
processSample(pathId, fd);
Expand Down
13 changes: 13 additions & 0 deletions core/sysfsadaptor.h
Expand Up @@ -35,6 +35,7 @@
#include <QThread>
#include "filterproperty.h"
#include <QMutex>
#include <QFile>

class SysfsAdaptor;

Expand Down Expand Up @@ -165,6 +166,18 @@ protected slots:
*/
virtual unsigned int interval() const;

/**
* Utility function for reading data from files.
* parameters
*
* @param path Path of the file to read from
* @param buf Buffer for data read
* @return resultant read data string.
*/
QString readFromFile(QString path, char* buf);

QString openPollFile(QFile& pollFile, QIODevice::OpenMode mode) const;

/**
* Sets the interval for the adaptor. This function is valid for
* adaptors using PollMode. It just sets the number of milliseconds
Expand Down

0 comments on commit e4244d8

Please sign in to comment.