Skip to content
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

add huawei support for charging thresholds #439

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
10 changes: 6 additions & 4 deletions src/charge_thresholds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const UNSUPPORTED_ERROR: &str = "Not running System76 firmware with charge thres
const OUT_OF_RANGE_ERROR: &str = "Charge threshold out of range: should be 0-100";
const ORDER_ERROR: &str = "Charge end threshold must be strictly greater than start";

fn is_s76_ec() -> bool {
fn is_supported() -> bool {
// For now, only support thresholds on System76 hardware
Path::new("/sys/bus/acpi/devices/17761776:00").is_dir()
Path::new("/sys/bus/acpi/devices/17761776:00").is_dir() ||
// and Huawei
Path::new("/sys/devices/platform/huawei-wmi/charge_control_thresholds").exists()
}

fn supports_thresholds() -> bool {
Expand Down Expand Up @@ -56,7 +58,7 @@ pub fn get_charge_profiles() -> Vec<ChargeProfile> {
}

pub(crate) fn get_charge_thresholds() -> anyhow::Result<(u8, u8)> {
if !is_s76_ec() || !supports_thresholds() {
if !is_supported() || !supports_thresholds() {
return Err(anyhow::anyhow!(UNSUPPORTED_ERROR));
}

Expand All @@ -70,7 +72,7 @@ pub(crate) fn get_charge_thresholds() -> anyhow::Result<(u8, u8)> {
}

pub(crate) fn set_charge_thresholds((start, end): (u8, u8)) -> anyhow::Result<()> {
if !is_s76_ec() || !supports_thresholds() {
if !is_supported() || !supports_thresholds() {
return Err(anyhow::anyhow!(UNSUPPORTED_ERROR));
} else if start > 100 || end > 100 {
return Err(anyhow::anyhow!(OUT_OF_RANGE_ERROR));
Expand Down
Loading