Skip to content

Commit faf02f0

Browse files
committed
Fix the EventReceiver API (on Linux)
Split EVENT_DEVICE_ADDED into EVENT_ZCM1_ADDED and EVENT_ZCM2_ADDED so the proper product ID can be used, this removes two FIXMEs and makes it work on Linux (NOT tested on OSX/windows, no code changes were needed on windows, and the OSX code changes were relatively simple)
1 parent c5d368b commit faf02f0

6 files changed

Lines changed: 12 additions & 15 deletions

File tree

src/daemon/moved.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,9 @@ on_monitor_update_moved(enum MonitorEvent event,
9898
{
9999
move_daemon *moved = static_cast<move_daemon *>(user_data);
100100

101-
if (event == EVENT_DEVICE_ADDED) {
101+
if (event == EVENT_ZCM1_ADDED || event == EVENT_ZCM2_ADDED) {
102102
if (device_type == EVENT_DEVICE_TYPE_USB) {
103-
// TODO: FIXME: This should use the device's actual USB product ID.
104-
// HACK: We rely on this invalid PID being translated to a
105-
// valid controller model (the old ZCM1, by default).
106-
unsigned short pid = 0;
103+
unsigned short pid = event == EVENT_ZCM1_ADDED ? PSMOVE_PID : PSMOVE_PS4_PID;
107104
PSMove *move = psmove_connect_internal(serial, path, -1, pid);
108105
if (psmove_pair(move)) {
109106
// Indicate to the user that pairing was successful

src/daemon/moved_monitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ extern "C" {
3737
#include <wchar.h>
3838

3939
enum MonitorEvent {
40-
EVENT_DEVICE_ADDED,
40+
EVENT_ZCM1_ADDED,
41+
EVENT_ZCM2_ADDED,
4142
EVENT_DEVICE_REMOVED,
4243
};
4344

src/daemon/moved_monitor_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ _moved_monitor_handle_device(moved_monitor *monitor, struct udev_device *dev)
158158
device_type = EVENT_DEVICE_TYPE_USB;
159159
}
160160

161-
monitor->event_callback(EVENT_DEVICE_ADDED, device_type, path,
161+
monitor->event_callback(product_id == PSMOVE_PID ? EVENT_ZCM1_ADDED : EVENT_ZCM2_ADDED, device_type, path,
162162
serial_number, monitor->event_callback_user_data);
163163
}
164164

src/daemon/moved_monitor_osx.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void pump_loop()
119119
static void on_device_matching(void *context, IOReturn result, void *sender, IOHIDDeviceRef device)
120120
{
121121
_moved_monitor *monitor = (_moved_monitor *)(context);
122-
monitor->make_event(EVENT_DEVICE_ADDED, device);
122+
monitor->make_event(get_product_id(device) == PSMOVE_PID ? EVENT_ZCM1_ADDED : EVENT_ZCM2_ADDED, device);
123123
}
124124

125125
static void on_device_removal(void *context, IOReturn result, void *sender, IOHIDDeviceRef device)

src/psmoveapi.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,11 @@ PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType
295295
auto self = static_cast<PSMoveAPI *>(user_data);
296296

297297
switch (event) {
298-
case EVENT_DEVICE_ADDED:
298+
case EVENT_ZCM1_ADDED:
299+
case EVENT_ZCM2_ADDED:
299300
{
300-
PSMOVE_DEBUG("on_monitor_event(event=EVENT_DEVICE_ADDED, device_type=0x%08x, path=\"%s\", serial=%p)",
301+
PSMOVE_DEBUG("on_monitor_event(event=%s, device_type=0x%08x, path=\"%s\", serial=%p)",
302+
event == EVENT_ZCM1_ADDED ? "EVENT_ZCM1_ADDED" : "EVENT_ZCM2_ADDED",
301303
device_type, path, serial);
302304

303305
for (auto &c: self->controllers) {
@@ -308,10 +310,7 @@ PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType
308310
}
309311
}
310312

311-
// TODO: FIXME: This should use the device's actual USB product ID.
312-
// HACK: We rely on this invalid PID being translated to a
313-
// valid controller model (the old ZCM1, by default).
314-
unsigned short pid = 0;
313+
unsigned short pid = event == EVENT_ZCM1_ADDED ? PSMOVE_PID : PSMOVE_PS4_PID;
315314
PSMove *move = psmove_connect_internal(serial, path, -1, pid);
316315
if (move == nullptr) {
317316
PSMOVE_ERROR("Cannot open move for retrieving serial!");

src/utils/psmovepair.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ on_monitor_update_pair(enum MonitorEvent event,
9797
const char *path, const wchar_t *serial,
9898
void *user_data)
9999
{
100-
if (event == EVENT_DEVICE_ADDED) {
100+
if (event == EVENT_ZCM1_ADDED || event == EVENT_ZCM2_ADDED) {
101101
if (device_type == EVENT_DEVICE_TYPE_USB) {
102102
pair(NULL);
103103
}

0 commit comments

Comments
 (0)