Cleaned added max loops esc, clear esc

This commit is contained in:
2021-11-30 21:23:33 +01:00
parent e88638c146
commit 762ed25669
3 changed files with 24 additions and 17 deletions

View File

@@ -24,17 +24,17 @@ eDict_t Escapes[] = {
{"\u001b[1m","bold",eDict_t::CONTROL, BOLD}, {"\u001b[1m","bold",eDict_t::CONTROL, BOLD},
{"\u001b[4m","underline",eDict_t::CONTROL, UNDERLINE}, {"\u001b[4m","underline",eDict_t::CONTROL, UNDERLINE},
{"\u001b[7m","reversed",eDict_t::CONTROL, REVERSED}, {"\u001b[7m","reversed",eDict_t::CONTROL, REVERSED},
{"\u001b[2J","clear",eDict_t::CONTROL, CLEAR_ALL},
{"\u001b[97;%dm","loops",eDict_t::CONTOL_WITH_PARAM, LOOPS},
{"\u001b[98;%dm","speed",eDict_t::CONTOL_WITH_PARAM, SPEED}, {"\u001b[98;%dm","speed",eDict_t::CONTOL_WITH_PARAM, SPEED},
{"\u001b[99;%dm","timeout",eDict_t::CONTOL_WITH_PARAM, TIMEOUT}, {"\u001b[99;%dm","timeout",eDict_t::CONTOL_WITH_PARAM, TIMEOUT},
}; };
SimpleMap<String, eDict_t*>* escMap; SimpleMap<String, eDict_t*>* escMap;
Scroller::Scroller(int max_loops) Scroller::Scroller()
{ {
_max_loops = max_loops; _act_setting = _setting;
_act_setting = _setting;
} }
void Scroller::init() void Scroller::init()
@@ -81,6 +81,8 @@ bool Scroller::decodeEscape2Setting(String es)
if (e->tt == eDict_t::CONTROL) { if (e->tt == eDict_t::CONTROL) {
switch (e->control) { switch (e->control) {
case CLEAR_ALL:
DeleteLines();
case RESET_ALL: case RESET_ALL:
_act_setting = _setting; _act_setting = _setting;
break; break;
@@ -93,7 +95,6 @@ bool Scroller::decodeEscape2Setting(String es)
case REVERSED: case REVERSED:
_act_setting.reversed = true; _act_setting.reversed = true;
break; break;
} }
} }
if (e->tt == eDict_t::CONTOL_WITH_PARAM) if (e->tt == eDict_t::CONTOL_WITH_PARAM)
@@ -107,6 +108,9 @@ bool Scroller::decodeEscape2Setting(String es)
case TIMEOUT: case TIMEOUT:
_act_setting.timeout = param; _act_setting.timeout = param;
break; break;
case LOOPS:
_act_setting.loops = param;
break;
} }
} }
if (e->tt == eDict_t::COLOR) _act_setting.color = e->color; if (e->tt == eDict_t::COLOR) _act_setting.color = e->color;
@@ -157,6 +161,7 @@ bool Scroller::ReplaceLine(int number,String line)
void Scroller::DeleteLines() void Scroller::DeleteLines()
{ {
_nlines = 0; _nlines = 0;
_lp = 0;
} }
void Scroller::Show(int _x,int _y,String line) void Scroller::Show(int _x,int _y,String line)
@@ -166,7 +171,9 @@ void Scroller::Show(int _x,int _y,String line)
for (int l=0;l < line.length();l++) { for (int l=0;l < line.length();l++) {
if (line.charAt(l) == '\u001b') { if (line.charAt(l) == '\u001b') {
int ee = line.indexOf('m',l); int ee;
for (ee = l+2; (line.charAt(ee) >= '0' && line.charAt(ee) <= '9') || line.charAt(ee) == ';'; ee++ )
;
decodeEscape2Setting(line.substring(l,ee+1)); decodeEscape2Setting(line.substring(l,ee+1));
l = ee; l = ee;
continue; continue;
@@ -192,7 +199,9 @@ String Scroller::LineUnescaped(String line)
String rawLine = ""; String rawLine = "";
for (int l=0;l < line.length();l++) { for (int l=0;l < line.length();l++) {
if (line.charAt(l) == '\u001b') { if (line.charAt(l) == '\u001b') {
int ee = line.indexOf('m',l); int ee;
for (ee = l+2; (line.charAt(ee) >= '0' && line.charAt(ee) <= '9') || line.charAt(ee) == ';'; ee++ )
;
l = ee; l = ee;
continue; continue;
} }
@@ -276,7 +285,7 @@ void Scroller::loop(ulong tick)
_delayTicks = 50; _delayTicks = 50;
} }
if (TimesScrolled() == _max_loops) { if (TimesScrolled() == _act_setting.loops) {
Serial.println("MAX LOOP"); Serial.println("MAX LOOP");
TurnOff(); TurnOff();
return; return;

View File

@@ -20,10 +20,11 @@ typedef struct {
} ; } ;
} eDict_t; } eDict_t;
enum {RESET_ALL,BOLD, UNDERLINE=4,REVERSED=7, SPEED, TIMEOUT}; enum {RESET_ALL,CLEAR_ALL, BOLD, UNDERLINE=4,REVERSED=7, SPEED, TIMEOUT, LOOPS};
struct Setting struct Setting
{ {
uint8_t loops;
uint32_t color; uint32_t color;
uint32_t bcolor; uint32_t bcolor;
uint8_t brightness; uint8_t brightness;
@@ -40,7 +41,7 @@ private:
/* data */ /* data */
const static int MAX_LINES = 100; const static int MAX_LINES = 100;
String _Lines[MAX_LINES]; String _Lines[MAX_LINES];
Setting _setting = { CRGB::Red, CRGB::Black, 10, 3000, 100, false, false, false}; // default setting Setting _setting = {1, CRGB::Red, CRGB::Black, 10, 3000, 100, false, false, false}; // default setting
Setting _act_setting; // actual setting Setting _act_setting; // actual setting
int _nlines = 0; int _nlines = 0;
int _lp = 0; int _lp = 0;
@@ -49,12 +50,11 @@ private:
int _nscrolled = 0; int _nscrolled = 0;
int _x = 0, _y = 0; int _x = 0, _y = 0;
FastLED_NeoMatrix *_matrix; FastLED_NeoMatrix *_matrix;
int _max_loops;
bool _off = true; bool _off = true;
public: public:
Scroller(int max_loops); Scroller();
bool TurnOn(); bool TurnOn();
void init(); void init();

View File

@@ -31,9 +31,7 @@
Adafruit_BME280 bme; // I2C Adafruit_BME280 bme; // I2C
#define COMMAND_PARAMETER_LENGTH 30 #define MATRIX_PIN 13
#define MAX_TIMES_SCROLLED 5
#define PIN 13
WiFiClient espClient; WiFiClient espClient;
PubSubClient client(espClient); PubSubClient client(espClient);
@@ -72,7 +70,7 @@ NTP ntp(ntpUDP);
TimeZone DateTime; TimeZone DateTime;
Scroller scroller(MAX_TIMES_SCROLLED); Scroller scroller;
unsigned long last_millis; unsigned long last_millis;
bool showTextMqtt = false; bool showTextMqtt = false;
@@ -105,7 +103,7 @@ void setup_matrix()
matrix = new FastLED_NeoMatrix(matrixleds, lcdw, lcdh, 1, 1, matrix = new FastLED_NeoMatrix(matrixleds, lcdw, lcdh, 1, 1,
NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG ); NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG );
FastLED.addLeds<NEOPIXEL,PIN>(matrixleds, NUMMATRIX); FastLED.addLeds<NEOPIXEL,MATRIX_PIN>(matrixleds, NUMMATRIX);
matrix->begin(); matrix->begin();
matrix->setTextWrap(false); matrix->setTextWrap(false);
matrix->setBrightness(20); matrix->setBrightness(20);