From d3844c40b675df2dfa8fde70df5fde5d947fbb84 Mon Sep 17 00:00:00 2001 From: Christoph Schiessl Date: Sat, 5 May 2018 12:37:16 +0200 Subject: [PATCH] refactor(battery): simplify animation subthread --- lib/xpp | 2 +- src/modules/battery.cpp | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/xpp b/lib/xpp index 8c019e6d..ab6247ba 160000 --- a/lib/xpp +++ b/lib/xpp @@ -1 +1 @@ -Subproject commit 8c019e6d7fefd2468791bc1cbf90d68ff7c1ba33 +Subproject commit ab6247ba7baee2c06d35534e81ae27f622ebd5b4 diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index be9e4ea4..f2563820 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -342,24 +342,18 @@ namespace modules { * same time. */ void battery_module::subthread() { - chrono::duration 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());