From 35e69435319939cac339a72e0dedc6fbebcfc9fb Mon Sep 17 00:00:00 2001 From: mz Date: Mon, 14 Jun 2021 19:02:01 +0200 Subject: [PATCH 1/2] Differentiate "Not Charging" and "Discharging" in state tag of battery module. Some batteries support charge thresholds and when the upper limit is set to a number less than 100 percent and it reaches that limit and it is connected to the charger the battery state will be "Not charging". It doesn't charge anymore despite it's not full. --- modules/battery.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/battery.c b/modules/battery.c index 7b8ff5e..f5cc0f8 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -20,7 +20,7 @@ #include "../config-verify.h" #include "../plugin.h" -enum state { STATE_FULL, STATE_CHARGING, STATE_DISCHARGING }; +enum state { STATE_FULL, STATE_NOTCHARGING, STATE_CHARGING, STATE_DISCHARGING }; struct private { struct particle *label; @@ -65,6 +65,7 @@ content(struct module *mod) mtx_lock(&mod->lock); assert(m->state == STATE_FULL || + m->state == STATE_NOTCHARGING || m->state == STATE_CHARGING || m->state == STATE_DISCHARGING); @@ -79,7 +80,7 @@ content(struct module *mod) ? m->energy_full - m->energy : m->energy; double hours_as_float; - if (m->state == STATE_FULL) + if (m->state == STATE_FULL || m->state == STATE_NOTCHARGING) hours_as_float = 0.0; else if (m->power > 0) hours_as_float = (double)energy / m->power; @@ -93,7 +94,7 @@ content(struct module *mod) ? m->charge_full - m->charge : m->charge; double hours_as_float; - if (m->state == STATE_FULL) + if (m->state == STATE_FULL || m->state == STATE_NOTCHARGING) hours_as_float = 0.0; else if (m->current > 0) hours_as_float = (double)charge / m->current; @@ -117,6 +118,7 @@ content(struct module *mod) tag_new_string(mod, "model", m->model), tag_new_string(mod, "state", m->state == STATE_FULL ? "full" : + m->state == STATE_NOTCHARGING ? "not charging" : m->state == STATE_CHARGING ? "charging" : m->state == STATE_DISCHARGING ? "discharging" : "unknown"), @@ -349,12 +351,12 @@ update_status(struct module *mod) state = STATE_DISCHARGING; } else if (strcmp(status, "Full") == 0) state = STATE_FULL; + else if (strcmp(status, "Not charging") == 0) + state = STATE_NOTCHARGING; else if (strcmp(status, "Charging") == 0) state = STATE_CHARGING; else if (strcmp(status, "Discharging") == 0) state = STATE_DISCHARGING; - else if (strcmp(status, "Not charging") == 0) - state = STATE_DISCHARGING; else if (strcmp(status, "Unknown") == 0) state = STATE_DISCHARGING; else { From e2f3df87a3610e4246dc32902bc949be35260471 Mon Sep 17 00:00:00 2001 From: mzeinali Date: Mon, 14 Jun 2021 22:42:22 +0430 Subject: [PATCH 2/2] add changes in response to PR #58 comments --- CHANGELOG.md | 4 ++++ doc/yambar-modules-battery.5.scd | 2 +- examples/configurations/laptop.conf | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2c7f53..fa0cc0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ * battery: don’t terminate (causing last status to “freeze”) when failing to update; retry again later (https://codeberg.org/dnkl/yambar/issues/44). +* battery: differentiate "Not Charging" and "Discharging" in state + tag of battery module. + (https://codeberg.org/dnkl/yambar/issues/57). ### Deprecated @@ -41,6 +44,7 @@ ### Contributors * [novakane](https://codeberg.org/novakane) +* [mz](https://codeberg.org/mz) ## 1.6.1 diff --git a/doc/yambar-modules-battery.5.scd b/doc/yambar-modules-battery.5.scd index 58fa6c6..42b5e00 100644 --- a/doc/yambar-modules-battery.5.scd +++ b/doc/yambar-modules-battery.5.scd @@ -24,7 +24,7 @@ uses *udev* to monitor for changes. : Battery model name | state : string -: One of *full*, *charging*, *discharging* or *unknown* +: One of *full*, *not charging*, *charging*, *discharging* or *unknown* | capacity : range : capacity left, in percent diff --git a/examples/configurations/laptop.conf b/examples/configurations/laptop.conf index b07ed8a..593d9f3 100644 --- a/examples/configurations/laptop.conf +++ b/examples/configurations/laptop.conf @@ -271,6 +271,21 @@ bar: full: - string: {text: , foreground: 00ff00ff, font: *awesome} - string: {text: "{capacity}% full"} + not charging: + - ramp: + tag: capacity + items: + - string: {text:  , foreground: ff0000ff, font: *awesome} + - string: {text:  , foreground: ffa600ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text:  , foreground: 00ff00ff, font: *awesome} + - string: {text: "{capacity}%"} - clock: time-format: "%H:%M %Z" content: