Fixed refresh alignment again
This commit is contained in:
14
TRMNL.cpp
14
TRMNL.cpp
@@ -1,14 +1,11 @@
|
|||||||
#include "TRMNL.h"
|
#include "TRMNL.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
using std::list;
|
using std::list;
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::optional;
|
using std::optional;
|
||||||
using std::set;
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
@@ -31,12 +28,14 @@ TRMNL::TRMNL(const nlohmann::json& j)
|
|||||||
m_api_key(""),
|
m_api_key(""),
|
||||||
m_friendly_id(""),
|
m_friendly_id(""),
|
||||||
m_refresh_rate(DEFAULT_REFRESH_RATE),
|
m_refresh_rate(DEFAULT_REFRESH_RATE),
|
||||||
|
m_is_refresh_aligned(true),
|
||||||
m_update_handler()
|
m_update_handler()
|
||||||
{
|
{
|
||||||
json_extract(j, "ID", m_id);
|
json_extract(j, "ID", m_id);
|
||||||
json_extract(j, "api_key", m_api_key);
|
json_extract(j, "api_key", m_api_key);
|
||||||
json_extract(j, "friendly_id", m_friendly_id);
|
json_extract(j, "friendly_id", m_friendly_id);
|
||||||
json_extract(j, "refresh_rate", m_refresh_rate);
|
json_extract(j, "refresh_rate", m_refresh_rate);
|
||||||
|
json_extract(j, "refresh_aligned", m_is_refresh_aligned);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& TRMNL::id() const
|
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);
|
struct tm* now = localtime(&curr);
|
||||||
|
|
||||||
int tmp_refresh = m_refresh_rate;
|
int tmp_refresh = m_refresh_rate;
|
||||||
set<int> allowed_minutes = {0, 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30};
|
|
||||||
set<int> allowed_hours = {1, 2, 3, 4, 6, 8, 12, 24};
|
|
||||||
|
|
||||||
// Check whether refresh rate is minutes aligned
|
// Check whether refresh rate is minutes aligned
|
||||||
if (0 == m_refresh_rate % 60)
|
if (0 == tmp_refresh % 60)
|
||||||
{
|
{
|
||||||
tmp_refresh /= 60;
|
tmp_refresh /= 60;
|
||||||
now->tm_sec = 0;
|
now->tm_sec = 0;
|
||||||
@@ -97,7 +94,7 @@ int TRMNL::get_next_refresh(int min_time, int offset) const
|
|||||||
now->tm_min = 0;
|
now->tm_min = 0;
|
||||||
|
|
||||||
// Hours within the day
|
// Hours within the day
|
||||||
if (0 != allowed_hours.count(tmp_refresh))
|
if (0 == 24 % tmp_refresh)
|
||||||
{
|
{
|
||||||
now->tm_hour -= now->tm_hour % 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
|
else
|
||||||
{
|
{
|
||||||
// Minutes within the hour
|
// Minutes within the hour
|
||||||
if (0 != allowed_minutes.count(tmp_refresh))
|
if (0 == 60 % tmp_refresh)
|
||||||
{
|
{
|
||||||
now->tm_min -= now->tm_min % 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},
|
{"api_key", trmnl.m_api_key},
|
||||||
{"friendly_id", trmnl.m_friendly_id},
|
{"friendly_id", trmnl.m_friendly_id},
|
||||||
{"refresh_rate", trmnl.m_refresh_rate},
|
{"refresh_rate", trmnl.m_refresh_rate},
|
||||||
|
{"refresh_aligned", trmnl.m_is_refresh_aligned},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user