From 9ee7a2124b0ab0092efa65fb6d867670fc3ef5b8 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 9 Aug 2018 18:43:07 +0200 Subject: [PATCH 1/4] removed unused code --- Firmware/Marlin_main.cpp | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 543d17b9..55cce6c7 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -972,42 +972,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) case 2: _delay_ms(0); break; case 3: _delay_ms(0); break; } - // _delay_ms(100); - /* - #ifdef MESH_BED_LEVELING - _delay_ms(2000); - - if (!READ(BTN_ENC)) - { - WRITE(BEEPER, HIGH); - _delay_ms(100); - WRITE(BEEPER, LOW); - _delay_ms(200); - WRITE(BEEPER, HIGH); - _delay_ms(100); - WRITE(BEEPER, LOW); - - int _z = 0; - calibration_status_store(CALIBRATION_STATUS_CALIBRATED); - EEPROM_save_B(EEPROM_BABYSTEP_X, &_z); - EEPROM_save_B(EEPROM_BABYSTEP_Y, &_z); - EEPROM_save_B(EEPROM_BABYSTEP_Z, &_z); - } - else - { - - WRITE(BEEPER, HIGH); - _delay_ms(100); - WRITE(BEEPER, LOW); - } - #endif // mesh */ } } - else - { - //_delay_ms(1000); // wait 1sec to display the splash screen // what's this and why do we need it?? - andre - } KEEPALIVE_STATE(IN_HANDLER); } From 923a06c164d6bb605c5a94e21c255c1a67e22f54 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 10 Aug 2018 02:59:49 +0200 Subject: [PATCH 2/4] menu data shared memory re-design +code cleaning --- Firmware/Timer.cpp | 2 +- Firmware/menu.cpp | 28 +++-- Firmware/menu.h | 9 -- Firmware/ultralcd.cpp | 231 +++++++++++++++++++++++++++--------------- Firmware/ultralcd.h | 88 ---------------- 5 files changed, 167 insertions(+), 191 deletions(-) diff --git a/Firmware/Timer.cpp b/Firmware/Timer.cpp index ecf9b9b9..e81abcc1 100644 --- a/Firmware/Timer.cpp +++ b/Firmware/Timer.cpp @@ -10,7 +10,7 @@ * @brief construct Timer * * It is guaranteed, that construction is equivalent with zeroing all members. - * This property can be exploited in MenuData union. + * This property can be exploited in menu_data. */ template Timer::Timer() : m_isRunning(false), m_started() diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 20d92385..1e4b77fa 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -273,25 +273,35 @@ void menu_draw_float13(char chr, const char* str, float val) lcd_printf_P(menu_fmt_float13, chr, str, spaces, val); } -#define _menu_data menuData.edit_menu +typedef struct +{ + //Variables used when editing values. + const char* editLabel; + void* editValue; + int32_t minEditValue; + int32_t maxEditValue; +} menu_data_edit_t; + void _menu_edit_int3(void) { + menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (lcd_draw_update) { - if (lcd_encoder < _menu_data.minEditValue) lcd_encoder = _menu_data.minEditValue; - if (lcd_encoder > _menu_data.maxEditValue) lcd_encoder = _menu_data.maxEditValue; + if (lcd_encoder < _md->minEditValue) lcd_encoder = _md->minEditValue; + if (lcd_encoder > _md->maxEditValue) lcd_encoder = _md->maxEditValue; lcd_set_cursor(0, 1); - menu_draw_int3(' ', _menu_data.editLabel, (int)lcd_encoder); + menu_draw_int3(' ', _md->editLabel, (int)lcd_encoder); } if (LCD_CLICKED) { - *((int*)(_menu_data.editValue)) = (int)lcd_encoder; + *((int*)(_md->editValue)) = (int)lcd_encoder; menu_back(); } } uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int16_t max_val) { + menu_data_edit_t* _md = (menu_data_edit_t*)&(menu_data[0]); if (menu_item == menu_line) { if (lcd_draw_update) @@ -302,10 +312,10 @@ uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int if (menu_clicked && (lcd_encoder == menu_item)) { menu_submenu(_menu_edit_int3); - _menu_data.editLabel = str; - _menu_data.editValue = pval; - _menu_data.minEditValue = min_val; - _menu_data.maxEditValue = max_val; + _md->editLabel = str; + _md->editValue = pval; + _md->minEditValue = min_val; + _md->maxEditValue = max_val; lcd_encoder = *pval; return menu_item_ret(); } diff --git a/Firmware/menu.h b/Firmware/menu.h index c8237df2..70a6151b 100644 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -16,15 +16,6 @@ typedef struct uint8_t position; } menu_record_t; -typedef struct -{ - //Variables used when editing values. - const char* editLabel; - void* editValue; - int32_t minEditValue; - int32_t maxEditValue; -} menu_data_edit_t; - extern menu_record_t menu_stack[MENU_DEPTH_MAX]; extern uint8_t menu_data[MENU_DATA_SIZE]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 1908b7ce..f25e4329 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -46,10 +46,6 @@ char longFilenameOLD[LONG_FILENAME_LENGTH]; static void lcd_sd_updir(); -// State of the currently active menu. -// C Union manages sharing of the static memory by all the menus. -union MenuData menuData = { 0 }; - int8_t ReInitLCD = 0; @@ -2175,23 +2171,34 @@ static void lcd_preheat_menu() static void lcd_support_menu() { - if (menuData.supportMenu.status == 0 || lcd_draw_update == 2) + typedef struct + { // 22bytes total + int8_t status; // 1byte + bool is_flash_air; // 1byte + uint8_t ip[4]; // 4bytes + char ip_str[3*4+3+1]; // 16bytes + } _menu_data_t; +#if (22 > MENU_DATA_SIZE) +#error "check MENU_DATA_SIZE definition!" +#endif + _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]); + if (_md->status == 0 || lcd_draw_update == 2) { // Menu was entered or SD card status has changed (plugged in or removed). // Initialize its status. - menuData.supportMenu.status = 1; - menuData.supportMenu.is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(menuData.supportMenu.ip); - if (menuData.supportMenu.is_flash_air) - sprintf_P(menuData.supportMenu.ip_str, PSTR("%d.%d.%d.%d"), - menuData.supportMenu.ip[0], menuData.supportMenu.ip[1], - menuData.supportMenu.ip[2], menuData.supportMenu.ip[3]); - } else if (menuData.supportMenu.is_flash_air && - menuData.supportMenu.ip[0] == 0 && menuData.supportMenu.ip[1] == 0 && - menuData.supportMenu.ip[2] == 0 && menuData.supportMenu.ip[3] == 0 && - ++ menuData.supportMenu.status == 16) + _md->status = 1; + _md->is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(_md->ip); + if (_md->is_flash_air) + sprintf_P(_md->ip_str, PSTR("%d.%d.%d.%d"), + _md->ip[0], _md->ip[1], + _md->ip[2], _md->ip[3]); + } else if (_md->is_flash_air && + _md->ip[0] == 0 && _md->ip[1] == 0 && + _md->ip[2] == 0 && _md->ip[3] == 0 && + ++ _md->status == 16) { // Waiting for the FlashAir card to get an IP address from a router. Force an update. - menuData.supportMenu.status = 0; + _md->status = 0; } MENU_BEGIN(); @@ -2241,10 +2248,10 @@ static void lcd_support_menu() // Show the FlashAir IP address, if the card is available. - if (menuData.supportMenu.is_flash_air) { + if (_md->is_flash_air) { MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:")); -///! MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, 0); +///! MENU_ITEM(back_RAM, _md->ip_str, 0); } #ifndef MK1BP @@ -2502,7 +2509,7 @@ static void lcd_menu_AutoLoadFilament() } else { - ShortTimer* ptimer = (ShortTimer*)&(menuData.autoLoadFilamentMenu.dummy); + ShortTimer* ptimer = (ShortTimer*)&(menu_data[0]); if (!ptimer->running()) ptimer->start(); lcd_set_cursor(0, 0); lcd_puts_P(_T(MSG_ERROR)); @@ -2613,10 +2620,19 @@ void lcd_menu_statistics() static void _lcd_move(const char *name, int axis, int min, int max) { - if (!menuData._lcd_moveMenu.initialized) + typedef struct + { // 2bytes total + bool initialized; // 1byte + bool endstopsEnabledPrevious; // 1byte + } _menu_data_t; +#if (2 > MENU_DATA_SIZE) +#error "check MENU_DATA_SIZE definition!" +#endif + _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]); + if (!_md->initialized) { - menuData._lcd_moveMenu.endstopsEnabledPrevious = enable_endstops(false); - menuData._lcd_moveMenu.initialized = true; + _md->endstopsEnabledPrevious = enable_endstops(false); + _md->initialized = true; } if (lcd_encoder != 0) { @@ -2637,7 +2653,7 @@ static void _lcd_move(const char *name, int axis, int min, int max) lcd_set_cursor(0, 1); menu_draw_float31(' ', name, current_position[axis]); } - if (menuExiting || LCD_CLICKED) (void)enable_endstops(menuData._lcd_moveMenu.endstopsEnabledPrevious); + if (menuExiting || LCD_CLICKED) (void)enable_endstops(_md->endstopsEnabledPrevious); if (LCD_CLICKED) menu_back(); } @@ -2809,23 +2825,33 @@ static void lcd_move_z() { */ static void _lcd_babystep(int axis, const char *msg) { - if (menuData.babyStep.status == 0) + typedef struct + { // 19bytes total + int8_t status; // 1byte + int babystepMem[3]; // 6bytes + float babystepMemMM[3]; // 12bytes + } _menu_data_t; +#if (19 > MENU_DATA_SIZE) +#error "check MENU_DATA_SIZE definition!" +#endif + _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]); + if (_md->status == 0) { // Menu was entered. // Initialize its status. - menuData.babyStep.status = 1; + _md->status = 1; check_babystep(); - EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]); - EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]); - EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]); + EEPROM_read_B(EEPROM_BABYSTEP_X, &_md->babystepMem[0]); + EEPROM_read_B(EEPROM_BABYSTEP_Y, &_md->babystepMem[1]); + EEPROM_read_B(EEPROM_BABYSTEP_Z, &_md->babystepMem[2]); - menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS]; - menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS]; - menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS]; + _md->babystepMemMM[0] = _md->babystepMem[0]/axis_steps_per_unit[X_AXIS]; + _md->babystepMemMM[1] = _md->babystepMem[1]/axis_steps_per_unit[Y_AXIS]; + _md->babystepMemMM[2] = _md->babystepMem[2]/axis_steps_per_unit[Z_AXIS]; lcd_draw_update = 1; //SERIAL_ECHO("Z baby step: "); - //SERIAL_ECHO(menuData.babyStep.babystepMem[2]); + //SERIAL_ECHO(_md->babystepMem[2]); // Wait 90 seconds before closing the live adjust dialog. lcd_timeoutToStatus.start(); } @@ -2833,11 +2859,11 @@ static void _lcd_babystep(int axis, const char *msg) if (lcd_encoder != 0) { if (homing_flag) lcd_encoder = 0; - menuData.babyStep.babystepMem[axis] += (int)lcd_encoder; + _md->babystepMem[axis] += (int)lcd_encoder; if (axis == 2) { - if (menuData.babyStep.babystepMem[axis] < Z_BABYSTEP_MIN) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm - else if (menuData.babyStep.babystepMem[axis] > Z_BABYSTEP_MAX) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MAX; //0 + if (_md->babystepMem[axis] < Z_BABYSTEP_MIN) _md->babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm + else if (_md->babystepMem[axis] > Z_BABYSTEP_MAX) _md->babystepMem[axis] = Z_BABYSTEP_MAX; //0 else { CRITICAL_SECTION_START @@ -2845,7 +2871,7 @@ static void _lcd_babystep(int axis, const char *msg) CRITICAL_SECTION_END } } - menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[axis]; + _md->babystepMemMM[axis] = _md->babystepMem[axis]/axis_steps_per_unit[axis]; delay(50); lcd_encoder = 0; lcd_draw_update = 1; @@ -2853,14 +2879,14 @@ static void _lcd_babystep(int axis, const char *msg) if (lcd_draw_update) { lcd_set_cursor(0, 1); - menu_draw_float13(' ', msg, menuData.babyStep.babystepMemMM[axis]); + menu_draw_float13(' ', msg, _md->babystepMemMM[axis]); } if (LCD_CLICKED || menuExiting) { // Only update the EEPROM when leaving the menu. EEPROM_save_B( (axis == X_AXIS) ? EEPROM_BABYSTEP_X : ((axis == Y_AXIS) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z), - &menuData.babyStep.babystepMem[axis]); + &_md->babystepMem[axis]); if(Z_AXIS == axis) calibration_status_store(CALIBRATION_STATUS_CALIBRATED); } if (LCD_CLICKED) menu_back(); @@ -2878,72 +2904,94 @@ static void lcd_babystep_z() { static void lcd_adjust_bed(); +typedef struct +{ // 13bytes total + int8_t status; // 1byte + int8_t left; // 1byte + int8_t right; // 1byte + int8_t front; // 1byte + int8_t rear; // 1byte + int left2; // 2byte + int right2; // 2byte + int front2; // 2byte + int rear2; // 2byte +} _menu_data_adjust_bed_t; +#if (13 > MENU_DATA_SIZE) +#error "check MENU_DATA_SIZE definition!" +#endif + static void lcd_adjust_bed_reset() { - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0); - eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0); - menuData.adjustBed.status = 0; + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0); + eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0); + _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]); + _md->status = 0; } -void adjust_bed_reset() { +void adjust_bed_reset() +{ + _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0); eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0); - menuData.adjustBed.left = menuData.adjustBed.left2 = 0; - menuData.adjustBed.right = menuData.adjustBed.right2 = 0; - menuData.adjustBed.front = menuData.adjustBed.front2 = 0; - menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0; + _md->left = _md->left2 = 0; + _md->right = _md->right2 = 0; + _md->front = _md->front2 = 0; + _md->rear = _md->rear2 = 0; } + #define BED_ADJUSTMENT_UM_MAX 50 static void lcd_adjust_bed() { - if (menuData.adjustBed.status == 0) { + _menu_data_adjust_bed_t* _md = (_menu_data_adjust_bed_t*)&(menu_data[0]); + if (_md->status == 0) + { // Menu was entered. // Initialize its status. - menuData.adjustBed.status = 1; + _md->status = 1; bool valid = false; - menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT); - menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT); - menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT); - menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR); + _md->left = _md->left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT); + _md->right = _md->right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT); + _md->front = _md->front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT); + _md->rear = _md->rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR); if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 && - menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX && - menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX && - menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX && - menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX) + _md->left >= -BED_ADJUSTMENT_UM_MAX && _md->left <= BED_ADJUSTMENT_UM_MAX && + _md->right >= -BED_ADJUSTMENT_UM_MAX && _md->right <= BED_ADJUSTMENT_UM_MAX && + _md->front >= -BED_ADJUSTMENT_UM_MAX && _md->front <= BED_ADJUSTMENT_UM_MAX && + _md->rear >= -BED_ADJUSTMENT_UM_MAX && _md->rear <= BED_ADJUSTMENT_UM_MAX) valid = true; if (! valid) { // Reset the values: simulate an edit. - menuData.adjustBed.left2 = 0; - menuData.adjustBed.right2 = 0; - menuData.adjustBed.front2 = 0; - menuData.adjustBed.rear2 = 0; + _md->left2 = 0; + _md->right2 = 0; + _md->front2 = 0; + _md->rear2 = 0; } lcd_draw_update = 1; eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1); } - if (menuData.adjustBed.left != menuData.adjustBed.left2) - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2); - if (menuData.adjustBed.right != menuData.adjustBed.right2) - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2); - if (menuData.adjustBed.front != menuData.adjustBed.front2) - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2); - if (menuData.adjustBed.rear != menuData.adjustBed.rear2) - eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2); + if (_md->left != _md->left2) + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, _md->left = _md->left2); + if (_md->right != _md->right2) + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, _md->right = _md->right2); + if (_md->front != _md->front2) + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, _md->front = _md->front2); + if (_md->rear != _md->rear2) + eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, _md->rear = _md->rear2); MENU_BEGIN(); MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); - MENU_ITEM_EDIT_int3_P(_i("Left side [um]"), &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 - MENU_ITEM_EDIT_int3_P(_i("Right side[um]"), &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14 r=1 - MENU_ITEM_EDIT_int3_P(_i("Front side[um]"), &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14 r=1 - MENU_ITEM_EDIT_int3_P(_i("Rear side [um]"), &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("Left side [um]"), &_md->left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("Right side[um]"), &_md->right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("Front side[um]"), &_md->front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14 r=1 + MENU_ITEM_EDIT_int3_P(_i("Rear side [um]"), &_md->rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14 r=1 MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_adjust_bed_reset);////MSG_BED_CORRECTION_RESET c=0 r=0 MENU_END(); } @@ -5733,15 +5781,30 @@ static void lcd_colorprint_change() { static void lcd_tune_menu() { - if (menuData.tuneMenu.status == 0) { - // Menu was entered. Mark the menu as entered and save the current extrudemultiply value. - menuData.tuneMenu.status = 1; - menuData.tuneMenu.extrudemultiply = extrudemultiply; - } else if (menuData.tuneMenu.extrudemultiply != extrudemultiply) { - // extrudemultiply has been changed from the child menu. Apply the new value. - menuData.tuneMenu.extrudemultiply = extrudemultiply; - calculate_extruder_multipliers(); - } + typedef struct + { // 3bytes total + // To recognize, whether the menu has been just initialized. + int8_t status; // 1byte + // Backup of extrudemultiply, to recognize, that the value has been changed and + // it needs to be applied. + int16_t extrudemultiply; // 2byte + } _menu_data_t; +#if (3 > MENU_DATA_SIZE) +#error "check MENU_DATA_SIZE definition!" +#endif + _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]); + if (_md->status == 0) + { + // Menu was entered. Mark the menu as entered and save the current extrudemultiply value. + _md->status = 1; + _md->extrudemultiply = extrudemultiply; + } + else if (_md->extrudemultiply != extrudemultiply) + { + // extrudemultiply has been changed from the child menu. Apply the new value. + _md->extrudemultiply = extrudemultiply; + calculate_extruder_multipliers(); + } EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu)); diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 77da5933..8925d13c 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -13,92 +13,6 @@ extern void menu_lcd_longpress_func(void); extern void menu_lcd_charsetup_func(void); extern void menu_lcd_lcdupdate_func(void); -struct EditMenuParentState -{ - //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings. - menu_func_t prevMenu; - uint16_t prevEncoderPosition; - //Variables used when editing values. - const char* editLabel; - void* editValue; - int32_t minEditValue, maxEditValue; - // menu_func_t callbackFunc; -}; - -union MenuData -{ - struct BabyStep - { - // 29B total - int8_t status; - int babystepMem[3]; - float babystepMemMM[3]; - } babyStep; - - struct SupportMenu - { - // 6B+16B=22B total - int8_t status; - bool is_flash_air; - uint8_t ip[4]; - char ip_str[3*4+3+1]; - } supportMenu; - - struct AdjustBed - { - // 6+13+16=35B - // editMenuParentState is used when an edit menu is entered, so it knows - // the return menu and encoder state. - struct EditMenuParentState editMenuParentState; - int8_t status; - int8_t left; - int8_t right; - int8_t front; - int8_t rear; - int left2; - int right2; - int front2; - int rear2; - } adjustBed; - - struct TuneMenu - { - // editMenuParentState is used when an edit menu is entered, so it knows - // the return menu and encoder state. - struct EditMenuParentState editMenuParentState; - // To recognize, whether the menu has been just initialized. - int8_t status; - // Backup of extrudemultiply, to recognize, that the value has been changed and - // it needs to be applied. - int16_t extrudemultiply; - } tuneMenu; - - // editMenuParentState is used when an edit menu is entered, so it knows - // the return menu and encoder state. - struct EditMenuParentState editMenuParentState; - - struct AutoLoadFilamentMenu - { - //ShortTimer timer; - char dummy; - } autoLoadFilamentMenu; - struct _Lcd_moveMenu - { - bool initialized; - bool endstopsEnabledPrevious; - } _lcd_moveMenu; - struct sdcard_menu_t - { - uint8_t viewState; - } sdcard_menu; - menu_data_edit_t edit_menu; -}; - -// State of the currently active menu. -// C Union manages sharing of the static memory by all the menus. -extern union MenuData menuData; - - // Call with a false parameter to suppress the LCD update from various places like the planner or the temp control. void ultralcd_init(); void lcd_setstatus(const char* message); @@ -225,8 +139,6 @@ void lcd_temp_cal_show_result(bool result); bool lcd_wait_for_pinda(float temp); -union MenuData; - void bowden_menu(); char reset_menu(); char choose_extruder_menu(); From b16fec956c51f06f3bfd048f54b0894e501232bd Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 10 Aug 2018 16:20:53 +0200 Subject: [PATCH 3/4] Enabled pullup for RX2 pin (it prevents uart2 from rx buffer overflow in case of disconnected MMU) --- Firmware/uart2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Firmware/uart2.c b/Firmware/uart2.c index 11015fa0..cfed5c09 100644 --- a/Firmware/uart2.c +++ b/Firmware/uart2.c @@ -34,6 +34,8 @@ int uart2_getchar(FILE *stream) //uart init (io + FILE stream) void uart2_init(void) { + DDRH &= ~0x01; + PORTH |= 0x01; rbuf_ini(uart2_ibuf, sizeof(uart2_ibuf) - 4); UCSR2A |= (1 << U2X2); // baudrate multiplier UBRR2L = UART_BAUD_SELECT(UART2_BAUD, F_CPU); // select baudrate From 8409a26594ae90b953f84f9ac861c1dacfe919af Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 10 Aug 2018 19:55:50 +0200 Subject: [PATCH 4/4] Live adjust Z - display zero in case of invalid calibration status (same logic in babystep_load and _lcd_babystep) --- Firmware/Marlin_main.cpp | 3 ++- Firmware/mesh_bed_calibration.cpp | 7 ++++--- Firmware/mesh_bed_calibration.h | 1 + Firmware/mmu.cpp | 2 +- Firmware/tmc2130.cpp | 3 ++- Firmware/ultralcd.cpp | 13 +++++++++---- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 55cce6c7..bca45487 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7699,7 +7699,8 @@ void wait_for_heater(long codenum) { } } -void check_babystep() { +void check_babystep() +{ int babystep_z; EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystep_z); if ((babystep_z < Z_BABYSTEP_MIN) || (babystep_z > Z_BABYSTEP_MAX)) { diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 48bb2071..102aebae 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2984,13 +2984,14 @@ static int babystepLoadZ = 0; void babystep_load() { + babystepLoadZ = 0; // Apply Z height correction aka baby stepping before mesh bed leveling gets activated. - if(calibration_status() < CALIBRATION_STATUS_LIVE_ADJUST) + if (calibration_status() < CALIBRATION_STATUS_LIVE_ADJUST) { check_babystep(); //checking if babystep is in allowed range, otherwise setting babystep to 0 // End of G80: Apply the baby stepping value. - EEPROM_read_B(EEPROM_BABYSTEP_Z,&babystepLoadZ); + EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ); #if 0 SERIAL_ECHO("Z baby step: "); @@ -3026,7 +3027,7 @@ void babystep_undo() void babystep_reset() { - babystepLoadZ = 0; + babystepLoadZ = 0; } void count_xyz_details(float (&distanceMin)[2]) { diff --git a/Firmware/mesh_bed_calibration.h b/Firmware/mesh_bed_calibration.h index 6d020f8c..d928f1d1 100644 --- a/Firmware/mesh_bed_calibration.h +++ b/Firmware/mesh_bed_calibration.h @@ -176,6 +176,7 @@ extern void babystep_undo(); // Reset the current babystep counter without moving the axes. extern void babystep_reset(); + extern void count_xyz_details(float (&distanceMin)[2]); extern bool sample_z(); diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 824a0648..75e436a1 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -26,7 +26,7 @@ extern char choose_extruder_menu(); bool mmu_enabled = false; -int8_t mmu_state = -1; +int8_t mmu_state = 0; uint8_t mmu_extruder = 0; diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 35b61ecc..0ff1b905 100644 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -77,7 +77,8 @@ bool tmc2130_sg_change = false; bool skip_debug_msg = false; -#define DBG(args...) printf_P(args) +#define DBG(args...) +//printf_P(args) #ifndef _n #define _n PSTR #endif //_n diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f25e4329..0a16b949 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -120,7 +120,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 lcd_settings_menu_back(); static void prusa_stat_printerstatus(int _status); static void prusa_stat_farm_number(); @@ -2846,6 +2846,10 @@ static void _lcd_babystep(int axis, const char *msg) EEPROM_read_B(EEPROM_BABYSTEP_Y, &_md->babystepMem[1]); EEPROM_read_B(EEPROM_BABYSTEP_Z, &_md->babystepMem[2]); + // same logic as in babystep_load + if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) + _md->babystepMem[2] = 0; + _md->babystepMemMM[0] = _md->babystepMem[0]/axis_steps_per_unit[X_AXIS]; _md->babystepMemMM[1] = _md->babystepMem[1]/axis_steps_per_unit[Y_AXIS]; _md->babystepMemMM[2] = _md->babystepMem[2]/axis_steps_per_unit[Z_AXIS]; @@ -3014,7 +3018,7 @@ void pid_extruder() { } } - +/* void lcd_adjust_z() { int enc_dif = 0; int cursor_pos = 1; @@ -3097,7 +3101,7 @@ void lcd_adjust_z() { lcd_clear(); lcd_return_to_status(); -} +}*/ bool lcd_wait_for_pinda(float temp) { lcd_set_custom_characters_degree(); @@ -4781,6 +4785,7 @@ static void lcd_ustep_linearity_menu_save() } #endif //TMC2130 +/* static void lcd_settings_menu_back() { #ifdef TMC2130 @@ -4799,7 +4804,7 @@ static void lcd_settings_menu_back() menu_menu = lcd_main_menu; // lcd_main_menu(); } - +*/ static void lcd_calibration_menu() {