#ifndef ACCELEROMETERSENSORANDROID_H
#define ACCELEROMETERSENSORANDROID_H


#ifdef ANDROID

#include <sstream>

#include "../AccelerometerSensor.h"

#include <QtSensors/QAccelerometer>

#include "../AccelerometerSensor.h"

class AccelerometerSensorAndroid : public AccelerometerSensor {

private:

	QAccelerometer acc;

	/** hidden ctor. use singleton */
	AccelerometerSensorAndroid() {
		;
	}

	bool started = false;

public:

	/** singleton access */
	static AccelerometerSensorAndroid& get() {
		static AccelerometerSensorAndroid acc;
		return acc;
	}

	void start() override {

		if (started) {return;}
		started = true;

		auto onSensorData = [&] () {
			AccelerometerData data(acc.reading()->x(), acc.reading()->y(), acc.reading()->z());
			informListeners(data);
		};

		// accelerometer is usually verry fast -> limit the maximum data-rate to 200 Hz (5ms)
		acc.setDataRate(200);

		acc.connect(&acc, &QAccelerometer::readingChanged, onSensorData);
		acc.start();

	}

	bool isRunning() const override {
		return started;
	}

	void stop() override {
		throw "TODO";
	}

};

#endif // ANDROID

#endif // ACCELEROMETERSENSORANDROID_H
