From dcf85d27d687c485e5b1515e8a5ecec850f98671 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 9 Dec 2021 21:41:06 +0100 Subject: [PATCH 1/6] Fix compile warning for usb_serial default initializer --- src/yk_usb_device.cpp | 1 + src/yk_usb_device.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/yk_usb_device.cpp b/src/yk_usb_device.cpp index a3f5595..cbd14b0 100644 --- a/src/yk_usb_device.cpp +++ b/src/yk_usb_device.cpp @@ -77,6 +77,7 @@ int UsbDevice::listConnected() UsbDevice::UsbDevice(unsigned int vendor_id, unsigned int product_id) { pid = product_id; vid = vendor_id; + usb_serial = NULL; } diff --git a/src/yk_usb_device.h b/src/yk_usb_device.h index 4dc7440..4a3c98f 100644 --- a/src/yk_usb_device.h +++ b/src/yk_usb_device.h @@ -63,7 +63,7 @@ class UsbDevice { unsigned char hid_report_out[64]; unsigned char hid_report_in[64]; - char *usb_serial = NULL; + char *usb_serial; }; From 0da06a6961fdca6ef14225d3d3c04dd823e483ae Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 9 Dec 2021 21:50:00 +0100 Subject: [PATCH 2/6] ykushxs_cmd_parser return 0 if no error to fix warning --- src/ykushxs/ykushxs.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ykushxs/ykushxs.cpp b/src/ykushxs/ykushxs.cpp index 1b088d9..de93223 100644 --- a/src/ykushxs/ykushxs.cpp +++ b/src/ykushxs/ykushxs.cpp @@ -104,10 +104,8 @@ int ykushxs_cmd_parser(int argc, char** argv) default: ykushxs.ykushxs_help(argv[0]); return -1; - break; - } - + return 0; } From e92643c972a9b148b90565bfa566373ee7ddc6b3 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 9 Dec 2021 21:53:52 +0100 Subject: [PATCH 3/6] Use portable swprintf for wide-string conversion --- src/yk_usb_device.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/yk_usb_device.cpp b/src/yk_usb_device.cpp index cbd14b0..4a4350f 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 @@ -153,12 +155,8 @@ int UsbDevice::sendHidReport(char *serial, unsigned char *msg, unsigned char *re 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); + } // Open the USB device handle = hid_open(vid, pid, serial ? cserial : NULL); From 0fa1fcea7a527f2b648eebfc672917f870129eb8 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 9 Dec 2021 21:54:17 +0100 Subject: [PATCH 4/6] Detect OS type to use hidapi on macOS --- Makefile | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 501f1d2..36ce5ea 100644 --- a/Makefile +++ b/Makefile @@ -8,23 +8,32 @@ SOURCE += yk_usb_device.cpp SOURCE += help/ykush_help.cpp SOURCE += utils/command_parser.cpp SOURCE += utils/string2val.cpp -SOURCE += usbhid/usbhid.cpp +# detect macOS/Darwin +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Darwin) + # build for macOS using hidapi + INCLUDEPATHS = $(shell pkg-config hidapi --cflags) + LIBS = -lhidapi +else + # build for Linux using libusb + DEFINES += _LINUX_ + DEFINES += _LIBUSB_ + SOURCE += usbhid/usbhid.cpp + INCLUDEPATHS = $(shell pkg-config libusb-1.0 --cflags) + LIBS = -lusb-1.0 +endif SOURCE_FULL = $(addprefix src/, $(SOURCE)) PROG_SOURCE_FULL = $(addprefix src/, $(PROG_SOURCE)) OBJS = $(SOURCE_FULL:.cpp=.o) PROG_OBJ = $(PROG_SOURCE_FULL:.cpp=.o) -DEFINES += _LINUX_ -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 ) LOADPATHS = -LIBS = -lusb-1.0 CPP = g++ From f645b55138d848ca7cb3b01abac076ef36d183e6 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 10 Dec 2021 09:57:13 +0100 Subject: [PATCH 5/6] README: add macOS --- README.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0389f2..211b48c 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Console application developed to illustrate the programmatic control of YKUSH fa It executes one command per run, being appropriate to be executed as a console command. But it can be easily adapted to execute a work-flow with multiple commands and we encourage you to alter it to best fit your needs. -The implementation makes use of libusb for Linux builds and hidapi for Windows. -For Linux we include a build and installation script, `build.sh` and `install.sh` respectively, for building and installing the application. +The implementation makes use of libusb for Linux builds and hidapi for macOS and Windows. +For Linux nad macOS we include a build and installation script, `build.sh` and `install.sh` respectively, for building and installing the application. Boards Supported @@ -32,7 +32,7 @@ Refer to [LICENSE](LICENSE.md) file. Building ======== -The steps for building on Linux and Windows are detailed bellow. +The steps for building on Linux, macOS and Windows are detailed bellow. Linux @@ -55,6 +55,27 @@ sudo ./install.sh After install, the `ykushcmd` command is ready for use. +macOS +----- + +For macOS `hidapi` must be installed. It can be installed with brew with +``` +brew install hidapi +``` + +With these dependencies installed, build the application the running the following script. +``` +./build.sh +``` + +After a successful build process you can install the ykush command in the system. To do so, run: +``` +sudo ./install.sh +``` + +After install, the `ykushcmd` command is ready for use. + + Windows ------- From db58cbc99aff4b0056895829e49439f01114e671 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 11 Mar 2022 16:10:32 +0100 Subject: [PATCH 6/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 211b48c..f35a4a5 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It executes one command per run, being appropriate to be executed as a console c But it can be easily adapted to execute a work-flow with multiple commands and we encourage you to alter it to best fit your needs. The implementation makes use of libusb for Linux builds and hidapi for macOS and Windows. -For Linux nad macOS we include a build and installation script, `build.sh` and `install.sh` respectively, for building and installing the application. +For Linux and macOS we include a build and installation script, `build.sh` and `install.sh` respectively, for building and installing the application. Boards Supported