浏览代码

Proper implementation of PID menu items

- Make this work per #1344
Scott Lahteine 9 年前
父节点
当前提交
2d6fa9ce80
共有 1 个文件被更改,包括 106 次插入88 次删除
  1. 106
    88
      Marlin/ultralcd.cpp

+ 106
- 88
Marlin/ultralcd.cpp 查看文件

@@ -41,11 +41,6 @@ char lcd_status_message[LCD_WIDTH+1] = WELCOME_MSG;
41 41
 #include "ultralcd_implementation_hitachi_HD44780.h"
42 42
 #endif
43 43
 
44
-/** forward declarations **/
45
-
46
-void copy_and_scalePID_i();
47
-void copy_and_scalePID_d();
48
-
49 44
 /* Different menus */
50 45
 static void lcd_status_screen();
51 46
 #ifdef ULTIPANEL
@@ -185,9 +180,8 @@ void* editValue;
185 180
 int32_t minEditValue, maxEditValue;
186 181
 menuFunc_t callbackFunc;
187 182
 
188
-// place-holders for Ki and Kd edits, and the extruder # being edited
183
+// place-holders for Ki and Kd edits
189 184
 float raw_Ki, raw_Kd;
190
-int pid_current_extruder;
191 185
 
192 186
 static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder=0, const bool feedback=true) {
193 187
   if (currentMenu != menu) {
@@ -811,76 +805,120 @@ static void lcd_control_menu()
811 805
     END_MENU();
812 806
 }
813 807
 
808
+#ifdef PIDTEMP
809
+  // Helpers for editing PID Ki & Kd values
810
+  // grab the PID value out of the temp variable; scale it; then update the PID driver
811
+  void copy_and_scalePID_i(int e) {
812
+    PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
813
+    updatePID();
814
+  }
815
+  void copy_and_scalePID_d(int e) {
816
+    PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
817
+    updatePID();
818
+  }
819
+  void copy_and_scalePID_i_E1() { copy_and_scalePID_i(0); }
820
+  void copy_and_scalePID_d_E1() { copy_and_scalePID_d(0); }
821
+  #if EXTRUDERS > 1
822
+    void copy_and_scalePID_i_E2() { copy_and_scalePID_i(1); }
823
+    void copy_and_scalePID_d_E2() { copy_and_scalePID_d(1); }
824
+    #if EXTRUDERS > 2
825
+      void copy_and_scalePID_i_E3() { copy_and_scalePID_i(2); }
826
+      void copy_and_scalePID_d_E3() { copy_and_scalePID_d(2); }
827
+      #if EXTRUDERS > 3
828
+        void copy_and_scalePID_i_E4() { copy_and_scalePID_i(3); }
829
+        void copy_and_scalePID_d_E5() { copy_and_scalePID_d(3); }
830
+      #endif
831
+    #endif
832
+  #endif
833
+#endif
834
+
814 835
 static void lcd_control_temperature_menu()
815 836
 {
816 837
   START_MENU();
817 838
   MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
818
-#if TEMP_SENSOR_0 != 0
819
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
820
-#endif
821
-#if TEMP_SENSOR_1 != 0 && EXTRUDERS > 1
822
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
823
-#endif
824
-#if TEMP_SENSOR_2 != 0 && EXTRUDERS > 2
825
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
826
-#endif
827
-#if TEMP_SENSOR_3 != 0 && EXTRUDERS > 3
828
-  MENU_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
829
-#endif
830
-#if TEMP_SENSOR_BED != 0
831
-  MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
832
-#endif
839
+  #if TEMP_SENSOR_0 != 0
840
+    MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
841
+  #endif
842
+  #if EXTRUDERS > 1
843
+    #if TEMP_SENSOR_1 != 0
844
+      MENU_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
845
+    #endif
846
+    #if EXTRUDERS > 2
847
+      #if TEMP_SENSOR_2 != 0
848
+        MENU_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
849
+      #endif
850
+      #if EXTRUDERS > 2
851
+        #if TEMP_SENSOR_3 != 0
852
+          MENU_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
853
+        #endif
854
+      #endif
855
+    #endif
856
+  #endif
857
+  #if TEMP_SENSOR_BED != 0
858
+    MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
859
+  #endif
833 860
   MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
834
-#if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
835
-  MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
836
-  MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
837
-  MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
838
-  MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
839
-#endif
840
-#ifdef PIDTEMP
841
-	// set up temp variables - undo the default scaling
842
-	pid_current_extruder = 0;
843
-	raw_Ki = unscalePID_i(PID_PARAM(Ki,0));
844
-	raw_Kd = unscalePID_d(PID_PARAM(Kd,0));
845
-	MENU_ITEM_EDIT(float52, MSG_PID_P, &PID_PARAM(Kp,0), 1, 9990);
846
-	// i is typically a small value so allows values below 1
847
-	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
848
-	MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d);
861
+  #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
862
+    MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
863
+    MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
864
+    MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
865
+    MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
866
+  #endif
867
+  #ifdef PIDTEMP
868
+    // set up temp variables - undo the default scaling
869
+    raw_Ki = unscalePID_i(PID_PARAM(Ki,0));
870
+    raw_Kd = unscalePID_d(PID_PARAM(Kd,0));
871
+    MENU_ITEM_EDIT(float52, MSG_PID_P, &PID_PARAM(Kp,0), 1, 9990);
872
+    // i is typically a small value so allows values below 1
873
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E1);
874
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d_E1);
849 875
     #ifdef PID_ADD_EXTRUSION_RATE
850
-	  MENU_ITEM_EDIT(float3, MSG_PID_C, &PID_PARAM(Kc,0), 1, 9990);
876
+      MENU_ITEM_EDIT(float3, MSG_PID_C, &PID_PARAM(Kc,0), 1, 9990);
851 877
     #endif//PID_ADD_EXTRUSION_RATE
852
-#ifdef PID_PARAMS_PER_EXTRUDER
853
-  #if EXTRUDERS > 1
854
-	  // set up temp variables - undo the default scaling
855
-	  pid_current_extruder = 0;
856
-	  raw_Ki = unscalePID_i(PID_PARAM(Ki,1));
857
-	  raw_Kd = unscalePID_d(PID_PARAM(Kd,1));
858
-	  MENU_ITEM_EDIT(float52, MSG_PID_P " E2", &PID_PARAM(Kp,1), 1, 9990);
859
-	  // i is typically a small value so allows values below 1
860
-	  MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E2", &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
861
-	  MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E2", &raw_Kd, 1, 9990, copy_and_scalePID_d);
862
-      #ifdef PID_ADD_EXTRUSION_RATE
863
-	    MENU_ITEM_EDIT(float3, MSG_PID_C " E2", &PID_PARAM(Kc,1), 1, 9990);
864
-      #endif//PID_ADD_EXTRUSION_RATE
865
-  #endif//EXTRUDERS > 1
866
-  #if EXTRUDERS > 2
867
-	    // set up temp variables - undo the default scaling
868
-	    pid_current_extruder = 0;
869
-	    raw_Ki = unscalePID_i(PID_PARAM(Ki,2));
870
-	    raw_Kd = unscalePID_d(PID_PARAM(Kd,2));
871
-	    MENU_ITEM_EDIT(float52, MSG_PID_P " E3", &PID_PARAM(Kp,2), 1, 9990);
872
-	    // i is typically a small value so allows values below 1
873
-	    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E3", &raw_Ki, 0.01, 9990, copy_and_scalePID_i);
874
-	    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E3", &raw_Kd, 1, 9990, copy_and_scalePID_d);
878
+    #ifdef PID_PARAMS_PER_EXTRUDER
879
+      #if EXTRUDERS > 1
880
+        // set up temp variables - undo the default scaling
881
+        raw_Ki = unscalePID_i(PID_PARAM(Ki,1));
882
+        raw_Kd = unscalePID_d(PID_PARAM(Kd,1));
883
+        MENU_ITEM_EDIT(float52, MSG_PID_P " E2", &PID_PARAM(Kp,1), 1, 9990);
884
+        // i is typically a small value so allows values below 1
885
+        MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E2", &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E2);
886
+        MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E2", &raw_Kd, 1, 9990, copy_and_scalePID_d_E2);
875 887
         #ifdef PID_ADD_EXTRUSION_RATE
876
-	      MENU_ITEM_EDIT(float3, MSG_PID_C " E3", &PID_PARAM(Kc,2), 1, 9990);
888
+          MENU_ITEM_EDIT(float3, MSG_PID_C " E2", &PID_PARAM(Kc,1), 1, 9990);
877 889
         #endif//PID_ADD_EXTRUSION_RATE
878
-  #endif//EXTRUDERS > 2
879
-#endif // PID_PARAMS_PER_EXTRUDER
880
-#endif//PIDTEMP
881
-    MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
882
-    MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
883
-    END_MENU();
890
+
891
+        #if EXTRUDERS > 2
892
+          // set up temp variables - undo the default scaling
893
+          raw_Ki = unscalePID_i(PID_PARAM(Ki,2));
894
+          raw_Kd = unscalePID_d(PID_PARAM(Kd,2));
895
+          MENU_ITEM_EDIT(float52, MSG_PID_P " E3", &PID_PARAM(Kp,2), 1, 9990);
896
+          // i is typically a small value so allows values below 1
897
+          MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E3", &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E3);
898
+          MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E3", &raw_Kd, 1, 9990, copy_and_scalePID_d_E3);
899
+          #ifdef PID_ADD_EXTRUSION_RATE
900
+            MENU_ITEM_EDIT(float3, MSG_PID_C " E3", &PID_PARAM(Kc,2), 1, 9990);
901
+          #endif//PID_ADD_EXTRUSION_RATE
902
+
903
+          #if EXTRUDERS > 3
904
+            // set up temp variables - undo the default scaling
905
+            raw_Ki = unscalePID_i(PID_PARAM(Ki,3));
906
+            raw_Kd = unscalePID_d(PID_PARAM(Kd,3));
907
+            MENU_ITEM_EDIT(float52, MSG_PID_P " E4", &PID_PARAM(Kp,3), 1, 9990);
908
+            // i is typically a small value so allows values below 1
909
+            MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E4", &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E4);
910
+            MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E4", &raw_Kd, 1, 9990, copy_and_scalePID_d_E4);
911
+            #ifdef PID_ADD_EXTRUSION_RATE
912
+              MENU_ITEM_EDIT(float3, MSG_PID_C " E4", &PID_PARAM(Kc,3), 1, 9990);
913
+            #endif//PID_ADD_EXTRUSION_RATE
914
+          #endif//EXTRUDERS > 3
915
+        #endif//EXTRUDERS > 2
916
+      #endif//EXTRUDERS > 1
917
+    #endif //PID_PARAMS_PER_EXTRUDER
918
+  #endif//PIDTEMP
919
+  MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
920
+  MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
921
+  END_MENU();
884 922
 }
885 923
 
886 924
 static void lcd_control_temperature_preheat_pla_settings_menu()
@@ -1785,24 +1823,4 @@ char *ftostr52(const float &x)
1785 1823
   return conv;
1786 1824
 }
1787 1825
 
1788
-// Callback for after editing PID i value
1789
-// grab the PID i value out of the temp variable; scale it; then update the PID driver
1790
-void copy_and_scalePID_i()
1791
-{
1792
-#ifdef PIDTEMP
1793
-  PID_PARAM(Ki, pid_current_extruder) = scalePID_i(raw_Ki);
1794
-  updatePID();
1795
-#endif
1796
-}
1797
-
1798
-// Callback for after editing PID d value
1799
-// grab the PID d value out of the temp variable; scale it; then update the PID driver
1800
-void copy_and_scalePID_d()
1801
-{
1802
-#ifdef PIDTEMP
1803
-	PID_PARAM(Kd, pid_current_extruder) = scalePID_d(raw_Kd);
1804
-  updatePID();
1805
-#endif
1806
-}
1807
-
1808 1826
 #endif //ULTRA_LCD

正在加载...
取消
保存