//-*-c++-*-

/* ParallelBehavior.h.fsm
 * Code for HW1 question 3. Flashes a sequence of LEDs (red, yellow, green,
 * blue) in parallel with playing three sounds. A green button press
 * reverses both sequences.
 * @author David Klionsky (dklionsk)
 */

#ifndef INCLUDED_ParallelBehavior_h_
#define INCLUDED_ParallelBehavior_h_
 
#include "Behaviors/StateMachine.h"
#include "Events/EventRouter.h"

class ParallelBehavior : public StateNode {

public:
  ParallelBehavior() : StateNode("ParallelBehavior") {}
 
  virtual void setup() {
#statemachine

startnode: StateNode =N=> {redFlash, barkLow}

redFlash: LedNode [getMC()->flash(RobotInfo::RedLEDMask, 1000);] =C=>
yellowFlash: LedNode [getMC()->flash(RobotInfo::YellowLEDMask, 1000);] =C=>
greenFlash: LedNode [getMC()->flash(RobotInfo::GreenLEDMask, 1000);] =C=>
blueFlash: LedNode [getMC()->flash(RobotInfo::BlueLEDMask, 1000);] =C=> redFlash

bredFlash: LedNode [getMC()->flash(RobotInfo::RedLEDMask, 1000);] =C=>
bblueFlash: LedNode [getMC()->flash(RobotInfo::BlueLEDMask, 1000);] =C=>
bgreenFlash: LedNode [getMC()->flash(RobotInfo::GreenLEDMask, 1000);] =C=>
byellowFlash: LedNode [getMC()->flash(RobotInfo::YellowLEDMask, 1000);] =C=> bredFlash

redFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> bblueFlash
bblueFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> redFlash
yellowFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> bredFlash
bredFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> yellowFlash
greenFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> byellowFlash
byellowFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> greenFlash
blueFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> bgreenFlash
bgreenFlash =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> blueFlash

barkLow: SoundNode($, "barklow.wav") =T(1000)=>
barkMed: SoundNode($, "barkmed.wav") =T(1000)=>
barkHigh: SoundNode($, "barkhigh.wav") =T(1000)=> barkLow

bbarkHigh: SoundNode($, "barkhigh.wav") =T(1000)=>
bbarkMed: SoundNode($, "barkmed.wav") =T(1000)=>
bbarkLow: SoundNode($, "barklow.wav") =T(1000)=> bbarkHigh

barkLow =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> bbarkHigh
barkMed =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> bbarkLow
barkHigh =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> bbarkMed
bbarkLow =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> barkMed
bbarkMed =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> barkHigh
bbarkHigh =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> barkLow

#endstatemachine
  }       // end of setup()

};

#endif
