/*
general-test.c
MyroC general commands testing
Written by Spencer B Liberto
Written on Oct 12, 2013

Testing for the following general MyroC commands:
    rConnect
    rDisconnect
    rBeep
    rBeep2
    rSetName
    rGetName
    rSetLEDFront
    rSetLEDBack
    rGetBattery 

  
   This program and all MyroC software is licensed under the Creative Commons
   Attribution-Noncommercial-Share Alike 3.0 United States License.
   Details may be found at http://creativecommons.org/licenses/by-nc-sa/3.0/us/
 */

#include <stdio.h>
#include <libc.h>           // needed for sleep command
#include "eSpeakPackage.h"
#include "MyroC.h"



int main(){

  eSpeakConnect();
  eSpeakSetGender("female");
  
  printf("Test 1 - Initial rConnect\n");
  eSpeakTalk("1 Initial r Connect");
  rConnect("/dev/rfcomm0");
  sleep(1);

  printf("Test 2 - Extra rConnect\n");
  eSpeakTalk("2 Extraneous rConnect");
  rConnect("/dev/rfcomm0");
  sleep(1);

  printf("Test 3 - Disconnect\n");
  eSpeakTalk("3 r Disconnect");
  rDisconnect();
  sleep(1);

  printf("Test 4 - Reconnect\n");
  eSpeakTalk("4 third r connect");
  rConnect("/dev/rfcomm0");
  sleep(2);

  printf("Test 5 - rBeep: Play notes of decreasing frequency and length.\n");
  eSpeakTalk("5 Playing single notes of decreasing frequenecies and lengths");
  rBeep(5.0,800);
  rBeep(4.0,700);
  rBeep(3.0,600);
  rBeep(2.0,550);
  rBeep(1.0,500);
  rBeep(0.1,450);
  sleep(1);

  eSpeakSetGender("male");
  printf("Test 6 - rBeep2 \n");
  eSpeakTalk("6 Playing double notes of decreasing frequencies and lengths");
  rBeep2(5.0,800,1200);
  rBeep2(4.0,700,1150);
  rBeep2(3.0,600,900);
  rBeep2(2.0,550,825);
  rBeep2(1.0,500,750);
  rBeep2(0.1,450,675);
  sleep(15);

  printf("Test 7 - rSetName and rGetName.\n");
  eSpeakTalk("7 Testing r Set Name and r Get Name\n");
  rSetName("");
  printf("Got %s, expected blank name\n", rGetName());
  rSetName("abcde");
  printf("Got %s, expected abcde\n", rGetName());
  rSetName("abcdefghij");
  printf("Got %s, expected abcdefghij\n", rGetName());
  rSetName("abcdefghijklmnopqrstuvwxyz");
  printf("Got %s, expected abcdefghijklmnop\n", rGetName());
  rSetName("abc\0def");
  printf("Got %s, expected abc\n", rGetName());
  sleep(1);
    
  printf("Test 8 - rSetLEDFront.\n");
  eSpeakTalk("8 Testing r set l e d front");
  eSpeakTalk("Turning front l e dees on");
  rSetLEDFront(1);
  sleep (1);
  eSpeakTalk("Turning front l e dees on extraneously");
  rSetLEDFront(1);
  sleep (1);
  eSpeakTalk("Turning front l e dees off");
  rSetLEDFront(0);
  sleep (1);
  eSpeakTalk("Turning front l e dees off extraneously");
  rSetLEDFront(0);
  sleep (1);

  printf("Test 9 - rSetLEDBack.\n");
  eSpeakTalk("9 Testing r set l e d back");
  eSpeakTalk("Back LED to progress from bright to dim");
  int i;
  double parm;
  for (i = 10; i >= 0; i--)
    {
      parm = i / 10.0;
      printf ("setting back LED to intensive %lf \n", parm);
      rSetLEDBack (parm);
      rBeep (0.5, 880 + 20*i);
      sleep (1);
    }
  sleep(1);

  //rGetBattery should be tested between multiple robots
  printf("Test 10 - getBattery .\n");
  eSpeakTalk("10 - Testing get battery");
  eSpeakTalk("The test for r get battery is performed five times");
  for (i = 0; i < 5; i++)
    printf("battery level %lf test\n", rGetBattery());
  sleep(1);
  
  eSpeakTalk("Testing complete Tests were succesful");
  /* sound distinctive opening tones */
    rBeep(.03, 784);
    rBeep(.03, 880);
    rBeep(.03, 698);
    rBeep(.03, 349);
    rBeep(.03, 523);

  eSpeakDisconnect();


  return 0;
}
