From: pavel Date: Sat, 28 Mar 2015 00:58:04 +0000 (+0300) Subject: Fix for linux & libusb version, added library to Linux makefile X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ac36c33be42b7f8616dfa938d76c8f880533aaa8;p=usb-relay-hid.git Fix for linux & libusb version, added library to Linux makefile --- diff --git a/commandline/hiddata.h b/commandline/hiddata.h index ca8cfa5..ed0144c 100644 --- a/commandline/hiddata.h +++ b/commandline/hiddata.h @@ -40,7 +40,7 @@ Libraries to link are: */ struct usbDevice; typedef struct usbDevice usbDevice_t; -typedef struct usbDevice *USBDEVHANDLE; +typedef usbDevice_t *USBDEVHANDLE; /* ------------------------------------------------------------------------ */ @@ -95,7 +95,7 @@ int usbhidGetReport(USBDEVHANDLE usbh, int reportID, char *buffer, int *len); * Return description of error code * TODO? return error descr. of underlying libusb or hid layer too? */ -int usbhidStrerror_r( int err, char *buf, int len); +int usbhidStrerror_r(int err, char *buf, int len); /* ------------------------------------------------------------------------ */ diff --git a/commandline/hiddata_libusb01.c b/commandline/hiddata_libusb01.c index 1cc8b73..b21aa80 100644 --- a/commandline/hiddata_libusb01.c +++ b/commandline/hiddata_libusb01.c @@ -14,9 +14,9 @@ #include #if 0 //ifdef DEBUG -#define DEBUG_PRINT(arg) printf arg +#define DEBUG_PRINT(fmt, ...) do {} while(0) #else -#define DEBUG_PRINT(arg) +#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) #endif @@ -70,7 +70,7 @@ int usbhidEnumDevices(int vendor, int product, handle = usb_open(dev); /* we need to open the device in order to query strings */ if ( !handle ) { errorCode = USBHID_ERR_ACCESS; - fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror()); + DEBUG_PRINT("Warning: cannot open USB device: %s\n", usb_strerror()); continue; } @@ -78,8 +78,8 @@ int usbhidEnumDevices(int vendor, int product, // printf("Probing: [%s] nc=%u %p\n", dev->filename, dev->num_children, dev->children); // Assume our devices are leaf, so we can use dev->children to store the handle - if ( dev->children ) { - fprintf(stderr, "ERROR: assertion failed for usb dev %p\n", dev); + if ( dev->num_children != 0 ) { + DEBUG_PRINT("ERROR: assertion failed for usb dev %p\n", dev); usb_close(handle); handle = NULL; continue; @@ -118,9 +118,9 @@ static int usbhidGetStringAscii(struct usb_dev_handle *dev, int index, char *buf if((rval = usb_get_string_simple(dev, index, buf, buflen)) >= 0) /* use libusb version if it works */ return rval; if (errno == EPERM) - fprintf(stderr, "usbhid: Access denied to USB device. Run as root or adjust device permissions.\n"); + DEBUG_PRINT("usbhid: Access denied to USB device. Run as root or adjust device permissions.\n"); else - fprintf(stderr, "usbhid: %s error %s\n", __FUNCTION__, usb_strerror()); + DEBUG_PRINT("usbhid: %s error %s\n", __FUNCTION__, usb_strerror()); return -1; } @@ -128,7 +128,7 @@ int usbhidGetVendorString(USBDEVHANDLE usbh, char *buffer, int len) { int len2 = usbhidGetStringAscii(usbDevHandle(usbh), usbDevStruct(usbh)->descriptor.iManufacturer, buffer, len); if (len2 < 0) { - fprintf(stderr, "Warning: cannot query vendor for device\n"); + DEBUG_PRINT("Warning: cannot query vendor for device\n"); return USBHID_ERR_IO; } return 0; @@ -138,7 +138,7 @@ int usbhidGetProductString(USBDEVHANDLE usbh, char *buffer, int len) { int len2 = usbhidGetStringAscii(usbDevHandle(usbh), usbDevStruct(usbh)->descriptor.iProduct, buffer, len); if (len2 < 0) { - fprintf(stderr, "Warning: cannot query product for device\n"); + DEBUG_PRINT("Warning: cannot query product for device\n"); return USBHID_ERR_IO; } return 0; @@ -160,7 +160,7 @@ int usbhidSetReport(USBDEVHANDLE usbh, char *buffer, int len) 0, buffer, len, A_REPORT_REQUEST_TIMEOUT); if (bytesSent != len) { if (bytesSent < 0) - fprintf(stderr, "Error sending message: %s\n", usb_strerror()); + DEBUG_PRINT("Error sending message: %s\n", usb_strerror()); return USBHID_ERR_IO; } return 0; @@ -180,7 +180,7 @@ int bytesReceived, maxLen = *len; USB_TYPE_CLASS | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USBRQ_HID_GET_REPORT, USB_HID_REPORT_TYPE_FEATURE << 8 | reportNumber, 0, buffer, maxLen, A_REPORT_REQUEST_TIMEOUT); if(bytesReceived < 0){ - fprintf(stderr, "Error sending message: %s\n", usb_strerror()); + DEBUG_PRINT("Error sending message: %s\n", usb_strerror()); return USBHID_ERR_IO; } *len = bytesReceived; diff --git a/commandline/makemake/Makefile b/commandline/makemake/Makefile index cc3b0f1..71af114 100644 --- a/commandline/makemake/Makefile +++ b/commandline/makemake/Makefile @@ -1,21 +1,22 @@ -# Makefile for HID USB relay utility, hidusbrelay-cmd -# pa03 24-jan-2015 -# +# Makefile for HID USB relay utility, hidusbrelay-cmd and library +# for Linux +# (Quick'n'dirty - no .h dependencies, etc.) +# Assume make is run in this dir +# pa04 24-jan-2015 + # prototype: # Author: Christian Starkjohann # Creation Date: 2008-04-11 -# Tabsize: 4 # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH -# License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) SRCDIR=.. VPATH = $(SRCDIR) -CMD_UTILITY=hidusb-relay-cmd +CMD_UTILITY := hidusb-relay-cmd +SHRLIB := usb_relay_device.so -# For Linux -# Using old simple version 0.1 of libusb -HIDDATA=hiddata_libusb01 +# For Linux: Using old simple version 0.1 of libusb +HIDDATA := hiddata_libusb01 USBFLAGS := $(shell libusb-config --cflags) USBLIBS := $(shell libusb-config --libs) EXE_SUFFIX= @@ -49,7 +50,19 @@ strip: $(PROGRAM) strip $(PROGRAM) clean: - rm -f $(OBJ) $(PROGRAM) + rm -f *.o $(PROGRAM) $(SHRLIB) %.c.o: $(CC) $(ARCH_COMPILE) $(CFLAGS) -c $*.c -o $*.o + +# +# Shared library +# The main lib source is in lib/ and hiddata src with the cmd utility - reorg! +# +SRCS_LIB = $(HIDDATA) usb_relay_lib +CFLAGS += -I../../lib +VPATH =../../lib:.. + +$(SHRLIB): $(addsuffix .o, $(SRCS_LIB)) + $(CC) -shared -Wl,-shared $(addsuffix .o, $(SRCS_LIB)) $(LIBS) -o $(SHRLIB) + diff --git a/lib/usb_relay_device.h b/lib/usb_relay_device.h index 05f88d1..19a62df 100644 --- a/lib/usb_relay_device.h +++ b/lib/usb_relay_device.h @@ -18,6 +18,9 @@ # define USBRL_CALL # define USBRL_API USBRL_CALL #endif /* Windows & Not Microsoft's compiler */ +#else /* non-Windows */ + /* do not include this always for compat with VC++ < 2010 */ +#include #endif /* WIN32 */ #ifndef USBRL_CALL diff --git a/lib/usb_relay_lib.c b/lib/usb_relay_lib.c index 9b9c568..c7aadc2 100644 --- a/lib/usb_relay_lib.c +++ b/lib/usb_relay_lib.c @@ -40,12 +40,12 @@ #include #include -//#define dbgprintf(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) -//#define dbgprintf(fmt, ...) printf(fmt, __VA_ARGS__) -#define dbgprintf(fmt, ...) __noop(fmt, __VA_ARGS__) -//#define printerr(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) -//#define printerr(fmt, ...) printf(fmt, __VA_ARGS__) -#define printerr(fmt, ...) __noop(fmt, __VA_ARGS__) +//#define dbgprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) +//#define dbgprintf(fmt, ...) printf(fmt, ## __VA_ARGS__) +#define dbgprintf(fmt, ...) //__noop(fmt, __VA_ARGS__) +//#define printerr(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) +//#define printerr(fmt, ...) printf(fmt, ## __VA_ARGS__) +#define printerr(fmt, ...) // __noop(fmt, __VA_ARGS__) #ifdef __cplusplus extern "C" {