Renaming, refactoring.
This commit is contained in:
9
include/ota_functions.h
Normal file
9
include/ota_functions.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef OTA_FUNCTIONS_H
|
||||||
|
#define OTA_FUNCTIONS_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
void handleOTA();
|
||||||
|
void setupOTA(String hostname);
|
||||||
|
|
||||||
|
#endif /* OTA_FUNCTIONS_H */
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#ifndef OTAFUNCTIONS_H
|
|
||||||
#define OTAFUNCTIONS_H
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
void handleOTA();
|
|
||||||
void setupOTA(String hostname);
|
|
||||||
|
|
||||||
#endif /* OTAFUNCTIONS_H */
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
#define PONG_H
|
#define PONG_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
#include "udp_logger.h"
|
#include "udp_logger.h"
|
||||||
|
|
||||||
#ifdef DEBOUNCE_TIME
|
#ifdef DEBOUNCE_TIME
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef WORDCLOCK_FUNCTIONS_H
|
#ifndef RENDER_FUNCTIONS_H
|
||||||
#define WORDCLOCK_FUNCTIONS_H
|
#define RENDER_FUNCTIONS_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
@@ -8,4 +8,4 @@ String split(String s, char parser, int index);
|
|||||||
String time_to_string(uint8_t hours, uint8_t minutes);
|
String time_to_string(uint8_t hours, uint8_t minutes);
|
||||||
void draw_minute_indicator(uint8_t minutes, uint32_t color);
|
void draw_minute_indicator(uint8_t minutes, uint32_t color);
|
||||||
|
|
||||||
#endif /* WORDCLOCK_FUNCTIONS_H */
|
#endif /* RENDER_FUNCTIONS_H */
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#define snake_h
|
#define snake_h
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
#include "udp_logger.h"
|
#include "udp_logger.h"
|
||||||
|
|
||||||
#ifdef DEBOUNCE_TIME
|
#ifdef DEBOUNCE_TIME
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#define TETRIS_H
|
#define TETRIS_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
#include "udp_logger.h"
|
#include "udp_logger.h"
|
||||||
|
|
||||||
#ifdef DEBOUNCE_TIME
|
#ifdef DEBOUNCE_TIME
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
#include "udp_logger.h"
|
#include "udp_logger.h"
|
||||||
|
|
||||||
extern UDPLogger logger;
|
extern UDPLogger logger;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include "otafunctions.h"
|
#include "ota_functions.h"
|
||||||
|
|
||||||
// setup Arduino OTA
|
// setup Arduino OTA
|
||||||
void setupOTA(String hostname)
|
void setupOTA(String hostname)
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "animation_functions.h"
|
#include "animation_functions.h"
|
||||||
#include "wordclock_constants.h"
|
#include "wordclock_constants.h"
|
||||||
#include "udp_logger.h"
|
#include "udp_logger.h"
|
||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
|
|
||||||
extern UDPLogger logger;
|
extern UDPLogger logger;
|
||||||
extern LEDMatrix led_matrix;
|
extern LEDMatrix led_matrix;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
#include "own_font.h"
|
#include "own_font.h"
|
||||||
#include "wordclock_constants.h"
|
#include "wordclock_constants.h"
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ const uint32_t colors_24bit[NUM_COLORS] = {
|
|||||||
* @param mybrightness the initial brightness of the leds
|
* @param mybrightness the initial brightness of the leds
|
||||||
* @param mylogger pointer to the UDPLogger object
|
* @param mylogger pointer to the UDPLogger object
|
||||||
*/
|
*/
|
||||||
LEDMatrix::LEDMatrix(Adafruit_NeoMatrix * matrix, uint8_t brightness, UDPLogger * logger)
|
LEDMatrix::LEDMatrix(Adafruit_NeoMatrix *matrix, uint8_t brightness, UDPLogger *logger)
|
||||||
{
|
{
|
||||||
_neomatrix = matrix;
|
_neomatrix = matrix;
|
||||||
_brightness = brightness;
|
_brightness = brightness;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "render_functions.h"
|
#include "render_functions.h"
|
||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
#include "udp_logger.h"
|
#include "udp_logger.h"
|
||||||
|
|
||||||
extern LEDMatrix led_matrix;
|
extern LEDMatrix led_matrix;
|
||||||
|
|||||||
@@ -37,11 +37,11 @@
|
|||||||
#include "pong.h"
|
#include "pong.h"
|
||||||
#include "snake.h"
|
#include "snake.h"
|
||||||
#include "tetris.h"
|
#include "tetris.h"
|
||||||
#include "ledmatrix.h"
|
#include "led_matrix.h"
|
||||||
#include "littlefs_wrapper.h"
|
#include "littlefs_wrapper.h"
|
||||||
#include "base64_wrapper.h" // copied from https://github.com/Xander-Electronics/Base64
|
#include "base64_wrapper.h" // copied from https://github.com/Xander-Electronics/Base64
|
||||||
#include "ntp_client_plus.h"
|
#include "ntp_client_plus.h"
|
||||||
#include "otafunctions.h"
|
#include "ota_functions.h"
|
||||||
#include "udp_logger.h"
|
#include "udp_logger.h"
|
||||||
#include "wordclock_constants.h"
|
#include "wordclock_constants.h"
|
||||||
#include "render_functions.h"
|
#include "render_functions.h"
|
||||||
@@ -323,23 +323,23 @@ void loop()
|
|||||||
|
|
||||||
void update_state_machine()
|
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
|
// 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 = current_time;
|
last_state_change = current_time_ms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_current_state()
|
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)
|
// 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)
|
switch (current_state)
|
||||||
{
|
{
|
||||||
@@ -428,13 +428,13 @@ void handle_current_state()
|
|||||||
*/
|
*/
|
||||||
void update_matrix()
|
void update_matrix()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time_ms = millis();
|
||||||
|
|
||||||
// periodically write colors to matrix
|
// 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);
|
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()
|
void send_heartbeat()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time_ms = 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_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
|
logger.log_string("Heartbeat, state: " + state_names[current_state] + ", FreeHeap: " + ESP.getFreeHeap() + \
|
||||||
last_heartbeat = current_time;
|
", 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)
|
// Check wifi status (only if no apmode)
|
||||||
if (WiFi.status() != WL_CONNECTED)
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
@@ -471,10 +473,10 @@ void send_heartbeat()
|
|||||||
*/
|
*/
|
||||||
void check_night_mode()
|
void check_night_mode()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time_ms = 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_ms - last_nightmode_check) > PERIOD_NIGHTMODE_CHECK)
|
||||||
{
|
{
|
||||||
int hours = ntp_client.getHours24();
|
int hours = ntp_client.getHours24();
|
||||||
int minutes = ntp_client.getMinutes();
|
int minutes = ntp_client.getMinutes();
|
||||||
@@ -487,7 +489,7 @@ void check_night_mode()
|
|||||||
{
|
{
|
||||||
set_night_mode(false);
|
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()
|
void ntp_time_update()
|
||||||
{
|
{
|
||||||
unsigned long current_time = millis();
|
unsigned long current_time_ms = millis();
|
||||||
|
|
||||||
// NTP time update
|
// 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();
|
int ntp_retval = ntp_client.updateNTP();
|
||||||
switch (ntp_retval)
|
switch (ntp_retval)
|
||||||
|
|||||||
Reference in New Issue
Block a user