Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Controls the distribution of events and services to the rest of the software
MODULE VARIABLES
CurrentState
MyPriority
GrowingBranch
InitTreeSM
Parameters:
Priority number of this service
Returns:
success/failure
Local Variables: Pseudo-code:
Set CurrentState to InitTSM
Post ES_INIT Event to this service
PostTreeSM
Parameters:
Returns:
Local Variables: Pseudo-code:
ES_PostToService
Return success/failure
RunTreeSM
Parameters:
Returns:
Local Variables:
ThisEvent
ReturnEvent
ReturnEvent
PostEvent
Pseudo-code:
SWITCH CurrentState
CurrentState is InitTSM
IF ThisEvent is ES_INIT
Set CurrentState to WaitingForArtist
Post WAITING event to this service
END IF
CurrentState is WaitingForArtist
IF ThisEvent is WAITING
Post WAITING event to motor, audio, and start buttons
END IF
IF ThisEvent is DONE_REPLAYING
Post WELCOME_REPLAY to Branch Service
END IF
IF ThisEvent is BTN_START
Set SEASON_TIMER for fraction of a second
Post RESET Event to branch and motor services
END IF
IF ThisEvent is ES_TIMEOUT and timer is SEASON_TIMER
Set CurrentState to Spring
Switch ThisEvent
ThisEvent is ES_TIMEOUT
IF ThisEvent Param is SEASON_TIMER
Set CurrentState to FallGrowing
Call ChangeSeasonTo function with parameter FALL
ELSE IF ThisEvent Param is GROWING_TIMER
Call HandleGrow function
END IF
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter SUMMER
ThisEvent is PROX_FAR with param for which sensor
Set CurrentState to Summer
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter of ThisEvent
END SWITCH
CurrentState is Fall
Switch ThisEvent
ThisEvent is ES_TIMEOUT and timer is SEASON_TIMER
Set CurrentState to Winter
Call ChangeSeasonTo function with parameter WINTER
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter FALL
ThisEvent is PROX_NEAR
Set CurrentState to FallGrowing
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter ThisEvent
END SWITCH
CurrentState is FallGrowing
Switch ThisEvent
ThisEvent is ES_TIMEOUT
If ThisEvent Param is SEASON_TIMER
Set CurrentState to WinterGrowing
Call ChangeSeasonTo function with parameter
WINTER
Elseif ThisEvent Param is GROWING_TIMER
Call HandleGrow function
Endif
ThisEvent is BTN_WEATHER
Call HandleWeather function with parameter FALL
ThisEvent is PROX_FAR
Set CurrentState to Fall
Call HandleProx function with parameter of ThisEvent
ThisEvent is ANALOG_CHANGE
Call HandleAnalog function with parameter of ThisEvent
END SWITCH
CurrentState is Winter
Switch ThisEvent
HandleWeather
Parameters:
Returns:
Local Variables:
Season
-
Current season
Pseudo-code:
Post WEATHER event to Audio and Branch Service with EventParam Season
HandleProx
Parameters:
ThisEvent
A proximity sensor event
Returns:
Local Variables: Pseudo-code:
IF ThisEvent is PROX_NEAR
Store the growing branch in GrowingBranch from the event parameter
Call ChangeVibrationMotor with parameter ON
Set GROWING_TIMER for GROWING_TIME
ELSE IF ThisEvent is PROX_FAR
Call ChangeVibrationMotor with parameter OFF
END IF
HandleAnalog
Parameters:
ThisEvent
Analog event
Returns:
Local Variables: Pseudo-code:
Call SetNewColorLimit function with parameter ThisEvent.EventParam
ChangeSeasonTo
Parameters:
Season
Current season
Returns:
Local Variables: PostEvent
Event to post to other services
Pseudo-code:
Post SEASON_CHANGE event with EventParam Season to Branch Service
If CurrentState is not ReplayTree
Set SEASON_TMER for SEASON_TIME
Endif
HandleGrow
Parameters:
Returns:
Local Variables: PostEvent
Event to post to other services
Pseudo-code:
Post GROW event with EventParam GrowingBranch to BranchService
Set GROWING_TIMER for GROWING_TIME