Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
ErrMsg.h
Go to the documentation of this file.
1/******************************************************************************/
6
7#ifndef ERRMSG_HEADER
8#define ERRMSG_HEADER
9
10#include "Menu.h"
11
16#define _MAXCHARS 85
17
18/******************************************************************************/
19/*** ***/
20/*** Class Definition: ErrMsg ***/
21/*** ***/
22/******************************************************************************/
44class ErrMsg
45{
46
47 Canvas _canvas; // Canvas for displaying the error message
48 const uint16_t _x = 10; // x position of the error message within _canvas
49 uint16_t _y; // y position of the error message within _canvas
50 const uint16_t _yStart = 10; // Starting position for the y cursor for a new error message within _canvas
51 const uint16_t _yMax = 480; // Maximum y position of the error message within _canvas
52 const uint16_t _deltaY = 25; // Spacing between lines of each error message
53
54 char _line[_MAXCHARS]; // Buffer used to build up each line of the error message
55 uint8_t pos; // Current position within the line buffer
56
57 uint16_t _fontFG = 0xFFFF; // Foreground color of the font
58 uint16_t _fontBG = 0x0000; // Background color of the font
59
60 static ErrMsg *_instance; // The Singleton instance of ErrMsg
61
62 enum ErrorType
63 {
64 WARNING,
65 ERROR
66 };
67 ErrorType _type; // Tracks whether this is a warning or error message
68
69 SoloMenu *_origMenu = nullptr; // The menu that was displayed before the error message was displayed
70
71 // Private Constructor
72 ErrMsg(void)
73 : _canvas{}, _y{_yStart}, _line{""}, pos{0}, _type{ErrorType::WARNING}
74 {
75 }
76
77 // Private Destructor
78 ~ErrMsg(void) = default;
79
80public:
81 struct EndlToken
82 {
83 };
84 static EndlToken endl;
85
91 static ErrMsg &getInstance(void)
92 {
93 if (!_instance)
94 _instance = new ErrMsg();
95 return *_instance;
96 };
97
99 ErrMsg(const ErrMsg &) = delete;
100
102 ErrMsg &operator=(const ErrMsg &) = delete;
103
111 ErrMsg &error(void);
112
121 ErrMsg &warning(void);
122
136 template <typename T>
137 ErrMsg &operator<<(const T value)
138 {
139 // Ignore if this line extends past _yMax
140 if (_y >= _yMax)
141 return *this;
142
143 // Ignore if we've run out of ro
144 int16_t buffSize = _MAXCHARS - pos;
145 if (buffSize <= 0)
146 return *this;
147
148 // Add the value to the line buffer
149 _addToLine(value, buffSize);
150
151 // Finished
152 return *this;
153 }
154
160 void send(void);
161
167 void checkForUserInput(void);
168
169private:
170 // Clears the canvas and sets the background color
171 void _resetCanvas(uint16_t color);
172
173 // Internal message used to send an error message to the screen
174 void _sendError(void);
175
176 // Internal message used to send a warning message to the screen
177 void _sendWarning(void);
178
179 // Adds a value to the current line. These methods provide functionality for the operator<<() method.
180 void _addToLine(const char *const value, int16_t buffSize);
181 void _addToLine(const int value, int16_t buffSize);
182 void _addToLine(const bool value, int16_t buffSize);
183 void _addToLine(const unsigned int value, int16_t buffSize);
184};
185
191template <>
192ErrMsg &ErrMsg::operator<< <ErrMsg::EndlToken>(const ErrMsg::EndlToken value);
193
197extern ErrMsg &errMsg;
198
199#endif // ERRMSG_HEADER
ErrMsg & errMsg
Global instance of ErrMsg.
Definition ErrMsg.cpp:185
#define _MAXCHARS
Maximum number of characters that can be displayed in each line.
Definition ErrMsg.h:16
Defines the menu classes used by the SoloController app.
Provides higher level TFT graphic functionality used by the menu system.
Definition Canvas.h:34
Provides a mechnism for displaying error and warning messages on the TFT display.
Definition ErrMsg.h:45
ErrMsg & warning(void)
Sets up the display to shown a warning message.
Definition ErrMsg.cpp:40
void send(void)
Displays the error message on the screen.
Definition ErrMsg.cpp:66
static ErrMsg & getInstance(void)
Returns reference to the ErrMsg object.
Definition ErrMsg.h:91
static EndlToken endl
End of line token used by the operator<< method.
Definition ErrMsg.h:84
ErrMsg & error(void)
Sets up the display to show an error message.
Definition ErrMsg.cpp:17
void checkForUserInput(void)
Method used by TaskManager. Asks ErrMsg check to see if the screen has been touched.
Definition ErrMsg.cpp:98
ErrMsg & operator<<(const T value)
Adds information to the error message.
Definition ErrMsg.h:137
Base class used by all menus.
Definition Menu.h:33
Token that indicates the end of a line in the error message.
Definition ErrMsg.h:82