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++ diff --git a/README.md b/README.md index a0389f2..f35a4a5 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 and 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 ------- diff --git a/src/yk_usb_device.cpp b/src/yk_usb_device.cpp index a3f5595..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 @@ -77,6 +79,7 @@ int UsbDevice::listConnected() UsbDevice::UsbDevice(unsigned int vendor_id, unsigned int product_id) { pid = product_id; vid = vendor_id; + usb_serial = NULL; } @@ -152,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); 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; }; 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; }