EX-Display
EX-Display
Loading...
Searching...
No Matches
/home/runner/work/EX-Display/EX-Display/DisplayInterface.h
Go to the documentation of this file.
1/*
2 * © 2025 Peter Cole
3 * © 2024 Peter Cole
4 *
5 * This is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * It is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this code. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#ifndef DISPLAYINTERFACE_H
20#define DISPLAYINTERFACE_H
21
22#include "Logger.h"
23#include "Screen.h"
24
34
37public:
39 virtual void begin() = 0;
40
42 virtual void clearScreen() = 0;
43
46 virtual void displayScreen(Screen *screen) = 0;
47
50 virtual void displayStartupInfo(const char *version) = 0;
51
58 virtual void displayFormattedRow(uint8_t row, uint8_t column, RowAttributes attributes, const char *text,
59 bool append) = 0;
60
63 void setNext(DisplayInterface *display);
64
68
71 void setLogger(Logger *logger);
72
75 void setId(uint8_t displayId);
76
79 uint8_t getId();
80
83 void setScreenId(int screenId);
84
87 int getScreenId();
88
91 int getCSPin();
92
95 void setNeedsRedraw(bool redraw);
96
99 bool needsRedraw();
100
104 void formatRow(int row, const char *text);
105
107 virtual ~DisplayInterface() = default;
108
109protected:
113 uint16_t _textColour;
117 Logger *_logger = nullptr;
119 uint8_t _displayId = 0;
121 int _screenId = -1;
123 uint8_t _rotation = 0;
125 uint8_t _textSize = 1;
127 uint8_t _maxRow = 0;
129 uint8_t _maxColumn = 0;
131 uint8_t _fontHeight = 0;
133 uint8_t _fontWidth = 0;
136 int _csPin = -1;
138 bool _needsRedraw = true;
139
148
155 bool _isModifier(char check);
156
164 RowAttributes _setAttribute(RowAttributes attributes, char modifier, uint16_t colour = 0xFFFF);
165
172 bool _isRGB(const char *colour);
173
179 uint16_t _convertRGBtoRGB565(const char *colour);
180};
181
182#endif // DISPLAYINTERFACE_H
Class to abstract away all physical display implementation to enable multiple display types.
Definition DisplayInterface.h:36
int getScreenId()
Get the Screen ID this display is currently displaing.
Definition DisplayInterface.cpp:36
int _csPin
If there are more than one SPI displays that libraries don't officially support, the CS pin can be pr...
Definition DisplayInterface.h:136
void setScreenId(int screenId)
Set the Screen ID this display is currently displaying.
Definition DisplayInterface.cpp:31
DisplayInterface * _next
Pointer to the next DisplayInterface derived instance in the list.
Definition DisplayInterface.h:111
void formatRow(int row, const char *text)
Static method to enable calling back to a derived class with a formatted row.
Definition DisplayInterface.cpp:58
uint8_t _fontWidth
Calculated font width to determine column positioning.
Definition DisplayInterface.h:133
void setNeedsRedraw(bool redraw)
Set the flag for whether this display needs redrawing or not - individual row updates are not affecte...
Definition DisplayInterface.cpp:40
uint8_t getId()
Get the ID of this display instance.
Definition DisplayInterface.cpp:29
void setLogger(Logger *logger)
Set the logger instance to use for diagnostic logging.
Definition DisplayInterface.cpp:25
uint8_t _displayId
ID for this display instance.
Definition DisplayInterface.h:119
Logger * _logger
Pointer to the Logger instance for the DisplayInterface derived classes.
Definition DisplayInterface.h:117
uint8_t _rotation
Orientation of this display, most displays require this setting otherwise ignore it.
Definition DisplayInterface.h:123
RowAttributes _setAttribute(RowAttributes attributes, char modifier, uint16_t colour=0xFFFF)
Update the provided RowAttributes struct according to the provided modifier.
Definition DisplayInterface.cpp:170
int _screenId
ID of the screen this display is currently displaying, defaults to -1 to flag it is not a valid ID.
Definition DisplayInterface.h:121
uint8_t _maxColumn
Maximum column number (not count) that will fit on this display (based on font width,...
Definition DisplayInterface.h:129
uint8_t _textSize
Multiplier for text size, most displays require this setting otherwise ignore it.
Definition DisplayInterface.h:125
uint16_t _textColour
Default text colour for the display.
Definition DisplayInterface.h:113
bool needsRedraw()
Test if this display needs an entire redraw.
Definition DisplayInterface.cpp:42
virtual void displayFormattedRow(uint8_t row, uint8_t column, RowAttributes attributes, const char *text, bool append)=0
Display a row using formatting modifiers.
virtual void displayStartupInfo(const char *version)=0
Display the startup screen with software version.
RowAttributes _sanitiseAttributes(RowAttributes attributes)
Sanitise the provided struct of RowAttributes.
Definition DisplayInterface.cpp:148
int getCSPin()
Get the defined CS pin for this display to see if it needs manual SPI switching.
Definition DisplayInterface.cpp:38
void setId(uint8_t displayId)
Set the ID for this display instance.
Definition DisplayInterface.cpp:27
uint8_t _maxRow
Maximum row number (not count) that will fit on this display (based on font height,...
Definition DisplayInterface.h:127
virtual void clearScreen()=0
Clear the entire screen.
virtual void begin()=0
Perform any initial once off setup or configuration here and call only once.
bool _needsRedraw
Flag that this display needs redrawing - needed for switching between screens.
Definition DisplayInterface.h:138
bool _isRGB(const char *colour)
Check if the provided string constant translates to a valid RGB colour code.
Definition DisplayInterface.cpp:194
void setNext(DisplayInterface *display)
Set the next DisplayInterface derived instance in the list.
Definition DisplayInterface.cpp:21
uint16_t _convertRGBtoRGB565(const char *colour)
Convert the provided RGB colour code string constant to a uint16_t RGB565 colour.
Definition DisplayInterface.cpp:205
uint8_t _fontHeight
Calculated font height to determine row positioning.
Definition DisplayInterface.h:131
bool _isModifier(char check)
Validates the provided char is a valid modifier.
Definition DisplayInterface.cpp:161
uint16_t _backgroundColour
Default background colour for the display.
Definition DisplayInterface.h:115
virtual ~DisplayInterface()=default
Destructor for a DisplayInterface.
virtual void displayScreen(Screen *screen)=0
Display the specified Screen on this display.
DisplayInterface * getNext()
Get the next DisplayInterface derived instance in the list.
Definition DisplayInterface.cpp:23
Class to enable simple logging to a Stream object with different log levels This enables embedding pe...
Definition Logger.h:35
Class for each screen as received from the EXRAIL SCREEN() command Each Screen instance contains a li...
Definition Screen.h:27
Structure for row attributes.
Definition DisplayInterface.h:26
bool colourSet
Definition DisplayInterface.h:27
bool isUnderlined
Definition DisplayInterface.h:28
bool isLine
Definition DisplayInterface.h:29
uint16_t textColour
Definition DisplayInterface.h:32
bool alwaysTicker
Definition DisplayInterface.h:30
bool neverTicker
Definition DisplayInterface.h:31