Skip to content

Commit

Permalink
Updated hidapi for Win10 compatibility. Modified feature report proce…
Browse files Browse the repository at this point in the history
…ssing to accommodate extra byte returned by newer hidapi in Windows only. Also made FindUSB1.cmake a little more robust.
  • Loading branch information
cboulay committed Oct 28, 2015
1 parent c023063 commit a001685
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 51 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "external/hidapi"]
path = external/hidapi
url = git://github.com/signal11/hidapi.git
[submodule "external/PS3EYEDriver"]
path = external/PS3EYEDriver
url = https://github.com/brendanwalker/PS3EYEDriver.git
Expand All @@ -13,3 +10,6 @@
[submodule "external/eigen"]
path = external/eigen
url = https://github.com/RLovelett/eigen.git
[submodule "external/hidapi"]
path = external/hidapi
url = https://github.com/cboulay/hidapi
25 changes: 11 additions & 14 deletions README.win64_msvc
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ Requirements
http://www.cmake.org/cmake/resources/software.html
- Git
http://code.google.com/p/msysgit/
- Mercurial
https://mercurial.selenic.com/wiki/Download

1. Clone the PS Move API repository
`git clone --recursive https://github.com/cboulay/psmoveapi.git`
`cd psmoveapi`

2. Eigen
Required - Necessary for orientation algorithms
`cd external`
`hg clone https://bitbucket.org/eigen/eigen`

3. Build libusb-1.0
Optional - Only required if you are building the positional tracker.
Open psmoveapi\external\libusb-1.0\msvc\libusb_2013.sln
Change the target to Release x64 (at the top of the Visual Studio window).
Right-click on libusb-1.0 (static) and select Properties.
In the properties Window, make sure the Platform is set to Active or All Platforms.
In the properties Window, make sure the Platform is set to All Platforms.
Set the Configurations to Release
In the properties Window, navigate to Configuration Properties > C/C++ > Code Generation
Change "Runtime Library" to Multi-threaded DLL (/MD)
Click Apply
Set the Configurations to Debug
Change "Runtime Library" to /MDd
Click OK
Right-click on libusb-1.0 (static) and Build.
Right-click on libusb-1.0 (static) and Build for each of the Release and Debug configurations,
and for each of the Win32 and x64 Target Platforms.

4. OpenCV
Optional - Only required if you are building the positional tracker.
Expand All @@ -41,7 +38,7 @@ Requirements

Open the solution in psmoveapi\external\opencv\build\OpenCV.sln
Change the target to Release x64 (at the top of the Visual Studio window).
Build the solution (Press F7).
Build the solution (Build Menu -> Build Solution).
You can also build the solution for Debug target if you intend to debug psmoveapi.

Note: OpenCV 2.4.11 is required only for MSVC builds of the psmoveapi; Linux and Mac builds of the psmoveapi require OpenCV 3.
Expand All @@ -56,7 +53,7 @@ Requirements

Open the solution (psmoveapi\external\SDL2\build\SDL2.sln)
Change the target to Release (at the top of the VS window).
Build the solution (Press F7).
Build the solution (Build Menu -> Build Solution).

6. stb - single file, header only game utility library
Optional - Only required if you are building the coregistration tool
Expand All @@ -67,15 +64,15 @@ Requirements

Still in the VS2013 command prompt:

`cd ..\..\..`
Change back to the psmoveapi directory.
`mkdir build `
`cd build`
`cmake .. -G "Visual Studio 12 Win64" -DPSMOVE_USE_PS3EYE_DRIVER=1 -DPSMOVE_BUILD_OPENGL_EXAMPLES=ON -DPSMOVE_BUILD_TUIO_SERVER=ON`
#`cmake .. -G "Visual Studio 12 Win64" -DPSMOVE_USE_PS3EYE_DRIVER=1 -DPSMOVE_BUILD_OPENGL_EXAMPLES=ON -DPSMOVE_BUILD_TUIO_SERVER=ON -DPSMOVE_USE_TRACKER_TRACE=ON -DPSMOVE_USE_DEBUG=ON`

Open the `build\Project.sln` solution file.
Change the target to Release.
Build the solution (Press F7).
Build the solution.
You can also build the Debug solution.

8. Read [this Wiki](https://github.com/cboulay/psmove-ue4/wiki) for windows-specific information on pairing and connecting the psmove controller and on using the PS3Eye camera.
Expand Down
63 changes: 39 additions & 24 deletions contrib/FindUSB1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ IF (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
set(LIBUSB_FOUND TRUE)

ELSE (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
set(LIBUSB_ROOT ${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0)
# Because we want to use the static library,
# look locally only.
find_path(LIBUSB_INCLUDE_DIR
NAMES
libusb.h
PATHS
${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0/libusb
${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0/libusb-1.0
${LIBUSB_ROOT}/libusb
${LIBUSB_ROOT}/libusb-1.0
/usr/local/include
)
# There are 4 platform-specific ways we might get the libraries.
Expand All @@ -40,41 +41,55 @@ ELSE (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
# Each of these puts the compiled library into a different folder
# and that is also architecture-specific.

set(LIBUSB_LIB_SEARCH_PATH ${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0)
set(LIBUSB_LIB_SEARCH_PATH_RELEASE ${LIBUSB_ROOT})
set(LIBUSB_LIB_SEARCH_PATH_DEBUG ${LIBUSB_ROOT})
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
IF(MINGW)
set(LIBUSB_PLATFORM_PREFIX MinGW)
set(LIBUSB_PLATFORM_PREFIX MinGW) # Does this get used?
#TODO: Add self-compiled folder for MinGW
IF (${CMAKE_C_SIZEOF_DATA_PTR} EQUAL 8)
list(APPEND LIBUSB_LIB_SEARCH_PATH
${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0/MinGW64/static)
#TODO: Add self-compiled folder for MinGW
list(APPEND LIBUSB_LIB_SEARCH_PATH_RELEASE
${LIBUSB_ROOT}/MinGW64/static)
list(APPEND LIBUSB_LIB_SEARCH_PATH_DEBUG
${LIBUSB_ROOT}/MinGW64/static)
ELSE()
list(APPEND LIBUSB_LIB_SEARCH_PATH
${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0/MinGW32/static)
#TODO: Add self-compiled folder for MinGW
list(APPEND LIBUSB_LIB_SEARCH_PATH_RELEASE
${LIBUSB_ROOT}/MinGW32/static)
list(APPEND LIBUSB_LIB_SEARCH_PATH_DEBUG
${LIBUSB_ROOT}/MinGW32/static)
ENDIF()
ELSE()
ELSE() # MSVC?
set(LIBUSB_PLATFORM_PREFIX MS) # Does this get used?
IF (${CMAKE_C_SIZEOF_DATA_PTR} EQUAL 8)
list(APPEND LIBUSB_LIB_SEARCH_PATH
${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0/x64/Release/lib)
list(APPEND LIBUSB_LIB_SEARCH_PATH_RELEASE
${LIBUSB_ROOT}/x64/Release/lib)
list(APPEND LIBUSB_LIB_SEARCH_PATH_DEBUG
${LIBUSB_ROOT}/x64/Debug/lib)
ELSE()
list(APPEND LIBUSB_LIB_SEARCH_PATH
${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0/Win32/Release/lib)
list(APPEND LIBUSB_LIB_SEARCH_PATH_RELEASE
${LIBUSB_ROOT}/Win32/Release/lib)
list(APPEND LIBUSB_LIB_SEARCH_PATH_DEBUG
${LIBUSB_ROOT}/Win32/Debug/lib)
ENDIF()
set(LIBUSB_PLATFORM_PREFIX MS)
ENDIF()
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND LIBUSB_LIB_SEARCH_PATH
${CMAKE_CURRENT_LIST_DIR}/../external/libusb-1.0/libusb/.libs
list(APPEND LIBUSB_LIB_SEARCH_PATH_RELEASE
${LIBUSB_ROOT}/libusb/.libs
/usr/local/lib)
list(APPEND LIBUSB_LIB_SEARCH_PATH_DEBUG
${LIBUSB_ROOT}/libusb/.libs
/usr/local/lib)
ENDIF()

find_library(LIBUSB_LIBRARIES
NAMES
libusb-1.0.a libusb-1.0.lib libusb-1.0 usb-1.0 usb
PATHS
${LIBUSB_LIB_SEARCH_PATH}
)
FIND_LIBRARY(LIBUSB_LIBRARY_RELEASE
NAMES libusb-1.0.a libusb-1.0.lib libusb-1.0 usb-1.0 usb
PATHS ${LIBUSB_LIB_SEARCH_PATH_RELEASE})
FIND_LIBRARY(LIBUSB_LIBRARY_DEBUG
NAMES libusb-1.0.a libusb-1.0.lib libusb-1.0 usb-1.0 usb
PATHS ${LIBUSB_LIB_SEARCH_PATH_DEBUG})
SET(LIBUSB_LIBRARIES
debug ${LIBUSB_LIBRARY_DEBUG}
optimized ${LIBUSB_LIBRARY_RELEASE})

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR)
Expand Down
2 changes: 1 addition & 1 deletion external/hidapi
1 change: 1 addition & 0 deletions external/stb
Submodule stb added at 385927
21 changes: 16 additions & 5 deletions src/psmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#define PSMOVE_BUFFER_SIZE 49

/* Buffer size for the Bluetooth address get request */
#define PSMOVE_BTADDR_GET_SIZE 16
#define PSMOVE_BTADDR_GET_SIZE 17

/* Buffer size for the Bluetooth address set request */
#define PSMOVE_BTADDR_SET_SIZE 23
Expand Down Expand Up @@ -509,6 +509,7 @@ psmove_count_connected_hidapi()
* The one with "&col01#" in the path is the one we will get most of our data from. Only count this one.
* The one with "&col02#" in the path is the one we will get the bluetooth address from.
**/
psmove_DEBUG("enumerating... hid path: %s\n", cur_dev->path);
if (strstr(cur_dev->path, "&col01#") == NULL) {
count--;
}
Expand Down Expand Up @@ -547,6 +548,8 @@ psmove_count_connected()
PSMove *
psmove_connect_internal(wchar_t *serial, char *path, int id)
{
psmove_DEBUG("psmove_connect_internal(%ls, %s)\n", serial, path);

char *tmp;

PSMove *move = (PSMove*)calloc(1, sizeof(PSMove));
Expand Down Expand Up @@ -581,10 +584,12 @@ psmove_connect_internal(wchar_t *serial, char *path, int id)
p[5] = '2';
psmove_return_val_if_fail((p = strstr(move->device_path_addr, "&0000#")) != NULL, NULL);
p[4] = '1';
psmove_DEBUG("move->handle_addr = hid_open_path(%s)\n", move->device_path_addr);
move->handle_addr = hid_open_path(move->device_path_addr);
hid_set_nonblocking(move->handle_addr, 1);

move->device_path = strdup(path);
psmove_DEBUG("move->handle = hid_open_path(%s)\n", move->device_path);
move->handle = hid_open_path(move->device_path);

#else
Expand Down Expand Up @@ -867,6 +872,7 @@ psmove_connect_by_id(int id)
cur_dev = devs;
while (cur_dev) {
#ifdef _WIN32
psmove_DEBUG("hid path: %s\n", cur_dev->path);
if (strstr(cur_dev->path, "&col01#") != NULL) {
#endif
if (count == id) {
Expand Down Expand Up @@ -949,6 +955,10 @@ _psmove_get_calibration_blob(PSMove *move, char **dest, size_t *size)
unsigned char calibration[PSMOVE_CALIBRATION_BLOB_SIZE];

unsigned char cal[PSMOVE_CALIBRATION_SIZE];
int tocopy = sizeof(cal);
#ifdef _WIN32
tocopy -= sizeof(unsigned char);
#endif
int res;
int x;

Expand All @@ -965,26 +975,27 @@ _psmove_get_calibration_blob(PSMove *move, char **dest, size_t *size)
"https://github.com/thp/psmoveapi/issues/108");
}
#endif
psmove_return_val_if_fail(res == PSMOVE_CALIBRATION_SIZE, 0);

psmove_return_val_if_fail(res == PSMOVE_CALIBRATION_SIZE, 0);

if (cal[1] == 0x00) {
/* First block */
dest_offset = 0;
src_offset = 0;
} else if (cal[1] == 0x01) {
/* Second block */
dest_offset = PSMOVE_CALIBRATION_SIZE;
dest_offset = tocopy;
src_offset = 2;
} else if (cal[1] == 0x82) {
/* Third block */
dest_offset = 2*PSMOVE_CALIBRATION_SIZE - 2;
dest_offset = (2 * tocopy) - 2;
src_offset = 2;
} else {
return 0;
}

memcpy(calibration+dest_offset, cal+src_offset,
sizeof(cal)-src_offset);
tocopy - src_offset);
}

*dest = (char*)malloc(sizeof(calibration));
Expand Down
4 changes: 2 additions & 2 deletions src/psmove_calibration.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ psmove_calibration_load(PSMoveCalibration *calibration)
psmove_file_close(fp);
return 0;
}
if (fread(&(calibration->flags),
sizeof(calibration->flags), 1, fp) != 1) {
int res = fread(&(calibration->flags), sizeof(calibration->flags), 1, fp);
if (res != 1) {
psmove_CRITICAL("Unable to read USB calibration");
psmove_file_close(fp);
return 0;
Expand Down
10 changes: 9 additions & 1 deletion src/psmove_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,19 @@ struct PSMove_RGBValue {
unsigned char b;
};


#ifdef _WIN32
/* Buffer size for calibration data */
#define PSMOVE_CALIBRATION_SIZE 50
/* Three blocks, minus 2x the header (2 bytes) for the 2nd and 3rd block */
#define PSMOVE_CALIBRATION_BLOB_SIZE (49*3 - 2*2)
#else
/* Buffer size for calibration data */
#define PSMOVE_CALIBRATION_SIZE 49

/* Three blocks, minus 2x the header (2 bytes) for the 2nd and 3rd block */
#define PSMOVE_CALIBRATION_BLOB_SIZE (PSMOVE_CALIBRATION_SIZE*3 - 2*2)
#endif


/* System-wide data directory */
#define PSMOVE_SYSTEM_DATA_DIR "/etc/psmoveapi"
Expand Down

0 comments on commit a001685

Please sign in to comment.