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
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

View file

@ -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

View file

@ -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:

View file

@ -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 {