implemented keymap struct
This commit is contained in:
4 files changed
+48
-5
No files matched your search
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
mod hid_wrapper;
|
mod hid_wrapper;
|
||||||
|
mod rgb;
|
||||||
mod rgb_controller;
|
mod rgb_controller;
|
||||||
|
|
||||||
pub use hid_wrapper::HidWrapperError;
|
pub use hid_wrapper::HidWrapperError;
|
||||||
|
pub use rgb::Rgb;
|
||||||
pub use rgb_controller::controller::RGBController;
|
pub use rgb_controller::controller::RGBController;
|
||||||
pub use rgb_controller::effects::Effects;
|
pub use rgb_controller::effects::Effects;
|
||||||
pub use rgb_controller::keymap::KeymapKeys;
|
pub use rgb_controller::keymap::{Keymap, KeymapKeys};
|
||||||
+11
@@ -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]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::Effects;
|
use crate::Effects;
|
||||||
use crate::HidWrapperError;
|
use crate::HidWrapperError;
|
||||||
|
use crate::Keymap;
|
||||||
use crate::hid_wrapper::HidWrapper;
|
use crate::hid_wrapper::HidWrapper;
|
||||||
|
|
||||||
pub struct RGBController {
|
pub struct RGBController {
|
||||||
@@ -258,6 +259,7 @@ impl RGBController {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_static_effect(
|
pub fn set_static_effect(
|
||||||
&mut self,
|
&mut self,
|
||||||
red: u8,
|
red: u8,
|
||||||
@@ -678,7 +680,7 @@ impl RGBController {
|
|||||||
pub fn set_static_per_key_effect(
|
pub fn set_static_per_key_effect(
|
||||||
&mut self,
|
&mut self,
|
||||||
brightness: u8,
|
brightness: u8,
|
||||||
keymap: [[u8; 3]; 144],
|
keymap: Keymap,
|
||||||
) -> Result<(), HidWrapperError> {
|
) -> Result<(), HidWrapperError> {
|
||||||
self.set_effect(
|
self.set_effect(
|
||||||
Effects::StaticPerKey,
|
Effects::StaticPerKey,
|
||||||
@@ -689,7 +691,7 @@ impl RGBController {
|
|||||||
brightness,
|
brightness,
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
Some(keymap),
|
Some(keymap.map()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::rgb::Rgb;
|
||||||
|
|
||||||
pub enum KeymapKeys {
|
pub enum KeymapKeys {
|
||||||
Escape,
|
Escape,
|
||||||
F1,
|
F1,
|
||||||
@@ -109,8 +111,8 @@ pub enum KeymapKeys {
|
|||||||
NumPlus,
|
NumPlus,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<usize> for KeymapKeys {
|
impl KeymapKeys {
|
||||||
fn into(self) -> usize {
|
fn to_usize(&self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
KeymapKeys::Escape => 1,
|
KeymapKeys::Escape => 1,
|
||||||
KeymapKeys::F1 => 2,
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user