Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
ErrMsg.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file ErrMsg.h
3 *
4 * @brief Defines a mechism for displaying error and warning messages onto the TFT display.
5 ******************************************************************************/
6
7#ifndef ERRMSG_HEADER
8#define ERRMSG_HEADER
9
10#include "Canvas.h"
11#include "Menu.h"
12
17#define _MAXCHARS 85
18
19/******************************************************************************/
20/*** ***/
21/*** Class Definition: ErrMsg ***/
22/*** ***/
23/******************************************************************************
24 * @brief Provides a mechnism for displaying error and warning messages on the TFT display.
25 *
26 * @details
27 * This is a Singleton class. Use ErrMsg::getInstance() to obtain a reference
28 * to the ErrMsg instance. Warning messages give users the abiliy to acknowledge
29 * the message and continue. Error messages halt the program altogether. The
30 * following is an example of how to use the ErrMsg class:
31 *
32 * @code {.cpp}
33 * errMsg.warning()
34 * << "This is a test warning message." << ErrMsg::endl
35 * << "Value too high: " << value << ErrMsg::endl;
36 * errMsg.send();
37 * @endcode
38 *
39 * @note It is recommended that their only be one instance of ErrMsg for a
40 * given application.
41 *
42 ******************************************************************************/
43class ErrMsg
44{
45
46 Canvas _canvas; // Canvas for displaying the error message
47 const uint16_t _x = 10; // x position of the error message within _canvas
48 uint16_t _y; // y position of the error message within _canvas
49 const uint16_t _yStart = 10; // Starting position for the y cursor for a new error message within _canvas
50 const uint16_t _yMax = 480; // Maximum y position of the error message within _canvas
51 const uint16_t _deltaY = 25; // Spacing between lines of each error message
52
53 char _line[_MAXCHARS]; // Buffer used to build up each line of the error message
54 uint8_t pos; // Current position within the line buffer
55
56 uint16_t _fontFG = 0xFFFF; // Foreground color of the font
57 uint16_t _fontBG = 0x0000; // Background color of the font
58
59 static ErrMsg *_instance; // The Singleton instance of ErrMsg
60
61 enum ErrorType
62 {
63 WARNING,
64 ERROR
65 };
66 ErrorType _type; // Tracks whether this is a warning or error message
67
68 SoloMenu *_origMenu = nullptr; // The menu that was displayed before the error message was displayed
69
70 // Private Constructor
71 ErrMsg(void)
72 : _canvas{}, _y{_yStart}, _line{""}, pos{0}, _type{ErrorType::WARNING}
73 {
74 }
75
76 // Private Destructor
77 ~ErrMsg(void) = default;
78
79public:
80 struct EndlToken
81 {
82 };
83 static EndlToken endl;
84
90 static ErrMsg &getInstance(void)
91 {
92 if (!_instance)
93 _instance = new ErrMsg();
94 return *_instance;
95 };
96
98 ErrMsg(const ErrMsg &) = delete;
99
101 ErrMsg &operator=(const ErrMsg &) = delete;
102
110 ErrMsg &error(void);
111
120 ErrMsg &warning(void);
121
135 template <typename T>
136 ErrMsg &operator<<(const T value)
137 {
138 // Ignore if this line extends past _yMax
139 if (_y >= _yMax)
140 return *this;
141
142 // Ignore if we've run out of ro
143 int16_t buffSize = _MAXCHARS - pos;
144 if (buffSize <= 0)
145 return *this;
146
147 // Add the value to the line buffer
148 _addToLine(value, buffSize);
149
150 // Finished
151 return *this;
152 }
153
159 void send(void);
160
166 void checkForUserInput(void);
167
168private:
169 // Clears the canvas and sets the background color
170 void _resetCanvas(uint16_t color);
171
172 // Internal message used to send an error message to the screen
173 void _sendError(void);
174
175 // Internal message used to send a warning message to the screen
176 void _sendWarning(void);
177
178 // Adds a value to the current line. These methods provide functionality for the operator<<() method.
179 void _addToLine(const char *const value, int16_t buffSize);
180 void _addToLine(const int value, int16_t buffSize);
181 void _addToLine(const bool value, int16_t buffSize);
182 void _addToLine(const unsigned int value, int16_t buffSize);
183};
184
190template <>
191ErrMsg &ErrMsg::operator<< <ErrMsg::EndlToken>(const ErrMsg::EndlToken value);
192
196extern ErrMsg &errMsg;
197
198#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:17
Definition Canvas.h:33
Definition ErrMsg.h:44
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:90
static EndlToken endl
End of line token used by the operator<< method.
Definition ErrMsg.h:83
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:136
Definition Menu.h:33
Token that indicates the end of a line in the error message.
Definition ErrMsg.h:81