Skip to content

Commit

Permalink
fix(ROG Ally/X): Support latest ally patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
pastaq committed Aug 5, 2024
1 parent 0b91da3 commit 8c62618
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
12 changes: 10 additions & 2 deletions rootfs/usr/share/inputplumber/devices/50-rog_ally.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 11 additions & 5 deletions rootfs/usr/share/inputplumber/devices/50-rog_ally_x.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 31 additions & 13 deletions src/drivers/rog_ally/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit 8c62618

Please sign in to comment.