Init device correctly for LED control

This commit is contained in:
Luke
2020-06-30 09:58:44 +12:00
parent b751ceb29e
commit 20b82b1f24
9 changed files with 37 additions and 27 deletions

View File

@@ -5,6 +5,11 @@ 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.13.1] - 2020-29-06
### Fixed
- Properly initialise the device
- Better log formatting
## [0.13.0] - 2020-29-06 ## [0.13.0] - 2020-29-06
### Changed ### Changed
- Dbus command `LedWriteBytes` renamed to `SetKeyBacklight` - Dbus command `LedWriteBytes` renamed to `SetKeyBacklight`

4
Cargo.lock generated
View File

@@ -736,7 +736,7 @@ checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac"
[[package]] [[package]]
name = "rog-client" name = "rog-client"
version = "0.11.0" version = "0.13.1"
dependencies = [ dependencies = [
"dbus", "dbus",
"gumdrop", "gumdrop",
@@ -750,7 +750,7 @@ dependencies = [
[[package]] [[package]]
name = "rog-daemon" name = "rog-daemon"
version = "0.13.0" version = "0.13.1"
dependencies = [ dependencies = [
"dbus", "dbus",
"dbus-tokio", "dbus-tokio",

7
debian/changelog vendored
View File

@@ -1,3 +1,10 @@
rog-core (0.13.1) focal; urgency=medium
* Properly initialise the device
* Better log formatting
-- Luke Jones <luke@ljones.dev> Tue, 30 Jun 2020 09:56:52 +1200
rog-core (0.13.0) focal; urgency=medium rog-core (0.13.0) focal; urgency=medium
- Dbus command `LedWriteBytes` renamed to `SetKeyBacklight` - Dbus command `LedWriteBytes` renamed to `SetKeyBacklight`

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "rog-client" name = "rog-client"
version = "0.11.0" version = "0.13.1"
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

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

@@ -62,7 +62,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
laptop.led_endpoint(), laptop.led_endpoint(),
laptop.supported_modes().to_owned(), laptop.supported_modes().to_owned(),
); );
led_writer.reload_last_builtin(&mut config).await?; led_writer.reload_last_builtin(&config).await?;
// Set up the mutexes // Set up the mutexes
let config = Arc::new(Mutex::new(config)); let config = Arc::new(Mutex::new(config));

View File

@@ -142,10 +142,7 @@ impl LaptopBase {
.unwrap_or_else(|err| warn!("LedBrightDown: {}", err)); .unwrap_or_else(|err| warn!("LedBrightDown: {}", err));
} }
FnKeys::AuraNext => { FnKeys::AuraNext => {
if let Ok(idx) = self if let Ok(idx) = self.supported_modes.binary_search(&config.current_mode) {
.supported_modes
.binary_search(&config.current_mode.into())
{
let idx_next = if idx < self.supported_modes.len() - 1 { let idx_next = if idx < self.supported_modes.len() - 1 {
idx + 1 idx + 1
} else { } else {
@@ -162,10 +159,7 @@ impl LaptopBase {
} }
} }
FnKeys::AuraPrevious => { FnKeys::AuraPrevious => {
if let Ok(idx) = self if let Ok(idx) = self.supported_modes.binary_search(&config.current_mode) {
.supported_modes
.binary_search(&config.current_mode.into())
{
let idx_next = if idx > 0 { let idx_next = if idx > 0 {
idx - 1 idx - 1
} else { } else {

View File

@@ -67,11 +67,7 @@ where
} }
} }
pub async fn do_command( async fn initialise(&mut self) -> Result<(), AuraError> {
&mut self,
command: AuraCommand,
config: &mut Config,
) -> Result<(), AuraError> {
if !self.initialised { if !self.initialised {
self.write_bytes(&LED_INIT1).await?; self.write_bytes(&LED_INIT1).await?;
self.write_bytes(LED_INIT2.as_bytes()).await?; self.write_bytes(LED_INIT2.as_bytes()).await?;
@@ -80,7 +76,15 @@ where
self.write_bytes(&LED_INIT5).await?; self.write_bytes(&LED_INIT5).await?;
self.initialised = true; self.initialised = true;
} }
Ok(())
}
pub async fn do_command(
&mut self,
command: AuraCommand,
config: &mut Config,
) -> Result<(), AuraError> {
self.initialise().await?;
match command { match command {
AuraCommand::WriteMode(mode) => self.set_and_save(mode, config).await?, AuraCommand::WriteMode(mode) => self.set_and_save(mode, config).await?,
AuraCommand::WriteMultizone(effect) => self.write_multizone(effect).await?, AuraCommand::WriteMultizone(effect) => self.write_multizone(effect).await?,
@@ -154,7 +158,7 @@ where
return Ok(()); return Ok(());
} }
_ => { _ => {
let mode_num: u8 = u8::from(&mode).into(); let mode_num: u8 = u8::from(&mode);
if self.supported_modes.contains(&mode_num) { 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?; self.write_bytes(&bytes).await?;
@@ -176,7 +180,8 @@ where
} }
#[inline] #[inline]
pub async fn reload_last_builtin(&self, config: &Config) -> Result<(), AuraError> { pub async fn reload_last_builtin(&mut self, config: &Config) -> Result<(), AuraError> {
self.initialise().await?;
// set current mode (if any) // set current mode (if any)
if self.supported_modes.len() > 1 { if self.supported_modes.len() > 1 {
let mode = config let mode = config

View File

@@ -1,6 +1,5 @@
use daemon::daemon::start_daemon; use daemon::daemon::start_daemon;
use daemon::rogcore::FanLevel; use daemon::rogcore::FanLevel;
use env_logger::{Builder, Target};
use gumdrop::Options; use gumdrop::Options;
use log::LevelFilter; use log::LevelFilter;
use rog_client::{ use rog_client::{
@@ -9,8 +8,9 @@ use rog_client::{
core_dbus::AuraDbusWriter, core_dbus::AuraDbusWriter,
LED_MSG_LEN, LED_MSG_LEN,
}; };
use std::io::Write;
static VERSION: &str = "0.13.0"; static VERSION: &str = "0.13.1";
#[derive(Debug, Options)] #[derive(Debug, Options)]
struct CLIStart { struct CLIStart {
@@ -46,11 +46,10 @@ struct LedModeCommand {
#[tokio::main] #[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> { pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut builder = Builder::new(); let mut logger = env_logger::Builder::new();
builder logger
.target(Target::Stdout) .target(env_logger::Target::Stdout)
.format_module_path(false) .format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()))
.format_timestamp(None)
.filter(None, LevelFilter::Info) .filter(None, LevelFilter::Info)
.init(); .init();