added compass support added ui elements for gps and compass added support for writing sensor data
75 lines
1.2 KiB
C++
75 lines
1.2 KiB
C++
#ifndef GPSSENSORANDROID_H
|
|
#define GPSSENSORANDROID_H
|
|
|
|
#ifdef ANDROID
|
|
|
|
#include <sstream>
|
|
|
|
#include "../GPSSensor.h"
|
|
|
|
#include <QtPositioning>
|
|
|
|
class GPSSensorAndroid : public GPSSensor {
|
|
|
|
private:
|
|
|
|
QGeoPositionInfoSource* source;
|
|
|
|
/** hidden ctor. use singleton */
|
|
GPSSensorAndroid() {
|
|
|
|
source = QGeoPositionInfoSource::createDefaultSource(nullptr);
|
|
return;
|
|
|
|
}
|
|
|
|
bool started = false;
|
|
|
|
public:
|
|
|
|
/** singleton access */
|
|
static GPSSensorAndroid& get() {
|
|
static GPSSensorAndroid gps;
|
|
return gps;
|
|
}
|
|
|
|
void start() override {
|
|
|
|
if (started) {return;}
|
|
started = true;
|
|
|
|
auto onPositionData = [&] (const QGeoPositionInfo& update) {
|
|
|
|
GPSData data(
|
|
//Timestamp::ms(update.timestamp().toMSecsSinceEpoch()),
|
|
Timestamp::fromRunningTime(),
|
|
update.coordinate().latitude(),
|
|
update.coordinate().longitude(),
|
|
update.coordinate().altitude()
|
|
);
|
|
|
|
informListeners(data);
|
|
|
|
};
|
|
|
|
if (source) {
|
|
source->connect(source, &QGeoPositionInfoSource::positionUpdated, onPositionData);
|
|
source->startUpdates();
|
|
}
|
|
|
|
}
|
|
|
|
bool isRunning() const override {
|
|
return started;
|
|
}
|
|
|
|
void stop() override {
|
|
throw "TODO";
|
|
}
|
|
|
|
};
|
|
|
|
#endif // ANDROID
|
|
|
|
#endif // GPSSENSORANDROID_H
|