]> cvs.zerfleddert.de Git - hmcfgusb/blobdiff - hmcfgusb.c
Allow the user to specify the compiler via environment variable
[hmcfgusb] / hmcfgusb.c
index c82613f77dbf3997b7df0d030c6f818ff4751694..90e82f2583eaa5b70224844823acca59e08aacea 100644 (file)
@@ -1,6 +1,6 @@
 /* HM-CFG-USB libusb-driver
  *
- * Copyright (c) 2013 Michael Gernoth <michael@gernoth.net>
+ * Copyright (c) 2013-16 Michael Gernoth <michael@gernoth.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -61,7 +61,7 @@ static int debug = 0;
 static int libusb_initialized = 0;
 
 /* Not in all libusb-1.0 versions, so we have to roll our own :-( */
-static char * usb_strerror(int e)
+static const char* usb_strerror(int e)
 {
        static char unknerr[256];
 
@@ -99,6 +99,30 @@ static char * usb_strerror(int e)
        return unknerr;
 }
 
+static const char* usb_str_transfer_status(int e)
+{
+       static char unknerr[256];
+
+       switch (e) {
+               case LIBUSB_TRANSFER_COMPLETED:
+                       return "Transfer completed";
+               case LIBUSB_TRANSFER_ERROR:
+                       return "Transfer error";
+               case LIBUSB_TRANSFER_TIMED_OUT:
+                       return "Transfer timed out";
+               case LIBUSB_TRANSFER_CANCELLED:
+                       return "Transfer cancelled";
+               case LIBUSB_TRANSFER_STALL:
+                       return "For bulk/interrupt endpoints: endpoint stalled. For control endpoints: control request not supported.";
+               case LIBUSB_TRANSFER_NO_DEVICE:
+                       return "No device";
+               case LIBUSB_TRANSFER_OVERFLOW:
+                       return "Transfer overflow";
+       };
+       snprintf(unknerr, sizeof(unknerr), "Unknown transfer status %d / 0x%02x", e, e);
+       return unknerr;
+}
+
 static libusb_device_handle *hmcfgusb_find(int vid, int pid, char *serial) {
        libusb_device_handle *devh = NULL;
        libusb_device **list;
@@ -279,7 +303,7 @@ static void LIBUSB_CALL hmcfgusb_interrupt(struct libusb_transfer *transfer)
        if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
                if (transfer->status != LIBUSB_TRANSFER_TIMED_OUT) {
                        if (transfer->status != LIBUSB_TRANSFER_CANCELLED)
-                               fprintf(stderr, "Interrupt transfer not completed: %s!\n", usb_strerror(transfer->status));
+                               fprintf(stderr, "Interrupt transfer not completed: %s!\n", usb_str_transfer_status(transfer->status));
 
                        quit = EIO;
                        goto out;
Impressum, Datenschutz