Skip to content

Commit 7782bc3

Browse files
authored
Fix drawLogBuffer for scrolling (#394)
When logBuffer has logBufferMaxLines, the drawing needs to start shifted up by displayHeight % lineHeight so that the first line drops off a bit, and not the last. Now printing to display really just works. (I moved the `length++` and removed the `else` because both sides of the condition started with it.)
1 parent 546fe9b commit 7782bc3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/OLEDDisplay.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,25 +829,27 @@ void OLEDDisplay::drawLogBuffer(uint16_t xMove, uint16_t yMove) {
829829
uint16_t line = 0;
830830
uint16_t lastPos = 0;
831831

832+
// If the lineHeight and the display height are not cleanly divisible, we need
833+
// to start off the screen when the buffer has logBufferMaxLines so that the
834+
// first line, and not the last line, drops off.
835+
uint16_t shiftUp = (this->logBufferLine == this->logBufferMaxLines) ? displayHeight % lineHeight : 0;
836+
832837
for (uint16_t i=0;i<this->logBufferFilled;i++){
838+
length++;
833839
// Everytime we have a \n print
834840
if (this->logBuffer[i] == 10) {
835-
length++;
836841
// Draw string on line `line` from lastPos to length
837842
// Passing 0 as the lenght because we are in TEXT_ALIGN_LEFT
838-
drawStringInternal(xMove, yMove + (line++) * lineHeight, &this->logBuffer[lastPos], length, 0, false);
843+
drawStringInternal(xMove, yMove - shiftUp + (line++) * lineHeight, &this->logBuffer[lastPos], length, 0, false);
839844
// Remember last pos
840845
lastPos = i;
841846
// Reset length
842847
length = 0;
843-
} else {
844-
// Count chars until next linebreak
845-
length++;
846848
}
847849
}
848850
// Draw the remaining string
849851
if (length > 0) {
850-
drawStringInternal(xMove, yMove + line * lineHeight, &this->logBuffer[lastPos], length, 0, false);
852+
drawStringInternal(xMove, yMove - shiftUp + line * lineHeight, &this->logBuffer[lastPos], length, 0, false);
851853
}
852854
}
853855

0 commit comments

Comments
 (0)