Created
December 1, 2015 04:19
-
-
Save michaellin/68549d01f5abe8e45a95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pseudo Code for Wrench Service | |
InitaializeWrenchService | |
Takes a priority number, returns true. | |
Initialize the MyPriority variable with the passed in parameter | |
Initialize the port line to read analog input for Pot | |
Initialize the port lines to light wrench LEDs and SR_Init_LED() | |
Turn off all LEDs | |
Sample pot port line and use it to initialize LastWrenchState variable (probably as bins of values) | |
Set CurrentState to be InitWrenchService | |
Set TimeDelta to 0 (time wrench takes to get to right position) | |
Post event ES_Init to InitialzeWrench queue (this service) | |
End of InitializeWrenchService | |
CheckWrenchEvents | |
Takes no parameters, returns True if an event was posted | |
Local ReturnVal = False | |
Get the current wrench input state from the anolog input line | |
If Current input state of pot is different from LastInputState or Current input State is in LED bin | |
If current LED on is in Wrench_Bin | |
PostEvent ES_ReachedLED with the parameter of the Current Time | |
Endif | |
Else | |
PostEvent ES_NotReachedLED | |
endElse | |
Set ReturnVal True | |
Endif | |
Set LastInputState to CurrentInputState | |
Return ReturnVal | |
End of CheckWrenchEvents | |
Post WrenchSerivce | |
Takes an ES_Event, returns bool | |
RunWrenchService | |
Takes an ES_Event, Returs an ES_Event. | |
The EventType field will be one of: ES_Init, ES_ReachedLED, ES_NotReachedLED, ES_TimeOut, START_BUTTON_DBDOWN, ES_WRENCH2GOAL | |
Set NextState to CurrentState | |
Switch CurrentState : | |
CurrentState is InitWrenchService | |
If ThisEvent is ES_Init | |
Set NextState to WaitingForStart | |
Endif | |
End InitWrenchServiceBlock | |
CurrentState is WaitingForStart | |
If ThisEvent is START_BUTTON_DBDOWN | |
Set NextState to Wrench2Position | |
Set WrenchStartTime = Get Current Time | |
Turn on a random LED and save its position (LED_Position) | |
Endif | |
End WaitingForStart block | |
CurrentState is Wrench2Position | |
If ThisEvent is ES_ReachedLED | |
Start WrenchTimer | |
Set NextState to WrenchInPosition | |
Endif | |
If ThisEvent is PipeDown (or PipeTimerTimeout) | |
Set NextState to PipeBurst | |
Turn off LEDs | |
Endif | |
End Wrench2Position block | |
CurrentState is PipeBurst | |
If ThisEvent is (ES_PIPE_BUTTON1_DBDOWN) or (ES_PIPE_BUTTON2_DBDOWN) or (ES_FAIL_DRIP_CATCH) | |
Turn on a random LED and save its position (LED_Position) | |
Set NextState to Wrench2Position | |
Set WrenchStartTime = Get Current Time | |
Endif | |
End PipeBurst block | |
CurrentState is WrenchInPosition | |
If ThisEvent is ES_NotReachedLED | |
Set NextState to Wrench2Position | |
Endif | |
If ThisEvent is ES_TimeOut (for Wrench timer) | |
TimeDelta = GetCurrentTime - WrenchStartTime | |
Post ES_WRENCH2GOAL with parameter of TimeDelta (uint16) | |
Set WrenchStartTime = Get Current Time | |
Set NextState to Wrench2Position | |
Light a new LED and save its position | |
EndIf | |
If ThisEvent is PipeDown (or PipeTimerTimeout) | |
Set NextState to PipeBurst | |
Turn off LEDs | |
Endif | |
End WrenchInPosition block | |
End of Switch | |
Set CurrentState to Next State | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment