Introduction of state machine for TimeManager. Minor refactoring.
This commit is contained in:
@@ -195,7 +195,7 @@ void setup()
|
||||
}
|
||||
|
||||
// get initial time
|
||||
if (tm_mgr.ntp_time_update(true) == NTP_UPDATE_OK)
|
||||
if (tm_mgr.ntp_time_update() == NTP_UPDATE_OK)
|
||||
{
|
||||
// show the current time for short time in words
|
||||
String timeMessage = time_to_string(tm_mgr.tm_hour(), tm_mgr.tm_min());
|
||||
@@ -252,7 +252,7 @@ void loop()
|
||||
{
|
||||
send_heartbeat(); // send heartbeat update
|
||||
|
||||
tm_mgr.log_time(); // TODO rm
|
||||
tm_mgr.log_time(); // TODO rm
|
||||
|
||||
last_heartbeat_us = system_get_time();
|
||||
delay(10);
|
||||
@@ -283,14 +283,7 @@ void loop()
|
||||
|
||||
if ((current_time_us - last_time_update_us) >= PERIOD_TIME_UPDATE_US)
|
||||
{
|
||||
if (tm_mgr.ntp_sync_successful() == true) // regular case
|
||||
{
|
||||
(void)tm_mgr.ntp_time_update(); // NTP time update
|
||||
}
|
||||
else // if there was never a NTP time update before (set up failed)
|
||||
{
|
||||
(void)tm_mgr.ntp_time_update(true); // NTP time update with init!
|
||||
}
|
||||
tm_mgr.ntp_time_update(); // NTP time update
|
||||
|
||||
if (tm_mgr.ntp_update_failed_prolonged() == true)
|
||||
{
|
||||
@@ -375,13 +368,40 @@ void handle_current_state()
|
||||
{
|
||||
case ST_CLOCK: // state clock
|
||||
{
|
||||
(void)show_string_on_clock(time_to_string((uint8_t)tm_mgr.tm_hour(), (uint8_t)tm_mgr.tm_min()), main_color_clock);
|
||||
draw_minute_indicator((uint8_t)tm_mgr.tm_min(), main_color_clock);
|
||||
if (tm_mgr.ntp_sync_successful() && tm_mgr.tm_state() == TM_NORMAL)
|
||||
{
|
||||
(void)show_string_on_clock(time_to_string((uint8_t)tm_mgr.tm_hour(), (uint8_t)tm_mgr.tm_min()), main_color_clock);
|
||||
draw_minute_indicator((uint8_t)tm_mgr.tm_min(), main_color_clock);
|
||||
}
|
||||
else if (tm_mgr.ntp_sync_successful() && tm_mgr.tm_state() == TM_RETRY_SYNC)
|
||||
{
|
||||
(void)show_string_on_clock(time_to_string((uint8_t)tm_mgr.tm_hour(), (uint8_t)tm_mgr.tm_min()), main_color_clock);
|
||||
draw_minute_indicator((uint8_t)tm_mgr.tm_min(), colors_24bit[6]); // in blue to indicate a network problem
|
||||
}
|
||||
else
|
||||
{
|
||||
// clear matrix
|
||||
led_matrix.flush();
|
||||
// Turn on minutes LEDs (blue)
|
||||
led_matrix.set_min_indicator(15, colors_24bit[6]);
|
||||
led_matrix.draw_on_matrix_instant();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ST_DICLOCK: // state diclock
|
||||
{
|
||||
show_digital_clock((uint8_t)tm_mgr.tm_hour(), (uint8_t)tm_mgr.tm_min(), main_color_clock);
|
||||
if (tm_mgr.ntp_sync_successful())
|
||||
{
|
||||
show_digital_clock((uint8_t)tm_mgr.tm_hour(), (uint8_t)tm_mgr.tm_min(), main_color_clock);
|
||||
}
|
||||
else
|
||||
{
|
||||
// clear matrix
|
||||
led_matrix.flush();
|
||||
// Turn on minutes LEDs (blue)
|
||||
led_matrix.set_min_indicator(15, colors_24bit[6]);
|
||||
led_matrix.draw_on_matrix_instant();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ST_SPIRAL: // state spiral
|
||||
|
||||
Reference in New Issue
Block a user