forked from jinschoi/SphereBot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SerialDisplayPrint.cpp
206 lines (184 loc) · 5.21 KB
/
SerialDisplayPrint.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
SerialDisplayPrint.cpp - Library for printing to both the serial port and display.
Created by Terence F. Golla, May 29, 2022
Released into the public domain.
*/
#include "SerialDisplayPrint.h"
SerialDisplayPrint::SerialDisplayPrint() { }
#if ADAFRUIT_TFT_TOUCH_SHIELD
void SerialDisplayPrint::begin(HardwareSerial &serial, Adafruit_SPITFT &tft)
{
Serial = &serial;
TFT = &tft;
}
#else
void SerialDisplayPrint::begin(HardwareSerial &serial)
{
Serial = &serial;
}
#endif
#if ADAFRUIT_TFT_TOUCH_SHIELD
void SerialDisplayPrint::SetTextSize(int textSize)
{
TFT->setTextSize(textSize);
currentTextSize = textSize;
}
void SerialDisplayPrint::SetTextDisplay()
{
TFT->fillScreen(TFT_TEXT_BACKGROUND_COLOR);
TFT->setTextColor(TFT_TEXT_COLOR);
SetTextSize(TFT_TEXT_SIZE);
TFT->setTextWrap(false);
TFT->setCursor(0, 0);
currentDisplayLineCursor = 0;
}
void SerialDisplayPrint::AdvanceToNextLineOnDisplay()
{
currentDisplayLineCursor = currentDisplayLineCursor + (TFT_TEXT_HEIGHT * currentTextSize);
// At lease part of the next line is on the display, so erase what was previously there.
if (currentDisplayLineCursor <= TFT_HEIGHT)
TFT->fillRect(0, currentDisplayLineCursor, TFT_WIDTH, TFT_TEXT_HEIGHT * currentTextSize, ILI9341_BLACK);
// If the next line will not completely fit on the display, return to the top of the display.
if (currentDisplayLineCursor + (TFT_TEXT_HEIGHT * currentTextSize) > TFT_HEIGHT + 1)
{
currentDisplayLineCursor = 0;
TFT->fillRect(0, currentDisplayLineCursor, TFT_WIDTH, TFT_TEXT_HEIGHT * currentTextSize, ILI9341_BLACK);
}
TFT->setCursor(0, currentDisplayLineCursor);
}
#endif
void SerialDisplayPrint::print(byte data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
TFT->print(data);
#endif
if (device == Both || device == SerialOnly)
Serial->print(data);
}
void SerialDisplayPrint::print(short data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
TFT->print(data);
#endif
if (device == Both || device == SerialOnly)
Serial->print(data);
}
void SerialDisplayPrint::print(int data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
TFT->print(data);
#endif
if (device == Both || device == SerialOnly)
Serial->print(data);
}
void SerialDisplayPrint::print(unsigned long data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
TFT->print(data);
#endif
if (device == Both || device == SerialOnly)
Serial->print(data);
}
void SerialDisplayPrint::print(double data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
TFT->print(data);
#endif
if (device == Both || device == SerialOnly)
Serial->print(data);
}
void SerialDisplayPrint::print(char data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
TFT->print(data);
#endif
if (device == Both || device == SerialOnly)
Serial->print(data);
}
void SerialDisplayPrint::print(char *data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
TFT->print(data);
#endif
if (device == Both || device == SerialOnly)
Serial->print(data);
}
void SerialDisplayPrint::println(byte data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
{
TFT->print(data);
AdvanceToNextLineOnDisplay();
}
#endif
if (device == Both || device == SerialOnly)
Serial->println(data);
}
void SerialDisplayPrint::println(short data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
{
TFT->print(data);
AdvanceToNextLineOnDisplay();
}
#endif
if (device == Both || device == SerialOnly)
Serial->println(data);
}
void SerialDisplayPrint::println(int data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
{
TFT->print(data);
AdvanceToNextLineOnDisplay();
}
#endif
if (device == Both || device == SerialOnly)
Serial->println(data);
}
void SerialDisplayPrint::println(unsigned long data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
{
TFT->print(data);
AdvanceToNextLineOnDisplay();
}
#endif
if (device == Both || device == SerialOnly)
Serial->println(data);
}
void SerialDisplayPrint::println(double data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
{
TFT->print(data);
AdvanceToNextLineOnDisplay();
}
#endif
if (device == Both || device == SerialOnly)
Serial->println(data);
}
void SerialDisplayPrint::println(char *data, PrintDevice device)
{
#if ADAFRUIT_TFT_TOUCH_SHIELD
if (device == Both || device == DisplayOnly)
{
TFT->print(data);
AdvanceToNextLineOnDisplay();
}
#endif
if (device == Both || device == SerialOnly)
Serial->println(data);
}