mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Add git hooks via cargo-husky. Many many cleanups.
This commit is contained in:
@@ -303,6 +303,7 @@ impl LedUsbPackets {
|
||||
fn rgb_for_led_code(&mut self, led_code: LedCode) -> Option<&mut [u8]> {
|
||||
let zoned = self.zoned;
|
||||
// Tuples are indexes in to array
|
||||
#[allow(clippy::match_same_arms)]
|
||||
let (row, col) = match led_code {
|
||||
LedCode::VolDown => (0, 15),
|
||||
LedCode::VolUp => (0, 18),
|
||||
|
||||
@@ -8,6 +8,7 @@ impl From<LedCode> for &str {
|
||||
|
||||
impl From<&LedCode> for &str {
|
||||
fn from(k: &LedCode) -> Self {
|
||||
#[allow(clippy::match_same_arms)]
|
||||
match k {
|
||||
LedCode::VolUp => "Volume Up",
|
||||
LedCode::VolDown => "Volume Down",
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Read;
|
||||
|
||||
use log::{error, info, warn};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
@@ -76,39 +73,33 @@ impl LedSupportFile {
|
||||
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) = ron::from_str::<LedSupportFile>(&buf) {
|
||||
data.0.append(&mut tmp.0);
|
||||
}
|
||||
info!(
|
||||
"Loaded user-defined LED support data from {}",
|
||||
ASUS_LED_MODE_USER_CONF
|
||||
);
|
||||
if let Ok(file) = std::fs::read_to_string(ASUS_LED_MODE_USER_CONF) {
|
||||
if file.is_empty() {
|
||||
warn!("{} is empty", ASUS_LED_MODE_USER_CONF);
|
||||
} else {
|
||||
if let Ok(mut tmp) = ron::from_str::<LedSupportFile>(&file) {
|
||||
data.0.append(&mut tmp.0);
|
||||
}
|
||||
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 {
|
||||
let mut tmp: LedSupportFile = ron::from_str(&buf)
|
||||
.map_err(|e| error!("{e}"))
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", ASUS_LED_MODE_CONF));
|
||||
data.0.append(&mut tmp.0);
|
||||
loaded = true;
|
||||
info!(
|
||||
"Loaded default LED support data from {}",
|
||||
ASUS_LED_MODE_CONF
|
||||
);
|
||||
}
|
||||
if let Ok(file) = std::fs::read_to_string(ASUS_LED_MODE_CONF) {
|
||||
if file.is_empty() {
|
||||
warn!("{} is empty", ASUS_LED_MODE_CONF);
|
||||
} else {
|
||||
let mut tmp: LedSupportFile = ron::from_str(&file)
|
||||
.map_err(|e| error!("{e}"))
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", ASUS_LED_MODE_CONF));
|
||||
data.0.append(&mut tmp.0);
|
||||
loaded = true;
|
||||
info!(
|
||||
"Loaded default LED support data from {}",
|
||||
ASUS_LED_MODE_CONF
|
||||
);
|
||||
}
|
||||
}
|
||||
data.0.sort_by(|a, b| a.board_name.cmp(&b.board_name));
|
||||
@@ -125,7 +116,7 @@ impl LedSupportFile {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{Read, Write};
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use ron::ser::PrettyConfig;
|
||||
@@ -155,9 +146,7 @@ mod tests {
|
||||
let mut data = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
data.push("data/aura_support.ron");
|
||||
|
||||
let mut file = OpenOptions::new().read(true).open(&data).unwrap();
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let buf = std::fs::read_to_string(&data).unwrap();
|
||||
|
||||
let tmp = ron::from_str::<LedSupportFile>(&buf).unwrap();
|
||||
|
||||
|
||||
@@ -284,7 +284,8 @@ impl FromStr for AuraZone {
|
||||
}
|
||||
|
||||
/// Default factory modes structure. This easily converts to an USB HID packet
|
||||
/// with: ```rust
|
||||
/// with:
|
||||
/// ```rust
|
||||
/// // let bytes: [u8; LED_MSG_LEN] = mode.into();
|
||||
/// ```
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
@@ -350,6 +351,7 @@ pub struct AuraParameters {
|
||||
pub direction: bool,
|
||||
}
|
||||
|
||||
#[allow(clippy::fn_params_excessive_bools)]
|
||||
impl AuraParameters {
|
||||
pub const fn new(
|
||||
zone: bool,
|
||||
|
||||
@@ -28,6 +28,6 @@ impl EffectState for InputBased {
|
||||
}
|
||||
|
||||
fn set_led(&mut self, address: LedCode) {
|
||||
self.led = address
|
||||
self.led = address;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
//! editable config.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::{self, OpenOptions};
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::slice::Iter;
|
||||
|
||||
@@ -88,8 +86,8 @@ impl KeyShape {
|
||||
/// The first `Key` will determine the row height.
|
||||
///
|
||||
/// Every row is considered to start a x=0, with the first row being y=0,
|
||||
/// and following rows starting after the previous row_y+pad_top and
|
||||
/// row_x+pad_left
|
||||
/// and following rows starting after the previous `row_y + pad_top` and
|
||||
/// `row_x + pad_left`
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct KeyRow {
|
||||
pad_left: f32,
|
||||
@@ -138,7 +136,7 @@ impl KeyRow {
|
||||
};
|
||||
|
||||
if h < height {
|
||||
h = height
|
||||
h = height;
|
||||
}
|
||||
}
|
||||
h
|
||||
@@ -192,15 +190,9 @@ pub struct KeyLayout {
|
||||
|
||||
impl KeyLayout {
|
||||
pub fn from_file(path: &Path) -> Result<Self, Error> {
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(path)
|
||||
let buf: String = std::fs::read_to_string(path)
|
||||
.map_err(|e| Error::IoPath(path.to_string_lossy().to_string(), e))?;
|
||||
let mut buf = String::new();
|
||||
let read_len = file
|
||||
.read_to_string(&mut buf)
|
||||
.map_err(|e| Error::IoPath(path.to_string_lossy().to_string(), e))?;
|
||||
if read_len == 0 {
|
||||
if buf.is_empty() {
|
||||
Err(Error::IoPath(
|
||||
path.to_string_lossy().to_string(),
|
||||
std::io::ErrorKind::InvalidData.into(),
|
||||
@@ -233,7 +225,7 @@ impl KeyLayout {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rows(&self) -> Iter<KeyRow> {
|
||||
pub fn rows(&self) -> Iter<'_, KeyRow> {
|
||||
self.key_rows.iter()
|
||||
}
|
||||
|
||||
@@ -279,7 +271,7 @@ impl KeyLayout {
|
||||
for r in &self.key_rows {
|
||||
let tmp = r.width();
|
||||
if width < tmp {
|
||||
width = tmp
|
||||
width = tmp;
|
||||
}
|
||||
}
|
||||
width
|
||||
@@ -305,7 +297,7 @@ impl KeyLayout {
|
||||
data_path.push("layouts");
|
||||
let path = data_path.as_path();
|
||||
let mut files = Vec::new();
|
||||
fs::read_dir(path)
|
||||
std::fs::read_dir(path)
|
||||
.map_err(|e| {
|
||||
println!("{:?}, {e}", path);
|
||||
e
|
||||
@@ -471,7 +463,6 @@ mod tests {
|
||||
data_path.push("data");
|
||||
data_path.push("layouts");
|
||||
let path = data_path.as_path();
|
||||
let mut buf = String::new();
|
||||
for p in fs::read_dir(path)
|
||||
.map_err(|e| {
|
||||
println!("{:?}, {e}", path);
|
||||
@@ -479,9 +470,7 @@ mod tests {
|
||||
})
|
||||
.unwrap()
|
||||
{
|
||||
let path = p.unwrap().path();
|
||||
let mut file = OpenOptions::new().read(true).open(&path).unwrap();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let mut buf = std::fs::read_to_string(p.unwrap().path()).unwrap();
|
||||
|
||||
let data: KeyLayout = ron::from_str(&buf).unwrap();
|
||||
|
||||
@@ -501,9 +490,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
if !unused.is_empty() {
|
||||
panic!("The layout {path:?} had unused shapes {unused:?}",);
|
||||
}
|
||||
assert!(
|
||||
unused.is_empty(),
|
||||
"The layout {path:?} had unused shapes {unused:?}",
|
||||
);
|
||||
buf.clear();
|
||||
}
|
||||
|
||||
@@ -527,9 +517,7 @@ mod tests {
|
||||
data_path.push("data");
|
||||
data_path.push("aura_support.ron");
|
||||
|
||||
let mut buf = String::new();
|
||||
let mut file = OpenOptions::new().read(true).open(&data_path).unwrap();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let mut buf = std::fs::read_to_string(&data_path).unwrap();
|
||||
let data: LedSupportFile = ron::from_str(&buf).unwrap();
|
||||
|
||||
data_path.pop();
|
||||
@@ -553,6 +541,7 @@ mod tests {
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
#[allow(clippy::verbose_file_reads)]
|
||||
if let Err(e) = file.read_to_string(&mut buf) {
|
||||
panic!(
|
||||
"Error checking {data_path:?} for {} : {e:?}",
|
||||
|
||||
Reference in New Issue
Block a user