#pragma once
#include "PowerSwitched_Device.hpp"
#include <stdio.h>
#include <string>
#include <system_time.hpp>

enum class BellowPosError : uint8_t
{
	NONE = 0,
	NOT_CONFIGURED,
	WAITING_FOR_CONVERSION,
	OUT_OF_RANGE,
	UNKNOWN_ERROR,
	NUM_ERRORS
};
class BellowsPosition
{
public:
	struct bellowsPosSensorCfg_t
	{
		float sensor_slope_mm_per_volt;
		float sensor_offset_mm;
		
		float positionLowLim_mm;
		float positionHighLim_mm;
	};
	
	struct Measurement
	{
		int32_t counts;
		float volts;
		float position_mm;
		float position_pctFull;
		systime::DateTimeStruct tickstamp;
		bool conversion_good;
	};
	
public:
	BellowsPosition(std::string id, bellowsPosSensorCfg_t cfg);

	virtual BellowPosError start() = 0;

	virtual BellowPosError stop() = 0;

	virtual BellowPosError sleep() = 0;

	virtual BellowPosError requestMeasurement() = 0;
	
	void configure(bellowsPosSensorCfg_t cfg) { sensorCfg_ = cfg; }
	
	Measurement getMeasurement()
	{
		return lastMeasurement_;
	}
	
	virtual bool isBlocking() = 0;
	
	virtual bool isWithinLimits(bool takeNewMeasurement = false) = 0;

	void logEngLine(std::string comment);
	void logEngLine(BellowsPosition::Measurement meas, std::string comment);
	void logEngFileHeader();

  protected:
	virtual ~BellowsPosition() = default;

	const std::string id_;
	
	Measurement lastMeasurement_;
	
	bellowsPosSensorCfg_t sensorCfg_;
};
