#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
