Version 0.9

This commit is contained in:
2020-06-01 19:20:52 +02:00
parent 1b38f5b129
commit da0728d671
5 changed files with 762 additions and 56 deletions

140
src/Scroller.cpp Normal file
View File

@@ -0,0 +1,140 @@
#include "Scroller.h"
Scroller::Scroller(int max_loops)
{
_max_loops = max_loops;
}
void Scroller::SetMatrix(Adafruit_NeoMatrix *matrix)
{
this->_matrix = matrix;
}
int Scroller::GetNumberOfLines()
{
return this->_nlines;
}
int Scroller::AddLine(String line)
{
this->_Lines[this->_nlines] = line;
return _nlines++;
}
int Scroller::AddLines(String* lines,int nlines)
{
for (int i=0; i < nlines; i++) {
_Lines[i] = lines[i];
}
_nlines = nlines;
return _nlines;
}
bool Scroller::ReplaceLine(int number,String line)
{
_Lines[number] = line;
return true;
}
void Scroller::DeleteLines()
{
_nlines = 0;
}
int Scroller::Scroll(int tick)
{
int mx = 32;
String line;
line = _Lines[_lp];
if (line.length() * 6 > mx)
{
if (_x < line.length() * 6 - mx)
{
_matrix->fillScreen(0);
_matrix->setCursor(-_x, _y);
_matrix->setTextColor(_colors[1]);
_matrix->print(line);
_matrix->show();
if (_x++ == 0) {
return 3;
}
else {
return 1;
}
}
_lp++;
_x = 0;
return 10;
}
else
{
_matrix->fillScreen(0);
_matrix->setCursor(_x, _y);
_matrix->setTextColor(_colors[1]);
_matrix->print(line);
_matrix->show();
_lp++;
return 30;
}
}
bool Scroller::TurnOn()
{
_off = false;
_lp = 0;
_x = 0;
_y = 0;
_nscrolled = 0;
_delayTicks = 0;
return true;
}
void Scroller::TurnOff()
{
_matrix->fillScreen(0);
_matrix->print("");
_matrix->show();
_off = true;
}
void Scroller::SetColors(uint16_t *colors)
{
_colors = colors;
}
void Scroller::loop(int tick)
{
if (_off) return;
int delta = tick - _tick;
if (_lp == _nlines) {
_lp =0;
_nscrolled++;
_delayTicks = 50;
}
if (TimesScrolled() == _max_loops) {
TurnOff();
return;
}
if (_delayTicks - delta <= 0) _delayTicks = Scroll(tick);
else _delayTicks -= delta;
if (_delayTicks < 0) _delayTicks = 0;
}
int Scroller::TimesScrolled()
{
return _nscrolled;
}
Scroller::~Scroller()
{
}