Proper fix of laptop mode conversion bug

This commit is contained in:
Luke
2020-07-05 13:33:45 +12:00
parent a4c5b2754e
commit 98ffa817e6
6 changed files with 40 additions and 20 deletions

View File

@@ -5,6 +5,10 @@ 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.14.3] - 2020-05-07
### Changed
- Proper fix of laptop mode conversion bug
## [0.14.2] - 2020-04-07
### Changed
- Try to correct how laptop modes are handled

View File

@@ -234,6 +234,7 @@ impl From<&AuraModes> for u8 {
AuraModes::Comet(_) => COMET,
AuraModes::Flash(_) => FLASH,
AuraModes::MultiStatic(_) => MULTISTATIC,
AuraModes::RGB(_) => RGB,
_ => panic!("Invalid mode"),
}
}
@@ -279,6 +280,7 @@ impl From<u8> for AuraModes {
COMET => AuraModes::Comet(SingleColour::default()),
FLASH => AuraModes::Flash(SingleColour::default()),
MULTISTATIC => AuraModes::MultiStatic(MultiColour::default()),
RGB => AuraModes::RGB(vec![]),
_ => panic!("Invalid mode byte"),
}
}

View File

@@ -151,8 +151,7 @@ impl From<&AuraModes> for [u8; LED_MSG_LEN] {
AuraModes::Pulse(_) => msg[3] = 0x0a,
AuraModes::Comet(_) => msg[3] = 0x0b,
AuraModes::Flash(_) => msg[3] = 0x0c,
AuraModes::MultiStatic(_) => msg[3] = 0x0d,
_ => print!("Mode not convertable to array: {}", <&str>::from(mode)),
_ => panic!("Mode not convertable to 1D array: {}", <&str>::from(mode)),
}
match mode {
@@ -195,7 +194,7 @@ impl From<&AuraModes> for [u8; LED_MSG_LEN] {
msg[5] = settings.colour.1;
msg[6] = settings.colour.2;
}
_ => panic!("Mode not convertable to array"),
_ => panic!("Mode not convertable to 1D array: {}", <&str>::from(mode)),
}
msg
}
@@ -240,7 +239,7 @@ impl From<&AuraModes> for [[u8; LED_MSG_LEN]; 4] {
msg[3][5] = settings.colour4.1;
msg[3][6] = settings.colour4.2;
}
_ => panic!("Mode not convertable to array"),
_ => panic!("Mode not convertable to 2D array: {}", <&str>::from(mode)),
}
msg
}

View File

@@ -78,6 +78,7 @@ impl Config {
let byte: u8 = (&mode).into();
for (index, n) in self.builtin_modes.iter().enumerate() {
if byte == u8::from(n) {
// Consume it, OMNOMNOMNOM
self.builtin_modes[index] = mode;
break;
}

View File

@@ -101,7 +101,7 @@ where
///
/// `aura_effect_init` must be called any effect routine, and called only once.
#[inline]
async fn write_effect(&mut self, effect: Vec<Vec<u8>>) -> Result<(), RogError> {
async fn write_effect(&mut self, effect: &Vec<Vec<u8>>) -> Result<(), RogError> {
if self.flip_effect_write {
for row in effect.iter().rev() {
self.write_bytes(row).await?;
@@ -121,14 +121,6 @@ where
#[inline]
async fn set_and_save(&mut self, mode: AuraModes, config: &mut Config) -> Result<(), RogError> {
match mode {
AuraModes::RGB(v) => {
if v[0].is_empty() {
let bytes = KeyColourArray::get_init_msg();
self.write_bytes(&bytes).await?;
} else {
self.write_effect(v).await?;
}
}
AuraModes::LedBrightness(n) => {
let bytes: [u8; LED_MSG_LEN] = (&mode).into();
self.write_bytes(&bytes).await?;
@@ -138,10 +130,36 @@ where
}
_ => {
let mode_num: u8 = u8::from(&mode);
self.write_mode(&mode).await?;
config.current_mode = mode_num;
config.set_mode_data(mode);
config.write();
info!(
"Switched LED mode to {}",
<&str>::from(&<AuraModes>::from(config.current_mode))
);
}
}
Ok(())
}
#[inline]
async fn write_mode(&mut self, mode: &AuraModes) -> Result<(), RogError> {
match mode {
AuraModes::RGB(v) => {
if v.is_empty() || v[0].is_empty() {
let bytes = KeyColourArray::get_init_msg();
self.write_bytes(&bytes).await?;
} else {
self.write_effect(v).await?;
}
}
_ => {
let mode_num: u8 = u8::from(mode);
match mode {
AuraModes::MultiStatic(_) => {
if self.supported_modes.contains(&mode_num) {
let bytes: [[u8; LED_MSG_LEN]; 4] = (&mode).into();
let bytes: [[u8; LED_MSG_LEN]; 4] = mode.into();
for array in bytes.iter() {
self.write_bytes(array).await?;
}
@@ -149,7 +167,7 @@ where
}
_ => {
if self.supported_modes.contains(&mode_num) {
let bytes: [u8; LED_MSG_LEN] = (&mode).into();
let bytes: [u8; LED_MSG_LEN] = mode.into();
self.write_bytes(&bytes).await?;
}
}
@@ -157,10 +175,6 @@ where
self.write_bytes(&LED_SET).await?;
// Changes won't persist unless apply is set
self.write_bytes(&LED_APPLY).await?;
config.current_mode = mode_num;
config.set_mode_data(mode);
config.write();
info!("Switched LED mode to {:#?}", config.current_mode);
}
}
Ok(())

View File

@@ -9,7 +9,7 @@ use rog_client::{
};
use std::io::Write;
static VERSION: &str = "0.14.2";
static VERSION: &str = "0.14.3";
#[derive(Options)]
struct CLIStart {