Add support for /etc/asusd/asusd-user-ledmodes.toml

This commit is contained in:
Luke D. Jones
2022-07-16 13:40:57 +12:00
parent 6956f7dffc
commit a117c300d5
3 changed files with 51 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for GA402 Anime Matrix display (Author: I-Al-Istannen & Luke Jones)
- Support for power-config of all LED zones. See `asusctrl led-power --help` (Author: Luke Jones, With much help from: @MNS26)
- Full support for multizone LED <logo, keyboard, lightbar> (Author: Luke Jones, With much help from: @MNS26)
- Add ability to load extra data from `/etc/asusd/asusd-user-ledmodes.toml` for LED support if file exits
### Changed
- Data for anime-matrix now requires passing the laptop model as enum
- Extra unit tests for anime stuff to help verify things

View File

@@ -5,6 +5,7 @@ use std::fs::OpenOptions;
use std::io::Read;
pub const ASUS_LED_MODE_CONF: &str = "/etc/asusd/asusd-ledmodes.toml";
pub const ASUS_LED_MODE_USER_CONF: &str = "/etc/asusd/asusd-user-ledmodes.toml";
pub const ASUS_KEYBOARD_DEVICES: [&str; 4] = ["1866", "1869", "1854", "19b6"];
pub fn print_board_info() {
@@ -32,7 +33,7 @@ pub fn print_modes(supported_modes: &[u8]) {
}
}
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize)]
struct LedSupportFile {
led_data: Vec<LaptopLedData>,
}
@@ -86,19 +87,49 @@ impl LedSupportFile {
}
fn load_from_config() -> Option<Self> {
let mut loaded = false;
let mut data = LedSupportFile::default();
// Load user configs first so they are first to be checked
if let Ok(mut file) = OpenOptions::new().read(true).open(&ASUS_LED_MODE_USER_CONF) {
let mut buf = String::new();
if let Ok(l) = file.read_to_string(&mut buf) {
if l == 0 {
warn!("{} is empty", ASUS_LED_MODE_USER_CONF);
} else {
if let Ok(mut tmp) = toml::from_str::<LedSupportFile>(&buf) {
data.led_data.append(&mut tmp.led_data);
}
info!(
"Loaded user-defined LED support data from {}",
ASUS_LED_MODE_USER_CONF
);
}
}
}
// Load and append the default LED support data
if let Ok(mut file) = OpenOptions::new().read(true).open(&ASUS_LED_MODE_CONF) {
let mut buf = String::new();
if let Ok(l) = file.read_to_string(&mut buf) {
if l == 0 {
warn!("{} is empty", ASUS_LED_MODE_CONF);
} else {
return Some(toml::from_str(&buf).unwrap_or_else(|_| {
panic!("Could not deserialise {}", ASUS_LED_MODE_CONF)
}));
let mut tmp: LedSupportFile = toml::from_str(&buf)
.unwrap_or_else(|_| panic!("Could not deserialise {}", ASUS_LED_MODE_CONF));
data.led_data.append(&mut tmp.led_data);
loaded = true;
info!(
"Loaded default LED support data from {}",
ASUS_LED_MODE_CONF
);
}
}
}
warn!("Does {} exist?", ASUS_LED_MODE_CONF);
if loaded {
return Some(data);
}
warn!("Does {} exist?", ASUS_LED_MODE_USER_CONF);
None
}
}

View File

@@ -308,7 +308,8 @@ impl AnimeImage {
}
}
fn edge_outline(&mut self) {
/// A helper for determining physical position alignment
fn _edge_outline(&mut self) {
// Janky shit here just to try help align images
let mut last_x = 0.0;
let mut last_y = 0.0;
@@ -503,7 +504,7 @@ impl From<&AnimeImage> for AnimeDataBuffer {
mod tests {
use std::path::PathBuf;
use crate::{image::*, AnimePacketType, AnimeGif, AnimTime};
use crate::{image::*, AnimTime, AnimeGif, AnimePacketType};
#[test]
fn led_positions() {
@@ -727,7 +728,7 @@ mod tests {
100,
AnimeType::GA402,
);
matrix.edge_outline();
matrix._edge_outline();
let data = AnimeDataBuffer::from(&matrix);
let pkt = AnimePacketType::from(data);
@@ -742,7 +743,16 @@ mod tests {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("data/anime/custom/sonic-run.gif");
let matrix = AnimeGif::from_gif(&path, 1.0, 0.0, Vec2::default(), AnimTime::Infinite, 1.0, AnimeType::GA402).unwrap();
let matrix = AnimeGif::from_gif(
&path,
1.0,
0.0,
Vec2::default(),
AnimTime::Infinite,
1.0,
AnimeType::GA402,
)
.unwrap();
matrix.frames()[0].frame();
let _pkt = AnimePacketType::from(matrix.frames()[0].frame().clone());
}