From 11ce786aaa5856f4be6024911b537a5f44ee681e Mon Sep 17 00:00:00 2001 From: DRracer Date: Tue, 27 Aug 2019 13:47:58 +0200 Subject: [PATCH 01/21] Support for more special characters allowed in file names (^ + = [ ] ; ,) --- Firmware/Marlin_main.cpp | 14 +++++++++----- Firmware/SdBaseFile.cpp | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5279776d..a034f94e 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3815,10 +3815,14 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); // lcd_calibration(); // } - } - else if (code_seen('^')) { - // nothing, this is a version line - } else if(code_seen('G')) + } + // This prevents reading files with "^" in their names. + // Since it is unclear, if there is some usage of this construct, + // it will be deprecated in 3.9 alpha a possibly completely removed in the future: + // else if (code_seen('^')) { + // // nothing, this is a version line + // } + else if(code_seen('G')) { gcode_in_progress = (int)code_value(); // printf_P(_N("BEGIN G-CODE=%u\n"), gcode_in_progress); @@ -5319,7 +5323,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) // ----------------------------------- case 23: starpos = (strchr(strchr_pointer + 4,'*')); - if(starpos!=NULL) + if(starpos!=NULL) *(starpos)='\0'; card.openFile(strchr_pointer + 4,true); break; diff --git a/Firmware/SdBaseFile.cpp b/Firmware/SdBaseFile.cpp index be04ab1a..b9e881ef 100644 --- a/Firmware/SdBaseFile.cpp +++ b/Firmware/SdBaseFile.cpp @@ -394,7 +394,10 @@ bool SdBaseFile::make83Name(const char* str, uint8_t* name, const char** ptr) { i = 8; // place for extension } else { // illegal FAT characters - PGM_P p = PSTR("|<>^+=?/[];,*\"\\"); + //PGM_P p = PSTR("|<>^+=?/[];,*\"\\"); + // 2019-08-27 really? + // Microsoft defines, that only a subset of these characters is not allowed. + PGM_P p = PSTR("|<>?/*\"\\"); uint8_t b; while ((b = pgm_read_byte(p++))) if (b == c) goto fail; // check size and only allow ASCII printable characters From bf2097342dfe4ef8902a67805f92e644e4cb4e75 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Tue, 27 Aug 2019 17:01:41 +0200 Subject: [PATCH 02/21] Add ASA preheat into mFilamentMenu(); --- Firmware/ultralcd.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e601fd75..43ab4042 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2486,6 +2486,12 @@ bFilamentPreheatState=false; mFilamentItem(PET_PREHEAT_HOTEND_TEMP,PET_PREHEAT_HPB_TEMP); } +static void mFilamentItem_ASA() +{ + bFilamentPreheatState=false; + mFilamentItem(ASA_PREHEAT_HOTEND_TEMP,ASA_PREHEAT_HPB_TEMP); +} + static void mFilamentItem_ABS() { bFilamentPreheatState=false; @@ -2520,15 +2526,16 @@ if(eFilamentAction==FilamentAction::AutoLoad) void mFilamentMenu() { -MENU_BEGIN(); -MENU_ITEM_FUNCTION_P(_T(MSG_MAIN),mFilamentBack); -MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA); -MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET); -MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS); -MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS); -MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP); -MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX); -MENU_END(); + MENU_BEGIN(); + MENU_ITEM_FUNCTION_P(_T(MSG_MAIN),mFilamentBack); + MENU_ITEM_SUBMENU_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)),mFilamentItem_PLA); + MENU_ITEM_SUBMENU_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)),mFilamentItem_PET); + MENU_ITEM_SUBMENU_P(PSTR("ASA - " STRINGIFY(ASA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ASA_PREHEAT_HPB_TEMP)),mFilamentItem_ASA); + MENU_ITEM_SUBMENU_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)),mFilamentItem_ABS); + MENU_ITEM_SUBMENU_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)),mFilamentItem_HIPS); + MENU_ITEM_SUBMENU_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)),mFilamentItem_PP); + MENU_ITEM_SUBMENU_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)),mFilamentItem_FLEX); + MENU_END(); } void mFilamentItemForce() From 1a1be5c518cc98426d85c78da9bff6b4cee15f26 Mon Sep 17 00:00:00 2001 From: DRracer Date: Tue, 27 Aug 2019 17:10:29 +0200 Subject: [PATCH 03/21] Fix sound mode [assist]: encoder clicking indefinitely when MMU wants to select filament --- Firmware/sound.h | 6 +++--- Firmware/ultralcd.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/sound.h b/Firmware/sound.h index bdd32ec8..90f3e723 100644 --- a/Firmware/sound.h +++ b/Firmware/sound.h @@ -3,10 +3,10 @@ #define SOUND_H -#define MSG_SOUND_MODE_LOUD "Sound [loud]" -#define MSG_SOUND_MODE_ONCE "Sound [once]" +#define MSG_SOUND_MODE_LOUD "Sound [loud]" +#define MSG_SOUND_MODE_ONCE "Sound [once]" #define MSG_SOUND_MODE_SILENT "Sound [silent]" -#define MSG_SOUND_MODE_BLIND "Sound [blind]" +#define MSG_SOUND_MODE_BLIND "Sound [assist]" #define e_SOUND_MODE_NULL 0xFF diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e601fd75..12010ff3 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5902,6 +5902,7 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite cursor_pos++; } enc_dif = lcd_encoder_diff; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); } if (cursor_pos > 3) @@ -5952,7 +5953,6 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite lcd_print(" "); lcd_set_cursor(0, cursor_pos); lcd_print(">"); - Sound_MakeSound(e_SOUND_TYPE_EncoderMove); _delay(100); if (lcd_clicked()) From 1d23cc52e9ff7edc17b091d3af9e827d0da33200 Mon Sep 17 00:00:00 2001 From: DRracer Date: Wed, 28 Aug 2019 09:39:28 +0200 Subject: [PATCH 04/21] endstop sound alert fixes --- Firmware/ultralcd.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 12010ff3..0df9d9a0 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5907,23 +5907,25 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite if (cursor_pos > 3) { - Sound_MakeSound(e_SOUND_TYPE_BlindAlert); cursor_pos = 3; if (first < items_no - 3) { first++; lcd_clear(); + } else { // here we are at the very end of the list + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); } } if (cursor_pos < 1) { - Sound_MakeSound(e_SOUND_TYPE_BlindAlert); cursor_pos = 1; if (first > 0) { first--; lcd_clear(); + } else { // here we are at the very end of the list + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); } } From 49bc11037cf2af7738429e853f8707b0b96e6c2a Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Wed, 28 Aug 2019 18:14:10 +0200 Subject: [PATCH 05/21] Remove statements with no effect. --- Firmware/ultralcd.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 43ab4042..bb2540db 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6596,22 +6596,11 @@ static void lcd_rename_sheet_menu() static void lcd_reset_sheet() { - struct MenuData - { - bool initialized; - uint8_t selected; - char name[sizeof(Sheet::name)]; - }; - static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data"); - MenuData* menuData = (MenuData*)&(menu_data[0]); - eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name)); + char name[sizeof(Sheet::name)]; - menuData->initialized = false; - strcpy_P(menuData->name, (char *)pgm_read_word(&(defaultSheetNames[selected_sheet]))); - - + strcpy_P(name, (char *)pgm_read_word(&(defaultSheetNames[selected_sheet]))); eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),0xffff); - eeprom_update_block(menuData->name,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name)); + eeprom_update_block(name,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name)); menu_back(2); } From 33675c6d1e9c692252525a33bdc8dd36766be2f4 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Wed, 28 Aug 2019 18:16:35 +0200 Subject: [PATCH 06/21] Change default sheet names. --- Firmware/Marlin.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 582cea34..0da565f1 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -308,10 +308,10 @@ extern bool axis_known_position[3]; extern int fanSpeed; extern int8_t lcd_change_fil_state; -const char smooth1[] PROGMEM = "Smooth1"; -const char smooth2[] PROGMEM = "Smooth2"; -const char textured[] PROGMEM = "Textur1"; -const char *const defaultSheetNames[] PROGMEM = {smooth1,smooth2,textured}; +const char sheet1[] PROGMEM = "1"; +const char sheet2[] PROGMEM = "2"; +const char sheet3[] PROGMEM = "3"; +const char *const defaultSheetNames[] PROGMEM = {sheet1,sheet2,sheet3}; #ifdef TMC2130 void homeaxis(int axis, uint8_t cnt = 1, uint8_t* pstep = 0); From 3903dc819adafa256074da41242145ebdb0f5dc6 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Wed, 28 Aug 2019 18:59:48 +0200 Subject: [PATCH 07/21] Extract function next_initialized_sheet from change_sheet_from_menu(). Make it more general to depend on sizeof(Sheets::s) instead of hard coded value of 2. --- Firmware/ultralcd.cpp | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index bb2540db..9fba0039 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6515,22 +6515,31 @@ static void change_sheet() menu_back(3); } -static void change_sheet_from_menu(){ - uint8_t next_sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))+1; - while(true){ - if(next_sheet > 2) next_sheet = 0; - if(is_sheet_initialized(next_sheet)){ - eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), next_sheet); - selected_sheet = next_sheet; - break; - } - else if (next_sheet == selected_sheet){ - break; - } - else{ - next_sheet++; - } - } +//! @brief Get next initialized sheet +//! +//! If current sheet is the only sheet initialized, current sheet is returned. +//! +//! @param sheet Current sheet +//! @return next initialized sheet +//! @retval -1 no sheet is initialized +static int8_t next_initialized_sheet(int8_t sheet) +{ + for (int8_t i = 0; i < static_cast(sizeof(Sheets::s)/sizeof(Sheet)); ++i) + { + ++sheet; + if (sheet >= static_cast(sizeof(Sheets::s)/sizeof(Sheet))) sheet = 0; + if (is_sheet_initialized(sheet)) return sheet; + } + return -1; +} + +static void change_sheet_from_menu() +{ + int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); + + sheet = next_initialized_sheet(sheet); + if (sheet >= 0) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), sheet); + menu_back(); } From 9692f94683d97750d92b05de33ed7e2fa0273ea8 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Wed, 28 Aug 2019 19:01:48 +0200 Subject: [PATCH 08/21] Move sheet menu up to be after Print from SD. --- Firmware/ultralcd.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 9fba0039..ac3c53c0 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6719,6 +6719,14 @@ static void lcd_main_menu() } #endif + if(!isPrintPaused && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) + { + if (!farm_mode) + { + MENU_ITEM_SUBMENU_SELECT_SHEET_E(EEPROM_Sheets_base->s[eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))], change_sheet_from_menu); + } + } + if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::Layer1Cal)) { @@ -6763,14 +6771,6 @@ static void lcd_main_menu() if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu); } - - if(!isPrintPaused && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) - { - if (!farm_mode) - { - MENU_ITEM_SUBMENU_SELECT_SHEET_E(EEPROM_Sheets_base->s[eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))], change_sheet_from_menu); - } - } if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) { From f64252b59b95205abc1242d9b94fe0f9c9f2b060 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Wed, 28 Aug 2019 19:08:53 +0200 Subject: [PATCH 09/21] Hide sheet switcher from main menu, if there are less than 2 sheets calibrated. --- Firmware/ultralcd.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index ac3c53c0..4c431444 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6723,7 +6723,12 @@ static void lcd_main_menu() { if (!farm_mode) { - MENU_ITEM_SUBMENU_SELECT_SHEET_E(EEPROM_Sheets_base->s[eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))], change_sheet_from_menu); + const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); + const int8_t nextSheet = next_initialized_sheet(sheet); + if ((nextSheet >= 0) && (sheet != nextSheet)) // show menu only if we have 2 or more sheets initialized + { + MENU_ITEM_SUBMENU_SELECT_SHEET_E(EEPROM_Sheets_base->s[sheet], change_sheet_from_menu); + } } } From f3bb72be64631d6f7cc0c6f155c08226e8c04c99 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 29 Aug 2019 03:33:33 +0200 Subject: [PATCH 10/21] Reset calibration status if there is no calibrated sheet after reset. --- Firmware/ultralcd.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 4c431444..3296ce55 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6610,6 +6610,15 @@ static void lcd_reset_sheet() strcpy_P(name, (char *)pgm_read_word(&(defaultSheetNames[selected_sheet]))); eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),0xffff); eeprom_update_block(name,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name)); + if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) + { + change_sheet_from_menu(); + if((-1 == next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status())) + { + calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); + } + } + menu_back(2); } From 32f435d1a0e2bdf7b8172a0813991aca8a7352ec Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 29 Aug 2019 17:21:08 +0200 Subject: [PATCH 11/21] Increase number of configurable steel sheets to 8. Move sheets into sub menu of HW setup. --- Firmware/Marlin.h | 5 --- Firmware/eeprom.cpp | 21 +++++++---- Firmware/eeprom.h | 19 +++++----- Firmware/ultralcd.cpp | 82 ++++++++++++++++--------------------------- 4 files changed, 57 insertions(+), 70 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 0da565f1..625e079e 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -308,11 +308,6 @@ extern bool axis_known_position[3]; extern int fanSpeed; extern int8_t lcd_change_fil_state; -const char sheet1[] PROGMEM = "1"; -const char sheet2[] PROGMEM = "2"; -const char sheet3[] PROGMEM = "3"; -const char *const defaultSheetNames[] PROGMEM = {sheet1,sheet2,sheet3}; - #ifdef TMC2130 void homeaxis(int axis, uint8_t cnt = 1, uint8_t* pstep = 0); #else diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index 94314ddd..10080c07 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -72,11 +72,11 @@ void eeprom_init() } if(is_uninitialized) { + SheetName sheetName; + default_sheet_name(i,sheetName); - char sheet_PROGMEM_buffer[8]; - strcpy_P(sheet_PROGMEM_buffer, (char *)pgm_read_word(&(defaultSheetNames[i]))); for (uint_least8_t a = 0; a < sizeof(Sheet::name); ++a){ - eeprom_write(&(EEPROM_Sheets_base->s[i].name[a]), sheet_PROGMEM_buffer[a]); + eeprom_write(&(EEPROM_Sheets_base->s[i].name[a]), sheetName.c[a]); } // When upgrading from version older version (before multiple sheets were implemented in v3.8.0) @@ -90,6 +90,15 @@ void eeprom_init() check_babystep(); } - - - +//! @brief Get default sheet name for index +//! +//! @param[in] index +//! @param[out] sheetName +void default_sheet_name(uint8_t index, SheetName &sheetName) +{ + sheetName.c[0] = '1' + index; + for (uint8_t i = 1; i < (sizeof(sheetName.c)/sizeof(sheetName.c[0])); ++i) + { + sheetName.c[i] = '\0'; + } +} diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index c41fb9ff..23c812af 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -3,12 +3,6 @@ #include -#ifdef __cplusplus -void eeprom_init(); -extern bool is_sheet_initialized(uint8_t sheet_num); -#endif - - typedef struct { char name[7]; //!< Can be null terminated, doesn't need to be null terminated @@ -19,12 +13,12 @@ typedef struct typedef struct { - Sheet s[3]; + Sheet s[8]; uint8_t active_sheet; } Sheets; // sizeof(Sheets). Do not change it unless EEPROM_Sheets_base is last item in EEPROM. // Otherwise it would move following items. -#define EEPROM_SHEETS_SIZEOF 34 +#define EEPROM_SHEETS_SIZEOF 89 #ifdef __cplusplus static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEPROM_SHEETS_SIZEOF."); @@ -235,5 +229,14 @@ enum EEPROM_MMU_CUTTER_ENABLED_always = 2, }; +#ifdef __cplusplus +void eeprom_init(); +bool is_sheet_initialized(uint8_t sheet_num); +struct SheetName +{ + char c[sizeof(Sheet::name) + 1]; +}; +void default_sheet_name(uint8_t index, SheetName &sheetName); +#endif #endif // EEPROM_H diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3296ce55..b3d202c5 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -244,10 +244,6 @@ void lcd_finishstatus(); static void lcd_sdcard_menu(); static void lcd_sheet_menu(); -static void lcd_select_sheet_0_menu(); -static void lcd_select_sheet_1_menu(); -static void lcd_select_sheet_2_menu(); - #ifdef DELTA_CALIBRATION_MENU static void lcd_delta_calibrate_menu(); #endif // DELTA_CALIBRATION_MENU @@ -5526,37 +5522,38 @@ SETTINGS_VERSION; MENU_END(); } +template +static void select_sheet_menu() +{ + selected_sheet = number; + lcd_sheet_menu(); +} + +static void sheets_menu() +{ + MENU_BEGIN(); + MENU_ITEM_BACK_P(_i("HW Setup")); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], select_sheet_menu<0>); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], select_sheet_menu<1>); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], select_sheet_menu<2>); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[3], select_sheet_menu<3>); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[4], select_sheet_menu<4>); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[5], select_sheet_menu<5>); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[6], select_sheet_menu<6>); + MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[7], select_sheet_menu<7>); + MENU_END(); +} + void lcd_hw_setup_menu(void) // can not be "static" { -MENU_BEGIN(); -MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch + MENU_BEGIN(); + MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch -//strncpy(buffer,_i("Sheet"),sizeof(buffer)); -//strncpy(buffer,_i(" "),sizeof(buffer)); -//strncpy(buffer,EEPROM_Sheets_base->s[0].name,sizeof(buffer)); + MENU_ITEM_SUBMENU_P(_i("Steel sheets"), sheets_menu); + SETTINGS_NOZZLE; + MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); -//const char* menu = EEPROM_Sheets_base->s[0].name.c_str(); - -//const char *b = new char(buffer); -//const char *b = const char *b = new char(buffer);(buffer); -//printf_P(_N("UVLO - end %d\n"), _millis() - time_start); -//SERIAL_ECHOPGM(buffer); -//SERIAL_ECHOPGM(reinterpret_cast(buffer)); -//SERIAL_ECHOPGM("lakdjushasdjaljsdakjsdn"); -//char* p = &buffer[0]; - -//MENU_ITEM_SUBMENU_P(reinterpret_cast(p),lcd_sheet_menu); - -//delete(b); - -MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], lcd_select_sheet_0_menu); -MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], lcd_select_sheet_1_menu); -MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], lcd_select_sheet_2_menu); - -SETTINGS_NOZZLE; -MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); - -MENU_END(); + MENU_END(); } static void lcd_settings_menu() @@ -6543,22 +6540,6 @@ static void change_sheet_from_menu() menu_back(); } -static void lcd_select_sheet_0_menu() -{ - selected_sheet = 0; - lcd_sheet_menu(); -} -static void lcd_select_sheet_1_menu() -{ - selected_sheet = 1; - lcd_sheet_menu(); -} -static void lcd_select_sheet_2_menu() -{ - selected_sheet = 2; - lcd_sheet_menu(); -} - static void lcd_rename_sheet_menu() { struct MenuData @@ -6605,11 +6586,10 @@ static void lcd_rename_sheet_menu() static void lcd_reset_sheet() { - char name[sizeof(Sheet::name)]; - - strcpy_P(name, (char *)pgm_read_word(&(defaultSheetNames[selected_sheet]))); + SheetName sheetName; + default_sheet_name(selected_sheet, sheetName); eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),0xffff); - eeprom_update_block(name,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name)); + eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name)); if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) { change_sheet_from_menu(); From 0b196da6fc5b2af796c9d3feff67085511beccab Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 29 Aug 2019 18:07:49 +0200 Subject: [PATCH 12/21] Migrate old vale of EEPROM_BABYSTEP_Z only if active sheet is not initialized. --- Firmware/eeprom.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index 10080c07..758bac6d 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -61,7 +61,14 @@ void eeprom_init() if (eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) == 0xffff) eeprom_update_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT, 0); if (eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_FAIL, 0); if (eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0); - if (eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)) == 0xff) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), 0); + if (eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)) == 0xff) + { + eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), 0); + // When upgrading from version older version (before multiple sheets were implemented in v3.8.0) + // Sheet 1 uses the previous Live adjust Z (@EEPROM_BABYSTEP_Z) + int last_babystep = eeprom_read_word((uint16_t *)EEPROM_BABYSTEP_Z); + eeprom_write_word(reinterpret_cast(&(EEPROM_Sheets_base->s[0].z_offset)), last_babystep); + } for (uint_least8_t i = 0; i < (sizeof(Sheets::s)/sizeof(Sheets::s[0])); ++i) { @@ -78,13 +85,6 @@ void eeprom_init() for (uint_least8_t a = 0; a < sizeof(Sheet::name); ++a){ eeprom_write(&(EEPROM_Sheets_base->s[i].name[a]), sheetName.c[a]); } - - // When upgrading from version older version (before multiple sheets were implemented in v3.8.0) - // Sheet 1 uses the previous Live adjust Z (@EEPROM_BABYSTEP_Z) - if(i == 0){ - int last_babystep = eeprom_read_word((uint16_t *)EEPROM_BABYSTEP_Z); - eeprom_write_word(reinterpret_cast(&(EEPROM_Sheets_base->s[i].z_offset)), last_babystep); - } } } check_babystep(); From cd7805ba4629b525f219e0e998bef3c442fd641c Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 29 Aug 2019 18:26:24 +0200 Subject: [PATCH 13/21] Document --- Firmware/eeprom.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 23c812af..732cddff 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -30,9 +30,9 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP #define EEPROM_TOP 4096 #define EEPROM_SILENT 4095 #define EEPROM_LANG 4094 -#define EEPROM_BABYSTEP_X 4092 -#define EEPROM_BABYSTEP_Y 4090 -#define EEPROM_BABYSTEP_Z 4088 +#define EEPROM_BABYSTEP_X 4092 //unused +#define EEPROM_BABYSTEP_Y 4090 //unused +#define EEPROM_BABYSTEP_Z 4088 //legacy, multiple values stored now in EEPROM_Sheets_base #define EEPROM_CALIBRATION_STATUS 4087 #define EEPROM_BABYSTEP_Z0 4085 #define EEPROM_FILAMENTUSED 4081 From d647cdc02c703c7da01d66cd254905bea498de76 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 29 Aug 2019 20:13:10 +0200 Subject: [PATCH 14/21] Convert sheet switcher from sub menu to function. Handle null characters in sheet name. --- Firmware/menu.cpp | 20 ++++++++++++++------ Firmware/menu.h | 4 ++-- Firmware/ultralcd.cpp | 4 +--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 7839bbdc..1b3830a7 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -203,9 +203,13 @@ void menu_format_sheet_E(const Sheet &sheet_E, SheetFormatBuffer &buffer) void menu_format_sheet_select_E(const Sheet &sheet_E, SheetFormatBuffer &buffer) { uint_least8_t index = sprintf_P(buffer.c,PSTR("%-9.9S["), _T(MSG_SHEET)); - eeprom_read_block(&(buffer.c[index]), sheet_E.name, 7); - buffer.c[index + 7] = ']'; - buffer.c[index + 8] = '\0'; + eeprom_read_block(&(buffer.c[index]), sheet_E.name, sizeof(sheet_E.name)/sizeof(sheet_E.name[0])); + for (const uint_least8_t start = index;index - start < sizeof(sheet_E.name)/sizeof(sheet_E.name[0]);++index) + { + if (buffer.c[index] == '\0') break; + } + buffer.c[index] = ']'; + buffer.c[index + 1] = '\0'; } static void menu_draw_item_select_sheet_E(char type_char, const Sheet &sheet) @@ -290,14 +294,18 @@ uint8_t menu_item_submenu_E(const Sheet &sheet, menu_func_t submenu) return 0; } -uint8_t menu_item_submenu_select_sheet_E(const Sheet &sheet, menu_func_t submenu) +uint8_t menu_item_function_E(const Sheet &sheet, menu_func_t func) { if (menu_item == menu_line) { - if (lcd_draw_update) menu_draw_item_select_sheet_E(LCD_STR_ARROW_RIGHT[0], sheet); + if (lcd_draw_update) menu_draw_item_select_sheet_E(' ', sheet); if (menu_clicked && (lcd_encoder == menu_item)) { - menu_submenu(submenu); + menu_clicked = false; + lcd_consume_click(); + lcd_update_enabled = 0; + if (func) func(); + lcd_update_enabled = 1; return menu_item_ret(); } } diff --git a/Firmware/menu.h b/Firmware/menu.h index d9bbf876..c07fe984 100755 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -103,8 +103,8 @@ extern uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu); #define MENU_ITEM_SUBMENU_E(sheet, submenu) do { if (menu_item_submenu_E(sheet, submenu)) return; } while (0) extern uint8_t menu_item_submenu_E(const Sheet &sheet, menu_func_t submenu); -#define MENU_ITEM_SUBMENU_SELECT_SHEET_E(sheet, submenu) do { if (menu_item_submenu_select_sheet_E(sheet, submenu)) return; } while (0) -extern uint8_t menu_item_submenu_select_sheet_E(const Sheet &sheet, menu_func_t submenu); +#define MENU_ITEM_FUNCTION_E(sheet, submenu) do { if (menu_item_function_E(sheet, submenu)) return; } while (0) +extern uint8_t menu_item_function_E(const Sheet &sheet, menu_func_t func); #define MENU_ITEM_BACK_P(str) do { if (menu_item_back_P(str)) return; } while (0) extern uint8_t menu_item_back_P(const char* str); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index b3d202c5..f4fe1ee1 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6536,8 +6536,6 @@ static void change_sheet_from_menu() sheet = next_initialized_sheet(sheet); if (sheet >= 0) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), sheet); - - menu_back(); } static void lcd_rename_sheet_menu() @@ -6716,7 +6714,7 @@ static void lcd_main_menu() const int8_t nextSheet = next_initialized_sheet(sheet); if ((nextSheet >= 0) && (sheet != nextSheet)) // show menu only if we have 2 or more sheets initialized { - MENU_ITEM_SUBMENU_SELECT_SHEET_E(EEPROM_Sheets_base->s[sheet], change_sheet_from_menu); + MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], change_sheet_from_menu); } } } From abf84e36f58c189de8caf301366de255fdb7b6a4 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 29 Aug 2019 20:23:02 +0200 Subject: [PATCH 15/21] Fix sheet menu back caption to Steel sheets to match parent menu caption. --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f4fe1ee1..f0abdc4d 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6603,7 +6603,7 @@ static void lcd_reset_sheet() static void lcd_sheet_menu() { MENU_BEGIN(); - MENU_ITEM_BACK_P(_T(MSG_HW_SETUP)); + MENU_ITEM_BACK_P(_i("Steel sheets")); if(is_sheet_initialized(selected_sheet)){ MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); //// c=18 From 8c8619be051f35f418c1fe72c279d86bf4d014d4 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Thu, 29 Aug 2019 20:52:53 +0200 Subject: [PATCH 16/21] Convert reset sheet sub menu to function. --- Firmware/ultralcd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f0abdc4d..96ec847d 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6597,7 +6597,7 @@ static void lcd_reset_sheet() } } - menu_back(2); + menu_back(); } static void lcd_sheet_menu() @@ -6611,7 +6611,7 @@ static void lcd_sheet_menu() MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_v2_calibration); MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); //// c=18 - MENU_ITEM_SUBMENU_P(_i("Reset"), lcd_reset_sheet); //// c=18 + MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_reset_sheet); //// c=18 MENU_END(); } From 50a8c16f276302c5794b5f238be624cc9eda2217 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 30 Aug 2019 12:00:33 +0200 Subject: [PATCH 17/21] Use EEPROM update instead of write. --- Firmware/eeprom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index 758bac6d..ed10fdcd 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -67,7 +67,7 @@ void eeprom_init() // When upgrading from version older version (before multiple sheets were implemented in v3.8.0) // Sheet 1 uses the previous Live adjust Z (@EEPROM_BABYSTEP_Z) int last_babystep = eeprom_read_word((uint16_t *)EEPROM_BABYSTEP_Z); - eeprom_write_word(reinterpret_cast(&(EEPROM_Sheets_base->s[0].z_offset)), last_babystep); + eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[0].z_offset)), last_babystep); } for (uint_least8_t i = 0; i < (sizeof(Sheets::s)/sizeof(Sheets::s[0])); ++i) From 6c78c2fad58bf175667533d7c8035447c53d6fa3 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 30 Aug 2019 12:02:48 +0200 Subject: [PATCH 18/21] Fix compiler warning. --- Firmware/menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 1b3830a7..7aad723c 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -204,7 +204,7 @@ void menu_format_sheet_select_E(const Sheet &sheet_E, SheetFormatBuffer &buffer) { uint_least8_t index = sprintf_P(buffer.c,PSTR("%-9.9S["), _T(MSG_SHEET)); eeprom_read_block(&(buffer.c[index]), sheet_E.name, sizeof(sheet_E.name)/sizeof(sheet_E.name[0])); - for (const uint_least8_t start = index;index - start < sizeof(sheet_E.name)/sizeof(sheet_E.name[0]);++index) + for (const uint_least8_t start = index; static_cast(index - start) < sizeof(sheet_E.name)/sizeof(sheet_E.name[0]); ++index) { if (buffer.c[index] == '\0') break; } From 26423f98bcb72bae58d27daeb6d618631f0b408b Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 30 Aug 2019 12:24:13 +0200 Subject: [PATCH 19/21] Switch to next sheet if currently selected sheet is not initialized. Move next_initialized_sheet() and change_sheet_from_menu() to eeprom.cpp, rename it to eeprom_next_initialized_sheet() and eeprom_switch_to_next_sheet(). Rename default_sheet_name() to eeprom_default_sheet_name(). --- Firmware/eeprom.cpp | 37 ++++++++++++++++++++++++++++++++++--- Firmware/eeprom.h | 6 ++++-- Firmware/ultralcd.cpp | 38 +++++++------------------------------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index ed10fdcd..60b5c946 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -41,7 +41,8 @@ bool eeprom_is_uninitialized(char *address) return (0xff == eeprom_read_byte(reinterpret_cast(address))); } -bool is_sheet_initialized(uint8_t sheet_num){ +bool eeprom_is_sheet_initialized(uint8_t sheet_num) +{ return (0xffff != eeprom_read_word(reinterpret_cast(&(EEPROM_Sheets_base-> s[sheet_num].z_offset)))); } @@ -80,13 +81,17 @@ void eeprom_init() if(is_uninitialized) { SheetName sheetName; - default_sheet_name(i,sheetName); + eeprom_default_sheet_name(i,sheetName); for (uint_least8_t a = 0; a < sizeof(Sheet::name); ++a){ eeprom_write(&(EEPROM_Sheets_base->s[i].name[a]), sheetName.c[a]); } } } + if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))) + { + eeprom_switch_to_next_sheet(); + } check_babystep(); } @@ -94,7 +99,7 @@ void eeprom_init() //! //! @param[in] index //! @param[out] sheetName -void default_sheet_name(uint8_t index, SheetName &sheetName) +void eeprom_default_sheet_name(uint8_t index, SheetName &sheetName) { sheetName.c[0] = '1' + index; for (uint8_t i = 1; i < (sizeof(sheetName.c)/sizeof(sheetName.c[0])); ++i) @@ -102,3 +107,29 @@ void default_sheet_name(uint8_t index, SheetName &sheetName) sheetName.c[i] = '\0'; } } + +//! @brief Get next initialized sheet +//! +//! If current sheet is the only sheet initialized, current sheet is returned. +//! +//! @param sheet Current sheet +//! @return next initialized sheet +//! @retval -1 no sheet is initialized +int8_t eeprom_next_initialized_sheet(int8_t sheet) +{ + for (int8_t i = 0; i < static_cast(sizeof(Sheets::s)/sizeof(Sheet)); ++i) + { + ++sheet; + if (sheet >= static_cast(sizeof(Sheets::s)/sizeof(Sheet))) sheet = 0; + if (eeprom_is_sheet_initialized(sheet)) return sheet; + } + return -1; +} + +void eeprom_switch_to_next_sheet() +{ + int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); + + sheet = eeprom_next_initialized_sheet(sheet); + if (sheet >= 0) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), sheet); +} diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 732cddff..482ddf93 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -231,12 +231,14 @@ enum #ifdef __cplusplus void eeprom_init(); -bool is_sheet_initialized(uint8_t sheet_num); +bool eeprom_is_sheet_initialized(uint8_t sheet_num); struct SheetName { char c[sizeof(Sheet::name) + 1]; }; -void default_sheet_name(uint8_t index, SheetName &sheetName); +void eeprom_default_sheet_name(uint8_t index, SheetName &sheetName); +int8_t eeprom_next_initialized_sheet(int8_t sheet); +void eeprom_switch_to_next_sheet(); #endif #endif // EEPROM_H diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 96ec847d..6f49f925 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3098,7 +3098,7 @@ static void lcd_babystep_z() _md->status = 1; check_babystep(); - if(!is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){ + if(!eeprom_is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){ _md->babystepMemZ = 0; } else{ @@ -6512,31 +6512,7 @@ static void change_sheet() menu_back(3); } -//! @brief Get next initialized sheet -//! -//! If current sheet is the only sheet initialized, current sheet is returned. -//! -//! @param sheet Current sheet -//! @return next initialized sheet -//! @retval -1 no sheet is initialized -static int8_t next_initialized_sheet(int8_t sheet) -{ - for (int8_t i = 0; i < static_cast(sizeof(Sheets::s)/sizeof(Sheet)); ++i) - { - ++sheet; - if (sheet >= static_cast(sizeof(Sheets::s)/sizeof(Sheet))) sheet = 0; - if (is_sheet_initialized(sheet)) return sheet; - } - return -1; -} -static void change_sheet_from_menu() -{ - int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); - - sheet = next_initialized_sheet(sheet); - if (sheet >= 0) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), sheet); -} static void lcd_rename_sheet_menu() { @@ -6585,13 +6561,13 @@ static void lcd_rename_sheet_menu() static void lcd_reset_sheet() { SheetName sheetName; - default_sheet_name(selected_sheet, sheetName); + eeprom_default_sheet_name(selected_sheet, sheetName); eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),0xffff); eeprom_update_block(sheetName.c,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name)); if (selected_sheet == eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))) { - change_sheet_from_menu(); - if((-1 == next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status())) + eeprom_switch_to_next_sheet(); + if((-1 == eeprom_next_initialized_sheet(0)) && (CALIBRATION_STATUS_CALIBRATED == calibration_status())) { calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); } @@ -6605,7 +6581,7 @@ static void lcd_sheet_menu() MENU_BEGIN(); MENU_ITEM_BACK_P(_i("Steel sheets")); - if(is_sheet_initialized(selected_sheet)){ + if(eeprom_is_sheet_initialized(selected_sheet)){ MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); //// c=18 } @@ -6711,10 +6687,10 @@ static void lcd_main_menu() if (!farm_mode) { const int8_t sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); - const int8_t nextSheet = next_initialized_sheet(sheet); + const int8_t nextSheet = eeprom_next_initialized_sheet(sheet); if ((nextSheet >= 0) && (sheet != nextSheet)) // show menu only if we have 2 or more sheets initialized { - MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], change_sheet_from_menu); + MENU_ITEM_FUNCTION_E(EEPROM_Sheets_base->s[sheet], eeprom_switch_to_next_sheet); } } } From 3d292350d4e896fcb871569339bafe3d4da11baf Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 30 Aug 2019 14:45:25 +0200 Subject: [PATCH 20/21] Do not activate selected_sheet in lcd_v2_calibration() as this leads to calibrating random sheet if activated from calibration menu. selected_sheet is initialized to 0 and contains index of last Sheet menu visited. --- Firmware/ultralcd.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 6f49f925..f1334551 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4690,7 +4690,6 @@ void lcd_toshiba_flash_air_compatibility_toggle() void lcd_v2_calibration() { - eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet); if (mmu_enabled) { const uint8_t filament = choose_menu_P(_i("Select PLA filament:"),_T(MSG_FILAMENT),_i("Cancel")); ////c=20 r=1 ////c=19 r=1 @@ -6576,6 +6575,13 @@ static void lcd_reset_sheet() menu_back(); } +//! @brief Activate selected_sheet and run first layer calibration +static void activate_calibrate_sheet() +{ + eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet); + lcd_v2_calibration(); +} + static void lcd_sheet_menu() { MENU_BEGIN(); @@ -6585,7 +6591,7 @@ static void lcd_sheet_menu() MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); //// c=18 } - MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_v2_calibration); + MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), activate_calibrate_sheet); MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); //// c=18 MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_reset_sheet); //// c=18 From 865484590b46fd14f331efe81bb0b65718136f5a Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 30 Aug 2019 16:11:41 +0200 Subject: [PATCH 21/21] Change default sheet name from "" to "Sheet ". --- Firmware/eeprom.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index 60b5c946..dd1a410b 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -101,11 +101,11 @@ void eeprom_init() //! @param[out] sheetName void eeprom_default_sheet_name(uint8_t index, SheetName &sheetName) { - sheetName.c[0] = '1' + index; - for (uint8_t i = 1; i < (sizeof(sheetName.c)/sizeof(sheetName.c[0])); ++i) - { - sheetName.c[i] = '\0'; - } + static_assert(8 == sizeof(SheetName),"Default sheet name needs to be adjusted."); + sprintf_P(sheetName.c, PSTR("%-6.6S"), _T(MSG_SHEET)); + + sheetName.c[6] = '1' + index; + sheetName.c[7] = '\0'; } //! @brief Get next initialized sheet