Merge branch 'battery-not-charging'

This commit is contained in:
Daniel Eklöf 2021-06-15 05:19:54 +02:00
commit 8fc0d148c8
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 27 additions and 6 deletions

View file

@ -23,6 +23,9 @@
* battery: dont terminate (causing last status to “freeze”) when * battery: dont terminate (causing last status to “freeze”) when
failing to update; retry again later failing to update; retry again later
(https://codeberg.org/dnkl/yambar/issues/44). (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 ### Deprecated
@ -41,6 +44,7 @@
### Contributors ### Contributors
* [novakane](https://codeberg.org/novakane) * [novakane](https://codeberg.org/novakane)
* [mz](https://codeberg.org/mz)
## 1.6.1 ## 1.6.1

View file

@ -24,7 +24,7 @@ uses *udev* to monitor for changes.
: Battery model name : Battery model name
| state | state
: string : string
: One of *full*, *charging*, *discharging* or *unknown* : One of *full*, *not charging*, *charging*, *discharging* or *unknown*
| capacity | capacity
: range : range
: capacity left, in percent : capacity left, in percent

View file

@ -271,6 +271,21 @@ bar:
full: full:
- string: {text: , foreground: 00ff00ff, font: *awesome} - string: {text: , foreground: 00ff00ff, font: *awesome}
- string: {text: "{capacity}% full"} - 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: - clock:
time-format: "%H:%M %Z" time-format: "%H:%M %Z"
content: content:

View file

@ -20,7 +20,7 @@
#include "../config-verify.h" #include "../config-verify.h"
#include "../plugin.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 private {
struct particle *label; struct particle *label;
@ -65,6 +65,7 @@ content(struct module *mod)
mtx_lock(&mod->lock); mtx_lock(&mod->lock);
assert(m->state == STATE_FULL || assert(m->state == STATE_FULL ||
m->state == STATE_NOTCHARGING ||
m->state == STATE_CHARGING || m->state == STATE_CHARGING ||
m->state == STATE_DISCHARGING); m->state == STATE_DISCHARGING);
@ -79,7 +80,7 @@ content(struct module *mod)
? m->energy_full - m->energy : m->energy; ? m->energy_full - m->energy : m->energy;
double hours_as_float; double hours_as_float;
if (m->state == STATE_FULL) if (m->state == STATE_FULL || m->state == STATE_NOTCHARGING)
hours_as_float = 0.0; hours_as_float = 0.0;
else if (m->power > 0) else if (m->power > 0)
hours_as_float = (double)energy / m->power; hours_as_float = (double)energy / m->power;
@ -93,7 +94,7 @@ content(struct module *mod)
? m->charge_full - m->charge : m->charge; ? m->charge_full - m->charge : m->charge;
double hours_as_float; double hours_as_float;
if (m->state == STATE_FULL) if (m->state == STATE_FULL || m->state == STATE_NOTCHARGING)
hours_as_float = 0.0; hours_as_float = 0.0;
else if (m->current > 0) else if (m->current > 0)
hours_as_float = (double)charge / m->current; 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, "model", m->model),
tag_new_string(mod, "state", tag_new_string(mod, "state",
m->state == STATE_FULL ? "full" : m->state == STATE_FULL ? "full" :
m->state == STATE_NOTCHARGING ? "not charging" :
m->state == STATE_CHARGING ? "charging" : m->state == STATE_CHARGING ? "charging" :
m->state == STATE_DISCHARGING ? "discharging" : m->state == STATE_DISCHARGING ? "discharging" :
"unknown"), "unknown"),
@ -349,12 +351,12 @@ update_status(struct module *mod)
state = STATE_DISCHARGING; state = STATE_DISCHARGING;
} else if (strcmp(status, "Full") == 0) } else if (strcmp(status, "Full") == 0)
state = STATE_FULL; state = STATE_FULL;
else if (strcmp(status, "Not charging") == 0)
state = STATE_NOTCHARGING;
else if (strcmp(status, "Charging") == 0) else if (strcmp(status, "Charging") == 0)
state = STATE_CHARGING; state = STATE_CHARGING;
else if (strcmp(status, "Discharging") == 0) else if (strcmp(status, "Discharging") == 0)
state = STATE_DISCHARGING; state = STATE_DISCHARGING;
else if (strcmp(status, "Not charging") == 0)
state = STATE_DISCHARGING;
else if (strcmp(status, "Unknown") == 0) else if (strcmp(status, "Unknown") == 0)
state = STATE_DISCHARGING; state = STATE_DISCHARGING;
else { else {