#ifndef __PRESSURE_SENSOR_THREAD_H__
#define __PRESSURE_SENSOR_THREAD_H__

#include "threads.h"
#include "mutex.h"

class PressureSensorThread : public Thread {

//	friend stringstream& operator<< (stringstream& out, const ControlThread& controller);

public:

	PressureSensorThread (Elmo& winch, Elmo& levelWind)
		: m_Winch(winch), m_LevelWind(levelWind),
		  m_Started(false) {}

	~PressureSensorThread(void) {}

	void SetWinchRPM(double rpm);

	void StartController(void);
	void StopController(void);
	void Query(void);

protected:
	virtual void* Run(void*);

private:

	struct ItemsToLog
	{
		double		requestedWinchRPM;
		double		levelWindBaseDAC_Voltage;
		double		winchDAC_Voltage;
		double		levelWindDAC_Voltage;
		double		motorTensionPounds;
		double		flangeTensionPounds;
		double		totalTensionPounds;
		double		levelWindError;
		uint32_t	winchCountsPerSecond;
		uint32_t	levelWindDirection;
		Mode		levelWindMode;
		bool		isEndOfTravelLeftSwitchClosed;
		bool		isEndOfTravelRightSwitchClosed;
		bool		isCableLeftSwitchClosed;
		bool		isCableRightSwitchClosed;
	};

	Mutex		m_ExclusiveAccess;
	Elmo&		m_Winch;
	Elmo&		m_LevelWind;
	double		m_RequestedWinchRPM;
	double		m_LevelWindBaseDAC_Voltage;
	double		m_WinchDAC_voltage;
	double		m_LevelWindDAC_voltage;
	double 		m_MotorTensionPounds;
	double	 	m_FlangeTensionPounds;
	double		m_TotalTensionPounds;
	double		m_LevelWindError;
	uint32_t	m_WinchCountsPerSecond;
	uint32_t	m_LevelWindDirection;
	Mode		m_LevelWindMode;
	bool		m_IsEndOfTravelLeftSwitchClosed;
	bool		m_IsEndOfTravelRightSwitchClosed;
	bool		m_IsCableLeftSwitchClosed;
	bool		m_IsCableRightSwitchClosed;
	bool		m_Started;
	ItemsToLog	m_l;
};

#endif // of __CONTROL_THREAD_H_INCLUDED__


#endif // __PRESSURE_SENSOR_THREAD_H__
