/* Program to demonstrate storing pictures in a linked list */

#include <MyroC.h>
#include <stdio.h>
#include <stdlib.h>

/* ----------------  data definitions  -------------------*/
typedef struct node movieNode;

struct node {
  Picture pic;
  movieNode* next;
};

/* ----------------  function prototypes -------------------*/

/* add a given picture to the end of the movieList specified by first algorithm:
      a new node is created
         the pic field of the node is set to frame
         the next field is set to NULL
      if first is NULL, first is changed to point to the new node
      otherwise, the next field of the last node is set to the new node
*/
void
addPicture (movieNode** first, Picture frame);

/* the movie is printed from first item to last, with a short delay
   between successive frames */
void
printForward (const movieNode* first);

/* the movie is printed from last item to first, with a short delay
   between successive frames */
void
printReverse (const movieNode* first);

/* -------------------  main program ----------------------*/

/* program that makes a movie*/ 
int
main(void)
{
  printf("Starting program:  ");
  rConnect("/dev/rfcomm0");
  rSetForwardness("fluke-forward");

  printf("program asking Scribbler 2 to take and display pictures\n");
  /* determine how many pictures */

  movieNode* movie = NULL;  /* the initial movie list contains no pictures */
  int numPics = 0;          /* counter for the number of pictures */

  /* take pictures until program aborted */
  while (1) 
    {
      /*take picture and turn left a little */
      Picture frame = rTakePicture();
      rTurnLeft(0.3, 0.3);

      /* add frame to movie */
      addPicture(&movie, frame);
      numPics++;

      /* display move forward and backward every 10 frames */
      if (numPics % 10 == 0)
        {
          printForward(movie);
          printReverse(movie);
        }
    }

  /* the following lines look nice, but they are never executed 
     because the main loop does not terminate */
  printf ("Closing connection to robot....");
  rDisconnect();
  printf (" finished.\n\n");
} // main
 
/* ------------------  function details --------------------*/

/* add a given picture to the end of the movieList specified by first 
   algorithm:
      a new node is created
         the pic field of the node is set to frame
         the next field is set to NULL
      if first is NULL, first is changed to point to the new node
      otherwise, the next field of the last node is set to the new node
*/
void
addPicture (movieNode** first, Picture frame)
{
  printf ("not yet implemented\n");
} // addPicture

/* the movie is printed from first item to last, with a short delay
   between successive frames */
void
printForward (const movieNode* first)
{
  printf ("not yet implemented\n");
} // printForward

/* the movie is printed from last item to first, with a short delay
   between successive frames */
void
printReverse (const movieNode* first)
{
  printf ("not yet implemented\n");
} // printReverse
