@@ -29,7 +29,10 @@ use crate::ccgx::hid::{check_ccg_fw_version, find_devices, DP_CARD_PID, HDMI_CAR
2929use crate :: ccgx:: { self , SiliconId :: * } ;
3030use crate :: chromium_ec;
3131use crate :: chromium_ec:: commands:: DeckStateMode ;
32+ use crate :: chromium_ec:: commands:: FpLedBrightnessLevel ;
3233use crate :: chromium_ec:: print_err;
34+ use crate :: chromium_ec:: EcError ;
35+ use crate :: chromium_ec:: EcResult ;
3336#[ cfg( feature = "linux" ) ]
3437use crate :: csme;
3538use crate :: ec_binary;
@@ -56,6 +59,23 @@ pub enum ConsoleArg {
5659 Follow ,
5760}
5861
62+ #[ cfg_attr( not( feature = "uefi" ) , derive( clap:: ValueEnum ) ) ]
63+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
64+ pub enum FpBrightnessArg {
65+ High ,
66+ Medium ,
67+ Low ,
68+ }
69+ impl From < FpBrightnessArg > for FpLedBrightnessLevel {
70+ fn from ( w : FpBrightnessArg ) -> FpLedBrightnessLevel {
71+ match w {
72+ FpBrightnessArg :: High => FpLedBrightnessLevel :: High ,
73+ FpBrightnessArg :: Medium => FpLedBrightnessLevel :: Medium ,
74+ FpBrightnessArg :: Low => FpLedBrightnessLevel :: Low ,
75+ }
76+ }
77+ }
78+
5979#[ cfg_attr( not( feature = "uefi" ) , derive( clap:: ValueEnum ) ) ]
6080#[ derive( Clone , Copy , Debug , PartialEq ) ]
6181pub enum InputDeckModeArg {
@@ -100,6 +120,8 @@ pub struct Cli {
100120 pub intrusion : bool ,
101121 pub inputmodules : bool ,
102122 pub input_deck_mode : Option < InputDeckModeArg > ,
123+ pub charge_limit : Option < Option < u8 > > ,
124+ pub fp_brightness : Option < Option < FpBrightnessArg > > ,
103125 pub kblight : Option < Option < u8 > > ,
104126 pub console : Option < ConsoleArg > ,
105127 pub help : bool ,
@@ -437,6 +459,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
437459 } else if let Some ( mode) = & args. input_deck_mode {
438460 println ! ( "Set mode to: {:?}" , mode) ;
439461 ec. set_input_deck_mode ( ( * mode) . into ( ) ) . unwrap ( ) ;
462+ } else if let Some ( maybe_limit) = args. charge_limit {
463+ print_err ( handle_charge_limit ( & ec, maybe_limit) ) ;
464+ } else if let Some ( maybe_brightness) = & args. fp_brightness {
465+ print_err ( handle_fp_brightness ( & ec, * maybe_brightness) ) ;
440466 } else if let Some ( Some ( kblight) ) = args. kblight {
441467 assert ! ( kblight <= 100 ) ;
442468 ec. set_keyboard_backlight ( kblight) ;
@@ -624,6 +650,8 @@ Options:
624650 --capsule <CAPSULE> Parse UEFI Capsule information from binary file
625651 --intrusion Show status of intrusion switch
626652 --inputmodules Show status of the input modules (Framework 16 only)
653+ --charge-limit [<VAL>] Get or set battery charge limit (Percentage number as arg, e.g. '100')
654+ --fp-brightness [<VAL>]Get or set fingerprint LED brightness level [possible values: high, medium, low]
627655 --kblight [<KBLIGHT>] Set keyboard backlight percentage or get, if no value provided
628656 --console <CONSOLE> Get EC console, choose whether recent or to follow the output [possible values: recent, follow]
629657 -t, --test Run self-test to check if interaction with EC is possible
@@ -843,3 +871,32 @@ pub fn analyze_capsule(data: &[u8]) -> Option<capsule::EfiCapsuleHeader> {
843871
844872 Some ( header)
845873}
874+
875+ fn handle_charge_limit ( ec : & CrosEc , maybe_limit : Option < u8 > ) -> EcResult < ( ) > {
876+ let ( cur_min, _cur_max) = ec. get_charge_limit ( ) ?;
877+ if let Some ( limit) = maybe_limit {
878+ // Prevent accidentally setting a very low limit
879+ if limit < 25 {
880+ return Err ( EcError :: DeviceError (
881+ "Not recommended to set charge limit below 25%" . to_string ( ) ,
882+ ) ) ;
883+ }
884+ ec. set_charge_limit ( cur_min, limit) ?;
885+ }
886+
887+ let ( min, max) = ec. get_charge_limit ( ) ?;
888+ println ! ( "Minimum {}%, Maximum {}%" , min, max) ;
889+
890+ Ok ( ( ) )
891+ }
892+
893+ fn handle_fp_brightness ( ec : & CrosEc , maybe_brightness : Option < FpBrightnessArg > ) -> EcResult < ( ) > {
894+ if let Some ( brightness) = maybe_brightness {
895+ ec. set_fp_led_level ( brightness. into ( ) ) ?;
896+ }
897+
898+ let level = ec. get_fp_led_level ( ) ?;
899+ println ! ( "Fingerprint LED Brightness: {:?}%" , level) ;
900+
901+ Ok ( ( ) )
902+ }
0 commit comments