forked from external/yambar
module/battery: read all data into local variables first
This minimizes the time we'll have to hold the lock (once we lock).
This commit is contained in:
parent
f253bbebd2
commit
d279b585db
1 changed files with 17 additions and 10 deletions
|
@ -218,27 +218,34 @@ run(struct module_run_context *ctx)
|
||||||
} else
|
} else
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
|
long capacity = readint_from_fd(capacity_fd);
|
||||||
|
long energy = readint_from_fd(energy_fd);
|
||||||
|
long power = readint_from_fd(power_fd);
|
||||||
|
|
||||||
const char *status = readline_from_fd(status_fd);
|
const char *status = readline_from_fd(status_fd);
|
||||||
|
enum state state;
|
||||||
|
|
||||||
if (strcmp(status, "Full") == 0)
|
if (strcmp(status, "Full") == 0)
|
||||||
m->state = STATE_FULL;
|
state = STATE_FULL;
|
||||||
else if (strcmp(status, "Charging") == 0)
|
else if (strcmp(status, "Charging") == 0)
|
||||||
m->state = STATE_CHARGING;
|
state = STATE_CHARGING;
|
||||||
else if (strcmp(status, "Discharging") == 0)
|
else if (strcmp(status, "Discharging") == 0)
|
||||||
m->state = STATE_DISCHARGING;
|
state = STATE_DISCHARGING;
|
||||||
else if (strcmp(status, "Unknown") == 0)
|
else if (strcmp(status, "Unknown") == 0)
|
||||||
m->state = STATE_DISCHARGING;
|
state = STATE_DISCHARGING;
|
||||||
else {
|
else {
|
||||||
LOG_ERR("unrecognized battery state: %s", status);
|
LOG_ERR("unrecognized battery state: %s", status);
|
||||||
m->state = STATE_DISCHARGING;
|
state = STATE_DISCHARGING;
|
||||||
assert(false && "unrecognized battery state");
|
assert(false && "unrecognized battery state");
|
||||||
}
|
}
|
||||||
|
|
||||||
m->capacity = readint_from_fd(capacity_fd);
|
LOG_DBG("capacity: %ld, energy: %ld, power: %ld",
|
||||||
m->energy = readint_from_fd(energy_fd);
|
capacity, energy, power);
|
||||||
m->power = readint_from_fd(power_fd);
|
|
||||||
|
|
||||||
LOG_DBG("capacity: %lu, energy: %lu, power: %lu",
|
m->state = state;
|
||||||
m->capacity, m->energy, m->power);
|
m->capacity = capacity;
|
||||||
|
m->energy = energy;
|
||||||
|
m->power = power;
|
||||||
|
|
||||||
bar->refresh(bar);
|
bar->refresh(bar);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue