//-*-c++-*-

/* BlinkBehavior.h.fsm
 * Code for HW1 question 4. Plays 4 sounds synchronously with 4 LED lights.
 * Pressing the green button reverses the sequence.
 * @author David Klionsky (dklionsk)
 */

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

class ForkJoinBehavior : public StateNode {

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

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

redFlash: LedNode [getMC()->cset(RobotInfo::RedLEDMask, 1.0);]
yellowFlash: LedNode [getMC()->cset(RobotInfo::YellowLEDMask, 1.0);]
greenFlash: LedNode [getMC()->cset(RobotInfo::GreenLEDMask, 1.0);]
blueFlash: LedNode [getMC()->cset(RobotInfo::BlueLEDMask, 1.0);]

bredFlash: LedNode [getMC()->cset(RobotInfo::RedLEDMask, 1.0);]
bblueFlash: LedNode [getMC()->cset(RobotInfo::BlueLEDMask, 1.0);]
bgreenFlash: LedNode [getMC()->cset(RobotInfo::GreenLEDMask, 1.0);]
byellowFlash: LedNode [getMC()->cset(RobotInfo::YellowLEDMask, 1.0);]

redSound: SoundNode($, "howl.wav")
yellowSound: SoundNode($, "barklow.wav")
greenSound: SoundNode($, "ping.wav")
blueSound: SoundNode($, "toc.wav")

bredSound: SoundNode($, "howl.wav")
byellowSound: SoundNode($, "barklow.wav")
bgreenSound: SoundNode($, "ping.wav")
bblueSound: SoundNode($, "toc.wav")

{redSound, redFlash} =C(1)=> {yellowFlash, yellowSound}
{yellowSound, yellowFlash} =C(1)=> {greenFlash, greenSound}
{greenSound, greenFlash} =C(1)=> {blueFlash, blueSound}
{blueSound, blueFlash} =C(1)=> {redFlash, redSound}

{byellowSound, byellowFlash} =C(1)=> {bredFlash, bredSound}
{bgreenSound, bgreenFlash} =C(1)=> {byellowFlash, byellowSound}
{bblueSound, bblueFlash} =C(1)=> {bgreenFlash, bgreenSound}
{bredSound, bredFlash} =C(1)=> {bblueFlash, bblueSound}

{redSound, redFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {bblueFlash, bblueSound}
{yellowSound, yellowFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {bredFlash, bredSound}
{greenSound, greenFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {byellowFlash, byellowSound}
{blueSound, blueFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {bgreenFlash, bgreenSound}

{bredSound, bredFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {yellowFlash, yellowSound}
{byellowSound, byellowFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {greenFlash, greenSound}
{bgreenSound, bgreenFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {blueFlash, blueSound}
{bblueSound, bblueFlash} =E(buttonEGID, ChiaraInfo::GreenButOffset, activateETID)=> {redFlash, redSound}

#endstatemachine
  }       // end of setup()

};

#endif
