Skip to content

Commit

Permalink
hid_backlight: Correct colors on bonw15
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobgkau authored and jackpot51 committed Jul 11, 2023
1 parent 3a3d2a3 commit 07596f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/hid_backlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ fn keyboard(device: &HidDevice, brightness: u8, color: u32) -> HidResult<()> {
let raw_brightness = (((brightness as u16) * 10 + 254) / 255) as u8;
log::debug!("keyboard brightness {}/10 color #{:06X}", raw_brightness, color);

// Determine color channel values
let r = (color >> 16) as u8;
let mut g = (color >> 8) as u8;
let mut b = color as u8;

// Color correction based on model
let dmi_vendor = fs::read_to_string("/sys/class/dmi/id/sys_vendor").unwrap_or(String::new());
let dmi_model =
fs::read_to_string("/sys/class/dmi/id/product_version").unwrap_or(String::new());
match (dmi_vendor.trim(), dmi_model.trim()) {
("System76", "bonw15") => {
g = (((g as u16) * 0x65) / 0xFF) as u8;
b = (((b as u16) * 0x60) / 0xFF) as u8;
}
_ => {}
}

// Set all LED colors
for led in 0..=255 {
device.send_feature_report(&[
0xCC,
0x01,
led,
(color >> 16) as u8,
(color >> 8) as u8,
color as u8,
])?;
device.send_feature_report(&[0xCC, 0x01, led, r, g, b])?;
}

// Set brightness
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#![deny(clippy::all)]
#![deny(unused_crate_dependencies)]
#![deny(unused_imports)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::single_match)]

pub mod acpi_platform;
pub mod args;
Expand Down

0 comments on commit 07596f7

Please sign in to comment.