Escolar Documentos
Profissional Documentos
Cultura Documentos
Defines
uint32_t FLAG_UPDATE_INTERVAL - time in ms at which to adjust flag position
InitFlagService
Takes a priority number, returns True.
Initialize the MyPriority variable with the passed in parameter.
End of InitFlagService
RunFlagService
static local variable CurrentPosition // percentage of total servo motion
local variable newPosition
Based on the state of the ThisEvent variable choose one of the following blocks of code:
If ThisEvent is FlagStart Event
Call Servos_SetServo(flag servo, 0%)
Start MainTimer at 60s
Start FlagTimer at FLAG_UPDATE_INTERVAL
End if ThisEvent is FlagStart Event
If ThisEvent is FlagWin Event (Added 11/3/11 JEC)
CurrentPosition = 100;
Call Servos_SetServo(flag servo, 100%)
End if ThisEvent is FlagWin Event
if ThisEvent is FlagTimeout
newPosition = CurrentPosition + FLAG_UPDATE_INTERVAL/60,000
CurrentPosition = newPosition
Call Servos_SetServo(flag servo, newPosition)
End if ThisEvent is FlagTimeout Event
if ThisEvent is AbortButtonDown
CurrentPosition = 0;
Call Servos_SetServo(flag servo, 0%)
End if ThisEvent is AbortButtonDown Event
End of RunFlag
JoySequenceSM
Defines
uint32_t JOY_UPDATE_INTERVAL - time in ms at which to change display
InitJoySequenceSM
Takes a priority number, returns True.
Initialize the MyPriority variable with the passed in parameter.
Set CurrentState to be InitJoyState
Post Event ES_Init to JoySequenceSM queue (this service)
End of InitJoyService
RunJoySequenceSM
Returns ES_NO_EVENT
Local Variables: NextState
Set NextState to CurrentState
Based on the state of the CurrentState variable choose one of the following blocks of code:
CurrentState is InitJoySequenceSM
If ThisEvent is ES_Init
Set NextState to JoyWaiting
Endif
End InitJoySequenceSM block
CurrentState is JoyWaiting
If ThisEvent is BeginJoySequence
Call ShiftRegister_AllLEDsOn()
Start JoyTimer for JOY_UPDATE_INTERVAL
Set NextState to JoyState1
Endif
End Waiting block
CurrentState is JoyState1
If ThisEvent is JoySequenceTimeout
Call ShiftRegister_AllLEDsOff()
Start JoyTimer for JOY_UPDATE_INTERVAL
Set NextState to JoyState2
Endif
If ThisEvent is AbortButtonDown or JoyTimeout
NextState = Waiting
EndIf
End JoyState1 block
CurrentState is JoyState2
If ThisEvent is JoySequenceTimeout
Call ShiftRegister_AllLEDsOn()
Start JoyTimer for JOY_UPDATE_INTERVAL
Set NextState to JoyState1
Endif
If ThisEvent is AbortButtonDown or JoyTimeout
NextState = Waiting
EndIf
End JoyState2 block
End of RunJoySequenceSM
SharkPosition Service
Data private to the module: (static) CurrentPosition
Defines
AbortButton Service
local variable CurrentAbortState, LastAbortState
Defines
ABORT_DB_TIME- the debouncing time of the abort button
InitializeAbortButton
Takes a priority number, returns True.
Initialize the MyPriority variable with the passed in parameter.
Sample the button port pin and use it to initialize LastAbortButtonState
Set CurrentAbortState to be AbortDebouncing
Start abort_debounce timer (timer posts to AbortButtonDebounceSM)
End of InitializeAbortButton (return True)
RunAbortButtonDebounceSM (implements a 2-state state machine for debouncing timing)
The EventType field of ThisEvent will be one of: AbortButtonUp, AbortButtonDown, or ES_TIMEOUT
If CurrentAbortState is AbortDebouncing
If EventType is ES_TIMEOUT & parameter is abort debounce timer number
Set CurrentAbortState to Wait4AbortDB
Else if CurrentState is Wait4AbortDB
If EventType is AbortButtonUp
Start debounce timer
Set CurrentAbortState to DEBOUNCING
End if
If EventType is AbortButtonDown
Start abort_debounce timer
Set CurrentAbortState to DEBOUNCING
Post AbortButtonDown to DDM_SM
Post AbortButtonDown to SharkPositionService
Post AbortButtonDown to FlagService
Post AbortButtonDown to JoySequenceSM
End if
End Else
Return ES_NO_EVENT
End of RunAbortButtonDebounceSM
FireButton Service
local variable CurrentFireState, LastFireState
Defines
FIRE_DB_TIME- the debouncing time of the abort button
InitializeFireButton
Takes a priority number, returns True.
Initialize the MyPriority variable with the passed in parameter.
Sample the button port pin and use it to initialize LastFireButtonState
Set CurrentFireState to be FireDebouncing
Start fire_debounce timer (timer posts to FireButtonDebounceSM()
End of InitializeFireButton (return True)
RunFireButtonDebounceSM (implements a 2-state state machine for debouncing timing)
The EventType field of ThisEvent will be one of: FireButtonUp, FireButtonDown, or ES_TIMEOUT
If CurrentFireState is FireDebouncing
If EventType is ES_TIMEOUT & parameter is fire debounce timer number
Set CurrentFireState to Wait4FireDB
Else if CurrentFireState is Wait4FireDB
If EventType is FireButtonUp
Start debounce timer
Set CurrentFireState to DEBOUNCING
End if
If EventType is FireButtonDown
Start fire_debounce timer
Set CurrentFireState to DEBOUNCING
Post FireButtonDown to DDM_SM
Post FireButtonDown to SharkPositionService
End if
End Else
Return ES_NO_EVENT
End of RunFiretButtonDebounceSM