//-*-c++-*-
#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() {
    std::cout << getName() << " is setting up the state machine." << std::endl;

#statemachine

forkJoinBegin: StateNode =N=>{red1, howl1}

//States

//-- Cycle
red1: LedNode [getMC()->cset(RobotInfo::RedLEDMask, 1.0);]

howl1: SoundNode($, "howl.wav")

yellow1: LedNode [getMC()->cset(RobotInfo::YellowLEDMask, 1.0);]

barklow1: SoundNode($, "barklow.wav")

green1: LedNode [getMC()->cset(RobotInfo::GreenLEDMask, 1.0);]

ping1: SoundNode($, "ping.wav")

blue1: LedNode [getMC()->cset(RobotInfo::BlueLEDMask, 1.0);]

toc1: SoundNode($, "toc.wav")

//-- Inverse Cycle

red2: LedNode [getMC()->cset(RobotInfo::RedLEDMask, 1.0);]

howl2: SoundNode($, "howl.wav")

yellow2: LedNode [getMC()->cset(RobotInfo::YellowLEDMask, 1.0);]

barklow2: SoundNode($, "barklow.wav")

green2: LedNode [getMC()->cset(RobotInfo::GreenLEDMask, 1.0);]

ping2: SoundNode($, "ping.wav")

blue2: LedNode [getMC()->cset(RobotInfo::BlueLEDMask, 1.0);]

toc2: SoundNode($, "toc.wav")

//Transitions
//--Cycle
{red1, howl1} =C(1)=> {yellow1, barklow1}

{yellow1, barklow1} =C(1)=> {green1, ping1}

{green1, ping1} =C(1)=> {blue1, toc1}

{blue1, toc1} =C(1)=> {red1, howl1}

//--Inverse cycle
{red2, howl2} =C(1)=> {blue2, toc2} 

{yellow2, barklow2} =C(1)=> {red2, howl2}

{green2, ping2} =C(1)=> {yellow2, barklow2} 

{blue2, toc2} =C(1)=> {green2, ping2}

//--Button press invert cycle to cycle
{red2, howl2} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {yellow1, barklow1}

{yellow2, barklow2} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {green1, ping1}

{green2, ping2} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {blue1, toc1}

{blue2, toc2} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {red1, howl1}

//--Button press cycle to invert cycle
{red1, howl1} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {blue2, toc2} 

{yellow1, barklow1} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {red2, howl2}

{green1, ping1} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {yellow2, barklow2} 

{blue1, toc1} =E(buttonEGID, RobotInfo::GreenButOffset, activateETID)=> {green2, ping2}

#endstatemachine

    startnode=forkJoinBeginset;

  }

virtual void DoStart() {
    std::cout << getName() << " is starting up." << std::endl;
  }
  
  virtual void DoStop() {
    std::cout << getName() << " is shutting down." << std::endl;
  }
  
 private:  // Dummy methods to satisfy the compiler
  ForkJoinBehavior(const ForkJoinBehavior&);
  ForkJoinBehavior& operator=(const ForkJoinBehavior&);
  
};

#endif
