From 7d32c7f36def22a6241f1a7b4d243000610e25fa Mon Sep 17 00:00:00 2001
From: grob6000 <grobinson6000@gmail.com>
Date: Sun, 11 Jan 2015 01:14:02 +1100
Subject: [PATCH] Multiple PID parameter edit for ultralcd

* Depending on extruder count, will add menu items for ultralcd to edit
individual PID parameters for each extruder
* Added menu items to each language_xx.h
* Builds OK, but recommend testing with typical LCD
---
 Marlin/language_ca.h |  8 +++++++
 Marlin/language_de.h |  8 +++++++
 Marlin/language_en.h |  8 +++++++
 Marlin/language_es.h |  8 +++++++
 Marlin/language_eu.h |  8 +++++++
 Marlin/language_fi.h |  8 +++++++
 Marlin/language_fr.h |  8 +++++++
 Marlin/language_it.h |  8 +++++++
 Marlin/language_nl.h |  8 +++++++
 Marlin/language_pl.h |  8 +++++++
 Marlin/language_pt.h |  8 +++++++
 Marlin/language_ru.h |  8 +++++++
 Marlin/ultralcd.cpp  | 53 ++++++++++++++++++++++++++++++++------------
 13 files changed, 135 insertions(+), 14 deletions(-)

diff --git a/Marlin/language_ca.h b/Marlin/language_ca.h
index ba5d37127f..db0e8021af 100644
--- a/Marlin/language_ca.h
+++ b/Marlin/language_ca.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Accel"
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_de.h b/Marlin/language_de.h
index e442448af6..a019290dca 100644
--- a/Marlin/language_de.h
+++ b/Marlin/language_de.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Acc"
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_en.h b/Marlin/language_en.h
index 014b42e51e..ecf87fc1d4 100644
--- a/Marlin/language_en.h
+++ b/Marlin/language_en.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Accel"
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_es.h b/Marlin/language_es.h
index 064c770604..8f5fb73d34 100644
--- a/Marlin/language_es.h
+++ b/Marlin/language_es.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Acel"
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_eu.h b/Marlin/language_eu.h
index 7e65ca59d1..66962543cf 100644
--- a/Marlin/language_eu.h
+++ b/Marlin/language_eu.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Azelerazioa"
 #define MSG_VXY_JERK                        "Vxy-astindua"
 #define MSG_VZ_JERK                         "Vz-astindua"
diff --git a/Marlin/language_fi.h b/Marlin/language_fi.h
index 0b1ac9cad9..c04637dc8b 100644
--- a/Marlin/language_fi.h
+++ b/Marlin/language_fi.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Kiihtyv"
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_fr.h b/Marlin/language_fr.h
index 59066b1268..29922c3270 100644
--- a/Marlin/language_fr.h
+++ b/Marlin/language_fr.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Accel"
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_it.h b/Marlin/language_it.h
index cb7dc466ae..d7abee458f 100644
--- a/Marlin/language_it.h
+++ b/Marlin/language_it.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Accel."
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_nl.h b/Marlin/language_nl.h
index e9dc380605..77e256e589 100644
--- a/Marlin/language_nl.h
+++ b/Marlin/language_nl.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Versn"
 #define MSG_VXY_JERK                        "Vxy-jerk"
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_pl.h b/Marlin/language_pl.h
index 55ec20ee36..8992097286 100644
--- a/Marlin/language_pl.h
+++ b/Marlin/language_pl.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I"
 #define MSG_PID_D                           "PID-D"
 #define MSG_PID_C                           "PID-C"
+#define MSG_PID_P1                          "PID-P E2"
+#define MSG_PID_I1                          "PID-I E2"
+#define MSG_PID_D1                          "PID-D E2"
+#define MSG_PID_C1                          "PID-C E2"
+#define MSG_PID_P2                          "PID-P E3"
+#define MSG_PID_I2                          "PID-I E3"
+#define MSG_PID_D2                          "PID-D E3"
+#define MSG_PID_C2                          "PID-C E3"
 #define MSG_ACC                             "Przyspieszenie"
 #define MSG_VXY_JERK                        "Zryw Vxy"
 #define MSG_VZ_JERK                         "Zryw Vz"
diff --git a/Marlin/language_pt.h b/Marlin/language_pt.h
index 09e346748f..473bed3e96 100644
--- a/Marlin/language_pt.h
+++ b/Marlin/language_pt.h
@@ -67,6 +67,14 @@
 #define MSG_PID_I                           "PID-I: "
 #define MSG_PID_D                           "PID-D: "
 #define MSG_PID_C                           "PID-C: "
+#define MSG_PID_P1                          "PID-P E2: "
+#define MSG_PID_I1                          "PID-I E2: "
+#define MSG_PID_D1                          "PID-D E2: "
+#define MSG_PID_C1                          "PID-C E2: "
+#define MSG_PID_P2                          "PID-P E3: "
+#define MSG_PID_I2                          "PID-I E3: "
+#define MSG_PID_D2                          "PID-D E3: "
+#define MSG_PID_C2                          "PID-C E3: "
 #define MSG_ACC                             "Acc:"
 #define MSG_VXY_JERK                        "Vxy-jerk: "
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/language_ru.h b/Marlin/language_ru.h
index ec666f186b..87c5b1db73 100644
--- a/Marlin/language_ru.h
+++ b/Marlin/language_ru.h
@@ -69,6 +69,14 @@
 #define MSG_PID_I                           "PID-I: "
 #define MSG_PID_D                           "PID-D: "
 #define MSG_PID_C                           "PID-C: "
+#define MSG_PID_P1                          "PID-P E2: "
+#define MSG_PID_I1                          "PID-I E2: "
+#define MSG_PID_D1                          "PID-D E2: "
+#define MSG_PID_C1                          "PID-C E2: "
+#define MSG_PID_P2                          "PID-P E3: "
+#define MSG_PID_I2                          "PID-I E3: "
+#define MSG_PID_D2                          "PID-D E3: "
+#define MSG_PID_C2                          "PID-C E3: "
 #define MSG_ACC                             "Acc:"
 #define MSG_VXY_JERK                        "Vxy-jerk: "
 #define MSG_VZ_JERK                         "Vz-jerk"
diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp
index d790266d92..f380d45ccc 100644
--- a/Marlin/ultralcd.cpp
+++ b/Marlin/ultralcd.cpp
@@ -185,8 +185,9 @@ void* editValue;
 int32_t minEditValue, maxEditValue;
 menuFunc_t callbackFunc;
 
-// place-holders for Ki and Kd edits
+// place-holders for Ki and Kd edits, and the extruder # being edited
 float raw_Ki, raw_Kd;
+int pid_current_extruder;
 
 static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
   if (currentMenu != menu) {
@@ -764,12 +765,6 @@ static void lcd_control_menu()
 
 static void lcd_control_temperature_menu()
 {
-#ifdef PIDTEMP
-    // set up temp variables - undo the default scaling
-    raw_Ki = unscalePID_i(Ki);
-    raw_Kd = unscalePID_d(Kd);
-#endif
-
     START_MENU();
     MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
 #if TEMP_SENSOR_0 != 0
@@ -792,13 +787,43 @@ static void lcd_control_temperature_menu()
     MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
 #endif
 #ifdef PIDTEMP
-    MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp, 1, 9990);
-    // i is typically a small value so allows values below 1
-    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
-    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
+	// set up temp variables - undo the default scaling
+	pid_current_extruder = 0;
+	raw_Ki = unscalePID_i(Ki[0]);
+	raw_Kd = unscalePID_d(Kd[0]);
+	MENU_ITEM_EDIT(float52, MSG_PID_P, &Kp[0], 1, 9990);
+	// i is typically a small value so allows values below 1
+	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
+	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
 # ifdef PID_ADD_EXTRUSION_RATE
-    MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc, 1, 9990);
+	MENU_ITEM_EDIT(float3, MSG_PID_C, &Kc[0], 1, 9990);
 # endif//PID_ADD_EXTRUSION_RATE
+#if EXTRUDERS > 1
+	// set up temp variables - undo the default scaling
+	pid_current_extruder = 1;
+	raw_Ki = unscalePID_i(Ki[1]);
+	raw_Kd = unscalePID_d(Kd[1]);
+	MENU_ITEM_EDIT(float52, MSG_PID_P1, &Kp[1], 1, 9990);
+	// i is typically a small value so allows values below 1
+	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I1, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
+	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D1, &raw_Kd, 1, 9990, copy_and_scalePID_d);
+# ifdef PID_ADD_EXTRUSION_RATE
+	MENU_ITEM_EDIT(float3, MSG_PID_C1, &Kc[1], 1, 9990);
+# endif//PID_ADD_EXTRUSION_RATE	
+#endif//EXTRUDERS > 1
+#if EXTRUDERS > 2
+	// set up temp variables - undo the default scaling
+	pid_current_extruder = 2;
+	raw_Ki = unscalePID_i(Ki[2]);
+	raw_Kd = unscalePID_d(Kd[2]);
+	MENU_ITEM_EDIT(float52, MSG_PID_P2, &Kp[2], 1, 9990);
+	// i is typically a small value so allows values below 1
+	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I2, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
+	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D2, &raw_Kd, 1, 9990, copy_and_scalePID_d);
+# ifdef PID_ADD_EXTRUSION_RATE
+	MENU_ITEM_EDIT(float3, MSG_PID_C2, &Kc[2], 1, 9990);
+# endif//PID_ADD_EXTRUSION_RATE	
+#endif//EXTRUDERS > 2
 #endif//PIDTEMP
     MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
     MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
@@ -1705,7 +1730,7 @@ char *ftostr52(const float &x)
 void copy_and_scalePID_i()
 {
 #ifdef PIDTEMP
-  Ki = scalePID_i(raw_Ki);
+  Ki[pid_current_extruder] = scalePID_i(raw_Ki);
   updatePID();
 #endif
 }
@@ -1715,7 +1740,7 @@ void copy_and_scalePID_i()
 void copy_and_scalePID_d()
 {
 #ifdef PIDTEMP
-  Kd = scalePID_d(raw_Kd);
+  Kd[pid_current_extruder] = scalePID_d(raw_Kd);
   updatePID();
 #endif
 }