Many small fixes

- 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.
This commit is contained in:
Luke Jones
2020-05-22 15:05:49 +12:00
committed by Luke
parent 2381a64b71
commit 0e6f6f3289
9 changed files with 45 additions and 41 deletions

View File

@@ -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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
## [0.9.5] - 2020-22-05
### Changed ### Changed
- Flip writing order of effect colour blocks every other block write to try - 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. and even out. Previously the bottom rows were always last to be written.
- Add more examples: ball, comet, pulser. - Add more examples: ball, comet, pulser.
- Refine the keyboard layout grid for GX502. - Refine the keyboard layout grid for GX502.
- Use tokio to delay main loop, not thread::sleep - Use tokio to delay main loop, not thread::sleep
- Minor tweaks to error handling. Needs refactor of errors.
## [0.9.4] - 2020-05-05 ## [0.9.4] - 2020-05-05
### Changed ### Changed

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "rog-aura" name = "rog-aura"
version = "0.9.1" version = "0.9.2"
license = "MPL-2.0" license = "MPL-2.0"
readme = "README.md" readme = "README.md"
authors = ["Luke <luke@ljones.dev>"] authors = ["Luke <luke@ljones.dev>"]

6
debian/changelog vendored
View File

@@ -1,3 +1,9 @@
rog-core (0.9.5) focal; urgency=medium
* Internal fixes to many small issues
-- Luke Jones <luke@ljones.dev> Fri, 22 May 2020 15:10:24 +1200
rog-core (0.9.4) focal; urgency=medium rog-core (0.9.4) focal; urgency=medium
* Fix reloading last keyboard brightness on boot * Fix reloading last keyboard brightness on boot

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "rog-daemon" name = "rog-daemon"
version = "0.9.4" version = "0.9.5"
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

@@ -31,6 +31,7 @@ impl Config {
let mut c = Config::default(); let mut c = Config::default();
c.current_mode[0] = 0x5d; c.current_mode[0] = 0x5d;
c.current_mode[1] = 0xb3; 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(); let toml = toml::to_string(&c).unwrap();
file.write_all(toml.as_bytes()) file.write_all(toml.as_bytes())
.expect("Writing default config failed"); .expect("Writing default config failed");

View File

@@ -72,8 +72,8 @@ impl RogCore {
vendor: u16, vendor: u16,
product: u16, product: u16,
) -> Result<DeviceHandle<rusb::GlobalContext>, rusb::Error> { ) -> Result<DeviceHandle<rusb::GlobalContext>, rusb::Error> {
for device in rusb::devices().unwrap().iter() { for device in rusb::devices()?.iter() {
let device_desc = device.device_descriptor().unwrap(); let device_desc = device.device_descriptor()?;
if device_desc.vendor_id() == vendor && device_desc.product_id() == product { if device_desc.vendor_id() == vendor && device_desc.product_id() == product {
return device.open(); return device.open();
} }

View File

@@ -56,8 +56,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
rogcore rogcore
.fan_mode_reload(&mut config) .fan_mode_reload(&mut config)
.await .await
.map_err(|err| warn!("Fan mode: {}", err)) .unwrap_or_else(|err| warn!("Fan mode: {}", err));
.unwrap();
let mut led_writer = LedWriter::new( let mut led_writer = LedWriter::new(
rogcore.get_raw_device_handle(), rogcore.get_raw_device_handle(),
laptop.led_endpoint(), laptop.led_endpoint(),
@@ -104,8 +103,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
laptop laptop
.run(&mut rogcore, &config1, bytes, acs) .run(&mut rogcore, &config1, bytes, acs)
.await .await
.map_err(|err| warn!("{:?}", err)) .unwrap_or_else(|err| warn!("{:?}", err));
.unwrap();
} }
} }
}); });
@@ -122,8 +120,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
led_writer led_writer
.do_command(command, &mut config) .do_command(command, &mut config)
.await .await
.map_err(|err| warn!("{:?}", err)) .unwrap_or_else(|err| warn!("{:?}", err));
.unwrap();
connection connection
.send( .send(
@@ -131,7 +128,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
.msg(&DBUS_PATH.into(), &DBUS_IFACE.into()) .msg(&DBUS_PATH.into(), &DBUS_IFACE.into())
.append1(true), .append1(true),
) )
.unwrap(); .unwrap_or_else(|_| 0);
// Clear any possible queued effect // Clear any possible queued effect
let mut effect = effect.lock().await; let mut effect = effect.lock().await;
*effect = None; *effect = None;
@@ -144,8 +141,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
led_writer led_writer
.do_command(AuraCommand::WriteBytes(bytes), &mut config) .do_command(AuraCommand::WriteBytes(bytes), &mut config)
.await .await
.map_err(|err| warn!("{:?}", err)) .unwrap_or_else(|err| warn!("{:?}", err));
.unwrap();
// Also cancel any effect client // Also cancel any effect client
connection connection
.send( .send(
@@ -164,8 +160,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
led_writer led_writer
.do_command(AuraCommand::WriteEffect(effect), &mut config) .do_command(AuraCommand::WriteEffect(effect), &mut config)
.await .await
.map_err(|err| warn!("{:?}", err)) .unwrap_or_else(|err| warn!("{:?}", err));
.unwrap();
time_mark = Instant::now(); time_mark = Instant::now();
} }
} }

View File

@@ -108,30 +108,32 @@ where
AuraCommand::BuiltinNext => { AuraCommand::BuiltinNext => {
// TODO: different path for multi-zone (byte 2 controlled, non-zero) // TODO: different path for multi-zone (byte 2 controlled, non-zero)
let mode_curr = config.current_mode[3]; let mode_curr = config.current_mode[3];
let idx = self if let Ok(idx) = self.supported_modes.binary_search(&mode_curr.into()) {
.supported_modes let idx_next = if idx < self.supported_modes.len() - 1 {
.binary_search(&mode_curr.into()) idx + 1
.unwrap(); } else {
let idx_next = if idx < self.supported_modes.len() - 1 { 0
idx + 1 };
self.set_builtin(config, idx_next).await?;
} else { } else {
0 warn!("Tried to step to next LED mode while in non-supported mode");
}; self.set_builtin(config, 0).await?;
self.set_builtin(config, idx_next).await?; }
} }
AuraCommand::BuiltinPrev => { AuraCommand::BuiltinPrev => {
// TODO: different path for multi-zone (byte 2 controlled, non-zero) // TODO: different path for multi-zone (byte 2 controlled, non-zero)
let mode_curr = config.current_mode[3]; let mode_curr = config.current_mode[3];
let idx = self if let Ok(idx) = self.supported_modes.binary_search(&mode_curr.into()) {
.supported_modes let idx_next = if idx > 0 {
.binary_search(&mode_curr.into()) idx - 1
.unwrap(); } else {
let idx_next = if idx > 0 { self.supported_modes.len() - 1
idx - 1 };
self.set_builtin(config, idx_next).await?;
} else { } else {
self.supported_modes.len() - 1 warn!("Tried to step to next LED mode while in non-supported mode");
}; self.set_builtin(config, 0).await?;
self.set_builtin(config, idx_next).await?; }
} }
AuraCommand::WriteBytes(bytes) => self.set_and_save(&bytes, config).await?, AuraCommand::WriteBytes(bytes) => self.set_and_save(&bytes, config).await?,
AuraCommand::WriteEffect(effect) => self.write_effect(effect).await?, AuraCommand::WriteEffect(effect) => self.write_effect(effect).await?,
@@ -183,7 +185,6 @@ where
} }
} }
self.flip_effect_write = !self.flip_effect_write; self.flip_effect_write = !self.flip_effect_write;
let now = std::time::Instant::now();
Ok(()) Ok(())
} }
@@ -206,14 +207,13 @@ where
Err(AuraError::NotSupported) Err(AuraError::NotSupported)
} }
/// Used to set a builtin mode and save the settings for it
#[inline] #[inline]
async fn reload_last_builtin(&self, config: &Config) -> Result<(), AuraError> { async fn reload_last_builtin(&self, config: &Config) -> Result<(), AuraError> {
let mode_curr = config.current_mode[3]; let mode_curr = config.current_mode[3];
let mode = config let mode = config
.builtin_modes .builtin_modes
.get_field_from(mode_curr) .get_field_from(mode_curr)
.unwrap() .ok_or(AuraError::NotSupported)?
.to_owned(); .to_owned();
self.write_bytes(&mode).await?; self.write_bytes(&mode).await?;
// Reload brightness too // Reload brightness too
@@ -224,15 +224,12 @@ where
Ok(()) Ok(())
} }
/// Select next Aura effect
///
/// If the current effect is the last one then the effect selected wraps around to the first.
#[inline] #[inline]
async fn set_builtin(&self, config: &mut Config, index: usize) -> Result<(), AuraError> { async fn set_builtin(&self, config: &mut Config, index: usize) -> Result<(), AuraError> {
let mode_next = config let mode_next = config
.builtin_modes .builtin_modes
.get_field_from(self.supported_modes[index].into()) .get_field_from(self.supported_modes[index].into())
.unwrap() .ok_or(AuraError::NotSupported)?
.to_owned(); .to_owned();
println!("{:X?}", &mode_next); println!("{:X?}", &mode_next);
self.set_and_save(&mode_next, config).await?; self.set_and_save(&mode_next, config).await?;

View File

@@ -1,3 +1,4 @@
use log::error;
use uhid_virt::{Bus, CreateParams, UHIDDevice}; use uhid_virt::{Bus, CreateParams, UHIDDevice};
/// Create a virtual device to emit key-presses /// Create a virtual device to emit key-presses
@@ -91,7 +92,8 @@ impl VirtKeys {
] ]
.to_vec(), .to_vec(),
}) })
.unwrap(), .map_err(|err| error!("Could not create virtual device: {:?}", err))
.expect("Could not create virtual device"),
} }
} }