Replace base64 files with library. Major refactoring.

This commit is contained in:
2024-04-03 01:10:15 +02:00
parent ef6061fc21
commit 0543b9c0c7
9 changed files with 220 additions and 342 deletions

View File

@@ -4,6 +4,8 @@
#include <Arduino.h>
#include "wordclock_constants.h"
extern bool spiral_direction; // Direction of sprial animation
enum Direction
{
RIGHT,

View File

@@ -1,26 +0,0 @@
/*
Copyright (C) 2016 Arturo Guadalupi. All right reserved.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*/
#ifndef BASE64_WRAPPER_H
#define BASE64_WRAPPER_H
class Base64Class{
public:
int encode(char *output, char *input, int inputLength);
int decode(char * output, char * input, int inputLength);
int encodedLength(int plainLength);
int decodedLength(char * input, int inputLength);
private:
inline void fromA3ToA4(unsigned char * A4, unsigned char * A3);
inline void fromA4ToA3(unsigned char * A3, unsigned char * A4);
inline unsigned char lookupTable(char c);
};
extern Base64Class Base64;
#endif /* BASE64_WRAPPER_H */

View File

@@ -43,10 +43,10 @@ private:
// current representation of matrix as 2D array
uint32_t _current_grid[MATRIX_HEIGHT][MATRIX_WIDTH] = {0};
// target representation of minutes indicator leds
// target representation of minutes indicator LEDs
uint32_t _target_minute_indicators[4] = {0, 0, 0, 0};
// current representation of minutes indicator leds
// current representation of minutes indicator LEDs
uint32_t _current_minute_indicators[4] = {0, 0, 0, 0};
void _draw_on_matrix(float factor);

View File

@@ -67,4 +67,12 @@
#define MATRIX_WIDTH (11)
#define MATRIX_HEIGHT (11)
// NTP macros
#define BUILD_YEAR (__DATE__ + 7) /* Will expand to current year at compile time as string. */
#define NTP_MININUM_RX_YEAR (atoi(BUILD_YEAR) - 1) /* Will expand to current year at compile time minus one. */
#define NTP_MININUM_YEAR (1900) // NTP minimum year is 1900
#define NTP_MAX_UPDATE_TIME_US (500000) // 500ms max update time
#define NTP_NEXT_UPDATE_DELAY_US (10000000) // 10s delay time between updates
#define NTP_WATCHDOG_COUNTER_INIT (30) // Watchdog value, count of retries before restart
#endif /* WORDCLOCK_CONSTANTS_H */

View File

@@ -12,13 +12,9 @@
#define EEPROM_SIZE (sizeof(EepromLayout_st) / sizeof(uint8_t))
#define BUILD_YEAR (__DATE__ + 7) /* Will expand to current year at compile time as string. */
#define NTP_MININUM_RX_YEAR (atoi(BUILD_YEAR) - 1) /* Will expand to current year at compile time minus one. */
#define NTP_MININUM_YEAR (1900) // NTP minimum year is 1900
#define NTP_MAX_UPDATE_TIME_US (500000) // 500ms max update time
#define NTP_NEXT_UPDATE_DELAY_US (10000000) // 10s delay time between updates
#define NTP_WATCHDOG_COUNTER_INIT (30) // Watchdog value, count of retries before restart
// ----------------------------------------------------------------------------------
// TYPEDEFS
// ----------------------------------------------------------------------------------
typedef struct
{
int start_hour;
@@ -32,7 +28,7 @@ typedef struct
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t alpha;
uint8_t alpha; // note: unused
} Color_st;
typedef struct
@@ -62,12 +58,16 @@ typedef enum
NUM_STATES
} ClockState_en;
bool get_ntp_time(uint32 usec);
// ----------------------------------------------------------------------------------
// FUNCTIONS DECLARATIONS
// ----------------------------------------------------------------------------------
bool get_ntp_time(uint32 timeout);
String leading_zero2digit(int value);
uint8_t calculate_dynamic_brightness(uint8_t min_brightness, uint8_t max_brightness, int hours, int minutes, bool summertime);
uint8_t update_brightness(void);
void check_night_mode(void);
void check_wifi_status(void);
void cold_start_setup(void);
void draw_main_color(void);
void handle_button(void);
void handle_command(void);
@@ -75,6 +75,7 @@ void handle_current_state(void);
void handle_data_request(void);
void handle_led_direct(void);
void limit_value_ranges(void);
void log_data(void);
void log_time(tm local_time);
void ntp_time_update(uint32 max_update_time);
void on_state_entry(uint8_t state);