Skip to content

Commit c0758b6

Browse files
authored
Implement cls(), document Print functionality (#397)
There was no previous way for the user to empty the logBuffer, cls() fixes that. Also the documentation now explains the Print functionality and how it relates to the rest of the functions.
1 parent 1da41d9 commit c0758b6

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,25 @@ void setTextAlignment(OLEDDISPLAY_TEXT_ALIGNMENT textAlignment);
262262
void setFont(const uint8_t* fontData);
263263
```
264264
265+
## Arduino `Print` functionality
266+
267+
Because this class has been "derived" from Arduino's `Print` class, you can use the functions it provides. In plain language, this means that you can use `print`, `println` and `printf` to the display. Internally, a buffer holds the text that was printed to the display previously (that would still fit on the display) and every time you print something, this buffer is put on the screen, using the functions from the previous section.
268+
269+
What that means is that printing using `print` and "manually" putting things on the display are somewhat mutually exclusive: as soon as you print, everything that was on the display already is gone and only what you put there before with `print`, `println` or `printf` remains. Still, using `print` is a very simple way to put something on the display quickly.
270+
271+
One extra function is provided: `cls()`
272+
```cpp
273+
// cls() will clear the display immediately and empty the logBuffer, meaning
274+
// the next print statement will print at the top of the display again.
275+
// cls() should not be confused with clear(), which only clears the internal
276+
// graphics buffer, which can then be shown on the display with display().
277+
void cls();
278+
```
279+
280+
 
281+
282+
<hr>
283+
265284
## Ui Library (OLEDDisplayUi)
266285

267286
The Ui Library is used to provide a basic set of user interface elements called `Frames` and `Overlays`. A `Frame` is used to provide

src/OLEDDisplay.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,13 @@ uint16_t OLEDDisplay::getHeight(void) {
861861
return displayHeight;
862862
}
863863

864+
void OLEDDisplay::cls() {
865+
clear();
866+
this->logBufferFilled = 0;
867+
this->logBufferLine = 0;
868+
display();
869+
}
870+
864871
bool OLEDDisplay::setLogBuffer(uint16_t lines, uint16_t chars){
865872
if (logBuffer != NULL) free(logBuffer);
866873
uint16_t size = lines * chars;

src/OLEDDisplay.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,27 @@ class OLEDDisplay : public Stream {
311311
// Clear the local pixel buffer
312312
void clear(void);
313313

314-
// Log buffer implementation
315-
316-
// This will define the lines and characters you can
317-
// print to the screen. When you exeed the buffer size (lines * chars)
318-
// the output may be truncated due to the size constraint.
314+
// Print class device
315+
316+
// Because this display class is "derived" from Arduino's Print class,
317+
// various function that work on it also work here. These functions include
318+
// print, println and printf.
319+
320+
// cls() will clear the display immediately and empty the logBuffer, meaning
321+
// the next print statement will print at the top of the display again.
322+
// cls() should not be confused with clear(), which only clears the internal
323+
// graphics buffer, which can then be shown on the display with display().
324+
void cls();
325+
326+
// This will define the lines and characters you can print to the screen.
327+
// When you exeed the buffer size (lines * chars) the output may be
328+
// truncated due to the size constraint. (Automatically called with the
329+
// correct parameters when you first print to the display.)
319330
bool setLogBuffer(uint16_t lines, uint16_t chars);
320331

321332
// Draw the log buffer at position (x, y)
333+
//
334+
// (Automatically called with you use print, println or printf)
322335
void drawLogBuffer(uint16_t x, uint16_t y);
323336

324337
// Get screen geometry

0 commit comments

Comments
 (0)