/** 
 * \file machine.h
 * \brief machine header file
 * \details File contains structures and enumerations declarations for Main program
 *
 * \author Juraj Golej
 * \version 1.0
 */ 


#ifndef MACHINE_H_
#define MACHINE_H_

#define MACHINE_CMD_LEN		20	///< Maximum command length

/** 
 * \brief Machine state enumeration
 */
enum MACHINE_STATE {
	S_MAN0,			///< State Manual mode 0
	S_MAN1,			///< State Manual mode 1
	S_MAN2,			///< State Manual mode 2
	S_FILEMENU0,	///< State File menu 0
	S_FILEMENU1,	///< State File menu 1
	S_FILEMENU2,	///< State File menu 2
	S_AUTO0,		///< State Automatic mode 0
	S_AUTO1,		///< State Automatic mode 1
	S_AUTO2,		///< State Automatic mode 2
	S_AUTO3,		///< State Automatic mode 3
	S_AUTO4,		///< State Automatic mode 4
	S_AUTO5,		///< State Automatic mode 5
	S_AUTO6,		///< State Automatic mode 6
	S_AUTO7,		///< State Automatic mode 7
	S_AUTO8,		///< State Automatic mode 8
	S_AUTO9,		///< State Automatic mode 9
	S_AUTO10,		///< State Automatic mode 10
	S_ERROR0,		///< State Error 0
	S_ERROR1,		///< State Error 1
}; /* enum MACHINE_STATE */

/** 
 * \brief Command integer variable enumeration
 */
enum MACHINE_VAR_INT {
	MACHINE_VAR_INT_X,			///< Position on X axis (in mm)
	MACHINE_VAR_INT_Y,			///< Position on Y axis	(in mm)
	MACHINE_VAR_INT_Z,			///< Position on Z axis	(in mm)
	MACHINE_VAR_INT_CIRCX,		///< Circle center in X axis (in mm)
	MACHINE_VAR_INT_CIRCY,		///< Circle center in Y axis (in mm)
	MACHINE_VAR_INT_CIRCR,		///< Circle radius (in mm)
	MACHINE_VAR_INT_FRATEXY,	///< Feed rate in X and Y axis (in mm/s)
	MACHINE_VAR_INT_FRATEZ,		///< Feed rate in Z axis (in mm/s)
	MACHINE_VAR_INT_PRESS,		///< Pressure (in g)
	MACHINE_VAR_INT_TIME,		///< Time (in ms)

	MACHINE_VAR_INT,			///< Number of integer variables
}; /* enum MACHINE_VAR_INT */

/** 
 * \brief Command decimal variable enumeration
 */
enum MACHINE_VAR_DEC {


	MACHINE_VAR_DEC,			///< Number of decimal variables
}; /* enum MACHINE_VAR_DEC */

/** 
 * \brief Command actions enumeration
 */
enum MACHINE_ACTION {
	MACHINE_ACT_LINEAR,		///< Linear interpolation
	MACHINE_ACT_CIRCLENEG,	///< Circular interpolation in negative direction
	MACHINE_ACT_CIRCLEPOS,	///< Circular interpolation in positive direction
	MACHINE_ACT_HOMEMACH,	///< Home positioning
	MACHINE_ACT_HOMEWORKP,	///< Workpiece positioning
	MACHINE_ACT_PRESS,		///< Press down on the desired pressure
	MACHINE_ACT_COORDMACH,	///< Set machine coordination system
	MACHINE_ACT_COORDWORKP,	///< Set workpiece coordination system
	MACHINE_ACT_COORDABS,	///< Set absolute coordination system
	MACHINE_ACT_COORDINC,	///< Set incremental coordination system
	MACHINE_ACT_PAUSE,		///< Pause
	MACHINE_ACT_CHANGETOOL,	///< Tool change request

	MACHINE_ACT,			///< Number of actions
}; /* enum MACHINE_ACTION */

/** 
 * \brief Machine action function pointer
 */
typedef void (*machine_action)();

/** 
 * \brief General machine data struct
 */
struct MACHINE_data {
	char command[MACHINE_CMD_LEN];			///< Command buffer
	int16_t cmdLength;						///< Actual command length
	machine_action actionFunc[MACHINE_ACT];	///< Actions array
	uint8_t actionIndex;					///< Actual action index

	struct var {
		int32_t groupInt[MACHINE_VAR_INT];	///< Integer command variables array
		//float gropuDec[MACHINE_VAR_DEC];	///< Decimal command variables array
	} var;
	
	struct coord {
		bool relative;						///< \c true for workpiece, \c false for machine coordination system
		bool incremental;					///< \c true for incremental, \c false for absolute coordination system
	} coord;
	
	struct workpiece {
		float X;							///< Workpiece X coordination
		float Y;							///< Workpiece Y coordination
	} workpiece;
}; /* struct MACHINE_data */

/** 
 * \brief Main machine function with state machine
 */
void Machine();

#endif /* MACHINE_H_ */