Skip to content

Commit b69985a

Browse files
committed
Add --rgbkbd commandline
Works like this: ``` > cargo build && sudo ./target/debug/framework_tool --rgbkbd 0 16711680 65280 255 ``` Signed-off-by: Daniel Schaefer <[email protected]>
1 parent a718e63 commit b69985a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

framework_lib/src/commandline/clap_std.rs

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! as well as on the UEFI shell tool.
44
use clap::Parser;
55

6+
use crate::chromium_ec::commands::EC_RGBKBD_MAX_KEY_COUNT;
67
use crate::chromium_ec::CrosEcDriverType;
78
use crate::commandline::{
89
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, RebootEcArg,
@@ -149,6 +150,13 @@ struct ClapCli {
149150
#[arg(long)]
150151
kblight: Option<Option<u8>>,
151152

153+
/// Set the color of <key> to <RGB>. Multiple colors for adjacent keys can be set at once.
154+
/// <key> <RGB> [<RGB> ...]
155+
/// Example: 0 0xFF000 0x00FF00 0x0000FF
156+
#[clap(num_args = 2..EC_RGBKBD_MAX_KEY_COUNT)]
157+
#[arg(long)]
158+
rgbkbd: Vec<u64>,
159+
152160
/// Set tablet mode override
153161
#[clap(value_enum)]
154162
#[arg(long)]
@@ -274,6 +282,7 @@ pub fn parse(args: &[String]) -> Cli {
274282
fp_led_level: args.fp_led_level,
275283
fp_brightness: args.fp_brightness,
276284
kblight: args.kblight,
285+
rgbkbd: args.rgbkbd,
277286
tablet_mode: args.tablet_mode,
278287
console: args.console,
279288
reboot_ec: args.reboot_ec,

framework_lib/src/commandline/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::chromium_ec;
3535
use crate::chromium_ec::commands::DeckStateMode;
3636
use crate::chromium_ec::commands::FpLedBrightnessLevel;
3737
use crate::chromium_ec::commands::RebootEcCmd;
38+
use crate::chromium_ec::commands::RgbS;
3839
use crate::chromium_ec::commands::TabletModeOverride;
3940
use crate::chromium_ec::EcResponseStatus;
4041
use crate::chromium_ec::{print_err, EcFlashType};
@@ -166,6 +167,7 @@ pub struct Cli {
166167
pub fp_led_level: Option<Option<FpBrightnessArg>>,
167168
pub fp_brightness: Option<Option<u8>>,
168169
pub kblight: Option<Option<u8>>,
170+
pub rgbkbd: Vec<u64>,
169171
pub tablet_mode: Option<TabletModeArg>,
170172
pub console: Option<ConsoleArg>,
171173
pub reboot_ec: Option<RebootEcArg>,
@@ -753,6 +755,21 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
753755
} else if let Some(Some(kblight)) = args.kblight {
754756
assert!(kblight <= 100);
755757
ec.set_keyboard_backlight(kblight);
758+
} else if !args.rgbkbd.is_empty() {
759+
if args.rgbkbd.len() < 2 {
760+
println!(
761+
"Must provide at least 2 arguments. Provided only: {}",
762+
args.rgbkbd.len()
763+
);
764+
} else {
765+
let start_key = args.rgbkbd[0] as u8;
766+
let colors = args.rgbkbd[1..].iter().map(|color| RgbS {
767+
r: ((color & 0x00FF0000) >> 16) as u8,
768+
g: ((color & 0x0000FF00) >> 8) as u8,
769+
b: (color & 0x000000FF) as u8,
770+
});
771+
ec.rgbkbd_set_color(start_key, colors.collect()).unwrap();
772+
}
756773
} else if let Some(None) = args.kblight {
757774
print!("Keyboard backlight: ");
758775
if let Some(percentage) = print_err(ec.get_keyboard_backlight()) {

framework_lib/src/commandline/uefi.rs

+13
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn parse(args: &[String]) -> Cli {
8787
fp_led_level: None,
8888
fp_brightness: None,
8989
kblight: None,
90+
rgbkbd: vec![],
9091
tablet_mode: None,
9192
console: None,
9293
reboot_ec: None,
@@ -216,6 +217,18 @@ pub fn parse(args: &[String]) -> Cli {
216217
Some(None)
217218
};
218219
found_an_option = true;
220+
} else if arg == "--rgbkbd" {
221+
cli.rgbkbd = if args.len() > i + 2 {
222+
let mut colors = Vec::<u64>::new();
223+
for color_i in i + 1..args.len() {
224+
// TODO: Fail parsing instead of unwrap()
225+
colors.push(args[color_i].parse::<u64>().unwrap());
226+
}
227+
colors
228+
} else {
229+
println!("--rgbkbd requires at least 2 arguments, the start key and an RGB value");
230+
vec![]
231+
}
219232
} else if arg == "--tablet-mode" {
220233
cli.tablet_mode = if args.len() > i + 1 {
221234
let tablet_mode_arg = &args[i + 1];

0 commit comments

Comments
 (0)