Skip to content

Commit 45d5f34

Browse files
authored
Merge pull request #501 from wmww/master
Fix the EventReceiver API (on Linux)
2 parents be2e576 + 8c418e4 commit 45d5f34

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

src/daemon/moved.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,12 @@ static void
9494
on_monitor_update_moved(enum MonitorEvent event,
9595
enum MonitorEventDeviceType device_type,
9696
const char *path, const wchar_t *serial,
97-
void *user_data)
97+
unsigned short pid, void *user_data)
9898
{
9999
move_daemon *moved = static_cast<move_daemon *>(user_data);
100100

101101
if (event == EVENT_DEVICE_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;
107103
PSMove *move = psmove_connect_internal(serial, path, -1, pid);
108104
if (psmove_pair(move)) {
109105
// 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
@@ -47,9 +47,10 @@ enum MonitorEventDeviceType {
4747
EVENT_DEVICE_TYPE_UNKNOWN,
4848
};
4949

50+
// pid is the product ID on connect, it may be 0 on disconnect
5051
typedef void (*moved_event_callback)(enum MonitorEvent event,
5152
enum MonitorEventDeviceType device_type, const char *path,
52-
const wchar_t *serial, void *user_data);
53+
const wchar_t *serial, unsigned short pid, void *user_data);
5354

5455
typedef struct _moved_monitor moved_monitor;
5556

src/daemon/moved_monitor_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ _moved_monitor_handle_device(moved_monitor *monitor, struct udev_device *dev)
159159
}
160160

161161
monitor->event_callback(EVENT_DEVICE_ADDED, device_type, path,
162-
serial_number, monitor->event_callback_user_data);
162+
serial_number, product_id, monitor->event_callback_user_data);
163163
}
164164

165165
free(serial_number);
@@ -170,7 +170,7 @@ _moved_monitor_handle_device(moved_monitor *monitor, struct udev_device *dev)
170170
free(uevent);
171171
} else if (strcmp(action, "remove") == 0) {
172172
monitor->event_callback(EVENT_DEVICE_REMOVED, device_type, path,
173-
NULL, monitor->event_callback_user_data);
173+
NULL, 0, monitor->event_callback_user_data);
174174
}
175175
}
176176

src/daemon/moved_monitor_osx.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
enum MonitorEventDeviceType device_type;
5050
char path[256];
5151
wchar_t serial_number[256];
52+
unsigned short pid;
5253
};
5354

5455
struct _moved_monitor {
@@ -85,7 +86,7 @@ void pump_loop()
8586
auto event = events.front();
8687
event_callback(event.event, event.device_type,
8788
event.path, event.serial_number,
88-
event_callback_user_data);
89+
event.pid, event_callback_user_data);
8990
events.pop();
9091
}
9192
}
@@ -94,10 +95,12 @@ void pump_loop()
9495
void
9596
make_event(enum MonitorEvent event, IOHIDDeviceRef device)
9697
{
97-
if (get_vendor_id(device) == PSMOVE_VID && (get_product_id(device) == PSMOVE_PID || get_product_id(device) == PSMOVE_PS4_PID)) {
98+
unsigned short pid = get_product_id(device);
99+
if (get_vendor_id(device) == PSMOVE_VID && (pid == PSMOVE_PID || pid == PSMOVE_PS4_PID)) {
98100
ASyncDeviceEvent ade;
99101
ade.event = event;
100102
ade.device_type = EVENT_DEVICE_TYPE_UNKNOWN;
103+
ade.pid = pid;
101104

102105
// Example paths:
103106
// e.g. "USB_054c_03d5_14100000"

src/psmoveapi.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct PSMoveAPI {
7070

7171
void update();
7272

73-
static void on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, void *user_data);
73+
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);
7474

7575
EventReceiver *receiver;
7676
void *user_data;
@@ -290,7 +290,7 @@ PSMoveAPI::update()
290290
}
291291

292292
void
293-
PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, void *user_data)
293+
PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType device_type, const char *path, const wchar_t *serial, unsigned short pid, void *user_data)
294294
{
295295
auto self = static_cast<PSMoveAPI *>(user_data);
296296

@@ -308,10 +308,6 @@ PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType
308308
}
309309
}
310310

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;
315311
PSMove *move = psmove_connect_internal(serial, path, -1, pid);
316312
if (move == nullptr) {
317313
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
@@ -95,7 +95,7 @@ static void
9595
on_monitor_update_pair(enum MonitorEvent event,
9696
enum MonitorEventDeviceType device_type,
9797
const char *path, const wchar_t *serial,
98-
void *user_data)
98+
unsigned short pid, void *user_data)
9999
{
100100
if (event == EVENT_DEVICE_ADDED) {
101101
if (device_type == EVENT_DEVICE_TYPE_USB) {

0 commit comments

Comments
 (0)