/* Program combining test-to-speech capabilities
 * with Scribbler 2 motion and sound
 *
 * Part 1: robot moves forward and right three times 
 *         while playing an ascending musical chord 
 * Part 2: robot moves forward and left three times 
 *         while playing a descending musical chord
 * Part 3: repeats Part 1
 *
 * Author:  Henry M. Walker
 * Date created:  12 May 2016
 * 
 */

#include "eSpeakPackage.h"
#include "MyroC.h"
#include <stdio.h>

/* List musical notes for a C chord */
const int pitchC6 = 1047;
const int pitchE6 = 1319;
const int pitchG6 = 1568;
const int pitchC7 = 2092;

int main ()
{
  // connect for both MyroC and eSpeak
  rConnect ("/dev/rfcomm0");
  eSpeakConnect ();

  /* Part 1: robot moves forward and right three times 
             while playing an ascending musical chord 
  */
  printf ("starting Part 1\n");
  eSpeakTalk ("move forward and turn right");
  /* rForward, rTurnRight, rTurnLeft require speed and duration
     max speed forward is 1.0
     duration in seconds
  */
  rForward (1.0, 1.0);
  rBeep (0.5, pitchC6);
  rTurnRight (0.7, 0.75);
  
  eSpeakTalk ("move forward and turn right again");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchE6);
  rTurnRight (0.7, 0.5);
  
  eSpeakTalk ("move and turn a third time");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchG6);
  rTurnRight (0.7, 0.25);

  rBeep (0.5, pitchC7);

  /* Part 2: robot moves forward and left three times 
             while playing a descending musical chord 
  */
  eSpeakSetGender ("female");  // specify voice characteristics
  printf ("starting Part 2\n");
  eSpeakTalk ("move forward and turn left");

  rForward (1.0, 1.0);
  rBeep (0.5, pitchC7);
  rTurnLeft (0.7, 0.25);
  
  eSpeakTalk ("move forward and turn left again");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchG6);
  rTurnLeft (0.7, 0.5);
  
  eSpeakTalk ("move and turn a third time");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchE6);
  rTurnLeft (0.7, 0.75);

  rBeep (0.5, pitchC6);

  /* Part 3: robot moves forward and right three times 
             while playing an ascending musical chord 
  */
  eSpeakSetGender ("male");  // specify voice characteristics
  printf ("starting Part 3\n");
  eSpeakTalk ("Part 3 repeats Part 1");
  
  eSpeakTalk ("move forward and turn right");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchC6);
  rTurnRight (0.7, 0.75);
  
  eSpeakTalk ("move forward and turn right again");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchE6);
  rTurnRight (0.7, 0.5);
  
  eSpeakTalk ("move and turn a third time");
  rForward (1.0, 1.0);
  rBeep (0.5, pitchG6);
  rTurnRight (0.7, 0.25);

  rBeep (0.5, pitchC7);

  // finish with no errors
  eSpeakTalk ("Enough of this; I am going to stop now");
  rDisconnect ();
  eSpeakDisconnect ();

  return 0;
}
