[COLOR="Red"]Counter = 0; //Global Var.
RelayLatched = 0;//Global Var.
SwitchRelease = 0;//Global Var.
OnSwitchInterrupt(){
ActivateTimer(); //"osal_start_timerEx( EndptApp_TaskID,EP_JOIN_BUTTON_PRESSING, 100);"?
RETI; //Return From Switch Int.
}[/COLOR]
OnTimerEvent(){
if (ButtonPressed==1 && RelayLatched == 1 && SwitchRelease == 1){
DelatchRelay();
SwitchRelease = 0;
}
if (ButtonPressed==1 && RelayLatched == 0){ //Let's call 'ButtonPressed' a beautiful name for uC's pin where the button is connected to. And for this code 1 = pressed, 0 = released.
Counter++;
if (Counter>=20){ //If button is still pressed and at least 2s have passed, it is time to latch the relay.
LatchRelay();
RelayLatched = 1;//We are going to use this flag.
Counter = 0;
}
osal_start_timerEx( EndptApp_TaskID,EP_JOIN_BUTTON_PRESSING, 100); [B]//Keep the timer runing.[/B]
}
if (ButtonPressed==0 && RelayLatched == 0){
if (Counter<=4 ) {//If button is not pressed and less than 400ms have passed.
BlinkLED();
}
Counter=0; //If the Counter is >4, just clear it and stop the timer
osal_stop_timerEx( EndptApp_TaskID, EP_JOIN_BUTTON_PRESSING); [B]//TimerStop[/B]
}
if (ButtonPressed==0 && RelayLatched == 1){//If button is not pressed and the relay is latched, then it is a switch release, so we are going to flag it.
SwitchRelease = 1; // Flag that it was a switch release.
osal_stop_timerEx( EndptApp_TaskID, EP_JOIN_BUTTON_PRESSING); [B]//TimerStop[/B]
}
RETI; //Return From Timer Int.
}