#include <stdio.h>

#include "DeviceToolKits/Input.h"
#ifndef  TESTPROTO
#define  NO_PRAGMAS  1
#endif
#include "DeviceToolKits/proto/Input.h"
#include "DeviceToolKits/InputBase.h"

DTInput_t            Unit0;
struct   InputEvent  event;

main(argc,argv)
int   argc;
char  *argv[];
{
   long  status;
   int   i;

#ifdef   TESTSHARED
/*  Open the Input library  */

   DTInputOpen(DTINPUTREV);
#endif

/*  Try to initialize unit 0 of the Input  */

   if ((Unit0 = DTInputCreate(&status)) == NULL) {
      fprintf(stderr,"Error initializing unit 0 = %ld.\n",status);
      fflush(stderr);
      goto cleanup;
   }

   fprintf(stderr,"Unit0 = %lX\n",(long) Unit0);
   fflush(stderr);

/*  Do some fun stuff with the mouse  */

   for (i=0; i<1; i++) {
      do_box();
   }

/*  Free the stuff  */

cleanup:
   DTInputFree(Unit0);
#ifdef   TESTSHARED
   DTInputClose();
#endif
}

do_box()
{
   int   i;

   for (i=0; i<300; i++) {
      mouse_event(i,0);
   }
   printf("Try moving the mouse\n");
   fflush(stdout);
   Delay(5L*60L);
   for (i=0; i<300; i++) {
      mouse_event(300,i);
   }
   for (i=300; i>=0; i--) {
      mouse_event(i,300);
   }
   printf("Try moving the mouse\n");
   fflush(stdout);
   Delay(5L*60L);
   for (i=300; i>=0; i--) {
      mouse_event(0,i);
   }

   return (0);
}

mouse_event(x,y)
int   x;
int   y;
{
   long  status;

   event.ie_NextEvent = NULL;
   event.ie_Class = IECLASS_POINTERPOS;
   event.ie_SubClass = 0;
   event.ie_Code = 0;
   event.ie_Qualifier = 0;
   event.ie_position.ie_xy.ie_x = x;
   event.ie_position.ie_xy.ie_y = y;
   event.ie_TimeStamp.tv_secs = 0;
   event.ie_TimeStamp.tv_micro = 0;

   if ((status = DTInputWriteEvent(Unit0,(BYTE *) &event,
         sizeof(event))) != 0) {
      fprintf(stderr,"Error writing event to unit 0 = %ld,%ld.\n",
               status,Unit0->in_error);
      fflush(stderr);
      DTInputFree(Unit0);
      exit(0);
   }

   return (0);
}

