Merge branch 'fluke/fixup' into 'next'

Fixes: Handle keyboard nodes better.

Closes #4, #8, #10, and #7

See merge request asus-linux/asus-nb-ctrl!2
This commit is contained in:
Luke Jones
2020-09-09 23:41:29 +00:00
13 changed files with 143 additions and 126 deletions

View File

@@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
# [1.1.0] - 2020-09-10
### Changed
- Uses string instead of debug print for some errors
- Add interface num arg for LED controller (should help support
older laptops better)
- Some slightly better error messages
- Fix an idiotic mistake in `for i in 0..2.. if i > 0` -_-
- Remove "unsupported" warning on laptop ctrl
- Silence warning about AniMe not existing
- Adjust the turbo-toggle CLI arg
- Version bump for new release with fancurves
## [1.0.2] - 2020-08-13 ## [1.0.2] - 2020-08-13
### Changed ### Changed

44
Cargo.lock generated
View File

@@ -17,7 +17,7 @@ dependencies = [
[[package]] [[package]]
name = "asus-nb" name = "asus-nb"
version = "0.15.0" version = "1.1.0"
dependencies = [ dependencies = [
"dbus", "dbus",
"gumdrop", "gumdrop",
@@ -31,7 +31,7 @@ dependencies = [
[[package]] [[package]]
name = "asus-nb-ctrl" name = "asus-nb-ctrl"
version = "1.0.4" version = "1.1.0"
dependencies = [ dependencies = [
"asus-nb", "asus-nb",
"async-trait", "async-trait",
@@ -54,9 +54,9 @@ dependencies = [
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.38" version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e1a4a2f97ce50c9d0282c1468816208588441492b40d813b2e0419c22c05e7f" checksum = "687c230d85c0a52504709705fc8a53e4a692b83a2184f03dae73e38e1e93a783"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -74,21 +74,6 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "bit-set"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.2.1" version = "1.2.1"
@@ -479,9 +464,9 @@ dependencies = [
[[package]] [[package]]
name = "net2" name = "net2"
version = "0.2.34" version = "0.2.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
@@ -596,9 +581,9 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.19" version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@@ -659,11 +644,10 @@ dependencies = [
[[package]] [[package]]
name = "rusb" name = "rusb"
version = "0.6.0" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884a9ee2c66cdb5ca6c5243ea91cdbba9865506792c3d175d1ad8de8bb0ea64a" checksum = "327ba984f811d7e34f52f08b5745911ce89c432e1098879f2f8288c76a88aa0c"
dependencies = [ dependencies = [
"bit-set",
"libc", "libc",
"libusb1-sys", "libusb1-sys",
] ]
@@ -732,9 +716,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.39" version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9" checksum = "963f7d3cc59b59b9325165add223142bbf1df27655d07789f109896d353d8350"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -770,9 +754,9 @@ checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
[[package]] [[package]]
name = "tar" name = "tar"
version = "0.4.29" version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8a4c1d0bee3230179544336c15eefb563cf0302955d962e456542323e8c2e8a" checksum = "489997b7557e9a43e192c527face4feacc78bfbe6eed67fd55c4c9e381cba290"
dependencies = [ dependencies = [
"filetime", "filetime",
"libc", "libc",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "asus-nb-ctrl" name = "asus-nb-ctrl"
version = "1.0.4" version = "1.1.0"
license = "MPL-2.0" license = "MPL-2.0"
readme = "README.md" readme = "README.md"
authors = ["Luke <luke@ljones.dev>"] authors = ["Luke <luke@ljones.dev>"]
@@ -23,7 +23,7 @@ path = "src/daemon.rs"
[dependencies] [dependencies]
asus-nb = { path = "../asus-nb" } asus-nb = { path = "../asus-nb" }
rusb = "=0.6.0" rusb = "^0.6.0"
udev = "^0.4.0" udev = "^0.4.0"
async-trait = "0.1.36" async-trait = "0.1.36"

View File

@@ -37,7 +37,10 @@ impl Config {
self = Config::create_default(&mut file, &supported_led_modes); self = Config::create_default(&mut file, &supported_led_modes);
} else { } else {
self = serde_json::from_str(&buf).unwrap_or_else(|_| { self = serde_json::from_str(&buf).unwrap_or_else(|_| {
warn!("Could not deserialise {}", CONFIG_PATH); warn!(
"Could not deserialise {}. Overwriting with default",
CONFIG_PATH
);
Config::create_default(&mut file, &supported_led_modes) Config::create_default(&mut file, &supported_led_modes)
}); });
} }
@@ -126,7 +129,7 @@ impl Config {
pub struct Profile { pub struct Profile {
pub min_percentage: u8, pub min_percentage: u8,
pub max_percentage: u8, pub max_percentage: u8,
pub no_turbo: bool, pub turbo: bool,
pub fan_preset: u8, pub fan_preset: u8,
pub fan_curve: Option<Curve>, pub fan_curve: Option<Curve>,
} }
@@ -139,7 +142,7 @@ impl Default for Profile {
Profile { Profile {
min_percentage: 0, min_percentage: 0,
max_percentage: 100, max_percentage: 100,
no_turbo: false, turbo: false,
fan_preset: 0, fan_preset: 0,
fan_curve: None, fan_curve: None,
} }

View File

@@ -67,21 +67,18 @@ impl CtrlAnimeDisplay {
#[inline] #[inline]
pub fn new() -> Result<CtrlAnimeDisplay, Box<dyn Error>> { pub fn new() -> Result<CtrlAnimeDisplay, Box<dyn Error>> {
// We don't expect this ID to ever change // We don't expect this ID to ever change
let device = CtrlAnimeDisplay::get_device(0x0b05, 0x193b).map_err(|err| { let device = CtrlAnimeDisplay::get_device(0x0b05, 0x193b)?;
warn!("Could not get AniMe display handle: {:?}", err);
err
})?;
let mut device = device.open()?; let mut device = device.open()?;
device.reset()?; device.reset()?;
device.set_auto_detach_kernel_driver(true).map_err(|err| { device.set_auto_detach_kernel_driver(true).map_err(|err| {
error!("Auto-detach kernel driver failed: {:?}", err); error!("Auto-detach kernel driver failed: {}", err);
err err
})?; })?;
device.claim_interface(0).map_err(|err| { device.claim_interface(0).map_err(|err| {
error!("Could not claim device interface: {:?}", err); error!("Could not claim device interface: {}", err);
err err
})?; })?;
@@ -120,7 +117,6 @@ impl CtrlAnimeDisplay {
/// Should only be used if the bytes you are writing are verified correct /// Should only be used if the bytes you are writing are verified correct
#[inline] #[inline]
async fn write_bytes(&self, message: &[u8]) -> Result<(), AuraError> { async fn write_bytes(&self, message: &[u8]) -> Result<(), AuraError> {
let prev = std::time::Instant::now();
match self.handle.write_control( match self.handle.write_control(
0x21, // request_type 0x21, // request_type
0x09, // request 0x09, // request
@@ -129,15 +125,10 @@ impl CtrlAnimeDisplay {
message, message,
Duration::from_millis(200), Duration::from_millis(200),
) { ) {
Ok(_) => { Ok(_) => {}
println!(
"{:?}",
std::time::Instant::now().duration_since(prev).as_micros()
);
}
Err(err) => match err { Err(err) => match err {
rusb::Error::Timeout => {} rusb::Error::Timeout => {}
_ => error!("Failed to write to led interrupt: {:?}", err), _ => error!("Failed to write to led interrupt: {}", err),
}, },
} }
Ok(()) Ok(())

View File

@@ -34,7 +34,7 @@ impl crate::Controller for CtrlCharge {
while let Some(n) = recv.recv().await { while let Some(n) = recv.recv().await {
let mut config = config.lock().await; let mut config = config.lock().await;
self.set_charge_limit(n, &mut config) self.set_charge_limit(n, &mut config)
.unwrap_or_else(|err| warn!("charge_limit: {:?}", err)); .unwrap_or_else(|err| warn!("charge_limit: {}", err));
} }
})] })]
} }
@@ -80,11 +80,11 @@ impl CtrlCharge {
.write(true) .write(true)
.open(self.path) .open(self.path)
.map_err(|err| { .map_err(|err| {
warn!("Failed to open battery charge limit path: {:?}", err); warn!("Failed to open battery charge limit path: {}", err);
err err
})?; })?;
file.write_all(limit.to_string().as_bytes()) file.write_all(limit.to_string().as_bytes())
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", BAT_CHARGE_PATH, err)); .unwrap_or_else(|err| error!("Could not write to {}, {}", BAT_CHARGE_PATH, err));
info!("Battery charge limit: {}", limit); info!("Battery charge limit: {}", limit);
config.read(); config.read();

View File

@@ -47,7 +47,7 @@ impl crate::Controller for CtrlFanAndCPU {
config.read(); config.read();
lock.handle_profile_event(&event, &mut config) lock.handle_profile_event(&event, &mut config)
.unwrap_or_else(|err| warn!("{:?}", err)); .unwrap_or_else(|err| warn!("{}", err));
} }
}), }),
// need to watch file path // need to watch file path
@@ -57,7 +57,7 @@ impl crate::Controller for CtrlFanAndCPU {
let mut lock = gate2.lock().await; let mut lock = gate2.lock().await;
let mut config = config.lock().await; let mut config = config.lock().await;
lock.fan_mode_check_change(&mut config) lock.fan_mode_check_change(&mut config)
.unwrap_or_else(|err| warn!("fan_ctrl: {:?}", err)); .unwrap_or_else(|err| warn!("fan_ctrl: {}", err));
} }
}), }),
] ]
@@ -65,8 +65,8 @@ impl crate::Controller for CtrlFanAndCPU {
async fn reload_from_config(&mut self, config: &mut Config) -> Result<(), Box<dyn Error>> { async fn reload_from_config(&mut self, config: &mut Config) -> Result<(), Box<dyn Error>> {
let mut file = OpenOptions::new().write(true).open(self.path)?; let mut file = OpenOptions::new().write(true).open(self.path)?;
file.write_all(format!("{:?}\n", config.power_profile).as_bytes()) file.write_all(format!("{}\n", config.power_profile).as_bytes())
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", self.path, err)); .unwrap_or_else(|err| error!("Could not write to {}, {}", self.path, err));
let profile = config.active_profile.clone(); let profile = config.active_profile.clone();
self.set_profile(&profile, config)?; self.set_profile(&profile, config)?;
info!( info!(
@@ -92,7 +92,7 @@ impl CtrlFanAndCPU {
} else { } else {
Err(std::io::Error::new( Err(std::io::Error::new(
std::io::ErrorKind::NotFound, std::io::ErrorKind::NotFound,
"Fan mode not available", "Fan mode not available, you may require a v5.8 series kernel or newer",
)) ))
} }
} }
@@ -126,7 +126,7 @@ impl CtrlFanAndCPU {
self.set_profile(&new_profile, config)?; self.set_profile(&new_profile, config)?;
info!("Profile was changed: {:?}", &new_profile); info!("Profile was changed: {}", &new_profile);
} }
return Ok(()); return Ok(());
} }
@@ -153,8 +153,8 @@ impl CtrlFanAndCPU {
mode_config.fan_preset = preset; mode_config.fan_preset = preset;
config.write(); config.write();
fan_ctrl fan_ctrl
.write_all(format!("{:?}\n", preset).as_bytes()) .write_all(format!("{}\n", preset).as_bytes())
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", self.path, err)); .unwrap_or_else(|err| error!("Could not write to {}, {}", self.path, err));
info!("Fan mode set to: {:?}", FanLevel::from(preset)); info!("Fan mode set to: {:?}", FanLevel::from(preset));
self.set_pstate_for_fan_mode(&mode, config)?; self.set_pstate_for_fan_mode(&mode, config)?;
self.set_fan_curve_for_fan_mode(&mode, config)?; self.set_fan_curve_for_fan_mode(&mode, config)?;
@@ -180,7 +180,7 @@ impl CtrlFanAndCPU {
config config
.power_profiles .power_profiles
.entry(profile_key.clone()) .entry(profile_key.clone())
.or_insert_with(|| Profile::default()) .or_insert_with(Profile::default)
} else { } else {
config config
.power_profiles .power_profiles
@@ -188,11 +188,8 @@ impl CtrlFanAndCPU {
.ok_or_else(|| RogError::MissingProfile(profile_key.clone()))? .ok_or_else(|| RogError::MissingProfile(profile_key.clone()))?
}; };
if command.turbo { if command.turbo.is_some() {
profile.no_turbo = false; profile.turbo = command.turbo.unwrap();
}
if command.no_turbo {
profile.no_turbo = true;
} }
if let Some(min_perc) = command.min_percentage { if let Some(min_perc) = command.min_percentage {
profile.min_percentage = min_perc; profile.min_percentage = min_perc;
@@ -220,8 +217,8 @@ impl CtrlFanAndCPU {
.ok_or_else(|| RogError::MissingProfile(profile.into()))?; .ok_or_else(|| RogError::MissingProfile(profile.into()))?;
let mut fan_ctrl = OpenOptions::new().write(true).open(self.path)?; let mut fan_ctrl = OpenOptions::new().write(true).open(self.path)?;
fan_ctrl fan_ctrl
.write_all(format!("{:?}\n", mode_config.fan_preset).as_bytes()) .write_all(format!("{}\n", mode_config.fan_preset).as_bytes())
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", self.path, err)); .unwrap_or_else(|err| error!("Could not write to {}, {}", self.path, err));
config.power_profile = mode_config.fan_preset; config.power_profile = mode_config.fan_preset;
self.set_pstate_for_fan_mode(profile, config)?; self.set_pstate_for_fan_mode(profile, config)?;
@@ -249,10 +246,10 @@ impl CtrlFanAndCPU {
if let Ok(pstate) = intel_pstate::PState::new() { if let Ok(pstate) = intel_pstate::PState::new() {
pstate.set_min_perf_pct(mode_config.min_percentage)?; pstate.set_min_perf_pct(mode_config.min_percentage)?;
pstate.set_max_perf_pct(mode_config.max_percentage)?; pstate.set_max_perf_pct(mode_config.max_percentage)?;
pstate.set_no_turbo(mode_config.no_turbo)?; pstate.set_no_turbo(!mode_config.turbo)?;
info!( info!(
"Intel CPU Power: min: {:?}%, max: {:?}%, turbo: {:?}", "Intel CPU Power: min: {}%, max: {}%, turbo: {}",
mode_config.min_percentage, mode_config.max_percentage, !mode_config.no_turbo mode_config.min_percentage, mode_config.max_percentage, mode_config.turbo
); );
} else { } else {
info!("Setting pstate for AMD CPU"); info!("Setting pstate for AMD CPU");
@@ -261,14 +258,14 @@ impl CtrlFanAndCPU {
.write(true) .write(true)
.open(AMD_BOOST_PATH) .open(AMD_BOOST_PATH)
.map_err(|err| { .map_err(|err| {
warn!("Failed to open AMD boost: {:?}", err); warn!("Failed to open AMD boost: {}", err);
err err
})?; })?;
let boost = if mode_config.no_turbo { "0" } else { "1" }; // opposite of Intel let boost = if mode_config.turbo { "0" } else { "1" }; // opposite of Intel
file.write_all(boost.as_bytes()) file.write_all(boost.as_bytes())
.unwrap_or_else(|err| error!("Could not write to {}, {:?}", AMD_BOOST_PATH, err)); .unwrap_or_else(|err| error!("Could not write to {}, {}", AMD_BOOST_PATH, err));
info!("AMD CPU Turbo: {:?}", boost); info!("AMD CPU Turbo: {}", boost);
} }
Ok(()) Ok(())
} }

View File

@@ -2,7 +2,7 @@
static LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; static LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
static LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; static LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
use crate::{config::Config, error::RogError}; use crate::{config::Config, error::RogError, laptops::HELP_ADDRESS};
use asus_nb::{ use asus_nb::{
aura_brightness_bytes, aura_modes::AuraModes, fancy::KeyColourArray, DBUS_IFACE, DBUS_PATH, aura_brightness_bytes, aura_modes::AuraModes, fancy::KeyColourArray, DBUS_IFACE, DBUS_PATH,
LED_MSG_LEN, LED_MSG_LEN,
@@ -18,9 +18,9 @@ use tokio::sync::Mutex;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
pub struct CtrlKbdBacklight { pub struct CtrlKbdBacklight {
led_node: String, led_node: Option<String>,
#[allow(dead_code)] #[allow(dead_code)]
kbd_node: String, kbd_node: Option<String>,
bright_node: String, bright_node: String,
supported_modes: Vec<u8>, supported_modes: Vec<u8>,
flip_effect_write: bool, flip_effect_write: bool,
@@ -81,7 +81,7 @@ impl crate::Controller for CtrlKbdBacklight {
let mut lock = gate2.lock().await; let mut lock = gate2.lock().await;
let mut config = config.lock().await; let mut config = config.lock().await;
lock.let_bright_check_change(&mut config) lock.let_bright_check_change(&mut config)
.unwrap_or_else(|err| warn!("led_ctrl: {:?}", err)); .unwrap_or_else(|err| warn!("led_ctrl: {}", err));
} }
}), }),
] ]
@@ -131,26 +131,29 @@ impl crate::Controller for CtrlKbdBacklight {
impl CtrlKbdBacklight { impl CtrlKbdBacklight {
#[inline] #[inline]
pub fn new(id_product: &str, supported_modes: Vec<u8>) -> Result<Self, std::io::Error> { pub fn new(id_product: &str, condev_iface: Option<&String>, supported_modes: Vec<u8>) -> Self {
Ok(CtrlKbdBacklight { // TODO: return error if *all* nodes are None
led_node: Self::get_node_failover(id_product, Self::scan_led_node)?, CtrlKbdBacklight {
kbd_node: Self::get_node_failover(id_product, Self::scan_kbd_node)?, led_node: Self::get_node_failover(id_product, None, Self::scan_led_node).ok(),
// brightness node path should always be constant but this *might* change? kbd_node: Self::get_node_failover(id_product, condev_iface, Self::scan_kbd_node).ok(),
// TODO: Check for existance
bright_node: "/sys/class/leds/asus::kbd_backlight/brightness".to_string(), bright_node: "/sys/class/leds/asus::kbd_backlight/brightness".to_string(),
supported_modes, supported_modes,
flip_effect_write: false, flip_effect_write: false,
}) }
} }
fn get_node_failover( fn get_node_failover(
id_product: &str, id_product: &str,
fun: fn(&str) -> Result<String, std::io::Error>, iface: Option<&String>,
fun: fn(&str, Option<&String>) -> Result<String, std::io::Error>,
) -> Result<String, std::io::Error> { ) -> Result<String, std::io::Error> {
for n in 0..2 { for n in 0..=2 {
match fun(id_product) { // 0,1,2 inclusive
match fun(id_product, iface) {
Ok(o) => return Ok(o), Ok(o) => return Ok(o),
Err(e) => { Err(e) => {
if n > 0 { if n == 2 {
warn!("Looking for node: {}", e.to_string()); warn!("Looking for node: {}", e.to_string());
std::thread::sleep(std::time::Duration::from_secs(1)); std::thread::sleep(std::time::Duration::from_secs(1));
} else { } else {
@@ -164,12 +167,24 @@ impl CtrlKbdBacklight {
Err(err) Err(err)
} }
fn scan_led_node(id_product: &str) -> Result<String, std::io::Error> { fn scan_led_node(id_product: &str, _: Option<&String>) -> Result<String, std::io::Error> {
let mut enumerator = udev::Enumerator::new()?; let mut enumerator = udev::Enumerator::new().map_err(|err| {
enumerator.match_subsystem("hidraw")?; warn!("{}", err);
err
})?;
enumerator.match_subsystem("hidraw").map_err(|err| {
warn!("{}", err);
err
})?;
for device in enumerator.scan_devices()? { for device in enumerator.scan_devices()? {
if let Some(parent) = device.parent_with_subsystem_devtype("usb", "usb_device")? { if let Some(parent) = device
.parent_with_subsystem_devtype("usb", "usb_device")
.map_err(|err| {
warn!("{}", err);
err
})?
{
if parent.attribute_value("idProduct").unwrap() == id_product { if parent.attribute_value("idProduct").unwrap() == id_product {
// && device.parent().unwrap().sysnum().unwrap() == 3 // && device.parent().unwrap().sysnum().unwrap() == 3
if let Some(dev_node) = device.devnode() { if let Some(dev_node) = device.devnode() {
@@ -183,28 +198,43 @@ impl CtrlKbdBacklight {
std::io::ErrorKind::NotFound, std::io::ErrorKind::NotFound,
"ASUS LED device node not found", "ASUS LED device node not found",
); );
warn!("Did not find a hidraw node for LED control, your device may be unsupported or require a kernel patch, see: {}", HELP_ADDRESS);
Err(err) Err(err)
} }
fn scan_kbd_node(id_product: &str) -> Result<String, std::io::Error> { fn scan_kbd_node(id_product: &str, iface: Option<&String>) -> Result<String, std::io::Error> {
let mut enumerator = udev::Enumerator::new()?; let mut enumerator = udev::Enumerator::new()?;
enumerator.match_subsystem("input")?; enumerator.match_subsystem("input").map_err(|err| {
enumerator.match_property("ID_MODEL_ID", id_product)?; warn!("{}", err);
err
})?;
enumerator
.match_property("ID_MODEL_ID", id_product)
.map_err(|err| {
warn!("{}", err);
err
})?;
for device in enumerator.scan_devices()? { for device in enumerator.scan_devices().map_err(|err| {
warn!("{}", err);
err
})? {
if let Some(dev_node) = device.devnode() { if let Some(dev_node) = device.devnode() {
if let Some(inum) = device.property_value("ID_USB_INTERFACE_NUM") { if let Some(inum) = device.property_value("ID_USB_INTERFACE_NUM") {
if inum == "02" { if let Some(iface) = iface {
info!("Using device at: {:?} for keyboard polling", dev_node); if inum == iface.as_str() {
return Ok(dev_node.to_string_lossy().to_string()); info!("Using device at: {:?} for keyboard polling", dev_node);
return Ok(dev_node.to_string_lossy().to_string());
}
} }
} }
} }
} }
let err = std::io::Error::new( let err = std::io::Error::new(
std::io::ErrorKind::NotFound, std::io::ErrorKind::NotFound,
"ASUS N-Key Consumer Device node not found", "ASUS keyboard 'Consumer Device' node not found",
); );
warn!("Did not find keyboard consumer device node, if expected functions are missing please file an issue at {}", HELP_ADDRESS);
Err(err) Err(err)
} }
@@ -238,9 +268,11 @@ impl CtrlKbdBacklight {
/// Should only be used if the bytes you are writing are verified correct /// Should only be used if the bytes you are writing are verified correct
#[inline] #[inline]
async fn write_bytes(&self, message: &[u8]) -> Result<(), Box<dyn Error>> { async fn write_bytes(&self, message: &[u8]) -> Result<(), Box<dyn Error>> {
if let Ok(mut file) = OpenOptions::new().write(true).open(&self.led_node) { if let Some(led_node) = &self.led_node {
file.write_all(message).unwrap(); if let Ok(mut file) = OpenOptions::new().write(true).open(led_node) {
return Ok(()); file.write_all(message).unwrap();
return Ok(());
}
} }
Err(Box::new(RogError::NotSupported)) Err(Box::new(RogError::NotSupported))
} }

View File

@@ -52,14 +52,11 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
}; };
let mut led_control = if let Some(laptop) = laptop { let mut led_control = if let Some(laptop) = laptop {
CtrlKbdBacklight::new(laptop.usb_product(), laptop.supported_modes().to_owned()) Some(CtrlKbdBacklight::new(
.map_or_else( laptop.usb_product(),
|err| { laptop.condev_iface(),
error!("{}", err); laptop.supported_modes().to_owned(),
None ))
},
Some,
)
} else { } else {
None None
}; };

View File

@@ -6,10 +6,11 @@ use std::io::Read;
pub static LEDMODE_CONFIG_PATH: &str = "/etc/asusd/asusd-ledmodes.toml"; pub static LEDMODE_CONFIG_PATH: &str = "/etc/asusd/asusd-ledmodes.toml";
static HELP_ADDRESS: &str = "https://gitlab.com/asus-linux/asus-nb-ctrl"; pub static HELP_ADDRESS: &str = "https://gitlab.com/asus-linux/asus-nb-ctrl";
pub struct LaptopBase { pub struct LaptopBase {
usb_product: String, usb_product: String,
condev_iface: Option<String>, // required for finding the Consumer Device interface
supported_modes: Vec<u8>, supported_modes: Vec<u8>,
} }
@@ -17,6 +18,9 @@ impl LaptopBase {
pub fn usb_product(&self) -> &str { pub fn usb_product(&self) -> &str {
&self.usb_product &self.usb_product
} }
pub fn condev_iface(&self) -> Option<&String> {
self.condev_iface.as_ref()
}
pub fn supported_modes(&self) -> &[u8] { pub fn supported_modes(&self) -> &[u8] {
&self.supported_modes &self.supported_modes
} }
@@ -37,6 +41,7 @@ pub fn match_laptop() -> Option<LaptopBase> {
info!("Found GL753 or similar"); info!("Found GL753 or similar");
return Some(LaptopBase { return Some(LaptopBase {
usb_product: "1854".to_string(), usb_product: "1854".to_string(),
condev_iface: None,
supported_modes: vec![STATIC, BREATHING, STROBE], supported_modes: vec![STATIC, BREATHING, STROBE],
}); });
} }
@@ -44,6 +49,11 @@ pub fn match_laptop() -> Option<LaptopBase> {
} }
} }
} }
warn!(
"Unsupported laptop, please request support at {}",
HELP_ADDRESS
);
warn!("Continuing with minimal support");
None None
} }
@@ -58,6 +68,7 @@ fn select_1866_device(prod: String) -> LaptopBase {
let mut laptop = LaptopBase { let mut laptop = LaptopBase {
usb_product: prod, usb_product: prod,
condev_iface: Some("02".to_owned()),
supported_modes: vec![], supported_modes: vec![],
}; };
@@ -67,13 +78,6 @@ fn select_1866_device(prod: String) -> LaptopBase {
return laptop; return laptop;
} }
} }
warn!(
"Unsupported laptop, please request support at {}",
HELP_ADDRESS
);
warn!("Continuing with minimal support");
laptop laptop
} }

View File

@@ -23,7 +23,7 @@ use std::sync::Arc;
use tokio::sync::{mpsc::Receiver, Mutex}; use tokio::sync::{mpsc::Receiver, Mutex};
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
pub static VERSION: &str = "1.0.4"; pub static VERSION: &str = "1.1.0";
use ::dbus::{nonblock::SyncConnection, tree::Signal}; use ::dbus::{nonblock::SyncConnection, tree::Signal};

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "asus-nb" name = "asus-nb"
version = "0.15.0" version = "1.1.0"
license = "MPL-2.0" license = "MPL-2.0"
readme = "README.md" readme = "README.md"
authors = ["Luke <luke@ljones.dev>"] authors = ["Luke <luke@ljones.dev>"]

View File

@@ -78,10 +78,8 @@ pub struct ProfileCommand {
#[options(help = "create the profile if it doesn't exist")] #[options(help = "create the profile if it doesn't exist")]
pub create: bool, pub create: bool,
#[options(help = "enable cpu turbo (AMD)")] #[options(help = "enable or disable cpu turbo")]
pub turbo: bool, pub turbo: Option<bool>,
#[options(help = "disable cpu turbo (AMD)")]
pub no_turbo: bool,
#[options(help = "set min cpu scaling (intel)")] #[options(help = "set min cpu scaling (intel)")]
pub min_percentage: Option<u8>, pub min_percentage: Option<u8>,
#[options(help = "set max cpu scaling (intel)")] #[options(help = "set max cpu scaling (intel)")]