-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainScreen.cpp
More file actions
196 lines (162 loc) · 4.39 KB
/
Copy pathMainScreen.cpp
File metadata and controls
196 lines (162 loc) · 4.39 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
#include "Globals.h"
#include "Utility.h"
#include "Menu.h"
extern int MakeRequestP(PGM_P Req, char* Resp, const int Len);
extern bool ParseM408S1(const char* Buffer, const int BytesRead);
static void MainScreen();
static PGM_P DecodeStatus(const char Code);
static void BedHeater(const int16_t x, const int16_t y, const bool On);
static void HotendHeater(const int16_t x, const int16_t y, const char Num, const bool On);
static void Heater(const int16_t x, const int16_t y, const char* current, const char* active, const char* standby);
void UpdateMain()
{
const int BytesRead = MakeRequestP(PSTR("M408 S0"), gSerialBuffer, sizeof(gSerialBuffer));
bool Redraw = false;
if (BytesRead)
{
if (ParseM408S1(gSerialBuffer, BytesRead))
{
Redraw = true;
}
else
{
DEBUG_PRINT_P("Bad parse");
}
}
else
{
#ifndef DEBUG_NO_DATA
gCurrentPage = PG_CONNECTING;
#endif
Redraw = true;
}
if (gFlags & FLAGS_ENC_SW)
{
gFlags &= ~FLAGS_ENC_SW;
gCurrentPage = PG_MENU1;
MENU_RESET();
}
if (Redraw)
{
gLCD.firstPage();
do
{
MainScreen();
}
while (gLCD.nextPage());
}
}
void MainScreen()
{
gLCD.setFont(u8g2_font_5x7_tr);
gLCD.drawStr(0, 7, gPrinterName);
PGM_P DecodedStatus = DecodeStatus(gStatusStr);
DrawStrP(128 - StrWidthP(DecodedStatus), 7, DecodedStatus);
gLCD.drawLine(0, 8, 128, 8);
BedHeater(12, 10, gData.MS.Heaters[0].Status == 2);// PanelDue only checks for 2
DrawStrP(0, 30, PSTR("C"));
DrawStrP(0, 37, PSTR("A"));
DrawStrP(0, 44, PSTR("S"));
for (unsigned char i = 0; i < gData.MS.HeaterCount; i++)
Heater(7 + 30 * i, 30, gData.MS.Heaters[i].Current, gData.MS.Heaters[i].Active, gData.MS.Heaters[i].Standby);
for (int i = 0; i < gNumTools; i++)
HotendHeater(40 + i * 28, 10, '1' + i, gData.MS.Tool == i);
if (gData.MS.FractionPrinted != NULL)
{
gLCD.setCursor(0,51);
if (gData.MS.FractionPrinted[0] != '0')
gLCD.print(gData.MS.FractionPrinted[0]);
if (gData.MS.FractionPrinted[2] != '0')
gLCD.print(gData.MS.FractionPrinted[2]);
if (isdigit(gData.MS.FractionPrinted[3]))
gLCD.print(gData.MS.FractionPrinted[3]);
else
gLCD.print('0');
gLCD.print('%');
}
gLCD.drawLine(0, 56, 128, 56);
//pos
DrawStrP(0, 64, PSTR("X"));
PrintFloat(gData.MS.Pos.X, 2, true);
DrawStrP(44, 64, PSTR("Y"));
PrintFloat(gData.MS.Pos.Y, 2, true);
DrawStrP(89, 64, PSTR("Z"));
PrintFloat(gData.MS.Pos.Z, 2, true);
}
PGM_P DecodeStatus(const char Code)
{
switch (Code)
{
case 'I':
return PSTR("Idle");
break;
case 'P':
return PSTR("Printing");
break;
case 'S':
return PSTR("Stopped");
break;
case 'C':
return PSTR("Booting");
break;
case 'A':
return PSTR("Paused");
break;
case 'R':
return PSTR("Resuming");
break;
case 'B':
return PSTR("Busy");
break;
case 'F':
return PSTR("Updating");
break;
default:
return PSTR("Unknown");
break;
}
}
void BedHeater(const int16_t x, const int16_t y, const bool On)
{
if (On)
{
gLCD.setFont(u8g2_font_unifont_t_76);
gLCD.drawGlyph(2 + x, 11 + y, 9832);
gLCD.setFont(u8g2_font_5x7_tr);
}
gLCD.drawBox(0 + x, 11 + y, 12, 2);
}
void HotendHeater(const int16_t x, const int16_t y, const char Num, const bool On)
{
//9929
if (On)
{
gLCD.setFont(u8g2_font_unifont_t_77);
gLCD.drawGlyph(0 + x, 13 + y, 9930);
gLCD.setFont(u8g2_font_5x7_tr);
gLCD.setDrawColor(0);
gLCD.setCursor(5 + x, 8 + y);
gLCD.print(Num);
//gLCD.drawStr(5 + x, 8 + y, Num);
gLCD.setDrawColor(1);
}
else
{
gLCD.setFont(u8g2_font_unifont_t_77);
gLCD.drawGlyph(0 + x, 13 + y, 9929);
gLCD.setFont(u8g2_font_5x7_tr);
//gLCD.drawStr(5 + x, 8 + y, Num);
gLCD.setCursor(5 + x, 8 + y);
gLCD.print(Num);
}
}
void Heater(const int16_t x, const int16_t y, const char* current, const char* active, const char* standby)
{
gLCD.setFont(u8g2_font_5x7_tr);
gLCD.setCursor(x, y);
PrintFloat(current, 1, false);
gLCD.setCursor(x, y + 7);
PrintFloat(active, 1, false);
gLCD.setCursor(x, y + 14);
PrintFloat(standby, 1, false);
}