Blink implementacia

This commit is contained in:
2022-01-22 19:12:36 +01:00
parent 18b13fe506
commit 5549c417ca
2 changed files with 49 additions and 16 deletions

View File

@@ -95,6 +95,8 @@ bool Scroller::decodeEscape2Setting(String es)
break; break;
case BLINK: case BLINK:
_act_setting.font.blink = true; _act_setting.font.blink = true;
_blink = true;
if (_blinkTimeout == 0) _blinkTimeout = BLINK_TICKS;
break; break;
case REVERSED: case REVERSED:
_act_setting.font.reversed = true; _act_setting.font.reversed = true;
@@ -172,6 +174,12 @@ void Scroller::DeleteLines()
_lp = 0; _lp = 0;
} }
void Scroller::NextLine()
{
_lp++;
_blink = false;
}
void Scroller::Show(int _x,int _y,String line) void Scroller::Show(int _x,int _y,String line)
{ {
_matrix->fillScreen(0); _matrix->fillScreen(0);
@@ -186,7 +194,14 @@ void Scroller::Show(int _x,int _y,String line)
l = ee; l = ee;
continue; continue;
} }
_matrix->setTextColor(Framebuffer_GFX::Color24to16(_act_setting.font.color),Framebuffer_GFX::Color24to16(_act_setting.font.bcolor));
uint32_t fcolor;
if (_blink && _act_setting.font.blink == true && _blinkState == BLINK_OFF)
fcolor = _act_setting.font.bcolor;
else
fcolor = _act_setting.font.color;
_matrix->setTextColor(Framebuffer_GFX::Color24to16(fcolor),Framebuffer_GFX::Color24to16(_act_setting.font.bcolor));
_matrix->setBrightness(_act_setting.font.brightness); _matrix->setBrightness(_act_setting.font.brightness);
if (l != line.length()) { if (l != line.length()) {
#ifdef DEBUG #ifdef DEBUG
@@ -220,7 +235,7 @@ String Scroller::LineUnescaped(String line)
return rawLine; return rawLine;
} }
int Scroller::Scroll() void Scroller::Scroll()
{ {
int mx = 32; int mx = 32;
String line; String line;
@@ -233,21 +248,25 @@ int Scroller::Scroll()
{ {
Show(-_x,_y,line); Show(-_x,_y,line);
if (_x++ == 0) { if (_x++ == 0) {
return _act_setting.control.timeout/SCROLLER_TICK_TIME; _redrawTicks = _tick + _act_setting.control.timeout/SCROLLER_TICK_TIME;
return;
} }
else { else {
return _act_setting.control.speed/SCROLLER_TICK_TIME; _redrawTicks = _tick + _act_setting.control.speed/SCROLLER_TICK_TIME;
return;
} }
} }
_lp++; NextLine();
_x = 0; _x = 0;
return _act_setting.control.timeout/SCROLLER_TICK_TIME; _redrawTicks = _tick + _act_setting.control.timeout/SCROLLER_TICK_TIME;
return;
} }
else else
{ {
Show(_x,_y,line); Show(_x,_y,line);
_lp++; NextLine();
return _act_setting.control.timeout/SCROLLER_TICK_TIME; _redrawTicks = _tick + _act_setting.control.timeout/SCROLLER_TICK_TIME;
return;
} }
} }
@@ -285,6 +304,7 @@ void Scroller::TurnOff()
_matrix->print(""); _matrix->print("");
_matrix->show(); _matrix->show();
_off = true; _off = true;
_blink = false;
} }
void Scroller::loop(ulong tick) void Scroller::loop(ulong tick)
@@ -293,23 +313,29 @@ void Scroller::loop(ulong tick)
int delta = tick - _tick; int delta = tick - _tick;
if (_blink) _blinkTimeout -= delta;
_tick = tick;
if (TimesScrolled() > _act_setting.control.loops) { if (TimesScrolled() > _act_setting.control.loops) {
Serial.println("MAX LOOP"); Serial.println("MAX LOOP");
TurnOff(); TurnOff();
return; return;
} }
if (_delayTicks - delta <= 0) _delayTicks = Scroll(); if (_redrawTicks <= _tick || (_blink && _blinkTimeout <= 0)) {
else _delayTicks -= delta;
if (_delayTicks < 0) _delayTicks = 0; if (_blink && _blinkTimeout <=0) {
_blinkState = _blinkState == BLINK_OFF ? BLINK_ON : BLINK_OFF;
_blinkTimeout = BLINK_TICKS;
}
Scroll();
}
_tick = tick;
if (_lp > _nlines) { if (_lp > _nlines) {
_lp =0; _lp =0;
_nscrolled++; _nscrolled++;
_delayTicks = 500;
} }
} }

View File

@@ -8,6 +8,7 @@
#define SCROLLER_TICK_TIME 10 //ms #define SCROLLER_TICK_TIME 10 //ms
#define BLINK_TICKS (250/SCROLLER_TICK_TIME) // 250 ms for change time
typedef struct { typedef struct {
char const *code; char const *code;
@@ -21,6 +22,7 @@ typedef struct {
} eDict_t; } eDict_t;
enum {RESET_ALL,CLEAR_ALL, BOLD, UNDERLINE=4, BLINK=5,REVERSED=7, SPEED, TIMEOUT, LOOPS}; enum {RESET_ALL,CLEAR_ALL, BOLD, UNDERLINE=4, BLINK=5,REVERSED=7, SPEED, TIMEOUT, LOOPS};
enum eblinkState {BLINK_ON, BLINK_OFF} ;
struct Setting struct Setting
{ {
@@ -50,8 +52,12 @@ private:
Setting _act_setting; // actual setting Setting _act_setting; // actual setting
int _nlines = 0; int _nlines = 0;
int _lp = 0; int _lp = 0;
int _tick=0; ulong _tick=0;
int _delayTicks = 100; int _delayTicks = 100;
ulong _redrawTicks;
boolean _blink = false;
int _blinkTimeout = 0;
eblinkState _blinkState;
int _nscrolled = 0; int _nscrolled = 0;
int _x = 0, _y = 0; int _x = 0, _y = 0;
FastLED_NeoMatrix *_matrix; FastLED_NeoMatrix *_matrix;
@@ -71,9 +77,10 @@ public:
void SetParameters(int line,uint8_t color=1,uint8_t brightness=10,int timeout_off=2000,int timeout_on=2000,int speed=200); void SetParameters(int line,uint8_t color=1,uint8_t brightness=10,int timeout_off=2000,int timeout_on=2000,int speed=200);
int AddLines(String* lines,int nlines); int AddLines(String* lines,int nlines);
void DeleteLines(); void DeleteLines();
void NextLine();
bool ReplaceLine(int number,String line); bool ReplaceLine(int number,String line);
int GetNumberOfLines(); int GetNumberOfLines();
int Scroll(); void Scroll();
int TimesScrolled(); int TimesScrolled();
void PrintSerialLines(); void PrintSerialLines();
bool IsOff(); bool IsOff();