This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YASMIN/sensors/android/GyroscopeSensorAndroid.h
kazu 44f9b6ac80 performance enhancements
memory enhancements
prevent starting sensors more than once
fix for wifi lag issues
map scaling for huge buildings
2016-10-01 10:21:15 +02:00

74 lines
1.3 KiB
C++

#ifndef GYROSCOPESENSORANDROID_H
#define GYROSCOPESENSORANDROID_H
#ifdef ANDROID
#include <sstream>
#include "../GyroscopeSensor.h"
#include <QtSensors/QGyroscope>
#include "../AccelerometerSensor.h"
class GyroscopeSensorAndroid : public GyroscopeSensor {
private:
QGyroscope gyro;
/** hidden ctor. use singleton */
GyroscopeSensorAndroid() {
;
}
bool started = false;
public:
/** singleton access */
static GyroscopeSensorAndroid& get() {
static GyroscopeSensorAndroid gyro;
return gyro;
}
float degToRad(const float deg) {
return deg / 180.0f * M_PI;
}
void start() override {
if (started) {return;}
started = true;
auto onSensorData = [&] () {
GyroscopeData data(degToRad(gyro.reading()->x()), degToRad(gyro.reading()->y()), degToRad(gyro.reading()->z()));
informListeners(data);
// const Timestamp now = Timestamp::fromRunningTime();
// Log::add("123", "ts:" + std::to_string(now.ms()));
};
// gyroscope is usually not as fast as the acceleromter -> limiting not needed
//gyro.setDataRate(200);
gyro.connect(&gyro, &QGyroscope::readingChanged, onSensorData);
gyro.start();
}
bool isRunning() const override {
return started;
}
void stop() override {
throw "TODO";
}
};
#endif // ANDROID
#endif // GYROSCOPESENSORANDROID_H