Blink implementacia
This commit is contained in:
@@ -95,6 +95,8 @@ bool Scroller::decodeEscape2Setting(String es)
|
||||
break;
|
||||
case BLINK:
|
||||
_act_setting.font.blink = true;
|
||||
_blink = true;
|
||||
if (_blinkTimeout == 0) _blinkTimeout = BLINK_TICKS;
|
||||
break;
|
||||
case REVERSED:
|
||||
_act_setting.font.reversed = true;
|
||||
@@ -172,6 +174,12 @@ void Scroller::DeleteLines()
|
||||
_lp = 0;
|
||||
}
|
||||
|
||||
void Scroller::NextLine()
|
||||
{
|
||||
_lp++;
|
||||
_blink = false;
|
||||
}
|
||||
|
||||
void Scroller::Show(int _x,int _y,String line)
|
||||
{
|
||||
_matrix->fillScreen(0);
|
||||
@@ -186,7 +194,14 @@ void Scroller::Show(int _x,int _y,String line)
|
||||
l = ee;
|
||||
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);
|
||||
if (l != line.length()) {
|
||||
#ifdef DEBUG
|
||||
@@ -220,7 +235,7 @@ String Scroller::LineUnescaped(String line)
|
||||
return rawLine;
|
||||
}
|
||||
|
||||
int Scroller::Scroll()
|
||||
void Scroller::Scroll()
|
||||
{
|
||||
int mx = 32;
|
||||
String line;
|
||||
@@ -233,21 +248,25 @@ int Scroller::Scroll()
|
||||
{
|
||||
Show(-_x,_y,line);
|
||||
if (_x++ == 0) {
|
||||
return _act_setting.control.timeout/SCROLLER_TICK_TIME;
|
||||
_redrawTicks = _tick + _act_setting.control.timeout/SCROLLER_TICK_TIME;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
return _act_setting.control.speed/SCROLLER_TICK_TIME;
|
||||
_redrawTicks = _tick + _act_setting.control.speed/SCROLLER_TICK_TIME;
|
||||
return;
|
||||
}
|
||||
}
|
||||
_lp++;
|
||||
NextLine();
|
||||
_x = 0;
|
||||
return _act_setting.control.timeout/SCROLLER_TICK_TIME;
|
||||
_redrawTicks = _tick + _act_setting.control.timeout/SCROLLER_TICK_TIME;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Show(_x,_y,line);
|
||||
_lp++;
|
||||
return _act_setting.control.timeout/SCROLLER_TICK_TIME;
|
||||
NextLine();
|
||||
_redrawTicks = _tick + _act_setting.control.timeout/SCROLLER_TICK_TIME;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,6 +304,7 @@ void Scroller::TurnOff()
|
||||
_matrix->print("");
|
||||
_matrix->show();
|
||||
_off = true;
|
||||
_blink = false;
|
||||
}
|
||||
|
||||
void Scroller::loop(ulong tick)
|
||||
@@ -293,23 +313,29 @@ void Scroller::loop(ulong tick)
|
||||
|
||||
int delta = tick - _tick;
|
||||
|
||||
if (_blink) _blinkTimeout -= delta;
|
||||
_tick = tick;
|
||||
|
||||
if (TimesScrolled() > _act_setting.control.loops) {
|
||||
Serial.println("MAX LOOP");
|
||||
TurnOff();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_delayTicks - delta <= 0) _delayTicks = Scroll();
|
||||
else _delayTicks -= delta;
|
||||
|
||||
if (_delayTicks < 0) _delayTicks = 0;
|
||||
if (_redrawTicks <= _tick || (_blink && _blinkTimeout <= 0)) {
|
||||
|
||||
_tick = tick;
|
||||
if (_blink && _blinkTimeout <=0) {
|
||||
_blinkState = _blinkState == BLINK_OFF ? BLINK_ON : BLINK_OFF;
|
||||
_blinkTimeout = BLINK_TICKS;
|
||||
}
|
||||
|
||||
Scroll();
|
||||
}
|
||||
|
||||
|
||||
if (_lp > _nlines) {
|
||||
_lp =0;
|
||||
_nscrolled++;
|
||||
_delayTicks = 500;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
#define SCROLLER_TICK_TIME 10 //ms
|
||||
#define BLINK_TICKS (250/SCROLLER_TICK_TIME) // 250 ms for change time
|
||||
|
||||
typedef struct {
|
||||
char const *code;
|
||||
@@ -21,6 +22,7 @@ typedef struct {
|
||||
} eDict_t;
|
||||
|
||||
enum {RESET_ALL,CLEAR_ALL, BOLD, UNDERLINE=4, BLINK=5,REVERSED=7, SPEED, TIMEOUT, LOOPS};
|
||||
enum eblinkState {BLINK_ON, BLINK_OFF} ;
|
||||
|
||||
struct Setting
|
||||
{
|
||||
@@ -50,8 +52,12 @@ private:
|
||||
Setting _act_setting; // actual setting
|
||||
int _nlines = 0;
|
||||
int _lp = 0;
|
||||
int _tick=0;
|
||||
ulong _tick=0;
|
||||
int _delayTicks = 100;
|
||||
ulong _redrawTicks;
|
||||
boolean _blink = false;
|
||||
int _blinkTimeout = 0;
|
||||
eblinkState _blinkState;
|
||||
int _nscrolled = 0;
|
||||
int _x = 0, _y = 0;
|
||||
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);
|
||||
int AddLines(String* lines,int nlines);
|
||||
void DeleteLines();
|
||||
void NextLine();
|
||||
bool ReplaceLine(int number,String line);
|
||||
int GetNumberOfLines();
|
||||
int Scroll();
|
||||
void Scroll();
|
||||
int TimesScrolled();
|
||||
void PrintSerialLines();
|
||||
bool IsOff();
|
||||
|
||||
Reference in New Issue
Block a user