Skip to content

Allow overriding charge limit and charge full #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ impl CrosEc {
Ok((status.microphone == 1, status.camera == 1))
}

/// Let charge fully once, if currently a charge limit is set
pub fn charge_limit_override(&self) -> EcResult<()> {
let params = &[ChargeLimitControlModes::Override as u8, 0, 0];
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;

util::assert_win_len(data.len(), 0);

Ok(())
}

/// Disable all charge limits
pub fn charge_limit_disable(&self) -> EcResult<()> {
let params = &[ChargeLimitControlModes::Disable as u8, 0, 0];
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;

util::assert_win_len(data.len(), 0);

Ok(())
}

pub fn set_charge_limit(&self, min: u8, max: u8) -> EcResult<()> {
// Sending bytes manually because the Set command, as opposed to the Get command,
// does not return any data
Expand Down Expand Up @@ -316,8 +336,8 @@ impl CrosEc {
pub fn set_fp_led_level(&self, level: FpLedBrightnessLevel) -> EcResult<()> {
// Sending bytes manually because the Set command, as opposed to the Get command,
// does not return any data
let limits = &[level as u8, 0x00];
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, limits)?;
let params = &[level as u8, 0x00];
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, params)?;

util::assert_win_len(data.len(), 0);

Expand Down
12 changes: 11 additions & 1 deletion framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ struct ClapCli {
#[arg(long)]
input_deck_mode: Option<InputDeckModeArg>,

/// Get or set max charge limit
/// Temporarily remove the charge limit and charge full
#[arg(long)]
charge_full: bool,

/// Remove min/max charge limit (Overwritten by BIOS on reboot)
#[arg(long)]
charge_limit_disable: bool,

/// Get or set max charge limit (Overwritten by BIOS on reboot)
#[arg(long)]
charge_limit: Option<Option<u8>>,

Expand Down Expand Up @@ -265,6 +273,8 @@ pub fn parse(args: &[String]) -> Cli {
intrusion: args.intrusion,
inputmodules: args.inputmodules,
input_deck_mode: args.input_deck_mode,
charge_full: args.charge_full,
charge_limit_disable: args.charge_limit_disable,
charge_limit: args.charge_limit,
get_gpio: args.get_gpio,
fp_brightness: args.fp_brightness,
Expand Down
8 changes: 8 additions & 0 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ pub struct Cli {
pub intrusion: bool,
pub inputmodules: bool,
pub input_deck_mode: Option<InputDeckModeArg>,
pub charge_full: bool,
pub charge_limit_disable: bool,
pub charge_limit: Option<Option<u8>>,
pub get_gpio: Option<String>,
pub fp_brightness: Option<Option<FpBrightnessArg>>,
Expand Down Expand Up @@ -732,6 +734,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
} else if let Some(mode) = &args.input_deck_mode {
println!("Set mode to: {:?}", mode);
ec.set_input_deck_mode((*mode).into()).unwrap();
} else if args.charge_full {
print_err(ec.charge_limit_override());
} else if args.charge_limit_disable {
print_err(ec.charge_limit_disable());
} else if let Some(maybe_limit) = args.charge_limit {
print_err(handle_charge_limit(&ec, maybe_limit));
} else if let Some(gpio_name) = &args.get_gpio {
Expand Down Expand Up @@ -1007,6 +1013,8 @@ Options:
--intrusion Show status of intrusion switch
--inputmodules Show status of the input modules (Framework 16 only)
--input-deck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only)
--charge-full Temporarily remove the charge limit and charge full
--charge-limit-disable Remove min/max charge limit (Overwritten by BIOS on reboot)
--charge-limit [<VAL>] Get or set battery charge limit (Percentage number as arg, e.g. '100')
--get-gpio <GET_GPIO> Get GPIO value by name
--fp-brightness [<VAL>]Get or set fingerprint LED brightness level [possible values: high, medium, low]
Expand Down
8 changes: 8 additions & 0 deletions framework_lib/src/commandline/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub fn parse(args: &[String]) -> Cli {
intrusion: false,
inputmodules: false,
input_deck_mode: None,
charge_full: false,
charge_limit_disable: false,
charge_limit: None,
get_gpio: None,
fp_brightness: None,
Expand Down Expand Up @@ -178,6 +180,12 @@ pub fn parse(args: &[String]) -> Cli {
None
};
found_an_option = true;
} else if arg == "--charge-full" {
cli.charge_full = true;
found_an_option = true;
} else if arg == "--charge-limit-override" {
cli.charge_limit_disable = true;
found_an_option = true;
} else if arg == "--charge-limit" {
cli.charge_limit = if args.len() > i + 1 {
if let Ok(percent) = args[i + 1].parse::<u8>() {
Expand Down
Loading