From 40a064ffbcd619ed3f655c0ccb51a5c167659145 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Wed, 28 Mar 2018 18:53:37 +0200 Subject: [PATCH] Add extruder linearity correction to settings menu. --- Firmware/Configuration_prusa.h | 2 +- Firmware/Marlin_main.cpp | 2 ++ Firmware/langtool.pl | 0 Firmware/language_all.cpp | 10 +++++++ Firmware/language_all.h | 4 +++ Firmware/language_en.h | 2 ++ Firmware/ultralcd.cpp | 48 ++++++++++++++++++++++------------ Firmware/ultralcd.h | 4 +-- 8 files changed, 53 insertions(+), 19 deletions(-) mode change 100644 => 100755 Firmware/langtool.pl diff --git a/Firmware/Configuration_prusa.h b/Firmware/Configuration_prusa.h index 7cf413c3..6d781dce 100644 --- a/Firmware/Configuration_prusa.h +++ b/Firmware/Configuration_prusa.h @@ -137,7 +137,7 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #endif /* DEBUG_BUILD */ //#define EXPERIMENTAL_FEATURES -//#define TMC2130_LINEARITY_CORRECTION +#define TMC2130_LINEARITY_CORRECTION //#define TMC2130_VARIABLE_RESOLUTION diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1d0e0d60..488b726a 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1035,9 +1035,11 @@ void setup() } #ifdef TMC2130_LINEARITY_CORRECTION +#ifdef EXPERIMENTAL_FEATURES tmc2130_wave_fac[X_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_X_FAC); tmc2130_wave_fac[Y_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_Y_FAC); tmc2130_wave_fac[Z_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_Z_FAC); +#endif //EXPERIMENTAL_FEATURES tmc2130_wave_fac[E_AXIS] = eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_E_FAC); if (tmc2130_wave_fac[X_AXIS] == 0xffff) tmc2130_wave_fac[X_AXIS] = 0; if (tmc2130_wave_fac[Y_AXIS] == 0xffff) tmc2130_wave_fac[Y_AXIS] = 0; diff --git a/Firmware/langtool.pl b/Firmware/langtool.pl old mode 100644 new mode 100755 diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp index 7f5e4eb7..7acf23bf 100644 --- a/Firmware/language_all.cpp +++ b/Firmware/language_all.cpp @@ -599,6 +599,16 @@ const char * const MSG_EXTRUDER_4_LANG_TABLE[1] PROGMEM = { MSG_EXTRUDER_4_EN }; +const char MSG_EXTRUDER_CORRECTION_EN[] PROGMEM = "E-correct"; +const char * const MSG_EXTRUDER_CORRECTION_LANG_TABLE[1] PROGMEM = { + MSG_EXTRUDER_CORRECTION_EN +}; + +const char MSG_EXTRUDER_CORRECTION_OFF_EN[] PROGMEM = " [off"; +const char * const MSG_EXTRUDER_CORRECTION_OFF_LANG_TABLE[1] PROGMEM = { + MSG_EXTRUDER_CORRECTION_OFF_EN +}; + const char MSG_E_CAL_KNOB_EN[] PROGMEM = "Rotate knob until mark reaches extruder body. Click when done."; const char MSG_E_CAL_KNOB_CZ[] PROGMEM = "Otacejte tlacitkem dokud znacka nedosahne tela extruderu. Potvrdte tlacitkem."; const char * const MSG_E_CAL_KNOB_LANG_TABLE[LANG_NUM] PROGMEM = { diff --git a/Firmware/language_all.h b/Firmware/language_all.h index b8da5464..937a4a5b 100644 --- a/Firmware/language_all.h +++ b/Firmware/language_all.h @@ -214,6 +214,10 @@ extern const char* const MSG_EXTRUDER_3_LANG_TABLE[1]; #define MSG_EXTRUDER_3 LANG_TABLE_SELECT_EXPLICIT(MSG_EXTRUDER_3_LANG_TABLE, 0) extern const char* const MSG_EXTRUDER_4_LANG_TABLE[1]; #define MSG_EXTRUDER_4 LANG_TABLE_SELECT_EXPLICIT(MSG_EXTRUDER_4_LANG_TABLE, 0) +extern const char* const MSG_EXTRUDER_CORRECTION_LANG_TABLE[1]; +#define MSG_EXTRUDER_CORRECTION LANG_TABLE_SELECT_EXPLICIT(MSG_EXTRUDER_CORRECTION_LANG_TABLE, 0) +extern const char* const MSG_EXTRUDER_CORRECTION_OFF_LANG_TABLE[1]; +#define MSG_EXTRUDER_CORRECTION_OFF LANG_TABLE_SELECT_EXPLICIT(MSG_EXTRUDER_CORRECTION_OFF_LANG_TABLE, 0) extern const char* const MSG_E_CAL_KNOB_LANG_TABLE[LANG_NUM]; #define MSG_E_CAL_KNOB LANG_TABLE_SELECT(MSG_E_CAL_KNOB_LANG_TABLE) extern const char* const MSG_Enqueing_LANG_TABLE[1]; diff --git a/Firmware/language_en.h b/Firmware/language_en.h index a3ab5fb3..a0cf83e4 100644 --- a/Firmware/language_en.h +++ b/Firmware/language_en.h @@ -356,6 +356,8 @@ #define MSG_FSENSOR_OFF "Fil. sensor [off]" #define MSG_FSENSOR_NA "Fil. sensor [N/A]" #define MSG_FSENSOR_ON "Fil. sensor [on]" +#define(length=9)MSG_EXTRUDER_CORRECTION "E-correct" +#define(length=6)MSG_EXTRUDER_CORRECTION_OFF " [off" #define(length=20, lines=4) MSG_PLACE_STEEL_SHEET "Please place steel sheet on heatbed." #define(length=20, lines=4) MSG_REMOVE_STEEL_SHEET "Please remove steel sheet from heatbed." diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 1de7d375..f35ecbcb 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -207,6 +207,7 @@ static void lcd_control_temperature_preheat_pla_settings_menu(); static void lcd_control_temperature_preheat_abs_settings_menu(); static void lcd_control_motion_menu(); static void lcd_control_volumetric_menu(); +static void lcd_settings_menu_back(); static void prusa_stat_printerstatus(int _status); static void prusa_stat_farm_number(); @@ -3861,7 +3862,7 @@ static void lcd_settings_menu() EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu)); START_MENU(); - MENU_ITEM(back, MSG_MAIN, lcd_main_menu); + MENU_ITEM(back, MSG_MAIN, lcd_settings_menu_back); MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu); if (!homing_flag) @@ -3913,6 +3914,7 @@ static void lcd_settings_menu() else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set); } else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info); + MENU_ITEM_EDIT(wfac, MSG_EXTRUDER_CORRECTION, &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX); if (temp_cal_active == false) { MENU_ITEM(function, MSG_TEMP_CALIBRATION_OFF, lcd_temp_calibration_set); @@ -3974,6 +3976,16 @@ static void lcd_ustep_linearity_menu_save() eeprom_update_word((uint16_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]); eeprom_update_word((uint16_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]); } +static void lcd_settings_menu_back() +{ + bool changed = false; + if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0; + changed |= (eeprom_read_word((uint16_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]); + lcd_ustep_linearity_menu_save(); + if (changed) tmc2130_init(); + currentMenu = lcd_main_menu; + lcd_main_menu(); +} #ifdef EXPERIMENTAL_FEATURES static void lcd_experimantal_menu(); @@ -5847,13 +5859,15 @@ extern char conv[8]; // Convert tmc2130 wfac to string char *wfac_to_str5(const uint16_t &x) { - if (x>=TMC2130_WAVE_FAC1000_MIN) return ftostr43(((float)(x & 0xffff))/1000); - conv[0] = ' '; - conv[1] = ' '; - conv[2] = 'O'; - conv[3] = 'f'; - conv[4] = 'f'; - conv[5] = 0; + if (x>=TMC2130_WAVE_FAC1000_MIN) + { + conv[0] = '['; + ftostr43(((float)(x & 0xffff)/1000),1); + } + else strcpy_P(conv,MSG_EXTRUDER_CORRECTION_OFF); + conv[6] = ']'; + conv[7] = ' '; + conv[8] = 0; return conv; } @@ -7489,19 +7503,21 @@ char *ftostr32ns(const float &x) { // Convert float to string with 1.234 format -char *ftostr43(const float &x) +char *ftostr43(const float &x, uint8_t offset) { + const size_t maxOffset = sizeof(conv)/sizeof(conv[0]) - 6; + if (offset>maxOffset) offset = maxOffset; long xx = x * 1000; if (xx >= 0) - conv[0] = (xx / 1000) % 10 + '0'; + conv[offset] = (xx / 1000) % 10 + '0'; else - conv[0] = '-'; + conv[offset] = '-'; xx = abs(xx); - conv[1] = '.'; - conv[2] = (xx / 100) % 10 + '0'; - conv[3] = (xx / 10) % 10 + '0'; - conv[4] = (xx) % 10 + '0'; - conv[5] = 0; + conv[offset + 1] = '.'; + conv[offset + 2] = (xx / 100) % 10 + '0'; + conv[offset + 3] = (xx / 10) % 10 + '0'; + conv[offset + 4] = (xx) % 10 + '0'; + conv[offset + 5] = 0; return conv; } diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 53ced8a1..aad628ec 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -197,7 +197,7 @@ char *ftostr31ns(const float &x); // float to string without sign character char *ftostr31(const float &x); char *ftostr32(const float &x); char *ftostr32ns(const float &x); -char *ftostr43(const float &x); +char *ftostr43(const float &x, uint8_t offset = 0); char *ftostr12ns(const float &x); char *ftostr13ns(const float &x); char *ftostr32sp(const float &x); // remove zero-padding from ftostr32 @@ -285,4 +285,4 @@ void lcd_service_mode_show_result(); void lcd_wizard(); void lcd_wizard(int state); -#endif //ULTRALCD_H \ No newline at end of file +#endif //ULTRALCD_H