diff options
author | tv <tv@krebsco.de> | 2024-01-22 10:48:39 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2024-01-22 10:48:39 +0100 |
commit | a9eb76c7aa9ec3716e2c04b50c505793a4b4e18e (patch) | |
tree | 9a64fca6e3dc0ab6e9de5d2c3d58cbed4579b3b5 /pkgs | |
parent | 0f9e7ca902b5c97a9b178d11d9163b68a75a62e5 (diff) |
q-power_supply: admit POWER_SUPPLY_CAPACITY
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/simple/q-power_supply.nix | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/pkgs/simple/q-power_supply.nix b/pkgs/simple/q-power_supply.nix index ef133bf..7611edf 100644 --- a/pkgs/simple/q-power_supply.nix +++ b/pkgs/simple/q-power_supply.nix @@ -26,16 +26,16 @@ writeDashBin "q-power_supply" '' function print_bar(r) { return \ - (r >= .1 ? bar_gradient[0] : bar_background) "■" \ - (r >= .2 ? bar_gradient[1] : bar_background) "■" \ - (r >= .3 ? bar_gradient[2] : bar_background) "■" \ - (r >= .4 ? bar_gradient[3] : bar_background) "■" \ - (r >= .5 ? bar_gradient[4] : bar_background) "■" \ - (r >= .6 ? bar_gradient[5] : bar_background) "■" \ - (r >= .7 ? bar_gradient[6] : bar_background) "■" \ - (r >= .8 ? bar_gradient[7] : bar_background) "■" \ - (r >= .9 ? bar_gradient[8] : bar_background) "■" \ - (r >= 1 ? bar_gradient[9] : bar_background) "■" \ + (r >= 5 ? bar_gradient[0] : bar_background) "■" \ + (r >= 15 ? bar_gradient[1] : bar_background) "■" \ + (r >= 25 ? bar_gradient[2] : bar_background) "■" \ + (r >= 35 ? bar_gradient[3] : bar_background) "■" \ + (r >= 45 ? bar_gradient[4] : bar_background) "■" \ + (r >= 55 ? bar_gradient[5] : bar_background) "■" \ + (r >= 65 ? bar_gradient[6] : bar_background) "■" \ + (r >= 75 ? bar_gradient[7] : bar_background) "■" \ + (r >= 85 ? bar_gradient[8] : bar_background) "■" \ + (r >= 95 ? bar_gradient[9] : bar_background) "■" \ sgr() } @@ -112,15 +112,17 @@ writeDashBin "q-power_supply" '' energy_full = charge_full * voltage_min_design } - if (charge_now == 0 || charge_full == 0) { - die("unknown charge") + capacity = ENVIRON["POWER_SUPPLY_CAPACITY"] + if (!capacity) { + if (charge_now == 0 || charge_full == 0) { + die("unknown capacity") + } + capacity = 100 * charge_now / charge_full } - charge_ratio = charge_now / charge_full - out = out name - out = out sprintf(" %s", print_bar(charge_ratio)) - out = out sprintf(" %d%", charge_ratio * 100) + out = out sprintf(" %s", print_bar(capacity)) + out = out sprintf(" %d%", capacity) out = out sprintf(" %.2f%s", charge_now, charge_unit) if (current_now != 0) { out = out sprintf("/%.1f%s", current_now, current_unit) |