|
|
|
|
@@ -46,9 +46,6 @@
|
|
|
|
|
#include "wordclock_constants.h"
|
|
|
|
|
#include "render_functions.h"
|
|
|
|
|
|
|
|
|
|
// DEBUG
|
|
|
|
|
uint32_t dbg_counter = 0; // TODO RM
|
|
|
|
|
|
|
|
|
|
const String state_names[] = {"Clock", "DiClock", "Spiral", "Tetris", "Snake", "PingPong", "Hearts"};
|
|
|
|
|
// PERIODS for each state (different for stateAutoChange or Manual mode)
|
|
|
|
|
const uint16_t PERIODS[2][NUM_STATES] = {{PERIOD_TIME_VISU_UPDATE, // stateAutoChange = 0
|
|
|
|
|
@@ -110,6 +107,8 @@ NightModeTimes_st night_mode_times = {
|
|
|
|
|
NIGHTMODE_END_HR,
|
|
|
|
|
NIGHTMODE_END_MIN};
|
|
|
|
|
|
|
|
|
|
uint32_t heartbeat_counter = 0; // for heartbeat on-time in seconds
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
|
// SETUP
|
|
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
|
@@ -292,65 +291,48 @@ void loop()
|
|
|
|
|
static unsigned long last_state_change = 0; // time of last state change
|
|
|
|
|
|
|
|
|
|
handleOTA(); // handle OTA
|
|
|
|
|
yield();
|
|
|
|
|
|
|
|
|
|
webserver.handleClient(); // handle webserver
|
|
|
|
|
yield();
|
|
|
|
|
|
|
|
|
|
// send regularly heartbeat messages via UDP multicast
|
|
|
|
|
if ((current_time_ms - last_heartbeat) > PERIOD_HEARTBEAT)
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("a");
|
|
|
|
|
Serial.println();
|
|
|
|
|
send_heartbeat(); // send heartbeat update
|
|
|
|
|
last_heartbeat = CURRENT_TIME_MS;
|
|
|
|
|
yield();
|
|
|
|
|
Serial.printf("A");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!night_mode && ((current_time_ms - last_animation_step) > PERIODS[state_auto_change][current_state]) && ((current_time_ms - last_led_direct) > TIMEOUT_LEDDIRECT))
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("b");
|
|
|
|
|
handle_current_state(); // handle current state
|
|
|
|
|
last_animation_step = CURRENT_TIME_MS;
|
|
|
|
|
yield();
|
|
|
|
|
Serial.printf("B");
|
|
|
|
|
delay(10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((current_time_ms - last_matrix_update) > PERIOD_MATRIX_UPDATE)
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("c");
|
|
|
|
|
update_matrix(); // update matrix
|
|
|
|
|
last_matrix_update = CURRENT_TIME_MS;
|
|
|
|
|
yield();
|
|
|
|
|
Serial.printf("C");
|
|
|
|
|
delay(10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handle_button(); // handle button press
|
|
|
|
|
|
|
|
|
|
if (!night_mode && state_auto_change && (current_time_ms - last_state_change > PERIOD_STATE_CHANGE))
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("d");
|
|
|
|
|
update_state_machine(); // handle state changes
|
|
|
|
|
last_state_change = CURRENT_TIME_MS;
|
|
|
|
|
yield();
|
|
|
|
|
Serial.printf("D");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((current_time_ms - last_ntp_update) > PERIOD_NTP_UPDATE)
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("e");
|
|
|
|
|
ntp_time_update(&last_ntp_update); // ntp time update
|
|
|
|
|
yield();
|
|
|
|
|
Serial.printf("E");
|
|
|
|
|
delay(10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((current_time_ms - last_nightmode_check) > PERIOD_NIGHTMODE_CHECK)
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("f");
|
|
|
|
|
check_night_mode(); // check night mode
|
|
|
|
|
last_nightmode_check = CURRENT_TIME_MS;
|
|
|
|
|
Serial.printf("F");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -468,8 +450,10 @@ void update_matrix()
|
|
|
|
|
void send_heartbeat()
|
|
|
|
|
{
|
|
|
|
|
logger.log_string("Heartbeat, state: " + state_names[current_state] + ", FreeHeap: " + ESP.getFreeHeap() +
|
|
|
|
|
", HeapFrag: " + ESP.getHeapFragmentation() + ", MaxFreeBlock: " + ESP.getMaxFreeBlockSize() + "\nCounter: " +
|
|
|
|
|
dbg_counter + " , Hours: " + (float)(dbg_counter) / 3600.0 + "\n"); // TODO CHANGE
|
|
|
|
|
", HeapFrag: " + ESP.getHeapFragmentation() + ", MaxFreeBlock: " + ESP.getMaxFreeBlockSize() +
|
|
|
|
|
"\nCounter: " + heartbeat_counter + ", Hours: " + (float)(heartbeat_counter) / 3600.0 + "\n");
|
|
|
|
|
heartbeat_counter++;
|
|
|
|
|
|
|
|
|
|
// Check wifi status
|
|
|
|
|
if (WiFi.status() != WL_CONNECTED)
|
|
|
|
|
{
|
|
|
|
|
@@ -477,7 +461,6 @@ void send_heartbeat()
|
|
|
|
|
led_matrix.grid_add_pixel(0, 5, colors_24bit[1]);
|
|
|
|
|
led_matrix.draw_on_matrix_instant();
|
|
|
|
|
}
|
|
|
|
|
dbg_counter++; // TODO RM
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|