forked from odwdinc/DWIN_T5UIC1_LCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwinlcd.py
2326 lines (2069 loc) · 83.5 KB
/
dwinlcd.py
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
import time
import multitimer
import atexit
from encoder import Encoder
from RPi import GPIO
from printerInterface import PrinterData
from DWIN_Screen import T5UIC1_LCD
from time import sleep
def current_milli_time():
return round(time.time() * 1000)
def _MAX(lhs, rhs):
if lhs > rhs:
return lhs
else:
return rhs
def _MIN(lhs, rhs):
if lhs < rhs:
return lhs
else:
return rhs
class select_t:
now = 0
last = 0
def set(self, v):
self.now = self.last = v
def reset(self):
self.set(0)
def changed(self):
c = (self.now != self.last)
if c:
self.last = self.now
return c
def dec(self):
if (self.now):
self.now -= 1
return self.changed()
def inc(self, v):
if (self.now < (v - 1)):
self.now += 1
else:
self.now = (v - 1)
return self.changed()
class DWIN_LCD:
TROWS = 6
MROWS = TROWS - 1 # Total rows, and other-than-Back
TITLE_HEIGHT = 30 # Title bar height
MLINE = 53 # Menu line height
LBLX = 60 # Menu item label X
MENU_CHR_W = 8
STAT_CHR_W = 10
dwin_abort_flag = False # Flag to reset feedrate, return to Home
MSG_STOP_PRINT = "Stop Print"
MSG_PAUSE_PRINT = "Pausing..."
DWIN_SCROLL_UP = 2
DWIN_SCROLL_DOWN = 3
select_page = select_t()
select_file = select_t()
select_print = select_t()
select_prepare = select_t()
select_control = select_t()
select_axis = select_t()
select_temp = select_t()
select_motion = select_t()
select_tune = select_t()
select_PLA = select_t()
select_ABS = select_t()
index_file = MROWS
index_prepare = MROWS
index_control = MROWS
index_leveling = MROWS
index_tune = MROWS
MainMenu = 0
SelectFile = 1
Prepare = 2
Control = 3
Leveling = 4
PrintProcess = 5
AxisMove = 6
TemperatureID = 7
Motion = 8
Info = 9
Tune = 10
PLAPreheat = 11
ABSPreheat = 12
MaxSpeed = 13
MaxSpeed_value = 14
MaxAcceleration = 15
MaxAcceleration_value = 16
MaxJerk = 17
MaxJerk_value = 18
Step = 19
Step_value = 20
# Last Process ID
Last_Prepare = 21
# Back Process ID
Back_Main = 22
Back_Print = 23
# Date variable ID
Move_X = 24
Move_Y = 25
Move_Z = 26
Extruder = 27
ETemp = 28
Homeoffset = 29
BedTemp = 30
FanSpeed = 31
PrintSpeed = 32
Print_window = 33
Popup_Window = 34
MINUNITMULT = 10
ENCODER_DIFF_NO = 0 # no state
ENCODER_DIFF_CW = 1 # clockwise rotation
ENCODER_DIFF_CCW = 2 # counterclockwise rotation
ENCODER_DIFF_ENTER = 3 # click
ENCODER_WAIT = 50
ENCODER_ENTER_WAIT = 250
SCROLL_UPDATE_INTERVAL = 2000
dwin_zoffset = 0.0
last_zoffset = 0.0
# Picture ID
Start_Process = 0
Language_English = 1
Language_Chinese = 2
# ICON ID
ICON = 0x09
ICON_LOGO = 0
ICON_Print_0 = 1
ICON_Print_1 = 2
ICON_Prepare_0 = 3
ICON_Prepare_1 = 4
ICON_Control_0 = 5
ICON_Control_1 = 6
ICON_Leveling_0 = 7
ICON_Leveling_1 = 8
ICON_HotendTemp = 9
ICON_BedTemp = 10
ICON_Speed = 11
ICON_Zoffset = 12
ICON_Back = 13
ICON_File = 14
ICON_PrintTime = 15
ICON_RemainTime = 16
ICON_Setup_0 = 17
ICON_Setup_1 = 18
ICON_Pause_0 = 19
ICON_Pause_1 = 20
ICON_Continue_0 = 21
ICON_Continue_1 = 22
ICON_Stop_0 = 23
ICON_Stop_1 = 24
ICON_Bar = 25
ICON_More = 26
ICON_Axis = 27
ICON_CloseMotor = 28
ICON_Homing = 29
ICON_SetHome = 30
ICON_PLAPreheat = 31
ICON_ABSPreheat = 32
ICON_Cool = 33
ICON_Language = 34
ICON_MoveX = 35
ICON_MoveY = 36
ICON_MoveZ = 37
ICON_Extruder = 38
ICON_Temperature = 40
ICON_Motion = 41
ICON_WriteEEPROM = 42
ICON_ReadEEPROM = 43
ICON_ResumeEEPROM = 44
ICON_Info = 45
ICON_SetEndTemp = 46
ICON_SetBedTemp = 47
ICON_FanSpeed = 48
ICON_SetPLAPreheat = 49
ICON_SetABSPreheat = 50
ICON_MaxSpeed = 51
ICON_MaxAccelerated = 52
ICON_MaxJerk = 53
ICON_Step = 54
ICON_PrintSize = 55
ICON_Version = 56
ICON_Contact = 57
ICON_StockConfiguraton = 58
ICON_MaxSpeedX = 59
ICON_MaxSpeedY = 60
ICON_MaxSpeedZ = 61
ICON_MaxSpeedE = 62
ICON_MaxAccX = 63
ICON_MaxAccY = 64
ICON_MaxAccZ = 65
ICON_MaxAccE = 66
ICON_MaxSpeedJerkX = 67
ICON_MaxSpeedJerkY = 68
ICON_MaxSpeedJerkZ = 69
ICON_MaxSpeedJerkE = 70
ICON_StepX = 71
ICON_StepY = 72
ICON_StepZ = 73
ICON_StepE = 74
ICON_Setspeed = 75
ICON_SetZOffset = 76
ICON_Rectangle = 77
ICON_BLTouch = 78
ICON_TempTooLow = 79
ICON_AutoLeveling = 80
ICON_TempTooHigh = 81
ICON_NoTips_C = 82
ICON_NoTips_E = 83
ICON_Continue_C = 84
ICON_Continue_E = 85
ICON_Cancel_C = 86
ICON_Cancel_E = 87
ICON_Confirm_C = 88
ICON_Confirm_E = 89
ICON_Info_0 = 90
ICON_Info_1 = 91
MENU_CHAR_LIMIT = 24
STATUS_Y = 360
MOTION_CASE_RATE = 1
MOTION_CASE_ACCEL = 2
MOTION_CASE_JERK = MOTION_CASE_ACCEL + 0
MOTION_CASE_STEPS = MOTION_CASE_JERK + 1
MOTION_CASE_TOTAL = MOTION_CASE_STEPS
PREPARE_CASE_MOVE = 1
PREPARE_CASE_DISA = 2
PREPARE_CASE_HOME = 3
PREPARE_CASE_ZOFF = PREPARE_CASE_HOME + 1
PREPARE_CASE_PLA = PREPARE_CASE_ZOFF + 1
PREPARE_CASE_ABS = PREPARE_CASE_PLA + 1
PREPARE_CASE_COOL = PREPARE_CASE_ABS + 1
PREPARE_CASE_LANG = PREPARE_CASE_COOL + 0
PREPARE_CASE_TOTAL = PREPARE_CASE_LANG
CONTROL_CASE_TEMP = 1
CONTROL_CASE_MOVE = 2
CONTROL_CASE_INFO = 3
CONTROL_CASE_TOTAL = 3
TUNE_CASE_SPEED = 1
TUNE_CASE_TEMP = (TUNE_CASE_SPEED + 1)
TUNE_CASE_BED = (TUNE_CASE_TEMP + 1)
TUNE_CASE_FAN = (TUNE_CASE_BED + 0)
TUNE_CASE_ZOFF = (TUNE_CASE_FAN + 0)
TUNE_CASE_TOTAL = TUNE_CASE_ZOFF
TEMP_CASE_TEMP = (0 + 1)
TEMP_CASE_BED = (TEMP_CASE_TEMP + 1)
TEMP_CASE_FAN = (TEMP_CASE_BED + 0)
TEMP_CASE_PLA = (TEMP_CASE_FAN + 1)
TEMP_CASE_ABS = (TEMP_CASE_PLA + 1)
TEMP_CASE_TOTAL = TEMP_CASE_ABS
PREHEAT_CASE_TEMP = (0 + 1)
PREHEAT_CASE_BED = (PREHEAT_CASE_TEMP + 1)
PREHEAT_CASE_FAN = (PREHEAT_CASE_BED + 0)
PREHEAT_CASE_SAVE = (PREHEAT_CASE_FAN + 1)
PREHEAT_CASE_TOTAL = PREHEAT_CASE_SAVE
# Dwen serial screen initialization
# Passing parameters: serial port number
# DWIN screen uses serial port 1 to send
def __init__(self, USARTx, encoder_pins, button_pin, buzzer_pin, octoPrint_API_Key):
GPIO.setmode(GPIO.BCM)
self.encoder = Encoder(encoder_pins[0], encoder_pins[1])
self.button_pin = button_pin
self.buzzer_pin = buzzer_pin
GPIO.setup(self.button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(self.buzzer_pin,GPIO.OUT)
GPIO.add_event_detect(self.button_pin, GPIO.BOTH, callback=self.encoder_has_data)
self.encoder.callback = self.encoder_has_data
self.EncodeLast = 0
self.EncodeMS = current_milli_time() + self.ENCODER_WAIT
self.EncodeMS_ENTER = current_milli_time() + self.ENCODER_ENTER_WAIT
self.next_rts_update_ms = 0
self.last_cardpercentValue = 101
self.lcd = T5UIC1_LCD(USARTx)
self.timer = multitimer.MultiTimer(interval=2, function=self.EachMomentUpdate)
self.pd = PrinterData(octoPrint_API_Key)
self.HMI_ShowBoot()
print("Boot looks good")
print("Testing Web-services")
self.pd.init_Webservices()
while self.pd.status is None:
print("No Web-services")
self.pd.init_Webservices()
self.HMI_ShowBoot("Web-service still loading")
self.HMI_Init()
self.HMI_StartFrame(False)
def lcdExit(self):
print("Shutting down the LCD")
self.lcd.JPG_ShowAndCache(0)
self.lcd.Frame_SetDir(1)
self.lcd.UpdateLCD()
self.timer.stop()
GPIO.remove_event_detect(self.button_pin)
def MBASE(self, L):
return 49 + self.MLINE * L
def HMI_SetLanguageCache(self):
self.lcd.JPG_CacheTo1(self.Language_English)
def HMI_SetLanguage(self):
self.HMI_SetLanguageCache()
def HMI_ShowBoot(self, mesg=None):
if mesg:
self.lcd.Draw_String(
False, False, self.lcd.DWIN_FONT_STAT,
self.lcd.Color_White, self.lcd.Color_Bg_Black,
10, 50,
mesg
)
for t in range(0, 100, 2):
self.lcd.ICON_Show(self.ICON, self.ICON_Bar, 15, 260)
self.lcd.Draw_Rectangle(1, self.lcd.Color_Bg_Black, 15 + t * 242 / 100, 260, 257, 280)
self.lcd.UpdateLCD()
time.sleep(.020)
def HMI_Init(self):
# HMI_SDCardInit()
self.HMI_SetLanguage()
self.timer.start()
atexit.register(self.lcdExit)
def HMI_StartFrame(self, with_update):
self.last_status = self.pd.status
if self.pd.status == "Printing":
self.Goto_PrintProcess()
elif self.pd.status == "Operational":
self.Goto_MainMenu()
else:
self.Goto_MainMenu()
self.Draw_Status_Area(with_update)
def HMI_MainMenu(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (encoder_diffState == self.ENCODER_DIFF_CW):
if(self.select_page.inc(4)):
if self.select_page.now == 0:
self.ICON_Print()
if self.select_page.now == 1:
self.ICON_Print()
self.ICON_Prepare()
if self.select_page.now == 2:
self.ICON_Prepare()
self.ICON_Control()
if self.select_page.now == 3:
self.ICON_Control()
if self.pd.HAS_ONESTEP_LEVELING:
self.ICON_Leveling(True)
else:
self.ICON_StartInfo(True)
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
if (self.select_page.dec()):
if self.select_page.now == 0:
self.ICON_Print()
self.ICON_Prepare()
elif self.select_page.now == 1:
self.ICON_Prepare()
self.ICON_Control()
elif self.select_page.now == 2:
self.ICON_Control()
if self.pd.HAS_ONESTEP_LEVELING:
self.ICON_Leveling(False)
else:
self.ICON_StartInfo(False)
elif self.select_page.now == 3:
if self.pd.HAS_ONESTEP_LEVELING:
self.ICON_Leveling(True)
else:
self.ICON_StartInfo(True)
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if self.select_page.now == 0: # Print File
self.checkkey = self.SelectFile
self.Draw_Print_File_Menu()
if self.select_page.now == 1: # Prepare
self.checkkey = self.Prepare
self.select_prepare.reset()
self.index_prepare = self.MROWS
self.Draw_Prepare_Menu()
if self.select_page.now == 2: # Control
self.checkkey = self.Control
self.select_control.reset()
self.index_control = self.MROWS
self.Draw_Control_Menu()
if self.select_page.now == 3: # Leveling or Info
if self.pd.HAS_ONESTEP_LEVELING:
self.checkkey = self.Leveling
self.HMI_Leveling()
else:
self.checkkey = self.Info
self.Draw_Info_Menu()
self.lcd.UpdateLCD()
def HMI_SelectFile(self):
encoder_diffState = self.get_encoder_state()
hasUpDir = False # !card.flag.workDirIsRoot;
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
fullCnt = len(self.pd.GetFiles())
if (encoder_diffState == self.ENCODER_DIFF_CW and fullCnt):
if (self.select_file.inc(1 + fullCnt)):
itemnum = self.select_file.now - 1 # -1 for "Back"
if (self.select_file.now > self.MROWS and self.select_file.now > self.index_file): # Cursor past the bottom
self.index_file = self.select_file.now # New bottom line
self.Scroll_Menu(self.DWIN_SCROLL_UP)
self.Draw_SDItem(itemnum, self.MROWS) # Draw and init the shift name
else:
self.Move_Highlight(1, self.select_file.now + self.MROWS - self.index_file) # Just move highlight
elif (encoder_diffState == self.ENCODER_DIFF_CCW and fullCnt):
if (self.select_file.dec()):
itemnum = self.select_file.now - 1 # -1 for "Back"
if (self.select_file.now < self.index_file - self.MROWS): # Cursor past the top
self.index_file -= 1 # New bottom line
self.Scroll_Menu(self.DWIN_SCROLL_DOWN)
if (self.index_file == self.MROWS):
self.Draw_Back_First()
else:
self.Draw_SDItem(itemnum, 0) # Draw the item (and init shift name)
else:
self.Move_Highlight(-1, self.select_file.now + self.MROWS - self.index_file) # Just move highlight
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if (self.select_file.now == 0): # Back
self.select_page.set(0)
self.Goto_MainMenu()
else:
filenum = self.select_file.now - 1
# Reset highlight for next entry
self.select_print.reset()
self.select_file.reset()
# // Start choice and print SD file
self.pd.HMI_flag.heat_flag = True
self.pd.HMI_flag.print_finish = False
self.pd.HMI_ValueStruct.show_mode = 0
self.pd.openAndPrintFile(filenum)
self.Goto_PrintProcess()
self.lcd.UpdateLCD()
def HMI_Prepare(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (encoder_diffState == self.ENCODER_DIFF_CW):
if (self.select_prepare.inc(1 + self.PREPARE_CASE_TOTAL)):
if (self.select_prepare.now > self.MROWS and self.select_prepare.now > self.index_prepare):
self.index_prepare = self.select_prepare.now
# Scroll up and draw a blank bottom line
self.Scroll_Menu(self.DWIN_SCROLL_UP)
self.Draw_Menu_Icon(self.MROWS, self.ICON_Axis + self.select_prepare.now - 1)
# Draw "More" icon for sub-menus
if (self.index_prepare < 7):
self.Draw_More_Icon(self.MROWS - self.index_prepare + 1)
if self.pd.HAS_HOTEND:
if (self.index_prepare == self.PREPARE_CASE_ABS):
self.Item_Prepare_ABS(self.MROWS)
if self.pd.HAS_PREHEAT:
if (self.index_prepare == self.PREPARE_CASE_COOL):
self.Item_Prepare_Cool(self.MROWS)
else:
self.Move_Highlight(1, self.select_prepare.now + self.MROWS - self.index_prepare)
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
if (self.select_prepare.dec()):
if (self.select_prepare.now < self.index_prepare - self.MROWS):
self.index_prepare -= 1
self.Scroll_Menu(self.DWIN_SCROLL_DOWN)
if (self.index_prepare == self.MROWS):
self.Draw_Back_First()
else:
self.Draw_Menu_Line(0, self.ICON_Axis + self.select_prepare.now - 1)
if (self.index_prepare < 7):
self.Draw_More_Icon(self.MROWS - self.index_prepare + 1)
if (self.index_prepare == 6):
self.Item_Prepare_Move(0)
elif (self.index_prepare == 7):
self.Item_Prepare_Disable(0)
elif (self.index_prepare == 8):
self.Item_Prepare_Home(0)
else:
self.Move_Highlight(-1, self.select_prepare.now + self.MROWS - self.index_prepare)
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if (self.select_prepare.now == 0): # Back
self.select_page.set(1)
self.Goto_MainMenu()
elif self.select_prepare.now == self.PREPARE_CASE_MOVE: # Axis move
self.checkkey = self.AxisMove
self.select_axis.reset()
self.Draw_Move_Menu()
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(1), self.pd.current_position.x * self.MINUNITMULT
)
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(2), self.pd.current_position.y * self.MINUNITMULT
)
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(3), self.pd.current_position.z * self.MINUNITMULT
)
self.pd.queue("G92 E0")
self.pd.current_position.e = self.pd.HMI_ValueStruct.Move_E_scale = 0
self.lcd.Draw_Signed_Float(self.lcd.font8x16, self.lcd.Color_Bg_Black, 3, 1, 216, self.MBASE(4), 0)
elif self.select_prepare.now == self.PREPARE_CASE_DISA: # Disable steppers
self.pd.queue("M84")
elif self.select_prepare.now == self.PREPARE_CASE_HOME: # Homing
self.checkkey = self.Last_Prepare
self.index_prepare = self.MROWS
self.Popup_Window_Home()
self.pd.queue("G28")
self.pd.current_position.homing()
self.pd.HMI_flag.home_flag = True
elif self.select_prepare.now == self.PREPARE_CASE_ZOFF: # Z-offset
self.checkkey = self.Homeoffset
self.pd.probe_calibrate()
self.pd.HMI_ValueStruct.show_mode = -4
self.pd.HMI_ValueStruct.offset_value = self.pd.BABY_Z_VAR * 100
self.dwin_zoffset = self.pd.HMI_ValueStruct.offset_value / 100.0
self.lcd.Draw_Signed_Float(
self.lcd.font8x16, self.lcd.Select_Color, 2, 2, 202,
self.MBASE(self.PREPARE_CASE_ZOFF + self.MROWS - self.index_prepare),
self.pd.HMI_ValueStruct.offset_value
)
elif self.select_prepare.now == self.PREPARE_CASE_PLA: # PLA preheat
self.pd.preheat("PLA")
elif self.select_prepare.now == self.PREPARE_CASE_ABS: # ABS preheat
self.pd.preheat("ABS")
elif self.select_prepare.now == self.PREPARE_CASE_COOL: # Cool
if self.pd.HAS_FAN:
self.pd.zero_fan_speeds()
self.pd.disable_all_heaters()
elif self.select_prepare.now == self.PREPARE_CASE_LANG: # Toggle Language
self.HMI_ToggleLanguage()
self.Draw_Prepare_Menu()
self.lcd.UpdateLCD()
def HMI_Control(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (encoder_diffState == self.ENCODER_DIFF_CW):
if (self.select_control.inc(1 + self.CONTROL_CASE_TOTAL)):
if (self.select_control.now > self.MROWS and self.select_control.now > self.index_control):
self.index_control = self.select_control.now
self.Scroll_Menu(self.DWIN_SCROLL_UP)
self.Draw_Menu_Icon(self.MROWS, self.ICON_Temperature + self.index_control - 1)
self.Draw_More_Icon(self.CONTROL_CASE_TEMP + self.MROWS - self.index_control) # Temperature >
self.Draw_More_Icon(self.CONTROL_CASE_MOVE + self.MROWS - self.index_control) # Motion >
if (self.index_control > self.MROWS):
self.Draw_More_Icon(self.CONTROL_CASE_INFO + self.MROWS - self.index_control) # Info >
self.lcd.Frame_AreaCopy(1, 0, 104, 24, 114, self.LBLX, self.MBASE(self.CONTROL_CASE_INFO - 1))
else:
self.Move_Highlight(1, self.select_control.now + self.MROWS - self.index_control)
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
if (self.select_control.dec()):
if (self.select_control.now < self.index_control - self.MROWS):
self.index_control -= 1
self.Scroll_Menu(self.DWIN_SCROLL_DOWN)
if (self.index_control == self.MROWS):
self.Draw_Back_First()
else:
self.Draw_Menu_Line(0, self.ICON_Temperature + self.select_control.now - 1)
self.Draw_More_Icon(0 + self.MROWS - self.index_control + 1) # Temperature >
self.Draw_More_Icon(1 + self.MROWS - self.index_control + 1) # Motion >
else:
self.Move_Highlight(-1, self.select_control.now + self.MROWS - self.index_control)
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if (self.select_control.now == 0): # Back
self.select_page.set(2)
self.Goto_MainMenu()
if (self.select_control.now == self.CONTROL_CASE_TEMP): # Temperature
self.checkkey = self.TemperatureID
self.pd.HMI_ValueStruct.show_mode = -1
self.select_temp.reset()
self.Draw_Temperature_Menu()
if (self.select_control.now == self.CONTROL_CASE_MOVE): # Motion
self.checkkey = self.Motion
self.select_motion.reset()
self.Draw_Motion_Menu()
if (self.select_control.now == self.CONTROL_CASE_INFO): # Info
self.checkkey = self.Info
self.Draw_Info_Menu()
self.lcd.UpdateLCD()
def HMI_Info(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (encoder_diffState == self.ENCODER_DIFF_ENTER):
if self.pd.HAS_ONESTEP_LEVELING:
self.checkkey = self.Control
self.select_control.set(self.CONTROL_CASE_INFO)
self.Draw_Control_Menu()
else:
self.select_page.set(3)
self.Goto_MainMenu()
self.lcd.UpdateLCD()
def HMI_Printing(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (self.pd.HMI_flag.done_confirm_flag):
if (encoder_diffState == self.ENCODER_DIFF_ENTER):
self.pd.HMI_flag.done_confirm_flag = False
self.dwin_abort_flag = True # Reset feedrate, return to Home
return
if (encoder_diffState == self.ENCODER_DIFF_CW):
if (self.select_print.inc(3)):
if self.select_print.now == 0:
self.ICON_Tune()
elif self.select_print.now == 1:
self.ICON_Tune()
if (self.pd.printingIsPaused()):
self.ICON_Continue()
else:
self.ICON_Pause()
elif self.select_print.now == 2:
if (self.pd.printingIsPaused()):
self.ICON_Continue()
else:
self.ICON_Pause()
self.ICON_Stop()
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
if (self.select_print.dec()):
if self.select_print.now == 0:
self.ICON_Tune()
if (self.pd.printingIsPaused()):
self.ICON_Continue()
else:
self.ICON_Pause()
elif self.select_print.now == 1:
if (self.pd.printingIsPaused()):
self.ICON_Continue()
else:
self.ICON_Pause()
self.ICON_Stop()
elif self.select_print.now == 2:
self.ICON_Stop()
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if self.select_print.now == 0: # Tune
self.checkkey = self.Tune
self.pd.HMI_ValueStruct.show_mode = 0
self.select_tune.reset()
self.index_tune = self.MROWS
self.Draw_Tune_Menu()
elif self.select_print.now == 1: # Pause
if (self.pd.HMI_flag.pause_flag):
self.ICON_Pause()
self.pd.resume_job()
else:
self.pd.HMI_flag.select_flag = True
self.checkkey = self.Print_window
self.Popup_window_PauseOrStop()
elif self.select_print.now == 2: # Stop
self.pd.HMI_flag.select_flag = True
self.checkkey = self.Print_window
self.Popup_window_PauseOrStop()
self.lcd.UpdateLCD()
# Pause and Stop window */
def HMI_PauseOrStop(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (encoder_diffState == self.ENCODER_DIFF_CW):
self.Draw_Select_Highlight(False)
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
self.Draw_Select_Highlight(True)
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if (self.select_print.now == 1): # pause window
if (self.pd.HMI_flag.select_flag):
self.pd.HMI_flag.pause_action = True
self.ICON_Continue()
self.pd.pause_job()
self.Goto_PrintProcess()
elif (self.select_print.now == 2): # stop window
if (self.pd.HMI_flag.select_flag):
self.dwin_abort_flag = True # Reset feedrate, return to Home
self.pd.cancel_job()
self.Goto_MainMenu()
else:
self.Goto_PrintProcess() # cancel stop
self.lcd.UpdateLCD()
# Tune */
def HMI_Tune(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (encoder_diffState == self.ENCODER_DIFF_CW):
if (self.select_tune.inc(1 + self.TUNE_CASE_TOTAL)):
if (self.select_tune.now > self.MROWS and self.select_tune.now > self.index_tune):
self.index_tune = self.select_tune.now
self.Scroll_Menu(self.DWIN_SCROLL_UP)
else:
self.Move_Highlight(1, self.select_tune.now + self.MROWS - self.index_tune)
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
if (self.select_tune.dec()):
if (self.select_tune.now < self.index_tune - self.MROWS):
self.index_tune -= 1
self.Scroll_Menu(self.DWIN_SCROLL_DOWN)
if (self.index_tune == self.MROWS):
self.Draw_Back_First()
else:
self.Move_Highlight(-1, self.select_tune.now + self.MROWS - self.index_tune)
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if self.select_tune.now == 0: # Back
self.select_print.set(0)
self.Goto_PrintProcess()
if self.select_tune.now == self.TUNE_CASE_SPEED: # Print speed
self.checkkey = self.PrintSpeed
self.pd.HMI_ValueStruct.print_speed = self.pd.feedrate_percentage
self.lcd.Draw_IntValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Select_Color,
3, 216, self.MBASE(self.TUNE_CASE_SPEED + self.MROWS - self.index_tune),
self.pd.feedrate_percentage
)
self.lcd.UpdateLCD()
def HMI_PrintSpeed(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if (encoder_diffState == self.ENCODER_DIFF_CW):
self.pd.HMI_ValueStruct.print_speed += 1
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
self.pd.HMI_ValueStruct.print_speed -= 1
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
self.checkkey = self.Tune
self.pd.set_feedrate(self.pd.HMI_ValueStruct.print_speed)
self.lcd.Draw_IntValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 216, self.MBASE(self.select_tune.now + self.MROWS - self.index_tune),
self.pd.HMI_ValueStruct.print_speed
)
def HMI_AxisMove(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
if self.pd.PREVENT_COLD_EXTRUSION:
# popup window resume
if (self.pd.HMI_flag.ETempTooLow_flag):
if (encoder_diffState == self.ENCODER_DIFF_ENTER):
self.pd.HMI_flag.ETempTooLow_flag = False
self.pd.current_position.e = self.pd.HMI_ValueStruct.Move_E_scale = 0
self.Draw_Move_Menu()
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(1),
self.pd.HMI_ValueStruct.Move_X_scale
)
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(2),
self.pd.HMI_ValueStruct.Move_Y_scale
)
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(3),
self.pd.HMI_ValueStruct.Move_Z_scale
)
self.lcd.Draw_Signed_Float(
self.lcd.font8x16, self.lcd.Color_Bg_Black, 3, 1, 216, self.MBASE(4), 0
)
self.lcd.UpdateLCD()
return
# Avoid flicker by updating only the previous menu
if (encoder_diffState == self.ENCODER_DIFF_CW):
if (self.select_axis.inc(1 + 4)):
self.Move_Highlight(1, self.select_axis.now)
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
if (self.select_axis.dec()):
self.Move_Highlight(-1, self.select_axis.now)
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
if self.select_axis.now == 0: # Back
self.checkkey = self.Prepare
self.select_prepare.set(1)
self.index_prepare = self.MROWS
self.Draw_Prepare_Menu()
elif self.select_axis.now == 1: # axis move
self.checkkey = self.Move_X
self.pd.HMI_ValueStruct.Move_X_scale = self.pd.current_position.x * self.MINUNITMULT
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Select_Color,
3, 1, 216, self.MBASE(1),
self.pd.HMI_ValueStruct.Move_X_scale
)
elif self.select_axis.now == 2: # Y axis move
self.checkkey = self.Move_Y
self.pd.HMI_ValueStruct.Move_Y_scale = self.pd.current_position.y * self.MINUNITMULT
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Select_Color,
3, 1, 216, self.MBASE(2),
self.pd.HMI_ValueStruct.Move_Y_scale
)
elif self.select_axis.now == 3: # Z axis move
self.checkkey = self.Move_Z
self.pd.HMI_ValueStruct.Move_Z_scale = self.pd.current_position.z * self.MINUNITMULT
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Select_Color,
3, 1, 216, self.MBASE(3),
self.pd.HMI_ValueStruct.Move_Z_scale
)
elif self.select_axis.now == 4: # Extruder
# window tips
if self.pd.PREVENT_COLD_EXTRUSION:
if (self.pd.thermalManager['temp_hotend'][0]['celsius'] < self.pd.EXTRUDE_MINTEMP):
self.pd.HMI_flag.ETempTooLow_flag = True
self.Popup_Window_ETempTooLow()
self.lcd.UpdateLCD()
return
self.checkkey = self.Extruder
self.pd.HMI_ValueStruct.Move_E_scale = self.pd.current_position.e * self.MINUNITMULT
self.lcd.Draw_Signed_Float(
self.lcd.font8x16, self.lcd.Select_Color, 3, 1, 216, self.MBASE(4),
self.pd.HMI_ValueStruct.Move_E_scale
)
self.lcd.UpdateLCD()
def HMI_Move_X(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
self.checkkey = self.AxisMove
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(1),
self.pd.HMI_ValueStruct.Move_X_scale
)
self.pd.jog(x=self.pd.current_position.x)
self.lcd.UpdateLCD()
return
elif (encoder_diffState == self.ENCODER_DIFF_CW):
self.pd.HMI_ValueStruct.Move_X_scale += 1
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
self.pd.HMI_ValueStruct.Move_X_scale -= 1
if self.pd.HMI_ValueStruct.Move_X_scale < (self.pd.X_MIN_POS) * self.MINUNITMULT:
self.pd.HMI_ValueStruct.Move_X_scale = (self.pd.X_MIN_POS) * self.MINUNITMULT
if self.pd.HMI_ValueStruct.Move_X_scale > (self.pd.X_MAX_POS) * self.MINUNITMULT:
self.pd.HMI_ValueStruct.Move_X_scale = (self.pd.X_MAX_POS) * self.MINUNITMULT
self.pd.current_position.x = self.pd.HMI_ValueStruct.Move_X_scale / 10
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Select_Color,
3, 1, 216, self.MBASE(1), self.pd.HMI_ValueStruct.Move_X_scale)
self.lcd.UpdateLCD()
def HMI_Move_Y(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
self.checkkey = self.AxisMove
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(2),
self.pd.HMI_ValueStruct.Move_Y_scale
)
self.pd.jog(y=self.pd.current_position.y)
self.lcd.UpdateLCD()
return
elif (encoder_diffState == self.ENCODER_DIFF_CW):
self.pd.HMI_ValueStruct.Move_Y_scale += 1
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
self.pd.HMI_ValueStruct.Move_Y_scale -= 1
if self.pd.HMI_ValueStruct.Move_Y_scale < (self.pd.Y_MIN_POS) * self.MINUNITMULT:
self.pd.HMI_ValueStruct.Move_Y_scale = (self.pd.Y_MIN_POS) * self.MINUNITMULT
if self.pd.HMI_ValueStruct.Move_Y_scale > (self.pd.Y_MAX_POS) * self.MINUNITMULT:
self.pd.HMI_ValueStruct.Move_Y_scale = (self.pd.Y_MAX_POS) * self.MINUNITMULT
self.pd.current_position.y = self.pd.HMI_ValueStruct.Move_Y_scale / 10
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Select_Color,
3, 1, 216, self.MBASE(2), self.pd.HMI_ValueStruct.Move_Y_scale)
self.lcd.UpdateLCD()
def HMI_Move_Z(self):
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):
self.checkkey = self.AxisMove
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Color_Bg_Black,
3, 1, 216, self.MBASE(3),
self.pd.HMI_ValueStruct.Move_Z_scale
)
self.pd.jog(z=self.pd.current_position.z)
self.lcd.UpdateLCD()
return
elif (encoder_diffState == self.ENCODER_DIFF_CW):
self.pd.HMI_ValueStruct.Move_Z_scale += 1
elif (encoder_diffState == self.ENCODER_DIFF_CCW):
self.pd.HMI_ValueStruct.Move_Z_scale -= 1
if self.pd.HMI_ValueStruct.Move_Z_scale < (self.pd.Z_MIN_POS) * self.MINUNITMULT:
self.pd.HMI_ValueStruct.Move_Z_scale = (self.pd.Z_MIN_POS) * self.MINUNITMULT
if self.pd.HMI_ValueStruct.Move_Z_scale > (self.pd.Z_MAX_POS) * self.MINUNITMULT:
self.pd.HMI_ValueStruct.Move_Z_scale = (self.pd.Z_MAX_POS) * self.MINUNITMULT
self.pd.current_position.z = self.pd.HMI_ValueStruct.Move_Z_scale / 10
self.lcd.Draw_FloatValue(
True, True, 0, self.lcd.font8x16, self.lcd.Color_White, self.lcd.Select_Color,
3, 1, 216, self.MBASE(3), self.pd.HMI_ValueStruct.Move_Z_scale)
self.lcd.UpdateLCD()
def HMI_Move_E(self):
self.pd.last_E_scale = 0
encoder_diffState = self.get_encoder_state()
if (encoder_diffState == self.ENCODER_DIFF_NO):
return
elif (encoder_diffState == self.ENCODER_DIFF_ENTER):