rog-aura: add basic per-key support

This commit is contained in:
Luke D. Jones
2022-08-25 21:45:36 +12:00
parent f378c54815
commit 40987ecd5d
11 changed files with 292 additions and 76 deletions

View File

@@ -10,7 +10,12 @@ pub mod gx502;
use crate::{error::Error, keys::Key};
use serde::{Deserialize, Serialize};
use std::{fs::OpenOptions, io::Read, path::Path, slice::Iter};
use std::{
fs::{self, OpenOptions},
io::Read,
path::{Path, PathBuf},
slice::Iter,
};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct KeyLayout {
@@ -53,6 +58,26 @@ impl KeyLayout {
pub fn rows_ref(&self) -> &[KeyRow] {
&self.rows
}
/// Find a layout matching the provided board name in the provided dir
pub fn find_layout(board_name: &str, mut data_path: PathBuf) -> Result<Self, Error> {
let mut layout = KeyLayout::ga401_layout(); // default
data_path.push("layouts");
let path = data_path.as_path();
for p in fs::read_dir(path).map_err(|e| {
println!("{:?}, {e}", path);
e
})? {
let tmp = KeyLayout::from_file(&p?.path()).unwrap();
if tmp.matches(board_name) {
layout = tmp;
break;
}
}
Ok(layout)
}
}
#[derive(Debug, Deserialize, Serialize, Clone)]

View File

@@ -204,6 +204,9 @@ mod tests {
colour: Default::default(),
});
let s = serde_json::to_string_pretty(&seq).unwrap();
println!("{s}");
seq.next_state(&layout);
let packets = seq.create_packets();