Commit 55d96c92 authored by guhl's avatar guhl

[hybris-adaptors] add powerstate_path as parameter to start and stop the sensor

parent 81b717fe
......@@ -22,6 +22,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
#define GRAVITY_RECIPROCAL_THOUSANDS 101.971621298
......@@ -32,6 +33,7 @@ HybrisAccelerometerAdaptor::HybrisAccelerometerAdaptor(const QString& id) :
setAdaptedSensor("accelerometer", "Internal accelerometer coordinates", buffer);
setDescription("Hybris accelerometer");
powerStatePath = Config::configuration()->value("accelerometer/powerstate_path").toByteArray();
// setDefaultInterval(50);
}
......@@ -42,15 +44,18 @@ HybrisAccelerometerAdaptor::~HybrisAccelerometerAdaptor()
bool HybrisAccelerometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
sensordLogD() << "Hybris AccelAdaptor start\n";
return true;
}
void HybrisAccelerometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris AccelAdaptor stop\n";
}
......
......@@ -57,6 +57,7 @@ protected:
private:
DeviceAdaptorRingBuffer<AccelerationData>* buffer;
int sensorType;
QByteArray powerStatePath;
};
#endif
......@@ -25,6 +25,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
#include <fcntl.h>
#include <unistd.h>
......@@ -36,6 +37,7 @@ HybrisAlsAdaptor::HybrisAlsAdaptor(const QString& id) :
buffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1);
setAdaptedSensor("als", "Internal ambient light sensor lux values", buffer);
setDescription("Hybris als");
powerStatePath = Config::configuration()->value("als/powerstate_path").toByteArray();
}
HybrisAlsAdaptor::~HybrisAlsAdaptor()
......@@ -45,6 +47,8 @@ HybrisAlsAdaptor::~HybrisAlsAdaptor()
bool HybrisAlsAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
......@@ -111,6 +115,8 @@ void HybrisAlsAdaptor::sendInitialData()
void HybrisAlsAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris HybrisAlsAdaptor stop\n";
}
......
......@@ -62,6 +62,7 @@ protected:
private:
DeviceAdaptorRingBuffer<TimedUnsigned>* buffer;
unsigned lastLightValue;
QByteArray powerStatePath;
};
#endif
......@@ -22,6 +22,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
#include <math.h>
#define RADIANS_TO_DEGREESECONDS 57295.7795
......@@ -34,6 +35,7 @@ HybrisGyroscopeAdaptor::HybrisGyroscopeAdaptor(const QString& id) :
setAdaptedSensor("gyroscopeadaptor", "Internal gyroscope coordinates", buffer);
setDescription("Hybris gyroscope");
powerStatePath = Config::configuration()->value("gyroscope/powerstate_path").toByteArray();
setDefaultInterval(50);
}
......@@ -44,6 +46,8 @@ HybrisGyroscopeAdaptor::~HybrisGyroscopeAdaptor()
bool HybrisGyroscopeAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
......@@ -53,6 +57,8 @@ bool HybrisGyroscopeAdaptor::startSensor()
void HybrisGyroscopeAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "HybrisGyroscopeAdaptor stop\n";
}
......
......@@ -57,5 +57,7 @@ protected:
private:
DeviceAdaptorRingBuffer<TimedXyzData>* buffer;
int sensorType;
QByteArray powerStatePath;
};
#endif
......@@ -18,11 +18,11 @@
**
****************************************************************************/
#include "config.h"
#include "hybrismagnetometeradaptor.h"
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
HybrisMagnetometerAdaptor::HybrisMagnetometerAdaptor(const QString& id) :
HybrisAdaptor(id,SENSOR_TYPE_MAGNETIC_FIELD)
......@@ -31,6 +31,7 @@ HybrisMagnetometerAdaptor::HybrisMagnetometerAdaptor(const QString& id) :
setAdaptedSensor("magnetometer", "Internal magnetometer coordinates", buffer);
setDescription("Hybris magnetometer");
powerStatePath = Config::configuration()->value("magnetometer/powerstate_path").toByteArray();
//setStandbyOverride(false);
setDefaultInterval(50);
}
......@@ -42,6 +43,8 @@ HybrisMagnetometerAdaptor::~HybrisMagnetometerAdaptor()
bool HybrisMagnetometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
sensordLogD() << "HybrisMagnetometerAdaptor start\n";
......@@ -50,6 +53,8 @@ bool HybrisMagnetometerAdaptor::startSensor()
void HybrisMagnetometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "HybrisMagnetometerAdaptor stop\n";
}
......
......@@ -57,6 +57,7 @@ protected:
private:
DeviceAdaptorRingBuffer<CalibratedMagneticFieldData>* buffer;
int sensorType;
QByteArray powerStatePath;
};
#endif
......@@ -22,6 +22,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
/*
* azimuth: angle between the magnetic north direction and the Y axis, around
......@@ -47,6 +48,7 @@ HybrisOrientationAdaptor::HybrisOrientationAdaptor(const QString& id) :
setAdaptedSensor("hybrisorientation", "Internal orientation coordinates", buffer);
setDescription("Hybris orientation");
powerStatePath = Config::configuration()->value("orientation/powerstate_path").toByteArray();
// setDefaultInterval(50);
}
......@@ -57,6 +59,8 @@ HybrisOrientationAdaptor::~HybrisOrientationAdaptor()
bool HybrisOrientationAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
......@@ -66,6 +70,8 @@ bool HybrisOrientationAdaptor::startSensor()
void HybrisOrientationAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris OrientationAdaptor stop\n";
}
......
......@@ -55,6 +55,7 @@ protected:
private:
DeviceAdaptorRingBuffer<CompassData>* buffer;
int sensorType;
QByteArray powerStatePath;
};
#endif
......@@ -26,6 +26,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
#include <fcntl.h>
#include <unistd.h>
......@@ -38,6 +39,7 @@ HybrisProximityAdaptor::HybrisProximityAdaptor(const QString& id) :
setAdaptedSensor("proximity", "Internal proximity coordinates", buffer);
setDescription("Hybris proximity");
powerStatePath = Config::configuration()->value("proximity/powerstate_path").toByteArray();
}
}
......@@ -50,6 +52,8 @@ HybrisProximityAdaptor::~HybrisProximityAdaptor()
bool HybrisProximityAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
sensordLogD() << "HybrisProximityAdaptor start\n";
......@@ -118,6 +122,8 @@ void HybrisProximityAdaptor::sendInitialData()
void HybrisProximityAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "HybrisProximityAdaptor stop\n";
}
......
......@@ -62,5 +62,7 @@ private:
DeviceAdaptorRingBuffer<ProximityData>* buffer;
int sensorType;
int lastNearValue;
QByteArray powerStatePath;
};
#endif
......@@ -25,6 +25,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
#ifndef SENSOR_TYPE_STEP_COUNTER
#define SENSOR_TYPE_STEP_COUNTER (19)
......@@ -40,6 +41,7 @@ HybrisStepCounterAdaptor::HybrisStepCounterAdaptor(const QString& id) :
buffer = new DeviceAdaptorRingBuffer<TimedUnsigned>(1);
setAdaptedSensor("stepcounter", "Internal step counter steps since reboot", buffer);
setDescription("Hybris step counter");
powerStatePath = Config::configuration()->value("stepcounter/powerstate_path").toByteArray();
}
HybrisStepCounterAdaptor::~HybrisStepCounterAdaptor()
......@@ -49,6 +51,8 @@ HybrisStepCounterAdaptor::~HybrisStepCounterAdaptor()
bool HybrisStepCounterAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
......@@ -63,6 +67,8 @@ void HybrisStepCounterAdaptor::sendInitialData()
void HybrisStepCounterAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris HybrisStepCounterAdaptor stop\n";
}
......
......@@ -64,6 +64,7 @@ protected:
private:
DeviceAdaptorRingBuffer<TimedUnsigned>* buffer;
QByteArray powerStatePath;
};
#endif
......@@ -549,6 +549,25 @@ unsigned int HybrisAdaptor::evaluateIntervalRequests(int& sessionId) const
return highestValue > 0 ? highestValue : defaultInterval();
}
bool HybrisAdaptor::writeToFile(const QByteArray& path, const QByteArray& content)
{
sensordLogT() << "Writing to '" << path << ": " << content;
QFile file(path);
if (!file.open(QIODevice::WriteOnly))
{
sensordLogW() << "Failed to open '" << path << "': " << file.errorString();
return false;
}
if (file.write(content.constData(), content.size()) == -1) {
sensordLogW() << "Failed to write to '" << path << "': " << file.errorString();
file.close();
return false;
}
file.close();
return true;
}
/*/////////////////////////////////////////////////////////////////////
/// \brief HybrisAdaptorReader::HybrisAdaptorReader
/// \param parent
......
......@@ -24,6 +24,7 @@
#include <QObject>
#include <QThread>
#include <QTimer>
#include <QFile>
#include "deviceadaptor.h"
#include <hardware/sensors.h>
......@@ -130,6 +131,7 @@ protected:
virtual unsigned int interval() const;
virtual bool setInterval(const unsigned int value, const int sessionId);
virtual unsigned int evaluateIntervalRequests(int& sessionId) const;
static bool writeToFile(const QByteArray& path, const QByteArray& content);
private:
void stopReaderThread();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment