forked from DCC-EX/DCCInspector-EX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OledDisplay.h
90 lines (73 loc) · 2.92 KB
/
OledDisplay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Copyright (c) 2021 Neil McKechnie
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see
* <http://www.gnu.org/licenses/>.
*/
/*
* OledDisplay class
*
* Handles the Oled Display output from the DCC diagnostic program.
*
* The output to be displayed is passed to the program as parameter
* to the function update(). The string is sent to the screen (at least
* as much as fits on the screen). The buffer reference is held so that,
* if the user presses the button connected to BUTTONPIN, the screen is updated
* starting at a later line in the buffer. In this way, the user can
* scroll through the text.
* If the current scroll line number is greater than the number of lines
* of text when a refresh is due, then the text is displayed from the
* beginning once more.
*
* OLED ISN'T SUPPORTED ON ARDUINO NANO AND UNO because of the lack of memory.
*/
#ifndef oleddisplay_h
#define oleddisplay_h
#include <Adafruit_SSD1306.h>
#include "Config.h"
// Only compile if USE_OLED is defined.
// If not, then the entire contents are ignored by the compiler.
#ifdef USE_OLED
#include "DCCStatistics.h"
#include "StringBuilder.h"
class OledDisplayClass {
public:
// Function called to initialise the object instance.
// Connects to the OLED display and puts it into a
// suitable mode.
bool begin(int sdaPin, int sclPin);
inline void reset() { sbOled.reset(); }
// Function called to force an update of the screen,
// starting with the line referenced by 'firstLine'.
void refresh();
// Check the button pin input to see if the button has
// been pressed. If so, increment 'firstLine' and refresh,
// so that the displayed text scrolls upwards.
// This function should be called regularly from the loop() function.
void checkButton();
// Display specified text on the screen.
void append(const char *string);
// Write a summary version of the statistics data onto the screen.
void writeShortStatistics(Statistics &lastStats);
private:
// OLED Display
Adafruit_SSD1306 display = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Line number (starting with 0) of first line to be displayed.
int firstLine = 0;
const char *selectedLine();
char sbBuffer[1000];
StringBuilder sbOled = StringBuilder(sbBuffer, sizeof(sbBuffer));
} /* class OledDisplayClass */;
extern OledDisplayClass OledDisplay;
#endif
#endif