From 9970b30397c080e6178267289ee398680ad3f066 Mon Sep 17 00:00:00 2001 From: nedko Date: Tue, 30 Jun 2026 17:35:54 +0300 Subject: [PATCH] Fixed refresh alignment again --- TRMNL.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/TRMNL.cpp b/TRMNL.cpp index 697a77b..f53a57a 100644 --- a/TRMNL.cpp +++ b/TRMNL.cpp @@ -1,14 +1,11 @@ #include "TRMNL.h" #include "helpers.h" -#include - #include using std::list; using std::map; using std::optional; -using std::set; using std::string; using nlohmann::json; @@ -31,12 +28,14 @@ TRMNL::TRMNL(const nlohmann::json& j) m_api_key(""), m_friendly_id(""), m_refresh_rate(DEFAULT_REFRESH_RATE), +m_is_refresh_aligned(true), m_update_handler() { json_extract(j, "ID", m_id); json_extract(j, "api_key", m_api_key); json_extract(j, "friendly_id", m_friendly_id); json_extract(j, "refresh_rate", m_refresh_rate); + json_extract(j, "refresh_aligned", m_is_refresh_aligned); } const string& TRMNL::id() const @@ -81,11 +80,9 @@ int TRMNL::get_next_refresh(int min_time, int offset) const struct tm* now = localtime(&curr); int tmp_refresh = m_refresh_rate; - set allowed_minutes = {0, 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30}; - set allowed_hours = {1, 2, 3, 4, 6, 8, 12, 24}; // Check whether refresh rate is minutes aligned - if (0 == m_refresh_rate % 60) + if (0 == tmp_refresh % 60) { tmp_refresh /= 60; now->tm_sec = 0; @@ -97,7 +94,7 @@ int TRMNL::get_next_refresh(int min_time, int offset) const now->tm_min = 0; // Hours within the day - if (0 != allowed_hours.count(tmp_refresh)) + if (0 == 24 % tmp_refresh) { now->tm_hour -= now->tm_hour % tmp_refresh; } @@ -106,7 +103,7 @@ int TRMNL::get_next_refresh(int min_time, int offset) const else { // Minutes within the hour - if (0 != allowed_minutes.count(tmp_refresh)) + if (0 == 60 % tmp_refresh) { now->tm_min -= now->tm_min % tmp_refresh; } @@ -200,6 +197,7 @@ void to_json(json& j, const TRMNL& trmnl) {"api_key", trmnl.m_api_key}, {"friendly_id", trmnl.m_friendly_id}, {"refresh_rate", trmnl.m_refresh_rate}, + {"refresh_aligned", trmnl.m_is_refresh_aligned}, }; }