0% found this document useful (0 votes)
91 views3 pages

Pseudoleaf

The document describes pseudo-code for a Leaf module that implements a state machine. The Leaf module has four states - InitLeafState, NoLeaf, LeafNotDone, and LeafDone. It uses events to transition between states. Based on the current state and incoming event, the code will perform actions like changing LED lights, starting/stopping timers, opening/closing a leaf servo, and posting new events.

Uploaded by

api-437846864
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views3 pages

Pseudoleaf

The document describes pseudo-code for a Leaf module that implements a state machine. The Leaf module has four states - InitLeafState, NoLeaf, LeafNotDone, and LeafDone. It uses events to transition between states. Based on the current state and incoming event, the code will perform actions like changing LED lights, starting/stopping timers, opening/closing a leaf servo, and posting new events.

Uploaded by

api-437846864
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

*************************************************************************************

Pseudo-code for the Leaf module (a service that implements a state machine)

InitializeLeaf
Takes a priority number, returns True.

Initialize the MyPriority variable with the passed in parameter.


Set LastInputState to current LEAF state
Set CurrentState to be InitLeaf
Post Event ES_INIT to Leaf queue (this service)
End of InitializeLeaf

CheckLeafEvents
Takes no parameters, returns True if an event was posted
Local ReturnVal = False, CurrentInputState

Get the CurrentInputState from the input line


If the state of the Leaf input line has changed
If the current state of the input line is low
If CurrentState is not InitLeafState
Post ES_LEAF_INSERTED event to this service
EndIf
Else (current input state is high)
If Current State is not InitLeafState
Post ES_LEAF_REMOVED event to this service
EndIf
EndIf
Set ReturnVal = True
EndIf
Set LastInputState to CurrentInputState
Return ReturnVal
End of CheckLeafEvents

RunLeafSM (implements the state machine for Leaf module)


Set ReturnEvent to ES_NO_EVENT

LocalVariables: NextState

Set NextState to CurrentState


Based on the state of the CurrentState variable choose one of the following blocks of code:

CurrentState is InitLeafState
If ThisEvent is ES_INIT
Close LEAF servo
Post event to LEDStrip to change lights for leaf actions
Set NextState to NoLeaf
EndIf
If ThisEvent is ES_RESET_BUTTON
Close LEAF servo
Post event to LEDStrip to change lights for leaf actions
EndIf
End InitLeaf block

CurrentState is NoLeaf
If ThisEvent is ES_LEAF_INSERTED
Post event to LEDStrip for LeafInserted
Start ACTIVITY_TIMER to 30s
Set NextState to LeafNotDone
EndIf
End NoLeaf block

CurrentState is LeafNotDone
If ThisEvent is ES_LEAF_REMOVED
If TurnTableSM is in Motion
Post LEDStrip event for LeafRemovedEarly
Post ES_GAME_LOST to List1
Set NextState to InitLeafState
Else
Post LEDStrip event for initial leaf
Set NextState to NoLeaf
Stop ACTIVITY_TIMER
Post ES_RESET_BUTTON to List 1 to simulate a reset
EndIf
EndIf
If ThisEvent is ES_GAME_LOST
Start LEAF_SERVO_TIMER to LEAF_SERVO_DELAY
Set NextState to LeafDone
EndIf
If ThisEvent is ES_GAME_WON
Start LEAF_SERVO_TIMER to LEAF_SERVO_DELAY
Set NextState to LeafDone
EndIf
If ThisEvent is ES_RESET_BUTTON
Post to LEDStrip LeafRemovedEarly
Set NextState to InitLeafState
EndIf
If ThisEvent is ES_TIMEOUT and parameter is ACTIVITY_TIMER
Post ES_GAME_LOST event to List1
Set LED strip to ActivityTimeout
Set NextState to InitLeafState
EndIf
End LeafNotDone block

CurrentState is LeafDone
If ThisEvent is ES_LEAF_REMOVED
Post to LEDStrip a RESET_NEEDED_LIGHT_TYPE event with param
RESET_NEEDED LIGHT_COLOR
Set NextState to NoLeaf
EndIf
If ThisEvent is ES_RESET_BUTTON
Post LEDStrip RESET_NEEDED_LIGHT_TYPE with param
RESET_NEEDED_LIGHT_COLOR
Set NextState to InitLeafState
EndIf
If ThisEvent is ES_TIMEOUT and parameter is LEAF_SERVO_TIMER
Open Leaf servo
EndIf
End LeafDone block

Set CurrentState to NextState

Return ReturnEvent
End of RunLeafSM

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy