Skip to content

Commit

Permalink
feat(Grand Unified Controller): add unified controller driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Feb 19, 2025
1 parent 13a515e commit dd92326
Show file tree
Hide file tree
Showing 16 changed files with 2,887 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ setup: /usr/share/dbus-1/system.d/$(DBUS_NAME).conf ## Install dbus policies
/usr/share/dbus-1/system.d/$(DBUS_NAME).conf
sudo systemctl reload dbus

.PHONY: example
example:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER='sudo -E' cargo run --example unified_gamepad

##@ Distribution

.PHONY: dist
Expand Down
44 changes: 44 additions & 0 deletions examples/unified_gamepad/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::{env, fs, thread::sleep, time::Duration};

use inputplumber::drivers::grand_unified_controller::driver::Driver;

const SEARCH_PATH: &str = "/sys/bus/hid/devices";

fn main() {
// Look for a Unified Controller
let paths = fs::read_dir(SEARCH_PATH).expect("Unable to read HID devices");

println!("Searching for Unified Controller");
let mut device_sys_path = None;
for path in paths {
let path = path.unwrap();
let mut file_path = path.path().into_os_string();
file_path.push("/uevent");
println!("{file_path:?}");

let data = fs::read_to_string(file_path).unwrap();
println!("{data}");
if data.contains("InputPlumber Unified Gamepad") {
device_sys_path = Some(path);
break;
}
}

// Get the hidraw name of the device
let device_sys_path = device_sys_path.expect("Unable to find Unified Controller");
let mut hid_sys_path = device_sys_path.path().into_os_string();
hid_sys_path.push("/hidraw");
let paths = fs::read_dir(hid_sys_path).expect("Unable to read HID device info");
let device_name = paths.into_iter().next().unwrap().unwrap().file_name();

println!("Found Unified Controller device: {device_name:?}");
println!("Starting Unified Controller driver!");

let path = format!("/dev/{}", device_name.to_string_lossy());
let mut driver = Driver::new(path).expect("Failed to create driver instance");

loop {
let events = driver.poll().expect("Failed to poll device");
sleep(Duration::from_millis(1));
}
}
Loading

0 comments on commit dd92326

Please sign in to comment.