diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index a04b0173..a7f657fb 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -61,9 +61,6 @@ namespace modules { interval_t m_interval; chrono::system_clock::time_point m_lastpoll; - stateflag m_notified{false}; - stateflag m_polling{false}; - int m_fullat = 100; }; } diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 84cc5d5e..0f3961aa 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -10,7 +10,7 @@ namespace modules { m_battery = m_conf.get(name(), "battery", "BAT0"); m_adapter = m_conf.get(name(), "adapter", "ADP1"); m_fullat = m_conf.get(name(), "full-at", 100); - m_interval = interval_t{m_conf.get(name(), "poll-interval", 3.0f)}; + m_interval = interval_t{m_conf.get(name(), "poll-interval", 5.0f)}; m_lastpoll = chrono::system_clock::now(); m_path_capacity = string_util::replace(PATH_BATTERY_CAPACITY, "%battery%", m_battery); @@ -76,17 +76,15 @@ namespace modules { } void battery_module::idle() { - // Manually poll for events as a fallback for systems that + // Manually poll values as a fallback for systems that // doesn't report inotify events for files on sysfs - if (m_interval.count() > 0 && !m_notified.load(std::memory_order_relaxed)) { + if (m_interval.count() > 0) { auto now = chrono::system_clock::now(); - if (now - m_lastpoll > m_interval) { - m_log.info("%s: Polling values (inotify fallback)", name()); - m_polling.store(true, std::memory_order_relaxed); + if (chrono::duration_cast(now - m_lastpoll) > m_interval) { m_lastpoll = now; - on_event(nullptr); - broadcast(); + m_log.info("%s: Polling values (inotify fallback)", name()); + file_util::get_contents(m_path_capacity); } } @@ -95,19 +93,12 @@ namespace modules { bool battery_module::on_event(inotify_event* event) { if (event != nullptr) { - m_log.trace("%s: %s", name(), event->filename); - - if (m_polling.load(std::memory_order_relaxed)) { - m_log.info("%s: Inotify event reported, assuming fake...", name()); - m_polling.store(false, std::memory_order_relaxed); - } else if (!m_notified.load(std::memory_order_relaxed)) { - m_log.info("%s: Inotify event reported, disable polling fallback...", name()); - m_notified.store(true, std::memory_order_relaxed); - } else { - m_log.info("%s: Inotify event reported", name()); - } + m_log.trace("%s: Inotify event reported for %s", name(), event->filename); } + // Reset timer to avoid unnecessary polling + m_lastpoll = chrono::system_clock::now(); + auto state = current_state(); int percentage = m_percentage;