#ifndef STEPSENSOR_H
#define STEPSENSOR_H

#include <Indoor/sensors/imu/StepDetection.h>
#include "AccelerometerSensor.h"


struct StepData {
	const int stepsSinceLastEvent = 0;
	StepData(const int stepsSinceLastEvent) : stepsSinceLastEvent(stepsSinceLastEvent) {;}
};

/**
 * step-sensor detects steps from the accelerometer
 */
class StepSensor :
		public SensorListener<AccelerometerData>,		// << takes
		public Sensor<StepData> {						// << provides

private:

	AccelerometerSensor& acc;
	StepDetection sd;

public:

	StepSensor(AccelerometerSensor& acc) : acc(acc) {
		acc.addListener(this);
	}

	virtual void start() override {
		//
	}

	virtual void stop() override {
		//
	}

	bool isRunning() const override {
		return acc.isRunning();
	}

	virtual void onSensorData(Sensor<AccelerometerData>* sensor, const Timestamp ts, const AccelerometerData& data) override {
		(void) sensor;
		const bool step = sd.add(ts, data);
		if (step) {
			informListeners(ts, StepData(1));
		}
	}

};

#endif // STEPSENSOR_H
