#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() {
		;
	}

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 {

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

		gyro.connect(&gyro, &QGyroscope::readingChanged, onSensorData);
		gyro.start();

	}

	bool isRunning() const override {
		return gyro.isActive();
	}

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



};

#endif // ANDROID

#endif // GYROSCOPESENSORANDROID_H
