Jelajahi Sumber

Merge remote-tracking branch 'upstream/MK3' into MK3-new_lang

Robert Pelnar 6 tahun lalu
induk
melakukan
10af023eae

+ 1 - 0
.gitignore

@@ -11,3 +11,4 @@ Firmware/Doc
 /Firmware/Firmware.vcxproj.filters
 /Firmware/Firmware - Shortcut.lnk
 /Firmware/variants/1_75mm_MK3-MMU-EINSy10a-E3Dv6full.h.bak
+/Firmware/Marlin_main.cpp~RF12cfae7.TMP

+ 49 - 13
Firmware/Marlin_main.cpp

@@ -140,6 +140,11 @@
 #define PRINTING_TYPE_SD 0
 #define PRINTING_TYPE_USB 1
 
+//filament types 
+#define FILAMENT_DEFAULT 0
+#define FILAMENT_FLEX 1
+#define FILAMENT_PVA 2
+
 // look here for descriptions of G-codes: http://linuxcnc.org/handbook/gcode/g-code.html
 // http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes
 
@@ -3117,9 +3122,9 @@ void gcode_M600(bool automatic, float x_position, float y_position, float z_shif
 		
 		// Unload filament
 #if defined (SNMM) || defined (SNMM_V2) 
-		extr_unload(); //unload just current filament
+		extr_unload(); //unload just current filament for multimaterial printers (used also in M702)
 #else
-		unload_filament(); //unload filament fopr single material (used also in M702)
+		unload_filament(); //unload filament for single material (used also in M702)
 #endif 
 		//finish moves
 		st_synchronize();
@@ -3159,7 +3164,7 @@ void gcode_M600(bool automatic, float x_position, float y_position, float z_shif
       st_synchronize();  
       
 	  //Unretract
-      current_position[E_AXIS]= current_position[E_AXIS] - FILAMENTCHANGE_FIRSTRETRACT;
+      current_position[E_AXIS]= current_position[E_AXIS] - e_shift;
       plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], current_position[E_AXIS], FILAMENTCHANGE_RFEED, active_extruder);
 	  st_synchronize();
 
@@ -3351,8 +3356,8 @@ void process_commands()
 	  if(code_seen("CRASH_DETECTED"))
 	  {
 		  uint8_t mask = 0;
-		  if (code_seen("X")) mask |= X_AXIS_MASK;
-		  if (code_seen("Y")) mask |= Y_AXIS_MASK;
+		  if (code_seen('X')) mask |= X_AXIS_MASK;
+		  if (code_seen('Y')) mask |= Y_AXIS_MASK;
 		  crashdet_detected(mask);
 	  }
 	  else if(code_seen("CRASH_RECOVER"))
@@ -3464,7 +3469,9 @@ void process_commands()
                enquecommand_P(PSTR("M24")); 
 		}	
 		else if (code_seen("MMURES")) {
-			fprintf_P(uart2io, PSTR("X0"));
+
+			printf_P(PSTR("X0\n"));
+			fprintf_P(uart2io, PSTR("X0\n"));
 		}
 		else if (code_seen("RESET")) {
             // careful!
@@ -4281,10 +4288,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
 
 		if (code_seen('X')) dimension_x = code_value();
 		if (code_seen('Y')) dimension_y = code_value();
-		if (code_seen('XP')) points_x = code_value();
-		if (code_seen('YP')) points_y = code_value();
-		if (code_seen('XO')) offset_x = code_value();
-		if (code_seen('YO')) offset_y = code_value();
+		if (code_seen("XP")) { strchr_pointer+=1; points_x = code_value(); }
+		if (code_seen("YP")) { strchr_pointer+=1; points_y = code_value(); }
+		if (code_seen("XO")) { strchr_pointer+=1; offset_x = code_value(); }
+		if (code_seen("YO")) { strchr_pointer+=1; offset_y = code_value(); }
 		
 		bed_analysis(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y);
 		
@@ -6289,6 +6296,29 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
     }
     break;
 
+	case 403: //M403 set filament type (material) for particular extruder and send this information to mmu
+	{
+		//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;
+		}
+		printf_P(PSTR("F%d%d\n"), extruder, filament);
+		fprintf_P(uart2io, PSTR("F%d%d\n"), extruder, filament);
+	}
+	break;
+
     case 500: // M500 Store settings in EEPROM
     {
         Config_StoreSettings(EEPROM_OFFSET);
@@ -7775,7 +7805,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_
 	int ix = 0;
 	int iy = 0;
 
-	char* filename_wldsd = "wldsd.txt";
+	const char* filename_wldsd = "wldsd.txt";
 	char data_wldsd[70];
 	char numb_wldsd[10];
 
@@ -9075,11 +9105,16 @@ void M600_wait_for_user() {
 		WRITE(BEEPER, LOW);
 }
 
-void mmu_M600_load_filament(bool automatic) {
+void mmu_M600_load_filament(bool automatic) { 
+	//load filament for mmu v2
 #ifdef SNMM_V2
 		  bool response = false;
+		  bool yes = false;
 		  if (!automatic) {
-			  tmp_extruder = choose_extruder_menu();
+			  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 = snmm_extruder;
+
 		  }
 		  else {
 			  tmp_extruder = (tmp_extruder+1)%5;
@@ -9130,6 +9165,7 @@ void M600_load_filament_movements() {
 }
 
 void M600_load_filament() {
+	//load filament for single material and SNMM 
 	lcd_wait_interact();
 
 	//load_filament_time = millis();

+ 11 - 0
Firmware/adc.h

@@ -10,6 +10,17 @@
 extern "C" {
 #endif //defined(__cplusplus)
 
+/*
+http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
+*/
+#define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255)
+#define BX_(x) ((x) - (((x)>>1)&0x77777777) - (((x)>>2)&0x33333333) - (((x)>>3)&0x11111111))
+
+#define ADC_PIN_IDX(pin) BITCOUNT(ADC_CHAN_MSK & ((1 << (pin)) - 1))
+
+#if BITCOUNT(ADC_CHAN_MSK) != ADC_CHAN_CNT
+# error "ADC_CHAN_MSK oes not match ADC_CHAN_CNT"
+#endif
 
 extern uint8_t adc_state;
 extern uint8_t adc_count;

+ 5 - 5
Firmware/cardreader.cpp

@@ -258,7 +258,7 @@ void CardReader::pauseSDPrint()
 }
 
 
-void CardReader::openLogFile(char* name)
+void CardReader::openLogFile(const char* name)
 {
   logging = true;
   openFile(name, false);
@@ -289,7 +289,7 @@ void CardReader::getAbsFilename(char *t)
     t[0]=0;
 }
 
-void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/)
+void CardReader::openFile(const char* name,bool read, bool replace_current/*=true*/)
 {
   if(!cardOK)
     return;
@@ -341,7 +341,7 @@ void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/)
  
   SdFile myDir;
   curDir=&root;
-  char *fname=name;
+  const char *fname=name;
   
   char *dirname_start,*dirname_end;
   if(name[0]=='/')
@@ -429,7 +429,7 @@ void CardReader::openFile(char* name,bool read, bool replace_current/*=true*/)
   
 }
 
-void CardReader::removeFile(char* name)
+void CardReader::removeFile(const char* name)
 {
   if(!cardOK)
     return;
@@ -439,7 +439,7 @@ void CardReader::removeFile(char* name)
   
   SdFile myDir;
   curDir=&root;
-  char *fname=name;
+  const char *fname=name;
   
   char *dirname_start,*dirname_end;
   if(name[0]=='/')

+ 3 - 3
Firmware/cardreader.h

@@ -19,9 +19,9 @@ public:
   //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
 
   void checkautostart(bool x); 
-  void openFile(char* name,bool read,bool replace_current=true);
-  void openLogFile(char* name);
-  void removeFile(char* name);
+  void openFile(const char* name,bool read,bool replace_current=true);
+  void openLogFile(const char* name);
+  void removeFile(const char* name);
   void closefile(bool store_location=false);
   void release();
   void startFileprint();

+ 6 - 2
Firmware/menu.cpp

@@ -8,6 +8,7 @@
 #include "lcd.h"
 #include "Configuration.h"
 #include "Marlin.h"
+#include "ultralcd.h"
 
 
 
@@ -75,7 +76,10 @@ void menu_end(void)
 
 void menu_back(void)
 {
-	if (menu_depth > 0) menu_goto(menu_stack[--menu_depth].menu, menu_stack[menu_depth].position, true, true);
+	if (menu_depth > 0) {
+		menu_depth--;		
+		menu_goto(menu_stack[menu_depth].menu, menu_stack[menu_depth].position, true, true);
+	}
 }
 
 void menu_back_if_clicked(void)
@@ -266,7 +270,7 @@ void menu_draw_float13(char chr, const char* str, float val)
 	lcd_printf_P(menu_fmt_float13, chr, str, spaces, val);
 }
 
-#define _menu_data (*((menu_data_edit_t*)menu_data))
+#define _menu_data menuData.edit_menu
 void _menu_edit_int3(void)
 {
 	if (lcd_draw_update)

+ 6 - 6
Firmware/temperature.cpp

@@ -1552,17 +1552,17 @@ extern "C" {
 
 void adc_ready(void) //callback from adc when sampling finished
 {
-	current_temperature_raw[0] = adc_values[TEMP_0_PIN]; //heater
-	current_temperature_raw_pinda = adc_values[TEMP_PINDA_PIN];
-	current_temperature_bed_raw = adc_values[TEMP_BED_PIN];
+	current_temperature_raw[0] = adc_values[ADC_PIN_IDX(TEMP_0_PIN)]; //heater
+	current_temperature_raw_pinda = adc_values[ADC_PIN_IDX(TEMP_PINDA_PIN)];
+	current_temperature_bed_raw = adc_values[ADC_PIN_IDX(TEMP_BED_PIN)];
 #ifdef VOLT_PWR_PIN
-	current_voltage_raw_pwr = adc_values[VOLT_PWR_PIN];
+	current_voltage_raw_pwr = adc_values[ADC_PIN_IDX(VOLT_PWR_PIN)];
 #endif
 #ifdef AMBIENT_THERMISTOR
-	current_temperature_raw_ambient = adc_values[TEMP_AMBIENT_PIN];
+	current_temperature_raw_ambient = adc_values[ADC_PIN_IDX(TEMP_AMBIENT_PIN)];
 #endif //AMBIENT_THERMISTOR
 #ifdef VOLT_BED_PIN
-	current_voltage_raw_bed = adc_values[VOLT_BED_PIN]; // 6->9
+	current_voltage_raw_bed = adc_values[ADC_PIN_IDX(VOLT_BED_PIN)]; // 6->9
 #endif
 	temp_meas_ready = true;
 }

+ 8 - 8
Firmware/tmc2130.cpp

@@ -129,10 +129,10 @@ void tmc2130_wr_TPWMTHRS(uint8_t axis, uint32_t val32);
 void tmc2130_wr_THIGH(uint8_t axis, uint32_t val32);
 
 #define tmc2130_rd(axis, addr, rval) tmc2130_rx(axis, addr, rval)
-#define tmc2130_wr(axis, addr, wval) tmc2130_tx(axis, addr | 0x80, wval)
+#define tmc2130_wr(axis, addr, wval) tmc2130_tx(axis, (addr) | 0x80, wval)
 
-uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval);
-uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval);
+static void tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval);
+static uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval);
 
 
 void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r);
@@ -627,7 +627,7 @@ inline void tmc2130_cs_high(uint8_t axis)
 #define TMC2130_SPI_TXRX       spi_txrx
 #define TMC2130_SPI_LEAVE()
 
-uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval)
+static void tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval)
 {
 	//datagram1 - request
 	TMC2130_SPI_ENTER();
@@ -641,7 +641,7 @@ uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval)
 	TMC2130_SPI_LEAVE();
 }
 
-uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval)
+static uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval)
 {
 	//datagram1 - request
 	TMC2130_SPI_ENTER();
@@ -860,8 +860,8 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
 	printf_P(PSTR(" factor: %s\n"), ftostr43(fac));
 	uint8_t vA = 0;                //value of currentA
 	uint8_t va = 0;                //previous vA
-	uint8_t d0 = 0;                //delta0
-	uint8_t d1 = 1;                //delta1
+	int8_t d0 = 0;                //delta0
+	int8_t d1 = 1;                //delta1
 	uint8_t w[4] = {1,1,1,1};      //W bits (MSLUTSEL)
 	uint8_t x[3] = {255,255,255};  //X segment bounds (MSLUTSEL)
 	uint8_t s = 0;                 //current segment
@@ -872,7 +872,7 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000)
 	tmc2130_wr_MSLUTSTART(axis, 0, amp);
 	for (i = 0; i < 256; i++)
 	{
-		if ((i & 31) == 0)
+		if ((i & 0x1f) == 0)
 			reg = 0;
 		// calculate value
 		if (fac == 0) // default TMC wave

+ 34 - 99
Firmware/ultralcd.cpp

@@ -48,90 +48,10 @@ char longFilenameOLD[LONG_FILENAME_LENGTH];
 
 static void lcd_sd_updir();
 
-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;
-};
 
 // State of the currently active menu.
 // C Union manages sharing of the static memory by all the menus.
-//union MenuData menuData = { 0 };
-#define menuData (*((MenuData*)menu_data))
+union MenuData menuData = { 0 };
 
 
 int8_t ReInitLCD = 0;
@@ -3573,7 +3493,7 @@ void lcd_bed_calibration_show_result(uint8_t result, uint8_t point_too_far_mask)
         else if (point_too_far_mask == 2 || point_too_far_mask == 7)
             // Only the center point or all the three front points.
             msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8
-        else if (point_too_far_mask & 1 == 0)
+        else if ((point_too_far_mask & 1) == 0)
             // The right and maybe the center point out of reach.
             msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8
         else
@@ -3585,7 +3505,7 @@ void lcd_bed_calibration_show_result(uint8_t result, uint8_t point_too_far_mask)
             if (point_too_far_mask == 2 || point_too_far_mask == 7)
                 // Only the center point or all the three front points.
                 msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
-            else if (point_too_far_mask & 1 == 0)
+            else if ((point_too_far_mask & 1) == 0)
                 // The right and maybe the center point out of reach.
                 msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
             else
@@ -3648,11 +3568,11 @@ static void lcd_show_end_stops() {
 	lcd_set_cursor(0, 0);
 	lcd_puts_P((PSTR("End stops diag")));
 	lcd_set_cursor(0, 1);
-	lcd_puts_P((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
+	lcd_puts_P((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ? (PSTR("X1")) : (PSTR("X0")));
 	lcd_set_cursor(0, 2);
-	lcd_puts_P((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
+	lcd_puts_P((READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ? (PSTR("Y1")) : (PSTR("Y0")));
 	lcd_set_cursor(0, 3);
-	lcd_puts_P((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
+	lcd_puts_P((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING) ? (PSTR("Z1")) : (PSTR("Z0")));
 }
 
 static void menu_show_end_stops() {
@@ -5356,7 +5276,7 @@ void extr_adj(int extruder) //loading filament for SNMM
 }
 
 
-void extr_unload() { //unloads filament
+void extr_unload() { //unload just current filament for multimaterial printers
 	#ifndef SNMM_V2
 	float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
 	float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
@@ -6234,6 +6154,25 @@ static void lcd_tune_menu()
 		}
 	}
 #endif //TMC2130
+
+     switch(eSoundMode)
+          {
+          case e_SOUND_MODE_LOUD:
+               MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
+               break;
+          case e_SOUND_MODE_ONCE:
+               MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_ONCE),lcd_sound_state_set);
+               break;
+          case e_SOUND_MODE_SILENT:
+               MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);
+               break;
+          case e_SOUND_MODE_MUTE:
+               MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);
+               break;
+          default:
+               MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);
+          }
+
 	MENU_END();
 }
 
@@ -6685,13 +6624,12 @@ static bool lcd_selfcheck_axis_sg(char axis) {
 			enable_endstops(false);
 
 			const char *_error_1;
-			const char *_error_2;
 
 			if (axis == X_AXIS) _error_1 = "X";
 			if (axis == Y_AXIS) _error_1 = "Y";
 			if (axis == Z_AXIS) _error_1 = "Z";
 
-			lcd_selftest_error(9, _error_1, _error_2);
+			lcd_selftest_error(9, _error_1, NULL);
 			current_position[axis] = 0;
 			plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
 			reset_crash_det(axis);
@@ -6704,13 +6642,12 @@ static bool lcd_selfcheck_axis_sg(char axis) {
 		if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
 			//loose pulleys
 			const char *_error_1;
-			const char *_error_2;
 
 			if (axis == X_AXIS) _error_1 = "X";
 			if (axis == Y_AXIS) _error_1 = "Y";
 			if (axis == Z_AXIS) _error_1 = "Z";
 
-			lcd_selftest_error(8, _error_1, _error_2);
+			lcd_selftest_error(8, _error_1, NULL);
 			current_position[axis] = 0;
 			plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
 			reset_crash_det(axis);
@@ -6748,11 +6685,11 @@ static bool lcd_selfcheck_axis(int _axis, int _travel)
 		plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
 		st_synchronize();
 #ifdef TMC2130
-		if (((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
+		if ((READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
 #else //TMC2130
-		if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
-			((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
-			((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
+		if ((READ(X_MIN_PIN) ^ (bool)X_MIN_ENDSTOP_INVERTING) ||
+			(READ(Y_MIN_PIN) ^ (bool)Y_MIN_ENDSTOP_INVERTING) ||
+			(READ(Z_MIN_PIN) ^ (bool)Z_MIN_ENDSTOP_INVERTING))
 #endif //TMC2130
 		{
 			if (_axis == 0)
@@ -7125,8 +7062,7 @@ static bool lcd_selftest_fsensor(void)
 	fsensor_init();
 	if (fsensor_not_responding)
 	{
-		const char *_err;
-		lcd_selftest_error(11, _err, _err);
+		lcd_selftest_error(11, NULL, NULL);
 	}
 	return (!fsensor_not_responding);
 }
@@ -7281,8 +7217,7 @@ static bool lcd_selftest_fan_dialog(int _fan)
 	}
 	if (!_result)
 	{
-		const char *_err;
-		lcd_selftest_error(_errno, _err, _err);
+		lcd_selftest_error(_errno, NULL, NULL);
 	}
 	return _result;
 }

+ 86 - 0
Firmware/ultralcd.h

@@ -4,6 +4,7 @@
 #include "Marlin.h"
 #include "lcd.h"
 #include "conv2str.h"
+#include "menu.h"
 
 extern int lcd_puts_P(const char* str);
 extern int lcd_printf_P(const char* format, ...);
@@ -12,6 +13,91 @@ 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();

+ 4 - 4
Firmware/xyzcal.cpp

@@ -210,16 +210,16 @@ bool xyzcal_spiral8(int16_t cx, int16_t cy, int16_t z0, int16_t dz, int16_t radi
 	if (pad) ad = *pad;
 	DBG(_n("xyzcal_spiral8 cx=%d cy=%d z0=%d dz=%d radius=%d ad=%d\n"), cx, cy, z0, dz, radius, ad);
 	if (!ret && (ad < 720))
-		if (ret = xyzcal_spiral2(cx, cy, z0 - 0*dz, dz, radius, 0, delay_us, check_pinda, &ad))
+		if ((ret = xyzcal_spiral2(cx, cy, z0 - 0*dz, dz, radius, 0, delay_us, check_pinda, &ad)) != 0)
 			ad += 0;
 	if (!ret && (ad < 1440))
-		if (ret = xyzcal_spiral2(cx, cy, z0 - 1*dz, dz, -radius, 0, delay_us, check_pinda, &ad))
+		if ((ret = xyzcal_spiral2(cx, cy, z0 - 1*dz, dz, -radius, 0, delay_us, check_pinda, &ad)) != 0)
 			ad += 720;
 	if (!ret && (ad < 2160))
-		if (ret = xyzcal_spiral2(cx, cy, z0 - 2*dz, dz, radius, 180, delay_us, check_pinda, &ad))
+		if ((ret = xyzcal_spiral2(cx, cy, z0 - 2*dz, dz, radius, 180, delay_us, check_pinda, &ad)) != 0)
 			ad += 1440;
 	if (!ret && (ad < 2880))
-		if (ret = xyzcal_spiral2(cx, cy, z0 - 3*dz, dz, -radius, 180, delay_us, check_pinda, &ad))
+		if ((ret = xyzcal_spiral2(cx, cy, z0 - 3*dz, dz, -radius, 180, delay_us, check_pinda, &ad)) != 0)
 			ad += 2160;
 	if (pad) *pad = ad;
 	return ret;