-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDcDisplay.cpp
More file actions
337 lines (281 loc) · 6.62 KB
/
Copy pathDcDisplay.cpp
File metadata and controls
337 lines (281 loc) · 6.62 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
#include "Arduino.h"
/***
* Project: Dolly Control
* File : DcDisplay.cpp
* Author : Werner Riemann
* Created: 10.05.2025
* Board: Arduino Nano
*
* Description: Method implementation for Class DcDisplay
*
* Pins:
*
* A4,A5 - I2C Display control (A4 - SDA, A5 - SCL)
*
*/
#include "DcDisplay.h"
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
char szVersion[17] = "[ V0.02 ]";
char szMenuSettings[9][11] = {
" Exit",
" Speed",
" Distance",
" Mode",
" Direction",
"StartDelay",
" Save",
" Version",
" Exit"
};
char szRunModNames[3][11] = {
"Manual Run",
" Automatic",
"AutoReturn"
};
char szRunModShort[3][11] = {
"Manual Run",
"Auto",
"ARet"
};
char szDirectionName[2][9] = {
" Forward",
"Backward"
};
char szDirectionNameShort[2][5] = {
"Fwd>",
"Bwd<"
};
DcDisplay::DcDisplay(/* args */)
{
}
void DcDisplay::Setup()
{
lcd.begin(16, 2);
lcd.clear();
}
void DcDisplay::SetVersion(const char *strVersion)
{
strcpy(szVersion, "[ V");
strcat(szVersion, strVersion);
strcat(szVersion, " ]");
}
void DcDisplay::SetBacklight(uint8_t mode)
{
lcd.setBacklight(mode);
}
void DcDisplay::BlinkOn()
{
lcd.blink();
}
void DcDisplay::BlinkOff()
{
lcd.noBlink();
}
void DcDisplay::CursorOn()
{
lcd.cursor();
}
void DcDisplay::CursorOff()
{
lcd.noCursor();
}
void DcDisplay::CursorPos(int x, int y)
{
lcd.setCursor(x,y);
}
void DcDisplay::PrintBatteryVoltage(uint8_t col, uint8_t row, int rawValue)
{
char szbuf[6];
float batteryVoltage = 5.00 / 1024 * rawValue;
dtostrf(batteryVoltage, 3, 2, szbuf);
lcd.setCursor(col,row);
lcd.print(" ");
lcd.setCursor(col,row);
lcd.print(szbuf);
}
void DcDisplay::PrintBatteryCapacity(uint8_t col, uint8_t row, int rawValue)
{
char szbuf[6] = "B";
char szval[4] ="";
uint8_t percentVal = 0;
float batteryVoltage = 5.00 / 1024 * rawValue;
if(batteryVoltage >= 4.15) percentVal = 100;
if(batteryVoltage >= 4.08 && batteryVoltage < 4.15) percentVal = 90;
if(batteryVoltage >= 3.98 && batteryVoltage < 4.08) percentVal = 80;
if(batteryVoltage >= 3.95 && batteryVoltage < 3.98) percentVal = 70;
if(batteryVoltage >= 3.9 && batteryVoltage < 3.95) percentVal = 60;
if(batteryVoltage >= 3.85 && batteryVoltage < 3.9) percentVal = 50;
if(batteryVoltage >= 3.8 && batteryVoltage < 3.85) percentVal = 40;
if(batteryVoltage >= 3.7 && batteryVoltage < 3.8) percentVal = 20;
if(batteryVoltage >= 3.6 && batteryVoltage < 3.7) percentVal = 10;
if(batteryVoltage < 3.6 ) percentVal = 0;
//dtostrf(batteryVoltage, 3, 1, szbuf);
itoa(percentVal, szval, 10);
if(percentVal < 100) strcat(szbuf, " ");
strcat(szbuf, szval);
strcat(szbuf, "%");
lcd.setCursor(col,row);
lcd.print(szbuf);
}
void DcDisplay::PrintSelectedMenuNo(int selctNo)
{
lcd.setCursor(5,0);
lcd.print(" ]");
lcd.setCursor(5,0);
lcd.print(szMenuSettings[selctNo -1]);
}
void DcDisplay::PrintMainRunInfo(int runMode, int direction, int speed, int distance)
{
char szbuf[6];
int l = 0;
lcd.setCursor(0,0);
lcd.print(szRunModShort[runMode-1]);
if(runMode > SCR_RUNMODE_MAN) // display distance only in Auto and ARet mode
{
itoa(distance, szbuf, 10);
l = strlen(szbuf);
lcd.setCursor(5 + 3-l,0);
lcd.print(szbuf);
lcd.print("cm");
}
// direction
lcd.setCursor(0,1);
lcd.print(szDirectionNameShort[direction]);
//speed
lcd.setCursor(5,1);
itoa(speed, szbuf, 10);
lcd.print(szbuf);
lcd.print("mms");
}
void DcDisplay::PrintParamInfo(int paramNo, int runMode, int direction, int speed, int distance, int startDelay, bool valueOnly)
{
char szbuf[6];
int l;
if(!valueOnly)
{
lcd.setCursor(0,1); // clear the value line
lcd.print(" ");
}
switch (paramNo)
{
case SCR_VAL_SPEED:
if(!valueOnly)
{
lcd.setCursor(12, 1);
lcd.print("mm/s");
}
itoa(speed, szbuf,10);
lcd.setCursor(9, 1);
lcd.print(szbuf);
lcd.setCursor(10, 1);
break;
case SCR_VAL_DISTANCE:
if(!valueOnly)
{
lcd.setCursor(14, 1);
lcd.print("cm");
}
itoa(distance, szbuf,10);
lcd.setCursor(10, 1);
lcd.print("000");
l = strlen(szbuf);
lcd.setCursor(13 - l, 1);
lcd.print(szbuf);
break;
case SCR_VAL_MODE:
lcd.setCursor(6, 1);
lcd.print(szRunModNames[runMode-1]);
lcd.setCursor(6, 1);
break;
case SCR_VAL_DIRECTION:
lcd.setCursor(8, 1);
lcd.print(szDirectionName[direction]);
lcd.setCursor(8, 1);
break;
case SCR_VAL_STARTDELAY:
if(!valueOnly)
{
lcd.setCursor(15, 1);
lcd.print("s");
}
itoa(startDelay, szbuf,10);
lcd.setCursor(14, 1);
lcd.print(szbuf);
lcd.setCursor(14, 1);
break;
}
}
void DcDisplay::SetEdDistanceCursorPosVal(int edDistanceModeNo, int value, bool withValue)
{
uint8_t xpos[4] = {0,10,11,12};
char szbuf[3];
itoa(value, szbuf,10);
if(withValue)
{
lcd.setCursor(xpos[edDistanceModeNo-1],1);
lcd.print(szbuf);
}
lcd.setCursor(xpos[edDistanceModeNo-1],1);
}
void DcDisplay::PrintEdDistanceExit()
{
lcd.setCursor(0,1);
lcd.print("RET");
lcd.setCursor(0,1);
}
void DcDisplay::PrintSaveDone()
{
lcd.setCursor(0,1);
lcd.print("-- SAVE DONE! --");
}
void DcDisplay::PrintVersion()
{
lcd.setCursor(0,1);
lcd.print(szVersion);
}
void DcDisplay::RunBlinkOn()
{
lcd.setCursor(3,1);
lcd.blink();
}
void DcDisplay::RunBlinkOff()
{
lcd.setCursor(3,1);
lcd.noBlink();
}
void DcDisplay::PrintCurRotationCount(int rotations)
{
char szbuf[6];
itoa(rotations, szbuf, 10);
lcd.setCursor(5,1);
lcd.print(" ");
lcd.setCursor(5,1);
lcd.print(szbuf);
}
void DcDisplay::ScreenOut(uint8_t uiScreenID)
{
lcd.clear();
lcd.setCursor(0,0); // start ist immer oben links
switch(uiScreenID)
{
case SCR_CLEAR:
lcd.clear();
break;
case SCR_WELCOME:
lcd.print("-Dolly Control-");
lcd.setCursor(0,1);
lcd.print(szVersion);
lcd.setCursor(4,1);
break;
case SCR_MAINRUN:
lcd.print(" |B %");
lcd.setCursor(0,1);
lcd.print(" | V");
break;
case SCR_SELMENU:
lcd.print("SEL [ ]");
lcd.setCursor(0,1);
lcd.print(" ");
break;
}
}