#ifndef BAROMETERSENSORANDROID_H
#define BAROMETERSENSORANDROID_H

#ifdef ANDROID

#include <sstream>

#include "../BarometerSensor.h"

#include <QtSensors/QPressureSensor>

#include "../AccelerometerSensor.h"

class BarometerSensorAndroid : public BarometerSensor {

private:

	QPressureSensor baro;

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

	bool started = false;

public:

	/** singleton access */
	static BarometerSensorAndroid& get() {
		static BarometerSensorAndroid baro;
		return baro;
	}

	void start() override {

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

		auto onSensorData = [&] () {
			BarometerData data(baro.reading()->pressure() / 100.0f);		// convert Pa to hPa
			informListeners(data);
		};

		baro.connect(&baro, &QPressureSensor::readingChanged, onSensorData);
		baro.start();

	}

	bool isRunning() const override {
		return started;
	}

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



};

#endif

#endif // BAROMETERSENSORANDROID_H
