#include "MyroC.h"
#include <stdio.h>   // for printf function
#include <unistd.h>  // for sleep function
//Picture pic1, pic2, pic3, pic4;

int main ()
{
  Picture pic, picalt;

  //rConnect ("/dev/rfcomm0");
  //rConnect ("00:1E:19:01:0E:8C"); // robot at workstation even
  //rConnect ("365827"); // robot at workstation even
  //rConnect ("B4:D8:A9:00:09:09"); // robot at workstation curry
  //rConnect ("B4:D8:A9:00:09:58"); // robot at workstation perlis
  //rConnect ("B4:D8:A9:00:09:13"); // robot at workstation wilkes
  //rConnect ("B4:D8:A9:00:09:1B"); // robot at workstation loaner-1
  //rConnect ("B4:D8:A9:00:09:09"); // robot at workstation loaner-2
  //rConnect ("B4:D8:A9:00:09:22"); // robot at workstation loaner-3
  //rConnect ("B4:D8:A9:00:0D:40"); // robot at workstation loaner-4
  rConnect ("B4:D8:A9:00:09:50"); // robot at workstation loaner-4

  printf ("program to test taking, saving, and displaying camera images\n");
  printf ("play beep before taking, saving, and displaying each picture\n");

  rBeep (1.0, 1000);
  pic = rTakePicture(); 
  printf ("picture taken; saving in picture1.jpg\n");
  rSavePicture (&pic, "picture1.jpg");
  printf ("BLOCKING\n");
  rDisplayPicture (&pic, 25, "pic1");

 
  rBeep (1.0, 1100);
  rTurnRight (0.25, 0.25);

  pic = rTakePicture(); 
  printf ("second picture taken; saving in picture2.jpg\n");
  rSavePicture (&pic, "picture2.jpg");
  printf ("TIMED, NON-BLOCKING\n");
  rDisplayPicture (&pic, -25, "pic2");

  rBeep (1.0, 1200);
  rTurnRight (0.25, 0.25);

  pic = rTakePicture(); 
  printf ("third picture taken; saving in picture3.jpg\n");
  rSavePicture (&pic, "picture3.jpg");
  printf ("NON-TIMED, NON-BLOCKING\n");
  rDisplayPicture (&pic, 0, "pic3");

  rBeep (1.0, 1300);
  rTurnRight (0.25, 0.25);

  picalt = rTakePicture(); 
  printf ("fourth picture taken; saving in picture4.jpg\n");
  rSavePicture (&picalt, "picture4.jpg");
  rDisplayPicture (&picalt, 5, "pic4");

  rBeep (1.0, 1400);

  printf ("modify picture3\n");

  printf ("picture display completed\n");
  Pixel black = {0, 0, 0}; 

  int i, j;
  for (i = 0; i < 100; i++)
    for (j = 0; j < 100; j++)
      {
        pic.pix_array[i][j] = black;
      }

  printf ("replace picture 3 with black corner\n");
  rDisplayPicture (&pic, 25, "pic3");

  sleep (1);
  
  rDisconnect();

    return 0;
}
