Skip to content

Commit

Permalink
fix(AllyX): Add Ally X Support
Browse files Browse the repository at this point in the history
  • Loading branch information
pastaq committed Jul 29, 2024
1 parent b545cd9 commit 72b0f39
Show file tree
Hide file tree
Showing 24 changed files with 1,393 additions and 62 deletions.
4 changes: 2 additions & 2 deletions rootfs/usr/share/inputplumber/capability_maps/ally_type1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mapping:
- keyboard: KeyF16
target_event:
gamepad:
button: Guide #Select
button: Guide
- name: Control Center (Long)
source_events:
- keyboard: KeyLeftCtrl
Expand All @@ -32,7 +32,7 @@ mapping:
- keyboard: KeyProg1
target_event:
gamepad:
button: QuickAccess #Start
button: QuickAccess
- name: Armory Crate (Long)
source_events:
- keyboard: KeyF17
Expand Down
5 changes: 5 additions & 0 deletions rootfs/usr/share/inputplumber/devices/50-rog_ally.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ matches:
# One or more source devices to combine into a single virtual device. The events
# from these devices will be watched and translated according to the key map.
source_devices:
- group: gamepad # Used for setting attributes on load
hidraw:
vendor_id: 0x0b05
product_id: 0x1abe
interface_num: 2
- group: gamepad
evdev:
name: Microsoft X-Box 360 pad
Expand Down
57 changes: 57 additions & 0 deletions rootfs/usr/share/inputplumber/devices/50-rog_ally_x.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/ShadowBlip/InputPlumber/main/rootfs/usr/share/inputplumber/schema/composite_device_v1.json
# Schema version number
version: 1

# The type of configuration schema
kind: CompositeDevice

# Name of the composite device mapping
name: ASUS ROG Ally X

# Only allow a single source device per composite device of this type.
single_source: false

# Only use this profile if *any* of the given matches matches. If this list is
# empty, then the source devices will *always* be checked.
# /sys/class/dmi/id/product_name
matches:
- dmi_data:
board_name: RC72LA
sys_vendor: ASUSTeK COMPUTER INC.

# One or more source devices to combine into a single virtual device. The events
# from these devices will be watched and translated according to the key map.
source_devices:
- group: gamepad # Used for setting attributes on load
hidraw:
vendor_id: 0x0b05
product_id: 0x1b4c
interface_num: 2
- group: gamepad
evdev:
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]
handler: event*
- group: imu
iio:
name: bmi323-imu
mount_matrix:
x: [-1, 0, 0]
y: [0, 0, -1]
z: [0, 1, 0]

# The target input device(s) that the virtual device profile can use
target_devices:
- xbox-elite
- mouse
- keyboard

# The ID of a device event mapping in the 'event_maps' folder
capability_map_id: aly1
38 changes: 20 additions & 18 deletions rootfs/usr/share/inputplumber/schema/capability_map_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,41 +260,43 @@
"button": {
"type": "string",
"enum": [
"South",
"East",
"North",
"West",
"Start",
"Select",
"Guide",
"QuickAccess",
"QuickAccess2",
"Keyboard",
"Screenshot",
"DPadUp",
"C",
"DPadDown",
"DPadLeft",
"DPadRight",
"DPadUp",
"East",
"Guide",
"Keyboard",
"LeftBumper",
"LeftTop",
"LeftTrigger",
"LeftPaddle1",
"LeftPaddle2",
"LeftPaddle3",
"LeftStick",
"LeftStickTouch",
"LeftTouchpadTouch",
"LeftTop",
"LeftTouchpadPress",
"LeftTouchpadTouch",
"LeftTrigger",
"North",
"QuickAccess",
"QuickAccess2",
"RightBumper",
"RightTop",
"RightTrigger",
"RightPaddle1",
"RightPaddle2",
"RightPaddle3",
"RightStick",
"RightStickTouch",
"RightTop",
"RightTouchpadPress",
"RightTouchpadTouch",
"RightTouchpadPress"
"RightTrigger",
"Screenshot",
"Select",
"South",
"Start",
"West",
"Z"
]
},
"trigger": {
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/lego/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Events that can be emitted by the Steam Deck controller
/// Events that can be emitted by the Legion Go controller
#[derive(Clone, Debug)]
pub enum Event {
Button(ButtonEvent),
Expand Down Expand Up @@ -157,3 +157,4 @@ pub enum StatusEvent {
RightControllerMode0(StatusInput),
RightControllerMode1(StatusInput),
}

2 changes: 2 additions & 0 deletions src/drivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ pub mod fts3528;
pub mod iio_imu;
pub mod lego;
pub mod opineo;
pub mod rog_ally;
pub mod steam_deck;
pub mod xpad_uhid;
4 changes: 2 additions & 2 deletions src/drivers/opineo/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ impl Driver {
//log::trace!("---- End Report ----");

// Update the state
let old_dinput_state = self.update_touchpad_state(input_report);
let old_state = self.update_touchpad_state(input_report);

// Translate the state into a stream of input events
let events = self.translate_touch(old_dinput_state);
let events = self.translate_touch(old_state);

Ok(events)
}
Expand Down
66 changes: 66 additions & 0 deletions src/drivers/rog_ally/driver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use std::{error::Error, ffi::OsStr};

use udev::Device;

use crate::udev::device::{AttributeSetter, UdevDevice};

// Hardware ID's
const ALLY_PID: u16 = 0x1abe;
const ALLYX_PID: u16 = 0x1b4c;
pub const PIDS: [u16; 2] = [ALLY_PID, ALLYX_PID];
pub const VID: u16 = 0x0b05;

pub struct Driver {
_device: UdevDevice,
}

impl Driver {
pub fn new(udevice: UdevDevice) -> Result<Self, Box<dyn Error + Send + Sync>> {
let vid = udevice.id_vendor();
let pid = udevice.id_product();
if VID != vid || !PIDS.contains(&pid) {
return Err(format!("'{}' is not an ROG Ally controller", udevice.devnode()).into());
}

// Set the controller buttons to the correct values at startup
let device = udevice.get_device()?;
let Some(mut parent) = device.parent() else {
return Err("Failed to get device parent".into());
};
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()),
};
} else {
return Err("Device is not an asus device.".into());
}

Ok(Self { _device: udevice })
}
}

pub fn set_attribute(
mut device: Device,
attribute: &str,
value: &str,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let result = device.set_attribute_on_tree(attribute, value);
match result {
Ok(r) => {
log::debug!("set {attribute} to {value}");
Ok(r)
}
Err(e) => Err(format!("Could not set {attribute} to {value}: {e:?}").into()),
}
}
1 change: 1 addition & 0 deletions src/drivers/rog_ally/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod driver;
Loading

0 comments on commit 72b0f39

Please sign in to comment.