Professional Documents
Culture Documents
c
\\ Implements SM that controls music, hand backlight, indicator LEDs and reads the
headphone state
PostMusicSequence
Takes Event, returns True
CurrentState is WelcomeState
If ThisEvent is HEADPHONES_LIFTED
Write headphone LED OFF
Set timer for welcome clip
Set CurrentState to FirstDebounceHeadphones
EndIf
break
EndBlock
CurrentState is FirstDebounceHeadphones:
If ThisEvent is ES_TIMEOUT and parameter is IntroDelayTimer
Write the Welcome audio clip
Set timer for length of audio LO pulse
ElseIf ThisEvent is ES_TIMEOUT and parameter is AudioPulseTimer
Set all triggers back HI
PostEvent WELCOME_AUDIO to Car service
Turn on car LED
Set CurrentState to WaitForCar
ElseIf ThisEvent is HEADPHONES_PLACED
PostEvent EARLY_RESET to all services
Set ResetEarly to 1
Set CurrentSTate to WaitForHeadphonesMusic
EndIf
Break
EndBlock
CurrentState is WaitForCar
If ThisEvent is CAR_PLACED
Write CarMount LED OFF, HandBackLight LED ON and ButtonLED[NoteIndex] ON
Set CurrentState to WaitForNote
CurrentState is WaitForNote
If ThisEvent is CORRECT_NOTE[NoteIndex != MAXNOTES]
Write PWM Tone channel to 50% duty cycle with frequency of NoteTones[NoteIndex]
Set NoteTimer with duration NoteDurations[NoteIndex]
Turn off last button
PostEvent CORRECT_NOTE to Car service
NoteIndex++
CurrentState is WaitForAttack
If ThisEvent is ES_TIMEOUT and EventParam is NoteTimer
Write PWM Tone channel to 0 duty cycle
CurrentState is WaitForHeadphonesMusic
If ThisEvent is HEADPHONES_PLACED or ResetEarly equals 1
Set HeadphoneDelay Timer
Set CurrentState to DebounceHeadphones
ElseIf ThisEvent is ES_TIMEOUT and EventPAram is AudioPulseTimer
Set all triggers back HI
End if
break
EndBlock
CurrentState is DebounceHeadphones
If EventType is ES_TIMEOUT and EventParam is HeadphoneTimer
If ResetEarly is zero
PostEvent HEADPHONES_RESET to all services
EndIf
Set ResetEarly to zero
Set CurrentState to WelcomeState
Turn on headphone LED
Set all triggers back HI
Set NoteIndex to zero
End If
break
EndBlock
END of RunMusicSequence
Check4Headphones
Takes no parameters, returns True if an event was posted
LocalVariables: ReturnValue = False, CurrentHeadphoneState
End if
Set ReturnValue = True
End if
END of Check4Headphones
If CurrentButtonStates == Buttons[NoteIndex]
PostEvent CORRECT_NOTE to MusicSequence Service and Idle Service
ReturnValue = True
EndIf
EndIf
END of Check4Notes