implemented keymap struct

This commit is contained in:
vextrixes committed 2026-06-03 22:06:59 +02:00
1 parent be70eb95ee
commit 07477e9d58
4 files changed
+48 -5

No files matched your search

+3 -1
View File
@@ -1,7 +1,9 @@
mod hid_wrapper;
mod rgb;
mod rgb_controller;
pub use hid_wrapper::HidWrapperError;
pub use rgb::Rgb;
pub use rgb_controller::controller::RGBController;
pub use rgb_controller::effects::Effects;
pub use rgb_controller::keymap::KeymapKeys;
pub use rgb_controller::keymap::{Keymap, KeymapKeys};
+11
View File
@@ -0,0 +1,11 @@
pub struct Rgb {
pub red: u8,
pub green: u8,
pub blue: u8,
}
impl Rgb {
pub fn to_array(self) -> [u8; 3] {
[self.red, self.green, self.blue]
}
}
+4 -2
View File
@@ -1,5 +1,6 @@
use crate::Effects;
use crate::HidWrapperError;
use crate::Keymap;
use crate::hid_wrapper::HidWrapper;
pub struct RGBController {
@@ -258,6 +259,7 @@ impl RGBController {
Ok(())
}
pub fn set_static_effect(
&mut self,
red: u8,
@@ -678,7 +680,7 @@ impl RGBController {
pub fn set_static_per_key_effect(
&mut self,
brightness: u8,
keymap: [[u8; 3]; 144],
keymap: Keymap,
) -> Result<(), HidWrapperError> {
self.set_effect(
Effects::StaticPerKey,
@@ -689,7 +691,7 @@ impl RGBController {
brightness,
1,
0,
Some(keymap),
Some(keymap.map()),
)
}
}
+30 -2
View File
@@ -1,3 +1,5 @@
use crate::rgb::Rgb;
pub enum KeymapKeys {
Escape,
F1,
@@ -109,8 +111,8 @@ pub enum KeymapKeys {
NumPlus,
}
impl Into<usize> for KeymapKeys {
fn into(self) -> usize {
impl KeymapKeys {
fn to_usize(&self) -> usize {
match self {
KeymapKeys::Escape => 1,
KeymapKeys::F1 => 2,
@@ -223,3 +225,29 @@ impl Into<usize> for KeymapKeys {
}
}
}
pub struct Keymap {
map: [[u8; 3]; 144],
}
impl Default for Keymap {
fn default() -> Self {
Self { map: [[0; 3]; 144] }
}
}
impl Keymap {
pub fn set_key(&mut self, key: KeymapKeys, color: Rgb) {
self.map[key.to_usize()] = color.to_array();
}
pub fn set_all_keys(&mut self, color: Rgb) {
self.map = [color.to_array(); 144];
}
}
impl Keymap {
pub fn map(&self) -> [[u8; 3]; 144] {
self.map.clone()
}
}