From 2c06cb68d190431ab8cc7545a4f2b5554bc84150 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Tue, 17 Jul 2018 20:04:12 +0200 Subject: [PATCH 1/5] FSensor tunning - filtering changed, chunk length = 0.64mm and MAX_ERR = 10 --- Firmware/fsensor.cpp | 77 ++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 67f66e21..1a84b7cb 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -10,11 +10,14 @@ #include "cmdqueue.h" +const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n"; -#define FSENSOR_ERR_MAX 5 //filament sensor max error count +//#define FSENSOR_ERR_MAX 5 //filament sensor max error count +#define FSENSOR_ERR_MAX 10 //filament sensor max error count #define FSENSOR_INT_PIN 63 //filament sensor interrupt pin PK1 #define FSENSOR_INT_PIN_MSK 0x02 //filament sensor interrupt pin mask (bit1) -#define FSENSOR_CHUNK_LEN 280 //filament sensor chunk length in steps +//#define FSENSOR_CHUNK_LEN 280 //filament sensor chunk length in steps - 1mm +#define FSENSOR_CHUNK_LEN 180 //filament sensor chunk length in steps - 0.64mm extern void stop_and_save_print_to_ram(float z_move, float e_move); extern void restore_print_from_ram_and_continue(float e_move); @@ -115,7 +118,7 @@ void fsensor_autoload_check_start(void) // puts_P(PSTR("fsensor_autoload_check_start\n")); if (!pat9125_update_y()) //update sensor { - puts_P(PSTR("pat9125 not responding (3).\n")); + printf_P(ERRMSG_PAT9125_NOT_RESP, 3); fsensor_disable(); fsensor_not_responding = true; fsensor_autoload_enabled = false; @@ -144,7 +147,7 @@ bool fsensor_check_autoload(void) fsensor_autoload_last_millis = millis(); if (!pat9125_update_y()) { - puts_P(PSTR("pat9125 not responding (2).\n")); + printf_P(ERRMSG_PAT9125_NOT_RESP, 2); fsensor_disable(); fsensor_not_responding = true; return false; //update sensor @@ -173,74 +176,44 @@ bool fsensor_check_autoload(void) ISR(PCINT2_vect) { -// puts("PCINT2\n"); if (!((fsensor_int_pin_old ^ PINK) & FSENSOR_INT_PIN_MSK)) return; fsensor_int_pin_old = PINK; static bool _lock = false; if (_lock) return; _lock = true; -// return; int st_cnt = fsensor_st_cnt; fsensor_st_cnt = 0; sei(); -/* *digitalPinToPCMSK(fsensor_int_pin) &= ~bit(digitalPinToPCMSKbit(fsensor_int_pin)); - digitalWrite(fsensor_int_pin, HIGH); - *digitalPinToPCMSK(fsensor_int_pin) |= bit(digitalPinToPCMSKbit(fsensor_int_pin));*/ + uint8_t old_err_cnt = fsensor_err_cnt; if (!pat9125_update_y()) { -//#ifdef DEBUG_FSENSOR_LOG - puts_P(PSTR("pat9125 not responding (1).\n")); -//#endif //DEBUG_FSENSOR_LOG + printf_P(ERRMSG_PAT9125_NOT_RESP, 1); fsensor_disable(); fsensor_not_responding = true; } if (st_cnt != 0) - { -#ifdef DEBUG_FSENSOR_LOG - if (fsensor_log) + { //movement + if (st_cnt > 0) //positive movement { - MYSERIAL.print("cnt="); - MYSERIAL.print(st_cnt, DEC); - MYSERIAL.print(" dy="); - MYSERIAL.print(pat9125_y, DEC); - } -#endif //DEBUG_FSENSOR_LOG - if (st_cnt != 0) - { - if( (pat9125_y == 0) || ((pat9125_y > 0) && (st_cnt < 0)) || ((pat9125_y < 0) && (st_cnt > 0))) - { //invalid movement - if (st_cnt > 0) //only positive movements - fsensor_err_cnt++; -#ifdef DEBUG_FSENSOR_LOG - if (fsensor_log) - { - MYSERIAL.print("\tNG ! err="); - MYSERIAL.println(fsensor_err_cnt, DEC); - } -#endif //DEBUG_FSENSOR_LOG - } + if (pat9125_y <= 0) + fsensor_err_cnt++; else - { //propper movement - if (fsensor_err_cnt > 0) + if (fsensor_err_cnt) fsensor_err_cnt--; -// fsensor_err_cnt = 0; -#ifdef DEBUG_FSENSOR_LOG - if (fsensor_log) - { - MYSERIAL.print("\tOK err="); - MYSERIAL.println(fsensor_err_cnt, DEC); - } -#endif //DEBUG_FSENSOR_LOG - } } - else - { //no movement -#ifdef DEBUG_FSENSOR_LOG - if (fsensor_log) - MYSERIAL.println("\tOK 0"); -#endif //DEBUG_FSENSOR_LOG + else //negative movement + { } } + else + { //no movement + } + +#ifdef DEBUG_FSENSOR_LOG + if (fsensor_log) + printf_P(_N("FSENSOR cnt=%d dy=%d err=%d %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); +#endif //DEBUG_FSENSOR_LOG + pat9125_y = 0; _lock = false; return; From afb9ca4687e059e2930001dbcb8c13d75491f76f Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 18 Jul 2018 17:45:54 +0200 Subject: [PATCH 2/5] FSensor - removed fsensor blocking while load, added filament quality meassurement --- Firmware/Marlin_main.cpp | 12 ++++++------ Firmware/fsensor.cpp | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6217aec6..f8ba3f28 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6221,7 +6221,7 @@ Sigma_Exit: { #ifdef PAT9125 bool old_fsensor_enabled = fsensor_enabled; - fsensor_enabled = false; //temporary solution for unexpected restarting +// fsensor_enabled = false; //temporary solution for unexpected restarting #endif //PAT9125 st_synchronize(); @@ -6671,7 +6671,7 @@ Sigma_Exit: custom_message_type = 0; #ifdef PAT9125 - fsensor_enabled = old_fsensor_enabled; //temporary solution for unexpected restarting +// fsensor_enabled = old_fsensor_enabled; //temporary solution for unexpected restarting if (fsensor_M600) { @@ -6683,10 +6683,10 @@ Sigma_Exit: cmdqueue_pop_front(); } KEEPALIVE_STATE(IN_HANDLER); - fsensor_enable(); +// fsensor_enable(); fsensor_restore_print_and_continue(); } - + fsensor_M600 = false; #endif //PAT9125 } @@ -7005,7 +7005,7 @@ Sigma_Exit: #else #ifdef PAT9125 bool old_fsensor_enabled = fsensor_enabled; - fsensor_enabled = false; +// fsensor_enabled = false; #endif //PAT9125 custom_message = true; custom_message_type = 2; @@ -7049,7 +7049,7 @@ Sigma_Exit: custom_message = false; custom_message_type = 0; #ifdef PAT9125 - fsensor_enabled = old_fsensor_enabled; +// fsensor_enabled = old_fsensor_enabled; #endif //PAT9125 #endif } diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 1a84b7cb..4ce8db18 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -38,7 +38,6 @@ uint8_t fsensor_int_pin_old = 0; int16_t fsensor_chunk_len = FSENSOR_CHUNK_LEN; bool fsensor_enabled = true; bool fsensor_not_responding = false; -//bool fsensor_ignore_error = true; bool fsensor_M600 = false; uint8_t fsensor_err_cnt = 0; int16_t fsensor_st_cnt = 0; @@ -51,6 +50,10 @@ uint8_t fsensor_autoload_c = 0; uint32_t fsensor_autoload_last_millis = 0; uint8_t fsensor_autoload_sum = 0; +uint32_t fsensor_st_sum = 0; +uint32_t fsensor_yd_sum = 0; +uint32_t fsensor_er_sum = 0; + void fsensor_block() { fsensor_enabled = false; @@ -70,12 +73,16 @@ bool fsensor_enable() else fsensor_not_responding = true; fsensor_enabled = pat9125?true:false; -// fsensor_ignore_error = true; fsensor_M600 = false; fsensor_err_cnt = 0; eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled?0x01:0x00); FSensorStateMenu = fsensor_enabled?1:0; // printf_P(PSTR("fsensor_enable - end %d\n"), fsensor_enabled?1:0); + + fsensor_st_sum = 0; + fsensor_yd_sum = 0; + fsensor_er_sum = 0; + return fsensor_enabled; } @@ -196,10 +203,17 @@ ISR(PCINT2_vect) if (st_cnt > 0) //positive movement { if (pat9125_y <= 0) + { fsensor_err_cnt++; + fsensor_er_sum++; + } else + { if (fsensor_err_cnt) fsensor_err_cnt--; + fsensor_st_sum += st_cnt; + fsensor_yd_sum += pat9125_y; + } } else //negative movement { @@ -211,7 +225,10 @@ ISR(PCINT2_vect) #ifdef DEBUG_FSENSOR_LOG if (fsensor_log) + { printf_P(_N("FSENSOR cnt=%d dy=%d err=%d %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); + printf_P(_N("FSENSOR st_sum=%lu yd_sum=%lu er_sum=%lu\n"), fsensor_st_sum, fsensor_yd_sum, fsensor_er_sum); + } #endif //DEBUG_FSENSOR_LOG pat9125_y = 0; @@ -247,7 +264,7 @@ void fsensor_st_block_chunk(block_t* bl, int cnt) void fsensor_update() { - if (!fsensor_enabled) return; + if (!fsensor_enabled || fsensor_M600) return; if (fsensor_err_cnt > FSENSOR_ERR_MAX) { fsensor_stop_and_save_print(); @@ -274,7 +291,7 @@ void fsensor_update() eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1); enquecommand_front_P((PSTR("M600"))); fsensor_M600 = true; - fsensor_enabled = false; +// fsensor_enabled = false; } } } From 6db1c6dc3bc8efd1d5c26d654a6f2677f4d5c08a Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Jul 2018 13:54:56 +0200 Subject: [PATCH 3/5] Long press Move Z fixed --- Firmware/ultralcd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a53ce727..58502130 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7383,6 +7383,7 @@ uint8_t get_message_level() void menu_lcd_longpress_func(void) { + move_menu_scale = 1.0; menu_submenu(lcd_move_z); } From 42d2f312487ab1360c32a8f03bed3f030435e530 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Jul 2018 14:23:45 +0200 Subject: [PATCH 4/5] PFW-446 Stop print fix (recursion in lcd_update) --- Firmware/ultralcd.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 58502130..b09d137a 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6044,13 +6044,15 @@ static void lcd_sd_updir() menu_top = 0; } -void lcd_print_stop() { +void lcd_print_stop() +{ cancel_heatup = true; #ifdef MESH_BED_LEVELING mbl.active = false; #endif // Stop the stoppers, update the position from the stoppers. - if (mesh_bed_leveling_flag == false && homing_flag == false) { + if (mesh_bed_leveling_flag == false && homing_flag == false) + { planner_abort_hard(); // Because the planner_abort_hard() initialized current_position[Z] from the stepper, // Z baystep is no more applied. Reset it. @@ -6059,20 +6061,16 @@ void lcd_print_stop() { // Clean the input command queue. cmdqueue_reset(); lcd_setstatuspgm(_T(MSG_PRINT_ABORTED)); - lcd_update(2); card.sdprinting = false; card.closefile(); - stoptime = millis(); unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s pause_time = 0; save_statistics(total_filament_used, t); - lcd_return_to_status(); lcd_ignore_click(true); lcd_commands_step = 0; lcd_commands_type = LCD_COMMAND_STOP_PRINT; - // Turn off the print fan SET_OUTPUT(FAN_PIN); WRITE(FAN_PIN, 0); From fa9d4550f011fda7ed42ef684f9acebd3a2d505b Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 19 Jul 2018 15:21:46 +0200 Subject: [PATCH 5/5] PFW-448 menu items displaying fix --- Firmware/menu.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 17292930..7b6be855 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -224,7 +224,18 @@ uint8_t menu_item_gcode_P(const char* str, const char* str_gcode) return 0; } -const char menu_fmt_int3[] PROGMEM = "%c%S:\x1b[%hhu;16H%3d"; +const char menu_20x_space[] PROGMEM = " "; +const char menu_fmt_int3[] PROGMEM = "%c%.15S:%s%3d"; +void menu_draw_int3(char chr, const char* str, int16_t val) +{ + int text_len = strlen_P(str); + if (text_len > 15) text_len = 15; + char spaces[21]; + strcpy_P(spaces, menu_20x_space); + spaces[15 - text_len] = 0; + lcd_printf_P(menu_fmt_int3, chr, str, spaces, val); +} + #define _menu_data (*((menu_data_edit_t*)menu_data)) void _menu_edit_int3(void) @@ -234,7 +245,7 @@ void _menu_edit_int3(void) if (lcd_encoder < _menu_data.minEditValue) lcd_encoder = _menu_data.minEditValue; if (lcd_encoder > _menu_data.maxEditValue) lcd_encoder = _menu_data.maxEditValue; lcd_set_cursor(0, 1); - lcd_printf_P(menu_fmt_int3, ' ', _menu_data.editLabel, (uint8_t)1, (int)lcd_encoder); + menu_draw_int3(' ', _menu_data.editLabel, (int)lcd_encoder); } if (LCD_CLICKED) { @@ -250,7 +261,7 @@ uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int if (lcd_draw_update) { lcd_set_cursor(0, menu_row); - lcd_printf_P(menu_fmt_int3, (lcd_encoder == menu_item)?'>':' ', str, menu_row, *pval); + menu_draw_int3((lcd_encoder == menu_item)?'>':' ', str, *pval); } if (menu_clicked && (lcd_encoder == menu_item)) {