Tree MODULE PSEUDOCODE
Tree Module
define static variable: currentPins
define static variable: pinCounter=0
define static variable: numOfPins=10 //however many hooks you want to use
static array of masks defining how LEDs correspond to hooks: MASK[numOfPins]
InitTree takes nothing, returns true
initialize I/O pins
set up array of masks to light LEDs
set currentState to TreeInit
return True
End of InitTree
RunTree takes events
If currentState is TreeInit
If EventType is ES_INIT
currentState=WaitForTree
End if
End if
If currentState is WaitForTree
If EventType is ES_CARD_READ
currentState=TreeActive
End if
If EventType is ES_CARD_REMOVED
reset tree, currentState = WaitForTree
End if
If currentState is TreeActive
If EventType is ES_PIN_CHANGE
If the next pin is low, write the next mask to the shift registers, and increment the pin count
If pinCounter==numOfPins
currentState=TreeDone
post ES_TREE_DONE to bear module
If EventType is ES_CARD_REMOVED
reset tree, currentState=WaitForTree
End if
End if
End if
End if
End if
End if
If currentState is IDLE
If EventType is ES_CARD_REMOVED
reset tree, currentState = WaitForTree
End if
End if
End of RunTree
define static variable: currentPins
define static variable: pinCounter=0
define static variable: numOfPins=10 //however many hooks you want to use
static array of masks defining how LEDs correspond to hooks: MASK[numOfPins]
InitTree takes nothing, returns true
initialize I/O pins
set up array of masks to light LEDs
set currentState to TreeInit
return True
End of InitTree
RunTree takes events
If currentState is TreeInit
If EventType is ES_INIT
currentState=WaitForTree
End if
End if
If currentState is WaitForTree
If EventType is ES_CARD_READ
currentState=TreeActive
End if
If EventType is ES_CARD_REMOVED
reset tree, currentState = WaitForTree
End if
If currentState is TreeActive
If EventType is ES_PIN_CHANGE
If the next pin is low, write the next mask to the shift registers, and increment the pin count
If pinCounter==numOfPins
currentState=TreeDone
post ES_TREE_DONE to bear module
If EventType is ES_CARD_REMOVED
reset tree, currentState=WaitForTree
End if
End if
End if
End if
End if
End if
If currentState is IDLE
If EventType is ES_CARD_REMOVED
reset tree, currentState = WaitForTree
End if
End if
End of RunTree