Git Product home page Git Product logo

acpi_client's People

Contributors

duhdugg avatar ssnover avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

duhdugg

acpi_client's Issues

Doesn’t work with batteries providing power_now, not current_now

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.