Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
Init device correctly for LED control
Browse files Browse the repository at this point in the history
  • Loading branch information
flukejones committed Jun 29, 2020
1 parent b751ceb commit 20b82b1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion rog-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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>"]
Expand Down
2 changes: 1 addition & 1 deletion rog-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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>"]
Expand Down
2 changes: 1 addition & 1 deletion rog-core/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 2 additions & 8 deletions rog-core/src/laptops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
19 changes: 12 additions & 7 deletions rog-core/src/led_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand All @@ -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?,
Expand Down Expand Up @@ -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?;
Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions rog-core/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 20b82b1

Please sign in to comment.