Minor refactoring.
This commit is contained in:
@@ -323,19 +323,22 @@ void loop()
|
||||
|
||||
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
|
||||
state_change((current_state + 1) % NUM_STATES);
|
||||
// save last automatic state change
|
||||
last_state_change = millis();
|
||||
last_state_change = current_time;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_current_state()
|
||||
{
|
||||
// handle mode behaviours (trigger loopCycles of different modes depending on current mode)
|
||||
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))
|
||||
{
|
||||
switch (current_state)
|
||||
@@ -426,6 +429,7 @@ void handle_current_state()
|
||||
void update_matrix()
|
||||
{
|
||||
unsigned long current_time = millis();
|
||||
|
||||
// periodically write colors to matrix
|
||||
if ((current_time - last_animation_step) > PERIOD_MATRIX_UPDATE)
|
||||
{
|
||||
@@ -442,6 +446,7 @@ void update_matrix()
|
||||
void send_heartbeat()
|
||||
{
|
||||
unsigned long current_time = millis();
|
||||
|
||||
// send regularly heartbeat messages via UDP multicast
|
||||
if ((current_time - last_heartbeat) > PERIOD_HEARTBEAT)
|
||||
{
|
||||
@@ -467,6 +472,7 @@ void send_heartbeat()
|
||||
void check_night_mode()
|
||||
{
|
||||
unsigned long current_time = millis();
|
||||
|
||||
// check if nightmode need to be activated
|
||||
if ((current_time - last_nightmode_check) > PERIOD_NIGHTMODE_CHECK)
|
||||
{
|
||||
@@ -493,6 +499,7 @@ void check_night_mode()
|
||||
void ntp_time_update()
|
||||
{
|
||||
unsigned long current_time = millis();
|
||||
|
||||
// NTP time update
|
||||
if ((current_time - last_ntp_update) > PERIOD_NTP_UPDATE)
|
||||
{
|
||||
@@ -620,8 +627,7 @@ void state_change(uint8_t newState)
|
||||
{
|
||||
if (night_mode)
|
||||
{
|
||||
// deactivate Nightmode
|
||||
set_night_mode(false);
|
||||
set_night_mode(false); // deactivate Nightmode
|
||||
}
|
||||
// first clear matrix
|
||||
led_matrix.flush();
|
||||
@@ -686,6 +692,7 @@ void handle_button()
|
||||
{
|
||||
static bool lastButtonState = false;
|
||||
bool buttonPressed = !digitalRead(BUTTON_PIN);
|
||||
|
||||
// check rising edge
|
||||
if (buttonPressed == true && lastButtonState == false)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user