added gps support
added compass support added ui elements for gps and compass added support for writing sensor data
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#ifndef ACCELEROMETERSENSORANDROID_H
|
||||
#define ACCELEROMETERSENSORANDROID_H
|
||||
|
||||
|
||||
#ifdef ANDROID
|
||||
|
||||
#include <sstream>
|
||||
|
||||
63
sensors/android/CompassSensorAndroid.h
Normal file
63
sensors/android/CompassSensorAndroid.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef COMPASSSENSORANDROID_H
|
||||
#define COMPASSSENSORANDROID_H
|
||||
|
||||
#ifdef ANDROID
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "../CompassSensor.h"
|
||||
|
||||
#include <QtSensors/QCompass>
|
||||
|
||||
class CompassSensorAndroid : public CompassSensor {
|
||||
|
||||
private:
|
||||
|
||||
QCompass compass;
|
||||
|
||||
/** hidden ctor. use singleton */
|
||||
CompassSensorAndroid() {
|
||||
;
|
||||
}
|
||||
|
||||
bool started = false;
|
||||
|
||||
public:
|
||||
|
||||
/** singleton access */
|
||||
static CompassSensorAndroid& get() {
|
||||
static CompassSensorAndroid compass;
|
||||
return compass;
|
||||
}
|
||||
|
||||
void start() override {
|
||||
|
||||
if (started) {return;}
|
||||
started = true;
|
||||
|
||||
auto onSensorData = [&] () {
|
||||
CompassData data(
|
||||
compass.reading()->azimuth(),
|
||||
compass.reading()->calibrationLevel()
|
||||
);
|
||||
informListeners(data);
|
||||
};
|
||||
|
||||
compass.connect(&compass, &QCompass::readingChanged, onSensorData);
|
||||
compass.start();
|
||||
|
||||
}
|
||||
|
||||
bool isRunning() const override {
|
||||
return started;
|
||||
}
|
||||
|
||||
void stop() override {
|
||||
throw "TODO";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // COMPASSSENSORANDROID_H
|
||||
74
sensors/android/GPSSensorAndroid.h
Normal file
74
sensors/android/GPSSensorAndroid.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#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
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "AccelerometerSensorAndroid.h"
|
||||
#include "GyroscopeSensorAndroid.h"
|
||||
#include "BarometerSensorAndroid.h"
|
||||
#include "CompassSensorAndroid.h"
|
||||
#include "GPSSensorAndroid.h"
|
||||
|
||||
/**
|
||||
* sensor factory that provides real hardware sensors from
|
||||
@@ -34,6 +36,14 @@ public:
|
||||
return BarometerSensorAndroid::get();
|
||||
}
|
||||
|
||||
CompassSensor& getCompass() override {
|
||||
return CompassSensorAndroid::get();
|
||||
}
|
||||
|
||||
GPSSensor& getGPS() override {
|
||||
return GPSSensorAndroid::get();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user