diff --git a/src/daemon/moved.cpp b/src/daemon/moved.cpp index 746f30f6..6912cb9f 100644 --- a/src/daemon/moved.cpp +++ b/src/daemon/moved.cpp @@ -94,16 +94,12 @@ static void on_monitor_update_moved(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, - void *user_data) + unsigned short pid, void *user_data) { move_daemon *moved = static_cast(user_data); if (event == EVENT_DEVICE_ADDED) { if (device_type == EVENT_DEVICE_TYPE_USB) { - // TODO: FIXME: This should use the device's actual USB product ID. - // HACK: We rely on this invalid PID being translated to a - // valid controller model (the old ZCM1, by default). - unsigned short pid = 0; PSMove *move = psmove_connect_internal(serial, path, -1, pid); if (psmove_pair(move)) { // Indicate to the user that pairing was successful diff --git a/src/daemon/moved_monitor.h b/src/daemon/moved_monitor.h index d06e11d9..0f27485f 100644 --- a/src/daemon/moved_monitor.h +++ b/src/daemon/moved_monitor.h @@ -47,9 +47,10 @@ enum MonitorEventDeviceType { EVENT_DEVICE_TYPE_UNKNOWN, }; +// pid is the product ID on connect, it may be 0 on disconnect typedef void (*moved_event_callback)(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, - const wchar_t *serial, void *user_data); + const wchar_t *serial, unsigned short pid, void *user_data); typedef struct _moved_monitor moved_monitor; diff --git a/src/daemon/moved_monitor_linux.c b/src/daemon/moved_monitor_linux.c index 8f6e699f..ed5bfa02 100644 --- a/src/daemon/moved_monitor_linux.c +++ b/src/daemon/moved_monitor_linux.c @@ -159,7 +159,7 @@ _moved_monitor_handle_device(moved_monitor *monitor, struct udev_device *dev) } monitor->event_callback(EVENT_DEVICE_ADDED, device_type, path, - serial_number, monitor->event_callback_user_data); + serial_number, product_id, monitor->event_callback_user_data); } free(serial_number); @@ -170,7 +170,7 @@ _moved_monitor_handle_device(moved_monitor *monitor, struct udev_device *dev) free(uevent); } else if (strcmp(action, "remove") == 0) { monitor->event_callback(EVENT_DEVICE_REMOVED, device_type, path, - NULL, monitor->event_callback_user_data); + NULL, 0, monitor->event_callback_user_data); } } diff --git a/src/daemon/moved_monitor_osx.mm b/src/daemon/moved_monitor_osx.mm index 76379e00..3bd13fd4 100644 --- a/src/daemon/moved_monitor_osx.mm +++ b/src/daemon/moved_monitor_osx.mm @@ -49,6 +49,7 @@ enum MonitorEventDeviceType device_type; char path[256]; wchar_t serial_number[256]; + unsigned short pid; }; struct _moved_monitor { @@ -85,7 +86,7 @@ void pump_loop() auto event = events.front(); event_callback(event.event, event.device_type, event.path, event.serial_number, - event_callback_user_data); + event.pid, event_callback_user_data); events.pop(); } } @@ -94,10 +95,12 @@ void pump_loop() void make_event(enum MonitorEvent event, IOHIDDeviceRef device) { - if (get_vendor_id(device) == PSMOVE_VID && (get_product_id(device) == PSMOVE_PID || get_product_id(device) == PSMOVE_PS4_PID)) { + unsigned short pid = get_product_id(device); + if (get_vendor_id(device) == PSMOVE_VID && (pid == PSMOVE_PID || pid == PSMOVE_PS4_PID)) { ASyncDeviceEvent ade; ade.event = event; ade.device_type = EVENT_DEVICE_TYPE_UNKNOWN; + ade.pid = pid; // Example paths: // e.g. "USB_054c_03d5_14100000" diff --git a/src/psmoveapi.cpp b/src/psmoveapi.cpp index 62032014..7cbfd6d2 100644 --- a/src/psmoveapi.cpp +++ b/src/psmoveapi.cpp @@ -70,7 +70,7 @@ struct PSMoveAPI { void update(); - static void on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, void *user_data); + static void on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, unsigned short pid, void *user_data); EventReceiver *receiver; void *user_data; @@ -290,7 +290,7 @@ PSMoveAPI::update() } void -PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, void *user_data) +PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, unsigned short pid, void *user_data) { auto self = static_cast(user_data); @@ -308,10 +308,6 @@ PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType } } - // TODO: FIXME: This should use the device's actual USB product ID. - // HACK: We rely on this invalid PID being translated to a - // valid controller model (the old ZCM1, by default). - unsigned short pid = 0; PSMove *move = psmove_connect_internal(serial, path, -1, pid); if (move == nullptr) { PSMOVE_ERROR("Cannot open move for retrieving serial!"); diff --git a/src/utils/psmovepair.c b/src/utils/psmovepair.c index b4fe6726..5be709d3 100644 --- a/src/utils/psmovepair.c +++ b/src/utils/psmovepair.c @@ -95,7 +95,7 @@ static void on_monitor_update_pair(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, - void *user_data) + unsigned short pid, void *user_data) { if (event == EVENT_DEVICE_ADDED) { if (device_type == EVENT_DEVICE_TYPE_USB) {