Skip to content

Commit

Permalink
1.Optimized the logic of material breakage detection
Browse files Browse the repository at this point in the history
2.Optimized page jump logic after resonance

3.Added the function of exporting logs

4.Revise and reset the factory settings function

5.Adjusted the rising distance during boot up guidance
  • Loading branch information
Rainboooom committed Oct 6, 2023
1 parent d3419e2 commit 73eb9bd
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 55 deletions.
9 changes: 9 additions & 0 deletions include/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,13 @@ std::string replaceCharacters(const std::string& path, const std::string& search
void restore_config();
void refresh_page_restoring();

//4.2.10 CLL 新增输出日志功能
void print_log();

//4.2.10 CLL 修改断料检测开关逻辑
void filament_sensor_switch(bool status);

//4.2.10 CLL 新增共振补偿超时强制跳转
void send_gcode(std::string command);

#endif
13 changes: 13 additions & 0 deletions include/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#define TJC_PAGE_OPEN_LEVELED_FINISH 0x02

#define TJC_PAGE_OPEN_SYNTONY 6
//4.2.10 CLL 新增共振补偿超时强制跳转
#define TJC_PAGE_OPEN_SYNTONY_JUMP_OUT 0x00

#define TJC_PAGE_OPEN_FILAMENT_1 7 // 作废
#define TJC_PAGE_OPEN_FILAMENT_1_NEXT 0x02 // 作废
Expand Down Expand Up @@ -348,6 +350,8 @@
#define TJC_PAGE_SET_ZOFFSET_B16 0x16

#define TJC_PAGE_SYNTONY_MOVE 42
//4.2.10 CLL 新增共振补偿超时强制跳转
#define TJC_PAGE_SYNTONY_MOVE_JUMP_OUT 0x00

#define TJC_PAGE_SYNTONY_FINISH 43

Expand Down Expand Up @@ -443,6 +447,8 @@
#define TJC_PAGE_ABOUT_OOBE 0x0e
//4.2.7 CLL 新增恢复出厂设置功能
#define TJC_PAGE_ABOUT_RESTORE 0x0f
//4.2.10 CLL 新增输出日志功能
#define TJC_PAGE_ABOUT_PRINT_LOG 0x10

#define TJC_PAGE_PRINT_F_POP 53
#define TJC_PAGE_PRINT_F_POP_YES 0x02
Expand Down Expand Up @@ -506,6 +512,8 @@
#define TJC_PAGE_NO_UPDATA_OOBE 0x0e
//4.2.7 CLL 新增恢复出厂设置功能
#define TJC_PAGE_NO_UPDATA_RESTORE 0x0f
//4.2.10 CLL 新增输出日志功能
#define TJC_PAGE_NO_UPDATA_PRINT_LOG 0x10

#define TJC_PAGE_KEYDBA 51
#define TJC_PAGE_KEYDBA_HOME 0x2c
Expand Down Expand Up @@ -673,6 +681,11 @@

#define TJC_PAGE_RESTORING 116

//4.2.10 CLL 新增输出日志功能
#define TJC_PAGE_PRINT_LOG_S 117
#define TJC_PAGE_PRINT_LOG_F 118
#define TJC_PAGE_PRINT_LOG_YES 0x00

#endif


Expand Down
104 changes: 82 additions & 22 deletions src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ void refresh_page_show() {
if (printer_print_stats_state == "printing") {
if (printer_print_stats_filename != "") {
sleep(5);
//4.2.10 CLL 修改断料检测开关逻辑
if (mks_fila_status == true) {
filament_sensor_switch(true);
}
MKSLOG_BLUE("跳入到打印函数\n");
//4.2.5 CLL 新增息屏功能
if (previous_caselight_value == true) {
Expand Down Expand Up @@ -1018,7 +1022,7 @@ void refresh_page_syntony_finish() {
MKSLOG_BLUE("Printer webhooks state: %s", printer_webhooks_state.c_str());
if (page_syntony_finished == false) {
page_syntony_finished = true;
ep->Send(json_run_a_gcode("SAVE_CONFIG"));
//ep->Send(json_run_a_gcode("SAVE_CONFIG"));
all_level_saving = false;
}

Expand Down Expand Up @@ -1144,7 +1148,8 @@ void refresh_page_about() {

//4.2.5 CLL 修复UI按下效果
void refresh_page_auto_level() {
send_cmd_txt(tty_fd, "t1", std::to_string(printer_gcode_move_homing_origin[2]).substr(0,5) + "mm");
//4.2.10 使调平界面显示最终zoffset值
send_cmd_txt(tty_fd, "t1", std::to_string(printer_gcode_move_homing_origin[2] - 0.15).substr(0,5) + "mm");
if (auto_level_dist == (float)0.01) {
send_cmd_picc(tty_fd, "b3", "95");
send_cmd_picc2(tty_fd, "b3", "317");
Expand Down Expand Up @@ -1202,7 +1207,8 @@ void refresh_page_stopping() {

//4.2.5 CLL 新增设置Z轴偏移页面
void refresh_page_set_zoffset_2() {
send_cmd_txt(tty_fd, "t1", std::to_string(printer_gcode_move_homing_origin[2]).substr(0,5) + "mm");
//4.2.10 CLL 使调平界面显示最终zoffset值
send_cmd_txt(tty_fd, "t1", std::to_string(printer_gcode_move_homing_origin[2] - 0.15).substr(0,5) + "mm");
if (auto_level_dist == (float)0.01) {
send_cmd_picc(tty_fd, "b3", "95");
send_cmd_picc2(tty_fd, "b3", "317");
Expand Down Expand Up @@ -1423,8 +1429,12 @@ void refresh_page_print_filament() {
//2023.4.20 网页暂停开始与UI相匹配
if (printer_print_stats_state == "printing") {
if (printer_ready == true) {
page_to(TJC_PAGE_PRINTING);
printer_ready = false;
//4.2.10 CLL 修改断料检测开关逻辑
if (mks_fila_status == true) {
filament_sensor_switch(true);
}
page_to(TJC_PAGE_PRINTING);
printer_ready = false;
}
}

Expand Down Expand Up @@ -1794,7 +1804,8 @@ void refresh_page_filament() {
send_cmd_picc2(tty_fd, "b22", "421");
}

if (filament_switch_sensor_fila_enabled == true) {
//if (filament_switch_sensor_fila_enabled == true) {
if (mks_fila_status == true) {
send_cmd_picc(tty_fd, "b5", "422");
send_cmd_picc2(tty_fd, "b5", "421");
} else {
Expand Down Expand Up @@ -1877,13 +1888,15 @@ void refresh_page_printing_zoffset() {
//2023.4.20 网页暂停开始与UI相匹配
if (printer_print_stats_state == "paused") {
if (printer_ready == true) {
filament_sensor_switch(false);
page_to(TJC_PAGE_PRINT_FILAMENT);
printer_ready = false;
}
}

if (printer_print_stats_state == "complete") {
if (level_mode_printing_is_printing_level == false) {
filament_sensor_switch(false);
complete_print();
//2.1.2 CLL 修复网页显示预览图bug
clear_previous_data();
Expand All @@ -1901,12 +1914,14 @@ void refresh_page_printing_zoffset() {

//2023.5.8 CLL 网页停止后将跳转至打印停止界面
if (printer_print_stats_state == "standby") {
filament_sensor_switch(false);
page_to(TJC_PAGE_STOPPING);
}
//2023.5.8 CLL 报错弹窗
if (printer_print_stats_state == "error") {
page_to(TJC_PAGE_GCODE_ERROR);
send_cmd_txt(tty_fd, "t0", "gcode error:" + output_console);
filament_sensor_switch(false);
}
//2.1.2 CLL 在打印设置zoffset界面也会有断料提醒弹窗
if (filament_switch_sensor_fila_enabled == true) {
Expand Down Expand Up @@ -2104,12 +2119,14 @@ void refresh_page_printing() {
//2023.4.20 网页暂停开始与UI相匹配
if (printer_print_stats_state == "paused") {
if (printer_ready == true) {
filament_sensor_switch(false);
page_to(TJC_PAGE_PRINT_FILAMENT);
printer_ready = false;
}
}

if (printer_print_stats_state == "complete") {
filament_sensor_switch(false);
complete_print();
//2.1.2 CLL 修复网页显示预览图bug
clear_previous_data();
Expand All @@ -2123,13 +2140,15 @@ void refresh_page_printing() {

//2023.5.8 CLL 网页停止后将跳转至打印停止界面
if (printer_print_stats_state == "standby") {
filament_sensor_switch(false);
page_to(TJC_PAGE_STOPPING);
}

//2023.5.8 CLL 报错弹窗
if (printer_print_stats_state == "error") {
page_to(TJC_PAGE_GCODE_ERROR);
send_cmd_txt(tty_fd, "t0", "gcode error:" + output_console);
filament_sensor_switch(false);
}

if (filament_switch_sensor_fila_enabled == true) {
Expand Down Expand Up @@ -2601,11 +2620,11 @@ void move_y_increase() {
}

void move_z_decrease() {
ep->Send(move(AXIS_Z, "-" + std::to_string(printer_move_dist), 130));
ep->Send(move(AXIS_Z, "-" + std::to_string(printer_move_dist), 10));
}

void move_z_increase() {
ep->Send(move(AXIS_Z, "+" + std::to_string(printer_move_dist), 130));
ep->Send(move(AXIS_Z, "+" + std::to_string(printer_move_dist), 10));
}

bool get_filament_detected() {
Expand All @@ -2629,6 +2648,7 @@ void set_print_pause_resume() {
}

void set_print_pause() {
filament_sensor_switch(false);
ep->Send(json_run_a_gcode("PAUSE"));
// printer_pause_taget = printer_extruder_target;
// ep->Send(json_run_a_gcode("G1 Z10\n"));
Expand All @@ -2637,15 +2657,20 @@ void set_print_pause() {
}

void set_print_resume() {
if (get_mks_fila_status() == true) {
filament_sensor_switch(true);
}
ep->Send(json_run_a_gcode("RESUME"));
// set_extruder_target(printer_pause_taget);
// printer_pause_taget = 0;
}

void cancel_print() {
filament_sensor_switch(false);
printer_print_stats_filename = "";
clear_cp0_image();
/* 执行这个避免一直加热 */
filament_sensor_switch(false);
// ep->Send(json_run_a_gcode(set_heater_temp("extruder", 0)));
// ep->Send(json_run_a_gcode(set_heater_temp("heater_bed", 0)));
// ep->Send(json_run_a_gcode(set_heater_temp("hot", 0)));
Expand Down Expand Up @@ -3020,13 +3045,15 @@ void finish_print() {

void set_filament_sensor() {
std::cout << "filament_switch_sensor fila = " << filament_switch_sensor_fila_enabled << std::endl;
if (filament_switch_sensor_fila_enabled == 0) {
ep->Send(json_run_a_gcode("SET_FILAMENT_SENSOR SENSOR=fila ENABLE=1\n"));
mks_fila_status = true;
//4.2.10 CLL 修改断料检测开关逻辑
if (mks_fila_status == true) {
//if (filament_switch_sensor_fila_enabled == 0) {
//ep->Send(json_run_a_gcode("SET_FILAMENT_SENSOR SENSOR=fila ENABLE=1\n"));
mks_fila_status = false;
set_mks_fila_status();
} else {
ep->Send(json_run_a_gcode("SET_FILAMENT_SENSOR SENSOR=fila ENABLE=0\n"));
mks_fila_status = false;
//ep->Send(json_run_a_gcode("SET_FILAMENT_SENSOR SENSOR=fila ENABLE=0\n"));
mks_fila_status = true;
set_mks_fila_status();
}
}
Expand All @@ -3046,25 +3073,25 @@ void beep_on_off() {
if (printer_out_pin_beep_value == 0) {
ep->Send(json_run_a_gcode("beep_on"));
mks_beep_status = true;
set_mks_beep_status();
//set_mks_beep_status();
} else {
ep->Send(json_run_a_gcode("beep_off"));
mks_beep_status = false;
set_mks_beep_status();
//set_mks_beep_status();
}
}

void led_on_off() {
if (printer_caselight_value == 0) {
ep->Send(json_run_a_gcode("SET_PIN PIN=caselight VALUE=1"));
mks_led_status = true;
set_mks_led_status();
//set_mks_led_status();
} else {
ep->Send(json_run_a_gcode("SET_PIN PIN=caselight VALUE=0"));
//4.2.8 CLL 息屏不保存状态
if (previous_caselight_value == false) {
mks_led_status = false;
set_mks_led_status();
//set_mks_led_status();
}
}
}
Expand Down Expand Up @@ -3523,6 +3550,9 @@ void init_mks_status() {
get_mks_total_printed_time();
get_mks_babystep();
printer_set_babystep();
//4.2.10 开机自动设置声音关、灯开、断料检测关
ep->Send(json_run_a_gcode("beep_off\nSET_PIN PIN=caselight VALUE=1\nSET_FILAMENT_SENSOR SENSOR=fila ENABLE=0\n"));
/*
if (get_mks_beep_status() == 0) {
MKSLOG_RED("关闭蜂鸣器");
if (get_mks_led_status() == 0) {
Expand Down Expand Up @@ -3566,6 +3596,7 @@ void init_mks_status() {
}
}
}
*/
}

void after_scan_refresh_page() {
Expand Down Expand Up @@ -3762,7 +3793,7 @@ void open_syntony_finish() {
MKSLOG_BLUE("Printer webhooks state: %s", printer_webhooks_state.c_str());
if (page_syntony_finished == false) {
page_syntony_finished = true;
ep->Send(json_run_a_gcode("SAVE_CONFIG"));
//ep->Send(json_run_a_gcode("SAVE_CONFIG"));
}

if (printer_idle_timeout_state == "Ready" && printer_webhooks_state == "ready") {
Expand Down Expand Up @@ -3963,7 +3994,8 @@ void refresh_page_open_heater_bed() {
//2.1.2 CLL 修改开机引导流程
void open_heater_bed_up() {
page_to(TJC_PAGE_OPEN_VIDEO_4);
ep->Send(json_run_a_gcode("G91\nG1 Z-150 F600\nG1 X-50 Y-50 F1200\nG90\n"));
//4.2.10 CLL 修改开机引导平台上移距离
ep->Send(json_run_a_gcode("G91\nG1 Z-110 F600\nG1 X-120 Y-120 F1200\nG90\n"));
}

//2.1.2 CLL 新增热床调平
Expand Down Expand Up @@ -4122,13 +4154,41 @@ void refresh_page_open_level() {
//4.2.7 CLL 新增恢复出厂设置功能
void restore_config() {
system("cp /home/mks/klipper_config/config.mksini.bak /home/mks/klipper_config/config.mksini");
ep->Send(json_run_a_gcode("BED_MESH_PROFILE REMOVE=\"default\"\nSAVE_CONFIG"));
sleep(1);
page_to(TJC_PAGE_RESTORING);
//ep->Send(json_run_a_gcode("BED_MESH_PROFILE REMOVE=\"default\"\nSAVE_CONFIG"));
//sleep(1);
//page_to(TJC_PAGE_RESTORING);
//4.2.10 CLL 恢复出厂设置不再清空热床调平数据
page_to(TJC_PAGE_MAIN);
}

void refresh_page_restoring() {
if (printer_idle_timeout_state == "Ready" && printer_webhooks_state == "ready") {
page_to(TJC_PAGE_MAIN);
}
}

//4.2.10 CLL 新增输出日志文件功能
void print_log() {
if (detect_disk() == -1) {
page_to(TJC_PAGE_PRINT_LOG_F);
} else {
system("mkdir /home/mks/gcode_files/sda1/QD_Log");
system("cp /home/mks/klipper_logs/klippy.log /home/mks/gcode_files/sda1/QD_Log/klippy.log\n");
system("cp /home/mks/klipper_logs/moonraker.log /home/mks/gcode_files/sda1/QD_Log/moonraker.log\n");
page_to(TJC_PAGE_PRINT_LOG_S);
}
}

//4.2.10 CLL 修改断料检测开关逻辑
void filament_sensor_switch(bool status) {
if (status == true) {
ep->Send(json_run_a_gcode("SET_FILAMENT_SENSOR SENSOR=fila ENABLE=1\n"));
} else if (status == false) {
ep->Send(json_run_a_gcode("SET_FILAMENT_SENSOR SENSOR=fila ENABLE=0\n"));
}
}

//4.2.10 CLL 新增共振补偿超时强制跳转
void send_gcode(std::string command) {
ep->Send(json_run_a_gcode(command));
}
2 changes: 2 additions & 0 deletions src/mks_gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void parse_gcode_response(nlohmann::json params) {
if (params0 == "// Klipper state: Ready") {
MKSLOG("重启Klipper已准备就绪,发送订阅内容");
printer_webhooks_state = "ready";
//4.2.10 CLL 修复跳转界面卡住问题
printer_idle_timeout_state = "Ready";
printer_webhooks_state_message = "Klipper state: Ready";
// if (all_level_saving == false) {
sleep(5);
Expand Down
Loading

0 comments on commit 73eb9bd

Please sign in to comment.