#include <time.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Modtronix.h"

#define OK 0

#define VPRINT if (verbose) printf

void usage();

int main(int argc, char **argv)
{
   int c, sync = 0, verbose = 0;
   unsigned long port = 54123;
   char *host = "134.89.32.55";
   while ( (c = getopt(argc, argv, "h:pv")) != EOF )
   {
      switch (c) {
         case 'h':
         host = strdup(optarg);
         break;

         case 'p':
         port = atol(optarg);
         break;

         case 'v':
         verbose = 1;
         break;

         default:
         usage();
         return OK;

      }
   }
   c = OK;

   // Check inputs
   //
   if ( !host )
   {
      usage();
      return 0;
   }

   Modtronix *mod = new Modtronix("mod_test", host, port, 1000);
   if (mod->initialize() < 0)
   {
      printf("Modtronix initialization failed\n");
      return -1;
   }

   //mod->light_level(0);
   //mod->light_level(100);
   //mod->light_level(56);
   for (int i = 0; i < 255; i++)
   {
      mod->mod_callback();
      sleep(2);
      //mod->light_switch(1);
      //sleep(5);
      //mod->light_switch(0);
      //sleep(10);
   }

   //mod->power_switch(1);

   if (c == OK)
   {
      printf("Normal successful completion\n");
   }
   else
   {
      printf("There was an issue\n");
   }

   return c;

}

void usage()
{
   fprintf(stderr, "USAGE: kiProTest host [page]\n\
    \thost: the website hostname. ex: coding.debuntu.org\n\
    \tpage: the page to retrieve. ex: index.html, default: /\n");
}
     
     
