From d9f61230e9c8ddb43ea673210a64edcab6be0491 Mon Sep 17 00:00:00 2001 From: William Edwards Date: Thu, 27 Feb 2025 10:54:56 -0800 Subject: [PATCH] fix(Unified Gamepad): implement top buttons and touchscreen --- src/drivers/unified_gamepad/capability.rs | 21 ++++++--- src/input/target/unified_gamepad.rs | 52 ++++++++++++++++++++--- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/drivers/unified_gamepad/capability.rs b/src/drivers/unified_gamepad/capability.rs index bce8666..5abb020 100644 --- a/src/drivers/unified_gamepad/capability.rs +++ b/src/drivers/unified_gamepad/capability.rs @@ -640,6 +640,12 @@ pub enum InputCapability { GamepadButtonRightStick = 0x13e, /* Non-standard gamepad codes */ + /// Dedicated button to open an on-screen keyboard + GamepadButtonKeyboard = 0x304, + /// Dedicated button to take screenshots + GamepadButtonScreenshot = 0x305, + /// Dedicated mute button, Sony DualSense Mute + GamepadButtonMute = 0x306, /// Left back paddle button, Xbox P3, Steam Deck L4 GamepadButtonLeftPaddle1 = 0x307, /// Left back paddle button, Xbox P4, Steam Deck L5 @@ -657,12 +663,10 @@ pub enum InputCapability { /// Touch binary sensor for right stick GamepadButtonRightStickTouch = 0x30e, - /// Dedicated button to open an on-screen keyboard - GamepadButtonKeyboard = 0x304, - /// Dedicated button to take screenshots - GamepadButtonScreenshot = 0x305, - /// Dedicated mute button, Sony DualSense Mute - GamepadButtonMute = 0x306, + /// Top left button next to the left trigger, Ayaneo LC + GamepadButtonLeftTop = 0x30f, + /// Top left button next to the left trigger, Ayaneo RC + GamepadButtonRightTop = 0x310, /// Left analog stick GamepadAxisLeftStick = 0x400, @@ -704,4 +708,9 @@ pub enum InputCapability { TouchpadCenterButton = 0x704, /// Right touchpad button press TouchpadRightButton = 0x705, + + /// 'Main' Touchscreen touch motion + TouchscreenMotion = 0x710, + /// Top touchscreen motion for dualscreen touch devices + TouchscreenTopMotion = 0x711, } diff --git a/src/input/target/unified_gamepad.rs b/src/input/target/unified_gamepad.rs index 4bf309f..ea880b0 100644 --- a/src/input/target/unified_gamepad.rs +++ b/src/input/target/unified_gamepad.rs @@ -643,7 +643,46 @@ impl From for StateUpdate { } }, }, - Capability::Touchscreen(_) => Self::default(), + Capability::Touchscreen(touch) => match touch { + Touch::Motion => { + let value = match event.get_value() { + InputValue::Touch { + index, + is_touching, + pressure, + x, + y, + } => TouchValue { + index: Integer::from_primitive(index), + is_touching, + pressure: pressure + .map(|p| (p * u8::MAX as f64) as u8) + .unwrap_or(u8::MAX), + x: x.map(|x| (x * u16::MAX as f64) as u16).unwrap_or(0), + y: y.map(|y| (y * u16::MAX as f64) as u16).unwrap_or(0), + }, + _ => { + return Self::default(); + } + }; + let value = ValueUpdate::Touch(value); + + Self { capability, value } + } + Touch::Button(_) => { + let value = match event.get_value() { + InputValue::Bool(value) => BoolUpdate { value }, + InputValue::Float(value) => BoolUpdate { value: value > 0.5 }, + _ => { + // Cannot convert other values to bool + return Self::default(); + } + }; + let value = ValueUpdate::Bool(value); + + Self { capability, value } + } + }, } } } @@ -676,7 +715,7 @@ impl From for InputCapability { GamepadButton::DPadLeft => Self::GamepadButtonDpadLeft, GamepadButton::DPadRight => Self::GamepadButtonDpadRight, GamepadButton::LeftBumper => Self::GamepadButtonLeftBumper, - GamepadButton::LeftTop => Self::default(), + GamepadButton::LeftTop => Self::GamepadButtonLeftTop, GamepadButton::LeftTrigger => Self::GamepadButtonLeftTrigger, GamepadButton::LeftPaddle1 => Self::GamepadButtonLeftPaddle1, GamepadButton::LeftPaddle2 => Self::GamepadButtonLeftPaddle2, @@ -684,7 +723,7 @@ impl From for InputCapability { GamepadButton::LeftStick => Self::GamepadButtonLeftStick, GamepadButton::LeftStickTouch => Self::GamepadButtonLeftStickTouch, GamepadButton::RightBumper => Self::GamepadButtonRightBumper, - GamepadButton::RightTop => Self::default(), + GamepadButton::RightTop => Self::GamepadButtonRightTop, GamepadButton::RightTrigger => Self::GamepadButtonRightTrigger, GamepadButton::RightPaddle1 => Self::GamepadButtonRightPaddle1, GamepadButton::RightPaddle2 => Self::GamepadButtonRightPaddle2, @@ -727,7 +766,10 @@ impl From for InputCapability { Touch::Button(_) => Self::TouchpadCenterButton, }, }, - Capability::Touchscreen(_) => Self::default(), + Capability::Touchscreen(touch) => match touch { + Touch::Motion => Self::TouchscreenMotion, + Touch::Button(_) => Self::default(), + }, } } } @@ -750,7 +792,7 @@ impl From for InputCapabilityInfo { Gamepad::Gyro => Self::new(capability, ValueType::Int16Vector3), }, Capability::Mouse(_) => Self::default(), - Capability::Keyboard(_) => Self::default(), + Capability::Keyboard(_) => Self::new(capability, ValueType::Bool), Capability::Touchpad(touchpad) => match touchpad { Touchpad::LeftPad(pad) => match pad { Touch::Motion => Self::new(capability, ValueType::Touch),