// EyeBot Demo Program: Drive with IR remote control, T. Bräunl, Sep. 2016
#include "eyebot.h"

int main()
{ int     i=0,ir, recording=0;
  char    name[50];
  QVGAcol img;
  
  LCDMenu("R-OFF", "", "", "END");
  CAMInit(QVGA);
  VWControl(9,5,6,1.5);
  
  do
  { switch (ir = IRTVRead())
    { case IRTV_5: VWSetSpeed(  0,  0); break;   // stop
      case IRTV_2: VWSetSpeed( 50,  0); break;   // forward
      case IRTV_4: VWSetSpeed(-50,  0); break;   // back
      case IRTV_6: VWSetSpeed(  0, 50); break;   // turn left
      case IRTV_8: VWSetSpeed(  0,-50); break;   // turn right
      case IRTV_1: VWSetSpeed( 50, 50); break;   // curve left
      case IRTV_3: VWSetSpeed( 50,-50); break;   // curve right
      case IRTV_0: recording =!recording; break; // toggle
    }
    if (KEYGet()==KEY1) recording =!recording; // toggle
    if (recording) LCDMenuI(1, "REC", BLACK, RED);
      else         LCDMenuI(1, "R-OFF", BLACK, RED);
     
    CAMGet(img);
    LCDImage(img);
    if (recording)
    { sprintf(name, "%04d.ppm", i++);
      IPWriteFile(name, img);
    }
  } while (KEYGet()!=KEY4);
}
