refactor(battery): simplify animation subthread

This commit is contained in:
Christoph Schiessl 2018-05-05 12:37:16 +02:00 committed by Patrick Ziegler
parent 4ef2bd5575
commit d3844c40b6
2 changed files with 10 additions and 16 deletions

@ -1 +1 @@
Subproject commit 8c019e6d7fefd2468791bc1cbf90d68ff7c1ba33
Subproject commit ab6247ba7baee2c06d35534e81ae27f622ebd5b4

View File

@ -342,24 +342,18 @@ namespace modules {
* same time.
*/
void battery_module::subthread() {
chrono::duration<double> dur{0.0};
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;
}
m_log.trace("%s: Start of subthread", name());
while (running()) {
for (int i = 0; running() && i < dur.count(); ++i) {
if (m_state == battery_module::state::CHARGING ||
m_state == battery_module::state::DISCHARGING) {
broadcast();
}
sleep(dur);
int framerate = 1000; // milliseconds
if (m_state == battery_module::state::CHARGING) {
broadcast();
framerate = m_animation_charging->framerate();
} else if (m_state == battery_module::state::DISCHARGING) {
broadcast();
framerate = m_animation_discharging->framerate();
}
this_thread::sleep_for(std::chrono::milliseconds(framerate));
}
m_log.trace("%s: End of subthread", name());