From 3823590856c368e6449943606858acf83a690b21 Mon Sep 17 00:00:00 2001 From: Frank Glaser Date: Wed, 9 Jul 2014 19:37:18 +0200 Subject: [PATCH 1/9] Removed static declaration of clock_gettime because of linker error Tested with Win8.1 x64 mingw32-i686-4.8.3-release-win32-sjlj-rt_v3-rev0 cmake-2.8.12.2-win32-x86 --- src/psmove.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psmove.c b/src/psmove.c index 6a9602be..2b7d8446 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -2030,7 +2030,7 @@ _psmove_normalize_btaddr(const char *addr, int lowercase, char separator) #define CLOCK_MONOTONIC 0 -static int +int clock_gettime(int unused, struct timespec *ts) { struct timeval tv; From aa4437aade233b3a7136c86f6073e71c670dadd1 Mon Sep 17 00:00:00 2001 From: Frank Glaser Date: Wed, 9 Jul 2014 20:43:08 +0200 Subject: [PATCH 2/9] Include winsock2.h before windows.h --- src/psmove.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/psmove.c b/src/psmove.c index 2b7d8446..8958656f 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -64,6 +64,7 @@ #endif #ifdef _WIN32 +# include # include # include # include From 5f8449da9d0aa6fcdc99d39459fabf5ec90cf28c Mon Sep 17 00:00:00 2001 From: Frank Glaser Date: Sun, 13 Jul 2014 18:25:28 +0200 Subject: [PATCH 3/9] Fixed calibration for windows 8 Separated calibration device from input device --- src/psmove.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/psmove.c b/src/psmove.c index 8958656f..4b4446eb 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -252,6 +252,7 @@ struct _PSMove { /* The handle to the HIDAPI device */ hid_device *handle; + hid_device *handle_calib; /* The handle to the moved client */ moved_client *client; @@ -269,6 +270,7 @@ struct _PSMove { /* Device path of the controller */ char *device_path; + char *device_path_calib; /* Nonzero if the value of the LEDs or rumble has changed */ unsigned char leds_dirty; @@ -562,10 +564,8 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* XXX Ugly: Convert "col02" path to "col01" path (tested w/ BT and USB) */ char *p; - psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); - p[5] = '1'; + psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); psmove_return_val_if_fail((p = strstr(path, "&0001#")) != NULL, NULL); - p[4] = '0'; #endif if (serial == NULL && path != NULL) { @@ -581,7 +581,28 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* Use Non-Blocking I/O */ hid_set_nonblocking(move->handle, 1); - + +#ifdef _WIN32 + char *path_calib = (char*) calloc(strlen(path)+1, sizeof(char)); + strncpy(path_calib, path, strlen(path)+1); + psmove_return_val_if_fail((p = strstr(path_calib, "&col02#")) != NULL, NULL); + p[5] = '1'; + psmove_return_val_if_fail((p = strstr(path_calib, "&0001#")) != NULL, NULL); + p[4] = '0'; + + move->handle_calib = hid_open_path(path_calib); + if (!move->handle_calib) { + free(move); + return NULL; + } + + hid_set_nonblocking(move->handle_calib, 1); + + if (path_calib != NULL) { + move->device_path_calib = strdup(path_calib); + } +#endif + /* Message type for LED set requests */ move->leds.type = PSMove_Req_SetLEDs; @@ -912,7 +933,11 @@ _psmove_get_calibration_blob(PSMove *move, char **dest, size_t *size) for (x=0; x<3; x++) { memset(cal, 0, sizeof(cal)); cal[0] = PSMove_Req_GetCalibration; - res = hid_get_feature_report(move->handle, cal, sizeof(cal)); + + if(move->handle_calib) + res = hid_get_feature_report(move->handle_calib, cal, sizeof(cal)); + else + res = hid_get_feature_report(move->handle, cal, sizeof(cal)); #if defined(__linux) if(res == -1) { psmove_WARNING("hid_get_feature_report failed, kernel issue? see %s\n", @@ -1715,8 +1740,6 @@ psmove_get_magnetometer_calibration_filename(PSMove *move) char filename[PATH_MAX]; char *serial = psmove_get_serial(move); - psmove_return_val_if_fail(serial != NULL, NULL); - int i; for (i=0; itype) { case PSMove_HIDAPI: hid_close(move->handle); + if(move->handle_calib) + hid_close(move->handle_calib); break; case PSMove_MOVED: // XXX: Close connection? @@ -1847,6 +1872,8 @@ psmove_disconnect(PSMove *move) free(move->serial_number); free(move->device_path); + if(move->device_path_calib) + free(move->device_path_calib); free(move); /* Bookkeeping of open handles (for psmove_reinit) */ From 0fa01bcad5f32f6c83ee62908321656cf6a94209 Mon Sep 17 00:00:00 2001 From: Frank Glaser Date: Sun, 13 Jul 2014 18:29:55 +0200 Subject: [PATCH 4/9] Added basic support for the navigation controller --- include/psmove.h | 2 +- src/psmove.c | 262 ++++++++++++++++++++++++++++++++++++++----- src/psmove_private.h | 18 ++- 3 files changed, 252 insertions(+), 30 deletions(-) diff --git a/include/psmove.h b/include/psmove.h index 09664323..62ee5e62 100644 --- a/include/psmove.h +++ b/include/psmove.h @@ -105,7 +105,7 @@ enum PSMove_Button { Btn_SHARPSHOOTER_TRIGGER = 1 << 27, /*!< Trigger on Sharp Shooter */ Btn_SHARPSHOOTER_RELOAD = 1 << 28, /*!< Reload on Sharp Shooter */ -#if 0 +#if 1 /* Not used for now - only on Sixaxis/DS3 or nav controller */ Btn_L2 = 1 << 0x00, Btn_R2 = 1 << 0x01, diff --git a/src/psmove.c b/src/psmove.c index 4b4446eb..6f51ac45 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -89,9 +89,11 @@ /* Buffer size for the Bluetooth address get request */ #define PSMOVE_BTADDR_GET_SIZE 16 +#define PSMOVE_BTADDR_GET_NAVIGATION_SIZE 8 /* Buffer size for the Bluetooth address set request */ #define PSMOVE_BTADDR_SET_SIZE 23 +#define PSMOVE_BTADDR_SET_NAVIGATION_SIZE 8 /* Maximum length of the serial string */ #define PSMOVE_MAX_SERIAL_LENGTH 255 @@ -104,6 +106,7 @@ enum PSMove_Request_Type { + /* Motion Controller */ PSMove_Req_GetInput = 0x01, PSMove_Req_SetLEDs = 0x02, PSMove_Req_GetBTAddr = 0x04, @@ -112,6 +115,10 @@ enum PSMove_Request_Type { PSMove_Req_SetAuthChallenge = 0xA0, PSMove_Req_GetAuthResponse = 0xA1, PSMove_Req_SetDFUMode = 0xF2, + + /* Navigation Controller */ + PSMove_Req_HostBTAddr = 0xF5, + PSMove_Req_GetFirmwareInfo = 0xF9, /** @@ -306,6 +313,9 @@ struct _PSMove { /* Nonzero if this device is a Bluetooth device (on Windows only) */ unsigned char is_bluetooth; #endif + + /* Is this a navigation controller or a motion controller? */ + int is_navigation; }; void @@ -340,6 +350,14 @@ int _psmove_linux_bt_dev_info(int s, int dev_id, long arg) #endif /* defined(__linux) */ +void +_psmove_dump_data(unsigned char *data, int length) +{ + int i; + for (i=0; ivendor_id, cur_dev->product_id)) { + cur_dev = cur_dev->next; + continue; + } + #ifdef _WIN32 /** * Windows Quirk: Ignore extraneous devices (each dev is enumerated @@ -507,11 +530,14 @@ psmove_count_connected_hidapi() * We use col02 for enumeration, and col01 for connecting. We want to * have col02 here, because after connecting to col01, it disappears. **/ - if (strstr(cur_dev->path, "&col02#") == NULL) { - count--; - } -#endif + if (strstr(cur_dev->path, "col") == NULL ) { + count++; + }else if (strstr(cur_dev->path, "&col02#") != NULL ) { + count++; + } +#else count++; +#endif cur_dev = cur_dev->next; } hid_free_enumeration(devs); @@ -571,7 +597,15 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) if (serial == NULL && path != NULL) { move->handle = hid_open_path(path); } else { - move->handle = hid_open(PSMOVE_VID, PSMOVE_PID, serial); + move->handle = hid_open(PSMOVE_VID, PSMOVE_MOTION_PID, serial); +#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) + if (!move->handle) { + move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_USB_PID, serial); + } + if (!move->handle) { + move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_BT_PID, serial); + } +#endif } if (!move->handle) { @@ -656,6 +690,100 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) return move; } +#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) +PSMove * +psmove_connect_internal_nav(wchar_t *serial, char *path, int id) +{ + char *tmp; + + PSMove *move = (PSMove*)calloc(1, sizeof(PSMove)); + move->type = PSMove_HIDAPI; + + /* Make sure the first LEDs update will go through (+ init get_ticks) */ + move->last_leds_update = psmove_util_get_ticks() - PSMOVE_MAX_LED_INHIBIT_MS; + +#ifdef _WIN32 + /* Windows Quirk: USB devices have "0" as serial, BT devices their addr */ + if (serial != NULL && wcslen(serial) > 1) { + move->is_bluetooth = 1; + } + /* Windows Quirk: Use path instead of serial number by ignoring serial */ + serial = NULL; +#endif + if (serial == NULL && path != NULL) { + move->handle = hid_open_path(path); + } else { + move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_USB_PID, serial); + if (!move->handle) { + move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_BT_PID, serial); + } + } + + if (!move->handle) { + free(move); + return NULL; + } + + /* Use Non-Blocking I/O */ + hid_set_nonblocking(move->handle, 1); + + /* Message type for LED set requests */ + move->leds.type = PSMove_Req_SetLEDs; + + /* Remember the ID/index */ + move->id = id; + + /* Remember the serial number */ + move->serial_number = (char*)calloc(PSMOVE_MAX_SERIAL_LENGTH, sizeof(char)); + if (serial != NULL) { + wcstombs(move->serial_number, serial, PSMOVE_MAX_SERIAL_LENGTH); + } + + if (path != NULL) { + move->device_path = strdup(path); + } + + /** + * Normalize "aa-bb-cc-dd-ee-ff" (OS X format) into "aa:bb:cc:dd:ee:ff" + * Also normalize "AA:BB:CC:DD:EE:FF" into "aa:bb:cc:dd:ee:ff" (lowercase) + **/ + tmp = move->serial_number; + while (*tmp != '\0') { + if (*tmp == '-') { + *tmp = ':'; + } + + *tmp = tolower(*tmp); + tmp++; + } + +#if defined(PSMOVE_USE_PTHREADS) + psmove_return_val_if_fail(pthread_mutex_init(&move->led_write_mutex, + NULL) == 0, NULL); + psmove_return_val_if_fail(pthread_cond_init(&move->led_write_new_data, + NULL) == 0, NULL); + psmove_return_val_if_fail(pthread_create(&move->led_write_thread, + NULL, + _psmove_led_write_thread_proc, + (void*)move) == 0, NULL); +#endif + + /* Bookkeeping of open handles (for psmove_reinit) */ + psmove_num_open_handles++; + + /* Set controller type to Navigation Controller */ + move->is_navigation = 1; + + //move->calibration = psmove_calibration_new(move); + //move->orientation = psmove_orientation_new(move); + + /* Load magnetometer calibration data */ + //psmove_load_magnetometer_calibration(move); + + return move; +} +#endif + const char * _psmove_get_device_path(PSMove *move) { @@ -844,24 +972,46 @@ psmove_connect_by_id(int id) int count = 0; PSMove *move = NULL; - devs = hid_enumerate(PSMOVE_VID, PSMOVE_PID); + devs = hid_enumerate(0, 0); cur_dev = devs; while (cur_dev) { + if (!psmove_is_controller(cur_dev->vendor_id, cur_dev->product_id)) { + cur_dev = cur_dev->next; + continue; + } #ifdef _WIN32 - if (strstr(cur_dev->path, "&col02#") != NULL) { -#endif - if (count == id) { + if (cur_dev->product_id != PSMOVE_MOTION_PID) { + + if (count == id) { + + move = psmove_connect_internal_nav(cur_dev->serial_number, + cur_dev->path, id); + count++; + break; + } + + }else if (strstr(cur_dev->path, "&col02#") != NULL ) { + if (count == id) { move = psmove_connect_internal(cur_dev->serial_number, cur_dev->path, id); - break; + count++; + break; } -#ifdef _WIN32 - } else { - count--; - } + } +#else + if (count == id) { + + if (cur_dev->product_id != PSMOVE_MOTION_PID) { + move = psmove_connect_internal_nav(cur_dev->serial_number, + cur_dev->path, id); + }else{ + move = psmove_connect_internal(cur_dev->serial_number, + cur_dev->path, id); + } + count++; + break; + } #endif - - count++; cur_dev = cur_dev->next; } hid_free_enumeration(devs); @@ -891,10 +1041,47 @@ _psmove_read_btaddrs(PSMove *move, PSMove_Data_BTAddr *host, PSMove_Data_BTAddr /* Get Bluetooth address */ memset(btg, 0, sizeof(btg)); - btg[0] = PSMove_Req_GetBTAddr; - res = hid_get_feature_report(move->handle, btg, sizeof(btg)); - if (res == sizeof(btg)) { + if (move->is_navigation) { + btg[0] = PSMove_Req_HostBTAddr; + } else { + btg[0] = PSMove_Req_GetBTAddr; + } + + res = hid_get_feature_report(move->handle, btg, + move->is_navigation?PSMOVE_BTADDR_GET_NAVIGATION_SIZE:sizeof(btg)); + + printf("res: %d\n", res); +{ + DWORD dLastError = GetLastError(); + LPCTSTR strErrorMessage = NULL; + + FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + dLastError, + 0, + (LPWSTR) &strErrorMessage, + 0, + NULL); + + printf("getlast: %s\n", strErrorMessage); + } + printf("ERROR blob: %s , errno %d\n", strerror(errno), errno); + printf("hiderr: %d\n", hid_error(move->handle)); + + + if (res == sizeof(btg) || res == PSMOVE_BTADDR_GET_NAVIGATION_SIZE) { + /* Navigation controller result: + * 01 00 aa bb cc dd ee ff + * ^^^^^^^^^^^^^^^^^ + * host bt address + */ + if (move->is_navigation) { + _psmove_dump_data(btg, sizeof(btg)); + } + if (controller != NULL) { memcpy(*controller, btg+1, 6); } @@ -930,6 +1117,10 @@ _psmove_get_calibration_blob(PSMove *move, char **dest, size_t *size) int dest_offset; int src_offset; + if (move->is_navigation) { + return 0; + } + for (x=0; x<3; x++) { memset(cal, 0, sizeof(cal)); cal[0] = PSMove_Req_GetCalibration; @@ -1003,16 +1194,24 @@ psmove_set_btaddr(PSMove *move, PSMove_Data_BTAddr *addr) /* Get calibration data */ memset(bts, 0, sizeof(bts)); - bts[0] = PSMove_Req_SetBTAddr; - /* Copy 6 bytes from addr into bts[1]..bts[6] */ - for (i=0; i<6; i++) { - bts[1+i] = (*addr)[i]; + if (move->is_navigation) { + bts[0] = PSMove_Req_HostBTAddr; + /* Copy 6 bytes from addr into bts[2]..bts[7] */ + memcpy(bts+2, addr, 6); + } else { + bts[0] = PSMove_Req_SetBTAddr; + /* Copy 6 bytes from addr into bts[1]..bts[6], reversed */ + for (i=0; i<6; i++) { + bts[1+5-i] = (*addr)[i]; + } } - res = hid_send_feature_report(move->handle, bts, sizeof(bts)); + res = hid_send_feature_report(move->handle, bts, + move->is_navigation?PSMOVE_BTADDR_SET_NAVIGATION_SIZE:sizeof(bts)); + + return (res == sizeof(bts) || res == PSMOVE_BTADDR_SET_NAVIGATION_SIZE); - return (res == sizeof(bts)); } enum PSMove_Bool @@ -1641,7 +1840,10 @@ psmove_get_magnetometer_vector(PSMove *move, enum PSMove_Bool psmove_has_calibration(PSMove *move) { - psmove_return_val_if_fail(move != NULL, 0); + if (move->is_navigation) + return PSMove_False; + + psmove_return_val_if_fail(move != NULL, 0); return psmove_calibration_supported(move->calibration); } @@ -2058,6 +2260,9 @@ _psmove_normalize_btaddr(const char *addr, int lowercase, char separator) #define CLOCK_MONOTONIC 0 +#if !defined(_WIN32) +static +#endif int clock_gettime(int unused, struct timespec *ts) { @@ -2069,6 +2274,7 @@ clock_gettime(int unused, struct timespec *ts) return 0; } + #endif /* __APPLE__ || _WIN32 */ PSMove_timestamp diff --git a/src/psmove_private.h b/src/psmove_private.h index d606088d..7eed92a4 100755 --- a/src/psmove_private.h +++ b/src/psmove_private.h @@ -53,7 +53,12 @@ extern "C" { /* Vendor ID and Product ID of PS Move Controller */ #define PSMOVE_VID 0x054c -#define PSMOVE_PID 0x03d5 +#define PSMOVE_MOTION_PID 0x03d5 + +#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) +#define PSMOVE_NAVIGATION_USB_PID 0x042f +#define PSMOVE_NAVIGATION_BT_PID 0x0268 +#endif #define psmove_PRINTF(section, msg, ...) \ fprintf(stderr, "[" section "] " msg, ## __VA_ARGS__) @@ -90,6 +95,17 @@ extern "C" { #define psmove_goto_if_fail(expr, label) \ {if(!(expr)){psmove_CRITICAL(#expr);goto label;}} +#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) +#define psmove_is_controller(vid, pid) \ + (vid == PSMOVE_VID && \ + (pid == PSMOVE_MOTION_PID || pid == PSMOVE_NAVIGATION_USB_PID || \ + pid == PSMOVE_NAVIGATION_BT_PID)) +#else +#define psmove_is_controller(vid, pid) \ + (vid == PSMOVE_VID && \ + pid == PSMOVE_MOTION_PID) +#endif + /* Macro: Length of fixed-size array */ #define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0])) From 65ff131de7675c3d4d669d46a4195a7ae89d388c Mon Sep 17 00:00:00 2001 From: Frank Glaser Date: Thu, 31 Jul 2014 19:04:11 +0200 Subject: [PATCH 5/9] Changes according the comments of the first review --- include/psmove.h | 2 -- src/psmove.c | 89 ++++++++++++++++++++++++------------------------ 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/include/psmove.h b/include/psmove.h index 62ee5e62..68686a37 100644 --- a/include/psmove.h +++ b/include/psmove.h @@ -105,7 +105,6 @@ enum PSMove_Button { Btn_SHARPSHOOTER_TRIGGER = 1 << 27, /*!< Trigger on Sharp Shooter */ Btn_SHARPSHOOTER_RELOAD = 1 << 28, /*!< Reload on Sharp Shooter */ -#if 1 /* Not used for now - only on Sixaxis/DS3 or nav controller */ Btn_L2 = 1 << 0x00, Btn_R2 = 1 << 0x01, @@ -117,7 +116,6 @@ enum PSMove_Button { Btn_RIGHT = 1 << 0x0D, Btn_DOWN = 1 << 0x0E, Btn_LEFT = 1 << 0x0F, -#endif }; diff --git a/src/psmove.c b/src/psmove.c index 6f51ac45..d8230da1 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -106,19 +106,13 @@ enum PSMove_Request_Type { - /* Motion Controller */ + /* Common */ PSMove_Req_GetInput = 0x01, PSMove_Req_SetLEDs = 0x02, - PSMove_Req_GetBTAddr = 0x04, - PSMove_Req_SetBTAddr = 0x05, PSMove_Req_GetCalibration = 0x10, PSMove_Req_SetAuthChallenge = 0xA0, PSMove_Req_GetAuthResponse = 0xA1, PSMove_Req_SetDFUMode = 0xF2, - - /* Navigation Controller */ - PSMove_Req_HostBTAddr = 0xF5, - PSMove_Req_GetFirmwareInfo = 0xF9, /** @@ -137,6 +131,13 @@ enum PSMove_Request_Type { * https://github.com/thp/psmoveapi/issues/55 **/ PSMove_Req_SetLEDsPermanentUSB = 0xFA, + + /* Navigation Controller */ + PSMove_Req_HostBTAddr = 0xF5, + + /* Motion Controller */ + PSMove_Req_GetBTAddr = 0x04, + PSMove_Req_SetBTAddr = 0x05, }; enum PSMove_Device_Type { @@ -259,7 +260,7 @@ struct _PSMove { /* The handle to the HIDAPI device */ hid_device *handle; - hid_device *handle_calib; + hid_device *handle_calib; /* The handle to the moved client */ moved_client *client; @@ -277,7 +278,7 @@ struct _PSMove { /* Device path of the controller */ char *device_path; - char *device_path_calib; + char *device_path_calib; /* Nonzero if the value of the LEDs or rumble has changed */ unsigned char leds_dirty; @@ -350,7 +351,7 @@ int _psmove_linux_bt_dev_info(int s, int dev_id, long arg) #endif /* defined(__linux) */ -void +static void _psmove_dump_data(unsigned char *data, int length) { int i; @@ -516,12 +517,12 @@ psmove_count_connected_hidapi() devs = hid_enumerate(0, 0); cur_dev = devs; - while (cur_dev) { - if (!psmove_is_controller(cur_dev->vendor_id, cur_dev->product_id)) { + while (cur_dev) { + if (!psmove_is_controller(cur_dev->vendor_id, cur_dev->product_id)) { cur_dev = cur_dev->next; continue; } - + #ifdef _WIN32 /** * Windows Quirk: Ignore extraneous devices (each dev is enumerated @@ -530,9 +531,9 @@ psmove_count_connected_hidapi() * We use col02 for enumeration, and col01 for connecting. We want to * have col02 here, because after connecting to col01, it disappears. **/ - if (strstr(cur_dev->path, "col") == NULL ) { - count++; - }else if (strstr(cur_dev->path, "&col02#") != NULL ) { + if (strstr(cur_dev->path, "col") == NULL ) { + count++; + }else if (strstr(cur_dev->path, "&col02#") != NULL ) { count++; } #else @@ -590,7 +591,7 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* XXX Ugly: Convert "col02" path to "col01" path (tested w/ BT and USB) */ char *p; - psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); + psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); psmove_return_val_if_fail((p = strstr(path, "&0001#")) != NULL, NULL); #endif @@ -615,28 +616,28 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* Use Non-Blocking I/O */ hid_set_nonblocking(move->handle, 1); - + #ifdef _WIN32 - char *path_calib = (char*) calloc(strlen(path)+1, sizeof(char)); - strncpy(path_calib, path, strlen(path)+1); - psmove_return_val_if_fail((p = strstr(path_calib, "&col02#")) != NULL, NULL); - p[5] = '1'; - psmove_return_val_if_fail((p = strstr(path_calib, "&0001#")) != NULL, NULL); - p[4] = '0'; - - move->handle_calib = hid_open_path(path_calib); - if (!move->handle_calib) { - free(move); - return NULL; - } - - hid_set_nonblocking(move->handle_calib, 1); - - if (path_calib != NULL) { - move->device_path_calib = strdup(path_calib); - } + char *path_calib = (char*) calloc(strlen(path)+1, sizeof(char)); + strncpy(path_calib, path, strlen(path)+1); + psmove_return_val_if_fail((p = strstr(path_calib, "&col02#")) != NULL, NULL); + p[5] = '1'; + psmove_return_val_if_fail((p = strstr(path_calib, "&0001#")) != NULL, NULL); + p[4] = '0'; + + move->handle_calib = hid_open_path(path_calib); + if (!move->handle_calib) { + free(move); + return NULL; + } + + hid_set_nonblocking(move->handle_calib, 1); + + if (path_calib != NULL) { + move->device_path_calib = strdup(path_calib); + } #endif - + /* Message type for LED set requests */ move->leds.type = PSMove_Req_SetLEDs; @@ -710,7 +711,7 @@ psmove_connect_internal_nav(wchar_t *serial, char *path, int id) /* Windows Quirk: Use path instead of serial number by ignoring serial */ serial = NULL; #endif - if (serial == NULL && path != NULL) { + if (serial == NULL && path != NULL) { move->handle = hid_open_path(path); } else { move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_USB_PID, serial); @@ -726,7 +727,7 @@ psmove_connect_internal_nav(wchar_t *serial, char *path, int id) /* Use Non-Blocking I/O */ hid_set_nonblocking(move->handle, 1); - + /* Message type for LED set requests */ move->leds.type = PSMove_Req_SetLEDs; @@ -773,13 +774,11 @@ psmove_connect_internal_nav(wchar_t *serial, char *path, int id) /* Set controller type to Navigation Controller */ move->is_navigation = 1; - - //move->calibration = psmove_calibration_new(move); - //move->orientation = psmove_orientation_new(move); + + move->calibration = NULL - /* Load magnetometer calibration data */ - //psmove_load_magnetometer_calibration(move); - + move->orientation = NULL + return move; } #endif From 213e7f149b8e304b2cb23210e958c71d966f588a Mon Sep 17 00:00:00 2001 From: betonme Date: Tue, 30 Sep 2014 10:56:12 +0200 Subject: [PATCH 6/9] Revert "Added basic support for the navigation controller" This reverts commit 0fa01bcad5f32f6c83ee62908321656cf6a94209. --- include/psmove.h | 2 + src/psmove.c | 309 ++++++++----------------------------------- src/psmove_private.h | 18 +-- 3 files changed, 55 insertions(+), 274 deletions(-) diff --git a/include/psmove.h b/include/psmove.h index 68686a37..09664323 100644 --- a/include/psmove.h +++ b/include/psmove.h @@ -105,6 +105,7 @@ enum PSMove_Button { Btn_SHARPSHOOTER_TRIGGER = 1 << 27, /*!< Trigger on Sharp Shooter */ Btn_SHARPSHOOTER_RELOAD = 1 << 28, /*!< Reload on Sharp Shooter */ +#if 0 /* Not used for now - only on Sixaxis/DS3 or nav controller */ Btn_L2 = 1 << 0x00, Btn_R2 = 1 << 0x01, @@ -116,6 +117,7 @@ enum PSMove_Button { Btn_RIGHT = 1 << 0x0D, Btn_DOWN = 1 << 0x0E, Btn_LEFT = 1 << 0x0F, +#endif }; diff --git a/src/psmove.c b/src/psmove.c index d8230da1..4b4446eb 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -89,11 +89,9 @@ /* Buffer size for the Bluetooth address get request */ #define PSMOVE_BTADDR_GET_SIZE 16 -#define PSMOVE_BTADDR_GET_NAVIGATION_SIZE 8 /* Buffer size for the Bluetooth address set request */ #define PSMOVE_BTADDR_SET_SIZE 23 -#define PSMOVE_BTADDR_SET_NAVIGATION_SIZE 8 /* Maximum length of the serial string */ #define PSMOVE_MAX_SERIAL_LENGTH 255 @@ -106,9 +104,10 @@ enum PSMove_Request_Type { - /* Common */ PSMove_Req_GetInput = 0x01, PSMove_Req_SetLEDs = 0x02, + PSMove_Req_GetBTAddr = 0x04, + PSMove_Req_SetBTAddr = 0x05, PSMove_Req_GetCalibration = 0x10, PSMove_Req_SetAuthChallenge = 0xA0, PSMove_Req_GetAuthResponse = 0xA1, @@ -131,13 +130,6 @@ enum PSMove_Request_Type { * https://github.com/thp/psmoveapi/issues/55 **/ PSMove_Req_SetLEDsPermanentUSB = 0xFA, - - /* Navigation Controller */ - PSMove_Req_HostBTAddr = 0xF5, - - /* Motion Controller */ - PSMove_Req_GetBTAddr = 0x04, - PSMove_Req_SetBTAddr = 0x05, }; enum PSMove_Device_Type { @@ -260,7 +252,7 @@ struct _PSMove { /* The handle to the HIDAPI device */ hid_device *handle; - hid_device *handle_calib; + hid_device *handle_calib; /* The handle to the moved client */ moved_client *client; @@ -278,7 +270,7 @@ struct _PSMove { /* Device path of the controller */ char *device_path; - char *device_path_calib; + char *device_path_calib; /* Nonzero if the value of the LEDs or rumble has changed */ unsigned char leds_dirty; @@ -314,9 +306,6 @@ struct _PSMove { /* Nonzero if this device is a Bluetooth device (on Windows only) */ unsigned char is_bluetooth; #endif - - /* Is this a navigation controller or a motion controller? */ - int is_navigation; }; void @@ -351,14 +340,6 @@ int _psmove_linux_bt_dev_info(int s, int dev_id, long arg) #endif /* defined(__linux) */ -static void -_psmove_dump_data(unsigned char *data, int length) -{ - int i; - for (i=0; ivendor_id, cur_dev->product_id)) { - cur_dev = cur_dev->next; - continue; - } - #ifdef _WIN32 /** * Windows Quirk: Ignore extraneous devices (each dev is enumerated @@ -531,14 +507,11 @@ psmove_count_connected_hidapi() * We use col02 for enumeration, and col01 for connecting. We want to * have col02 here, because after connecting to col01, it disappears. **/ - if (strstr(cur_dev->path, "col") == NULL ) { - count++; - }else if (strstr(cur_dev->path, "&col02#") != NULL ) { - count++; - } -#else - count++; + if (strstr(cur_dev->path, "&col02#") == NULL) { + count--; + } #endif + count++; cur_dev = cur_dev->next; } hid_free_enumeration(devs); @@ -591,22 +564,14 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* XXX Ugly: Convert "col02" path to "col01" path (tested w/ BT and USB) */ char *p; - psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); + psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); psmove_return_val_if_fail((p = strstr(path, "&0001#")) != NULL, NULL); #endif if (serial == NULL && path != NULL) { move->handle = hid_open_path(path); } else { - move->handle = hid_open(PSMOVE_VID, PSMOVE_MOTION_PID, serial); -#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) - if (!move->handle) { - move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_USB_PID, serial); - } - if (!move->handle) { - move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_BT_PID, serial); - } -#endif + move->handle = hid_open(PSMOVE_VID, PSMOVE_PID, serial); } if (!move->handle) { @@ -616,28 +581,28 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* Use Non-Blocking I/O */ hid_set_nonblocking(move->handle, 1); - + #ifdef _WIN32 - char *path_calib = (char*) calloc(strlen(path)+1, sizeof(char)); - strncpy(path_calib, path, strlen(path)+1); - psmove_return_val_if_fail((p = strstr(path_calib, "&col02#")) != NULL, NULL); - p[5] = '1'; - psmove_return_val_if_fail((p = strstr(path_calib, "&0001#")) != NULL, NULL); - p[4] = '0'; - - move->handle_calib = hid_open_path(path_calib); - if (!move->handle_calib) { - free(move); - return NULL; - } - - hid_set_nonblocking(move->handle_calib, 1); - - if (path_calib != NULL) { - move->device_path_calib = strdup(path_calib); - } + char *path_calib = (char*) calloc(strlen(path)+1, sizeof(char)); + strncpy(path_calib, path, strlen(path)+1); + psmove_return_val_if_fail((p = strstr(path_calib, "&col02#")) != NULL, NULL); + p[5] = '1'; + psmove_return_val_if_fail((p = strstr(path_calib, "&0001#")) != NULL, NULL); + p[4] = '0'; + + move->handle_calib = hid_open_path(path_calib); + if (!move->handle_calib) { + free(move); + return NULL; + } + + hid_set_nonblocking(move->handle_calib, 1); + + if (path_calib != NULL) { + move->device_path_calib = strdup(path_calib); + } #endif - + /* Message type for LED set requests */ move->leds.type = PSMove_Req_SetLEDs; @@ -691,98 +656,6 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) return move; } -#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) -PSMove * -psmove_connect_internal_nav(wchar_t *serial, char *path, int id) -{ - char *tmp; - - PSMove *move = (PSMove*)calloc(1, sizeof(PSMove)); - move->type = PSMove_HIDAPI; - - /* Make sure the first LEDs update will go through (+ init get_ticks) */ - move->last_leds_update = psmove_util_get_ticks() - PSMOVE_MAX_LED_INHIBIT_MS; - -#ifdef _WIN32 - /* Windows Quirk: USB devices have "0" as serial, BT devices their addr */ - if (serial != NULL && wcslen(serial) > 1) { - move->is_bluetooth = 1; - } - /* Windows Quirk: Use path instead of serial number by ignoring serial */ - serial = NULL; -#endif - if (serial == NULL && path != NULL) { - move->handle = hid_open_path(path); - } else { - move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_USB_PID, serial); - if (!move->handle) { - move->handle = hid_open(PSMOVE_VID, PSMOVE_NAVIGATION_BT_PID, serial); - } - } - - if (!move->handle) { - free(move); - return NULL; - } - - /* Use Non-Blocking I/O */ - hid_set_nonblocking(move->handle, 1); - - /* Message type for LED set requests */ - move->leds.type = PSMove_Req_SetLEDs; - - /* Remember the ID/index */ - move->id = id; - - /* Remember the serial number */ - move->serial_number = (char*)calloc(PSMOVE_MAX_SERIAL_LENGTH, sizeof(char)); - if (serial != NULL) { - wcstombs(move->serial_number, serial, PSMOVE_MAX_SERIAL_LENGTH); - } - - if (path != NULL) { - move->device_path = strdup(path); - } - - /** - * Normalize "aa-bb-cc-dd-ee-ff" (OS X format) into "aa:bb:cc:dd:ee:ff" - * Also normalize "AA:BB:CC:DD:EE:FF" into "aa:bb:cc:dd:ee:ff" (lowercase) - **/ - tmp = move->serial_number; - while (*tmp != '\0') { - if (*tmp == '-') { - *tmp = ':'; - } - - *tmp = tolower(*tmp); - tmp++; - } - -#if defined(PSMOVE_USE_PTHREADS) - psmove_return_val_if_fail(pthread_mutex_init(&move->led_write_mutex, - NULL) == 0, NULL); - psmove_return_val_if_fail(pthread_cond_init(&move->led_write_new_data, - NULL) == 0, NULL); - psmove_return_val_if_fail(pthread_create(&move->led_write_thread, - NULL, - _psmove_led_write_thread_proc, - (void*)move) == 0, NULL); -#endif - - /* Bookkeeping of open handles (for psmove_reinit) */ - psmove_num_open_handles++; - - /* Set controller type to Navigation Controller */ - move->is_navigation = 1; - - move->calibration = NULL - - move->orientation = NULL - - return move; -} -#endif - const char * _psmove_get_device_path(PSMove *move) { @@ -971,46 +844,24 @@ psmove_connect_by_id(int id) int count = 0; PSMove *move = NULL; - devs = hid_enumerate(0, 0); + devs = hid_enumerate(PSMOVE_VID, PSMOVE_PID); cur_dev = devs; while (cur_dev) { - if (!psmove_is_controller(cur_dev->vendor_id, cur_dev->product_id)) { - cur_dev = cur_dev->next; - continue; - } #ifdef _WIN32 - if (cur_dev->product_id != PSMOVE_MOTION_PID) { - - if (count == id) { - - move = psmove_connect_internal_nav(cur_dev->serial_number, - cur_dev->path, id); - count++; - break; - } - - }else if (strstr(cur_dev->path, "&col02#") != NULL ) { - if (count == id) { + if (strstr(cur_dev->path, "&col02#") != NULL) { +#endif + if (count == id) { move = psmove_connect_internal(cur_dev->serial_number, cur_dev->path, id); - count++; - break; + break; } - } -#else - if (count == id) { - - if (cur_dev->product_id != PSMOVE_MOTION_PID) { - move = psmove_connect_internal_nav(cur_dev->serial_number, - cur_dev->path, id); - }else{ - move = psmove_connect_internal(cur_dev->serial_number, - cur_dev->path, id); - } - count++; - break; - } +#ifdef _WIN32 + } else { + count--; + } #endif + + count++; cur_dev = cur_dev->next; } hid_free_enumeration(devs); @@ -1040,47 +891,10 @@ _psmove_read_btaddrs(PSMove *move, PSMove_Data_BTAddr *host, PSMove_Data_BTAddr /* Get Bluetooth address */ memset(btg, 0, sizeof(btg)); + btg[0] = PSMove_Req_GetBTAddr; + res = hid_get_feature_report(move->handle, btg, sizeof(btg)); - if (move->is_navigation) { - btg[0] = PSMove_Req_HostBTAddr; - } else { - btg[0] = PSMove_Req_GetBTAddr; - } - - res = hid_get_feature_report(move->handle, btg, - move->is_navigation?PSMOVE_BTADDR_GET_NAVIGATION_SIZE:sizeof(btg)); - - printf("res: %d\n", res); -{ - DWORD dLastError = GetLastError(); - LPCTSTR strErrorMessage = NULL; - - FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, - dLastError, - 0, - (LPWSTR) &strErrorMessage, - 0, - NULL); - - printf("getlast: %s\n", strErrorMessage); - } - printf("ERROR blob: %s , errno %d\n", strerror(errno), errno); - printf("hiderr: %d\n", hid_error(move->handle)); - - - if (res == sizeof(btg) || res == PSMOVE_BTADDR_GET_NAVIGATION_SIZE) { - /* Navigation controller result: - * 01 00 aa bb cc dd ee ff - * ^^^^^^^^^^^^^^^^^ - * host bt address - */ - if (move->is_navigation) { - _psmove_dump_data(btg, sizeof(btg)); - } - + if (res == sizeof(btg)) { if (controller != NULL) { memcpy(*controller, btg+1, 6); } @@ -1116,10 +930,6 @@ _psmove_get_calibration_blob(PSMove *move, char **dest, size_t *size) int dest_offset; int src_offset; - if (move->is_navigation) { - return 0; - } - for (x=0; x<3; x++) { memset(cal, 0, sizeof(cal)); cal[0] = PSMove_Req_GetCalibration; @@ -1193,24 +1003,16 @@ psmove_set_btaddr(PSMove *move, PSMove_Data_BTAddr *addr) /* Get calibration data */ memset(bts, 0, sizeof(bts)); + bts[0] = PSMove_Req_SetBTAddr; - if (move->is_navigation) { - bts[0] = PSMove_Req_HostBTAddr; - /* Copy 6 bytes from addr into bts[2]..bts[7] */ - memcpy(bts+2, addr, 6); - } else { - bts[0] = PSMove_Req_SetBTAddr; - /* Copy 6 bytes from addr into bts[1]..bts[6], reversed */ - for (i=0; i<6; i++) { - bts[1+5-i] = (*addr)[i]; - } + /* Copy 6 bytes from addr into bts[1]..bts[6] */ + for (i=0; i<6; i++) { + bts[1+i] = (*addr)[i]; } - res = hid_send_feature_report(move->handle, bts, - move->is_navigation?PSMOVE_BTADDR_SET_NAVIGATION_SIZE:sizeof(bts)); - - return (res == sizeof(bts) || res == PSMOVE_BTADDR_SET_NAVIGATION_SIZE); + res = hid_send_feature_report(move->handle, bts, sizeof(bts)); + return (res == sizeof(bts)); } enum PSMove_Bool @@ -1839,10 +1641,7 @@ psmove_get_magnetometer_vector(PSMove *move, enum PSMove_Bool psmove_has_calibration(PSMove *move) { - if (move->is_navigation) - return PSMove_False; - - psmove_return_val_if_fail(move != NULL, 0); + psmove_return_val_if_fail(move != NULL, 0); return psmove_calibration_supported(move->calibration); } @@ -2259,9 +2058,6 @@ _psmove_normalize_btaddr(const char *addr, int lowercase, char separator) #define CLOCK_MONOTONIC 0 -#if !defined(_WIN32) -static -#endif int clock_gettime(int unused, struct timespec *ts) { @@ -2273,7 +2069,6 @@ clock_gettime(int unused, struct timespec *ts) return 0; } - #endif /* __APPLE__ || _WIN32 */ PSMove_timestamp diff --git a/src/psmove_private.h b/src/psmove_private.h index 7eed92a4..d606088d 100755 --- a/src/psmove_private.h +++ b/src/psmove_private.h @@ -53,12 +53,7 @@ extern "C" { /* Vendor ID and Product ID of PS Move Controller */ #define PSMOVE_VID 0x054c -#define PSMOVE_MOTION_PID 0x03d5 - -#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) -#define PSMOVE_NAVIGATION_USB_PID 0x042f -#define PSMOVE_NAVIGATION_BT_PID 0x0268 -#endif +#define PSMOVE_PID 0x03d5 #define psmove_PRINTF(section, msg, ...) \ fprintf(stderr, "[" section "] " msg, ## __VA_ARGS__) @@ -95,17 +90,6 @@ extern "C" { #define psmove_goto_if_fail(expr, label) \ {if(!(expr)){psmove_CRITICAL(#expr);goto label;}} -#if defined(PSMOVE_USE_MOVE_NAVIGATION_CONTROLLER) -#define psmove_is_controller(vid, pid) \ - (vid == PSMOVE_VID && \ - (pid == PSMOVE_MOTION_PID || pid == PSMOVE_NAVIGATION_USB_PID || \ - pid == PSMOVE_NAVIGATION_BT_PID)) -#else -#define psmove_is_controller(vid, pid) \ - (vid == PSMOVE_VID && \ - pid == PSMOVE_MOTION_PID) -#endif - /* Macro: Length of fixed-size array */ #define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0])) From 6d9b9132c034c33136fbe0aa71b9305073fbddc7 Mon Sep 17 00:00:00 2001 From: betonme Date: Tue, 30 Sep 2014 11:09:08 +0200 Subject: [PATCH 7/9] Fixed indentation --- src/psmove.c | 64 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/psmove.c b/src/psmove.c index 4b4446eb..b7bbc7b3 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -252,7 +252,7 @@ struct _PSMove { /* The handle to the HIDAPI device */ hid_device *handle; - hid_device *handle_calib; + hid_device *handle_calib; /* The handle to the moved client */ moved_client *client; @@ -270,7 +270,7 @@ struct _PSMove { /* Device path of the controller */ char *device_path; - char *device_path_calib; + char *device_path_calib; /* Nonzero if the value of the LEDs or rumble has changed */ unsigned char leds_dirty; @@ -564,7 +564,7 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* XXX Ugly: Convert "col02" path to "col01" path (tested w/ BT and USB) */ char *p; - psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); + psmove_return_val_if_fail((p = strstr(path, "&col02#")) != NULL, NULL); psmove_return_val_if_fail((p = strstr(path, "&0001#")) != NULL, NULL); #endif @@ -581,28 +581,28 @@ psmove_connect_internal(wchar_t *serial, char *path, int id) /* Use Non-Blocking I/O */ hid_set_nonblocking(move->handle, 1); - + #ifdef _WIN32 - char *path_calib = (char*) calloc(strlen(path)+1, sizeof(char)); - strncpy(path_calib, path, strlen(path)+1); - psmove_return_val_if_fail((p = strstr(path_calib, "&col02#")) != NULL, NULL); - p[5] = '1'; - psmove_return_val_if_fail((p = strstr(path_calib, "&0001#")) != NULL, NULL); - p[4] = '0'; - - move->handle_calib = hid_open_path(path_calib); - if (!move->handle_calib) { - free(move); - return NULL; - } - - hid_set_nonblocking(move->handle_calib, 1); - - if (path_calib != NULL) { - move->device_path_calib = strdup(path_calib); - } + char *path_calib = (char*) calloc(strlen(path)+1, sizeof(char)); + strncpy(path_calib, path, strlen(path)+1); + psmove_return_val_if_fail((p = strstr(path_calib, "&col02#")) != NULL, NULL); + p[5] = '1'; + psmove_return_val_if_fail((p = strstr(path_calib, "&0001#")) != NULL, NULL); + p[4] = '0'; + + move->handle_calib = hid_open_path(path_calib); + if (!move->handle_calib) { + free(move); + return NULL; + } + + hid_set_nonblocking(move->handle_calib, 1); + + if (path_calib != NULL) { + move->device_path_calib = strdup(path_calib); + } #endif - + /* Message type for LED set requests */ move->leds.type = PSMove_Req_SetLEDs; @@ -933,11 +933,11 @@ _psmove_get_calibration_blob(PSMove *move, char **dest, size_t *size) for (x=0; x<3; x++) { memset(cal, 0, sizeof(cal)); cal[0] = PSMove_Req_GetCalibration; - - if(move->handle_calib) - res = hid_get_feature_report(move->handle_calib, cal, sizeof(cal)); - else - res = hid_get_feature_report(move->handle, cal, sizeof(cal)); + + if(move->handle_calib) + res = hid_get_feature_report(move->handle_calib, cal, sizeof(cal)); + else + res = hid_get_feature_report(move->handle, cal, sizeof(cal)); #if defined(__linux) if(res == -1) { psmove_WARNING("hid_get_feature_report failed, kernel issue? see %s\n", @@ -1854,8 +1854,8 @@ psmove_disconnect(PSMove *move) switch (move->type) { case PSMove_HIDAPI: hid_close(move->handle); - if(move->handle_calib) - hid_close(move->handle_calib); + if(move->handle_calib) + hid_close(move->handle_calib); break; case PSMove_MOVED: // XXX: Close connection? @@ -1872,8 +1872,8 @@ psmove_disconnect(PSMove *move) free(move->serial_number); free(move->device_path); - if(move->device_path_calib) - free(move->device_path_calib); + if(move->device_path_calib) + free(move->device_path_calib); free(move); /* Bookkeeping of open handles (for psmove_reinit) */ From 547519042b69234521d91ebd0b6e81fcb2598511 Mon Sep 17 00:00:00 2001 From: betonme Date: Tue, 30 Sep 2014 12:20:26 +0200 Subject: [PATCH 8/9] Revert "Removed static declaration of clock_gettime because of linker error" This reverts commit 3823590856c368e6449943606858acf83a690b21. --- src/psmove.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psmove.c b/src/psmove.c index b7bbc7b3..0dcab1d9 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -2058,7 +2058,7 @@ _psmove_normalize_btaddr(const char *addr, int lowercase, char separator) #define CLOCK_MONOTONIC 0 -int +static int clock_gettime(int unused, struct timespec *ts) { struct timeval tv; From ac22979509efa719f23314856c2ce819a4b486a3 Mon Sep 17 00:00:00 2001 From: betonme Date: Tue, 30 Sep 2014 12:21:25 +0200 Subject: [PATCH 9/9] Removed CLOCK_MONOTONIC and clock_gettime for WIN32 --- src/psmove.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/psmove.c b/src/psmove.c index 0dcab1d9..7b89fa5a 100755 --- a/src/psmove.c +++ b/src/psmove.c @@ -2054,7 +2054,7 @@ _psmove_normalize_btaddr(const char *addr, int lowercase, char separator) return result; } -#if defined(__APPLE__) || defined(_WIN32) +#if defined(__APPLE__) #define CLOCK_MONOTONIC 0 @@ -2069,7 +2069,7 @@ clock_gettime(int unused, struct timespec *ts) return 0; } -#endif /* __APPLE__ || _WIN32 */ +#endif /* __APPLE__ */ PSMove_timestamp _psmove_timestamp()