Skip to content

Commit 8c418e4

Browse files
committed
Add pid parameter instead of EVENT_ZCM1_ADDED/EVENT_ZCM2_ADDED
1 parent faf02f0 commit 8c418e4

6 files changed

Lines changed: 20 additions & 21 deletions

File tree

src/daemon/moved.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +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

101-
if (event == EVENT_ZCM1_ADDED || event == EVENT_ZCM2_ADDED) {
101+
if (event == EVENT_DEVICE_ADDED) {
102102
if (device_type == EVENT_DEVICE_TYPE_USB) {
103-
unsigned short pid = event == EVENT_ZCM1_ADDED ? PSMOVE_PID : PSMOVE_PS4_PID;
104103
PSMove *move = psmove_connect_internal(serial, path, -1, pid);
105104
if (psmove_pair(move)) {
106105
// Indicate to the user that pairing was successful

src/daemon/moved_monitor.h

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

3939
enum MonitorEvent {
40-
EVENT_ZCM1_ADDED,
41-
EVENT_ZCM2_ADDED,
40+
EVENT_DEVICE_ADDED,
4241
EVENT_DEVICE_REMOVED,
4342
};
4443

@@ -48,9 +47,10 @@ enum MonitorEventDeviceType {
4847
EVENT_DEVICE_TYPE_UNKNOWN,
4948
};
5049

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

5555
typedef struct _moved_monitor moved_monitor;
5656

src/daemon/moved_monitor_linux.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ _moved_monitor_handle_device(moved_monitor *monitor, struct udev_device *dev)
158158
device_type = EVENT_DEVICE_TYPE_USB;
159159
}
160160

161-
monitor->event_callback(product_id == PSMOVE_PID ? EVENT_ZCM1_ADDED : EVENT_ZCM2_ADDED, device_type, path,
162-
serial_number, monitor->event_callback_user_data);
161+
monitor->event_callback(EVENT_DEVICE_ADDED, device_type, path,
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: 6 additions & 3 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"
@@ -119,7 +122,7 @@ void pump_loop()
119122
static void on_device_matching(void *context, IOReturn result, void *sender, IOHIDDeviceRef device)
120123
{
121124
_moved_monitor *monitor = (_moved_monitor *)(context);
122-
monitor->make_event(get_product_id(device) == PSMOVE_PID ? EVENT_ZCM1_ADDED : EVENT_ZCM2_ADDED, device);
125+
monitor->make_event(EVENT_DEVICE_ADDED, device);
123126
}
124127

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

src/psmoveapi.cpp

Lines changed: 4 additions & 7 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,16 +290,14 @@ 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

297297
switch (event) {
298-
case EVENT_ZCM1_ADDED:
299-
case EVENT_ZCM2_ADDED:
298+
case EVENT_DEVICE_ADDED:
300299
{
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",
300+
PSMOVE_DEBUG("on_monitor_event(event=EVENT_DEVICE_ADDED, device_type=0x%08x, path=\"%s\", serial=%p)",
303301
device_type, path, serial);
304302

305303
for (auto &c: self->controllers) {
@@ -310,7 +308,6 @@ PSMoveAPI::on_monitor_event(enum MonitorEvent event, enum MonitorEventDeviceType
310308
}
311309
}
312310

313-
unsigned short pid = event == EVENT_ZCM1_ADDED ? PSMOVE_PID : PSMOVE_PS4_PID;
314311
PSMove *move = psmove_connect_internal(serial, path, -1, pid);
315312
if (move == nullptr) {
316313
PSMOVE_ERROR("Cannot open move for retrieving serial!");

src/utils/psmovepair.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ 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
{
100-
if (event == EVENT_ZCM1_ADDED || event == EVENT_ZCM2_ADDED) {
100+
if (event == EVENT_DEVICE_ADDED) {
101101
if (device_type == EVENT_DEVICE_TYPE_USB) {
102102
pair(NULL);
103103
}

0 commit comments

Comments
 (0)