|
@@ -0,0 +1,853 @@
|
|
1
|
+/**
|
|
2
|
+ * Lightweight Status Screen for the RepRapDiscount Full
|
|
3
|
+ * Graphics Smart Controller (ST7920-based 128x64 LCD)
|
|
4
|
+ *
|
|
5
|
+ * (c) 2017 Aleph Objects, Inc.
|
|
6
|
+ *
|
|
7
|
+ * The code in this page is free software: you can
|
|
8
|
+ * redistribute it and/or modify it under the terms of the GNU
|
|
9
|
+ * General Public License (GNU GPL) as published by the Free Software
|
|
10
|
+ * Foundation, either version 3 of the License, or (at your option)
|
|
11
|
+ * any later version. The code is distributed WITHOUT ANY WARRANTY;
|
|
12
|
+ * without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13
|
+ * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
|
14
|
+ *
|
|
15
|
+ */
|
|
16
|
+
|
|
17
|
+/**
|
|
18
|
+ * Implementation of a Status Screen for the RepRapDiscount
|
|
19
|
+ * Full Graphics Smart Controller using native ST7920 commands
|
|
20
|
+ * instead of U8Glib.
|
|
21
|
+ *
|
|
22
|
+ * This alternative Status Screen makes use of the built-in character
|
|
23
|
+ * generation capabilities of the ST7920 to update the Status Screen
|
|
24
|
+ * with less SPI traffic and CPU use. In particular:
|
|
25
|
+ *
|
|
26
|
+ * - The fan and bed animations are handled using custom characters
|
|
27
|
+ * that are stored in CGRAM. This allows for the animation to be
|
|
28
|
+ * updated by writing a single character to the text-buffer (DDRAM).
|
|
29
|
+ *
|
|
30
|
+ * - All the information in the Status Screen is text that is written
|
|
31
|
+ * to DDRAM, so the work of generating the bitmaps is offloaded to
|
|
32
|
+ * the ST7920 rather than being render by U8Glib on the MCU.
|
|
33
|
+ *
|
|
34
|
+ * - The graphics buffer (GDRAM) is only used for static graphics
|
|
35
|
+ * elements (nozzle and feedrate bitmaps) and for the progress
|
|
36
|
+ * bar, so updates are sporadic.
|
|
37
|
+ */
|
|
38
|
+
|
|
39
|
+#include "status_screen_lite_ST7920_class.h"
|
|
40
|
+
|
|
41
|
+#include "../../libs/duration_t.h"
|
|
42
|
+
|
|
43
|
+#define BUFFER_WIDTH 256
|
|
44
|
+#define BUFFER_HEIGHT 32
|
|
45
|
+
|
|
46
|
+#define DDRAM_LINE_1 0x00
|
|
47
|
+#define DDRAM_LINE_2 0x10
|
|
48
|
+#define DDRAM_LINE_3 0x08
|
|
49
|
+#define DDRAM_LINE_4 0x18
|
|
50
|
+
|
|
51
|
+ST7920_Lite_Status_Screen::st7920_state_t ST7920_Lite_Status_Screen::current_bits;
|
|
52
|
+
|
|
53
|
+void ST7920_Lite_Status_Screen::cmd(const uint8_t cmd) {
|
|
54
|
+ if (!current_bits.synced || !current_bits.cmd) {
|
|
55
|
+ current_bits.synced = true;
|
|
56
|
+ current_bits.cmd = true;
|
|
57
|
+ sync_cmd();
|
|
58
|
+ }
|
|
59
|
+ write_byte(cmd);
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+void ST7920_Lite_Status_Screen::begin_data() {
|
|
63
|
+ if (!current_bits.synced || current_bits.cmd) {
|
|
64
|
+ current_bits.synced = true;
|
|
65
|
+ current_bits.cmd = false;
|
|
66
|
+ sync_dat();
|
|
67
|
+ }
|
|
68
|
+}
|
|
69
|
+
|
|
70
|
+void ST7920_Lite_Status_Screen::write_str(const char *str) {
|
|
71
|
+ while (*str) write_byte(*str++);
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+void ST7920_Lite_Status_Screen::write_str(const char *str, uint8_t len) {
|
|
75
|
+ while (*str && len--) write_byte(*str++);
|
|
76
|
+}
|
|
77
|
+
|
|
78
|
+void ST7920_Lite_Status_Screen::write_str_P(const char * const str) {
|
|
79
|
+ const char *p_str = (const char *)str;
|
|
80
|
+ while (char c = pgm_read_byte_near(p_str++)) write_byte(c);
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+void ST7920_Lite_Status_Screen::write_str(progmem_str str) {
|
|
84
|
+ write_str_P((const char*)str);
|
|
85
|
+}
|
|
86
|
+
|
|
87
|
+void ST7920_Lite_Status_Screen::write_number(const int16_t value, const uint8_t digits/*=3*/) {
|
|
88
|
+ char str[7];
|
|
89
|
+ const char *fmt;
|
|
90
|
+ switch (digits) {
|
|
91
|
+ case 6: fmt = PSTR("%6d"); break;
|
|
92
|
+ case 5: fmt = PSTR("%5d"); break;
|
|
93
|
+ case 4: fmt = PSTR("%4d"); break;
|
|
94
|
+ case 3: fmt = PSTR("%3d"); break;
|
|
95
|
+ case 2: fmt = PSTR("%2d"); break;
|
|
96
|
+ case 1: fmt = PSTR("%1d"); break;
|
|
97
|
+ }
|
|
98
|
+ sprintf_P(str, fmt, value);
|
|
99
|
+ write_str(str);
|
|
100
|
+}
|
|
101
|
+
|
|
102
|
+void ST7920_Lite_Status_Screen::display_status(const bool display_on, const bool cursor_on, const bool blink_on) {
|
|
103
|
+ extended_function_set(false);
|
|
104
|
+ cmd(0b00001000 |
|
|
105
|
+ (display_on ? 0b0100 : 0) |
|
|
106
|
+ (cursor_on ? 0b0010 : 0) |
|
|
107
|
+ (blink_on ? 0b0001 : 0)
|
|
108
|
+ );
|
|
109
|
+}
|
|
110
|
+
|
|
111
|
+// Sets the extended and graphics bits simultaneously, regardless of
|
|
112
|
+// the current state. This is a helper function for extended_function_set()
|
|
113
|
+// and graphics()
|
|
114
|
+void ST7920_Lite_Status_Screen::_extended_function_set(const bool extended, const bool graphics) {
|
|
115
|
+ cmd( 0b00100000 |
|
|
116
|
+ (extended ? 0b00000100 : 0) |
|
|
117
|
+ (graphics ? 0b00000010 : 0)
|
|
118
|
+ );
|
|
119
|
+ current_bits.extended = extended;
|
|
120
|
+ current_bits.graphics = graphics;
|
|
121
|
+}
|
|
122
|
+
|
|
123
|
+void ST7920_Lite_Status_Screen::extended_function_set(const bool extended) {
|
|
124
|
+ if (extended != current_bits.extended)
|
|
125
|
+ _extended_function_set(extended, current_bits.graphics);
|
|
126
|
+}
|
|
127
|
+
|
|
128
|
+void ST7920_Lite_Status_Screen::graphics(const bool graphics) {
|
|
129
|
+ if (graphics != current_bits.graphics)
|
|
130
|
+ _extended_function_set(current_bits.extended, graphics);
|
|
131
|
+}
|
|
132
|
+
|
|
133
|
+void ST7920_Lite_Status_Screen::entry_mode_select(const bool ac_increase, const bool shift) {
|
|
134
|
+ extended_function_set(false);
|
|
135
|
+ cmd(0b00000100 |
|
|
136
|
+ (ac_increase ? 0b00000010 : 0) |
|
|
137
|
+ (shift ? 0b00000001 : 0)
|
|
138
|
+ );
|
|
139
|
+}
|
|
140
|
+
|
|
141
|
+// Sets the sa bit regardless of the current state. This is a helper
|
|
142
|
+// function for scroll_or_addr_select()
|
|
143
|
+void ST7920_Lite_Status_Screen::_scroll_or_addr_select(const bool sa) {
|
|
144
|
+ extended_function_set(true);
|
|
145
|
+ cmd(0b00100010 |
|
|
146
|
+ (sa ? 0b000001 : 0)
|
|
147
|
+ );
|
|
148
|
+ current_bits.sa = sa;
|
|
149
|
+}
|
|
150
|
+
|
|
151
|
+void ST7920_Lite_Status_Screen::scroll_or_addr_select(const bool sa) {
|
|
152
|
+ if (sa != current_bits.sa)
|
|
153
|
+ _scroll_or_addr_select(sa);
|
|
154
|
+}
|
|
155
|
+
|
|
156
|
+void ST7920_Lite_Status_Screen::set_ddram_address(const uint8_t addr) {
|
|
157
|
+ extended_function_set(false);
|
|
158
|
+ cmd(0b10000000 | (addr & 0b00111111));
|
|
159
|
+}
|
|
160
|
+
|
|
161
|
+void ST7920_Lite_Status_Screen::set_cgram_address(const uint8_t addr) {
|
|
162
|
+ extended_function_set(false);
|
|
163
|
+ cmd(0b01000000 | (addr & 0b00111111));
|
|
164
|
+}
|
|
165
|
+
|
|
166
|
+void ST7920_Lite_Status_Screen::set_gdram_address(const uint8_t x, const uint8_t y) {
|
|
167
|
+ extended_function_set(true);
|
|
168
|
+ cmd(0b10000000 | (y & 0b01111111));
|
|
169
|
+ cmd(0b10000000 | (x & 0b00001111));
|
|
170
|
+}
|
|
171
|
+
|
|
172
|
+void ST7920_Lite_Status_Screen::clear() {
|
|
173
|
+ extended_function_set(false);
|
|
174
|
+ cmd(0x00000001);
|
|
175
|
+ delay(15); //delay for CGRAM clear
|
|
176
|
+}
|
|
177
|
+
|
|
178
|
+void ST7920_Lite_Status_Screen::home() {
|
|
179
|
+ extended_function_set(false);
|
|
180
|
+ cmd(0x00000010);
|
|
181
|
+}
|
|
182
|
+
|
|
183
|
+/* This fills the entire text buffer with spaces */
|
|
184
|
+void ST7920_Lite_Status_Screen::clear_ddram() {
|
|
185
|
+ set_ddram_address(DDRAM_LINE_1);
|
|
186
|
+ begin_data();
|
|
187
|
+ for (uint8_t i = 64; i--;) write_byte(' ');
|
|
188
|
+}
|
|
189
|
+
|
|
190
|
+/* This fills the entire graphics buffer with zeros */
|
|
191
|
+void ST7920_Lite_Status_Screen::clear_gdram() {
|
|
192
|
+ for (uint8_t y = 0; y < BUFFER_HEIGHT; y++) {
|
|
193
|
+ set_gdram_address(0, y);
|
|
194
|
+ begin_data();
|
|
195
|
+ for (uint8_t i = (BUFFER_WIDTH) / 16; i--;) write_word(0);
|
|
196
|
+ }
|
|
197
|
+}
|
|
198
|
+
|
|
199
|
+void ST7920_Lite_Status_Screen::load_cgram_icon(const uint16_t addr, const void *data) {
|
|
200
|
+ const uint16_t *p_word = (const uint16_t *)data;
|
|
201
|
+ set_cgram_address(addr);
|
|
202
|
+ begin_data();
|
|
203
|
+ for (uint8_t i = 16; i--;)
|
|
204
|
+ write_word(pgm_read_word_near(p_word++));
|
|
205
|
+}
|
|
206
|
+
|
|
207
|
+/**
|
|
208
|
+ * Draw an icon in GDRAM. Position specified in DDRAM
|
|
209
|
+ * coordinates. i.e., X from 1 to 8, Y from 1 to 4.
|
|
210
|
+ */
|
|
211
|
+void ST7920_Lite_Status_Screen::draw_gdram_icon(uint8_t x, uint8_t y, const void *data) {
|
|
212
|
+ const uint16_t *p_word = (const uint16_t *)data;
|
|
213
|
+ if (y > 2) { // Handle display folding
|
|
214
|
+ y -= 2;
|
|
215
|
+ x += 8;
|
|
216
|
+ }
|
|
217
|
+ --x;
|
|
218
|
+ --y;
|
|
219
|
+ for (int i = 0; i < 16; i++) {
|
|
220
|
+ set_gdram_address(x, i + y * 16);
|
|
221
|
+ begin_data();
|
|
222
|
+ write_word(pgm_read_word_near(p_word++));
|
|
223
|
+ }
|
|
224
|
+}
|
|
225
|
+
|
|
226
|
+/************************** ICON DEFINITIONS *************************************/
|
|
227
|
+
|
|
228
|
+#define CGRAM_ICON_1_ADDR 0x00
|
|
229
|
+#define CGRAM_ICON_2_ADDR 0x10
|
|
230
|
+#define CGRAM_ICON_3_ADDR 0x20
|
|
231
|
+#define CGRAM_ICON_4_ADDR 0x30
|
|
232
|
+
|
|
233
|
+#define CGRAM_ICON_1_WORD 0x00
|
|
234
|
+#define CGRAM_ICON_2_WORD 0x02
|
|
235
|
+#define CGRAM_ICON_3_WORD 0x04
|
|
236
|
+#define CGRAM_ICON_4_WORD 0x06
|
|
237
|
+
|
|
238
|
+const uint16_t nozzle_icon[] PROGMEM = {
|
|
239
|
+ 0b0000000000000000,
|
|
240
|
+ 0b0000000000000000,
|
|
241
|
+ 0b0000111111110000,
|
|
242
|
+ 0b0001111111111000,
|
|
243
|
+ 0b0001111111111000,
|
|
244
|
+ 0b0001111111111000,
|
|
245
|
+ 0b0000111111110000,
|
|
246
|
+ 0b0000111111110000,
|
|
247
|
+ 0b0001111111111000,
|
|
248
|
+ 0b0001111111111000,
|
|
249
|
+ 0b0001111111111000,
|
|
250
|
+ 0b0000011111100000,
|
|
251
|
+ 0b0000001111000000,
|
|
252
|
+ 0b0000000110000000,
|
|
253
|
+ 0b0000000000000000,
|
|
254
|
+ 0b0000000000000000
|
|
255
|
+};
|
|
256
|
+
|
|
257
|
+const uint16_t bed_icon[] PROGMEM = {
|
|
258
|
+ 0b0000000000000000,
|
|
259
|
+ 0b0000000000000000,
|
|
260
|
+ 0b0000000000000000,
|
|
261
|
+ 0b0000000000000000,
|
|
262
|
+ 0b0000000000000000,
|
|
263
|
+ 0b0000000000000000,
|
|
264
|
+ 0b0000000000000000,
|
|
265
|
+ 0b0000000000000000,
|
|
266
|
+ 0b0000000000000000,
|
|
267
|
+ 0b0000000000000000,
|
|
268
|
+ 0b0000000000000000,
|
|
269
|
+ 0b0111111111111110,
|
|
270
|
+ 0b0111111111111110,
|
|
271
|
+ 0b0110000000000110,
|
|
272
|
+ 0b0000000000000000,
|
|
273
|
+ 0b0000000000000000
|
|
274
|
+};
|
|
275
|
+
|
|
276
|
+const uint16_t heat1_icon[] PROGMEM = {
|
|
277
|
+ 0b0000000000000000,
|
|
278
|
+ 0b0010001000100000,
|
|
279
|
+ 0b0001000100010000,
|
|
280
|
+ 0b0000100010001000,
|
|
281
|
+ 0b0000100010001000,
|
|
282
|
+ 0b0001000100010000,
|
|
283
|
+ 0b0010001000100000,
|
|
284
|
+ 0b0010001000100000,
|
|
285
|
+ 0b0001000100010000,
|
|
286
|
+ 0b0000100010001000,
|
|
287
|
+ 0b0000000000000000,
|
|
288
|
+ 0b0000000000000000,
|
|
289
|
+ 0b0000000000000000,
|
|
290
|
+ 0b0000000000000000,
|
|
291
|
+ 0b0000000000000000,
|
|
292
|
+ 0b0000000000000000
|
|
293
|
+};
|
|
294
|
+
|
|
295
|
+const uint16_t heat2_icon[] PROGMEM = {
|
|
296
|
+ 0b0000000000000000,
|
|
297
|
+ 0b0000100010001000,
|
|
298
|
+ 0b0000100010001000,
|
|
299
|
+ 0b0001000100010000,
|
|
300
|
+ 0b0010001000100000,
|
|
301
|
+ 0b0010001000100000,
|
|
302
|
+ 0b0001000100010000,
|
|
303
|
+ 0b0000100010001000,
|
|
304
|
+ 0b0000100010001000,
|
|
305
|
+ 0b0001000100010000,
|
|
306
|
+ 0b0000000000000000,
|
|
307
|
+ 0b0000000000000000,
|
|
308
|
+ 0b0000000000000000,
|
|
309
|
+ 0b0000000000000000,
|
|
310
|
+ 0b0000000000000000,
|
|
311
|
+ 0b0000000000000000
|
|
312
|
+};
|
|
313
|
+
|
|
314
|
+const uint16_t fan1_icon[] PROGMEM = {
|
|
315
|
+ 0b0000000000000000,
|
|
316
|
+ 0b0111111111111110,
|
|
317
|
+ 0b0111000000001110,
|
|
318
|
+ 0b0110001111000110,
|
|
319
|
+ 0b0100001111000010,
|
|
320
|
+ 0b0100000110000010,
|
|
321
|
+ 0b0101100000011010,
|
|
322
|
+ 0b0101110110111010,
|
|
323
|
+ 0b0101100000011010,
|
|
324
|
+ 0b0100000110000010,
|
|
325
|
+ 0b0100001111000010,
|
|
326
|
+ 0b0110001111000110,
|
|
327
|
+ 0b0111000000001110,
|
|
328
|
+ 0b0111111111111110,
|
|
329
|
+ 0b0000000000000000,
|
|
330
|
+ 0b0000000000000000
|
|
331
|
+};
|
|
332
|
+
|
|
333
|
+const uint16_t fan2_icon[] PROGMEM = {
|
|
334
|
+ 0b0000000000000000,
|
|
335
|
+ 0b0111111111111110,
|
|
336
|
+ 0b0111000000001110,
|
|
337
|
+ 0b0110010000100110,
|
|
338
|
+ 0b0100111001110010,
|
|
339
|
+ 0b0101111001111010,
|
|
340
|
+ 0b0100110000110010,
|
|
341
|
+ 0b0100000110000010,
|
|
342
|
+ 0b0100110000110010,
|
|
343
|
+ 0b0101111001111010,
|
|
344
|
+ 0b0100111001110010,
|
|
345
|
+ 0b0110010000100110,
|
|
346
|
+ 0b0111000000001110,
|
|
347
|
+ 0b0111111111111110,
|
|
348
|
+ 0b0000000000000000,
|
|
349
|
+ 0b0000000000000000
|
|
350
|
+};
|
|
351
|
+
|
|
352
|
+const uint16_t feedrate_icon[] PROGMEM = {
|
|
353
|
+ 0b0000000000000000,
|
|
354
|
+ 0b0111111000000000,
|
|
355
|
+ 0b0100000000000000,
|
|
356
|
+ 0b0100000000000000,
|
|
357
|
+ 0b0100000000000000,
|
|
358
|
+ 0b0111111011111000,
|
|
359
|
+ 0b0100000010000100,
|
|
360
|
+ 0b0100000010000100,
|
|
361
|
+ 0b0100000010000100,
|
|
362
|
+ 0b0100000011111000,
|
|
363
|
+ 0b0000000010001000,
|
|
364
|
+ 0b0000000010000100,
|
|
365
|
+ 0b0000000010000100,
|
|
366
|
+ 0b0000000010000010,
|
|
367
|
+ 0b0000000000000000,
|
|
368
|
+ 0b0000000000000000
|
|
369
|
+};
|
|
370
|
+
|
|
371
|
+/************************** MAIN SCREEN *************************************/
|
|
372
|
+
|
|
373
|
+void ST7920_Lite_Status_Screen::draw_static_elements() {
|
|
374
|
+ scroll_or_addr_select(0);
|
|
375
|
+
|
|
376
|
+ // Load the animated bed and fan icons
|
|
377
|
+ load_cgram_icon(CGRAM_ICON_1_ADDR, heat1_icon);
|
|
378
|
+ load_cgram_icon(CGRAM_ICON_2_ADDR, heat2_icon);
|
|
379
|
+ load_cgram_icon(CGRAM_ICON_3_ADDR, fan1_icon);
|
|
380
|
+ load_cgram_icon(CGRAM_ICON_4_ADDR, fan2_icon);
|
|
381
|
+
|
|
382
|
+ // Draw the static icons in GDRAM
|
|
383
|
+ draw_gdram_icon(1, 1, nozzle_icon);
|
|
384
|
+ #if EXTRUDERS == 2
|
|
385
|
+ draw_gdram_icon(1,2,nozzle_icon);
|
|
386
|
+ draw_gdram_icon(1,3,bed_icon);
|
|
387
|
+ #else
|
|
388
|
+ draw_gdram_icon(1,2,bed_icon);
|
|
389
|
+ #endif
|
|
390
|
+ draw_gdram_icon(6,2,feedrate_icon);
|
|
391
|
+
|
|
392
|
+ // Draw the initial fan icon
|
|
393
|
+ draw_fan_icon(false);
|
|
394
|
+}
|
|
395
|
+
|
|
396
|
+/**
|
|
397
|
+ * Although this is undocumented, the ST7920 allows the character
|
|
398
|
+ * data buffer (DDRAM) to be used in conjunction with the graphics
|
|
399
|
+ * bitmap buffer (CGRAM). The contents of the graphics buffer is
|
|
400
|
+ * XORed with the data from the character generator. This allows
|
|
401
|
+ * us to make the progess bar out of graphical data (the bar) and
|
|
402
|
+ * text data (the percentage).
|
|
403
|
+ */
|
|
404
|
+void ST7920_Lite_Status_Screen::draw_progress_bar(const uint8_t value) {
|
|
405
|
+ #if EXTRUDERS == 1
|
|
406
|
+ // If we have only one extruder, draw a long progress bar on the third line
|
|
407
|
+ const uint8_t top = 1, // Top in pixels
|
|
408
|
+ bottom = 13, // Bottom in pixels
|
|
409
|
+ left = 8, // Left edge, in 16-bit words
|
|
410
|
+ width = 5; // Width of progress bar, in 16-bit words
|
|
411
|
+ #else
|
|
412
|
+ const uint8_t top = 16 + 1, // Top in pixels
|
|
413
|
+ bottom = 16 + 13, // Bottom in pixels
|
|
414
|
+ left = 5, // Left edge, in 16-bit words
|
|
415
|
+ width = 3; // Width of progress bar, in 16-bit words
|
|
416
|
+ #endif
|
|
417
|
+ const uint8_t char_pcnt = 100 / width; // How many percent does each 16-bit word represent?
|
|
418
|
+
|
|
419
|
+ // Draw the progress bar as a bitmap in CGRAM
|
|
420
|
+ for (uint8_t y = top; y <= bottom; y++) {
|
|
421
|
+ set_gdram_address(left, y);
|
|
422
|
+ begin_data();
|
|
423
|
+ for (uint8_t x = 0; x < width; x++) {
|
|
424
|
+ uint16_t gfx_word = 0x0000;
|
|
425
|
+ if ((x + 1) * char_pcnt <= value)
|
|
426
|
+ gfx_word = 0xFFFF; // Draw completely filled bytes
|
|
427
|
+ else if ((x * char_pcnt) < value)
|
|
428
|
+ gfx_word = int(0x8000) >> (value % char_pcnt) * 16 / char_pcnt; // Draw partially filled bytes
|
|
429
|
+
|
|
430
|
+ // Draw the frame around the progress bar
|
|
431
|
+ if (y == top || y == bottom)
|
|
432
|
+ gfx_word = 0xFFFF; // Draw top/bottom border
|
|
433
|
+ else if (x == width - 1)
|
|
434
|
+ gfx_word |= 0x0001; // Draw right border
|
|
435
|
+ else if (x == 0)
|
|
436
|
+ gfx_word |= 0x8000; // Draw left border
|
|
437
|
+ write_word(gfx_word);
|
|
438
|
+ }
|
|
439
|
+ }
|
|
440
|
+
|
|
441
|
+ // Draw the percentage as text in DDRAM
|
|
442
|
+ set_ddram_address(
|
|
443
|
+ #if EXTRUDERS == 1
|
|
444
|
+ DDRAM_LINE_3 + 1
|
|
445
|
+ #else
|
|
446
|
+ DDRAM_LINE_2 + left
|
|
447
|
+ #endif
|
|
448
|
+ );
|
|
449
|
+
|
|
450
|
+ begin_data();
|
|
451
|
+ if (value > 9) {
|
|
452
|
+ write_number(value, 4);
|
|
453
|
+ write_str(F("% "));
|
|
454
|
+ }
|
|
455
|
+ else {
|
|
456
|
+ write_number(value, 3);
|
|
457
|
+ write_str(F("% "));
|
|
458
|
+ }
|
|
459
|
+}
|
|
460
|
+
|
|
461
|
+void ST7920_Lite_Status_Screen::draw_fan_icon(const bool whichIcon) {
|
|
462
|
+ set_ddram_address(DDRAM_LINE_1 + 5);
|
|
463
|
+ begin_data();
|
|
464
|
+ write_word(whichIcon ? CGRAM_ICON_3_WORD : CGRAM_ICON_4_WORD);
|
|
465
|
+}
|
|
466
|
+
|
|
467
|
+void ST7920_Lite_Status_Screen::draw_heat_icon(const bool whichIcon, const bool heating) {
|
|
468
|
+ set_ddram_address(
|
|
469
|
+ #if EXTRUDERS == 1
|
|
470
|
+ DDRAM_LINE_2
|
|
471
|
+ #else
|
|
472
|
+ DDRAM_LINE_3
|
|
473
|
+ #endif
|
|
474
|
+ );
|
|
475
|
+ begin_data();
|
|
476
|
+ if (heating)
|
|
477
|
+ write_word(whichIcon ? CGRAM_ICON_1_WORD : CGRAM_ICON_2_WORD);
|
|
478
|
+ else {
|
|
479
|
+ write_byte(' ');
|
|
480
|
+ write_byte(' ');
|
|
481
|
+ }
|
|
482
|
+}
|
|
483
|
+
|
|
484
|
+#define FAR(a,b) (((a > b) ? (a-b) : (b-a)) > 1)
|
|
485
|
+
|
|
486
|
+void ST7920_Lite_Status_Screen::draw_extruder_1_temp(const int16_t temp, const int16_t target) {
|
|
487
|
+ set_ddram_address(DDRAM_LINE_1 + 1);
|
|
488
|
+ begin_data();
|
|
489
|
+ write_number(temp);
|
|
490
|
+ if (target && FAR(temp, target)) {
|
|
491
|
+ write_str(F("\x1A"));
|
|
492
|
+ write_number(target);
|
|
493
|
+ }
|
|
494
|
+ else
|
|
495
|
+ write_str(F(" "));
|
|
496
|
+}
|
|
497
|
+
|
|
498
|
+void ST7920_Lite_Status_Screen::draw_extruder_2_temp(const int16_t temp, const int16_t target) {
|
|
499
|
+ set_ddram_address(DDRAM_LINE_2 + 1);
|
|
500
|
+ begin_data();
|
|
501
|
+ write_number(temp);
|
|
502
|
+ if (target && FAR(temp, target)) {
|
|
503
|
+ write_str(F("\x1A"));
|
|
504
|
+ write_number(target);
|
|
505
|
+ }
|
|
506
|
+ else
|
|
507
|
+ write_str(F(" "));
|
|
508
|
+}
|
|
509
|
+
|
|
510
|
+void ST7920_Lite_Status_Screen::draw_bed_temp(const int16_t temp, const int16_t target) {
|
|
511
|
+ set_ddram_address(
|
|
512
|
+ #if EXTRUDERS == 1
|
|
513
|
+ DDRAM_LINE_2 + 1
|
|
514
|
+ #else
|
|
515
|
+ DDRAM_LINE_3 + 1
|
|
516
|
+ #endif
|
|
517
|
+ );
|
|
518
|
+ begin_data();
|
|
519
|
+ write_number(temp);
|
|
520
|
+ if (target && FAR(temp, target)) {
|
|
521
|
+ write_str(F("\x1A"));
|
|
522
|
+ write_number(target);
|
|
523
|
+ }
|
|
524
|
+ else
|
|
525
|
+ write_str(F(" "));
|
|
526
|
+}
|
|
527
|
+
|
|
528
|
+void ST7920_Lite_Status_Screen::draw_fan_speed(const uint8_t value) {
|
|
529
|
+ set_ddram_address(DDRAM_LINE_1 + 6);
|
|
530
|
+ begin_data();
|
|
531
|
+ write_number(value, 4);
|
|
532
|
+}
|
|
533
|
+
|
|
534
|
+void ST7920_Lite_Status_Screen::draw_print_time(const uint32_t elapsed) {
|
|
535
|
+ const uint8_t hrs = elapsed / 3600,
|
|
536
|
+ min = (elapsed / 60) % 60;
|
|
537
|
+ char str[7];
|
|
538
|
+ sprintf_P(str, hrs > 99 ? PSTR("%03d:%02d") : PSTR(" %02d:%02d"), hrs, min);
|
|
539
|
+
|
|
540
|
+ set_ddram_address(DDRAM_LINE_3 + 5);
|
|
541
|
+ begin_data();
|
|
542
|
+ write_str(str);
|
|
543
|
+}
|
|
544
|
+
|
|
545
|
+void ST7920_Lite_Status_Screen::draw_feedrate_percentage(const uint8_t percentage) {
|
|
546
|
+ // We only have enough room for the feedrate when
|
|
547
|
+ // we have one extruder
|
|
548
|
+ #if EXTRUDERS == 1
|
|
549
|
+ set_ddram_address(DDRAM_LINE_2 + 6);
|
|
550
|
+ begin_data();
|
|
551
|
+ write_number(percentage, 4);
|
|
552
|
+ #endif
|
|
553
|
+}
|
|
554
|
+
|
|
555
|
+void ST7920_Lite_Status_Screen::draw_status_message(const char *str) {
|
|
556
|
+ set_ddram_address(DDRAM_LINE_4);
|
|
557
|
+ begin_data();
|
|
558
|
+ #if ENABLED(STATUS_MESSAGE_SCROLLING)
|
|
559
|
+ const uint8_t lcd_len = 16;
|
|
560
|
+ const uint8_t padding = 2;
|
|
561
|
+ uint8_t str_len = strlen(str);
|
|
562
|
+
|
|
563
|
+ // Trim whitespace at the end of the str, as for some reason
|
|
564
|
+ // messages like "Card Inserted" are padded with many spaces
|
|
565
|
+ while (str_len > 0 && str[str_len - 1] == ' ') str_len--;
|
|
566
|
+
|
|
567
|
+ if (str_len <= lcd_len) {
|
|
568
|
+ // It all fits on the LCD without scrolling
|
|
569
|
+ write_str(str);
|
|
570
|
+ }
|
|
571
|
+ else {
|
|
572
|
+ // Print the message repeatedly until covering the LCD
|
|
573
|
+ uint8_t c = status_scroll_pos;
|
|
574
|
+ for (uint8_t n = 0; n < lcd_len; n++) {
|
|
575
|
+ write_byte(c < str_len ? str[c] : ' ');
|
|
576
|
+ c++;
|
|
577
|
+ c %= str_len + padding; // Wrap around
|
|
578
|
+ }
|
|
579
|
+
|
|
580
|
+ // Scroll the message
|
|
581
|
+ if (status_scroll_pos == str_len + padding)
|
|
582
|
+ status_scroll_pos = 0;
|
|
583
|
+ else
|
|
584
|
+ status_scroll_pos++;
|
|
585
|
+ }
|
|
586
|
+ #else
|
|
587
|
+ write_str(str, 16);
|
|
588
|
+ #endif
|
|
589
|
+}
|
|
590
|
+
|
|
591
|
+void ST7920_Lite_Status_Screen::draw_position(const float x, const float y, const float z, bool position_known) {
|
|
592
|
+ char str[7];
|
|
593
|
+ set_ddram_address(DDRAM_LINE_4);
|
|
594
|
+ begin_data();
|
|
595
|
+
|
|
596
|
+ // If position is unknown, flash the labels.
|
|
597
|
+ const unsigned char alt_label = position_known ? 0 : (lcd_blink() ? ' ' : 0);
|
|
598
|
+
|
|
599
|
+ dtostrf(x, -4, 0, str);
|
|
600
|
+ write_byte(alt_label ? alt_label : 'X');
|
|
601
|
+ write_str(str, 4);
|
|
602
|
+
|
|
603
|
+ dtostrf(y, -4, 0, str);
|
|
604
|
+ write_byte(alt_label ? alt_label : 'Y');
|
|
605
|
+ write_str(str, 4);
|
|
606
|
+
|
|
607
|
+ dtostrf(z, -5, 1, str);
|
|
608
|
+ write_byte(alt_label ? alt_label : 'Z');
|
|
609
|
+ write_str(str, 5);
|
|
610
|
+}
|
|
611
|
+
|
|
612
|
+bool ST7920_Lite_Status_Screen::indicators_changed() {
|
|
613
|
+ // We only add the target temperatures to the checksum
|
|
614
|
+ // because the actual temps fluctuate so by updating
|
|
615
|
+ // them only during blinks we gain a bit of stability.
|
|
616
|
+ const bool blink = lcd_blink();
|
|
617
|
+ const uint8_t feedrate_perc = feedrate_percentage;
|
|
618
|
+ const uint8_t fan_speed = ((fanSpeeds[0] + 1) * 100) / 256;
|
|
619
|
+ const float extruder_1_target = thermalManager.degTargetHotend(0);
|
|
620
|
+ #if EXTRUDERS == 2
|
|
621
|
+ const float extruder_2_target = thermalManager.degTargetHotend(1);
|
|
622
|
+ #endif
|
|
623
|
+ const float bed_target = thermalManager.degTargetBed();
|
|
624
|
+
|
|
625
|
+ static uint8_t last_checksum = 0;
|
|
626
|
+
|
|
627
|
+ const uint8_t checksum =
|
|
628
|
+ uint8_t(blink) ^
|
|
629
|
+ uint8_t(feedrate_perc) ^
|
|
630
|
+ uint8_t(fan_speed) ^
|
|
631
|
+ uint8_t(extruder_1_target) ^
|
|
632
|
+ #if EXTRUDERS == 2
|
|
633
|
+ uint8_t(extruder_2_target) ^
|
|
634
|
+ #endif
|
|
635
|
+ uint8_t(bed_target);
|
|
636
|
+
|
|
637
|
+ if (last_checksum == checksum) return false;
|
|
638
|
+
|
|
639
|
+ last_checksum = checksum;
|
|
640
|
+ return true;
|
|
641
|
+}
|
|
642
|
+
|
|
643
|
+void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) {
|
|
644
|
+ if (forceUpdate || indicators_changed()) {
|
|
645
|
+ const bool blink = lcd_blink();
|
|
646
|
+ const duration_t elapsed = print_job_timer.duration();
|
|
647
|
+ const uint32_t seconds_elapsed = elapsed.value;
|
|
648
|
+ const uint8_t feedrate_perc = feedrate_percentage;
|
|
649
|
+ const uint8_t fan_speed = ((fanSpeeds[0] + 1) * 100) / 256;
|
|
650
|
+ const float extruder_1_temp = thermalManager.degHotend(0);
|
|
651
|
+ const float extruder_1_target = thermalManager.degTargetHotend(0);
|
|
652
|
+ #if EXTRUDERS == 2
|
|
653
|
+ const float extruder_2_temp = thermalManager.degHotend(1);
|
|
654
|
+ const float extruder_2_target = thermalManager.degTargetHotend(1);
|
|
655
|
+ #endif
|
|
656
|
+ const float bed_temp = thermalManager.degBed();
|
|
657
|
+ const float bed_target = thermalManager.degTargetBed();
|
|
658
|
+
|
|
659
|
+ draw_extruder_1_temp(extruder_1_temp, extruder_1_target);
|
|
660
|
+ #if EXTRUDERS == 2
|
|
661
|
+ draw_extruder_2_temp(extruder_2_temp, extruder_2_target);
|
|
662
|
+ #endif
|
|
663
|
+ draw_bed_temp(bed_temp, bed_target);
|
|
664
|
+ draw_fan_speed(fan_speed);
|
|
665
|
+ draw_print_time(seconds_elapsed);
|
|
666
|
+ draw_feedrate_percentage(feedrate_perc);
|
|
667
|
+
|
|
668
|
+ // Update the fan and bed animations
|
|
669
|
+ if (fan_speed > 0) draw_fan_icon(blink);
|
|
670
|
+ if (bed_target > 0)
|
|
671
|
+ draw_heat_icon(blink, true);
|
|
672
|
+ else
|
|
673
|
+ draw_heat_icon(false, false);
|
|
674
|
+ }
|
|
675
|
+}
|
|
676
|
+
|
|
677
|
+bool ST7920_Lite_Status_Screen::position_changed() {
|
|
678
|
+ const float x_pos = current_position[X_AXIS],
|
|
679
|
+ y_pos = current_position[Y_AXIS],
|
|
680
|
+ z_pos = current_position[Z_AXIS];
|
|
681
|
+ const uint8_t checksum = uint8_t(x_pos) ^ uint8_t(y_pos) ^ uint8_t(z_pos);
|
|
682
|
+
|
|
683
|
+ static uint8_t last_checksum = 0;
|
|
684
|
+ if (last_checksum == checksum) return false;
|
|
685
|
+ last_checksum = checksum;
|
|
686
|
+ return true;
|
|
687
|
+}
|
|
688
|
+
|
|
689
|
+bool ST7920_Lite_Status_Screen::status_changed() {
|
|
690
|
+ uint8_t checksum = 0;
|
|
691
|
+ for (const char *p = lcd_status_message; *p; p++) checksum ^= *p;
|
|
692
|
+
|
|
693
|
+ static uint8_t last_checksum = 0;
|
|
694
|
+ if (last_checksum == checksum) return false;
|
|
695
|
+ last_checksum = checksum;
|
|
696
|
+ return true;
|
|
697
|
+}
|
|
698
|
+
|
|
699
|
+bool ST7920_Lite_Status_Screen::blink_changed() {
|
|
700
|
+ static uint8_t last_blink = 0;
|
|
701
|
+ const bool blink = lcd_blink();
|
|
702
|
+ if (last_blink == blink) return false;
|
|
703
|
+ last_blink = blink;
|
|
704
|
+ return true;
|
|
705
|
+}
|
|
706
|
+
|
|
707
|
+void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
|
|
708
|
+ static uint8_t countdown = 0;
|
|
709
|
+
|
|
710
|
+ /**
|
|
711
|
+ * There is only enough room in the display for either the
|
|
712
|
+ * status message or the position, not both, so we choose
|
|
713
|
+ * one or another. Whenever the status message changes,
|
|
714
|
+ * we show it for a number of consecutive seconds, but
|
|
715
|
+ * then go back to showing the position as soon as the
|
|
716
|
+ * head moves, i.e:
|
|
717
|
+ *
|
|
718
|
+ * countdown > 1 -- Show status
|
|
719
|
+ * countdown = 1 -- Show status, until movement
|
|
720
|
+ * countdown = 0 -- Show position
|
|
721
|
+ */
|
|
722
|
+ if (forceUpdate || status_changed()) {
|
|
723
|
+ #if ENABLED(STATUS_MESSAGE_SCROLLING)
|
|
724
|
+ status_scroll_pos = 0;
|
|
725
|
+ #endif
|
|
726
|
+ #ifndef STATUS_EXPIRE_SECONDS
|
|
727
|
+ #define STATUS_EXPIRE_SECONDS 20
|
|
728
|
+ #endif
|
|
729
|
+ countdown = lcd_strlen(lcd_status_message) ? STATUS_EXPIRE_SECONDS : 0;
|
|
730
|
+ draw_status_message(lcd_status_message);
|
|
731
|
+ blink_changed(); // Clear changed flag
|
|
732
|
+ }
|
|
733
|
+ else if (countdown > 1 && blink_changed()) {
|
|
734
|
+ countdown--;
|
|
735
|
+ #if ENABLED(STATUS_MESSAGE_SCROLLING)
|
|
736
|
+ draw_status_message(lcd_status_message);
|
|
737
|
+ #endif
|
|
738
|
+ }
|
|
739
|
+ else if (countdown > 0 && blink_changed()) {
|
|
740
|
+ if (position_changed()) {
|
|
741
|
+ countdown--;
|
|
742
|
+ forceUpdate = true;
|
|
743
|
+ }
|
|
744
|
+ #if ENABLED(STATUS_MESSAGE_SCROLLING)
|
|
745
|
+ draw_status_message(lcd_status_message);
|
|
746
|
+ #endif
|
|
747
|
+ }
|
|
748
|
+ if (countdown == 0 && (forceUpdate || position_changed() ||
|
|
749
|
+ #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
|
|
750
|
+ blink_changed()
|
|
751
|
+ #endif
|
|
752
|
+ )) {
|
|
753
|
+ draw_position(
|
|
754
|
+ current_position[X_AXIS],
|
|
755
|
+ current_position[Y_AXIS],
|
|
756
|
+ current_position[Z_AXIS],
|
|
757
|
+ #if ENABLED(DISABLE_REDUCED_ACCURACY_WARNING)
|
|
758
|
+ true
|
|
759
|
+ #else
|
|
760
|
+ axis_known_position[X_AXIS] &&
|
|
761
|
+ axis_known_position[Y_AXIS] &&
|
|
762
|
+ axis_known_position[Z_AXIS]
|
|
763
|
+ #endif
|
|
764
|
+ );
|
|
765
|
+ }
|
|
766
|
+}
|
|
767
|
+
|
|
768
|
+void ST7920_Lite_Status_Screen::update_progress(const bool forceUpdate) {
|
|
769
|
+ const uint8_t percent_done =
|
|
770
|
+ #if ENABLED(SDSUPPORT)
|
|
771
|
+ card.percentDone()
|
|
772
|
+ #else
|
|
773
|
+ 0
|
|
774
|
+ #endif
|
|
775
|
+ ;
|
|
776
|
+
|
|
777
|
+ // Since the progress bar involves writing
|
|
778
|
+ // quite a few bytes to GDRAM, only do this
|
|
779
|
+ // when an update is actually necessary.
|
|
780
|
+
|
|
781
|
+ static uint8_t last_progress = 0;
|
|
782
|
+ if (!forceUpdate && last_progress == percent_done) return;
|
|
783
|
+ last_progress = percent_done;
|
|
784
|
+
|
|
785
|
+ draw_progress_bar(percent_done);
|
|
786
|
+}
|
|
787
|
+
|
|
788
|
+void ST7920_Lite_Status_Screen::update(const bool forceUpdate) {
|
|
789
|
+ cs();
|
|
790
|
+ update_indicators(forceUpdate);
|
|
791
|
+ update_status_or_position(forceUpdate);
|
|
792
|
+ update_progress(forceUpdate);
|
|
793
|
+ ncs();
|
|
794
|
+}
|
|
795
|
+
|
|
796
|
+void ST7920_Lite_Status_Screen::reset_state_from_unknown() {
|
|
797
|
+ _extended_function_set(true, true); // Do it twice as only one bit
|
|
798
|
+ _extended_function_set(true, true); // get set at a time.
|
|
799
|
+ _scroll_or_addr_select(false);
|
|
800
|
+}
|
|
801
|
+
|
|
802
|
+void ST7920_Lite_Status_Screen::on_entry() {
|
|
803
|
+ cs();
|
|
804
|
+ reset_state_from_unknown();
|
|
805
|
+ clear();
|
|
806
|
+ clear_gdram();
|
|
807
|
+ draw_static_elements();
|
|
808
|
+ update(true);
|
|
809
|
+ ncs();
|
|
810
|
+}
|
|
811
|
+
|
|
812
|
+void ST7920_Lite_Status_Screen::on_exit() {
|
|
813
|
+ cs();
|
|
814
|
+ clear();
|
|
815
|
+ _extended_function_set(true, true); // Restore state to what u8g expects.
|
|
816
|
+ ncs();
|
|
817
|
+}
|
|
818
|
+
|
|
819
|
+// This is called prior to the KILL screen to
|
|
820
|
+// clear the screen so we don't end up with a
|
|
821
|
+// garbled display.
|
|
822
|
+void ST7920_Lite_Status_Screen::clear_text_buffer() {
|
|
823
|
+ cs();
|
|
824
|
+ reset_state_from_unknown();
|
|
825
|
+ clear();
|
|
826
|
+ _extended_function_set(true, true); // Restore state to what u8g expects.
|
|
827
|
+ ncs();
|
|
828
|
+}
|
|
829
|
+
|
|
830
|
+static void lcd_implementation_status_screen() {
|
|
831
|
+ ST7920_Lite_Status_Screen::update(false);
|
|
832
|
+}
|
|
833
|
+
|
|
834
|
+/**
|
|
835
|
+ * In order to properly update the lite Status Screen,
|
|
836
|
+ * we must know when we have entered and left the
|
|
837
|
+ * Status Screen. Since the ultralcd code is not
|
|
838
|
+ * set up for doing this, we call this function before
|
|
839
|
+ * each update indicating whether the current screen
|
|
840
|
+ * is the Status Screen.
|
|
841
|
+ *
|
|
842
|
+ * This function keeps track of whether we have left or
|
|
843
|
+ * entered the Status Screen and calls the on_entry()
|
|
844
|
+ * and on_exit() methods for cleanup.
|
|
845
|
+ */
|
|
846
|
+static void lcd_in_status(const bool inStatus) {
|
|
847
|
+ static bool lastInStatus = false;
|
|
848
|
+ if (lastInStatus == inStatus) return;
|
|
849
|
+ if ((lastInStatus = inStatus))
|
|
850
|
+ ST7920_Lite_Status_Screen::on_entry();
|
|
851
|
+ else
|
|
852
|
+ ST7920_Lite_Status_Screen::on_exit();
|
|
853
|
+}
|