Repository navigation
Expand file tree
/
Copy pathquickPRINT.cpp
More file actions
386 lines (322 loc) · 7.9 KB
/
Copy pathquickPRINT.cpp
File metadata and controls
386 lines (322 loc) · 7.9 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#include "quickPRINT.h"
void PrintHlpTime(byte hourIN, byte minIN, byte secIN){
DayTimeToStr(hourIN, minIN, secIN);
Serial.print(strHLP2);
}
void PrintHlpDate(byte dayIN, byte monthIN, uint16_t yearIN){
DateToStr(dayIN, monthIN, yearIN);
Serial.print(strHLP2);
}
void PrintSerTime(uint32_t timeIN, byte printDays, byte print){
// if "printDays" is set, '000d 00:00:00'
// else '00:00:00'
SerialDayTimeToStr(timeIN); // strHLP2 contains 00:00:00 - strHLP was used....
if (printDays){
uint32_t days = timeIN / 86400UL;
IntToIntStr(days, 3, ' '); // strHLP contains 000
memmove(&strHLP2[5], strHLP2, 9); // make space for "000d "
memcpy(strHLP2, strHLP, 3);
strHLP2[3] = 'd';
strHLP2[4] = ' ';
// Serial.print(strHLP);
// Serial.print(F("d "));
}
if (print){
Serial.print(strHLP2);
}
}
void PrintTime(){
PrintHlpTime(myHour, myMin, mySec);
}
void PrintRunTime(){
PrintSerTime(myRunTime, 1, 1);
}
void PrintDateTime(){
PrintHlpDate(myDay, myMonth, myYear);
Print1Space();
PrintHlpTime(myHour, myMin, mySec);
}
// Print char 'charToPrint' 'cnt' times
void PrintCharsCnt(char charToPrint, byte cnt){
while (cnt--){
Serial.print(charToPrint);
}
}
void PrintSpaces(byte cnt){
PrintCharsCnt(' ', cnt);
}
// Print One Space
void Print1Space(void){
PrintSpaces(1);
}
byte PrintLine(byte posY, byte posX, byte len){
if (posY && posX){
EscLocate(posX, posY++);
}
PrintCharsCnt('-', len);
return posY;
}
byte PrintDashLine(byte posY, byte posX, byte len){
if (posY && posX){
EscLocate(posX, posY++);
}
len /= 2;
while (len--){
Serial.print(F("- "));
}
return posY;
}
#if SMALL_GetUserVal
byte PrintBoldValue(long val, byte cntLeadingZeros, char leadingChar){
EscBold(1);
byte r = IntToIntStr(val, cntLeadingZeros, leadingChar);
Serial.print(strHLP);
EscBold(0);
return r;
}
#else
byte PrintValue(long val, byte cntLeadingZeros, byte cntDecimalPlaces, char leadingChar, byte bold){
byte r = 0;
EscBold(bold);
if (cntDecimalPlaces){
r = IntToFloatStr(val, cntLeadingZeros, cntDecimalPlaces, leadingChar);
}
else{
r = IntToIntStr(val, cntLeadingZeros, leadingChar);
}
Serial.print(strHLP);
EscBold(0);
return r;
}
#endif
void PrintErrorOK(int8_t err, byte len, char *strIN, byte addr){
// !! Bottom-Line of TUI !!
// Err: 0 = info, -1 = err, 1 = OK
// Err: 0 = black, -1 = red, 1 = green
//byte len = strlen(strIN) + 40;
if (!my.Boot){
// Terminal
EscInverse(1);
EscLocate(1,24);
if (err == -1){
// Error
EscColor(bgRed);
}
else if(err == 1){
// OK
EscColor(bgGreen);
}
else{
// Info
EscBold(1);
}
PrintSpaces(4);
//Serial.print(F(" "));
Serial.print(strIN);
EscBold(0);
EscColor(49);
Serial.print(F(" @ "));
Serial.print(addr);
PrintRunTime();
// c++ pointer shit...
if (!len){
// TAKE CARE
// if strIN is a char-array a la strHLP - we already have the len of strIN
// if not, function got called with a (char*)"BlaBlaBla"
len = strlen(strIN);
}
PrintSpaces(40 - len);
//for (int i = 0; i < len; i++){
//Print1Space();
//}
//PrintDateTime();
//Print1Space();
EscInverse(0);
//Serial.println("");
//Serial.println(strlen(strIN));
}
else if (my.Boot < 3){
// ModBus RTU & AscII
}
else{
// just values in case of an error
if (err == -1){
MBstart(my.Address);
iicStr[2] = 3; // Error
iicStr[3] = addr; // ID of probe
iicStr[4] = strIN[1]; // Error Code
MBstop(5);
}
}
}
void PrintCentered(char *strIN, byte centerLen){
byte spaces = centerLen - strlen(strIN);
byte frontSpaces = spaces / 2;
spaces -= frontSpaces;
PrintSpaces(frontSpaces);
Serial.print(strIN);
PrintSpaces(spaces);
}
byte PrintMenuTop(char *strIN){
EscCls();
EscColor(0);
EscInverse(1);
EscLocate(1, 1);
EscBold(1);
PrintCentered(strIN, 80);
EscBold(0);
EscInverse(0);
return 2;
}
void PrintMenuEnd(byte pos){
Serial.println(F("\n"));
Serial.print(F(" Select key, or Enter(for return)..."));
}
void PrintLoopTimes(){
// Print Runtime
EscLocate(67,1);
EscInverse(1);
PrintRunTime();
// Print Realtime
EscLocate(61,24);
PrintDateTime();
Serial.print(F(" "));
EscInverse(0);
}
void PrintMenuKey(char key, byte space, char leadChar, char trailChar, byte colon, byte bold, byte faint){
// "space" is a leading space - (as very 1st print)
// "key" is all time bold and underlined followed by a ')'
// "colon" ': ' (bold, underlined) is an option
// "leadChar" (bold, underlined) is an option
// "trailChar" (not bold, nor underlined) is an option
// "bold" sets bold on exit
// "faint" sets faint on exit
// if bold and faint is true... don't do ESCKeyStyle (Hack to get faint (or whatever) - see i.e. manual-menu QuickWater)
if (space){
Print1Space();
}
if (!(bold && faint)){
EscKeyStyle(1);
}
if (leadChar){
Serial.print(leadChar);
}
Serial.print(key);
Serial.print(F(")"));
if (colon){
Serial.print(F(":"));
}
EscBold(0);
EscUnder(0);
if (colon){
Print1Space();
}
if (trailChar){
Serial.print(trailChar);
}
EscColor(0);
if (bold && !faint){
EscBold(1);
}
else if (faint && !bold){
EscFaint(1);
}
}
void PrintMenuKeyStdBoldFaint(char key, byte bold, byte faint){
// "A): "
PrintMenuKey(key, 0, 0, 0, 1, bold, faint);
/*
PrintMenuKey((char)(ezo + 49), 0, '(', 0, 0, bold, !bold);
PrintMenuKey(i + 'o', 0, '(', ' ', 0, 1, 0);
PrintMenuKey(i + 'A', 1, '(', 0, 0, 0, 0);
PrintMenuKey(i + 'G', 1, '(', 0, 0, 0, 0);
*/
}
void PrintMenuKeyStd(char key){
// "A): "
PrintMenuKey(key, 0, 0, 0, 1, 0, 0);
}
void PrintMenuKeySmall(char key){
// "A) "
PrintMenuKey(key, 0, 0, ' ', 0, 0, 0);
}
void PrintMenuKeySmallBoldFaint(char key, byte bold, byte faint){
// "A) "
PrintMenuKey(key, 0, 0, ' ', 0, bold, faint);
}
void PrintMenuKeyBracketed(char key){
// " (A)"
PrintMenuKey(key, 1, '(', 0, 0, 0, 0);
}
void PrintOFF(void){
Serial.print(F("OFF"));
}
void PrintON(void){
Serial.print(F(" ON"));
}
void PrintTrue(void){
Serial.print(F(" True"));
}
void PrintFalse(void){
Serial.print(F("False"));
}
void PrintCharInSpaces(char charIN){
Print1Space();
Serial.print(charIN);
Print1Space();
}
void PrintSpacer(byte bold){
EscBold(0);
Serial.print(F(" | "));
if (bold){
EscBold(1);
}
}
void PrintHexByte(byte value){
Serial.print(value < 16 ? "0" : "");
Serial.print(value, HEX);
}
byte MBstart(byte address){
// Start a ModBUS message
// (re)misuse iicStr...
iicStr[0] = ':';
iicStr[1] = address;
return 2; // next pos in iicStr
}
void MBstop(byte pos){
// Finish a ModBUS message
byte lcr = 0;
Serial.print(":");
// Calc LCR - print message
for (byte i = 1; i < pos; i++){
lcr = lcr ^ iicStr[i];
PrintHexByte(iicStr[i]);
}
// print LCR
PrintHexByte(lcr);
// End message with crlf
Serial.print(F("\r\n"));
}
void MBaction(byte address, byte idPort, byte state, byte value){
MBstart(address);
iicStr[2] = 1; // Command ActionPort
iicStr[3] = idPort; // ID of port
iicStr[4] = state; // state of port
iicStr[5] = value;
MBstop(6);
}
void MBanalog(byte address, byte idProbe, byte idVal, int32_t value){
MBstart(address);
iicStr[2] = 2; // Command ActionPort
iicStr[3] = idProbe; // ID of port
iicStr[4] = idVal; // state of port
MBaddLong(value, 5);
MBstop(9);
}
byte MBaddLong(int32_t value, byte pos){
iicStr[pos++] = (uint8_t)((value >> 24) & 0xFF);
iicStr[pos++] = (uint8_t)((value >> 16) & 0xFF);
iicStr[pos++] = (uint8_t)((value >> 8) & 0xFF);
iicStr[pos++] = (uint8_t)(value & 0xFF);
return pos;
}