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