/* Program uses a struct containing an array of doubles and an int to move
 *   in a square.
 */

#include <MyroC.h>

#define NUM_ACTIONS 8

typedef struct {
  double speed;
  double time;
} movement_t;

void initSpeedTime(movement_t actions []) 
{ int i;
  /* Loop to initialize the values in the structs */
  for (i = 0; i < NUM_ACTIONS; i++)
    {
      /* Sets a constant speed for all actions */
      actions[i].speed = 1 - (.1 * i);

      /* Sets the time for each action to increase by half a second */
      actions[i].time = (i / 2.0) + 0.5;
    }

}

void moveScribbler (movement_t actions [])
{ int i;
  /* Loop to move the Scribbler according to the structs stored times
     and speed(s). */
  for (i = 0; i < NUM_ACTIONS; i++)
    {
      /* Command to move forward according to the speed and time stored
         in the struct in the array position i */
      rForward ( actions[i].speed, actions[i].time);

      /* Command to make a (roughly) 90 degree turn to the left */
      rTurnLeft (1, 0.8);
    }
}

int main()
{
  rConnect ("/dev/rfcomm0");
  rSetForwardnessTxt ("fluke-forward");

  /* Declares an array of NUM_ACTIONS movement structs */
  movement_t actions[NUM_ACTIONS];

  initSpeedTime(actions);
  moveScribbler (actions);
  rBeep(1, 600);

  rDisconnect();
  return 0;
} // main
