You are on page 1of 2

SenseWind.

c Pseudocode
Definitions
WINDPORT, definition of the port pin being used to read the windmill s ana
log output
Definitions for this pin being high and low
checkTime, how often to check the state of the pin
AnalogNoWind, the analog output when the windmill is not turning
AnalogMaxWind, the minimum analog output, windmill is turning full speed
MaxWindValue, the maximum wind event parameter value
minWindChange, the minimum wind change (read from pin) before we post ano
ther wind event
lightningWindThreshold, the threshold wind speed for a lightning event
Module Level Variables
uint8_t MyPriority to store priority number
WindSMState_t CurrentState to store the state of the wind state machine
(SM)
uint16_t LastWindValue to store the last wind value read from the pin
InitializeWindReader
Accepts a uint8_t specifying priority, returns True
Set the module level service priority to the passed-in parameter
Set the module-level current Wind SM state to the inactive, before-windscene state
Return True
End InitializeWindReader
PostWindReaderService
Accepts an ES_Event type event, returns True if the event is successfull
y posted, false otherwise
Post the passed-in event to the windReader service using its posting fun
ction
Return True if the event is successfully posted, false otherwise
End PostWindReaderService
readWindSpeed
Accepts an ES_Event, returns an event of type no-event
Declare a variable storing the next Wind SM state, and set it equal to t
he current state
Declare a return ES_Event type variable, and set its type to no-event
Declare a variable to store any new events
Switch statement
If the case is the inactive, before-wind-scene state
If the event is an ES_OPEN type event (curtain opened)
Set the next state equal to the active windScene
state
Set a timer to check the state of the pin
Endif
Break out of the case
If the case is the active windScene state
Declare a variable to store the current pin state
Declare a variable to store the current wind state out o
f 255 (uint8_t)
If the event is an ES_TIMEOUT event and the parameter is
of the wind timer
Get the current pin state
If the current pin state is higher than the maxi
mum value allowed
Set it equal to the maximum value allowe
d
If the current pin state is lower than the minim

um value allowed
Set it equal to the minimum value allowe
d
Scale the current pin state to be out of 255, inverting to make 255 high wind sp
eeds and 0 low wind speeds
Take the absolute value of the current pin less the last pin value
If this difference is greater than the minimum threshold for wind event
Set the new event type to an ES_WIND event
Set its parameter equal to the uint8_t wind speed
Post the event to the story SM
Set the last pin value to the current pin value
If the wind speed exceeds the lightning threshold
Declare an ES_Event variable of type ES_LIGHTNING
Post it to the weather service
Post it to the audio service
End if
End if
Set a timer to check the state of the wind pin
Set the next state to be the active wind scene state
If the event is an ES_GROW type event
Set the next state to the inactive, before-wind-scene state
If the event is an ES_RESET type event
Set the next state to the inactive, before-wind-scene state
End if
Break out of the case
End switch statement
Set the current state equal to the next state
Return an ES_Event of type no-event
End readWindSpeed

You might also like