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).
## [Unreleased]
## [0.13.1] - 2020-29-06
### Fixed
- Properly initialise the device
- Better log formatting
## [0.13.0] - 2020-29-06
### Changed
- Dbus command `LedWriteBytes` renamed to `SetKeyBacklight`

4
Cargo.lock generated
View File

@@ -736,7 +736,7 @@ checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac"
[[package]]
name = "rog-client"
version = "0.11.0"
version = "0.13.1"
dependencies = [
"dbus",
"gumdrop",
@@ -750,7 +750,7 @@ dependencies = [
[[package]]
name = "rog-daemon"
version = "0.13.0"
version = "0.13.1"
dependencies = [
"dbus",
"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
- Dbus command `LedWriteBytes` renamed to `SetKeyBacklight`

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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