Commit 09dbf907 authored by spiiroin's avatar spiiroin

Merge branch 'jb43020_initial_state' into 'master'

Refactor sensor start/stop logic and tune als/ps default values

See merge request !27
parents 8bd068fb a997710c
......@@ -44,20 +44,19 @@ HybrisAccelerometerAdaptor::~HybrisAccelerometerAdaptor()
bool HybrisAccelerometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris AccelAdaptor start\n";
return true;
}
void HybrisAccelerometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris AccelAdaptor stop\n";
}
......
......@@ -52,11 +52,10 @@ HybrisAlsAdaptor::~HybrisAlsAdaptor()
bool HybrisAlsAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris HybrisAlsAdaptor start\n";
return true;
}
......@@ -120,9 +119,9 @@ void HybrisAlsAdaptor::sendInitialData()
void HybrisAlsAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris HybrisAlsAdaptor stop\n";
}
......
......@@ -51,20 +51,19 @@ HybrisGyroscopeAdaptor::~HybrisGyroscopeAdaptor()
bool HybrisGyroscopeAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "HybrisGyroscopeAdaptor start\n";
return true;
}
void HybrisGyroscopeAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() &&!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "HybrisGyroscopeAdaptor stop\n";
}
......
......@@ -48,20 +48,19 @@ HybrisMagnetometerAdaptor::~HybrisMagnetometerAdaptor()
bool HybrisMagnetometerAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() &&!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "HybrisMagnetometerAdaptor start\n";
return true;
}
void HybrisMagnetometerAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "HybrisMagnetometerAdaptor stop\n";
}
......
......@@ -64,20 +64,19 @@ HybrisOrientationAdaptor::~HybrisOrientationAdaptor()
bool HybrisOrientationAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris OrientationAdaptor start\n";
return true;
}
void HybrisOrientationAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris OrientationAdaptor stop\n";
}
......
......@@ -50,20 +50,19 @@ HybrisPressureAdaptor::~HybrisPressureAdaptor()
bool HybrisPressureAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris HybrisPressureAdaptor start\n";
return true;
}
void HybrisPressureAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris HybrisPressureAdaptor stop\n";
}
......
......@@ -57,10 +57,10 @@ HybrisProximityAdaptor::~HybrisProximityAdaptor()
bool HybrisProximityAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "HybrisProximityAdaptor start\n";
return true;
}
......@@ -127,9 +127,9 @@ void HybrisProximityAdaptor::sendInitialData()
void HybrisProximityAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "HybrisProximityAdaptor stop\n";
}
......@@ -138,7 +138,7 @@ void HybrisProximityAdaptor::processSample(const sensors_event_t& data)
ProximityData *d = buffer->nextSlot();
d->timestamp_ = quint64(data.timestamp * .001);
bool near = false;
if (data.distance < maxRange) {
if (data.distance < maxRange()) {
near = true;
}
d->withinProximity_ = near;
......
......@@ -56,11 +56,10 @@ HybrisStepCounterAdaptor::~HybrisStepCounterAdaptor()
bool HybrisStepCounterAdaptor::startSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
if (!(HybrisAdaptor::startSensor()))
return false;
if (isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "1");
sensordLogD() << "Hybris HybrisStepCounterAdaptor start\n";
return true;
}
......@@ -72,9 +71,9 @@ void HybrisStepCounterAdaptor::sendInitialData()
void HybrisStepCounterAdaptor::stopSensor()
{
if(!powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
HybrisAdaptor::stopSensor();
if (!isRunning() && !powerStatePath.isEmpty())
writeToFile(powerStatePath, "0");
sensordLogD() << "Hybris HybrisStepCounterAdaptor stop\n";
}
......
This diff is collapsed.
......@@ -34,50 +34,70 @@
class HybrisAdaptor;
struct HybrisSensorState
{
HybrisSensorState();
~HybrisSensorState();
int m_minDelay;
int m_maxDelay;
int m_delay;
int m_active;
sensors_event_t m_fallbackEvent;
};
class HybrisManager : public QObject
{
Q_OBJECT
public:
explicit HybrisManager(QObject *parent = 0);
static HybrisManager *instance();
virtual ~HybrisManager();
int handleForType(int sensorType);
int maxRange(int sensorType);
int minDelay(int sensorType);
int resolution(int sensorType);
bool setDelay(int handle, int interval);
void startReader(HybrisAdaptor *adaptor);
void stopReader(HybrisAdaptor *adaptor);
bool resumeReader(HybrisAdaptor *adaptor);
void standbyReader(HybrisAdaptor *adaptor);
bool openSensors();
bool closeSensors();
void registerAdaptor(HybrisAdaptor * adaptor);
void processSample(const sensors_event_t& data);
explicit HybrisManager(QObject *parent = 0);
virtual ~HybrisManager();
protected:
// methods
void init();
void closeAllSensors();
/* - - - - - - - - - - - - - - - - - - - *
* android sensor hal functions
* - - - - - - - - - - - - - - - - - - - */
sensors_event_t *halEventForHandle(int handle) const;
int halIndexForHandle(int handle) const;
int halIndexForType (int sensorType) const;
int halHandleForType (int sensorType) const;
float halGetMaxRange (int handle) const;
float halGetResolution (int handle) const;
int halGetMinDelay (int handle) const;
int halGetMaxDelay (int handle) const;
int halGetDelay (int handle) const;
bool halSetDelay (int handle, int delay_ms);
bool halGetActive (int handle) const;
bool halSetActive (int handle, bool active);
/* - - - - - - - - - - - - - - - - - - - *
* HybrisManager <--> sensorfwd
* - - - - - - - - - - - - - - - - - - - */
void startReader (HybrisAdaptor *adaptor);
void stopReader (HybrisAdaptor *adaptor);
void registerAdaptor (HybrisAdaptor * adaptor);
void processSample (const sensors_event_t& data);
private:
// fields
struct sensors_poll_device_t* device;
struct sensor_t const* sensorList;
struct sensors_module_t* module;
int sensorsCount;
QMap <int, int> sensorMap; //type, index
QMap <int, HybrisAdaptor *> registeredAdaptors; //type, obj
pthread_t adaptorReaderTid;
bool m_initialized;
QMap <int, HybrisAdaptor *> m_registeredAdaptors; // type -> obj
struct sensors_module_t *m_halModule;
struct sensors_poll_device_t *m_halDevice;
int m_halSensorCount;
const struct sensor_t *m_halSensorArray; // [m_halSensorCount]
HybrisSensorState *m_halSensorState; // [m_halSensorCount]
QMap <int, int> m_halIndexOfType; // type -> index
QMap <int, int> m_halIndexOfHandle; // handle -> index
pthread_t m_halEventReaderTid;
friend class HybrisAdaptorReader;
private:
static void *adaptorReaderThread(void *aptr);
static void *halEventReaderThread(void *aptr);
};
class HybrisAdaptor : public DeviceAdaptor
......@@ -87,47 +107,44 @@ public:
virtual ~HybrisAdaptor();
virtual void init();
bool addSensorType(int type);
virtual bool startAdaptor();
bool isRunning() const;
bool isRunning() const;
virtual void stopAdaptor();
void evaluateSensor();
virtual bool startSensor();
virtual void stopSensor();
virtual bool standby();
virtual bool resume();
qreal maxRange;
qint32 minDelay;
qreal resolution;
virtual void sendInitialData();
friend class HybrisManager;
int sensorHandle;
int sensorType;
int cachedInterval;
virtual void sendInitialData() {}
protected:
virtual void processSample(const sensors_event_t& data) = 0;
qreal minRange() const;
qreal maxRange() const;
qreal resolution() const;
unsigned int minInterval() const;
unsigned int maxInterval() const;
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();
bool startReaderThread();
QList<int> sensorIds;
unsigned int interval_;
bool inStandbyMode_;
volatile bool running_;
bool shouldBeRunning_;
bool m_inStandbyMode;
volatile bool m_isRunning;
bool m_shouldBeRunning;
int m_sensorHandle;
int m_sensorType;
};
#endif // HybrisAdaptor_H
......@@ -29,9 +29,9 @@
#include <QDebug>
#define sensordLogT() (qDebug())
#define sensordLogD() (qInfo())
#define sensordLogW() (qWarning())
#define sensordLogC() (qCritical())
#define sensordLogT(ARGS_...) (qDebug(ARGS_))
#define sensordLogD(ARGS_...) (qInfo(ARGS_))
#define sensordLogW(ARGS_...) (qWarning(ARGS_))
#define sensordLogC(ARGS_...) (qCritical(ARGS_))
#endif //LOGGING_H
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