Minor refactoring.
This commit is contained in:
@@ -105,8 +105,8 @@ static unsigned long last_step = millis(); // t
|
|||||||
static bool night_mode = false; // stores state of nightmode
|
static bool night_mode = false; // stores state of nightmode
|
||||||
static bool state_auto_change = false; // stores state of automatic state change
|
static bool state_auto_change = false; // stores state of automatic state change
|
||||||
static float filter_factor = DEFAULT_SMOOTHING_FACTOR; // stores smoothing factor for led transition
|
static float filter_factor = DEFAULT_SMOOTHING_FACTOR; // stores smoothing factor for led transition
|
||||||
static uint32_t main_color_clock = colors_24bit[2]; // color of the clock and digital clock
|
static uint32_t main_color_clock = colors_24bit[2]; // color of the clock and digital clock
|
||||||
static uint32_t main_color_snake = colors_24bit[1]; // color of the random snake animation
|
static uint32_t main_color_snake = colors_24bit[1]; // color of the random snake animation
|
||||||
static uint8_t current_state = (uint8_t)ST_CLOCK; // stores current state
|
static uint8_t current_state = (uint8_t)ST_CLOCK; // stores current state
|
||||||
static int watchdog_counter = 30; // Watchdog counter to trigger restart if NTP update was not possible 30 times in a row (5min)
|
static int watchdog_counter = 30; // Watchdog counter to trigger restart if NTP update was not possible 30 times in a row (5min)
|
||||||
|
|
||||||
@@ -323,19 +323,22 @@ void loop()
|
|||||||
|
|
||||||
void update_state_machine()
|
void update_state_machine()
|
||||||
{
|
{
|
||||||
if (state_auto_change && (millis() - last_state_change > PERIOD_STATE_CHANGE) && !night_mode)
|
unsigned long current_time = millis();
|
||||||
|
|
||||||
|
if (state_auto_change && (current_time - last_state_change > PERIOD_STATE_CHANGE) && !night_mode)
|
||||||
{
|
{
|
||||||
// increment state variable and trigger state change
|
// increment state variable and trigger state change
|
||||||
state_change((current_state + 1) % NUM_STATES);
|
state_change((current_state + 1) % NUM_STATES);
|
||||||
// save last automatic state change
|
// save last automatic state change
|
||||||
last_state_change = millis();
|
last_state_change = current_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_current_state()
|
void handle_current_state()
|
||||||
{
|
{
|
||||||
// handle mode behaviours (trigger loopCycles of different modes depending on current mode)
|
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time = 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 - last_step) > PERIODS[state_auto_change][current_state]) && ((current_time - last_led_direct) > TIMEOUT_LEDDIRECT))
|
||||||
{
|
{
|
||||||
switch (current_state)
|
switch (current_state)
|
||||||
@@ -426,6 +429,7 @@ void handle_current_state()
|
|||||||
void update_matrix()
|
void update_matrix()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time = millis();
|
||||||
|
|
||||||
// periodically write colors to matrix
|
// periodically write colors to matrix
|
||||||
if ((current_time - last_animation_step) > PERIOD_MATRIX_UPDATE)
|
if ((current_time - last_animation_step) > PERIOD_MATRIX_UPDATE)
|
||||||
{
|
{
|
||||||
@@ -442,6 +446,7 @@ void update_matrix()
|
|||||||
void send_heartbeat()
|
void send_heartbeat()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time = millis();
|
||||||
|
|
||||||
// send regularly heartbeat messages via UDP multicast
|
// send regularly heartbeat messages via UDP multicast
|
||||||
if ((current_time - last_heartbeat) > PERIOD_HEARTBEAT)
|
if ((current_time - last_heartbeat) > PERIOD_HEARTBEAT)
|
||||||
{
|
{
|
||||||
@@ -467,6 +472,7 @@ void send_heartbeat()
|
|||||||
void check_night_mode()
|
void check_night_mode()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time = millis();
|
||||||
|
|
||||||
// check if nightmode need to be activated
|
// check if nightmode need to be activated
|
||||||
if ((current_time - last_nightmode_check) > PERIOD_NIGHTMODE_CHECK)
|
if ((current_time - last_nightmode_check) > PERIOD_NIGHTMODE_CHECK)
|
||||||
{
|
{
|
||||||
@@ -493,6 +499,7 @@ void check_night_mode()
|
|||||||
void ntp_time_update()
|
void ntp_time_update()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time = millis();
|
||||||
|
|
||||||
// NTP time update
|
// NTP time update
|
||||||
if ((current_time - last_ntp_update) > PERIOD_NTP_UPDATE)
|
if ((current_time - last_ntp_update) > PERIOD_NTP_UPDATE)
|
||||||
{
|
{
|
||||||
@@ -620,8 +627,7 @@ void state_change(uint8_t newState)
|
|||||||
{
|
{
|
||||||
if (night_mode)
|
if (night_mode)
|
||||||
{
|
{
|
||||||
// deactivate Nightmode
|
set_night_mode(false); // deactivate Nightmode
|
||||||
set_night_mode(false);
|
|
||||||
}
|
}
|
||||||
// first clear matrix
|
// first clear matrix
|
||||||
led_matrix.flush();
|
led_matrix.flush();
|
||||||
@@ -686,6 +692,7 @@ void handle_button()
|
|||||||
{
|
{
|
||||||
static bool lastButtonState = false;
|
static bool lastButtonState = false;
|
||||||
bool buttonPressed = !digitalRead(BUTTON_PIN);
|
bool buttonPressed = !digitalRead(BUTTON_PIN);
|
||||||
|
|
||||||
// check rising edge
|
// check rising edge
|
||||||
if (buttonPressed == true && lastButtonState == false)
|
if (buttonPressed == true && lastButtonState == false)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user