mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 21:21:24 +01:00
Move statics into LCDDisplay class, and reduce RAM.
Some state variables were static in LCDDisplay.write(). Moved to class members. Also, types of data items like row, column & character position changed to int8_t to save a few bytes of RAM.
This commit is contained in:
parent
c5ddbdf8d7
commit
3327c043a1
@ -46,20 +46,13 @@ size_t LCDDisplay::write(uint8_t b) {
|
|||||||
|
|
||||||
LCDDisplay *LCDDisplay::loop2(bool force)
|
LCDDisplay *LCDDisplay::loop2(bool force)
|
||||||
{
|
{
|
||||||
static int rowFirst = -1;
|
|
||||||
static int rowNext = 0;
|
|
||||||
static int charIndex = 0;
|
|
||||||
static char buffer[MAX_LCD_COLS+1];
|
|
||||||
static char *bptr = 0;
|
|
||||||
static bool done = false;
|
|
||||||
|
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
|
|
||||||
if ((!force) && (currentMillis - lastScrollTime) < LCD_SCROLL_TIME)
|
if ((!force) && (currentMillis - lastScrollTime) < LCD_SCROLL_TIME)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (bptr == 0) {
|
if (bufferPointer == 0) {
|
||||||
// Find a line of data to write to the screen.
|
// Find a line of data to write to the screen.
|
||||||
if (!done) {
|
if (!done) {
|
||||||
if (rowFirst < 0) rowFirst = rowNext;
|
if (rowFirst < 0) rowFirst = rowNext;
|
||||||
@ -74,26 +67,26 @@ LCDDisplay *LCDDisplay::loop2(bool force)
|
|||||||
}
|
}
|
||||||
if (!done) {
|
if (!done) {
|
||||||
// Non-blank line found, so copy it.
|
// Non-blank line found, so copy it.
|
||||||
for (int i=0; i<MAX_LCD_COLS+1; i++)
|
for (uint8_t i=0; i<sizeof(buffer); i++)
|
||||||
buffer[i] = rowBuffer[rowNext][i];
|
buffer[i] = rowBuffer[rowNext][i];
|
||||||
} else
|
} else
|
||||||
buffer[0] = '\0'; // Empty line
|
buffer[0] = '\0'; // Empty line
|
||||||
setRowNative(slot); // Set position for display
|
setRowNative(slot); // Set position for display
|
||||||
charIndex = 0;
|
charIndex = 0;
|
||||||
bptr = &buffer[0];
|
bufferPointer = &buffer[0];
|
||||||
} else {
|
} else {
|
||||||
// Write next character, or a space to erase current position.
|
// Write next character, or a space to erase current position.
|
||||||
char ch = *bptr;
|
char ch = *bufferPointer;
|
||||||
if (ch) {
|
if (ch) {
|
||||||
writeNative(ch);
|
writeNative(ch);
|
||||||
bptr++;
|
bufferPointer++;
|
||||||
} else
|
} else
|
||||||
writeNative(' ');
|
writeNative(' ');
|
||||||
|
|
||||||
if (++charIndex >= MAX_LCD_COLS) {
|
if (++charIndex >= MAX_LCD_COLS) {
|
||||||
// Screen slot completed, move to next one
|
// Screen slot completed, move to next one
|
||||||
slot++;
|
slot++;
|
||||||
bptr = 0;
|
bufferPointer = 0;
|
||||||
if (!done) {
|
if (!done) {
|
||||||
rowNext = (rowNext + 1) % MAX_LCD_ROWS;
|
rowNext = (rowNext + 1) % MAX_LCD_ROWS;
|
||||||
if (rowNext == rowFirst) done = true;
|
if (rowNext == rowFirst) done = true;
|
||||||
|
19
LCDDisplay.h
19
LCDDisplay.h
@ -52,12 +52,19 @@ class LCDDisplay : public Print {
|
|||||||
void writeNative(char b);
|
void writeNative(char b);
|
||||||
|
|
||||||
unsigned long lastScrollTime=0;
|
unsigned long lastScrollTime=0;
|
||||||
int hotRow=0;
|
int8_t hotRow=0;
|
||||||
int hotCol=0;
|
int8_t hotCol=0;
|
||||||
int topRow=0;
|
int8_t topRow=0;
|
||||||
int lcdRows;
|
int8_t lcdRows;
|
||||||
int lcdCols;
|
int8_t lcdCols;
|
||||||
int slot=0;
|
int8_t slot=0;
|
||||||
|
int8_t rowFirst=-1;
|
||||||
|
int8_t rowNext=0;
|
||||||
|
int8_t charIndex = 0;
|
||||||
|
char buffer[MAX_LCD_COLS+1];
|
||||||
|
char *bufferPointer = 0;
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
void renderRow(byte row);
|
void renderRow(byte row);
|
||||||
char rowBuffer[MAX_LCD_ROWS][MAX_LCD_COLS+1];
|
char rowBuffer[MAX_LCD_ROWS][MAX_LCD_COLS+1];
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user