From ebf83d6350d20c75fb707d0e4290424bd851db87 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 2 Jan 2024 19:18:12 +0100 Subject: [PATCH] Add touchbar to dualsense --- dev_out.c | 12 ++++++ devices_status.c | 3 ++ devices_status.h | 4 ++ message.h | 19 ++++++++++ rog_ally.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++- virt_ds5.c | 14 +++++-- 6 files changed, 144 insertions(+), 4 deletions(-) diff --git a/dev_out.c b/dev_out.c index e25046f..36e9f76 100644 --- a/dev_out.c +++ b/dev_out.c @@ -192,6 +192,18 @@ static void handle_incoming_message_gamepad_set( inout_gamepad->raw_accel[2] = msg_payload->status.accel.z; break; } + case GAMEPAD_TOUCHPAD_TOUCH_ACTIVE: { + inout_gamepad->touchpad_touch_num = msg_payload->status.touchpad_active.status; + break; + } + case GAMEPAD_TOUCHPAD_X: { + inout_gamepad->touchpad_x = msg_payload->status.touchpad_x.value; + break; + } + case GAMEPAD_TOUCHPAD_Y: { + inout_gamepad->touchpad_y = msg_payload->status.touchpad_y.value; + break; + } default: { fprintf(stderr, "Unknown gamepad element: %d\n", msg_payload->element); break; diff --git a/devices_status.c b/devices_status.c index f852b15..6173659 100644 --- a/devices_status.c +++ b/devices_status.c @@ -95,6 +95,9 @@ void gamepad_status_init(gamepad_status_t *const stats) { stats->leds_colors[0] = 0; stats->leds_colors[1] = 0; stats->leds_colors[2] = 0; + stats->touchpad_touch_num = -1; + stats->touchpad_x = 0; + stats->touchpad_y = 0; stats->flags = 0; } diff --git a/devices_status.h b/devices_status.h index 8543f89..c137df1 100644 --- a/devices_status.h +++ b/devices_status.h @@ -46,6 +46,10 @@ typedef struct gamepad_status { uint8_t touchpad_press; + int16_t touchpad_touch_num; // touchpad is inactive when this is -1 + int16_t touchpad_x; + int16_t touchpad_y; + struct timeval last_gyro_motion_time; struct timeval last_accel_motion_time; diff --git a/message.h b/message.h index 7270f5d..4fe7632 100644 --- a/message.h +++ b/message.h @@ -35,8 +35,24 @@ typedef enum in_message_gamepad_btn { GAMEPAD_GYROSCOPE, GAMEPAD_ACCELEROMETER, + + GAMEPAD_TOUCHPAD_X, + GAMEPAD_TOUCHPAD_Y, + GAMEPAD_TOUCHPAD_TOUCH_ACTIVE, } in_gamepad_element_t; +typedef struct in_message_gamepad_touchpad_x { + int16_t value; +} in_message_gamepad_touchpad_x_t; + +typedef struct in_message_gamepad_touchpad_y { + int16_t value; +} in_message_gamepad_touchpad_y_t; + +typedef struct in_message_gamepad_touchpad_active { + int16_t status; +} in_message_gamepad_touchpad_active_t; + typedef struct in_message_gamepad_gyro { struct timeval sample_time; @@ -61,6 +77,9 @@ typedef struct in_message_gamepad_set_element { int8_t dpad; // -1 | 0 | +1 in_message_gamepad_accel_t accel; in_message_gamepad_gyro_t gyro; + in_message_gamepad_touchpad_active_t touchpad_active; + in_message_gamepad_touchpad_x_t touchpad_x; + in_message_gamepad_touchpad_y_t touchpad_y; } status; } in_message_gamepad_set_element_t; diff --git a/rog_ally.c b/rog_ally.c index b966a76..1357c3d 100644 --- a/rog_ally.c +++ b/rog_ally.c @@ -3,6 +3,7 @@ #include "dev_hidraw.h" #include "message.h" #include "xbox360.h" +#include enum rc71l_leds_mode { ROG_ALLY_MODE_STATIC = 0, @@ -946,6 +947,98 @@ static input_dev_t in_iio_dev = { //.input_filter_fn = input_filter_imu_identity, }; +static void rc71l_timer_touchscreen( + const dev_in_settings_t *const conf, + struct libevdev* evdev, + const char* const timer_name, + uint64_t expired, + void* user_data +) { + +} + +static int touchscreen_ev_map( + const dev_in_settings_t *const conf, + const evdev_collected_t *const e, + in_message_t *const messages, + size_t messages_len, + void* user_data +) { + int written_msg = 0; + + for (size_t i = 0; i < e->ev_count; ++i) { + if (e->ev[i].type == EV_ABS) { + if (e->ev[i].code == ABS_MT_TRACKING_ID) { + const in_message_t current_message = { + .type = GAMEPAD_SET_ELEMENT, + .data = { + .gamepad_set = { + .element = GAMEPAD_TOUCHPAD_TOUCH_ACTIVE, + .status = { + .touchpad_active = { + .status = e->ev[i].value, + } + } + } + } + }; + + messages[written_msg++] = current_message; + } else if (e->ev[i].code == ABS_MT_POSITION_X) { + const in_message_t current_message = { + .type = GAMEPAD_SET_ELEMENT, + .data = { + .gamepad_set = { + .element = GAMEPAD_TOUCHPAD_X, + .status = { + .touchpad_active = { + .status = e->ev[i].value, + } + } + } + } + }; + + messages[written_msg++] = current_message; + } else if (e->ev[i].code == ABS_MT_POSITION_Y) { + const in_message_t current_message = { + .type = GAMEPAD_SET_ELEMENT, + .data = { + .gamepad_set = { + .element = GAMEPAD_TOUCHPAD_Y, + .status = { + .touchpad_active = { + .status = e->ev[i].value, + } + } + } + } + }; + + messages[written_msg++] = current_message; + } + } + } + + return written_msg; +} + +static input_dev_t in_touchscreen_dev = { + .dev_type = input_dev_type_uinput, + .filters = { + .ev = { + .name = "NVTK0603:00 0603:F200" + } + }, + .user_data = NULL, + .map = { + .ev_callbacks = { + .input_map_fn = touchscreen_ev_map, + .timeout_callback = rc71l_timer_touchscreen, + }, + } +}; + static void rc71l_timer_asus_kbd( const dev_in_settings_t *const conf, struct libevdev* evdev, @@ -1338,8 +1431,9 @@ input_dev_composite_t rc71l_composite = { &in_asus_kb_3_dev, &nkey_dev, &timer_dev, + &in_touchscreen_dev, }, - .dev_count = 7, + .dev_count = 8, .init_fn = rc71l_platform_init, .deinit_fn = rc71l_platform_deinit, .leds_fn = rc71l_platform_leds, diff --git a/virt_ds5.c b/virt_ds5.c index 2a4cdf2..a2bff02 100644 --- a/virt_ds5.c +++ b/virt_ds5.c @@ -1322,9 +1322,17 @@ void virt_dualsense_compose(virt_dualsense_t *const gamepad, gamepad_status_t *c memcpy(&out_shifted_buf[26], &a_z, sizeof(int16_t)); memcpy(&out_shifted_buf[28], ×tamp, sizeof(timestamp)); - // TODO: when touch is detected send 0x7F, when not 0x80 - out_shifted_buf[33] = 0x80; //touch0 active? - out_shifted_buf[37] = 0x80; //touch1 active? + // point of contact number 0 + out_shifted_buf[33] = in_device_status->touchpad_touch_num == -1 ? 0x80 : 0x7F; //contact + out_shifted_buf[34] = in_device_status->touchpad_x & (int16_t)0x00FF; //x_lo + out_shifted_buf[35] = ((in_device_status->touchpad_x & (int16_t)0x0F00) >> (int16_t)8) | ((in_device_status->touchpad_y & (int16_t)0x000F) >> (int16_t)0); //x_hi:4 y_lo:4 + out_shifted_buf[36] = ((in_device_status->touchpad_y & (int16_t)0x0FF0) >> (int16_t)4); //y_hi + + // point of contact number 1 + out_shifted_buf[37] = 0x80; //contact + out_shifted_buf[38] = 0x00; //x_lo + out_shifted_buf[39] = 0x00; //x_hi:4 y_lo:4 + out_shifted_buf[40] = 0x00; //y_hi /* buf[30] = 0x1b; // no headset attached