From 8c626182db6d37ddf894b595d40739820f472320 Mon Sep 17 00:00:00 2001 From: "Derek J. Clark" Date: Wed, 31 Jul 2024 15:14:27 -0700 Subject: [PATCH] fix(ROG Ally/X): Support latest ally patches. --- .../inputplumber/devices/50-rog_ally.yaml | 12 ++++- .../inputplumber/devices/50-rog_ally_x.yaml | 16 ++++--- src/drivers/rog_ally/driver.rs | 44 +++++++++++++------ 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/rootfs/usr/share/inputplumber/devices/50-rog_ally.yaml b/rootfs/usr/share/inputplumber/devices/50-rog_ally.yaml index adb5da2..65164ca 100644 --- a/rootfs/usr/share/inputplumber/devices/50-rog_ally.yaml +++ b/rootfs/usr/share/inputplumber/devices/50-rog_ally.yaml @@ -30,13 +30,21 @@ source_devices: - group: gamepad evdev: name: Microsoft X-Box 360 pad - phys_path: usb-0000:0[8-a]:00.3-2/input0 + vendor_id: 045e + product_id: 028e + handler: event* + - group: keyboard + evdev: + name: ASUS ROG Ally Config + vendor_id: 0b05 + product_id: 1abe handler: event* - group: keyboard unique: false evdev: name: Asus Keyboard - phys_path: usb-0000:0[8-a]:00.3-3/input[0-2] + vendor_id: 0b05 + product_id: 1abe handler: event* - group: imu iio: diff --git a/rootfs/usr/share/inputplumber/devices/50-rog_ally_x.yaml b/rootfs/usr/share/inputplumber/devices/50-rog_ally_x.yaml index 6555978..a93568e 100644 --- a/rootfs/usr/share/inputplumber/devices/50-rog_ally_x.yaml +++ b/rootfs/usr/share/inputplumber/devices/50-rog_ally_x.yaml @@ -27,17 +27,23 @@ source_devices: vendor_id: 0x0b05 product_id: 0x1b4c interface_num: 2 + - group: gamepad # Used for setting attributes on load + hidraw: + vendor_id: 0x0b05 + product_id: 0x1b4c + interface_num: 5 - group: gamepad evdev: - name: "ASUS ROG Ally X Gamepad" - vendor_id: "0b05" - product_id: "1b4c" + name: ASUS ROG Ally X Gamepad + vendor_id: 0b05 + product_id: 1b4c handler: event* - group: keyboard unique: false evdev: - name: "Asus Keyboard" - phys_path: usb-0000:64:00.3-2/input[2-3] + name: Asus Keyboard + vendor_id: 0b05 + product_id: 1b4c handler: event* - group: imu iio: diff --git a/src/drivers/rog_ally/driver.rs b/src/drivers/rog_ally/driver.rs index 0b1884a..9769880 100644 --- a/src/drivers/rog_ally/driver.rs +++ b/src/drivers/rog_ally/driver.rs @@ -2,7 +2,7 @@ use std::{error::Error, ffi::OsStr}; use udev::Device; -use crate::udev::device::{AttributeSetter, UdevDevice}; +use crate::udev::device::{AttributeGetter, AttributeSetter, UdevDevice}; // Hardware ID's const ALLY_PID: u16 = 0x1abe; @@ -30,20 +30,38 @@ impl Driver { let Some(driver) = parent.driver() else { return Err("Failed to identify device driver".into()); }; - if driver.to_str().unwrap() == "asus" { - set_attribute(device.clone(), "btn_m1/remap", "kb_f15")?; - set_attribute(device.clone(), "btn_m2/remap", "kb_f14")?; - set_attribute(device, "gamepad_mode", "1")?; - //TODO: Figure out why this fails and manually running the same thing - //doesn't. - //set_attribute(device, "apply", "1")?; - let result = parent.set_attribute_value(OsStr::new("apply"), OsStr::new("1")); - match result { - Ok(_) => log::debug!("set apply to 1"), - Err(e) => return Err(format!("Could set apply to 1: {e:?}").into()), + // Apply settings for the controller + if driver.to_str().unwrap() == "asus_rog_ally" { + let if_num = device.get_attribute_from_tree("bInterfaceNumber"); + let if_num = if_num.as_str(); + match if_num { + "02" => { + // Ally and Ally X, map back buttons and ensure it is in gamepad mode. + log::debug!("Setting buttons and gamepad mode."); + set_attribute(device.clone(), "btn_m1/remap", "kb_f15")?; + set_attribute(device.clone(), "btn_m2/remap", "kb_f14")?; + set_attribute(device, "gamepad_mode", "1")?; + //TODO: Figure out why this fails and manually running the same thing + //doesn't. + //set_attribute(device, "apply", "1")?; + let result = + parent.set_attribute_value(OsStr::new("apply_all"), OsStr::new("1")); + match result { + Ok(_) => log::debug!("set apply_all to 1"), + Err(e) => return Err(format!("Could set apply_all to 1: {e:?}").into()), + }; + } + "05" => { + // Ally X only, switch from driver emiting a BTN_MODE with CC and a + // BTN_MODE/BTN_SOUTH chord with AC to the same events as original + // Ally so we can capture them as the Guide and QuickAccess Capabilities. + log::debug!("Setting qam mode."); + set_attribute(device, "qam_mode", "0")?; + } + _ => return Err(format!("Invalid interface number {if_num} provided.").into()), }; } else { - return Err("Device is not an asus device.".into()); + return Err("Device is not using the asus_rog_ally driver.".into()); } Ok(Self { _device: udevice })