
#ifndef __HS_DIO_H
#define __HS_DIO_H




typedef enum
{
	LowActive = 0,
	HighActive
}LowHighActive;









struct stHSDIOTask__{

	char DORunFlag;
	char DIRunFlag;
	unsigned char DISecCount;

	int DORunPeriodTime;
	int DIRunPeriodTime;



};
typedef struct stHSDIOTask__ stHSDIOTask;





typedef struct stHSDIn__{
	unsigned char in;
	unsigned char onFlag;
	unsigned char softRelease;
	unsigned char pressedSec;
	//unsigned char SecCount;
	unsigned int  pressTime;
	unsigned int  longPressTimeOne;
	unsigned int  longPressTimeKeep;
	unsigned int  prevTime;


	unsigned int pressCount;
	unsigned int longPressCount;


	void (*Pressed)(struct stHSDIn__*);
	void (*Released)(struct stHSDIn__*);
	void (*LongPressedOne)(struct stHSDIn__*);
	void (*LongPressedKeep)(struct stHSDIn__*);


}stHSDIn;





struct stHSDOut__{
	uint8_t Mode;	// 1:Normal,  2:Repeate,  3:Toggle
	uint8_t LimitMode;
	uint8_t Trigger;
	uint8_t Out;
	uint8_t Run;
	uint8_t StartFalg;
	uint8_t Err;

	uint8_t DischageEnable;
	int DischargeTimer;

	int32_t AliveTimer;
	int32_t AliveCounter;	// Not used : -1

	int32_t OnDelay;
	int32_t StopFuncDelay;
	int32_t StopFuncDelaySet;
	int32_t RefleshTime;
	int32_t OnTime;
	int32_t OffTime;
	int32_t PulseCounter;
	

	int32_t UpdateTime;	// MODE3-timer for on/off switching    MODE1-Trigger Repeat
	uint32_t PrevTick;
	void (*StartFunc)(struct stHSDOut__*);
	void (*StopFunc)(struct stHSDOut__*);
	void (*OptFunc)(struct stHSDOut__*);
	void (*UpdateFunc)(struct stHSDOut__*);
};
typedef struct stHSDOut__ stHSDOut;





int DITask();
int DOTask();
void DioTask();

#if 0
void HSDataBitInit();
void HSDOutInit();
void HSDOutProcess(stHSDOut* DOut, const stDIOPortMap* PinMap, int Len);
void HSDInInit();
void HSDInRun(stHSDIn* DIn, const stDIOPortMap* PinMap, int Len);
void HOT_1_Init( char output );
void HSDataBitInRun(stHSDIn* DIn, uint32_t DataBit, int Len);


void HSDOut_0_Start(stHSDOut* pDout);
void HSDOut_0_Stop(stHSDOut* pDout);
void HSDOut_0_Opt(stHSDOut* pDout);
void HSDOut_1_Start(stHSDOut* pDout);
void HSDOut_1_Stop(stHSDOut* pDout);
void HSDOut_1_Opt(stHSDOut* pDout);
void HSDOut_2_Start(stHSDOut* pDout);
void HSDOut_2_Stop(stHSDOut* pDout);
void HSDOut_2_Opt(stHSDOut* pDout);
#endif





void Key_0_Pressed(stHSDIn* pDin);
void Key_0_Released(stHSDIn* pDin);
void Key_1_Pressed(stHSDIn* pDin);
void Key_1_Released(stHSDIn* pDin);
void Key_2_Pressed(stHSDIn* pDin);
void Key_2_Released(stHSDIn* pDin);
void Key_3_Pressed(stHSDIn* pDin);
void Key_3_Released(stHSDIn* pDin);
void Key_4_Pressed(stHSDIn* pDin);
void Key_4_Released(stHSDIn* pDin);
void DevRegLongPressedOne(stHSDIn* pDin);

void TriggerEmg();
void TriggerLineTest();
void TriggerRegDev();




#if 0


void Key_5_Pressed(stHSDIn* pDin);
void Key_5_Released(stHSDIn* pDin);
void Key_6_Pressed(stHSDIn* pDin);
void Key_6_Released(stHSDIn* pDin);
void Key_7_Pressed(stHSDIn* pDin);
void Key_7_Released(stHSDIn* pDin);
void Key_8_Pressed(stHSDIn* pDin);
void Key_8_Released(stHSDIn* pDin);
void Key_9_Pressed(stHSDIn* pDin);
void Key_9_Released(stHSDIn* pDin);
void Key_10_Pressed(stHSDIn* pDin);
void Key_10_Released(stHSDIn* pDin);
void Key_11_Pressed(stHSDIn* pDin);
void Key_11_Released(stHSDIn* pDin);
void Key_12_Pressed(stHSDIn* pDin);
void Key_12_Released(stHSDIn* pDin);
void Key_13_Pressed(stHSDIn* pDin);
void Key_13_Released(stHSDIn* pDin);
void Key_14_Pressed(stHSDIn* pDin);
void Key_14_Released(stHSDIn* pDin);
void Key_15_Pressed(stHSDIn* pDin);
void Key_15_Released(stHSDIn* pDin);
void Key_16_Pressed(stHSDIn* pDin);
void Key_16_Released(stHSDIn* pDin);
void Key_17_Pressed(stHSDIn* pDin);
void Key_17_Released(stHSDIn* pDin);
#endif






extern uint32_t ADCCurrent[];
extern uint32_t ADCCurrentPos;
extern float SetAmp;
extern char SetAmpUpdate;


extern stHSDOut HSDOut[];
extern stHSDIOTask HSDIOTask;


extern uint32_t TimeSlice[];
extern char Key1Flag;

extern void Buzzer_Select(uint8_t state);



#endif
