diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e1c585c..8a54e6cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,15 @@ 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). ## [Unreleased] + +## [0.9.5] - 2020-22-05 ### Changed - Flip writing order of effect colour blocks every other block write to try and even out. Previously the bottom rows were always last to be written. - Add more examples: ball, comet, pulser. - Refine the keyboard layout grid for GX502. - Use tokio to delay main loop, not thread::sleep +- Minor tweaks to error handling. Needs refactor of errors. ## [0.9.4] - 2020-05-05 ### Changed diff --git a/aura/Cargo.toml b/aura/Cargo.toml index 4fb61530..b6c9d9be 100644 --- a/aura/Cargo.toml +++ b/aura/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rog-aura" -version = "0.9.1" +version = "0.9.2" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/debian/changelog b/debian/changelog index 7c508fb0..70c6ddc5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +rog-core (0.9.5) focal; urgency=medium + + * Internal fixes to many small issues + + -- Luke Jones Fri, 22 May 2020 15:10:24 +1200 + rog-core (0.9.4) focal; urgency=medium * Fix reloading last keyboard brightness on boot diff --git a/rog-core/Cargo.toml b/rog-core/Cargo.toml index 047d087c..6f765d9f 100644 --- a/rog-core/Cargo.toml +++ b/rog-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rog-daemon" -version = "0.9.4" +version = "0.9.5" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/rog-core/src/config.rs b/rog-core/src/config.rs index 8a19aaf6..ba001d88 100644 --- a/rog-core/src/config.rs +++ b/rog-core/src/config.rs @@ -31,6 +31,7 @@ impl Config { let mut c = Config::default(); c.current_mode[0] = 0x5d; c.current_mode[1] = 0xb3; + // Should be okay to unwrap this as is since it is a Default let toml = toml::to_string(&c).unwrap(); file.write_all(toml.as_bytes()) .expect("Writing default config failed"); diff --git a/rog-core/src/core.rs b/rog-core/src/core.rs index 44e04a4b..48812fc8 100644 --- a/rog-core/src/core.rs +++ b/rog-core/src/core.rs @@ -72,8 +72,8 @@ impl RogCore { vendor: u16, product: u16, ) -> Result, rusb::Error> { - for device in rusb::devices().unwrap().iter() { - let device_desc = device.device_descriptor().unwrap(); + for device in rusb::devices()?.iter() { + let device_desc = device.device_descriptor()?; if device_desc.vendor_id() == vendor && device_desc.product_id() == product { return device.open(); } diff --git a/rog-core/src/daemon.rs b/rog-core/src/daemon.rs index a176c5c7..c7b29bcb 100644 --- a/rog-core/src/daemon.rs +++ b/rog-core/src/daemon.rs @@ -56,8 +56,7 @@ pub async fn start_daemon() -> Result<(), Box> { rogcore .fan_mode_reload(&mut config) .await - .map_err(|err| warn!("Fan mode: {}", err)) - .unwrap(); + .unwrap_or_else(|err| warn!("Fan mode: {}", err)); let mut led_writer = LedWriter::new( rogcore.get_raw_device_handle(), laptop.led_endpoint(), @@ -104,8 +103,7 @@ pub async fn start_daemon() -> Result<(), Box> { laptop .run(&mut rogcore, &config1, bytes, acs) .await - .map_err(|err| warn!("{:?}", err)) - .unwrap(); + .unwrap_or_else(|err| warn!("{:?}", err)); } } }); @@ -122,8 +120,7 @@ pub async fn start_daemon() -> Result<(), Box> { led_writer .do_command(command, &mut config) .await - .map_err(|err| warn!("{:?}", err)) - .unwrap(); + .unwrap_or_else(|err| warn!("{:?}", err)); connection .send( @@ -131,7 +128,7 @@ pub async fn start_daemon() -> Result<(), Box> { .msg(&DBUS_PATH.into(), &DBUS_IFACE.into()) .append1(true), ) - .unwrap(); + .unwrap_or_else(|_| 0); // Clear any possible queued effect let mut effect = effect.lock().await; *effect = None; @@ -144,8 +141,7 @@ pub async fn start_daemon() -> Result<(), Box> { led_writer .do_command(AuraCommand::WriteBytes(bytes), &mut config) .await - .map_err(|err| warn!("{:?}", err)) - .unwrap(); + .unwrap_or_else(|err| warn!("{:?}", err)); // Also cancel any effect client connection .send( @@ -164,8 +160,7 @@ pub async fn start_daemon() -> Result<(), Box> { led_writer .do_command(AuraCommand::WriteEffect(effect), &mut config) .await - .map_err(|err| warn!("{:?}", err)) - .unwrap(); + .unwrap_or_else(|err| warn!("{:?}", err)); time_mark = Instant::now(); } } diff --git a/rog-core/src/led_control.rs b/rog-core/src/led_control.rs index 79930628..813aacfe 100644 --- a/rog-core/src/led_control.rs +++ b/rog-core/src/led_control.rs @@ -108,30 +108,32 @@ where AuraCommand::BuiltinNext => { // TODO: different path for multi-zone (byte 2 controlled, non-zero) let mode_curr = config.current_mode[3]; - let idx = self - .supported_modes - .binary_search(&mode_curr.into()) - .unwrap(); - let idx_next = if idx < self.supported_modes.len() - 1 { - idx + 1 + if let Ok(idx) = self.supported_modes.binary_search(&mode_curr.into()) { + let idx_next = if idx < self.supported_modes.len() - 1 { + idx + 1 + } else { + 0 + }; + self.set_builtin(config, idx_next).await?; } else { - 0 - }; - self.set_builtin(config, idx_next).await?; + warn!("Tried to step to next LED mode while in non-supported mode"); + self.set_builtin(config, 0).await?; + } } AuraCommand::BuiltinPrev => { // TODO: different path for multi-zone (byte 2 controlled, non-zero) let mode_curr = config.current_mode[3]; - let idx = self - .supported_modes - .binary_search(&mode_curr.into()) - .unwrap(); - let idx_next = if idx > 0 { - idx - 1 + if let Ok(idx) = self.supported_modes.binary_search(&mode_curr.into()) { + let idx_next = if idx > 0 { + idx - 1 + } else { + self.supported_modes.len() - 1 + }; + self.set_builtin(config, idx_next).await?; } else { - self.supported_modes.len() - 1 - }; - self.set_builtin(config, idx_next).await?; + warn!("Tried to step to next LED mode while in non-supported mode"); + self.set_builtin(config, 0).await?; + } } AuraCommand::WriteBytes(bytes) => self.set_and_save(&bytes, config).await?, AuraCommand::WriteEffect(effect) => self.write_effect(effect).await?, @@ -183,7 +185,6 @@ where } } self.flip_effect_write = !self.flip_effect_write; - let now = std::time::Instant::now(); Ok(()) } @@ -206,14 +207,13 @@ where Err(AuraError::NotSupported) } - /// Used to set a builtin mode and save the settings for it #[inline] async fn reload_last_builtin(&self, config: &Config) -> Result<(), AuraError> { let mode_curr = config.current_mode[3]; let mode = config .builtin_modes .get_field_from(mode_curr) - .unwrap() + .ok_or(AuraError::NotSupported)? .to_owned(); self.write_bytes(&mode).await?; // Reload brightness too @@ -224,15 +224,12 @@ where Ok(()) } - /// Select next Aura effect - /// - /// If the current effect is the last one then the effect selected wraps around to the first. #[inline] async fn set_builtin(&self, config: &mut Config, index: usize) -> Result<(), AuraError> { let mode_next = config .builtin_modes .get_field_from(self.supported_modes[index].into()) - .unwrap() + .ok_or(AuraError::NotSupported)? .to_owned(); println!("{:X?}", &mode_next); self.set_and_save(&mode_next, config).await?; diff --git a/rog-core/src/virt_device.rs b/rog-core/src/virt_device.rs index ec8bb5e4..36a36e91 100644 --- a/rog-core/src/virt_device.rs +++ b/rog-core/src/virt_device.rs @@ -1,3 +1,4 @@ +use log::error; use uhid_virt::{Bus, CreateParams, UHIDDevice}; /// Create a virtual device to emit key-presses @@ -91,7 +92,8 @@ impl VirtKeys { ] .to_vec(), }) - .unwrap(), + .map_err(|err| error!("Could not create virtual device: {:?}", err)) + .expect("Could not create virtual device"), } }