*/
struct usbDevice;
typedef struct usbDevice usbDevice_t;
-typedef struct usbDevice *USBDEVHANDLE;
+typedef usbDevice_t *USBDEVHANDLE;
/* ------------------------------------------------------------------------ */
* 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);
/* ------------------------------------------------------------------------ */
#include <usb.h>
#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
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;
}
// 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;
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;
}
{
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;
{
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;
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;
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;
-# 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=
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)
+
# 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 <stdint.h>
#endif /* WIN32 */
#ifndef USBRL_CALL
#include <string.h>
#include <stdlib.h>
-//#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" {