Created
December 1, 2015 04:26
-
-
Save michaellin/c3e2b0157ea590e7fb5a 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
/***Service module for the main state machine of our project***/ | |
define ALL_BITS offset variable | |
define GoodScore threshold | |
define GAME_TIME | |
Initialize module leve variables | |
/************************************************************** | |
Function: InitUncleEd | |
Takes: 8 bit integer (priority number) | |
Returns: true or false | |
Purpose: Passes in priority number, initializes Tiva pins, and moves into state machine. | |
/*************************************************************/ | |
InitUncleEd | |
Initialize ThisEvent | |
Initialize MyPriority static variable with passed in parameter | |
Initialize CurrentLEDState = low | |
Initialize HourGlassPosition = low | |
Initialize bit 3 on port A | |
Initialize bit 3 on port B (5V line) | |
Set CurrentState to InitModeUncleEd | |
Post ES_Init event to UncleEd service | |
end | |
/************************************************************** | |
Function: PostUncleEd | |
Takes: ES_Event | |
Returns: true or false | |
Purpose: Posts events to this service's queue. | |
/*************************************************************/ | |
PostUncleEd | |
call ES_PostToService, and pass it the priority number of this service | |
end | |
/************************************************************** | |
Function: RunUncleEd | |
Takes: ES_Event | |
Returns: ES_Event (ES_NO_EVENT) | |
Purpose: Runs Uncle Ed state machine. | |
/*************************************************************/ | |
RunUncleEd | |
use a switch case to switch between states | |
case InitModeUncleEd: | |
if event type is ES_INIT | |
Move into ArmedMode state | |
Set Ed Timer to 10 ms | |
endif | |
break | |
case ArmedMode: | |
if event is a timeout for ed timer | |
Send tunes to audio services | |
Set 5V line low | |
Command Ed's Arm Servo to point ed's arm towards start button | |
Set StartButtonLED timer to 750 ms | |
else if event is timeout for start button timer | |
if CurrentLEDState is high | |
Set Start Button LED pin low (A3 low) | |
Set CurrentLEDState = low | |
Set StartButtonLED timer to 750 ms | |
else CurrentLEDState is low | |
Set Start Button LED pin high (A3 high) | |
Set CurrentLEDState = high | |
Set StartButtonLED timer to 750 ms | |
endif | |
else if event type is start button debounced down | |
Post debounced start button to all services | |
Send tunes to audio services | |
Reset ScoreCounter | |
Set Ed Timer to GAME_TIME | |
if hour glass is at low position | |
Command HourGlass servo to rotate to high position (0 deg) | |
Set HourGlassPosition = high | |
else | |
Command HourGlass servo to rotate to low position (180 deg) | |
Set HourGlassPosition = low | |
endif | |
Set Pipe Timer to 16 seconds | |
Set Start Button LED pin low | |
Set CurrentState = PlayingGame | |
break | |
case PlayingGame: | |
if event is an ed timer timeout | |
Post GAMEOVER event to all relevant services | |
Store the cumulated score in a static variable | |
if score is lower than GoodScore (golf scoring) | |
Move to CelebrationMode state | |
Set timer to 10 ms | |
else | |
Move to FailureMode state | |
Set timer to 10 ms | |
endif | |
Command Ed Arm servo to point at LCD | |
else if (ThisEvent.EventType == ES_LOST_POINT){ | |
Update score on LCD every time a point is lost | |
Send message to LCD via LCDMessage service | |
endif | |
break | |
case CelebrationMode1: | |
if event is an ed timer timeout | |
Send message to LCD via LCDMessage service | |
Set 5V line high | |
Send tunes to audio services | |
Set timer to a half second | |
Set CurrentCelebState = Red | |
Set CelebCounter to 0 | |
Set timer to 30 seconds for celebration mode | |
else if event is a start button timer timeout | |
if 30 seconds haven't passed yet | |
if CurrentCelebState is red | |
Set LightShowREDLED pin low | |
Set LightShowBLUELED pin high | |
Command ed's arm to point at the start button | |
Set StartButtonLED timer to a half second minus time taken to move servo (roughly 4 ms) | |
Set CurrentCelebState to blue (blue = 1) | |
else | |
Set LightShowBLUELED low | |
Set LightShowREDLED high | |
Command ed's arm to point at the LCD | |
Set StartButtonLED timer to a half second minus time taken to move servo (roughly 4 ms) | |
Set CurrentCelebState to red (red = 0) | |
endif | |
Increment CelebCounter | |
else | |
Turn off LEDs | |
Move to Ready2Arm state | |
endif | |
endif | |
break | |
case FailureMode1: | |
if event is an ed timer timeout | |
Send failure event to LCDMessage service | |
Send tunes to audio services | |
Set Timer to 10 seconds for failure mode | |
Move to Ready2Arm state | |
endif | |
break | |
case Ready2Arm: | |
if event is an ed timer timeout | |
Move to ArmedMode state | |
Set timer ro 10 ms | |
endif | |
break | |
end switch case | |
Return ES_NO_EVENT | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment