Health Bar MODULE PSEUDOCODE
HealthBar Module (Service)
define MAX_HEALTH
define PWM_MIN, PWM_MAX, PWM_COEF
define PWM_DEAD, PWM_FIN
static local variable myHealth
initHealthBar takes nothing, returns true
initialize myHealth to MAX_HEALTH
set PWM pulsewidth to PWM_MIN
return true
End of initHealthBar
runHealthBar takes event ES_MY_HEALTH, ES_CARD_REMOVED
If EventType is ES_MY_HEALTH
save EventParam to myHealth
If myHealth is 0
set PWM pulsewidth to PWM_DEAD
Else if myHealth is 10000 // means that EOGbutton is pressed
set PWM pulsewidth to PWM_FIN
Else
set PWM pulsewidth to PWM_MAX - myHealth * PWM_COEF
End if
Else if EventType is ES_CARD_REMOVED
set myHealth as MAX_HEALTH
set PWM pulsewidth to PWM_MIN
End if
End of runHealthBar
define MAX_HEALTH
define PWM_MIN, PWM_MAX, PWM_COEF
define PWM_DEAD, PWM_FIN
static local variable myHealth
initHealthBar takes nothing, returns true
initialize myHealth to MAX_HEALTH
set PWM pulsewidth to PWM_MIN
return true
End of initHealthBar
runHealthBar takes event ES_MY_HEALTH, ES_CARD_REMOVED
If EventType is ES_MY_HEALTH
save EventParam to myHealth
If myHealth is 0
set PWM pulsewidth to PWM_DEAD
Else if myHealth is 10000 // means that EOGbutton is pressed
set PWM pulsewidth to PWM_FIN
Else
set PWM pulsewidth to PWM_MAX - myHealth * PWM_COEF
End if
Else if EventType is ES_CARD_REMOVED
set myHealth as MAX_HEALTH
set PWM pulsewidth to PWM_MIN
End if
End of runHealthBar