#ifndef IDIBUS_4CNTtoPWMPWM_H_
#define IDIBUS_4CNTtoPWMPWM_H_

#include "IdiBusSlave.h"				//	Common slave defines
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define IDIBUS_CUSTDEF_ERCODE_COUNTER_CHANNEL_NOT_INITED						100U
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
enum IDIBUS_4CNTtoPWM_MODULE_DEVICES_LIST {	//	Describe devices on module
	IDIBUS_4CNTtoPWM_CNTRL_DEV = 0,			//	COUNTER device ID
	IDIBUS_4CNTtoPWM_DEVICES_NUMBER			//	Device count on module	
	};

enum {									// Describe channel configuration for device (COUNTER)	
	IDIBUS_4CNTtoPWM_CH1_NUM = 0,			// Name for 1st channel
	IDIBUS_4CNTtoPWM_CH2_NUM,				//			2nd ...
	IDIBUS_4CNTtoPWM_CH3_NUM,				//
	IDIBUS_4CNTtoPWM_CH4_NUM,				//
	IDIBUS_4CNTtoPWM_CH_COUNT,				// Channel count
	};

typedef struct {
	uint8_t PWM;					// Last returned value
	uint8_t MMES_Error;					// Last error
} IDIBUS_4CNTtoPWM_DATA_TYPE;				// Data structure for COUNTER channels

class IdiBus_4CNTtoPWM : public IdiBusSlave {									//	COUNTER module class
	public:																	//	Public methods
 		IdiBus_4CNTtoPWM ( IdiBusSerialLine *SlaveLine, uint8_t SlaveAddress);		// Init object with specified bus line and addr 
		IdiBus_4CNTtoPWM();															// init without specified line and addr (default value line=NULL,addr=1)
		 
		uint8_t setChPwm(uint8_t ChNum, uint8_t pwm);										//	Sends MMES and get Counts on ch (writes to CH structure and returns MMES error code)
		void    setAllChsPwm(void);											//	Sends MMES and get Counts on ch (writes to CH structure)

		void setChPwmLocal(uint8_t ChNum, uint8_t pwm);
		
		uint8_t initCh(uint8_t ChNum);											// Inits specified counter channel on module
		void    initAllChs(void);												// Inits all counters on module

		IDIBUS_4CNTtoPWM_DATA_TYPE  getChData(uint8_t ChNum);						// Returns data structure
	
	protected:																// 'Private' methods and structures			
		IDIBUS_4CNTtoPWM_DATA_TYPE  CH[IDIBUS_4CNTtoPWM_CH_COUNT];						// Data structure array
		
		void    setAllChErr(uint8_t ErrCode);									// Set error code for all channels
};
#endif
