diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index d0e2a5acf6..c45f88adfe 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -724,6 +724,7 @@ scrcpy(struct scrcpy_options *options) { #endif struct sc_keyboard_uhid *uhid_keyboard = NULL; + struct sc_gamepad_uhid *uhid_gamepad = NULL; if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_SDK) { sc_keyboard_sdk_init(&s->keyboard_sdk, &s->controller, @@ -758,8 +759,8 @@ scrcpy(struct scrcpy_options *options) { } struct sc_uhid_devices *uhid_devices = NULL; - if (uhid_keyboard) { - sc_uhid_devices_init(&s->uhid_devices, uhid_keyboard); + if (uhid_keyboard || uhid_gamepad) { + sc_uhid_devices_init(&s->uhid_devices, uhid_keyboard, uhid_gamepad); uhid_devices = &s->uhid_devices; } diff --git a/app/src/uhid/gamepad_uhid.c b/app/src/uhid/gamepad_uhid.c index 3c8d364311..5f19a9d0ee 100644 --- a/app/src/uhid/gamepad_uhid.c +++ b/app/src/uhid/gamepad_uhid.c @@ -3,6 +3,7 @@ #include "hid/hid_gamepad.h" #include "input_events.h" #include "util/log.h" +#include "util/str.h" /** Downcast gamepad processor to sc_gamepad_uhid */ #define DOWNCAST(GP) container_of(GP, struct sc_gamepad_uhid, gamepad_processor) @@ -105,6 +106,22 @@ sc_gamepad_processor_process_gamepad_button(struct sc_gamepad_processor *gp, } +void +sc_gamepad_uhid_process_hid_output(struct sc_gamepad_uhid *gamepad, + uint16_t hid_id, const uint8_t *data, + size_t size) { + (void) gamepad; + char *hex = sc_str_to_hex_string(data, size); + if (hex) { + LOGI("==== HID output [%" PRIu16 "] %s", hid_id, hex); + free(hex); + } else { + LOGI("==== HID output [%" PRIu16 "]", hid_id); + } + + // TODO +} + void sc_gamepad_uhid_init(struct sc_gamepad_uhid *gamepad, struct sc_controller *controller) { diff --git a/app/src/uhid/gamepad_uhid.h b/app/src/uhid/gamepad_uhid.h index 07d030995b..c94a6a8b2d 100644 --- a/app/src/uhid/gamepad_uhid.h +++ b/app/src/uhid/gamepad_uhid.h @@ -20,4 +20,9 @@ void sc_gamepad_uhid_init(struct sc_gamepad_uhid *mouse, struct sc_controller *controller); +void +sc_gamepad_uhid_process_hid_output(struct sc_gamepad_uhid *gamepad, + uint16_t hid_id, const uint8_t *data, + size_t size); + #endif diff --git a/app/src/uhid/uhid_output.c b/app/src/uhid/uhid_output.c index 05e691dab5..56a1d9f0c8 100644 --- a/app/src/uhid/uhid_output.c +++ b/app/src/uhid/uhid_output.c @@ -4,12 +4,15 @@ #include #include "uhid/keyboard_uhid.h" +#include "uhid/gamepad_uhid.h" #include "util/log.h" void sc_uhid_devices_init(struct sc_uhid_devices *devices, - struct sc_keyboard_uhid *keyboard) { + struct sc_keyboard_uhid *keyboard, + struct sc_gamepad_uhid *gamepad) { devices->keyboard = keyboard; + devices->gamepad = gamepad; } void @@ -21,6 +24,13 @@ sc_uhid_devices_process_hid_output(struct sc_uhid_devices *devices, uint16_t id, } else { LOGW("Unexpected keyboard HID output without UHID keyboard"); } + } else if (id >= SC_HID_ID_GAMEPAD_FIRST && id <= SC_HID_ID_GAMEPAD_LAST) { + if (devices->gamepad) { + sc_gamepad_uhid_process_hid_output(devices->gamepad, id, data, + size); + } else { + LOGW("Unexpected gamepad HID output without UHID gamepad"); + } } else { LOGW("HID output ignored for id %" PRIu16, id); } diff --git a/app/src/uhid/uhid_output.h b/app/src/uhid/uhid_output.h index cd6a800f87..d53bdf2006 100644 --- a/app/src/uhid/uhid_output.h +++ b/app/src/uhid/uhid_output.h @@ -14,11 +14,13 @@ struct sc_uhid_devices { struct sc_keyboard_uhid *keyboard; + struct sc_gamepad_uhid *gamepad; }; void sc_uhid_devices_init(struct sc_uhid_devices *devices, - struct sc_keyboard_uhid *keyboard); + struct sc_keyboard_uhid *keyboard, + struct sc_gamepad_uhid *gamepad); void sc_uhid_devices_process_hid_output(struct sc_uhid_devices *devices, uint16_t id,