ssnover / acpi_client Goto Github PK
View Code? Open in Web Editor NEWUserspace client to the Linux ACPI system written in Rust.
License: MIT License
Userspace client to the Linux ACPI system written in Rust.
License: MIT License
Bails out with Path is not a file.
on my system.
$ ls /sys/class/power_supply/BAT0/
alarm charge_start_threshold device@ energy_now model_name present subsystem@ uevent
capacity charge_stop_threshold energy_full hwmon2/ power/ serial_number technology voltage_min_design
capacity_level cycle_count energy_full_design manufacturer power_now status type voltage_now
$ cat /sys/class/power_supply/BAT0/uevent
POWER_SUPPLY_NAME=BAT0
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_CYCLE_COUNT=0
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000
POWER_SUPPLY_VOLTAGE_NOW=11123000
POWER_SUPPLY_POWER_NOW=11478000
POWER_SUPPLY_ENERGY_FULL_DESIGN=23200000
POWER_SUPPLY_ENERGY_FULL=14630000
POWER_SUPPLY_ENERGY_NOW=5850000
POWER_SUPPLY_CAPACITY=39
POWER_SUPPLY_CAPACITY_LEVEL=Normal
POWER_SUPPLY_MODEL_NAME=45N1773
POWER_SUPPLY_MANUFACTURER=SANYO
POWER_SUPPLY_SERIAL_NUMBER=21069
I tried doing something like this, but it didn’t work correctly (not sure whether it’s my understanding of how power_now
and current_now
work, or just the matter of getting arithmetic right 🙂):
@@ -118,8 +129,15 @@ fn parse_capacity_supply(path: &path::Path) -> Result<BatteryInfo, AcpiClientErr
/// * `path` - The path to the ACPI device.
fn parse_energy_supply(path: &path::Path) -> Result<BatteryInfo, AcpiClientError> {
let voltage = parse_file_to_i32(&path.join("voltage_now"), 1000)? as u32;
+ dbg!(voltage);
let remaining_capacity = parse_file_to_i32(&path.join("energy_now"), 1000)? as u32 / voltage;
- let present_rate = parse_file_to_i32(&path.join("current_now"), 1000)? as u32;
+ let present_rate = if let Ok(current_now) = parse_file_to_i32(&path.join("current_now"), 1000) {
+ current_now as u32
+ } else {
+ let power_now = parse_file_to_i32(&path.join("power_now"), 1)? as u32;
+ dbg!(power_now);
+ power_now / voltage
+ };
let design_capacity =
parse_file_to_i32(&path.join("energy_full_design"), 1000)? as u32 / voltage;
let last_capacity = parse_file_to_i32(&path.join("energy_full"), 1000)? as u32 / voltage;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.