refactor(battery): simplify animation subthread
This commit is contained in:
parent
4ef2bd5575
commit
d3844c40b6
2
lib/xpp
2
lib/xpp
@ -1 +1 @@
|
|||||||
Subproject commit 8c019e6d7fefd2468791bc1cbf90d68ff7c1ba33
|
Subproject commit ab6247ba7baee2c06d35534e81ae27f622ebd5b4
|
@ -342,24 +342,18 @@ namespace modules {
|
|||||||
* same time.
|
* same time.
|
||||||
*/
|
*/
|
||||||
void battery_module::subthread() {
|
void battery_module::subthread() {
|
||||||
chrono::duration<double> dur{0.0};
|
m_log.trace("%s: Start of subthread", name());
|
||||||
|
|
||||||
if (battery_module::state::CHARGING == m_state && m_animation_charging) {
|
|
||||||
dur += chrono::milliseconds{m_animation_charging->framerate()};
|
|
||||||
} else if (battery_module::state::DISCHARGING == m_state && m_animation_discharging) {
|
|
||||||
dur += chrono::milliseconds{m_animation_discharging->framerate()};
|
|
||||||
} else {
|
|
||||||
dur += 1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (running()) {
|
while (running()) {
|
||||||
for (int i = 0; running() && i < dur.count(); ++i) {
|
int framerate = 1000; // milliseconds
|
||||||
if (m_state == battery_module::state::CHARGING ||
|
if (m_state == battery_module::state::CHARGING) {
|
||||||
m_state == battery_module::state::DISCHARGING) {
|
|
||||||
broadcast();
|
broadcast();
|
||||||
|
framerate = m_animation_charging->framerate();
|
||||||
|
} else if (m_state == battery_module::state::DISCHARGING) {
|
||||||
|
broadcast();
|
||||||
|
framerate = m_animation_discharging->framerate();
|
||||||
}
|
}
|
||||||
sleep(dur);
|
this_thread::sleep_for(std::chrono::milliseconds(framerate));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_log.trace("%s: End of subthread", name());
|
m_log.trace("%s: End of subthread", name());
|
||||||
|
Loading…
Reference in New Issue
Block a user