Play Timer MODULE PSEUDOCODE
PlayTimer module (Service)
define END_OF_GAME 45
define PWM_MIN
define PWM_MAX
define PWM_COEF // coefficient relation between time and servo motor angle
static local variable playtime
InitPlayTimer takes nothing, returns true
initialize playtime to 0
set PWM pulsewidth to PWM_MIN
start ONE_SEC_TIMER
return True
End of InitPlayTimer
RunPlayTimer takes event ES_TIMEOUT, returns nothing
If EventType is ES_TIMEOUT
If EventParam is ONE_SEC_TIMER
increase Playtime by 1
set PWM pulsewidth to (PWM_MAX - Playtime * PWM_COEF)
If Playtime is END_OF_GAME
post ES_GAME_STOPPED to modules
Else
start ONE_SEC_TIMER
End if
Else if EventParam is GAME_STOP_TIMER
post ES_GAME_STOPPED to modules
End if
Else if EventType is ES_CARD_READ
start ONE_SEC_TIMER
start GAME_STOP_TIMER
Else if EventType is ES_GAME_STOPPED
stop ONE_SEC_TIMER
stop GAME_STOP_TIMER
Else if EventType is ES_GAME_OVER
stop ONE_SEC_TIMER
stop GAME_STOP_TIMER
Else if EventType is ES_CARD_REMOVED
stop ONE_SEC_TIMER
stop GAME_STOP_TIMER
set PWM pulsewidth to PWM_MAX
End if
End of RunPlayTimer
define END_OF_GAME 45
define PWM_MIN
define PWM_MAX
define PWM_COEF // coefficient relation between time and servo motor angle
static local variable playtime
InitPlayTimer takes nothing, returns true
initialize playtime to 0
set PWM pulsewidth to PWM_MIN
start ONE_SEC_TIMER
return True
End of InitPlayTimer
RunPlayTimer takes event ES_TIMEOUT, returns nothing
If EventType is ES_TIMEOUT
If EventParam is ONE_SEC_TIMER
increase Playtime by 1
set PWM pulsewidth to (PWM_MAX - Playtime * PWM_COEF)
If Playtime is END_OF_GAME
post ES_GAME_STOPPED to modules
Else
start ONE_SEC_TIMER
End if
Else if EventParam is GAME_STOP_TIMER
post ES_GAME_STOPPED to modules
End if
Else if EventType is ES_CARD_READ
start ONE_SEC_TIMER
start GAME_STOP_TIMER
Else if EventType is ES_GAME_STOPPED
stop ONE_SEC_TIMER
stop GAME_STOP_TIMER
Else if EventType is ES_GAME_OVER
stop ONE_SEC_TIMER
stop GAME_STOP_TIMER
Else if EventType is ES_CARD_REMOVED
stop ONE_SEC_TIMER
stop GAME_STOP_TIMER
set PWM pulsewidth to PWM_MAX
End if
End of RunPlayTimer