|
|
|
|
@@ -37,11 +37,11 @@
|
|
|
|
|
#include "pong.h"
|
|
|
|
|
#include "snake.h"
|
|
|
|
|
#include "tetris.h"
|
|
|
|
|
#include "ledmatrix.h"
|
|
|
|
|
#include "led_matrix.h"
|
|
|
|
|
#include "littlefs_wrapper.h"
|
|
|
|
|
#include "base64_wrapper.h" // copied from https://github.com/Xander-Electronics/Base64
|
|
|
|
|
#include "ntp_client_plus.h"
|
|
|
|
|
#include "otafunctions.h"
|
|
|
|
|
#include "ota_functions.h"
|
|
|
|
|
#include "udp_logger.h"
|
|
|
|
|
#include "wordclock_constants.h"
|
|
|
|
|
#include "render_functions.h"
|
|
|
|
|
@@ -323,23 +323,23 @@ void loop()
|
|
|
|
|
|
|
|
|
|
void update_state_machine()
|
|
|
|
|
{
|
|
|
|
|
unsigned long current_time = millis();
|
|
|
|
|
unsigned long current_time_ms = millis();
|
|
|
|
|
|
|
|
|
|
if (state_auto_change && (current_time - last_state_change > PERIOD_STATE_CHANGE) && !night_mode)
|
|
|
|
|
if (state_auto_change && (current_time_ms - last_state_change > PERIOD_STATE_CHANGE) && !night_mode)
|
|
|
|
|
{
|
|
|
|
|
// increment state variable and trigger state change
|
|
|
|
|
state_change((current_state + 1) % NUM_STATES);
|
|
|
|
|
// save last automatic state change
|
|
|
|
|
last_state_change = current_time;
|
|
|
|
|
last_state_change = current_time_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_current_state()
|
|
|
|
|
{
|
|
|
|
|
unsigned long current_time = millis();
|
|
|
|
|
unsigned long current_time_ms = millis();
|
|
|
|
|
|
|
|
|
|
// handle mode behaviours (trigger loopCycles of different modes depending on current mode)
|
|
|
|
|
if (!night_mode && ((current_time - last_step) > PERIODS[state_auto_change][current_state]) && ((current_time - last_led_direct) > TIMEOUT_LEDDIRECT))
|
|
|
|
|
if (!night_mode && ((current_time_ms - last_step) > PERIODS[state_auto_change][current_state]) && ((current_time_ms - last_led_direct) > TIMEOUT_LEDDIRECT))
|
|
|
|
|
{
|
|
|
|
|
switch (current_state)
|
|
|
|
|
{
|
|
|
|
|
@@ -428,13 +428,13 @@ void handle_current_state()
|
|
|
|
|
*/
|
|
|
|
|
void update_matrix()
|
|
|
|
|
{
|
|
|
|
|
unsigned long current_time = millis();
|
|
|
|
|
unsigned long current_time_ms = millis();
|
|
|
|
|
|
|
|
|
|
// periodically write colors to matrix
|
|
|
|
|
if ((current_time - last_animation_step) > PERIOD_MATRIX_UPDATE)
|
|
|
|
|
if ((current_time_ms - last_animation_step) > PERIOD_MATRIX_UPDATE)
|
|
|
|
|
{
|
|
|
|
|
led_matrix.draw_on_matrix_smooth(filter_factor);
|
|
|
|
|
last_animation_step = current_time;
|
|
|
|
|
last_animation_step = current_time_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -445,13 +445,15 @@ void update_matrix()
|
|
|
|
|
*/
|
|
|
|
|
void send_heartbeat()
|
|
|
|
|
{
|
|
|
|
|
unsigned long current_time = millis();
|
|
|
|
|
unsigned long current_time_ms = millis();
|
|
|
|
|
|
|
|
|
|
// send regularly heartbeat messages via UDP multicast
|
|
|
|
|
if ((current_time - last_heartbeat) > PERIOD_HEARTBEAT)
|
|
|
|
|
if ((current_time_ms - last_heartbeat) > PERIOD_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
|
|
|
|
|
last_heartbeat = current_time;
|
|
|
|
|
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
|
|
|
|
|
last_heartbeat = current_time_ms;
|
|
|
|
|
|
|
|
|
|
// Check wifi status (only if no apmode)
|
|
|
|
|
if (WiFi.status() != WL_CONNECTED)
|
|
|
|
|
@@ -471,10 +473,10 @@ void send_heartbeat()
|
|
|
|
|
*/
|
|
|
|
|
void check_night_mode()
|
|
|
|
|
{
|
|
|
|
|
unsigned long current_time = millis();
|
|
|
|
|
unsigned long current_time_ms = millis();
|
|
|
|
|
|
|
|
|
|
// check if nightmode need to be activated
|
|
|
|
|
if ((current_time - last_nightmode_check) > PERIOD_NIGHTMODE_CHECK)
|
|
|
|
|
if ((current_time_ms - last_nightmode_check) > PERIOD_NIGHTMODE_CHECK)
|
|
|
|
|
{
|
|
|
|
|
int hours = ntp_client.getHours24();
|
|
|
|
|
int minutes = ntp_client.getMinutes();
|
|
|
|
|
@@ -487,7 +489,7 @@ void check_night_mode()
|
|
|
|
|
{
|
|
|
|
|
set_night_mode(false);
|
|
|
|
|
}
|
|
|
|
|
last_nightmode_check = current_time;
|
|
|
|
|
last_nightmode_check = current_time_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -498,10 +500,10 @@ void check_night_mode()
|
|
|
|
|
*/
|
|
|
|
|
void ntp_time_update()
|
|
|
|
|
{
|
|
|
|
|
unsigned long current_time = millis();
|
|
|
|
|
unsigned long current_time_ms = millis();
|
|
|
|
|
|
|
|
|
|
// NTP time update
|
|
|
|
|
if ((current_time - last_ntp_update) > PERIOD_NTP_UPDATE)
|
|
|
|
|
if ((current_time_ms - last_ntp_update) > PERIOD_NTP_UPDATE)
|
|
|
|
|
{
|
|
|
|
|
int ntp_retval = ntp_client.updateNTP();
|
|
|
|
|
switch (ntp_retval)
|
|
|
|
|
|