forked from MarlinFirmware/Marlin
/
dwin.cpp
5473 lines (5147 loc) · 205 KB
/
dwin.cpp
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/**
* lcd/e3v2/jyersui/dwin.cpp
*/
#include "../../../inc/MarlinConfigPre.h"
#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
#include "dwin.h"
#include "../../marlinui.h"
#include "../../../MarlinCore.h"
#include "../../../gcode/gcode.h"
#include "../../../module/temperature.h"
#include "../../../module/planner.h"
#include "../../../module/settings.h"
#include "../../../libs/buzzer.h"
#include "../../../inc/Conditionals_post.h"
//#define DEBUG_OUT 1
#include "../../../core/debug_out.h"
#if ENABLED(ADVANCED_PAUSE_FEATURE)
#include "../../../feature/pause.h"
#endif
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
#include "../../../feature/runout.h"
#endif
#if ENABLED(HOST_ACTION_COMMANDS)
#include "../../../feature/host_actions.h"
#endif
#if ANY(BABYSTEPPING, HAS_BED_PROBE, HAS_WORKSPACE_OFFSET)
#define HAS_ZOFFSET_ITEM 1
#endif
#ifndef strcasecmp_P
#define strcasecmp_P(a, b) strcasecmp((a), (b))
#endif
#if HAS_LEVELING
#include "../../../feature/bedlevel/bedlevel.h"
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "../../../libs/least_squares_fit.h"
#include "../../../libs/vector_3.h"
#endif
#if HAS_BED_PROBE
#include "../../../module/probe.h"
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
#include "../../../feature/powerloss.h"
#endif
#define MACHINE_SIZE STRINGIFY(X_BED_SIZE) "x" STRINGIFY(Y_BED_SIZE) "x" STRINGIFY(Z_MAX_POS)
#define DWIN_FONT_MENU font8x16
#define DWIN_FONT_STAT font10x20
#define DWIN_FONT_HEAD font10x20
#define MENU_CHAR_LIMIT 24
#define STATUS_CHAR_LIMIT 30
#define STATUS_Y 352
#define MAX_PRINT_SPEED 500
#define MIN_PRINT_SPEED 10
#if HAS_FAN
#define MAX_FAN_SPEED 255
#define MIN_FAN_SPEED 0
#endif
#define MAX_XY_OFFSET 100
#if HAS_ZOFFSET_ITEM
#define MAX_Z_OFFSET 9.99
#if HAS_BED_PROBE
#define MIN_Z_OFFSET -9.99
#else
#define MIN_Z_OFFSET -1
#endif
#endif
#if HAS_HOTEND
#define MAX_FLOW_RATE 200
#define MIN_FLOW_RATE 10
#define MAX_E_TEMP (HEATER_0_MAXTEMP - HOTEND_OVERSHOOT)
#define MIN_E_TEMP 0
#endif
#if HAS_HEATED_BED
#define MAX_BED_TEMP BED_MAXTEMP
#define MIN_BED_TEMP 0
#endif
constexpr uint16_t TROWS = 6, MROWS = TROWS - 1,
TITLE_HEIGHT = 30,
MLINE = 53,
LBLX = 60,
MENU_CHR_W = 8, MENU_CHR_H = 16, STAT_CHR_W = 10;
#define KEY_WIDTH 26
#define KEY_HEIGHT 30
#define KEY_INSET 5
#define KEY_PADDING 3
#define KEY_Y_START DWIN_HEIGHT-(KEY_HEIGHT*4+2*(KEY_INSET+1))
#define MBASE(L) (49 + MLINE * (L))
constexpr float default_max_feedrate[] = DEFAULT_MAX_FEEDRATE;
constexpr float default_max_acceleration[] = DEFAULT_MAX_ACCELERATION;
constexpr float default_steps[] = DEFAULT_AXIS_STEPS_PER_UNIT;
#if HAS_CLASSIC_JERK
constexpr float default_max_jerk[] = { DEFAULT_XJERK, DEFAULT_YJERK, DEFAULT_ZJERK, DEFAULT_EJERK };
#endif
enum SelectItem : uint8_t {
PAGE_PRINT = 0,
PAGE_PREPARE,
PAGE_CONTROL,
PAGE_INFO_LEVELING,
PAGE_COUNT,
PRINT_SETUP = 0,
PRINT_PAUSE_RESUME,
PRINT_STOP,
PRINT_COUNT
};
uint8_t active_menu = MainMenu, last_menu = MainMenu;
uint8_t selection = 0, last_selection = 0;
uint8_t scrollpos = 0;
uint8_t process = Main, last_process = Main;
PopupID popup, last_popup;
bool keyboard_restrict, reset_keyboard, numeric_keyboard = false;
uint8_t maxstringlen;
char *stringpointer = nullptr;
void (*funcpointer)() = nullptr;
void *valuepointer = nullptr;
float tempvalue;
float valuemin;
float valuemax;
uint8_t valueunit;
uint8_t valuetype;
char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
char statusmsg[64];
char filename[LONG_FILENAME_LENGTH];
bool printing = false;
bool paused = false;
bool sdprint = false;
int16_t pausetemp, pausebed, pausefan;
bool livemove = false;
bool liveadjust = false;
uint8_t preheatmode = 0;
float zoffsetvalue = 0;
uint8_t gridpoint;
float corner_avg;
float corner_pos;
#if ENABLED(HOST_ACTION_COMMANDS)
char action1[9];
char action2[9];
char action3[9];
#endif
bool probe_deployed = false;
CrealityDWINClass CrealityDWIN;
#if HAS_MESH
struct Mesh_Settings {
bool viewer_asymmetric_range = false;
bool viewer_print_value = false;
bool goto_mesh_value = false;
bool drawing_mesh = false;
uint8_t mesh_x = 0;
uint8_t mesh_y = 0;
#if ENABLED(AUTO_BED_LEVELING_UBL)
uint8_t tilt_grid = 1;
void manual_value_update(bool undefined=false) {
sprintf_P(cmd, PSTR("M421 I%i J%i Z%s %s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1), undefined ? "N" : "");
gcode.process_subcommands_now(cmd);
planner.synchronize();
}
bool create_plane_from_mesh() {
struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results);
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y])) {
xy_pos_t rpos;
rpos.x = ubl.mesh_index_to_xpos(x);
rpos.y = ubl.mesh_index_to_ypos(y);
incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
}
}
if (finish_incremental_LSF(&lsf_results)) {
SERIAL_ECHOPGM("Could not complete LSF!");
return true;
}
ubl.set_all_mesh_points_to_value(0);
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
GRID_LOOP(i, j) {
float mx = ubl.mesh_index_to_xpos(i),
my = ubl.mesh_index_to_ypos(j),
mz = Z_VALUES_ARR[i][j];
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(my, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(mz, 7);
DEBUG_ECHOPGM("] ---> ");
DEBUG_DELAY(20);
}
rotation.apply_rotation_xyz(mx, my, mz);
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR_F("after rotation = [", mx, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(my, 7);
DEBUG_CHAR(',');
DEBUG_ECHO_F(mz, 7);
DEBUG_ECHOLNPGM("]");
DEBUG_DELAY(20);
}
Z_VALUES_ARR[i][j] = mz - lsf_results.D;
}
return false;
}
#else
void manual_value_update() {
sprintf_P(cmd, PSTR("G29 I%i J%i Z%s"), mesh_x, mesh_y, dtostrf(current_position.z, 1, 3, str_1));
gcode.process_subcommands_now(cmd);
planner.synchronize();
}
#endif
void manual_move(bool zmove=false) {
if (zmove) {
planner.synchronize();
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
}
else {
CrealityDWIN.Popup_Handler(MoveWait);
sprintf_P(cmd, PSTR("G0 F300 Z%s"), dtostrf(Z_CLEARANCE_BETWEEN_PROBES, 1, 3, str_1));
gcode.process_subcommands_now(cmd);
sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
gcode.process_subcommands_now(cmd);
planner.synchronize();
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
planner.synchronize();
CrealityDWIN.Redraw_Menu();
}
}
float get_max_value() {
float max = __FLT_MIN__;
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max)
max = Z_VALUES_ARR[x][y];
}
return max;
}
float get_min_value() {
float min = __FLT_MAX__;
GRID_LOOP(x, y) {
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min)
min = Z_VALUES_ARR[x][y];
}
return min;
}
void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7) {
drawing_mesh = true;
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
const uint16_t cell_width_px = total_width_px / GRID_MAX_POINTS_X;
const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
// Clear background from previous selection and select new square
DWIN_Draw_Rectangle(1, Color_Bg_Black, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px);
if (selected >= 0) {
const auto selected_y = selected / GRID_MAX_POINTS_X;
const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
const auto start_y_px = padding_y_top + selected_y * cell_height_px;
const auto start_x_px = padding_x + selected_x * cell_width_px;
DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px);
}
// Draw value square grid
char buf[8];
GRID_LOOP(x, y) {
const auto start_x_px = padding_x + x * cell_width_px;
const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width;
const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
isnan(Z_VALUES_ARR[x][y]) ? Color_Grey : ( // gray if undefined
(Z_VALUES_ARR[x][y] < 0 ?
(uint16_t)round(0x1F * -Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
(uint16_t)round(0x3F * Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
_MIN(0x1F, (((uint8_t)abs(Z_VALUES_ARR[x][y]) / 10) * 4))), // + blue stepping for every mm
start_x_px, start_y_px, end_x_px, end_y_px
);
safe_delay(10);
LCD_SERIAL.flushTX();
// Draw value text on
if (viewer_print_value) {
int8_t offset_x, offset_y = cell_height_px / 2 - 6;
if (isnan(Z_VALUES_ARR[x][y])) { // undefined
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
}
else { // has value
if (GRID_MAX_POINTS_X < 10)
sprintf_P(buf, PSTR("%s"), dtostrf(abs(Z_VALUES_ARR[x][y]), 1, 2, str_1));
else
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(Z_VALUES_ARR[x][y] - (int16_t)Z_VALUES_ARR[x][y]) * 100));
offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
if (!(GRID_MAX_POINTS_X < 10))
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + 1 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, buf);
}
safe_delay(10);
LCD_SERIAL.flushTX();
}
}
}
void Set_Mesh_Viewer_Status() { // TODO: draw gradient with values as a legend instead
float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
if (v_min > 3e+10F) v_min = 0.0000001;
if (v_max > 3e+10F) v_max = 0.0000001;
if (range > 3e+10F) range = 0.0000001;
char msg[46];
if (viewer_asymmetric_range) {
dtostrf(-v_min, 1, 3, str_1);
dtostrf( v_max, 1, 3, str_2);
}
else {
dtostrf(-range, 1, 3, str_1);
dtostrf( range, 1, 3, str_2);
}
sprintf_P(msg, PSTR("Red %s..0..%s Green"), str_1, str_2);
CrealityDWIN.Update_Status(msg);
drawing_mesh = false;
}
};
Mesh_Settings mesh_conf;
#endif // HAS_MESH
/* General Display Functions */
struct CrealityDWINClass::EEPROM_Settings CrealityDWINClass::eeprom_settings{0};
constexpr const char * const CrealityDWINClass::color_names[11];
constexpr const char * const CrealityDWINClass::preheat_modes[3];
// Clear a part of the screen
// 4=Entire screen
// 3=Title bar and Menu area (default)
// 2=Menu area
// 1=Title bar
void CrealityDWINClass::Clear_Screen(uint8_t e/*=3*/) {
if (e == 1 || e == 3 || e == 4) DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.menu_top_bg, Color_Bg_Blue, false), 0, 0, DWIN_WIDTH, TITLE_HEIGHT); // Clear Title Bar
if (e == 2 || e == 3) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, STATUS_Y); // Clear Menu Area
if (e == 4) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, DWIN_HEIGHT); // Clear Popup Area
}
void CrealityDWINClass::Draw_Float(float value, uint8_t row, bool selected/*=false*/, uint8_t minunit/*=10*/) {
const uint8_t digits = (uint8_t)floor(log10(abs(value))) + log10(minunit) + (minunit > 1);
const uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black;
const uint16_t xpos = 240 - (digits * 8);
DWIN_Draw_Rectangle(1, Color_Bg_Black, 194, MBASE(row), 234 - (digits * 8), MBASE(row) + 16);
if (isnan(value))
DWIN_Draw_String(true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), F(" NaN"));
else {
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, Color_White, bColor, digits - log10(minunit) + 1, log10(minunit), xpos, MBASE(row), (value < 0 ? -value : value));
DWIN_Draw_String(true, DWIN_FONT_MENU, Color_White, bColor, xpos - 8, MBASE(row), value < 0 ? F("-") : F(" "));
}
}
void CrealityDWINClass::Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected/*=false*/, bool color/*=false*/) {
uint16_t bColor = (selected) ? Select_Color : Color_Bg_Black;
uint16_t tColor = (color) ? GetColor(value, Color_White, false) : Color_White;
DWIN_Draw_Rectangle(1, bColor, 202, MBASE(row) + 14, 258, MBASE(row) - 2);
DWIN_Draw_String(false, DWIN_FONT_MENU, tColor, bColor, 202, MBASE(row) - 1, options[value]);
}
void CrealityDWINClass::Draw_String(char * string, uint8_t row, bool selected/*=false*/, bool below/*=false*/) {
if (!string) string[0] = '\0';
const uint8_t offset_x = DWIN_WIDTH-strlen(string)*8 - 20;
const uint8_t offset_y = (below) ? MENU_CHR_H * 3 / 5 : 0;
DWIN_Draw_Rectangle(1, Color_Bg_Black, offset_x - 10, MBASE(row)+offset_y-1, offset_x, MBASE(row)+16+offset_y);
DWIN_Draw_String(true, DWIN_FONT_MENU, Color_White, (selected) ? Select_Color : Color_Bg_Black, offset_x, MBASE(row)-1+offset_y, string);
}
const uint64_t CrealityDWINClass::Encode_String(const char * string) {
const char table[65] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
uint64_t output = 0;
LOOP_L_N(i, strlen(string)) {
uint8_t upper_bound = 63, lower_bound = 0;
uint8_t midpoint;
LOOP_L_N(x, 6) {
midpoint = (uint8_t)(0.5*(upper_bound+lower_bound));
if (string[i] > table[midpoint]) lower_bound = midpoint;
else if (string[i] < table[midpoint]) upper_bound = midpoint;
else break;
}
output += midpoint*pow(64,i);
}
return output;
}
void CrealityDWINClass::Decode_String(uint64_t num, char * string) {
const char table[65] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
LOOP_L_N(i, 30) {
string[i] = table[num%64];
num /= 64;
if (num==0) {
string[i+1] = '\0';
break;
}
}
}
uint16_t CrealityDWINClass::GetColor(uint8_t color, uint16_t original, bool light/*=false*/) {
switch (color){
case Default:
return original;
break;
case White:
return (light) ? Color_Light_White : Color_White;
break;
case Green:
return (light) ? Color_Light_Green : Color_Green;
break;
case Cyan:
return (light) ? Color_Light_Cyan : Color_Cyan;
break;
case Blue:
return (light) ? Color_Light_Blue : Color_Blue;
break;
case Magenta:
return (light) ? Color_Light_Magenta : Color_Magenta;
break;
case Red:
return (light) ? Color_Light_Red : Color_Red;
break;
case Orange:
return (light) ? Color_Light_Orange : Color_Orange;
break;
case Yellow:
return (light) ? Color_Light_Yellow : Color_Yellow;
break;
case Brown:
return (light) ? Color_Light_Brown : Color_Brown;
break;
case Black:
return Color_Black;
break;
}
return Color_White;
}
void CrealityDWINClass::Draw_Title(const char * ctitle) {
DWIN_Draw_String(false, DWIN_FONT_HEAD, GetColor(eeprom_settings.menu_top_txt, Color_White, false), Color_Bg_Blue, (DWIN_WIDTH - strlen(ctitle) * STAT_CHR_W) / 2, 5, ctitle);
}
void CrealityDWINClass::Draw_Title(FSTR_P const ftitle) {
DWIN_Draw_String(false, DWIN_FONT_HEAD, GetColor(eeprom_settings.menu_top_txt, Color_White, false), Color_Bg_Blue, (DWIN_WIDTH - strlen_P(FTOP(ftitle)) * STAT_CHR_W) / 2, 5, ftitle);
}
void _Decorate_Menu_Item(uint8_t row, uint8_t icon, bool more) {
if (icon) DWIN_ICON_Show(ICON, icon, 26, MBASE(row) - 3); //Draw Menu Icon
if (more) DWIN_ICON_Show(ICON, ICON_More, 226, MBASE(row) - 3); // Draw More Arrow
DWIN_Draw_Line(CrealityDWIN.GetColor(CrealityDWIN.eeprom_settings.menu_split_line, Line_Color, true), 16, MBASE(row) + 33, 256, MBASE(row) + 33); // Draw Menu Line
}
void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, const char * label1, const char * label2, bool more/*=false*/, bool centered/*=false*/) {
const uint8_t label_offset_y = (label1 && label2) ? MENU_CHR_H * 3 / 5 : 0,
label1_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label1 ? strlen(label1) : 0) * MENU_CHR_W) / 2),
label2_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (label2 ? strlen(label2) : 0) * MENU_CHR_W) / 2);
if (label1) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label1_offset_x, MBASE(row) - 1 - label_offset_y, label1); // Draw Label
if (label2) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label2_offset_x, MBASE(row) - 1 + label_offset_y, label2); // Draw Label
_Decorate_Menu_Item(row, icon, more);
}
void CrealityDWINClass::Draw_Menu_Item(uint8_t row, uint8_t icon/*=0*/, FSTR_P const flabel1, FSTR_P const flabel2, bool more/*=false*/, bool centered/*=false*/) {
const uint8_t label_offset_y = (flabel1 && flabel2) ? MENU_CHR_H * 3 / 5 : 0,
label1_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (flabel1 ? strlen_P(FTOP(flabel1)) : 0) * MENU_CHR_W) / 2),
label2_offset_x = !centered ? LBLX : LBLX * 4/5 + _MAX(LBLX * 1U/5, (DWIN_WIDTH - LBLX - (flabel2 ? strlen_P(FTOP(flabel2)) : 0) * MENU_CHR_W) / 2);
if (flabel1) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label1_offset_x, MBASE(row) - 1 - label_offset_y, flabel1); // Draw Label
if (flabel2) DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, label2_offset_x, MBASE(row) - 1 + label_offset_y, flabel2); // Draw Label
_Decorate_Menu_Item(row, icon, more);
}
void CrealityDWINClass::Draw_Checkbox(uint8_t row, bool value) {
#if ENABLED(DWIN_CREALITY_LCD_CUSTOM_ICONS) // Draw appropriate checkbox icon
DWIN_ICON_Show(ICON, (value ? ICON_Checkbox_T : ICON_Checkbox_F), 226, MBASE(row) - 3);
#else // Draw a basic checkbox using rectangles and lines
DWIN_Draw_Rectangle(1, Color_Bg_Black, 226, MBASE(row) - 3, 226 + 20, MBASE(row) - 3 + 20);
DWIN_Draw_Rectangle(0, Color_White, 226, MBASE(row) - 3, 226 + 20, MBASE(row) - 3 + 20);
if (value) {
DWIN_Draw_Line(Check_Color, 227, MBASE(row) - 3 + 11, 226 + 8, MBASE(row) - 3 + 17);
DWIN_Draw_Line(Check_Color, 227 + 8, MBASE(row) - 3 + 17, 226 + 19, MBASE(row) - 3 + 1);
DWIN_Draw_Line(Check_Color, 227, MBASE(row) - 3 + 12, 226 + 8, MBASE(row) - 3 + 18);
DWIN_Draw_Line(Check_Color, 227 + 8, MBASE(row) - 3 + 18, 226 + 19, MBASE(row) - 3 + 2);
DWIN_Draw_Line(Check_Color, 227, MBASE(row) - 3 + 13, 226 + 8, MBASE(row) - 3 + 19);
DWIN_Draw_Line(Check_Color, 227 + 8, MBASE(row) - 3 + 19, 226 + 19, MBASE(row) - 3 + 3);
}
#endif
}
void CrealityDWINClass::Draw_Menu(uint8_t menu, uint8_t select/*=0*/, uint8_t scroll/*=0*/) {
if (active_menu != menu) {
last_menu = active_menu;
if (process == Menu) last_selection = selection;
}
selection = _MIN(select, Get_Menu_Size(menu));
scrollpos = scroll;
if (selection - scrollpos > MROWS)
scrollpos = selection - MROWS;
process = Menu;
active_menu = menu;
Clear_Screen();
Draw_Title(Get_Menu_Title(menu));
LOOP_L_N(i, TROWS) Menu_Item_Handler(menu, i + scrollpos);
DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
}
void CrealityDWINClass::Redraw_Menu(bool lastprocess/*=true*/, bool lastselection/*=false*/, bool lastmenu/*=false*/) {
switch ((lastprocess) ? last_process : process) {
case Menu:
Draw_Menu((lastmenu) ? last_menu : active_menu, (lastselection) ? last_selection : selection, (lastmenu) ? 0 : scrollpos);
break;
case Main: Draw_Main_Menu((lastselection) ? last_selection : selection); break;
case Print: Draw_Print_Screen(); break;
case File: Draw_SD_List(); break;
default: break;
}
}
void CrealityDWINClass::Redraw_Screen() {
Redraw_Menu(false);
Draw_Status_Area(true);
Update_Status_Bar(true);
}
/* Primary Menus and Screen Elements */
void CrealityDWINClass::Main_Menu_Icons() {
if (selection == 0) {
DWIN_ICON_Show(ICON, ICON_Print_1, 17, 130);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 17, 130, 126, 229);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
}
else {
DWIN_ICON_Show(ICON, ICON_Print_0, 17, 130);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 52, 200, F("Print"));
}
if (selection == 1) {
DWIN_ICON_Show(ICON, ICON_Prepare_1, 145, 130);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 130, 254, 229);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
}
else {
DWIN_ICON_Show(ICON, ICON_Prepare_0, 145, 130);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 170, 200, F("Prepare"));
}
if (selection == 2) {
DWIN_ICON_Show(ICON, ICON_Control_1, 17, 246);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 17, 246, 126, 345);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
}
else {
DWIN_ICON_Show(ICON, ICON_Control_0, 17, 246);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 43, 317, F("Control"));
}
#if HAS_ABL_OR_UBL
if (selection == 3) {
DWIN_ICON_Show(ICON, ICON_Leveling_1, 145, 246);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 246, 254, 345);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
}
else {
DWIN_ICON_Show(ICON, ICON_Leveling_0, 145, 246);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 179, 317, F("Level"));
}
#else
if (selection == 3) {
DWIN_ICON_Show(ICON, ICON_Info_1, 145, 246);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 145, 246, 254, 345);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
}
else {
DWIN_ICON_Show(ICON, ICON_Info_0, 145, 246);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 181, 317, F("Info"));
}
#endif
}
void CrealityDWINClass::Draw_Main_Menu(uint8_t select/*=0*/) {
process = Main;
active_menu = MainMenu;
selection = select;
Clear_Screen();
Draw_Title(Get_Menu_Title(MainMenu));
SERIAL_ECHOPGM("\nDWIN handshake ");
DWIN_ICON_Show(ICON, ICON_LOGO, 71, 72);
Main_Menu_Icons();
}
void CrealityDWINClass::Print_Screen_Icons() {
if (selection == 0) {
DWIN_ICON_Show(ICON, ICON_Setup_1, 8, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 8, 252, 87, 351);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
}
else {
DWIN_ICON_Show(ICON, ICON_Setup_0, 8, 252);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 30, 322, F("Tune"));
}
if (selection == 2) {
DWIN_ICON_Show(ICON, ICON_Stop_1, 184, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 184, 252, 263, 351);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
}
else {
DWIN_ICON_Show(ICON, ICON_Stop_0, 184, 252);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 205, 322, F("Stop"));
}
if (paused) {
if (selection == 1) {
DWIN_ICON_Show(ICON, ICON_Continue_1, 96, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 96, 252, 175, 351);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
}
else {
DWIN_ICON_Show(ICON, ICON_Continue_0, 96, 252);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Print"));
}
}
else {
if (selection == 1) {
DWIN_ICON_Show(ICON, ICON_Pause_1, 96, 252);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 96, 252, 175, 351);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
}
else {
DWIN_ICON_Show(ICON, ICON_Pause_0, 96, 252);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Blue, 114, 322, F("Pause"));
}
}
}
void CrealityDWINClass::Draw_Print_Screen() {
process = Print;
selection = 0;
Clear_Screen();
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
Draw_Title("Printing...");
Print_Screen_Icons();
DWIN_ICON_Show(ICON, ICON_PrintTime, 14, 171);
DWIN_ICON_Show(ICON, ICON_RemainTime, 147, 169);
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 41, 163, F("Elapsed"));
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, 176, 163, F("Remaining"));
Update_Status_Bar(true);
Draw_Print_ProgressBar();
Draw_Print_ProgressElapsed();
TERN_(USE_M73_REMAINING_TIME, Draw_Print_ProgressRemain());
Draw_Print_Filename(true);
}
void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) {
static uint8_t namescrl = 0;
if (reset) namescrl = 0;
if (process == Print) {
constexpr int8_t maxlen = 30;
char *outstr = filename;
size_t slen = strlen(filename);
int8_t outlen = slen;
if (slen > maxlen) {
char dispname[maxlen + 1];
int8_t pos = slen - namescrl, len = maxlen;
if (pos >= 0) {
NOMORE(len, pos);
LOOP_L_N(i, len) dispname[i] = filename[i + namescrl];
}
else {
const int8_t mp = maxlen + pos;
LOOP_L_N(i, mp) dispname[i] = ' ';
LOOP_S_L_N(i, mp, maxlen) dispname[i] = filename[i - mp];
if (mp <= 0) namescrl = 0;
}
dispname[len] = '\0';
outstr = dispname;
outlen = maxlen;
namescrl++;
}
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
const int8_t npos = (DWIN_WIDTH - outlen * MENU_CHR_W) / 2;
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, outstr);
}
}
void CrealityDWINClass::Draw_Print_ProgressBar() {
uint8_t printpercent = sdprint ? card.percentDone() : (ui._get_progress() / 100);
DWIN_ICON_Show(ICON, ICON_Bar, 15, 93);
DWIN_Draw_Rectangle(1, BarFill_Color, 16 + printpercent * 240 / 100, 93, 256, 113);
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 3, 109, 133, printpercent);
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_percent, Percent_Color), Color_Bg_Black, 133, 133, F("%"));
}
#if ENABLED(USE_M73_REMAINING_TIME)
void CrealityDWINClass::Draw_Print_ProgressRemain() {
uint16_t remainingtime = ui.get_remaining_time();
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 176, 187, remainingtime / 3600);
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 200, 187, (remainingtime % 3600) / 60);
if (eeprom_settings.time_format_textual) {
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, F("h"));
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 216, 187, F("m"));
}
else
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 192, 187, F(":"));
}
#endif
void CrealityDWINClass::Draw_Print_ProgressElapsed() {
duration_t elapsed = print_job_timer.duration();
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 42, 187, elapsed.value / 3600);
DWIN_Draw_IntValue(true, true, 1, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 2, 66, 187, (elapsed.value % 3600) / 60);
if (eeprom_settings.time_format_textual) {
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, F("h"));
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 82, 187, F("m"));
}
else
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.progress_time, Color_White), Color_Bg_Black, 58, 187, F(":"));
}
void CrealityDWINClass::Draw_Print_confirm() {
Draw_Print_Screen();
process = Confirm;
popup = Complete;
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 252, 263, 351);
DWIN_ICON_Show(ICON, ICON_Confirm_E, 87, 283);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 86, 282, 187, 321);
DWIN_Draw_Rectangle(0, GetColor(eeprom_settings.highlight_box, Color_White), 85, 281, 188, 322);
}
void CrealityDWINClass::Draw_SD_Item(uint8_t item, uint8_t row) {
if (item == 0)
Draw_Menu_Item(0, ICON_Back, card.flag.workDirIsRoot ? F("Back") : F(".."));
else {
card.getfilename_sorted(SD_ORDER(item - 1, card.get_num_Files()));
char * const filename = card.longest_filename();
size_t max = MENU_CHAR_LIMIT;
size_t pos = strlen(filename), len = pos;
if (!card.flag.filenameIsDir)
while (pos && filename[pos] != '.') pos--;
len = pos;
if (len > max) len = max;
char name[len + 1];
LOOP_L_N(i, len) name[i] = filename[i];
if (pos > max)
LOOP_S_L_N(i, len - 3, len) name[i] = '.';
name[len] = '\0';
Draw_Menu_Item(row, card.flag.filenameIsDir ? ICON_More : ICON_File, name);
}
}
void CrealityDWINClass::Draw_SD_List(bool removed/*=false*/) {
Clear_Screen();
Draw_Title("Select File");
selection = 0;
scrollpos = 0;
process = File;
if (card.isMounted() && !removed) {
LOOP_L_N(i, _MIN(card.get_num_Files() + 1, TROWS))
Draw_SD_Item(i, i);
}
else {
Draw_Menu_Item(0, ICON_Back, F("Back"));
DWIN_Draw_Rectangle(1, Color_Bg_Red, 10, MBASE(3) - 10, DWIN_WIDTH - 10, MBASE(4));
DWIN_Draw_String(false, font16x32, Color_Yellow, Color_Bg_Red, ((DWIN_WIDTH) - 8 * 16) / 2, MBASE(3), F("No Media"));
}
DWIN_Draw_Rectangle(1, GetColor(eeprom_settings.cursor_color, Rectangle_Color), 0, MBASE(0) - 18, 14, MBASE(0) + 33);
}
void CrealityDWINClass::Draw_Status_Area(bool icons/*=false*/) {
if (icons) DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, STATUS_Y, DWIN_WIDTH, DWIN_HEIGHT - 1);
#if HAS_HOTEND
static float hotend = -1;
static int16_t hotendtarget = -1, flow = -1;
if (icons) {
hotend = -1;
hotendtarget = -1;
DWIN_ICON_Show(ICON, ICON_HotendTemp, 10, 383);
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 384, F("/"));
}
if (thermalManager.temp_hotend[0].celsius != hotend) {
hotend = thermalManager.temp_hotend[0].celsius;
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 28, 384, thermalManager.temp_hotend[0].celsius);
DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 3 * STAT_CHR_W + 5, 386);
}
if (thermalManager.temp_hotend[0].target != hotendtarget) {
hotendtarget = thermalManager.temp_hotend[0].target;
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 384, thermalManager.temp_hotend[0].target);
DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 4 * STAT_CHR_W + 39, 386);
}
if (icons) {
flow = -1;
DWIN_ICON_Show(ICON, ICON_StepE, 112, 417);
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 417, F("%"));
}
if (planner.flow_percentage[0] != flow) {
flow = planner.flow_percentage[0];
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 417, planner.flow_percentage[0]);
}
#endif
#if HAS_HEATED_BED
static float bed = -1;
static int16_t bedtarget = -1;
if (icons) {
bed = -1;
bedtarget = -1;
DWIN_ICON_Show(ICON, ICON_BedTemp, 10, 416);
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 417, F("/"));
}
if (thermalManager.temp_bed.celsius != bed) {
bed = thermalManager.temp_bed.celsius;
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 28, 417, thermalManager.temp_bed.celsius);
DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 3 * STAT_CHR_W + 5, 419);
}
if (thermalManager.temp_bed.target != bedtarget) {
bedtarget = thermalManager.temp_bed.target;
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 417, thermalManager.temp_bed.target);
DWIN_Draw_DegreeSymbol(GetColor(eeprom_settings.status_area_text, Color_White), 25 + 4 * STAT_CHR_W + 39, 419);
}
#endif
#if HAS_FAN
static uint8_t fan = -1;
if (icons) {
fan = -1;
DWIN_ICON_Show(ICON, ICON_FanSpeed, 187, 383);
}
if (thermalManager.fan_speed[0] != fan) {
fan = thermalManager.fan_speed[0];
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 195 + 2 * STAT_CHR_W, 384, thermalManager.fan_speed[0]);
}
#endif
#if HAS_ZOFFSET_ITEM
static float offset = -1;
if (icons) {
offset = -1;
DWIN_ICON_Show(ICON, ICON_Zoffset, 187, 416);
}
if (zoffsetvalue != offset) {
offset = zoffsetvalue;
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 2, 2, 207, 417, (zoffsetvalue < 0 ? -zoffsetvalue : zoffsetvalue));
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 205, 419, zoffsetvalue < 0 ? F("-") : F(" "));
}
#endif
static int16_t feedrate = -1;
if (icons) {
feedrate = -1;
DWIN_ICON_Show(ICON, ICON_Speed, 113, 383);
DWIN_Draw_String(false, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 384, F("%"));
}
if (feedrate_percentage != feedrate) {
feedrate = feedrate_percentage;
DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, GetColor(eeprom_settings.status_area_text, Color_White), Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 384, feedrate_percentage);
}
static float x = -1, y = -1, z = -1;
static bool update_x = false, update_y = false, update_z = false;
update_x = (current_position.x != x || axis_should_home(X_AXIS) || update_x);
update_y = (current_position.y != y || axis_should_home(Y_AXIS) || update_y);
update_z = (current_position.z != z || axis_should_home(Z_AXIS) || update_z);
if (icons) {
x = y = z = -1;
DWIN_Draw_Line(GetColor(eeprom_settings.coordinates_split_line, Line_Color, true), 16, 450, 256, 450);
DWIN_ICON_Show(ICON, ICON_MaxSpeedX, 10, 456);
DWIN_ICON_Show(ICON, ICON_MaxSpeedY, 95, 456);
DWIN_ICON_Show(ICON, ICON_MaxSpeedZ, 180, 456);
}
if (update_x) {
x = current_position.x;
if ((update_x = axis_should_home(X_AXIS) && ui.get_blink()))
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 35, 459, F(" -?- "));
else
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 1, 35, 459, current_position.x);
}
if (update_y) {
y = current_position.y;
if ((update_y = axis_should_home(Y_AXIS) && ui.get_blink()))
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 120, 459, F(" -?- "));
else
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 1, 120, 459, current_position.y);
}
if (update_z) {
z = current_position.z;
if ((update_z = axis_should_home(Z_AXIS) && ui.get_blink()))
DWIN_Draw_String(true, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 205, 459, F(" -?- "));
else
DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_MENU, GetColor(eeprom_settings.coordinates_text, Color_White), Color_Bg_Black, 3, 2, 205, 459, (current_position.z>=0) ? current_position.z : 0);
}
DWIN_UpdateLCD();
}
void CrealityDWINClass::Draw_Popup(FSTR_P const line1, FSTR_P const line2, FSTR_P const line3, uint8_t mode, uint8_t icon/*=0*/) {
if (process != Confirm && process != Popup && process != Wait) last_process = process;
if ((process == Menu || process == Wait) && mode == Popup) last_selection = selection;
process = mode;
Clear_Screen();
DWIN_Draw_Rectangle(0, Color_White, 13, 59, 259, 351);
DWIN_Draw_Rectangle(1, Color_Bg_Window, 14, 60, 258, 350);
const uint8_t ypos = (mode == Popup || mode == Confirm) ? 150 : 230;
if (icon > 0) DWIN_ICON_Show(ICON, icon, 101, 105);
DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(FTOP(line1))) / 2, ypos, line1);
DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(FTOP(line2))) / 2, ypos + 30, line2);
DWIN_Draw_String(true, DWIN_FONT_MENU, Popup_Text_Color, Color_Bg_Window, (272 - 8 * strlen_P(FTOP(line3))) / 2, ypos + 60, line3);
if (mode == Popup) {
selection = 0;
DWIN_Draw_Rectangle(1, Confirm_Color, 26, 280, 125, 317);
DWIN_Draw_Rectangle(1, Cancel_Color, 146, 280, 245, 317);
DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 39, 290, F("Confirm"));
DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 165, 290, F("Cancel"));
Popup_Select();
}
else if (mode == Confirm) {
DWIN_Draw_Rectangle(1, Confirm_Color, 87, 280, 186, 317);
DWIN_Draw_String(false, DWIN_FONT_STAT, Color_White, Color_Bg_Window, 96, 290, F("Continue"));
}
}
void MarlinUI::kill_screen(FSTR_P const error, FSTR_P const) {
CrealityDWIN.Draw_Popup(F("Printer Kill Reason:"), error, F("Restart Required"), Wait, ICON_BLTouch);
}