]> mj.ucw.cz Git - home-hw.git/blobdiff - host/test.c
Time display through USB
[home-hw.git] / host / test.c
index 81d428e69b8c46cae77e9466932d97948839379e..07b804e4d3a0fb2f274cec710ad2fa7396ff78fb 100644 (file)
@@ -1,5 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
 #include <libusb-1.0/libusb.h>
 
 struct libusb_context *usb_ctxt;
@@ -61,16 +63,25 @@ int main(void)
 
   for (;;)
     {
-      unsigned char req[64] = { 1, 2, 3, 4 };
+      time_t t = time(NULL);
+      struct tm *tm = localtime(&t);
+
+      unsigned char req[8] = {
+       tm->tm_hour / 10,
+       tm->tm_hour % 10,
+       (tm->tm_sec % 2 ? 10 : 0xff),
+       tm->tm_min / 10,
+       tm->tm_min % 10,
+      };
       int transferred;
-      if (err = libusb_bulk_transfer(devh, 0x01, req, 32, &transferred, 2000))
+      if (err = libusb_bulk_transfer(devh, 0x01, req, 8, &transferred, 2000))
        {
          fprintf(stderr, "Transfer failed: error %d\n", err);
          exit(1);
        }
       printf("Transferred %d bytes\n", transferred);
 
-#if 1
+#if 0
       unsigned char resp[1000];
       int received;
       if (err = libusb_bulk_transfer(devh, 0x82, resp, 1000, &received, 2000))
@@ -80,6 +91,8 @@ int main(void)
        }
       printf("Received %d bytes [%02x]\n", received, resp[0]);
 #endif
+
+      sleep(1);
     }
 
   return 0;