From ca3ba55ca7e1198a4494c8334db592ba24e16aac Mon Sep 17 00:00:00 2001
From: PavelSindler <sindlerpa@gmail.com>
Date: Fri, 15 Sep 2017 18:04:19 +0200
Subject: [PATCH 1/4] initial version

---
 Firmware/Marlin_main.cpp  | 38 ++++++++++++++++++++++++++++++++++++++
 Firmware/language_all.cpp |  5 +++++
 Firmware/language_en.h    |  5 +++--
 Firmware/ultralcd.cpp     | 35 +++++++++++++++++------------------
 Firmware/ultralcd.h       |  1 +
 5 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp
index 3b51a67c..6f93df24 100644
--- a/Firmware/Marlin_main.cpp
+++ b/Firmware/Marlin_main.cpp
@@ -6438,6 +6438,43 @@ void ClearToSend()
         SERIAL_PROTOCOLLNRPGM(MSG_OK);
 }
 
+update_currents() {
+	float current_high[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
+	float current_low[3] = DEFAULT_PWM_MOTOR_CURRENT;
+	float tmp_motor[3];
+	
+	SERIAL_ECHOLNPGM("Currents updated: ");
+
+	if (destination[Z_AXIS] < Z_SILENT) {
+		SERIAL_ECHOLNPGM("LOW");
+		for (uint8_t i = 0; i < 3; i++) {
+			digipot_current(i, current_low[i]);		
+			MYSERIAL.print(int(i));
+			SERIAL_ECHOPGM(": ");
+			MYSERIAL.println(current_low[i]);
+		}		
+	}
+	else if (destination[Z_AXIS] > Z_HIGH_POWER) {
+		SERIAL_ECHOLNPGM("HIGH");
+		for (uint8_t i = 0; i < 3; i++) {
+			digipot_current(i, current_high[i]);
+			MYSERIAL.print(int(i));
+			SERIAL_ECHOPGM(": ");
+			MYSERIAL.println(current_high[i]);
+		}		
+	}
+	else {
+		for (uint8_t i = 0; i < 3; i++) {
+			float q = current_low[i] - Z_SILENT*((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT));
+			tmp_motor[i] = ((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT))*destination[Z_AXIS] + q;
+			digipot_current(i, tmp_motor[i]);			
+			MYSERIAL.print(int(i));
+			SERIAL_ECHOPGM(": ");
+			MYSERIAL.println(tmp_motor[i]);
+		}
+	}
+}
+
 void get_coordinates()
 {
   bool seen[4]={false,false,false,false};
@@ -6459,6 +6496,7 @@ void get_coordinates()
       if (relative)
         destination[i] += current_position[i];
       seen[i]=true;
+	  if (i == Z_AXIS && SilentModeMenu == 2) update_currents();
     }
     else destination[i] = current_position[i]; //Are these else lines really needed?
   }
diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp
index 6d72bb18..b9d056b8 100644
--- a/Firmware/language_all.cpp
+++ b/Firmware/language_all.cpp
@@ -60,6 +60,11 @@ const char * const MSG_AUTO_HOME_LANG_TABLE[1] PROGMEM = {
 	MSG_AUTO_HOME_EN
 };
 
+const char MSG_AUTO_MODE_ON_EN[] PROGMEM = "Mode [auto power]";
+const char * const MSG_AUTO_MODE_ON_LANG_TABLE[1] PROGMEM = {
+	MSG_AUTO_MODE_ON_EN
+};
+
 const char MSG_A_RETRACT_EN[] PROGMEM = "A-retract";
 const char * const MSG_A_RETRACT_LANG_TABLE[1] PROGMEM = {
 	MSG_A_RETRACT_EN
diff --git a/Firmware/language_en.h b/Firmware/language_en.h
index c22d9fb4..1a576d42 100644
--- a/Firmware/language_en.h
+++ b/Firmware/language_en.h
@@ -102,8 +102,9 @@
 #define(length=20) MSG_CHANGING_FILAMENT	"Changing filament!"
 
 
-#define MSG_SILENT_MODE_ON					"Mode    [Stealth]"
-#define MSG_SILENT_MODE_OFF					"Mode     [Normal]" 
+#define MSG_SILENT_MODE_ON					"Mode     [silent]"
+#define MSG_SILENT_MODE_OFF					"Mode [high power]" 
+#define MSG_AUTO_MODE_ON					"Mode [auto power]"
 #define(length=20) MSG_REBOOT				"Reboot the printer"
 #define(length=20) MSG_TAKE_EFFECT			" for take effect"											
 
diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp
index 3b3d0706..35e95468 100644
--- a/Firmware/ultralcd.cpp
+++ b/Firmware/ultralcd.cpp
@@ -3412,7 +3412,12 @@ static void lcd_fsensor_fail()
 
 
 static void lcd_silent_mode_set() {
-  SilentModeMenu = !SilentModeMenu;
+	switch (SilentModeMenu) {
+	case 0: SilentModeMenu = 1; break;
+	case 1: SilentModeMenu = 2; break;
+	case 2: SilentModeMenu = 0; break;
+	default: SilentModeMenu = 0; break;
+	}
   eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
 #ifdef TMC2130
   // Wait until the planner queue is drained and the stepper routine achieves
@@ -3891,6 +3896,13 @@ static void lcd_settings_menu()
   {
 	  MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
   }
+  if (!farm_mode) { //dont show in menu if we are in farm mode
+	  switch (SilentModeMenu) {
+	  case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
+	  case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break;
+	  case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break;
+	  default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
+  }
 
 #ifdef PAT9125
 #ifndef DEBUG_DISABLE_FSENSORCHECK
@@ -3951,6 +3963,7 @@ static void lcd_settings_menu()
 	  MENU_ITEM(function, MSG_SECOND_SERIAL_ON, lcd_second_serial_set);
   }
 
+
   if (!isPrintPaused && !homing_flag)
 	{
 		MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
@@ -5281,24 +5294,10 @@ static void lcd_tune_menu()
   MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
 #endif
   
-#ifdef PAT9125
-#ifndef DEBUG_DISABLE_FSENSORCHECK
-  if (FSensorStateMenu == 0) {
-    MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
+  if (SilentModeMenu == 0) {
+    MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
   } else {
-    MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
-  }
-#endif //DEBUG_DISABLE_FSENSORCHECK
-#endif //PAT9125
-
-#ifdef TMC2130
-  if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
-  else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
-
-  if (SilentModeMenu == 0)
-  {
-    if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
-    else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
+    MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
   }
   else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
 #endif //TMC2130
diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h
index 1dde5128..87a58934 100644
--- a/Firmware/ultralcd.h
+++ b/Firmware/ultralcd.h
@@ -118,6 +118,7 @@ void lcd_mylang();
   extern int farm_no;
   extern int farm_timer;
   extern int farm_status;
+  extern int8_t SilentModeMenu;
 
 #ifdef SNMM
   extern uint8_t snmm_extruder;

From a369c7900e3fec504938bf424a71470db34789c5 Mon Sep 17 00:00:00 2001
From: PavelSindler <sindlerpa@gmail.com>
Date: Mon, 18 Sep 2017 12:46:50 +0200
Subject: [PATCH 2/4] tune menu updated

---
 Firmware/stepper.cpp  |  5 ++---
 Firmware/ultralcd.cpp | 12 ++++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp
index 8510daf9..0ee53e0d 100644
--- a/Firmware/stepper.cpp
+++ b/Firmware/stepper.cpp
@@ -1361,10 +1361,9 @@ void EEPROM_read_st(int pos, uint8_t* value, uint8_t size)
 
 
 void digipot_init() //Initialize Digipot Motor Current
-{
-
+{  
   EEPROM_read_st(EEPROM_SILENT,(uint8_t*)&SilentMode,sizeof(SilentMode));
-
+  SilentModeMenu = SilentMode;
   #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
     if(SilentMode == 0){
     const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT_LOUD;
diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp
index 35e95468..a0e269b4 100644
--- a/Firmware/ultralcd.cpp
+++ b/Firmware/ultralcd.cpp
@@ -5264,6 +5264,18 @@ static void lcd_autostart_sd()
 
 
 
+static void lcd_silent_mode_set_tune() {
+  switch (SilentModeMenu) {
+  case 0: SilentModeMenu = 1; break;
+  case 1: SilentModeMenu = 2; break;
+  case 2: SilentModeMenu = 0; break;
+  default: SilentModeMenu = 0; break;
+  }
+  eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
+  digipot_init();
+  lcd_goto_menu(lcd_tune_menu, 9);
+}
+
 static void lcd_colorprint_change() {
 	
 	enquecommand_P(PSTR("M600"));

From 1033bd3cf94a47d58bc40128d6fbccdf04160537 Mon Sep 17 00:00:00 2001
From: PavelSindler <sindlerpa@gmail.com>
Date: Mon, 18 Sep 2017 12:48:49 +0200
Subject: [PATCH 3/4] info on serial not used

---
 Firmware/Marlin_main.cpp | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp
index 6f93df24..e09cdad3 100644
--- a/Firmware/Marlin_main.cpp
+++ b/Firmware/Marlin_main.cpp
@@ -6443,24 +6443,24 @@ update_currents() {
 	float current_low[3] = DEFAULT_PWM_MOTOR_CURRENT;
 	float tmp_motor[3];
 	
-	SERIAL_ECHOLNPGM("Currents updated: ");
+	//SERIAL_ECHOLNPGM("Currents updated: ");
 
 	if (destination[Z_AXIS] < Z_SILENT) {
-		SERIAL_ECHOLNPGM("LOW");
+		//SERIAL_ECHOLNPGM("LOW");
 		for (uint8_t i = 0; i < 3; i++) {
 			digipot_current(i, current_low[i]);		
-			MYSERIAL.print(int(i));
+			/*MYSERIAL.print(int(i));
 			SERIAL_ECHOPGM(": ");
-			MYSERIAL.println(current_low[i]);
+			MYSERIAL.println(current_low[i]);*/
 		}		
 	}
 	else if (destination[Z_AXIS] > Z_HIGH_POWER) {
-		SERIAL_ECHOLNPGM("HIGH");
+		//SERIAL_ECHOLNPGM("HIGH");
 		for (uint8_t i = 0; i < 3; i++) {
 			digipot_current(i, current_high[i]);
-			MYSERIAL.print(int(i));
+			/*MYSERIAL.print(int(i));
 			SERIAL_ECHOPGM(": ");
-			MYSERIAL.println(current_high[i]);
+			MYSERIAL.println(current_high[i]);*/
 		}		
 	}
 	else {
@@ -6468,9 +6468,9 @@ update_currents() {
 			float q = current_low[i] - Z_SILENT*((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT));
 			tmp_motor[i] = ((current_high[i] - current_low[i]) / (Z_HIGH_POWER - Z_SILENT))*destination[Z_AXIS] + q;
 			digipot_current(i, tmp_motor[i]);			
-			MYSERIAL.print(int(i));
+			/*MYSERIAL.print(int(i));
 			SERIAL_ECHOPGM(": ");
-			MYSERIAL.println(tmp_motor[i]);
+			MYSERIAL.println(tmp_motor[i]);*/
 		}
 	}
 }

From 917689b5ce4ee4405a06c3d29a2d2b58bf10aad0 Mon Sep 17 00:00:00 2001
From: PavelSindler <sindlerpa@gmail.com>
Date: Mon, 5 Mar 2018 01:23:18 +0100
Subject: [PATCH 4/4] tune menu

---
 Firmware/Marlin.h         |  1 +
 Firmware/Marlin_main.cpp  |  2 +-
 Firmware/language_all.cpp |  4 +--
 Firmware/language_all.h   |  2 ++
 Firmware/ultralcd.cpp     | 63 +++++++++++++++++++++++++--------------
 5 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h
index a576a1f2..c7951383 100644
--- a/Firmware/Marlin.h
+++ b/Firmware/Marlin.h
@@ -218,6 +218,7 @@ enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
 
 void FlushSerialRequestResend();
 void ClearToSend();
+void update_currents();
 
 void get_coordinates();
 void prepare_move();
diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp
index e09cdad3..793dfdd1 100644
--- a/Firmware/Marlin_main.cpp
+++ b/Firmware/Marlin_main.cpp
@@ -6438,7 +6438,7 @@ void ClearToSend()
         SERIAL_PROTOCOLLNRPGM(MSG_OK);
 }
 
-update_currents() {
+void update_currents() {
 	float current_high[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
 	float current_low[3] = DEFAULT_PWM_MOTOR_CURRENT;
 	float tmp_motor[3];
diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp
index b9d056b8..3eb8ba85 100644
--- a/Firmware/language_all.cpp
+++ b/Firmware/language_all.cpp
@@ -1985,14 +1985,14 @@ const char * const MSG_SHOW_END_STOPS_LANG_TABLE[LANG_NUM] PROGMEM = {
 	MSG_SHOW_END_STOPS_CZ
 };
 
-const char MSG_SILENT_MODE_OFF_EN[] PROGMEM = "Mode     [Normal]";
+const char MSG_SILENT_MODE_OFF_EN[] PROGMEM = "Mode [high power]";
 const char MSG_SILENT_MODE_OFF_CZ[] PROGMEM = "Mod      [Normal]";
 const char * const MSG_SILENT_MODE_OFF_LANG_TABLE[LANG_NUM] PROGMEM = {
 	MSG_SILENT_MODE_OFF_EN,
 	MSG_SILENT_MODE_OFF_CZ
 };
 
-const char MSG_SILENT_MODE_ON_EN[] PROGMEM = "Mode    [Stealth]";
+const char MSG_SILENT_MODE_ON_EN[] PROGMEM = "Mode     [silent]";
 const char MSG_SILENT_MODE_ON_CZ[] PROGMEM = "Mod     [Stealth]";
 const char * const MSG_SILENT_MODE_ON_LANG_TABLE[LANG_NUM] PROGMEM = {
 	MSG_SILENT_MODE_ON_EN,
diff --git a/Firmware/language_all.h b/Firmware/language_all.h
index a055e361..bbc8e6fe 100644
--- a/Firmware/language_all.h
+++ b/Firmware/language_all.h
@@ -40,6 +40,8 @@ extern const char* const MSG_AUTOLOAD_FILAMENT_LANG_TABLE[LANG_NUM];
 #define MSG_AUTOLOAD_FILAMENT LANG_TABLE_SELECT(MSG_AUTOLOAD_FILAMENT_LANG_TABLE)
 extern const char* const MSG_AUTO_HOME_LANG_TABLE[1];
 #define MSG_AUTO_HOME LANG_TABLE_SELECT_EXPLICIT(MSG_AUTO_HOME_LANG_TABLE, 0)
+extern const char* const MSG_AUTO_MODE_ON_LANG_TABLE[1];
+#define MSG_AUTO_MODE_ON LANG_TABLE_SELECT_EXPLICIT(MSG_AUTO_MODE_ON_LANG_TABLE, 0)
 extern const char* const MSG_A_RETRACT_LANG_TABLE[1];
 #define MSG_A_RETRACT LANG_TABLE_SELECT_EXPLICIT(MSG_A_RETRACT_LANG_TABLE, 0)
 extern const char* const MSG_BABYSTEPPING_X_LANG_TABLE[1];
diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp
index a0e269b4..df8276f6 100644
--- a/Firmware/ultralcd.cpp
+++ b/Firmware/ultralcd.cpp
@@ -3902,6 +3902,7 @@ static void lcd_settings_menu()
 	  case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break;
 	  case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break;
 	  default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
+	  }
   }
 
 #ifdef PAT9125
@@ -5289,37 +5290,55 @@ static void lcd_colorprint_change() {
 
 static void lcd_tune_menu()
 {
-  EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
+	EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
 
-  
 
-  START_MENU();
-  MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
-  MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
 
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
-  MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
+	START_MENU();
+	MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
+	MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
 
-  MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
-  MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
+	MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
+	MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
+
+	MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
+	MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
 #ifdef FILAMENTCHANGEENABLE
-  MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
+	MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
 #endif
-  
-  if (SilentModeMenu == 0) {
-    MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
-  } else {
-    MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
-  }
-  else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
+
+#ifndef DEBUG_DISABLE_FSENSORCHECK
+	if (FSensorStateMenu == 0) {
+		MENU_ITEM(function, MSG_FSENSOR_OFF, lcd_fsensor_state_set);
+	}
+	else {
+		MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
+	}
+#endif //DEBUG_DISABLE_FSENSORCHECK
+
+#ifdef TMC2130
+	if (SilentModeMenu == 0) MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
+	else MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
+
+	if (SilentModeMenu == 0)
+	{
+		if (CrashDetectMenu == 0) MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
+		else MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
+	}
+	else MENU_ITEM(submenu, MSG_CRASHDETECT_NA, lcd_crash_mode_info);
+#else //TMC2130
+	if (!farm_mode) { //dont show in menu if we are in farm mode
+		switch (SilentModeMenu) {
+		case 0: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
+		case 1: MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); break;
+		case 2: MENU_ITEM(function, MSG_AUTO_MODE_ON, lcd_silent_mode_set); break;
+		default: MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); break;
+		}
+	}
 #endif //TMC2130
-
-  END_MENU();
+	END_MENU();
 }
 
-
-
-
 static void lcd_move_menu_01mm()
 {
   move_menu_scale = 0.1;