diff --git a/asus-nb-ctrl/src/ctrl_leds.rs b/asus-nb-ctrl/src/ctrl_leds.rs index d0f6ddf0..cd288048 100644 --- a/asus-nb-ctrl/src/ctrl_leds.rs +++ b/asus-nb-ctrl/src/ctrl_leds.rs @@ -132,8 +132,8 @@ impl CtrlKbdBacklight { #[inline] pub fn new(id_product: &str, supported_modes: Vec) -> Result { Ok(CtrlKbdBacklight { - led_node: Self::scan_led_node(id_product)?, - kbd_node: Self::scan_kbd_node(id_product)?, + led_node: Self::get_node_failover(id_product, Self::scan_led_node)?, + kbd_node: Self::get_node_failover(id_product, Self::scan_kbd_node)?, // brightness node path should always be constant but this *might* change? bright_node: "/sys/class/leds/asus::kbd_backlight/brightness".to_string(), supported_modes, @@ -141,6 +141,28 @@ impl CtrlKbdBacklight { }) } + fn get_node_failover(id_product: &str, fun: fn(&str) -> Result) -> Result { + for n in 0..2 { + match fun(id_product) { + Ok(o) => return Ok(o), + Err(e) => { + if n > 0 { + warn!("Looking for node: {}", e.to_string()); + std::thread::sleep(std::time::Duration::from_secs(1)); + } else { + return Err(e); + } + } + } + } + // Shouldn't be possible to reach this... + let err = std::io::Error::new( + std::io::ErrorKind::NotFound, + "node not found", + ); + Err(err) + } + fn scan_led_node(id_product: &str) -> Result { let mut enumerator = udev::Enumerator::new()?; enumerator.match_subsystem("hidraw")?;