2020-10-13 17:01:29 +02:00
|
|
|
#ifndef LED_DISPLAY_CONTROLLER
|
|
|
|
#define LED_DISPLAY_CONTROLLER
|
|
|
|
|
2020-10-28 09:17:33 +01:00
|
|
|
#define LDR_PIN 36
|
|
|
|
|
2020-10-13 17:01:29 +02:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <Adafruit_GFX.h>
|
|
|
|
#include <Adafruit_NeoMatrix.h>
|
|
|
|
#include <Adafruit_NeoPixel.h>
|
2020-10-15 22:54:20 +02:00
|
|
|
#include <EepromManager.h>
|
2020-10-15 00:02:48 +02:00
|
|
|
#include "esp_task_wdt.h"
|
2020-10-17 23:06:55 +02:00
|
|
|
#include <NeoPixelBrightnessBusGfx.h>
|
|
|
|
#include <NeoPixelBrightnessBus.h>
|
|
|
|
|
|
|
|
// function for updater task on core 0
|
|
|
|
void updateDisplayGlobal(void* object);
|
2020-10-13 17:01:29 +02:00
|
|
|
|
|
|
|
class LedDisplayController
|
|
|
|
{
|
|
|
|
public:
|
2020-10-17 23:06:55 +02:00
|
|
|
template<typename T_COLOR_FEATURE, typename T_METHOD>
|
|
|
|
explicit LedDisplayController(NeoPixelBrightnessBusGfx<T_COLOR_FEATURE, T_METHOD> *matrix )
|
|
|
|
{
|
|
|
|
this->eepromUnit = nullptr;
|
|
|
|
this->loadTextSets();
|
|
|
|
|
2020-10-18 19:16:27 +02:00
|
|
|
this->RFade = (StepsFade*log10(2))/log10(255);
|
|
|
|
|
2020-10-17 23:06:55 +02:00
|
|
|
this->matrix = matrix;
|
|
|
|
this->matrix->Begin();
|
|
|
|
this->matrix->setTextWrap(false);
|
2020-10-18 00:18:50 +02:00
|
|
|
|
2020-10-17 23:06:55 +02:00
|
|
|
text_curr_nr = 0;
|
|
|
|
text_set_starttime = 0;
|
|
|
|
text_pass = 0;
|
|
|
|
textpixel = 0;
|
|
|
|
disp_show = false;
|
|
|
|
|
2020-10-28 09:17:33 +01:00
|
|
|
|
|
|
|
this->brightness_init();
|
2020-10-17 23:06:55 +02:00
|
|
|
this->disp_init();
|
|
|
|
|
|
|
|
// create updater task
|
|
|
|
xTaskCreatePinnedToCore(updateDisplayGlobal, "DisplayUpdateTask", 10000, this, 1, &displayUpdateTask, 0);
|
|
|
|
} ;
|
2020-10-13 17:01:29 +02:00
|
|
|
~LedDisplayController();
|
|
|
|
|
2020-10-17 23:06:55 +02:00
|
|
|
//typedef uint16_t (*remapfn)(uint16_t, uint16_t);
|
|
|
|
|
2020-10-13 17:01:29 +02:00
|
|
|
enum text_align_t
|
|
|
|
{
|
2020-10-14 23:54:54 +02:00
|
|
|
AlignLeft,
|
|
|
|
AlignCenter,
|
|
|
|
AlignRight
|
2020-10-13 17:01:29 +02:00
|
|
|
};
|
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
enum DisplayTextSetParameter
|
2020-10-13 17:01:29 +02:00
|
|
|
{
|
2020-10-14 23:54:54 +02:00
|
|
|
TextParameter = 0,
|
|
|
|
ActiveParameter,
|
|
|
|
RuntimeParameter,
|
|
|
|
ColorParameter,
|
|
|
|
AlignmentParameter,
|
|
|
|
ScrollParameter,
|
2020-10-18 15:44:18 +02:00
|
|
|
ScrollDirectionParameter,
|
2020-10-14 23:54:54 +02:00
|
|
|
ScrollSpeedParameter,
|
|
|
|
ScrollCountParameter,
|
|
|
|
IndexParameter,
|
2020-10-15 00:02:48 +02:00
|
|
|
DisplayTextSetParameterCount /*!< Just for helping purposes */
|
2020-10-13 17:01:29 +02:00
|
|
|
};
|
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
enum GetSetTextSetParameterExitCode
|
2020-10-13 17:01:29 +02:00
|
|
|
{
|
2020-10-14 23:54:54 +02:00
|
|
|
Success,
|
|
|
|
InvalidParameterError,
|
|
|
|
ParameterNotWritableError,
|
|
|
|
ValueOutOfRangeError,
|
|
|
|
IndexOutOfRangeError,
|
|
|
|
ValueIsNullptrError,
|
|
|
|
InternalError
|
|
|
|
};
|
2020-10-13 17:01:29 +02:00
|
|
|
|
2020-10-15 00:02:48 +02:00
|
|
|
static const uint16_t maximumTextSets = 6;
|
|
|
|
static const uint16_t maximumTextLength = 256;
|
2020-10-13 17:01:29 +02:00
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
void loop();
|
2020-10-13 17:01:29 +02:00
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
// modifiers for the internal text sets
|
2020-10-15 22:54:20 +02:00
|
|
|
bool registerEepromUnit(EepromManager* eepromManager);
|
2020-10-14 23:54:54 +02:00
|
|
|
String getTextSetParameter(int index, DisplayTextSetParameter parameter);
|
|
|
|
GetSetTextSetParameterExitCode setTextSetParameter(int index, DisplayTextSetParameter parameter, String value);
|
2020-10-13 17:01:29 +02:00
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
// brightness control
|
|
|
|
int getBrightness();
|
|
|
|
bool setBrightness(int brightness);
|
2020-10-18 16:26:24 +02:00
|
|
|
bool getAutomaticBrightnessAdjustment();
|
|
|
|
void setAutomaticBrightnessAdjustment(bool automaticBrightnessAdjustment);
|
2020-10-13 17:01:29 +02:00
|
|
|
|
|
|
|
private:
|
2020-10-18 15:56:43 +02:00
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
// matrix objects
|
2020-10-13 17:01:29 +02:00
|
|
|
TaskHandle_t displayUpdateTask;
|
2020-10-17 23:06:55 +02:00
|
|
|
NeoPixelBrightnessBusGfx<NeoGrbFeature, Neo800KbpsMethod> *matrix;
|
|
|
|
|
2020-10-28 09:17:33 +01:00
|
|
|
// brigthness meassurement collection set
|
|
|
|
static const uint8_t meas_slots = 5;
|
|
|
|
uint8_t current_meas_slot;
|
|
|
|
uint16_t brightness_levels[meas_slots];
|
|
|
|
float brightness_adjust;
|
|
|
|
long last_brightness_meas;
|
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
// matrix variables
|
2020-10-13 17:01:29 +02:00
|
|
|
uint16_t text_curr_nr;
|
|
|
|
uint32_t text_set_starttime;
|
2020-10-18 15:10:20 +02:00
|
|
|
bool text_no_activ_legal_sets;
|
2020-10-13 17:01:29 +02:00
|
|
|
|
|
|
|
int text_pos;
|
|
|
|
unsigned int text_pass;
|
|
|
|
unsigned int textpixel;
|
|
|
|
bool disp_show;
|
2020-10-18 00:18:50 +02:00
|
|
|
long last_display_show_ms;
|
|
|
|
uint8_t default_display_show_wait_ms;
|
|
|
|
uint8_t display_show_wait_ms;
|
2020-10-13 17:01:29 +02:00
|
|
|
|
2020-10-18 19:16:27 +02:00
|
|
|
static const uint8_t StepsFade = 50;
|
|
|
|
float RFade;
|
|
|
|
|
2020-10-14 23:54:54 +02:00
|
|
|
// matrix control
|
2020-10-17 23:06:55 +02:00
|
|
|
//uint16_t remap(uint16_t x, uint16_t y);
|
2020-10-13 17:01:29 +02:00
|
|
|
void disp_init();
|
2020-10-28 09:17:33 +01:00
|
|
|
void brightness_init();
|
2020-10-14 23:54:54 +02:00
|
|
|
void disp_start_set();
|
|
|
|
void disp_scroll_text();
|
|
|
|
void show_matrix(const char *text, int pos, const char *color);
|
2020-10-28 09:17:33 +01:00
|
|
|
void measureBrightnessEnv( void );
|
|
|
|
uint8_t adjustBrightnessToEnv( void );
|
2020-10-14 23:54:54 +02:00
|
|
|
uint16_t colorFromHex(String hex);
|
|
|
|
|
|
|
|
// storage structs
|
|
|
|
typedef struct text_set_t
|
|
|
|
{
|
2020-10-15 00:02:48 +02:00
|
|
|
char text[maximumTextLength];
|
2020-10-14 23:54:54 +02:00
|
|
|
bool active;
|
|
|
|
uint16_t runtime;
|
|
|
|
char color[7];
|
|
|
|
text_align_t alignment;
|
|
|
|
bool scroll;
|
2020-10-18 15:44:18 +02:00
|
|
|
int scrollDirection;
|
2020-10-15 00:02:48 +02:00
|
|
|
int scrollSpeed; /*!< Between 0 and 10 */
|
2020-10-14 23:54:54 +02:00
|
|
|
uint16_t scrollCount;
|
|
|
|
} text_set_t;
|
|
|
|
|
|
|
|
typedef struct sets_t
|
|
|
|
{
|
2020-10-15 00:02:48 +02:00
|
|
|
text_set_t sets[maximumTextSets];
|
2020-10-18 00:18:50 +02:00
|
|
|
int disp_brightness;
|
2020-10-18 16:26:24 +02:00
|
|
|
bool disp_automatic_brightness_adjustment;
|
2020-10-14 23:54:54 +02:00
|
|
|
char valid[3];
|
|
|
|
} sets_t;
|
|
|
|
|
|
|
|
// storage variables
|
2020-10-18 15:44:18 +02:00
|
|
|
const text_set_t defaultTextSet {"", false, 0, "", AlignCenter, false, 0, 0, 0};
|
2020-10-14 23:54:54 +02:00
|
|
|
sets_t text_sets;
|
|
|
|
|
|
|
|
// storage control
|
2020-10-15 22:54:20 +02:00
|
|
|
EepromUnit* eepromUnit;
|
2020-10-14 23:54:54 +02:00
|
|
|
GetSetTextSetParameterExitCode getSetTextSetParameter(int index, DisplayTextSetParameter parameter, String *value, bool set = false);
|
2020-10-15 22:54:20 +02:00
|
|
|
bool storeTextSets();
|
2020-10-14 23:54:54 +02:00
|
|
|
bool loadTextSets();
|
2020-10-13 17:01:29 +02:00
|
|
|
};
|
|
|
|
|
2020-10-17 23:06:55 +02:00
|
|
|
|
2020-10-13 17:01:29 +02:00
|
|
|
|
|
|
|
#endif // LED_DISPLAY_CONTROLLER
|