/
event.cpp
3496 lines (3088 loc) · 119 KB
/
event.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
#include <iostream>
#include <set>
#include <stack>
#include <algorithm>
// #include <boost/algorithm/string.hpp>
#include <cstdio>
#include <memory>
#include <stdexcept>
#include <array>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include "../include/KlippyGcodes.h"
#include "../include/send_msg.h"
#include "../include/event.h"
#include "../include/mks_printer.h"
#include "../include/mks_file.h"
#include "../include/mks_update.h"
#include "../include/mks_wpa_cli.h"
#include "../include/mks_test.h"
#include "../include/MakerbaseSerial.h"
#include "../include/MakerbaseClient.h"
#include "../include/MakerbaseShell.h"
#include "../include/MakerbasePanel.h"
#include "../include/MakerbaseParseIni.h"
#include "../include/MakerbaseWiFi.h"
#include "../include/ui.h"
#include "../include/send_jpg.h"
#include <nlohmann/json.hpp>
#define DEFAULT_DIR "gcodes/"
extern int tty_fd;
extern MakerbaseClient *ep;
extern bool gimage_is_showed;
extern bool simage_is_showed;
extern int current_page_id; // 当前页面的id号
extern int previous_page_id; // 上一页面的id号
extern int next_page_id; // 下一页面的id号
/* Printer Extern Varible*/
extern bool mks_led_status;
extern bool mks_beep_status;
extern bool mks_fila_status;
extern int mks_language_status;
extern int mks_extruder_target;
extern int mks_heater_bed_target;
extern int mks_hot_target;
extern std::string mks_babystep_value;
extern std::string mks_adxl_offset;
extern std::string mks_version_soc;
extern std::string mks_version_mcu;
extern std::string mks_version_ui;
extern std::string printer_webhooks_state;
extern std::string printer_webhooks_state_message;
extern std::string current_webhooks_state_message;
extern float printer_gcode_move_speed_factor;
float current_speed_factor = 0;
extern float printer_gcode_move_speed;
float current_extruder_factor = 0;
extern float printer_gcode_move_extrude_factor;
extern float printer_gcode_move_homing_origin[4]; // [X, Y, Z, E] - 返回应用于每个轴的“gcode 偏移”。例如,可以检查“Z”轴以确定通过“babystepping”应用了多少偏移量。
extern float printer_gcode_move_position[4];
extern float printer_gcode_move_gcode_position[4];
extern std::string printer_toolhead_homed_axes;
extern float printer_toolhead_print_time;
extern float printer_toolhead_extimated_print_time;
extern double printer_toolhead_position[4];
extern double printer_toolhead_axis_minimum[4];
extern double printer_toolhead_axis_maximum[4];
extern double x_position;
extern double y_position;
extern double z_position;
extern float e_position;
extern double gcode_z_position;
extern int printer_extruder_temperature;
int current_extruder_temperature = 0;
extern int printer_extruder_target;
int current_extruder_target = 0;
extern int printer_heater_bed_temperature;
int current_heater_bed_temperature = 0;
extern int printer_heater_bed_target;
int current_heater_bed_target = 0;
extern int printer_hot_temperature;
int current_hot_temperature = 0;
extern int printer_hot_target;
int current_hot_target = 0;
extern float printer_fan_speed;
extern float printer_heater_fan_speed;
extern float printer_heater_fan_my_nozzle_fan1_speed;
extern float printer_out_pin_fan0_value;
float current_out_pin_fan0_value = 0;
extern float printer_out_pin_fan3_value;
float current_out_pin_fan3_value =0;
extern float printer_out_pin_fan2_value;
float current_out_pin_fan2_value = 0;
extern float printer_out_pin_beep_value;
extern std::string printer_idle_timeout_state;
extern float printer_printing_time;
extern std::string printer_print_stats_filename;
extern float printer_print_stats_total_duration;
extern float printer_print_stats_print_duration;
extern float printer_print_stats_filament_used;
extern std::string printer_print_stats_state; // 这个状态很有用
extern std::string printer_print_stats_message; // error detected, error message
extern std::string printer_display_status_message;
extern int printer_display_status_progress;
extern float auto_level_dist;
extern bool auto_level_finished;
extern bool auto_level_enabled;
std::string str_manual_level_offset;
extern float manual_level_dist;
extern int manual_level_count;
extern bool manual_level_finished;
extern float printer_bed_mesh_mesh_min[2];
extern float printer_bed_mesh_mesh_max[2];
extern float printer_bed_mesh_profiles_mks_points[5][5];
extern float printer_bed_mesh_profiles_mks_mesh_params_tension;
extern float printer_bed_mesh_profiles_mks_mesh_params_mesh_x_pps;
extern std::string printer_bed_mesh_profiles_mks_mesh_params_algo;
extern float printer_bed_mesh_profiles_mks_mesh_params_min_x;
extern float printer_bed_mesh_profiles_mks_mesh_params_min_y;
extern float printer_bed_mesh_profiles_mks_mesh_params_x_count;
extern float printer_bed_mesh_profiles_mks_mesh_params_y_count;
extern float printer_bed_mesh_profiles_mks_mesh_params_mesh_y_pps;
extern float printer_bed_mesh_profiles_mks_mesh_params_max_x;
extern float printer_bed_mesh_profiles_mks_mesh_params_max_y;
extern float page_set_zoffset_x_y_position[16][2];
extern float page_set_zoffset_z_position[16];
extern bool fresh_page_set_zoffset_data;
extern bool refresh_page_auto_finish_data;
extern int page_set_zoffset_index;
// filament switch sensor fila
extern bool filament_switch_sensor_fila_filament_detected;
extern bool filament_switch_sensor_fila_enabled;
extern float printer_caselight_value;
extern int printer_pause_taget;
extern bool printer_pause_resume_is_paused;
extern float printer_set_offset;
extern float printer_z_offset;
extern float printer_intern_z_offset;
extern float printer_extern_z_offset;
extern float printer_move_dist;
extern int printer_filament_extruder_target;
extern int printer_filament_extruedr_dist;
// probe
extern float printer_probe_x_zoffset;
extern float printer_probe_y_zoffset;
extern float printer_probe_z_zoffset;
// printer info software version
extern std::string printer_info_software_version;
/* wifi */
extern std::string page_wifi_ssid_list[5];
extern int page_wifi_current_pages;
extern int page_wifi_ssid_list_pages;
extern std::string get_wifi_name;
/* 文件列表处理相关变量 */
// extern std::set<std::string> page_files_dirname_filename_list;
extern bool filelist_changed;
extern int page_files_pages;
extern int page_files_current_pages;
extern int page_files_folder_layers;
extern std::string page_files_previous_path;
extern std::string page_files_root_path;
extern std::string page_files_path;
extern std::string page_files_list_name[9]; // 文件列表显示文件名称
extern std::string page_files_list_show_name[9]; // 文件列表名称
extern std::string page_files_list_show_type[9]; // 文件类型: [f]或者[d],或者[n]
extern std::stack<std::string> page_files_path_stack; // 路径栈
extern std::string page_files_root_path; // Klippy根目录
extern std::string page_files_previous_path; // 之前的路径
extern std::string page_files_path; // 文件所在路径
extern std::string page_files_print_files_path; // 要打印的文件路径
extern int file_metadata_estimated_time;
extern std::string file_metadata_filename;
extern float file_metadata_filament_total;
extern int file_metadata_object_height;
extern std::string file_metadata_filament_name;
extern std::string file_metadata_filament_type;
extern float file_metadata_filament_weight_total;
extern std::string file_metadata_gimage;
extern std::string file_metadata_simage;
extern int level_mode;
extern bool printing_keyboard_enabled;
// extern bool filament_keyboard_enabled;
extern bool auto_level_button_enabled;
extern bool manual_level_button_enabled;
extern bool show_preview_complete;
extern bool show_preview_gimage_completed;
/* 补偿值 */
float page_set_zoffset_number;
/* 共振补偿值 */
std::string page_syntony_shaper_freq_x = "";
std::string page_syntony_shaper_freq_y = "";
bool page_syntony_finished = false;
/* PID调节 */
bool page_pid_finished = false;
/* wifi */
extern struct mks_wifi_status_result_t status_result;
extern struct mks_wifi_status_t wpa_status;
std::string wifi_ip_address;
/* 打完关机 */
bool page_printing_shutdown_enable = false;
/* wifi键盘打开判断 */
extern bool printing_wifi_keyboard_enabled;
/* refresh about success*/
bool page_about_successed = false;
extern bool is_download_to_screen; // main.cpp 里面的变量
/* update page */
extern int filesize;
/* server history totals */
extern int total_jobs;
extern double total_time;
extern double total_print_time;
extern double total_filament_used;
/* 800个小时 */
int mks_total_printed_minutes;
/* 设置打印调平的目标温度 */
extern int level_mode_printing_extruder_target;
extern int level_mode_printing_heater_bed_target;
extern bool level_mode_printing_is_printing_level;
/* wifi 相关 */
std::string current_connected_ssid_name = "";
extern bool page_wifi_list_ssid_button_enabled[5];
// page print filament
extern bool page_print_filament_extrude_restract_button;
extern bool page_filament_extrude_button;
// oobe开箱引导
bool mks_oobe_enabled = false;
bool current_mks_oobe_enabled = false;
// 调平
bool start_pre_auto_level = false;
bool start_pre_manual_level = false;
bool all_level_saving = false;
extern bool mks_file_parse_finished;
// reset
// extern bool page_reset_to_about;
// 正在保存页面
bool is_refresh_page_saving = false;
std::string temp_idle_state = "";
// oobe
extern float oobe_printer_set_offset;
//extern std::string printed_file_path;
bool jump_to_print = false;
int printer_auto_level_heater_bed_target;
extern std::string filament_message;
bool printer_ready = false;
extern bool page_filament_unload_button;
extern bool printer_bed_leveling;
//4.4.1 CLL 耗材确认弹窗新增不再提示按钮
extern bool preview_pop_1_on;
extern bool preview_pop_2_on;
//4.4.1 CLL 修复断料检测与退料冲突bug
bool previous_filament_sensor_state = false;
//4.4.1 CLL 修改调平
std::string previous_zoffset;
//4.4.2 CLL 新增息屏功能
extern bool previous_caselight_value;
//4.4.2 CLL 修改调平不再需要设置zoffset值
bool step_1 = false;
bool step_2 = false;
bool step_3 = false;
bool step_4 = false;
//4.4.2 CLL 适配mates和霍尔耗材宽度探测器
bool filament_detected = true;
//4.4.2 CLL 文件列表新增本地、U盘切换按钮
extern std::string file_mode;
extern int manual_count;
float bed_offset;
extern std::string adjust_mode;
extern std::string set_mode;
extern bool move_fan_setting;
extern std::string thumbnail_path;
extern bool cache_clicked;
// CLL 以下变量用于修复gcode响应函数和refresh函数之间的冲突(gcode响应函数需设置变量在refresh_page_show中统一改变页面,否则会产生冲突)
bool jump_to_move_pop_1 = false;
bool jump_to_move_pop_2 = false;
bool jump_to_detect_error = false;
bool jump_to_level_error = false;
bool jump_to_filament_pop_1 = false;
bool jump_to_print_low_temp = false;
bool jump_to_memory_warning = false;
bool jump_to_resume_print = false;
std::string error_message;
bool main_picture_detected = false; // CLL 此变量用于检测cache中图片是否存在
bool main_picture_refreshed = false; // CLL 此变量用于标记主页面图片是否已经刷新过,防止反复刷新
extern int load_target;
int connection_method; // CLL 此变量用于记录二维码是否是局域网刷新 0为局域网连接,1为互联网连接
std::map<int, Server_config> serverConfigs;
std::string selected_server;
int current_server_page;
int total_server_count;
std::string target_soc_version;
bool open_qr_refreshed = false; // CLL 第一次开机刷新时不使用脚本重新生成二维码图片
extern bool qr_refreshed;
bool open_reprint_asked = false; // CLL 开机后进入主页面发出检测断电续打指令
/* 更新页面处理 */
void refresh_page_show() {
// CLL 以下if检测函数为无条件跳转,其在改变为true之前已经经过函数判断(跳转页面前需将对应变量置为false,否则会陷入死循环)
if (jump_to_move_pop_1 == true) {
jump_to_move_pop_1 = false;
page_to(TJC_PAGE_MOVE_POP_1);
}
if (jump_to_move_pop_2 == true) {
jump_to_move_pop_2 = false;
page_to(TJC_PAGE_MOVE_POP_2);
}
if (jump_to_detect_error == true) {
jump_to_detect_error = false;
page_to(TJC_PAGE_DETECT_ERROR);
send_cmd_txt(tty_fd, "t0", error_message);
}
if (jump_to_level_error == true) {
jump_to_level_error = false;
page_to(TJC_PAGE_LEVEL_ERROR);
}
if (jump_to_filament_pop_1 == true) {
jump_to_filament_pop_1 = false;
page_to(TJC_PAGE_FILAMENT_POP_1);
}
if (jump_to_print_low_temp == true) {
jump_to_print_low_temp = false;
page_to(TJC_PAGE_PRINT_LOW_TEMP);
}
if (jump_to_resume_print == true) {
jump_to_resume_print = false;
page_to(TJC_PAGE_RESUME_PRINT);
}
if (jump_to_memory_warning == true) {
jump_to_memory_warning = false;
page_to(TJC_PAGE_MEMORY_WARNING);
}
if (current_page_id != TJC_PAGE_PRINTING) {
switch (current_page_id)
{
case TJC_PAGE_PRINT_ZOFFSET:
break;
case TJC_PAGE_PRINT_FILAMENT:
break;
case TJC_PAGE_PRINT_STOP:
case TJC_PAGE_PRINT_NO_FILAMENT:
case TJC_PAGE_PRINT_NO_FILAMENT_2:
case TJC_PAGE_SHUTDOWN:
case TJC_PAGE_PRINT_STOPPING:
case TJC_PAGE_MOVE_POP_1:
case TJC_PAGE_GCODE_ERROR:
case TJC_PAGE_DETECT_ERROR:
case TJC_PAGE_RESET:
case TJC_PAGE_PREVIEW:
case TJC_PAGE_PREVIEW_POP_1:
case TJC_PAGE_PREVIEW_POP_2:
case TJC_PAGE_PRINTING_2:
case TJC_PAGE_FILAMENT_POP_2:
case TJC_PAGE_FILAMENT_POP_3:
break;
default:
if (printer_print_stats_state == "printing") {
if (printer_print_stats_filename != "") {
main_picture_detected = false;
main_picture_refreshed = false;
MKSLOG_BLUE("跳入到打印函数\n");
sleep(1);
get_file_estimated_time(printer_print_stats_filename);
sleep(1);
//4.4.2 CLL 新增息屏功能
if (previous_caselight_value == true) {
led_on_off();
previous_caselight_value = false;
}
jump_to_print = true;
printer_ready = false;
page_to(TJC_PAGE_PREVIEW);
break;
}
}
break;
}
}
if (current_page_id != TJC_PAGE_RESET) {
switch (current_page_id)
{
case TJC_PAGE_GCODE_ERROR:
case TJC_PAGE_DETECT_ERROR:
case TJC_PAGE_LEVEL_ERROR:
case TJC_PAGE_SHUTDOWN:
case TJC_PAGE_SERVICE:
case TJC_PAGE_LANGUAGE:
case TJC_PAGE_COMMON_SETTING:
case TJC_PAGE_SLEEP_MODE:
case TJC_PAGE_INTERNET:
case TJC_PAGE_WIFI_LIST:
case TJC_PAGE_WIFI_KB:
case TJC_PAGE_WIFI_CONNECT:
case TJC_PAGE_WIFI_FAILED:
case TJC_PAGE_WIFI_SUCCESS:
case TJC_PAGE_WIFI_SAVING:
case TJC_PAGE_UPDATE_FOUND:
case TJC_PAGE_UPDATE_NOT_FOUND:
case TJC_PAGE_UPDATING:
case TJC_PAGE_UPDATE_FINISH:
case TJC_PAGE_RESTORE_CONFIG:
case TJC_PAGE_SHOW_QR:
case TJC_PAGE_SERVER_SET:
case TJC_PAGE_UPDATE_MODE:
case TJC_PAGE_ONLINE_UPDATE:
case TJC_PAGE_SEARCH_SERVER:
break;
default:
// 喷头板断开的情况下跳到重启页面
if (printer_webhooks_state == "shutdown" || printer_webhooks_state == "error") {
if (printer_webhooks_state == "shutdown" && (current_page_id == TJC_PAGE_AUTO_MOVING || current_page_id == TJC_PAGE_OPEN_CALIBRATE)) {
break;
}
if (previous_caselight_value == true) {
led_on_off();
previous_caselight_value = false;
}
page_to(TJC_PAGE_RESET);
std::cout << "重启页面" << std::endl;
if (current_webhooks_state_message != printer_webhooks_state_message) {
current_webhooks_state_message = printer_webhooks_state_message;
std::string temp = printer_webhooks_state_message;
replace(temp.begin(), temp.end(), '\n', '.');
replace(temp.begin(), temp.end(), '\'', ' ');
replace(temp.begin(), temp.end(), '\"', ' ');
send_cmd_txt(tty_fd, "t0", temp);
}
}
break;
}
} else if (current_page_id == TJC_PAGE_RESET) {
if (printer_webhooks_state == "shutdown" || printer_webhooks_state == "error") {
if (current_webhooks_state_message != printer_webhooks_state_message) {
current_webhooks_state_message = printer_webhooks_state_message;
std::string temp = printer_webhooks_state_message;
replace(temp.begin(), temp.end(), '\n', '.');
replace(temp.begin(), temp.end(), '\'', ' ');
replace(temp.begin(), temp.end(), '\"', ' ');
send_cmd_txt(tty_fd, "t0", temp);
}
}
if (printer_webhooks_state == "ready") {
page_to(TJC_PAGE_SYS_OK);
}
}
switch (current_page_id)
{
case TJC_PAGE_MAIN:
refresh_page_main();
break;
case TJC_PAGE_PREVIEW:
refresh_page_preview();
break;
case TJC_PAGE_PRINTING:
case TJC_PAGE_PRINTING_2:
refresh_page_printing();
break;
case TJC_PAGE_PRINT_FILAMENT:
refresh_page_print_filament();
break;
case TJC_PAGE_MOVE:
refresh_page_move();
break;
case TJC_PAGE_PRINT_ZOFFSET:
refresh_page_printing_zoffset();
break;
case TJC_PAGE_AUTO_MOVING:
refresh_page_auto_moving();
break;
case TJC_PAGE_AUTO_FINISH:
refresh_page_auto_finish();
break;
case TJC_PAGE_SYNTONY_MOVE:
refresh_page_syntony_move();
break;
case TJC_PAGE_SYNTONY_FINISH:
// refresh_page_syntony_finish();
break;
case TJC_PAGE_PRINT_STOPPING:
refresh_page_stopping();
break;
case TJC_PAGE_PRE_BED_CALIBRATION:
refresh_page_auto_level();
break;
case TJC_PAGE_WIFI_LIST:
refresh_page_wifi_list_2();
break;
case TJC_PAGE_OPEN_FILAMENTVIDEO_2:
refresh_page_open_filament_video_2();
break;
case TJC_PAGE_ZOFFSET:
refresh_page_zoffset();
break;
case TJC_PAGE_AUTO_HEATERBED:
refresh_page_auto_heaterbed();
break;
case TJC_PAGE_OPEN_HEATERBED:
refresh_page_open_heaterbed();
break;
case TJC_PAGE_FILAMENT_POP_2:
case TJC_PAGE_FILAMENT_POP_3:
refresh_page_filament_pop();
break;
case TJC_PAGE_PREVIEW_POP_1:
case TJC_PAGE_PREVIEW_POP_2:
refresh_page_preview_pop();
break;
//4.4.2 CLL 文件列表新增本地、U盘切换按钮
case TJC_PAGE_FILE_LIST:
// refresh_page_files_list_2();
break;
case TJC_PAGE_BED_MOVING:
refresh_page_bed_moving();
break;
case TJC_PAGE_OPEN_CALIBRATE:
refresh_page_open_calibrate();
break;
case TJC_PAGE_COMMON_SETTING:
refresh_page_common_setting();
break;
case TJC_PAGE_FILAMENT_SET_FAN:
refresh_page_filament_set_fan();
break;
case TJC_PAGE_WIFI_KB:
refresh_page_wifi_keyboard();
break;
case TJC_PAGE_FILAMENT:
refresh_page_filament();
break;
case TJC_PAGE_SHOW_QR:
refresh_page_show_qr();
break;
case TJC_PAGE_SERVER_SET:
refresh_page_server_set();
break;
case TJC_PAGE_AUTO_UNLOAD:
refresh_page_auto_unload();
break;
default:
break;
}
}
void refresh_page_open_filament_video_2() {
if (printer_extruder_target == 0) {
send_cmd_pco(tty_fd, "t0", "65535");
send_cmd_pco(tty_fd, "n0", "65535");
send_cmd_picc(tty_fd, "b3", "9");
send_cmd_picc2(tty_fd, "b3", "25");
} else {
send_cmd_pco(tty_fd, "t0", "63488");
send_cmd_pco(tty_fd, "n0", "63488");
send_cmd_picc(tty_fd, "b3", "10");
send_cmd_picc2(tty_fd, "b3", "24");
}
send_cmd_txt(tty_fd, "t0", std::to_string(printer_extruder_temperature) + "/");
send_cmd_val(tty_fd, "n0", std::to_string(printer_extruder_target));
}
void refresh_page_wifi_keyboard() {
if (printing_wifi_keyboard_enabled == true) {
send_cmd_txt(tty_fd, "t0", get_wifi_name);
}
}
void refresh_page_syntony_finish() {
MKSLOG_BLUE("Printer ide_timeout state: %s", printer_idle_timeout_state.c_str());
MKSLOG_BLUE("Printer webhooks state: %s", printer_webhooks_state.c_str());
if (page_syntony_finished == false) {
page_syntony_finished = true;
all_level_saving = false;
}
if (printer_idle_timeout_state == "Ready" && printer_webhooks_state == "ready") {
MKSLOG_BLUE("Printer webhooks state: %s", printer_webhooks_state.c_str());
sleep(10);
system("sync"); // 保存好配置文件
all_level_saving = false;
init_mks_status(); // 重启后初始化之前保存的参数
sub_object_status();
get_object_status();
sleep(10);
page_to(TJC_PAGE_LEVEL_MODE);
MKSLOG_RED("从739行跳出去");
}
}
void refresh_page_auto_level() {
if (auto_level_dist == (float)0.01) {
send_cmd_picc(tty_fd, "b0", "113");
send_cmd_picc(tty_fd, "b1", "114");
send_cmd_picc(tty_fd, "b2", "114");
send_cmd_picc(tty_fd, "b3", "114");
send_cmd_picc2(tty_fd, "b0", "116");
send_cmd_picc2(tty_fd, "b1", "115");
send_cmd_picc2(tty_fd, "b2", "115");
send_cmd_picc2(tty_fd, "b3", "115");
} else if (auto_level_dist == (float)0.05) {
send_cmd_picc(tty_fd, "b0", "114");
send_cmd_picc(tty_fd, "b1", "113");
send_cmd_picc(tty_fd, "b2", "114");
send_cmd_picc(tty_fd, "b3", "114");
send_cmd_picc2(tty_fd, "b0", "115");
send_cmd_picc2(tty_fd, "b1", "116");
send_cmd_picc2(tty_fd, "b2", "115");
send_cmd_picc2(tty_fd, "b3", "115");
} else if (auto_level_dist == (float)0.1) {
send_cmd_picc(tty_fd, "b0", "114");
send_cmd_picc(tty_fd, "b1", "114");
send_cmd_picc(tty_fd, "b2", "113");
send_cmd_picc(tty_fd, "b3", "114");
send_cmd_picc2(tty_fd, "b0", "115");
send_cmd_picc2(tty_fd, "b1", "115");
send_cmd_picc2(tty_fd, "b2", "116");
send_cmd_picc2(tty_fd, "b3", "115");
} else if (auto_level_dist == (float)1) {
send_cmd_picc(tty_fd, "b0", "114");
send_cmd_picc(tty_fd, "b1", "114");
send_cmd_picc(tty_fd, "b2", "114");
send_cmd_picc(tty_fd, "b3", "113");
send_cmd_picc2(tty_fd, "b0", "115");
send_cmd_picc2(tty_fd, "b1", "115");
send_cmd_picc2(tty_fd, "b2", "115");
send_cmd_picc2(tty_fd, "b3", "116");
}
}
void refresh_page_stopping() {
MKSLOG_BLUE("Printer ide_timeout state: %s", printer_idle_timeout_state.c_str());
MKSLOG_BLUE("Printer webhooks state: %s", printer_webhooks_state.c_str());
if (printer_idle_timeout_state == "Ready") {
clear_previous_data();
sleep(5);
save_current_zoffset();
page_to(TJC_PAGE_MAIN);
}
}
void refresh_page_syntony_move() {
if (temp_idle_state != printer_idle_timeout_state) {
temp_idle_state = printer_idle_timeout_state;
MKSLOG_BLUE("Printer ide_timeout state: %s", printer_idle_timeout_state.c_str());
MKSLOG_BLUE("Printer webhooks state: %s", printer_webhooks_state.c_str());
}
if (step_1 == true) {
sleep(15);
page_to(TJC_PAGE_SYNTONY_FINISH);
}
}
void refresh_page_print_filament() {
send_cmd_txt(tty_fd, "t5", printer_print_stats_filename.substr(printer_print_stats_filename.rfind("/") +1 ));
if (printer_extruder_target == 0) {
send_cmd_pco(tty_fd, "t2", "65535");
send_cmd_picc(tty_fd, "b0", "63");
send_cmd_picc2(tty_fd, "b0", "64");
} else {
send_cmd_pco(tty_fd, "t2", "63488");
send_cmd_picc(tty_fd, "b0", "62");
send_cmd_picc2(tty_fd, "b0", "65");
}
send_cmd_val(tty_fd, "j0", std::to_string(printer_display_status_progress));
send_cmd_val(tty_fd, "n7", std::to_string(printer_display_status_progress));
send_cmd_txt(tty_fd, "t2", std::to_string(printer_extruder_temperature));
send_cmd_txt(tty_fd, "t3", std::to_string(printer_extruder_target));
send_cmd_txt(tty_fd, "t0", show_time((int)(printer_print_stats_print_duration)));
send_cmd_txt(tty_fd, "t1", show_time(get_cal_printing_time((int)(printer_print_stats_print_duration), file_metadata_estimated_time, printer_display_status_progress)));
if (printer_print_stats_state == "paused") {
printer_ready = true;
}
//4.4.2 CLL 适配mates和霍尔耗材宽度检测器
if (filament_detected == false) {
sleep(1);
printer_ready = false;
set_print_pause();
page_to(TJC_PAGE_PRINT_NO_FILAMENT);
}
if (printer_print_stats_state == "printing") {
if (printer_ready == true) {
printer_ready = false;
page_to(TJC_PAGE_PRINTING);
}
}
if (printer_print_stats_state == "standby") {
page_to(TJC_PAGE_PRINT_STOPPING);
}
if (printer_print_stats_state == "error") {
page_to(TJC_PAGE_GCODE_ERROR);
cancel_print();
clear_previous_data();
send_cmd_txt(tty_fd, "t0", "gcode error:" + error_message);
}
//4.4.2 CLL 长时间暂停使打印停止后会跳转页面
if (printer_idle_timeout_state == "Idle") {
ep->Send(json_run_a_gcode("G28\n"));
cancel_print();
}
}
void refresh_page_auto_finish() {
if ( printer_idle_timeout_state == "Idle" && printer_webhooks_state == "ready" ) {
auto_level_finished = true;
}
}
void refresh_page_auto_moving() {
if (step_1 == true) {
send_cmd_picc(tty_fd, "q0", "109");
send_cmd_pco(tty_fd, "t1", "65535");
send_cmd_pco(tty_fd, "t0", "38066");
send_cmd_vis(tty_fd, "gm1", "0");
send_cmd_vis(tty_fd, "gm2", "1");
step_1 = false;
}
if (step_2 == true) {
send_cmd_picc(tty_fd, "q0", "110");
send_cmd_pco(tty_fd, "t2", "65535");
send_cmd_pco(tty_fd, "t1", "38066");
send_cmd_vis(tty_fd, "gm2", "0");
send_cmd_vis(tty_fd, "gm3", "1");
step_2 = false;
}
if (step_3 == true) {
send_cmd_picc(tty_fd, "q0", "111");
send_cmd_pco(tty_fd, "t3", "65535");
send_cmd_pco(tty_fd, "t2", "38066");
send_cmd_vis(tty_fd, "gm3", "0");
send_cmd_vis(tty_fd, "gm4", "1");
step_3 = false;
printer_idle_timeout_state = "Printing";
get_mks_heater_bed_target();
set_heater_bed_target(mks_heater_bed_target);
ep->Send(json_run_a_gcode("M190 S" + std::to_string(mks_heater_bed_target) + "\n"));
sleep(1);
ep->Send(json_run_a_gcode("M4027\n"));
}
if (step_4 == true) {
sleep(15);
page_to(TJC_PAGE_AUTO_FINISH);
step_4 = false;
}
}
void refresh_page_move() {
std::string x_pos = std::to_string(x_position);
x_pos = x_pos.substr(0, x_pos.find(".") + 2);
std::string y_pos = std::to_string(y_position);
y_pos = y_pos.substr(0, y_pos.find(".") + 2);
std::string z_pos = std::to_string(z_position);
z_pos = z_pos.substr(0, z_pos.find(".") + 2);
send_cmd_txt(tty_fd, "t0", x_pos);
send_cmd_txt(tty_fd, "t1", y_pos);
send_cmd_txt(tty_fd, "t2", z_pos);
// CLL 刷新所选择距离
if (printer_move_dist == (float)0.1) {
send_cmd_picc(tty_fd, "b0", "77");
send_cmd_picc2(tty_fd, "b0", "74");
send_cmd_picc(tty_fd, "b1", "76");
send_cmd_picc2(tty_fd, "b1", "75");
send_cmd_picc(tty_fd, "b2", "76");
send_cmd_picc2(tty_fd, "b2", "75");
} else if (printer_move_dist == (float)1.0) {
send_cmd_picc(tty_fd, "b0", "76");
send_cmd_picc2(tty_fd, "b0", "75");
send_cmd_picc(tty_fd, "b1", "77");
send_cmd_picc2(tty_fd, "b1", "74");
send_cmd_picc(tty_fd, "b2", "76");
send_cmd_picc2(tty_fd, "b2", "75");
} else if (printer_move_dist == (float)10) {
send_cmd_picc(tty_fd, "b0", "76");
send_cmd_picc2(tty_fd, "b0", "75");
send_cmd_picc(tty_fd, "b1", "76");
send_cmd_picc2(tty_fd, "b1", "75");
send_cmd_picc(tty_fd, "b2", "77");
send_cmd_picc2(tty_fd, "b2", "74");
}
}
void refresh_page_offset(float intern_zoffset) {
printer_intern_z_offset = intern_zoffset;
printer_z_offset = printer_intern_z_offset + printer_extern_z_offset;
}
void refresh_page_printing_zoffset() {
std::string z_offset = std::to_string(printer_gcode_move_homing_origin[2]);
std::string show_gcode_z = std::to_string(gcode_z_position);
z_offset = z_offset.substr(0, z_offset.find(".") + 4);
show_gcode_z = show_gcode_z.substr(0, show_gcode_z.find(".") + 4);
send_cmd_txt(tty_fd, "t4", printer_print_stats_filename.substr(printer_print_stats_filename.rfind("/") +1 ));
if (z_offset != mks_babystep_value) {
mks_babystep_value = z_offset;
set_mks_babystep(mks_babystep_value);
}
send_cmd_txt(tty_fd, "t2", show_gcode_z);
send_cmd_txt(tty_fd, "t3", z_offset);
send_cmd_txt(tty_fd, "t0", show_time((int)(printer_print_stats_print_duration)));
send_cmd_val(tty_fd, "n7", std::to_string(printer_display_status_progress));
send_cmd_txt(tty_fd, "t1", show_time(get_cal_printing_time((int)(printer_print_stats_print_duration), file_metadata_estimated_time, printer_display_status_progress)));
send_cmd_val(tty_fd, "j0", std::to_string(printer_display_status_progress));
if (printer_print_stats_state == "printing") {
printer_ready = true;
}
if (filament_switch_sensor_fila_enabled == true) {
if (filament_switch_sensor_fila_filament_detected == false) {
printer_ready = false;
set_print_pause();
page_to(TJC_PAGE_PRINT_NO_FILAMENT_2);
}
}
//4.4.2 CLL 适配mates与霍尔耗材宽度检测器
if (filament_detected == false) {
sleep(1);
printer_ready = false;
set_print_pause();
page_to(TJC_PAGE_PRINT_NO_FILAMENT);
}
if (printer_print_stats_state == "standby") {
page_to(TJC_PAGE_PRINT_STOPPING);
}
if (printer_print_stats_state == "paused") {
if (printer_ready == true) {
printer_ready = false;
page_to(TJC_PAGE_PRINT_FILAMENT);
}
}
if (printer_print_stats_state == "complete") {
std::string time_duration = show_time((int)(printer_print_stats_print_duration));
complete_print();
clear_previous_data();
sleep(5);
save_current_zoffset();
page_to(TJC_PAGE_PRINT_FINISH);
send_cmd_txt(tty_fd, "t1", time_duration);
}
if (printer_print_stats_state == "error") {
page_to(TJC_PAGE_GCODE_ERROR);
cancel_print();
clear_previous_data();
send_cmd_txt(tty_fd , "t0", "gcode error:" + error_message);
}
if (printer_set_offset == (float)0.01) {
send_cmd_picc(tty_fd, "b1", std::to_string(57));