From 4b8bc6b0ff050da310ddb4b2546a9da1f6f6a37d Mon Sep 17 00:00:00 2001 From: skjaro Date: Fri, 24 Dec 2021 21:20:32 +0100 Subject: [PATCH] Fix bugs --- src/Scroller.cpp | 23 ++++++++++++----------- src/Scroller.h | 2 +- src/main.cpp | 7 +------ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Scroller.cpp b/src/Scroller.cpp index 4ed97c4..95867b6 100644 --- a/src/Scroller.cpp +++ b/src/Scroller.cpp @@ -138,6 +138,7 @@ int Scroller::GetNumberOfLines() int Scroller::AddLine(String line) { + if (_nlines > MAX_LINES) return _nlines; _Lines[_nlines] = line; return _nlines++; } @@ -264,8 +265,8 @@ bool Scroller::TurnOn() _x = 0; _y = 0; _nscrolled = 0; - _delayTicks = 0; - + _delayTicks = 100; + return true; } @@ -281,17 +282,11 @@ void Scroller::TurnOff() void Scroller::loop(ulong tick) { - if (_off) return; + if (_off || _nlines == 0) return; int delta = tick - _tick; - if (_lp == _nlines) { - _lp =0; - _nscrolled++; - _delayTicks = 50; - } - - if (TimesScrolled() == _act_setting.control.loops) { + if (TimesScrolled() > _act_setting.control.loops) { Serial.println("MAX LOOP"); TurnOff(); return; @@ -300,10 +295,16 @@ void Scroller::loop(ulong tick) if (_delayTicks - delta <= 0) _delayTicks = Scroll(); else _delayTicks -= delta; - if (_delayTicks < 0) _delayTicks = 0; _tick = tick; + + if (_lp > _nlines) { + _lp =0; + _nscrolled++; + _delayTicks = 500; + } + } int Scroller::TimesScrolled() diff --git a/src/Scroller.h b/src/Scroller.h index 3918240..0f2ebc5 100644 --- a/src/Scroller.h +++ b/src/Scroller.h @@ -50,7 +50,7 @@ private: int _nlines = 0; int _lp = 0; int _tick=0; - int _delayTicks = 0; + int _delayTicks = 100; int _nscrolled = 0; int _x = 0, _y = 0; FastLED_NeoMatrix *_matrix; diff --git a/src/main.cpp b/src/main.cpp index 304ea76..1232fc2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -250,7 +250,7 @@ void callback(char* topic, byte* payload, unsigned int length) { strncpy(msg,(char *)payload,length>255 ? 255 : length); msg[length>255 ? 255 : length] = '\0'; - if (scroller.IsOff()) showTextMqtt = true; + if (scroller.IsOff()) scroller.TurnOn(); scroller.AddLine(msg); } else if (String("get/home/sensor/decka/bme280") == String(topic)) { client.publish("home/sensor/decka/bme280/temperature",(String("N:") + String(bme.readTemperature())).c_str()); @@ -300,11 +300,6 @@ void loop() updateNtpTime = false; } - if (showTextMqtt) { - scroller.TurnOn(); - showTextMqtt = false; - } - scroller.loop(tick); client.loop(); }