From 23e5cea5d0ca0596378ca5507b442dd17a132c60 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 8 Aug 2018 18:58:03 +0200 Subject: [PATCH 01/16] MMU - code cleaning (modularity) M403 set filament type hardware reset --- Firmware/Marlin.h | 6 +- Firmware/Marlin_main.cpp | 185 +++-------------------------------- Firmware/mmu.cpp | 202 +++++++++++++++++++++++++++++++++++++-- Firmware/mmu.h | 13 +++ 4 files changed, 222 insertions(+), 184 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 2ab9c093..fff37bf3 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -467,12 +467,8 @@ void gcode_M701(); void proc_commands(); -void manage_response(bool move_axes, bool turn_off_nozzle); -bool mmu_get_response(bool timeout); -void mmu_not_responding(); -void mmu_load_to_nozzle(); + void M600_load_filament(); -void mmu_M600_load_filament(bool automatic); void M600_load_filament_movements(); void M600_wait_for_user(); void M600_check_state(); \ No newline at end of file diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index fe5553a2..b20b8254 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -508,7 +508,6 @@ unsigned long starttime=0; unsigned long stoptime=0; unsigned long _usb_timer = 0; -static uint8_t tmp_extruder; bool extruder_under_pressure = true; @@ -6336,21 +6335,14 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) //currently three different materials are needed (default, flex and PVA) //add storing this information for different load/unload profiles etc. in the future //firmware does not wait for "ok" from mmu - - uint8_t extruder; - uint8_t filament; - - if(code_seen('E')) extruder = code_value(); - if(code_seen('F')) filament = code_value(); - - printf_P(PSTR("Extruder: %d; "), extruder); - switch (filament) { - case FILAMENT_FLEX: printf_P(PSTR("Flex\n")); break; - case FILAMENT_PVA: printf_P(PSTR("PVA\n")); break; - default: printf_P(PSTR("Default\n")); break; + if (mmu_enabled) + { + uint8_t extruder; + uint8_t filament; + if(code_seen('E')) extruder = code_value(); + if(code_seen('F')) filament = code_value(); + mmu_set_filament_type(extruder, filament); } - printf_P(PSTR("F%d%d\n"), extruder, filament); - mmu_printf_P(PSTR("F%d%d\n"), extruder, filament); } break; @@ -8872,7 +8864,8 @@ uint16_t print_time_remaining() { return print_t; } -uint8_t print_percent_done() { +uint8_t print_percent_done() +{ //in case that we have information from M73 gcode return percentage counted by slicer, else return percentage counted as byte_printed/filesize uint8_t percent_done = 0; if (SilentModeMenu == SILENT_MODE_OFF && print_percent_done_normal <= 100) { @@ -8887,135 +8880,17 @@ uint8_t print_percent_done() { return percent_done; } -static void print_time_remaining_init() { +static void print_time_remaining_init() +{ print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; print_percent_done_normal = PRINT_PERCENT_DONE_INIT; print_percent_done_silent = PRINT_PERCENT_DONE_INIT; } -bool mmu_get_response(bool timeout) { - //waits for "ok" from mmu - //function returns true if "ok" was received - //if timeout is set to true function return false if there is no "ok" received before timeout - bool response = true; - LongTimer mmu_get_reponse_timeout; - KEEPALIVE_STATE(IN_PROCESS); - mmu_get_reponse_timeout.start(); - while (mmu_rx_ok() <= 0) - { - delay_keep_alive(100); - if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul)) { //5 minutes timeout - response = false; - break; - } - } - return response; -} - -void manage_response(bool move_axes, bool turn_off_nozzle) { - - bool response = false; - mmu_print_saved = false; - bool lcd_update_was_enabled = false; - float hotend_temp_bckp = degTargetHotend(active_extruder); - float z_position_bckp = current_position[Z_AXIS]; - float x_position_bckp = current_position[X_AXIS]; - float y_position_bckp = current_position[Y_AXIS]; - while(!response) { - response = mmu_get_response(true); //wait for "ok" from mmu - if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit - if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater - if (lcd_update_enabled) { - lcd_update_was_enabled = true; - lcd_update_enable(false); - } - st_synchronize(); - mmu_print_saved = true; - - hotend_temp_bckp = degTargetHotend(active_extruder); - if (move_axes) { - z_position_bckp = current_position[Z_AXIS]; - x_position_bckp = current_position[X_AXIS]; - y_position_bckp = current_position[Y_AXIS]; - - //lift z - current_position[Z_AXIS] += Z_PAUSE_LIFT; - if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); - st_synchronize(); - - //Move XY to side - current_position[X_AXIS] = X_PAUSE_POS; - current_position[Y_AXIS] = Y_PAUSE_POS; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); - st_synchronize(); - } - if (turn_off_nozzle) { - //set nozzle target temperature to 0 - setAllTargetHotends(0); - printf_P(PSTR("MMU not responding\n")); - lcd_show_fullscreen_message_and_wait_P(_i("MMU needs user attention. Please press knob to resume nozzle target temperature.")); - setTargetHotend(hotend_temp_bckp, active_extruder); - while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5) { - delay_keep_alive(1000); - lcd_wait_for_heater(); - } - } - } - lcd_display_message_fullscreen_P(_i("Check MMU. Fix the issue and then press button on MMU unit.")); - } - else if (mmu_print_saved) { - printf_P(PSTR("MMU start responding\n")); - lcd_clear(); - lcd_display_message_fullscreen_P(_i("MMU OK. Resuming...")); - if (move_axes) { - current_position[X_AXIS] = x_position_bckp; - current_position[Y_AXIS] = y_position_bckp; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); - st_synchronize(); - current_position[Z_AXIS] = z_position_bckp; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); - st_synchronize(); - } - else { - delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements - } - } - } - if (lcd_update_was_enabled) lcd_update_enable(true); -} - -void mmu_load_to_nozzle() { - st_synchronize(); - - bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; - current_position[E_AXIS] += 7.2f; - float feedrate = 562; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 14.4f; - feedrate = 871; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 36.0f; - feedrate = 1393; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 14.4f; - feedrate = 871; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; -} - -void mmu_switch_extruder(uint8_t extruder) { - -} - -void M600_check_state() { +void M600_check_state() +{ //Wait for user to check the state lcd_change_fil_state = 0; @@ -9129,40 +9004,6 @@ void M600_wait_for_user() { WRITE(BEEPER, LOW); } -void mmu_M600_load_filament(bool automatic) -{ - //load filament for mmu v2 - - bool response = false; - bool yes = false; - if (!automatic) { - yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false); - if(yes) tmp_extruder = choose_extruder_menu(); - else tmp_extruder = mmu_extruder; - - } - else { - tmp_extruder = (tmp_extruder+1)%5; - } - lcd_update_enable(false); - lcd_clear(); - lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT)); - lcd_print(" "); - lcd_print(tmp_extruder + 1); - snmm_filaments_used |= (1 << tmp_extruder); //for stop print - printf_P(PSTR("T code: %d \n"), tmp_extruder); - mmu_printf_P(PSTR("T%d\n"), tmp_extruder); - - manage_response(false, true); - mmu_extruder = tmp_extruder; //filament change is finished - - mmu_load_to_nozzle(); - - st_synchronize(); - current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder); -} - void M600_load_filament_movements() { #ifdef SNMM diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 70cc4ef3..de760d0c 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -10,14 +10,26 @@ extern const char* lcd_display_message_fullscreen_P(const char *msg); +extern void lcd_show_fullscreen_message_and_wait_P(const char *msg); +extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, bool default_yes = false); extern void lcd_return_to_status(); +extern void lcd_wait_for_heater(); +extern char choose_extruder_menu(); + + +#define MMU_TODELAY 100 +#define MMU_TIMEOUT 10 + +#define MMU_HWRESET +#define MMU_RST_PIN 76 -#define MMU_TIMEOUT 100 bool mmu_enabled = false; uint8_t mmu_extruder = 0; +uint8_t tmp_extruder = 0; + int8_t mmu_finda = -1; int16_t mmu_version = -1; @@ -62,6 +74,8 @@ int8_t mmu_rx_start(void) //initialize mmu_unit bool mmu_init(void) { + digitalWrite(MMU_RST_PIN, HIGH); + pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin uart2_init(); //init uart2 _delay_ms(10); //wait 10ms for sure if (mmu_reset()) //reset mmu @@ -75,10 +89,16 @@ bool mmu_init(void) bool mmu_reset(void) { +#ifdef MMU_HWRESET + digitalWrite(MMU_RST_PIN, LOW); + _delay_us(100); + digitalWrite(MMU_RST_PIN, HIGH); +#else mmu_puts_P(PSTR("X0\n")); //send command - unsigned char timeout = 10; //timeout = 10x100ms +#endif + unsigned char timeout = MMU_TIMEOUT; //timeout = 10x100ms while ((mmu_rx_start() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); + delay_keep_alive(MMU_TODELAY); mmu_enabled = timeout?true:false; return mmu_enabled; } @@ -86,9 +106,9 @@ bool mmu_reset(void) int8_t mmu_read_finda(void) { mmu_puts_P(PSTR("P0\n")); - unsigned char timeout = 10; //10x100ms + unsigned char timeout = MMU_TIMEOUT; //10x100ms while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); + delay_keep_alive(MMU_TODELAY); mmu_finda = -1; if (timeout) fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); @@ -98,14 +118,182 @@ int8_t mmu_read_finda(void) int16_t mmu_read_version(void) { mmu_puts_P(PSTR("S1\n")); - unsigned char timeout = 10; //10x100ms + unsigned char timeout = MMU_TIMEOUT; //10x100ms while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); + delay_keep_alive(MMU_TODELAY); if (timeout) fscanf_P(uart2io, PSTR("%u"), &mmu_version); return mmu_version; } +int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament) +{ + printf_P(PSTR("MMU <= 'F%d %d'\n"), extruder, filament); + mmu_printf_P(PSTR("F%d %d\n"), extruder, filament); + unsigned char timeout = MMU_TIMEOUT; //10x100ms + while ((mmu_rx_ok() <= 0) && (--timeout)) + delay_keep_alive(MMU_TODELAY); + return timeout?1:0; +} + +bool mmu_get_response(bool timeout) +{ + printf_P(PSTR("mmu_get_response - begin\n")); + //waits for "ok" from mmu + //function returns true if "ok" was received + //if timeout is set to true function return false if there is no "ok" received before timeout + bool response = true; + LongTimer mmu_get_reponse_timeout; + KEEPALIVE_STATE(IN_PROCESS); + mmu_get_reponse_timeout.start(); + while (mmu_rx_ok() <= 0) + { + delay_keep_alive(100); + if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul)) + { //5 minutes timeout + response = false; + break; + } + } + printf_P(PSTR("mmu_get_response - end %d\n"), response?1:0); + return response; +} + + +void manage_response(bool move_axes, bool turn_off_nozzle) +{ + bool response = false; + mmu_print_saved = false; + bool lcd_update_was_enabled = false; + float hotend_temp_bckp = degTargetHotend(active_extruder); + float z_position_bckp = current_position[Z_AXIS]; + float x_position_bckp = current_position[X_AXIS]; + float y_position_bckp = current_position[Y_AXIS]; + while(!response) + { + response = mmu_get_response(true); //wait for "ok" from mmu + if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit + if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater + if (lcd_update_enabled) { + lcd_update_was_enabled = true; + lcd_update_enable(false); + } + st_synchronize(); + mmu_print_saved = true; + + hotend_temp_bckp = degTargetHotend(active_extruder); + if (move_axes) { + z_position_bckp = current_position[Z_AXIS]; + x_position_bckp = current_position[X_AXIS]; + y_position_bckp = current_position[Y_AXIS]; + + //lift z + current_position[Z_AXIS] += Z_PAUSE_LIFT; + if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); + st_synchronize(); + + //Move XY to side + current_position[X_AXIS] = X_PAUSE_POS; + current_position[Y_AXIS] = Y_PAUSE_POS; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); + st_synchronize(); + } + if (turn_off_nozzle) { + //set nozzle target temperature to 0 + setAllTargetHotends(0); + printf_P(PSTR("MMU not responding\n")); + lcd_show_fullscreen_message_and_wait_P(_i("MMU needs user attention. Please press knob to resume nozzle target temperature.")); + setTargetHotend(hotend_temp_bckp, active_extruder); + while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5) { + delay_keep_alive(1000); + lcd_wait_for_heater(); + } + } + } + lcd_display_message_fullscreen_P(_i("Check MMU. Fix the issue and then press button on MMU unit.")); + } + else if (mmu_print_saved) { + printf_P(PSTR("MMU start responding\n")); + lcd_clear(); + lcd_display_message_fullscreen_P(_i("MMU OK. Resuming...")); + if (move_axes) { + current_position[X_AXIS] = x_position_bckp; + current_position[Y_AXIS] = y_position_bckp; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); + st_synchronize(); + current_position[Z_AXIS] = z_position_bckp; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); + st_synchronize(); + } + else { + delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements + } + } + } + if (lcd_update_was_enabled) lcd_update_enable(true); +} + +void mmu_load_to_nozzle() +{ + st_synchronize(); + + bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; + if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; + current_position[E_AXIS] += 7.2f; + float feedrate = 562; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 14.4f; + feedrate = 871; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 36.0f; + feedrate = 1393; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 14.4f; + feedrate = 871; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; +} + +void mmu_M600_load_filament(bool automatic) +{ + //load filament for mmu v2 + + bool response = false; + bool yes = false; + if (!automatic) { + yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false); + if(yes) tmp_extruder = choose_extruder_menu(); + else tmp_extruder = mmu_extruder; + + } + else { + tmp_extruder = (tmp_extruder+1)%5; + } + lcd_update_enable(false); + lcd_clear(); + lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT)); + lcd_print(" "); + lcd_print(tmp_extruder + 1); + snmm_filaments_used |= (1 << tmp_extruder); //for stop print + printf_P(PSTR("T code: %d \n"), tmp_extruder); + mmu_printf_P(PSTR("T%d\n"), tmp_extruder); + + manage_response(false, true); + mmu_extruder = tmp_extruder; //filament change is finished + + mmu_load_to_nozzle(); + + st_synchronize(); + current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder); +} + + void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is set_extrude_min_temp(.0); diff --git a/Firmware/mmu.h b/Firmware/mmu.h index 91a1f511..65bce969 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -7,6 +7,8 @@ extern bool mmu_enabled; extern uint8_t mmu_extruder; +extern uint8_t tmp_extruder; + extern int8_t mmu_finda; extern int16_t mmu_version; @@ -27,6 +29,17 @@ extern int8_t mmu_read_finda(void); extern int16_t mmu_read_version(void); +extern int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament); + + +extern bool mmu_get_response(bool timeout); + +extern void manage_response(bool move_axes, bool turn_off_nozzle); + +extern void mmu_load_to_nozzle(); + +extern void mmu_M600_load_filament(bool automatic); + extern void extr_mov(float shift, float feed_rate); extern void change_extr(int extr); From ca25ec90bdccff5eae5156036a685ce3e1969aac Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 8 Aug 2018 19:28:34 +0200 Subject: [PATCH 02/16] Disabled timeouts in support and failstats menus --- Firmware/ultralcd.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 02bf82c3..247eae6f 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1954,6 +1954,9 @@ static void lcd_menu_extruder_info() // Display Nozzle fan RPM fan_speed_RPM[0] = 60*fan_speed[0]; fan_speed_RPM[1] = 60*fan_speed[1]; + + lcd_timeoutToStatus.stop(); //infinite timeout + lcd_printf_P(_N( ESC_H(0,0) "Nozzle FAN: %4d RPM\n" @@ -2001,6 +2004,7 @@ static void lcd_menu_fails_stats_total() // Filam. runouts 000 // Crash X 000 Y 000 ////////////////////// + lcd_timeoutToStatus.stop(); //infinite timeout uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT); uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT); @@ -2017,6 +2021,7 @@ static void lcd_menu_fails_stats_print() // Filam. runouts 000 // Crash X 000 Y 000 ////////////////////// + lcd_timeoutToStatus.stop(); //infinite timeout uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT); uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X); @@ -2057,6 +2062,7 @@ static void lcd_menu_fails_stats() */ static void lcd_menu_fails_stats() { + lcd_timeoutToStatus.stop(); //infinite timeout uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal); @@ -2065,6 +2071,7 @@ static void lcd_menu_fails_stats() #else static void lcd_menu_fails_stats() { + lcd_timeoutToStatus.stop(); //infinite timeout MENU_BEGIN(); MENU_ITEM_BACK_P(_T(MSG_MAIN)); MENU_END(); @@ -2091,6 +2098,8 @@ static void lcd_menu_debug() static void lcd_menu_temperatures() { + lcd_timeoutToStatus.stop(); //infinite timeout + lcd_printf_P(PSTR(ESC_H(1,0) "Nozzle: %d%c" ESC_H(1,1) "Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01'); #ifdef AMBIENT_THERMISTOR lcd_printf_P(PSTR(ESC_H(1,2) "Ambient: %d%c" ESC_H(1,3) "PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01'); @@ -2108,6 +2117,7 @@ static void lcd_menu_temperatures() #define VOLT_DIV_REF 5 static void lcd_menu_voltages() { + lcd_timeoutToStatus.stop(); //infinite timeout float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; // float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; // lcd_printf_P(PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed))); From 2f1799762223d1e0ed9f26460b3a5827747ccb86 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 8 Aug 2018 19:33:44 +0200 Subject: [PATCH 03/16] reset safety timer everytime lcd clicked --- Firmware/lcd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index 0d1e3840..f8e4b4c6 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -770,6 +770,7 @@ void lcd_buttons_update(void) lcd_timeoutToStatus.start(); if (!buttonBlanking.running() || buttonBlanking.expired(BUTTON_BLANKING_TIME)) { buttonBlanking.start(); + safetyTimer.start(); if ((lcd_button_pressed == 0) && (lcd_long_press_active == 0)) { longPressTimer.start(); From 990a5c9119b2515d265ecb10f745371f2fee3cbb Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 8 Aug 2018 19:51:50 +0200 Subject: [PATCH 04/16] PFW489 (github issue 1008) - time remaining variables declared as uint32 --- Firmware/Marlin.h | 4 ++-- Firmware/Marlin_main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index fff37bf3..4333c977 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -362,8 +362,8 @@ extern uint8_t print_percent_done_normal; extern uint16_t print_time_remaining_normal; extern uint8_t print_percent_done_silent; extern uint16_t print_time_remaining_silent; -#define PRINT_TIME_REMAINING_INIT 65535 -#define PRINT_PERCENT_DONE_INIT 255 +#define PRINT_TIME_REMAINING_INIT 0xffffffff +#define PRINT_PERCENT_DONE_INIT 0xff #define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == 4) || saved_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL) || card.paused || mmu_print_saved) extern void calculate_extruder_multipliers(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b20b8254..72d01de5 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -475,9 +475,9 @@ bool mmu_print_saved = false; // storing estimated time to end of print counted by slicer uint8_t print_percent_done_normal = PRINT_PERCENT_DONE_INIT; -uint16_t print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes +uint32_t print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes uint8_t print_percent_done_silent = PRINT_PERCENT_DONE_INIT; -uint16_t print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes +uint32_t print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes //=========================================================================== //=============================Private Variables============================= From 310751397c28740b24f3688b956cece811a57319 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 8 Aug 2018 20:11:57 +0200 Subject: [PATCH 05/16] line endings + fixed declaration --- Firmware/Marlin.h | 4 ++-- Firmware/Marlin_main.cpp | 4 ++-- Firmware/lcd.cpp | 1 + Firmware/mmu.cpp | 11 +++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 4333c977..7187ac93 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -359,9 +359,9 @@ extern bool mmu_print_saved; //estimated time to end of the print extern uint8_t print_percent_done_normal; -extern uint16_t print_time_remaining_normal; +extern uint32_t print_time_remaining_normal; extern uint8_t print_percent_done_silent; -extern uint16_t print_time_remaining_silent; +extern uint32_t print_time_remaining_silent; #define PRINT_TIME_REMAINING_INIT 0xffffffff #define PRINT_PERCENT_DONE_INIT 0xff #define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == 4) || saved_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL) || card.paused || mmu_print_saved) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 72d01de5..af2942d1 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -336,8 +336,8 @@ float pause_lastpos[4]; unsigned long pause_time = 0; unsigned long start_pause_print = millis(); unsigned long t_fan_rising_edge = millis(); -static LongTimer safetyTimer; -static LongTimer crashDetTimer; +LongTimer safetyTimer; +LongTimer crashDetTimer; //unsigned long load_filament_time; diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index f8e4b4c6..62060d11 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -755,6 +755,7 @@ void lcd_update_enable(uint8_t enabled) } } +extern LongTimer safetyTimer; void lcd_buttons_update(void) { static bool _lock = false; diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index de760d0c..f215a7f4 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -34,6 +34,8 @@ int8_t mmu_finda = -1; int16_t mmu_version = -1; +int16_t mmu_build = -1; + //clear rx buffer void mmu_clr_rx_buf(void) @@ -74,8 +76,8 @@ int8_t mmu_rx_start(void) //initialize mmu_unit bool mmu_init(void) { - digitalWrite(MMU_RST_PIN, HIGH); - pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin + digitalWrite(MMU_RST_PIN, HIGH); + pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin uart2_init(); //init uart2 _delay_ms(10); //wait 10ms for sure if (mmu_reset()) //reset mmu @@ -90,8 +92,8 @@ bool mmu_init(void) bool mmu_reset(void) { #ifdef MMU_HWRESET - digitalWrite(MMU_RST_PIN, LOW); - _delay_us(100); + digitalWrite(MMU_RST_PIN, LOW); + _delay_us(100); digitalWrite(MMU_RST_PIN, HIGH); #else mmu_puts_P(PSTR("X0\n")); //send command @@ -100,6 +102,7 @@ bool mmu_reset(void) while ((mmu_rx_start() <= 0) && (--timeout)) delay_keep_alive(MMU_TODELAY); mmu_enabled = timeout?true:false; + mmu_enabled = true; return mmu_enabled; } From 4e32fb7181021ad04dff2f3a184daad2653d8c7b Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 8 Aug 2018 20:23:13 +0200 Subject: [PATCH 06/16] removed '!' signalization when accel/feedrate limits reached --- Firmware/ultralcd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 247eae6f..831a3a08 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -604,12 +604,13 @@ static void lcd_implementation_status_screen() //Print Feedrate lcd_set_cursor(LCD_WIDTH - 8-2, 1); lcd_puts_P(PSTR(" ")); +/* if (maxlimit_status) { maxlimit_status = 0; lcd_print('!'); } - else + else*/ lcd_print(LCD_STR_FEEDRATE[0]); lcd_print(itostr3(feedmultiply)); lcd_puts_P(PSTR("% ")); From 10cc077ee4a82a652e94b8fed558f67dbdf42410 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Wed, 8 Aug 2018 21:05:25 +0200 Subject: [PATCH 07/16] mmu_enabled = true removed --- Firmware/mmu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index f215a7f4..9e250934 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -102,7 +102,7 @@ bool mmu_reset(void) while ((mmu_rx_start() <= 0) && (--timeout)) delay_keep_alive(MMU_TODELAY); mmu_enabled = timeout?true:false; - mmu_enabled = true; +// mmu_enabled = true; return mmu_enabled; } From 796079bb0879ffcb346e32c6803f32b6ec825898 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 9 Aug 2018 17:43:43 +0200 Subject: [PATCH 08/16] MMU2 communication - connection after reset, fw versions, state machine +removed debug log from tmc2130 --- Firmware/Marlin_main.cpp | 19 ++----- Firmware/menu.cpp | 5 +- Firmware/menu.h | 2 +- Firmware/mmu.cpp | 109 ++++++++++++++++++++++++--------------- Firmware/mmu.h | 10 ++-- Firmware/tmc2130.cpp | 30 +++++------ Firmware/ultralcd.cpp | 37 +++++++++---- 7 files changed, 124 insertions(+), 88 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index af2942d1..543d17b9 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1157,7 +1157,9 @@ void list_sec_lang_from_external_flash() // are initialized by the main() routine provided by the Arduino framework. void setup() { - ultralcd_init(); + mmu_init(); + + ultralcd_init(); spi_init(); @@ -1777,11 +1779,6 @@ void setup() wdt_enable(WDTO_4S); #endif //WATCHDOG - puts_P(_N("Checking MMU unit...")); - if (mmu_init()) - printf_P(_N("MMU ENABLED, finda=%hhd, version=%d\n"), mmu_finda, mmu_version); - else - puts_P(_N("MMU DISABLED")); } @@ -2015,7 +2012,7 @@ void loop() } } #endif //TMC2130 - + mmu_loop(); } #define DEFINE_PGM_READ_ANY(type, reader) \ @@ -3478,14 +3475,6 @@ void process_commands() { mmu_reset(); } - else if (code_seen("MMUFIN")) - { - mmu_read_finda(); - } - else if (code_seen("MMUVER")) - { - mmu_read_version(); - } else if (code_seen("RESET")) { // careful! if (farm_mode) { diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 33e6184c..20d92385 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -116,7 +116,7 @@ uint8_t menu_item_ret(void) } /* -int menu_item_printf_P(char type_char, const char* format, ...) +int menu_draw_item_printf_P(char type_char, const char* format, ...) { va_list args; va_start(args, format); @@ -134,12 +134,14 @@ int menu_item_printf_P(char type_char, const char* format, ...) return ret; } */ + int menu_draw_item_puts_P(char type_char, const char* str) { lcd_set_cursor(0, menu_row); int cnt = lcd_printf_P(PSTR("%c%-18S%c"), (lcd_encoder == menu_item)?'>':' ', str, type_char); return cnt; } + /* int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, ) { @@ -148,6 +150,7 @@ int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, ) return cnt; } */ + void menu_item_dummy(void) { menu_item++; diff --git a/Firmware/menu.h b/Firmware/menu.h index 27548657..c8237df2 100644 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -63,7 +63,7 @@ extern void menu_submenu(menu_func_t submenu); extern uint8_t menu_item_ret(void); -//int menu_item_printf_P(char type_char, const char* format, ...); +//extern int menu_draw_item_printf_P(char type_char, const char* format, ...); extern int menu_draw_item_puts_P(char type_char, const char* str); diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 9e250934..824a0648 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -26,6 +26,8 @@ extern char choose_extruder_menu(); bool mmu_enabled = false; +int8_t mmu_state = -1; + uint8_t mmu_extruder = 0; uint8_t tmp_extruder = 0; @@ -34,7 +36,7 @@ int8_t mmu_finda = -1; int16_t mmu_version = -1; -int16_t mmu_build = -1; +int16_t mmu_buildnr = -1; //clear rx buffer @@ -73,60 +75,81 @@ int8_t mmu_rx_start(void) return uart2_rx_str_P(PSTR("start\n")); } -//initialize mmu_unit -bool mmu_init(void) +//initialize mmu2 unit - first part - should be done at begining of startup process +void mmu_init(void) { digitalWrite(MMU_RST_PIN, HIGH); pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin uart2_init(); //init uart2 _delay_ms(10); //wait 10ms for sure - if (mmu_reset()) //reset mmu - { - mmu_read_finda(); - mmu_read_version(); - return true; - } - return false; + mmu_reset(); //reset mmu (HW or SW), do not wait for response + mmu_state = -1; } -bool mmu_reset(void) +//mmu main loop - state machine processing +void mmu_loop(void) { -#ifdef MMU_HWRESET +// printf_P(PSTR("MMU loop, state=%d\n"), mmu_state); + switch (mmu_state) + { + case 0: + return; + case -1: + if (mmu_rx_start() > 0) + { + puts_P(PSTR("MMU => 'start'")); + puts_P(PSTR("MMU <= 'S1'")); + mmu_puts_P(PSTR("S1\n")); //send 'read version' request + mmu_state = -2; + } + else if (millis() > 30000) //30sec after reset disable mmu + { + puts_P(PSTR("MMU not responding - DISABLED")); + mmu_state = 0; + } + return; + case -2: + if (mmu_rx_ok() > 0) + { + fscanf_P(uart2io, PSTR("%u"), &mmu_version); //scan version from buffer + printf_P(PSTR("MMU => '%dok'\n"), mmu_version); + puts_P(PSTR("MMU <= 'S2'")); + mmu_puts_P(PSTR("S2\n")); //send 'read buildnr' request + mmu_state = -3; + } + return; + case -3: + if (mmu_rx_ok() > 0) + { + fscanf_P(uart2io, PSTR("%u"), &mmu_buildnr); //scan buildnr from buffer + printf_P(PSTR("MMU => '%dok'\n"), mmu_buildnr); + puts_P(PSTR("MMU <= 'P0'")); + mmu_puts_P(PSTR("P0\n")); //send 'read finda' request + mmu_state = -4; + } + return; + case -4: + if (mmu_rx_ok() > 0) + { + fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer + printf_P(PSTR("MMU => '%dok'\n"), mmu_finda); + puts_P(PSTR("MMU - ENABLED")); + mmu_enabled = true; + mmu_state = 1; + } + return; + } +} + +void mmu_reset(void) +{ +#ifdef MMU_HWRESET //HW - pulse reset pin digitalWrite(MMU_RST_PIN, LOW); _delay_us(100); digitalWrite(MMU_RST_PIN, HIGH); -#else - mmu_puts_P(PSTR("X0\n")); //send command +#else //SW - send X0 command + mmu_puts_P(PSTR("X0\n")); #endif - unsigned char timeout = MMU_TIMEOUT; //timeout = 10x100ms - while ((mmu_rx_start() <= 0) && (--timeout)) - delay_keep_alive(MMU_TODELAY); - mmu_enabled = timeout?true:false; -// mmu_enabled = true; - return mmu_enabled; -} - -int8_t mmu_read_finda(void) -{ - mmu_puts_P(PSTR("P0\n")); - unsigned char timeout = MMU_TIMEOUT; //10x100ms - while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TODELAY); - mmu_finda = -1; - if (timeout) - fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); - return mmu_finda; -} - -int16_t mmu_read_version(void) -{ - mmu_puts_P(PSTR("S1\n")); - unsigned char timeout = MMU_TIMEOUT; //10x100ms - while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TODELAY); - if (timeout) - fscanf_P(uart2io, PSTR("%u"), &mmu_version); - return mmu_version; } int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament) diff --git a/Firmware/mmu.h b/Firmware/mmu.h index 65bce969..9411ec37 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -5,6 +5,8 @@ extern bool mmu_enabled; +extern int8_t mmu_state; + extern uint8_t mmu_extruder; extern uint8_t tmp_extruder; @@ -12,6 +14,7 @@ extern uint8_t tmp_extruder; extern int8_t mmu_finda; extern int16_t mmu_version; +extern int16_t mmu_buildnr; extern int mmu_puts_P(const char* str); @@ -21,13 +24,12 @@ extern int mmu_printf_P(const char* format, ...); extern int8_t mmu_rx_ok(void); -extern bool mmu_init(void); +extern void mmu_init(void); -extern bool mmu_reset(void); +extern void mmu_loop(void); -extern int8_t mmu_read_finda(void); -extern int16_t mmu_read_version(void); +extern void mmu_reset(void); extern int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament); diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index d4295701..35b61ecc 100644 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -150,7 +150,7 @@ uint16_t __tcoolthrs(uint8_t axis) void tmc2130_init() { - DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("STEALTH"):_n("NORMAL")); +// DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("STEALTH"):_n("NORMAL")); WRITE(X_TMC2130_CS, HIGH); WRITE(Y_TMC2130_CS, HIGH); WRITE(Z_TMC2130_CS, HIGH); @@ -442,8 +442,8 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_ // toff = TMC2130_TOFF_E; // toff = 3-5 // rndtf = 1; } - DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r); - DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl); +// DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r); +// DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl); if (current_r <= 31) { tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 1, 0, 0, 0, mres, intpol, 0, 0); @@ -458,31 +458,31 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_ void tmc2130_set_current_h(uint8_t axis, uint8_t current) { - DBG(_n("tmc2130_set_current_h(axis=%d, current=%d\n"), axis, current); +// DBG(_n("tmc2130_set_current_h(axis=%d, current=%d\n"), axis, current); tmc2130_current_h[axis] = current; tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); } void tmc2130_set_current_r(uint8_t axis, uint8_t current) { - DBG(_n("tmc2130_set_current_r(axis=%d, current=%d\n"), axis, current); +// DBG(_n("tmc2130_set_current_r(axis=%d, current=%d\n"), axis, current); tmc2130_current_r[axis] = current; tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); } void tmc2130_print_currents() { - DBG(_n("tmc2130_print_currents()\n\tH\tR\nX\t%d\t%d\nY\t%d\t%d\nZ\t%d\t%d\nE\t%d\t%d\n"), - tmc2130_current_h[0], tmc2130_current_r[0], - tmc2130_current_h[1], tmc2130_current_r[1], - tmc2130_current_h[2], tmc2130_current_r[2], - tmc2130_current_h[3], tmc2130_current_r[3] - ); +// DBG(_n("tmc2130_print_currents()\n\tH\tR\nX\t%d\t%d\nY\t%d\t%d\nZ\t%d\t%d\nE\t%d\t%d\n"), +// tmc2130_current_h[0], tmc2130_current_r[0], +// tmc2130_current_h[1], tmc2130_current_r[1], +// tmc2130_current_h[2], tmc2130_current_r[2], +// tmc2130_current_h[3], tmc2130_current_r[3] +// ); } void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) { - DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl); +// DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl); tmc2130_pwm_ampl[axis] = pwm_ampl; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -490,7 +490,7 @@ void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_grad) { - DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad); +// DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad); tmc2130_pwm_grad[axis] = pwm_grad; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -852,12 +852,12 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) { // TMC2130 wave compression algorithm // optimized for minimal memory requirements - printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000); +// printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000); if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0; if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX; float fac = 0; if (fac1000) fac = ((float)((uint16_t)fac1000 + 1000) / 1000); //correction factor - printf_P(PSTR(" factor: %s\n"), ftostr43(fac)); +// printf_P(PSTR(" factor: %s\n"), ftostr43(fac)); uint8_t vA = 0; //value of currentA uint8_t va = 0; //previous vA int8_t d0 = 0; //delta0 diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 831a3a08..1908b7ce 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -225,9 +225,7 @@ bool wait_for_unclick; - - - +const char STR_SEPARATOR[] PROGMEM = "------------"; @@ -2177,7 +2175,8 @@ static void lcd_preheat_menu() static void lcd_support_menu() { - if (menuData.supportMenu.status == 0 || lcd_draw_update == 2) { + if (menuData.supportMenu.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; @@ -2189,7 +2188,8 @@ static void lcd_support_menu() } 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) { + ++ menuData.supportMenu.status == 16) + { // Waiting for the FlashAir card to get an IP address from a router. Force an update. menuData.supportMenu.status = 0; } @@ -2214,22 +2214,41 @@ static void lcd_support_menu() MENU_ITEM_BACK_P(_i("prusa3d.com"));////MSG_PRUSA3D c=0 r=0 MENU_ITEM_BACK_P(_i("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=0 r=0 MENU_ITEM_BACK_P(_i("howto.prusa3d.com"));////MSG_PRUSA3D_HOWTO c=0 r=0 - MENU_ITEM_BACK_P(PSTR("------------")); + MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE)); MENU_ITEM_BACK_P(PSTR(ELECTRONICS)); MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE)); - MENU_ITEM_BACK_P(PSTR("------------")); + MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1 MENU_ITEM_BACK_P(PSTR(__DATE__)); + MENU_ITEM_BACK_P(STR_SEPARATOR); + if (mmu_enabled) + { + MENU_ITEM_BACK_P(PSTR("MMU2 connected")); + MENU_ITEM_BACK_P(PSTR(" FW:")); + if (((menu_item - 1) == menu_line) && lcd_draw_update) + { + lcd_set_cursor(6, menu_row); + if ((mmu_version > 0) && (mmu_buildnr > 0)) + lcd_printf_P(PSTR("%d.%d.%d-%d"), mmu_version/100, mmu_version%100/10, mmu_version%10, mmu_buildnr); + else + lcd_puts_P(PSTR("unknown")); + } + } + else + MENU_ITEM_BACK_P(PSTR("MMU2 N/A")); + + // Show the FlashAir IP address, if the card is available. if (menuData.supportMenu.is_flash_air) { - MENU_ITEM_BACK_P(PSTR("------------")); + MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:")); ///! MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, 0); } + #ifndef MK1BP - MENU_ITEM_BACK_P(PSTR("------------")); + MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1 MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1 From 9ee7a2124b0ab0092efa65fb6d867670fc3ef5b8 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Thu, 9 Aug 2018 18:43:07 +0200 Subject: [PATCH 09/16] 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 10/16] 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 11/16] 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 12/16] 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() { From b7f17292ca55bc63cc7302bbdd3924637c01d567 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Fri, 10 Aug 2018 20:08:10 +0200 Subject: [PATCH 13/16] Version changed --- Firmware/Configuration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 3fa648f7..d2522375 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -7,8 +7,8 @@ #define STR(x) STR_HELPER(x) // Firmware version -#define FW_VERSION "3.3.1" -#define FW_COMMIT_NR 845 +#define FW_VERSION "3.4.0-RC1" +#define FW_COMMIT_NR 1168 // FW_VERSION_UNKNOWN means this is an unofficial build. // The firmware should only be checked into github with this symbol. #define FW_DEV_VERSION FW_VERSION_UNKNOWN From a11ae18f7eefaafd3ad3a15025e2e47c98b5b67e Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Mon, 13 Aug 2018 14:55:31 +0200 Subject: [PATCH 14/16] XYZ calibration fix (progmem constants declaration) + version changed --- Firmware/Configuration.h | 2 +- Firmware/xyzcal.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index d2522375..6e08fe28 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -8,7 +8,7 @@ // Firmware version #define FW_VERSION "3.4.0-RC1" -#define FW_COMMIT_NR 1168 +#define FW_COMMIT_NR 1170 // FW_VERSION_UNKNOWN means this is an unofficial build. // The firmware should only be checked into github with this symbol. #define FW_DEV_VERSION FW_VERSION_UNKNOWN diff --git a/Firmware/xyzcal.cpp b/Firmware/xyzcal.cpp index 27d4f519..03bdb2fb 100644 --- a/Firmware/xyzcal.cpp +++ b/Firmware/xyzcal.cpp @@ -686,17 +686,17 @@ uint8_t xyzcal_xycoords2point(int16_t x, int16_t y) //MK3 #if ((MOTHERBOARD == BOARD_EINSY_1_0a)) -const int16_t PROGMEM xyzcal_point_xcoords[4] = {1200, 22000, 22000, 1200}; -const int16_t PROGMEM xyzcal_point_ycoords[4] = {600, 600, 19800, 19800}; +const int16_t xyzcal_point_xcoords[4] PROGMEM = {1200, 22000, 22000, 1200}; +const int16_t xyzcal_point_ycoords[4] PROGMEM = {600, 600, 19800, 19800}; #endif //((MOTHERBOARD == BOARD_EINSY_1_0a)) //MK2.5 #if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3)) -const int16_t PROGMEM xyzcal_point_xcoords[4] = {1200, 22000, 22000, 1200}; -const int16_t PROGMEM xyzcal_point_ycoords[4] = {700, 700, 19800, 19800}; +const int16_t xyzcal_point_xcoords[4] PROGMEM = {1200, 22000, 22000, 1200}; +const int16_t xyzcal_point_ycoords[4] PROGMEM = {700, 700, 19800, 19800}; #endif //((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3)) -const uint16_t PROGMEM xyzcal_point_pattern[12] = {0x000, 0x0f0, 0x1f8, 0x3fc, 0x7fe, 0x7fe, 0x7fe, 0x7fe, 0x3fc, 0x1f8, 0x0f0, 0x000}; +const uint16_t xyzcal_point_pattern[12] PROGMEM = {0x000, 0x0f0, 0x1f8, 0x3fc, 0x7fe, 0x7fe, 0x7fe, 0x7fe, 0x3fc, 0x1f8, 0x0f0, 0x000}; bool xyzcal_searchZ(void) { @@ -747,7 +747,7 @@ bool xyzcal_scan_and_process(void) uint16_t* pattern = (uint16_t*)(histo + 2*16); for (uint8_t i = 0; i < 12; i++) { - pattern[i] = pgm_read_word_far((uint16_t*)(xyzcal_point_pattern + i)); + pattern[i] = pgm_read_word((uint16_t*)(xyzcal_point_pattern + i)); // DBG(_n(" pattern[%d]=%d\n"), i, pattern[i]); } uint8_t c = 0; @@ -777,8 +777,8 @@ bool xyzcal_find_bed_induction_sensor_point_xy(void) int16_t y = _Y; int16_t z = _Z; uint8_t point = xyzcal_xycoords2point(x, y); - x = pgm_read_word_far((uint16_t*)(xyzcal_point_xcoords + point)); - y = pgm_read_word_far((uint16_t*)(xyzcal_point_ycoords + point)); + x = pgm_read_word((uint16_t*)(xyzcal_point_xcoords + point)); + y = pgm_read_word((uint16_t*)(xyzcal_point_ycoords + point)); DBG(_n("point=%d x=%d y=%d z=%d\n"), point, x, y, z); xyzcal_meassure_enter(); xyzcal_lineXYZ_to(x, y, z, 200, 0); From ac62117d6b8d166ef015c5b6f92406ccc75e557f Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Mon, 13 Aug 2018 19:38:55 +0200 Subject: [PATCH 15/16] Merge remote-tracking branch 'prusa3d/MK3' into MK3_dev --- Firmware/Configuration.h | 4 +- Firmware/Marlin.h | 14 +- Firmware/Marlin_main.cpp | 242 +++--------------------- Firmware/Timer.cpp | 2 +- Firmware/lcd.cpp | 2 + Firmware/menu.cpp | 33 +++- Firmware/menu.h | 11 +- Firmware/mesh_bed_calibration.cpp | 7 +- Firmware/mesh_bed_calibration.h | 1 + Firmware/mmu.cpp | 274 +++++++++++++++++++++++---- Firmware/mmu.h | 23 ++- Firmware/tmc2130.cpp | 33 ++-- Firmware/uart2.c | 2 + Firmware/ultralcd.cpp | 295 ++++++++++++++++++++---------- Firmware/ultralcd.h | 88 --------- Firmware/xyzcal.cpp | 16 +- 16 files changed, 547 insertions(+), 500 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 3fa648f7..6e08fe28 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -7,8 +7,8 @@ #define STR(x) STR_HELPER(x) // Firmware version -#define FW_VERSION "3.3.1" -#define FW_COMMIT_NR 845 +#define FW_VERSION "3.4.0-RC1" +#define FW_COMMIT_NR 1170 // FW_VERSION_UNKNOWN means this is an unofficial build. // The firmware should only be checked into github with this symbol. #define FW_DEV_VERSION FW_VERSION_UNKNOWN diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index d97236a3..3912c9a2 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -360,11 +360,11 @@ extern bool mmu_print_saved; //estimated time to end of the print extern uint8_t print_percent_done_normal; -extern uint16_t print_time_remaining_normal; +extern uint32_t print_time_remaining_normal; extern uint8_t print_percent_done_silent; -extern uint16_t print_time_remaining_silent; -#define PRINT_TIME_REMAINING_INIT 65535 -#define PRINT_PERCENT_DONE_INIT 255 +extern uint32_t print_time_remaining_silent; +#define PRINT_TIME_REMAINING_INIT 0xffffffff +#define PRINT_PERCENT_DONE_INIT 0xff #define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == 4) || saved_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL) || card.paused || mmu_print_saved) extern void calculate_extruder_multipliers(); @@ -468,12 +468,8 @@ void gcode_M701(); void proc_commands(); -void manage_response(bool move_axes, bool turn_off_nozzle); -bool mmu_get_response(bool timeout); -void mmu_not_responding(); -void mmu_load_to_nozzle(); + void M600_load_filament(); -void mmu_M600_load_filament(bool automatic); void M600_load_filament_movements(); void M600_wait_for_user(); void M600_check_state(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f2ea1428..061d9352 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -337,8 +337,8 @@ float pause_lastpos[4]; unsigned long pause_time = 0; unsigned long start_pause_print = millis(); unsigned long t_fan_rising_edge = millis(); -static LongTimer safetyTimer; -static LongTimer crashDetTimer; +LongTimer safetyTimer; +LongTimer crashDetTimer; //unsigned long load_filament_time; @@ -476,9 +476,9 @@ bool mmu_print_saved = false; // storing estimated time to end of print counted by slicer uint8_t print_percent_done_normal = PRINT_PERCENT_DONE_INIT; -uint16_t print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes +uint32_t print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes uint8_t print_percent_done_silent = PRINT_PERCENT_DONE_INIT; -uint16_t print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes +uint32_t print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes //=========================================================================== //=============================Private Variables============================= @@ -509,7 +509,6 @@ unsigned long starttime=0; unsigned long stoptime=0; unsigned long _usb_timer = 0; -static uint8_t tmp_extruder; bool extruder_under_pressure = true; @@ -973,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); } @@ -1158,7 +1124,9 @@ void list_sec_lang_from_external_flash() // are initialized by the main() routine provided by the Arduino framework. void setup() { - ultralcd_init(); + mmu_init(); + + ultralcd_init(); spi_init(); @@ -1778,11 +1746,6 @@ void setup() wdt_enable(WDTO_4S); #endif //WATCHDOG - puts_P(_N("Checking MMU unit...")); - if (mmu_init()) - printf_P(_N("MMU ENABLED, finda=%hhd, version=%d\n"), mmu_finda, mmu_version); - else - puts_P(_N("MMU DISABLED")); } @@ -2016,7 +1979,7 @@ void loop() } } #endif //TMC2130 - + mmu_loop(); } #define DEFINE_PGM_READ_ANY(type, reader) \ @@ -3476,14 +3439,6 @@ void process_commands() { mmu_reset(); } - else if (code_seen("MMUFIN")) - { - mmu_read_finda(); - } - else if (code_seen("MMUVER")) - { - mmu_read_version(); - } else if (code_seen("RESET")) { // careful! if (farm_mode) { @@ -6333,21 +6288,14 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) //currently three different materials are needed (default, flex and PVA) //add storing this information for different load/unload profiles etc. in the future //firmware does not wait for "ok" from mmu - - uint8_t extruder = 255; - uint8_t filament = FILAMENT_UNDEFINED; - - if(code_seen('E')) extruder = code_value(); - if(code_seen('F')) filament = code_value(); - - printf_P(PSTR("Extruder: %d; "), extruder); - switch (filament) { - case FILAMENT_FLEX: printf_P(PSTR("Flex\n")); break; - case FILAMENT_PVA: printf_P(PSTR("PVA\n")); break; - default: printf_P(PSTR("Default\n")); break; + if (mmu_enabled) + { + uint8_t extruder = 255; + uint8_t filament = FILAMENT_UNDEFINED; + if(code_seen('E')) extruder = code_value(); + if(code_seen('F')) filament = code_value(); + mmu_set_filament_type(extruder, filament); } - printf_P(PSTR("F%d%d\n"), extruder, filament); - mmu_printf_P(PSTR("F%d%d\n"), extruder, filament); } break; @@ -7748,7 +7696,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)) { @@ -8869,7 +8818,8 @@ uint16_t print_time_remaining() { return print_t; } -uint8_t print_percent_done() { +uint8_t print_percent_done() +{ //in case that we have information from M73 gcode return percentage counted by slicer, else return percentage counted as byte_printed/filesize uint8_t percent_done = 0; if (SilentModeMenu == SILENT_MODE_OFF && print_percent_done_normal <= 100) { @@ -8884,131 +8834,16 @@ uint8_t print_percent_done() { return percent_done; } -static void print_time_remaining_init() { +static void print_time_remaining_init() +{ print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; print_percent_done_normal = PRINT_PERCENT_DONE_INIT; print_percent_done_silent = PRINT_PERCENT_DONE_INIT; } -bool mmu_get_response(bool timeout) { - //waits for "ok" from mmu - //function returns true if "ok" was received - //if timeout is set to true function return false if there is no "ok" received before timeout - bool response = true; - LongTimer mmu_get_reponse_timeout; - KEEPALIVE_STATE(IN_PROCESS); - mmu_get_reponse_timeout.start(); - while (mmu_rx_ok() <= 0) - { - delay_keep_alive(100); - if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul)) { //5 minutes timeout - response = false; - break; - } - } - return response; -} - - -void manage_response(bool move_axes, bool turn_off_nozzle) { - - bool response = false; - mmu_print_saved = false; - bool lcd_update_was_enabled = false; - float hotend_temp_bckp = degTargetHotend(active_extruder); - float z_position_bckp = current_position[Z_AXIS]; - float x_position_bckp = current_position[X_AXIS]; - float y_position_bckp = current_position[Y_AXIS]; - while(!response) { - response = mmu_get_response(true); //wait for "ok" from mmu - if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit - if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater - if (lcd_update_enabled) { - lcd_update_was_enabled = true; - lcd_update_enable(false); - } - st_synchronize(); - mmu_print_saved = true; - - hotend_temp_bckp = degTargetHotend(active_extruder); - if (move_axes) { - z_position_bckp = current_position[Z_AXIS]; - x_position_bckp = current_position[X_AXIS]; - y_position_bckp = current_position[Y_AXIS]; - - //lift z - current_position[Z_AXIS] += Z_PAUSE_LIFT; - if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); - st_synchronize(); - - //Move XY to side - current_position[X_AXIS] = X_PAUSE_POS; - current_position[Y_AXIS] = Y_PAUSE_POS; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); - st_synchronize(); - } - if (turn_off_nozzle) { - //set nozzle target temperature to 0 - setAllTargetHotends(0); - printf_P(PSTR("MMU not responding\n")); - lcd_show_fullscreen_message_and_wait_P(_i("MMU needs user attention. Please press knob to resume nozzle target temperature.")); - setTargetHotend(hotend_temp_bckp, active_extruder); - while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5) { - delay_keep_alive(1000); - lcd_wait_for_heater(); - } - } - } - lcd_display_message_fullscreen_P(_i("Check MMU. Fix the issue and then press button on MMU unit.")); - } - else if (mmu_print_saved) { - printf_P(PSTR("MMU start responding\n")); - lcd_clear(); - lcd_display_message_fullscreen_P(_i("MMU OK. Resuming...")); - if (move_axes) { - current_position[X_AXIS] = x_position_bckp; - current_position[Y_AXIS] = y_position_bckp; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); - st_synchronize(); - current_position[Z_AXIS] = z_position_bckp; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); - st_synchronize(); - } - else { - delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements - } - } - } - if (lcd_update_was_enabled) lcd_update_enable(true); -} - -void mmu_load_to_nozzle() { - st_synchronize(); - - bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; - current_position[E_AXIS] += 7.2f; - float feedrate = 562; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 14.4f; - feedrate = 871; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 36.0f; - feedrate = 1393; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - current_position[E_AXIS] += 14.4f; - feedrate = 871; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); - st_synchronize(); - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; -} - -void M600_check_state() { +void M600_check_state() +{ //Wait for user to check the state lcd_change_fil_state = 0; @@ -9120,37 +8955,6 @@ void M600_wait_for_user() { WRITE(BEEPER, LOW); } -void mmu_M600_load_filament(bool automatic) -{ - //load filament for mmu v2 - bool yes = false; - if (!automatic) - { - yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false); - if (yes) tmp_extruder = choose_extruder_menu(); - else tmp_extruder = mmu_extruder; - } - else - { - tmp_extruder = (tmp_extruder+1)%5; - } - lcd_update_enable(false); - lcd_clear(); - lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT)); - lcd_print(" "); - lcd_print(tmp_extruder + 1); - snmm_filaments_used |= (1 << tmp_extruder); //for stop print - printf_P(PSTR("T code: %d \n"), tmp_extruder); - mmu_printf_P(PSTR("T%d\n"), tmp_extruder); - manage_response(false, true); - mmu_extruder = tmp_extruder; //filament change is finished - mmu_load_to_nozzle(); - - st_synchronize(); - current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder); -} - void M600_load_filament_movements() { #ifdef SNMM 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/lcd.cpp b/Firmware/lcd.cpp index b4d969ce..e2a5d47a 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -754,6 +754,7 @@ void lcd_update_enable(uint8_t enabled) } } +extern LongTimer safetyTimer; void lcd_buttons_update(void) { static bool _lock = false; @@ -769,6 +770,7 @@ void lcd_buttons_update(void) lcd_timeoutToStatus.start(); if (!buttonBlanking.running() || buttonBlanking.expired(BUTTON_BLANKING_TIME)) { buttonBlanking.start(); + safetyTimer.start(); if ((lcd_button_pressed == 0) && (lcd_long_press_active == 0)) { longPressTimer.start(); diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 33e6184c..1e4b77fa 100644 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -116,7 +116,7 @@ uint8_t menu_item_ret(void) } /* -int menu_item_printf_P(char type_char, const char* format, ...) +int menu_draw_item_printf_P(char type_char, const char* format, ...) { va_list args; va_start(args, format); @@ -134,12 +134,14 @@ int menu_item_printf_P(char type_char, const char* format, ...) return ret; } */ + int menu_draw_item_puts_P(char type_char, const char* str) { lcd_set_cursor(0, menu_row); int cnt = lcd_printf_P(PSTR("%c%-18S%c"), (lcd_encoder == menu_item)?'>':' ', str, type_char); return cnt; } + /* int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, ) { @@ -148,6 +150,7 @@ int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, ) return cnt; } */ + void menu_item_dummy(void) { menu_item++; @@ -270,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) @@ -299,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 27548657..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]; @@ -63,7 +54,7 @@ extern void menu_submenu(menu_func_t submenu); extern uint8_t menu_item_ret(void); -//int menu_item_printf_P(char type_char, const char* format, ...); +//extern int menu_draw_item_printf_P(char type_char, const char* format, ...); extern int menu_draw_item_puts_P(char type_char, const char* str); diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 82320c4c..1a62ed3b 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2995,13 +2995,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: "); @@ -3037,7 +3038,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 1a6680e9..1e1afc78 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -10,18 +10,34 @@ extern const char* lcd_display_message_fullscreen_P(const char *msg); +extern void lcd_show_fullscreen_message_and_wait_P(const char *msg); +extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, bool default_yes = false); extern void lcd_return_to_status(); +extern void lcd_wait_for_heater(); +extern char choose_extruder_menu(); + + +#define MMU_TODELAY 100 +#define MMU_TIMEOUT 10 + +#define MMU_HWRESET +#define MMU_RST_PIN 76 -#define MMU_TIMEOUT 100 bool mmu_enabled = false; +int8_t mmu_state = 0; + uint8_t mmu_extruder = 0; +uint8_t tmp_extruder = 0; + int8_t mmu_finda = -1; int16_t mmu_version = -1; +int16_t mmu_buildnr = -1; + //clear rx buffer void mmu_clr_rx_buf(void) @@ -59,53 +75,249 @@ int8_t mmu_rx_start(void) return uart2_rx_str_P(PSTR("start\n")); } -//initialize mmu_unit -bool mmu_init(void) +//initialize mmu2 unit - first part - should be done at begining of startup process +void mmu_init(void) { + digitalWrite(MMU_RST_PIN, HIGH); + pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin uart2_init(); //init uart2 _delay_ms(10); //wait 10ms for sure - if (mmu_reset()) //reset mmu + mmu_reset(); //reset mmu (HW or SW), do not wait for response + mmu_state = -1; +} + +//mmu main loop - state machine processing +void mmu_loop(void) +{ +// printf_P(PSTR("MMU loop, state=%d\n"), mmu_state); + switch (mmu_state) { - mmu_read_finda(); - mmu_read_version(); - return true; + case 0: + return; + case -1: + if (mmu_rx_start() > 0) + { + puts_P(PSTR("MMU => 'start'")); + puts_P(PSTR("MMU <= 'S1'")); + mmu_puts_P(PSTR("S1\n")); //send 'read version' request + mmu_state = -2; + } + else if (millis() > 30000) //30sec after reset disable mmu + { + puts_P(PSTR("MMU not responding - DISABLED")); + mmu_state = 0; + } + return; + case -2: + if (mmu_rx_ok() > 0) + { + fscanf_P(uart2io, PSTR("%u"), &mmu_version); //scan version from buffer + printf_P(PSTR("MMU => '%dok'\n"), mmu_version); + puts_P(PSTR("MMU <= 'S2'")); + mmu_puts_P(PSTR("S2\n")); //send 'read buildnr' request + mmu_state = -3; + } + return; + case -3: + if (mmu_rx_ok() > 0) + { + fscanf_P(uart2io, PSTR("%u"), &mmu_buildnr); //scan buildnr from buffer + printf_P(PSTR("MMU => '%dok'\n"), mmu_buildnr); + puts_P(PSTR("MMU <= 'P0'")); + mmu_puts_P(PSTR("P0\n")); //send 'read finda' request + mmu_state = -4; + } + return; + case -4: + if (mmu_rx_ok() > 0) + { + fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer + printf_P(PSTR("MMU => '%dok'\n"), mmu_finda); + puts_P(PSTR("MMU - ENABLED")); + mmu_enabled = true; + mmu_state = 1; + } + return; } - return false; } -bool mmu_reset(void) +void mmu_reset(void) { - mmu_puts_P(PSTR("X0\n")); //send command - unsigned char timeout = 10; //timeout = 10x100ms - while ((mmu_rx_start() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); - mmu_enabled = timeout?true:false; - return mmu_enabled; +#ifdef MMU_HWRESET //HW - pulse reset pin + digitalWrite(MMU_RST_PIN, LOW); + _delay_us(100); + digitalWrite(MMU_RST_PIN, HIGH); +#else //SW - send X0 command + mmu_puts_P(PSTR("X0\n")); +#endif } -int8_t mmu_read_finda(void) +int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament) { - mmu_puts_P(PSTR("P0\n")); - unsigned char timeout = 10; //10x100ms + printf_P(PSTR("MMU <= 'F%d %d'\n"), extruder, filament); + mmu_printf_P(PSTR("F%d %d\n"), extruder, filament); + unsigned char timeout = MMU_TIMEOUT; //10x100ms while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); - mmu_finda = -1; - if (timeout) - fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); - return mmu_finda; + delay_keep_alive(MMU_TODELAY); + return timeout?1:0; } -int16_t mmu_read_version(void) +bool mmu_get_response(bool timeout) { - mmu_puts_P(PSTR("S1\n")); - unsigned char timeout = 10; //10x100ms - while ((mmu_rx_ok() <= 0) && (--timeout)) - delay_keep_alive(MMU_TIMEOUT); - if (timeout) - fscanf_P(uart2io, PSTR("%u"), &mmu_version); - return mmu_version; + printf_P(PSTR("mmu_get_response - begin\n")); + //waits for "ok" from mmu + //function returns true if "ok" was received + //if timeout is set to true function return false if there is no "ok" received before timeout + bool response = true; + LongTimer mmu_get_reponse_timeout; + KEEPALIVE_STATE(IN_PROCESS); + mmu_get_reponse_timeout.start(); + while (mmu_rx_ok() <= 0) + { + delay_keep_alive(100); + if (timeout && mmu_get_reponse_timeout.expired(5 * 60 * 1000ul)) + { //5 minutes timeout + response = false; + break; + } + } + printf_P(PSTR("mmu_get_response - end %d\n"), response?1:0); + return response; } + +void manage_response(bool move_axes, bool turn_off_nozzle) +{ + bool response = false; + mmu_print_saved = false; + bool lcd_update_was_enabled = false; + float hotend_temp_bckp = degTargetHotend(active_extruder); + float z_position_bckp = current_position[Z_AXIS]; + float x_position_bckp = current_position[X_AXIS]; + float y_position_bckp = current_position[Y_AXIS]; + while(!response) + { + response = mmu_get_response(true); //wait for "ok" from mmu + if (!response) { //no "ok" was received in reserved time frame, user will fix the issue on mmu unit + if (!mmu_print_saved) { //first occurence, we are saving current position, park print head in certain position and disable nozzle heater + if (lcd_update_enabled) { + lcd_update_was_enabled = true; + lcd_update_enable(false); + } + st_synchronize(); + mmu_print_saved = true; + + hotend_temp_bckp = degTargetHotend(active_extruder); + if (move_axes) { + z_position_bckp = current_position[Z_AXIS]; + x_position_bckp = current_position[X_AXIS]; + y_position_bckp = current_position[Y_AXIS]; + + //lift z + current_position[Z_AXIS] += Z_PAUSE_LIFT; + if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); + st_synchronize(); + + //Move XY to side + current_position[X_AXIS] = X_PAUSE_POS; + current_position[Y_AXIS] = Y_PAUSE_POS; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); + st_synchronize(); + } + if (turn_off_nozzle) { + //set nozzle target temperature to 0 + setAllTargetHotends(0); + printf_P(PSTR("MMU not responding\n")); + lcd_show_fullscreen_message_and_wait_P(_i("MMU needs user attention. Please press knob to resume nozzle target temperature.")); + setTargetHotend(hotend_temp_bckp, active_extruder); + while ((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5) { + delay_keep_alive(1000); + lcd_wait_for_heater(); + } + } + } + lcd_display_message_fullscreen_P(_i("Check MMU. Fix the issue and then press button on MMU unit.")); + } + else if (mmu_print_saved) { + printf_P(PSTR("MMU start responding\n")); + lcd_clear(); + lcd_display_message_fullscreen_P(_i("MMU OK. Resuming...")); + if (move_axes) { + current_position[X_AXIS] = x_position_bckp; + current_position[Y_AXIS] = y_position_bckp; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder); + st_synchronize(); + current_position[Z_AXIS] = z_position_bckp; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 15, active_extruder); + st_synchronize(); + } + else { + delay_keep_alive(1000); //delay just for showing MMU OK message for a while in case that there are no xyz movements + } + } + } + if (lcd_update_was_enabled) lcd_update_enable(true); +} + +void mmu_load_to_nozzle() +{ + st_synchronize(); + + bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; + if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; + current_position[E_AXIS] += 7.2f; + float feedrate = 562; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 14.4f; + feedrate = 871; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 36.0f; + feedrate = 1393; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + current_position[E_AXIS] += 14.4f; + feedrate = 871; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder); + st_synchronize(); + if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; +} + +void mmu_M600_load_filament(bool automatic) +{ + //load filament for mmu v2 + bool yes = false; + if (!automatic) { + yes = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Do you want to switch extruder?"), false); + if(yes) tmp_extruder = choose_extruder_menu(); + else tmp_extruder = mmu_extruder; + + } + else { + tmp_extruder = (tmp_extruder+1)%5; + } + lcd_update_enable(false); + lcd_clear(); + lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT)); + lcd_print(" "); + lcd_print(tmp_extruder + 1); + snmm_filaments_used |= (1 << tmp_extruder); //for stop print + printf_P(PSTR("T code: %d \n"), tmp_extruder); + mmu_printf_P(PSTR("T%d\n"), tmp_extruder); + + manage_response(false, true); + mmu_extruder = tmp_extruder; //filament change is finished + + mmu_load_to_nozzle(); + + st_synchronize(); + current_position[E_AXIS]+= FILAMENTCHANGE_FINALFEED ; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2, active_extruder); +} + + void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is set_extrude_min_temp(.0); diff --git a/Firmware/mmu.h b/Firmware/mmu.h index 91a1f511..9411ec37 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -5,11 +5,16 @@ extern bool mmu_enabled; +extern int8_t mmu_state; + extern uint8_t mmu_extruder; +extern uint8_t tmp_extruder; + extern int8_t mmu_finda; extern int16_t mmu_version; +extern int16_t mmu_buildnr; extern int mmu_puts_P(const char* str); @@ -19,13 +24,23 @@ extern int mmu_printf_P(const char* format, ...); extern int8_t mmu_rx_ok(void); -extern bool mmu_init(void); +extern void mmu_init(void); -extern bool mmu_reset(void); +extern void mmu_loop(void); -extern int8_t mmu_read_finda(void); -extern int16_t mmu_read_version(void); +extern void mmu_reset(void); + +extern int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament); + + +extern bool mmu_get_response(bool timeout); + +extern void manage_response(bool move_axes, bool turn_off_nozzle); + +extern void mmu_load_to_nozzle(); + +extern void mmu_M600_load_filament(bool automatic); extern void extr_mov(float shift, float feed_rate); diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index ddef5dd8..1d1495fe 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 @@ -150,7 +151,7 @@ uint16_t __tcoolthrs(uint8_t axis) void tmc2130_init() { - DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("STEALTH"):_n("NORMAL")); +// DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("STEALTH"):_n("NORMAL")); WRITE(X_TMC2130_CS, HIGH); WRITE(Y_TMC2130_CS, HIGH); WRITE(Z_TMC2130_CS, HIGH); @@ -442,8 +443,8 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_ // toff = TMC2130_TOFF_E; // toff = 3-5 // rndtf = 1; } - DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r); - DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl); +// DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r); +// DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl); if (current_r <= 31) { tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 1, 0, 0, 0, mres, intpol, 0, 0); @@ -458,31 +459,31 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_ void tmc2130_set_current_h(uint8_t axis, uint8_t current) { - DBG(_n("tmc2130_set_current_h(axis=%d, current=%d\n"), axis, current); +// DBG(_n("tmc2130_set_current_h(axis=%d, current=%d\n"), axis, current); tmc2130_current_h[axis] = current; tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); } void tmc2130_set_current_r(uint8_t axis, uint8_t current) { - DBG(_n("tmc2130_set_current_r(axis=%d, current=%d\n"), axis, current); +// DBG(_n("tmc2130_set_current_r(axis=%d, current=%d\n"), axis, current); tmc2130_current_r[axis] = current; tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); } void tmc2130_print_currents() { - DBG(_n("tmc2130_print_currents()\n\tH\tR\nX\t%d\t%d\nY\t%d\t%d\nZ\t%d\t%d\nE\t%d\t%d\n"), - tmc2130_current_h[0], tmc2130_current_r[0], - tmc2130_current_h[1], tmc2130_current_r[1], - tmc2130_current_h[2], tmc2130_current_r[2], - tmc2130_current_h[3], tmc2130_current_r[3] - ); +// DBG(_n("tmc2130_print_currents()\n\tH\tR\nX\t%d\t%d\nY\t%d\t%d\nZ\t%d\t%d\nE\t%d\t%d\n"), +// tmc2130_current_h[0], tmc2130_current_r[0], +// tmc2130_current_h[1], tmc2130_current_r[1], +// tmc2130_current_h[2], tmc2130_current_r[2], +// tmc2130_current_h[3], tmc2130_current_r[3] +// ); } void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) { - DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl); +// DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl); tmc2130_pwm_ampl[axis] = pwm_ampl; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -490,7 +491,7 @@ void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_grad) { - DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad); +// DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad); tmc2130_pwm_grad[axis] = pwm_grad; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -853,12 +854,12 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) { // TMC2130 wave compression algorithm // optimized for minimal memory requirements - printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000); +// printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000); if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0; if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX; float fac = 0; if (fac1000) fac = ((float)((uint16_t)fac1000 + 1000) / 1000); //correction factor - printf_P(PSTR(" factor: %s\n"), ftostr43(fac)); +// printf_P(PSTR(" factor: %s\n"), ftostr43(fac)); uint8_t vA = 0; //value of currentA uint8_t va = 0; //previous vA int8_t d0 = 0; //delta0 diff --git a/Firmware/uart2.c b/Firmware/uart2.c index 894d9587..47238999 100644 --- a/Firmware/uart2.c +++ b/Firmware/uart2.c @@ -34,6 +34,8 @@ int uart2_getchar(FILE *stream __attribute__((unused))) //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 diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 7c3078f7..b278eccc 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -44,12 +44,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; - - int8_t ReInitLCD = 0; @@ -116,11 +110,14 @@ static void lcd_tune_menu(); //static void lcd_move_menu(); static void lcd_settings_menu(); static void lcd_calibration_menu(); -static void lcd_control_temperature_menu(); #ifdef LINEARITY_CORRECTION static void lcd_settings_menu_back(); #endif //LINEARITY_CORRECTION - +static void lcd_control_temperature_menu(); +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 prusa_stat_printerstatus(int _status); static void prusa_stat_farm_number(); static void prusa_stat_temperatures(); @@ -225,9 +222,7 @@ bool wait_for_unclick; - - - +const char STR_SEPARATOR[] PROGMEM = "------------"; @@ -608,12 +603,13 @@ static void lcd_implementation_status_screen() //Print Feedrate lcd_set_cursor(LCD_WIDTH - 8-2, 1); lcd_puts_P(PSTR(" ")); +/* if (maxlimit_status) { maxlimit_status = 0; lcd_print('!'); } - else + else*/ lcd_print(LCD_STR_FEEDRATE[0]); lcd_print(itostr3(feedmultiply)); lcd_puts_P(PSTR("% ")); @@ -1958,6 +1954,9 @@ static void lcd_menu_extruder_info() // Display Nozzle fan RPM fan_speed_RPM[0] = 60*fan_speed[0]; fan_speed_RPM[1] = 60*fan_speed[1]; + + lcd_timeoutToStatus.stop(); //infinite timeout + lcd_printf_P(_N( ESC_H(0,0) "Nozzle FAN: %4d RPM\n" @@ -2005,6 +2004,7 @@ static void lcd_menu_fails_stats_total() // Filam. runouts 000 // Crash X 000 Y 000 ////////////////////// + lcd_timeoutToStatus.stop(); //infinite timeout uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT); uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT); @@ -2021,6 +2021,7 @@ static void lcd_menu_fails_stats_print() // Filam. runouts 000 // Crash X 000 Y 000 ////////////////////// + lcd_timeoutToStatus.stop(); //infinite timeout uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT); uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X); @@ -2061,6 +2062,7 @@ static void lcd_menu_fails_stats() */ static void lcd_menu_fails_stats() { + lcd_timeoutToStatus.stop(); //infinite timeout uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal); @@ -2069,6 +2071,7 @@ static void lcd_menu_fails_stats() #else static void lcd_menu_fails_stats() { + lcd_timeoutToStatus.stop(); //infinite timeout MENU_BEGIN(); MENU_ITEM_BACK_P(_T(MSG_MAIN)); MENU_END(); @@ -2095,6 +2098,8 @@ static void lcd_menu_debug() static void lcd_menu_temperatures() { + lcd_timeoutToStatus.stop(); //infinite timeout + lcd_printf_P(PSTR(ESC_H(1,0) "Nozzle: %d%c" ESC_H(1,1) "Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01'); #ifdef AMBIENT_THERMISTOR lcd_printf_P(PSTR(ESC_H(1,2) "Ambient: %d%c" ESC_H(1,3) "PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01'); @@ -2112,6 +2117,7 @@ static void lcd_menu_temperatures() #define VOLT_DIV_REF 5 static void lcd_menu_voltages() { + lcd_timeoutToStatus.stop(); //infinite timeout float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; // float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; // lcd_printf_P(PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed))); @@ -2170,21 +2176,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(); @@ -2207,22 +2226,41 @@ static void lcd_support_menu() MENU_ITEM_BACK_P(_i("prusa3d.com"));////MSG_PRUSA3D c=0 r=0 MENU_ITEM_BACK_P(_i("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=0 r=0 MENU_ITEM_BACK_P(_i("howto.prusa3d.com"));////MSG_PRUSA3D_HOWTO c=0 r=0 - MENU_ITEM_BACK_P(PSTR("------------")); + MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE)); MENU_ITEM_BACK_P(PSTR(ELECTRONICS)); MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE)); - MENU_ITEM_BACK_P(PSTR("------------")); + MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1 MENU_ITEM_BACK_P(PSTR(__DATE__)); + MENU_ITEM_BACK_P(STR_SEPARATOR); + if (mmu_enabled) + { + MENU_ITEM_BACK_P(PSTR("MMU2 connected")); + MENU_ITEM_BACK_P(PSTR(" FW:")); + if (((menu_item - 1) == menu_line) && lcd_draw_update) + { + lcd_set_cursor(6, menu_row); + if ((mmu_version > 0) && (mmu_buildnr > 0)) + lcd_printf_P(PSTR("%d.%d.%d-%d"), mmu_version/100, mmu_version%100/10, mmu_version%10, mmu_buildnr); + else + lcd_puts_P(PSTR("unknown")); + } + } + else + MENU_ITEM_BACK_P(PSTR("MMU2 N/A")); + + // Show the FlashAir IP address, if the card is available. - if (menuData.supportMenu.is_flash_air) { - MENU_ITEM_BACK_P(PSTR("------------")); + 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 - MENU_ITEM_BACK_P(PSTR("------------")); + MENU_ITEM_BACK_P(STR_SEPARATOR); MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1 MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1 @@ -2476,7 +2514,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)); @@ -2586,10 +2624,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) { @@ -2610,7 +2657,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(); } @@ -2782,23 +2829,37 @@ 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]; + // 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]; 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(); } @@ -2806,11 +2867,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 @@ -2818,7 +2879,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; @@ -2826,14 +2887,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(); @@ -2845,72 +2906,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(); } @@ -2933,7 +3016,7 @@ void pid_extruder() { } } - +/* void lcd_adjust_z() { int enc_dif = 0; int cursor_pos = 1; @@ -3016,7 +3099,7 @@ void lcd_adjust_z() { lcd_clear(); lcd_return_to_status(); -} +}*/ bool lcd_wait_for_pinda(float temp) { lcd_set_custom_characters_degree(); @@ -4717,7 +4800,6 @@ static void lcd_settings_menu_back() } #endif //LINEARITY_CORRECTION - static void lcd_calibration_menu() { MENU_BEGIN(); @@ -5672,15 +5754,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 fb655ccb..4b02388a 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -14,92 +14,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); @@ -226,8 +140,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(); diff --git a/Firmware/xyzcal.cpp b/Firmware/xyzcal.cpp index 18d124b3..3b9c0a4f 100644 --- a/Firmware/xyzcal.cpp +++ b/Firmware/xyzcal.cpp @@ -686,17 +686,17 @@ uint8_t xyzcal_xycoords2point(int16_t x, int16_t y) //MK3 #if ((MOTHERBOARD == BOARD_EINSY_1_0a)) -const int16_t PROGMEM xyzcal_point_xcoords[4] = {1200, 22000, 22000, 1200}; -const int16_t PROGMEM xyzcal_point_ycoords[4] = {600, 600, 19800, 19800}; +const int16_t xyzcal_point_xcoords[4] PROGMEM = {1200, 22000, 22000, 1200}; +const int16_t xyzcal_point_ycoords[4] PROGMEM = {600, 600, 19800, 19800}; #endif //((MOTHERBOARD == BOARD_EINSY_1_0a)) //MK2.5 #if ((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3)) -const int16_t PROGMEM xyzcal_point_xcoords[4] = {1200, 22000, 22000, 1200}; -const int16_t PROGMEM xyzcal_point_ycoords[4] = {700, 700, 19800, 19800}; +const int16_t xyzcal_point_xcoords[4] PROGMEM = {1200, 22000, 22000, 1200}; +const int16_t xyzcal_point_ycoords[4] PROGMEM = {700, 700, 19800, 19800}; #endif //((MOTHERBOARD == BOARD_RAMBO_MINI_1_0) || (MOTHERBOARD == BOARD_RAMBO_MINI_1_3)) -const uint16_t PROGMEM xyzcal_point_pattern[12] = {0x000, 0x0f0, 0x1f8, 0x3fc, 0x7fe, 0x7fe, 0x7fe, 0x7fe, 0x3fc, 0x1f8, 0x0f0, 0x000}; +const uint16_t xyzcal_point_pattern[12] PROGMEM = {0x000, 0x0f0, 0x1f8, 0x3fc, 0x7fe, 0x7fe, 0x7fe, 0x7fe, 0x3fc, 0x1f8, 0x0f0, 0x000}; bool xyzcal_searchZ(void) { @@ -747,7 +747,7 @@ bool xyzcal_scan_and_process(void) uint16_t* pattern = (uint16_t*)(histo + 2*16); for (uint8_t i = 0; i < 12; i++) { - pattern[i] = pgm_read_word_far((uint16_t*)(xyzcal_point_pattern + i)); + pattern[i] = pgm_read_word((uint16_t*)(xyzcal_point_pattern + i)); // DBG(_n(" pattern[%d]=%d\n"), i, pattern[i]); } uint8_t c = 0; @@ -777,8 +777,8 @@ bool xyzcal_find_bed_induction_sensor_point_xy(void) int16_t y = _Y; int16_t z = _Z; uint8_t point = xyzcal_xycoords2point(x, y); - x = pgm_read_word_far((uint16_t*)(xyzcal_point_xcoords + point)); - y = pgm_read_word_far((uint16_t*)(xyzcal_point_ycoords + point)); + x = pgm_read_word((uint16_t*)(xyzcal_point_xcoords + point)); + y = pgm_read_word((uint16_t*)(xyzcal_point_ycoords + point)); DBG(_n("point=%d x=%d y=%d z=%d\n"), point, x, y, z); xyzcal_meassure_enter(); xyzcal_lineXYZ_to(x, y, z, 200, 0); From 6c387384c7ba7417827fd21249ddb129018770aa Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Mon, 13 Aug 2018 19:43:37 +0200 Subject: [PATCH 16/16] Fix compiler warnings: sketch/Marlin.h:366:35: warning: large integer implicitly truncated to unsigned type [-Woverflow] #define PRINT_TIME_REMAINING_INIT 0xffffffff sketch/Marlin_main.cpp:8814:21: note: in expansion of macro 'PRINT_TIME_REMAINING_INIT' uint16_t print_t = PRINT_TIME_REMAINING_INIT; sketch/Marlin_main.cpp:8817:15: warning: comparison is always true due to limited range of data type [-Wtype-limits] if ((print_t != PRINT_TIME_REMAINING_INIT) && (feedmultiply != 0)) print_t = 100 * print_t / feedmultiply; --- Firmware/Marlin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 3912c9a2..4af4af49 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -363,7 +363,7 @@ extern uint8_t print_percent_done_normal; extern uint32_t print_time_remaining_normal; extern uint8_t print_percent_done_silent; extern uint32_t print_time_remaining_silent; -#define PRINT_TIME_REMAINING_INIT 0xffffffff +#define PRINT_TIME_REMAINING_INIT 0xffff #define PRINT_PERCENT_DONE_INIT 0xff #define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == 4) || saved_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL) || card.paused || mmu_print_saved)