summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pkgs/simple/q-power_supply.nix34
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)