memory enhancements prevent starting sensors more than once fix for wifi lag issues map scaling for huge buildings
74 lines
1.3 KiB
C++
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
|