Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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++


Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
-------
Expand Down
11 changes: 5 additions & 6 deletions src/yk_usb_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ limitations under the License.
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>

#ifdef _LIBUSB_
// Uses libusb directly
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/yk_usb_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};

Expand Down
4 changes: 1 addition & 3 deletions src/ykushxs/ykushxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ int ykushxs_cmd_parser(int argc, char** argv)
default:
ykushxs.ykushxs_help(argv[0]);
return -1;
break;

}

return 0;
}


Expand Down