#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <stdatomic.h>
#include "usb2200.h"

static volatile sig_atomic_t g_stop = 0;

static void on_signal(int signo)
{
  g_stop = 1;
}

int main(int argc, char **argv)
{
	int handle;
  WORD pid = USB2255_32;
  BYTE bid = 0x0;
  QWORD val;

  signal(SIGINT,  on_signal);

  handle = USB2200_OpenDevice(pid, bid);
	if(handle < 0) {
		printf("open failed, error code %d\n", handle);
		return 0;
	}

  printf("Ctrl + C to break\n");

  while(!g_stop)
  {
    USB2200_DI_ReadValue(handle, &val);
    printf("Read DI value 0x%lx\n",val);
    usleep(500000);
  }

  USB2200_CloseDevice(handle);
  printf("End demo\n");

	return 0;
}

