From 0c49ea5fa5362600d2cf71a8dbd53a0f68a0794b Mon Sep 17 00:00:00 2001 From: Mikael Eiman Date: Tue, 12 Oct 2021 16:35:04 +0200 Subject: [PATCH 1/2] Made various changes to get it to build and work on MacOS using hidapi --- Makefile | 7 ++++--- src/usbhid/usbhid.cpp | 2 ++ src/yk_usb_device.cpp | 6 ++++-- src/yk_usb_device.h | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 501f1d2..66cadb6 100644 --- a/Makefile +++ b/Makefile @@ -17,14 +17,15 @@ OBJS = $(SOURCE_FULL:.cpp=.o) PROG_OBJ = $(PROG_SOURCE_FULL:.cpp=.o) DEFINES += _LINUX_ -DEFINES += _LIBUSB_ +#DEFINES += _LIBUSB_ COMPILE_FLAGS += $(addprefix -D, $(DEFINES)) CUR_PATH = $(shell echo $(PWD)) -INCLUDEPATHS = $(addprefix -I$(CUR_PATH)/, $(dir $(SOURCE_FULL)) libusb ) +INCLUDEPATHS = $(addprefix -I$(CUR_PATH)/, $(dir $(SOURCE_FULL)) libusb ) -I/opt/homebrew/include LOADPATHS = -LIBS = -lusb-1.0 +#LIBS = -lusb-1.0 +LIBS = -lhidapi CPP = g++ diff --git a/src/usbhid/usbhid.cpp b/src/usbhid/usbhid.cpp index ef5fc0a..4e029fc 100644 --- a/src/usbhid/usbhid.cpp +++ b/src/usbhid/usbhid.cpp @@ -21,6 +21,7 @@ limitations under the License. #include +#if 0 UsbHid::UsbHid() { usb_context = NULL; @@ -405,3 +406,4 @@ int UsbHid::read(unsigned char *data, int length) return actual_length; } +#endif \ No newline at end of file diff --git a/src/yk_usb_device.cpp b/src/yk_usb_device.cpp index ef24347..40fd64a 100644 --- a/src/yk_usb_device.cpp +++ b/src/yk_usb_device.cpp @@ -19,7 +19,7 @@ limitations under the License. #ifdef _LIBUSB_ #include #else -#include +//#include #include #endif @@ -151,6 +151,7 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re return -1; } +#if 0 if (serial) { // Convert to a wchar_t* size_t origsize = strlen(serial) + 1; @@ -159,7 +160,8 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re mbstowcs_s(&convertedChars, cserial, origsize, serial, _TRUNCATE); } - +#endif + // Open the USB device handle = hid_open(vid, pid, serial ? cserial : NULL); diff --git a/src/yk_usb_device.h b/src/yk_usb_device.h index 4dc7440..3b240d8 100644 --- a/src/yk_usb_device.h +++ b/src/yk_usb_device.h @@ -19,7 +19,7 @@ limitations under the License. #ifdef _LIBUSB_ #include #else -#include +#include #endif #include From 856ed8b316d3233383ac382a11b2fa774f032006 Mon Sep 17 00:00:00 2001 From: Mikael Eiman Date: Wed, 13 Oct 2021 10:56:13 +0200 Subject: [PATCH 2/2] Fixed serial number to wchar* conversion --- src/yk_usb_device.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/yk_usb_device.cpp b/src/yk_usb_device.cpp index 40fd64a..4edbd84 100644 --- a/src/yk_usb_device.cpp +++ b/src/yk_usb_device.cpp @@ -26,6 +26,8 @@ limitations under the License. #include #include #include +#include +#include #ifdef _LIBUSB_ // Uses libusb directly @@ -151,16 +153,10 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re return -1; } -#if 0 if (serial) { // Convert to a wchar_t* - size_t origsize = strlen(serial) + 1; - size_t convertedChars = 0; - - mbstowcs_s(&convertedChars, cserial, origsize, serial, _TRUNCATE); - + swprintf(cserial, newsize, L"%s", serial); } -#endif // Open the USB device handle = hid_open(vid, pid, serial ? cserial : NULL);