Skip to content

Commit

Permalink
Merge branch 'master' into 'master'
Browse files Browse the repository at this point in the history
[hybris-adaptors] add powerstate_path as parameter to start and stop the sensor

The startSensor and stopSensor methods in hybrisa-adaptors fail to start/stop the sensors on the devices thea and titan. They can be started/stoped using the enable file.

This change implements the powerstate_path as a parameter in the config file to start/stop the device using the same logic as in the sysfssensor based adaptors.

See merge request !14
  • Loading branch information
spiiroin committed Feb 14, 2017
2 parents 81b717f + 3be1fc4 commit 2557bcf
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 1 deletion.
6 changes: 6 additions & 0 deletions adaptors/hybrisaccelerometer/hybrisaccelerometeradaptor.cpp
Expand Up @@ -22,6 +22,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"

#define GRAVITY_RECIPROCAL_THOUSANDS 101.971621298

Expand All @@ -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);
}

Expand All @@ -42,6 +44,8 @@ HybrisAccelerometerAdaptor::~HybrisAccelerometerAdaptor()

bool HybrisAccelerometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

Expand All @@ -51,6 +55,8 @@ bool HybrisAccelerometerAdaptor::startSensor()

void HybrisAccelerometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris AccelAdaptor stop\n";
}
Expand Down
1 change: 1 addition & 0 deletions adaptors/hybrisaccelerometer/hybrisaccelerometeradaptor.h
Expand Up @@ -57,6 +57,7 @@ class HybrisAccelerometerAdaptor : public HybrisAdaptor
private:
DeviceAdaptorRingBuffer<AccelerationData>* buffer;
int sensorType;
QByteArray powerStatePath;

};
#endif
11 changes: 11 additions & 0 deletions adaptors/hybrisalsadaptor/hybrisalsadaptor.cpp
Expand Up @@ -25,6 +25,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"

#include <fcntl.h>
#include <unistd.h>
Expand All @@ -36,6 +37,12 @@ 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();
if (!powerStatePath.isEmpty() && !QFile::exists(powerStatePath))
{
sensordLogW() << "Path does not exists: " << powerStatePath;
powerStatePath.clear();
}
}

HybrisAlsAdaptor::~HybrisAlsAdaptor()
Expand All @@ -45,6 +52,8 @@ HybrisAlsAdaptor::~HybrisAlsAdaptor()

bool HybrisAlsAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

Expand Down Expand Up @@ -111,6 +120,8 @@ void HybrisAlsAdaptor::sendInitialData()

void HybrisAlsAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris HybrisAlsAdaptor stop\n";
}
Expand Down
1 change: 1 addition & 0 deletions adaptors/hybrisalsadaptor/hybrisalsadaptor.h
Expand Up @@ -62,6 +62,7 @@ class HybrisAlsAdaptor : public HybrisAdaptor
private:
DeviceAdaptorRingBuffer<TimedUnsigned>* buffer;
unsigned lastLightValue;
QByteArray powerStatePath;

};
#endif
11 changes: 11 additions & 0 deletions adaptors/hybrisgyroscopeadaptor/hybrisgyroscopeadaptor.cpp
Expand Up @@ -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
Expand All @@ -34,6 +35,12 @@ HybrisGyroscopeAdaptor::HybrisGyroscopeAdaptor(const QString& id) :
setAdaptedSensor("gyroscopeadaptor", "Internal gyroscope coordinates", buffer);

setDescription("Hybris gyroscope");
powerStatePath = Config::configuration()->value("gyroscope/powerstate_path").toByteArray();
if (!powerStatePath.isEmpty() && !QFile::exists(powerStatePath))
{
sensordLogW() << "Path does not exists: " << powerStatePath;
powerStatePath.clear();
}
setDefaultInterval(50);
}

Expand All @@ -44,6 +51,8 @@ HybrisGyroscopeAdaptor::~HybrisGyroscopeAdaptor()

bool HybrisGyroscopeAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

Expand All @@ -53,6 +62,8 @@ bool HybrisGyroscopeAdaptor::startSensor()

void HybrisGyroscopeAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "HybrisGyroscopeAdaptor stop\n";
}
Expand Down
2 changes: 2 additions & 0 deletions adaptors/hybrisgyroscopeadaptor/hybrisgyroscopeadaptor.h
Expand Up @@ -57,5 +57,7 @@ class HybrisGyroscopeAdaptor : public HybrisAdaptor
private:
DeviceAdaptorRingBuffer<TimedXyzData>* buffer;
int sensorType;
QByteArray powerStatePath;

};
#endif
13 changes: 12 additions & 1 deletion adaptors/hybrismagnetometeradaptor/hybrismagnetometeradaptor.cpp
Expand Up @@ -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)
Expand All @@ -31,6 +31,12 @@ HybrisMagnetometerAdaptor::HybrisMagnetometerAdaptor(const QString& id) :
setAdaptedSensor("magnetometer", "Internal magnetometer coordinates", buffer);

setDescription("Hybris magnetometer");
powerStatePath = Config::configuration()->value("magnetometer/powerstate_path").toByteArray();
if (!powerStatePath.isEmpty() && !QFile::exists(powerStatePath))
{
sensordLogW() << "Path does not exists: " << powerStatePath;
powerStatePath.clear();
}
//setStandbyOverride(false);
setDefaultInterval(50);
}
Expand All @@ -42,14 +48,19 @@ HybrisMagnetometerAdaptor::~HybrisMagnetometerAdaptor()

bool HybrisMagnetometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

sensordLogD() << "HybrisMagnetometerAdaptor start\n";
return true;
}

void HybrisMagnetometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "HybrisMagnetometerAdaptor stop\n";
}
Expand Down
Expand Up @@ -57,6 +57,7 @@ class HybrisMagnetometerAdaptor : public HybrisAdaptor
private:
DeviceAdaptorRingBuffer<CalibratedMagneticFieldData>* buffer;
int sensorType;
QByteArray powerStatePath;

};
#endif
11 changes: 11 additions & 0 deletions adaptors/hybrisorientationadaptor/hybrisorientationadaptor.cpp
Expand Up @@ -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
Expand All @@ -47,6 +48,12 @@ HybrisOrientationAdaptor::HybrisOrientationAdaptor(const QString& id) :
setAdaptedSensor("hybrisorientation", "Internal orientation coordinates", buffer);

setDescription("Hybris orientation");
powerStatePath = Config::configuration()->value("orientation/powerstate_path").toByteArray();
if (!powerStatePath.isEmpty() && !QFile::exists(powerStatePath))
{
sensordLogW() << "Path does not exists: " << powerStatePath;
powerStatePath.clear();
}
// setDefaultInterval(50);
}

Expand All @@ -57,6 +64,8 @@ HybrisOrientationAdaptor::~HybrisOrientationAdaptor()

bool HybrisOrientationAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

Expand All @@ -66,6 +75,8 @@ bool HybrisOrientationAdaptor::startSensor()

void HybrisOrientationAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris OrientationAdaptor stop\n";
}
Expand Down
Expand Up @@ -55,6 +55,7 @@ class HybrisOrientationAdaptor : public HybrisAdaptor
private:
DeviceAdaptorRingBuffer<CompassData>* buffer;
int sensorType;
QByteArray powerStatePath;

};
#endif
11 changes: 11 additions & 0 deletions adaptors/hybrisproximityadaptor/hybrisproximityadaptor.cpp
Expand Up @@ -26,6 +26,7 @@
#include "logging.h"
#include "datatypes/utils.h"
#include <hardware/sensors.h>
#include "config.h"
#include <fcntl.h>
#include <unistd.h>

Expand All @@ -38,6 +39,12 @@ HybrisProximityAdaptor::HybrisProximityAdaptor(const QString& id) :
setAdaptedSensor("proximity", "Internal proximity coordinates", buffer);

setDescription("Hybris proximity");
powerStatePath = Config::configuration()->value("proximity/powerstate_path").toByteArray();
if (!powerStatePath.isEmpty() && !QFile::exists(powerStatePath))
{
sensordLogW() << "Path does not exists: " << powerStatePath;
powerStatePath.clear();
}
}
}

Expand All @@ -50,6 +57,8 @@ HybrisProximityAdaptor::~HybrisProximityAdaptor()

bool HybrisProximityAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
sensordLogD() << "HybrisProximityAdaptor start\n";
Expand Down Expand Up @@ -118,6 +127,8 @@ void HybrisProximityAdaptor::sendInitialData()

void HybrisProximityAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "HybrisProximityAdaptor stop\n";
}
Expand Down
2 changes: 2 additions & 0 deletions adaptors/hybrisproximityadaptor/hybrisproximityadaptor.h
Expand Up @@ -62,5 +62,7 @@ class HybrisProximityAdaptor : public HybrisAdaptor
DeviceAdaptorRingBuffer<ProximityData>* buffer;
int sensorType;
int lastNearValue;
QByteArray powerStatePath;

};
#endif
11 changes: 11 additions & 0 deletions adaptors/hybrisstepcounteradaptor/hybrisstepcounteradaptor.cpp
Expand Up @@ -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)
Expand All @@ -40,6 +41,12 @@ 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();
if (!powerStatePath.isEmpty() && !QFile::exists(powerStatePath))
{
sensordLogW() << "Path does not exists: " << powerStatePath;
powerStatePath.clear();
}
}

HybrisStepCounterAdaptor::~HybrisStepCounterAdaptor()
Expand All @@ -49,6 +56,8 @@ HybrisStepCounterAdaptor::~HybrisStepCounterAdaptor()

bool HybrisStepCounterAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;

Expand All @@ -63,6 +72,8 @@ void HybrisStepCounterAdaptor::sendInitialData()

void HybrisStepCounterAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
sensordLogD() << "Hybris HybrisStepCounterAdaptor stop\n";
}
Expand Down
Expand Up @@ -64,6 +64,7 @@ class HybrisStepCounterAdaptor : public HybrisAdaptor

private:
DeviceAdaptorRingBuffer<TimedUnsigned>* buffer;
QByteArray powerStatePath;

};
#endif
20 changes: 20 additions & 0 deletions core/hybrisadaptor.cpp
Expand Up @@ -549,6 +549,26 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions core/hybrisadaptor.h
Expand Up @@ -24,6 +24,7 @@
#include <QObject>
#include <QThread>
#include <QTimer>
#include <QFile>

#include "deviceadaptor.h"
#include <hardware/sensors.h>
Expand Down Expand Up @@ -130,6 +131,7 @@ class HybrisAdaptor : public DeviceAdaptor
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();
Expand Down

0 comments on commit 2557bcf

Please sign in to comment.