Explorar el Código

Merge pull request #1519 from thinkyhead/fix_recent_issues

Fix implementation of PID menu items
Scott Lahteine hace 10 años
padre
commit
4fcd4b444e
Se han modificado 1 ficheros con 110 adiciones y 88 borrados
  1. 110
    88
      Marlin/ultralcd.cpp

+ 110
- 88
Marlin/ultralcd.cpp Ver fichero

@@ -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,124 @@ static void lcd_control_menu()
811 805
     END_MENU();
812 806
 }
813 807
 
808
+#ifdef PIDTEMP
809
+
810
+  // Helpers for editing PID Ki & Kd values
811
+  // grab the PID value out of the temp variable; scale it; then update the PID driver
812
+  void copy_and_scalePID_i(int e) {
813
+    PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
814
+    updatePID();
815
+  }
816
+  void copy_and_scalePID_d(int e) {
817
+    PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
818
+    updatePID();
819
+  }
820
+  void copy_and_scalePID_i_E1() { copy_and_scalePID_i(0); }
821
+  void copy_and_scalePID_d_E1() { copy_and_scalePID_d(0); }
822
+  #ifdef PID_PARAMS_PER_EXTRUDER
823
+    #if EXTRUDERS > 1
824
+      void copy_and_scalePID_i_E2() { copy_and_scalePID_i(1); }
825
+      void copy_and_scalePID_d_E2() { copy_and_scalePID_d(1); }
826
+      #if EXTRUDERS > 2
827
+        void copy_and_scalePID_i_E3() { copy_and_scalePID_i(2); }
828
+        void copy_and_scalePID_d_E3() { copy_and_scalePID_d(2); }
829
+        #if EXTRUDERS > 3
830
+          void copy_and_scalePID_i_E4() { copy_and_scalePID_i(3); }
831
+          void copy_and_scalePID_d_E5() { copy_and_scalePID_d(3); }
832
+        #endif //EXTRUDERS > 3
833
+      #endif //EXTRUDERS > 2
834
+    #endif //EXTRUDERS > 1
835
+  #endif //PID_PARAMS_PER_EXTRUDER
836
+
837
+#endif //PIDTEMP
838
+
814 839
 static void lcd_control_temperature_menu()
815 840
 {
816 841
   START_MENU();
817 842
   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
843
+  #if TEMP_SENSOR_0 != 0
844
+    MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 15);
845
+  #endif
846
+  #if EXTRUDERS > 1
847
+    #if TEMP_SENSOR_1 != 0
848
+      MENU_ITEM_EDIT(int3, MSG_NOZZLE " 2", &target_temperature[1], 0, HEATER_1_MAXTEMP - 15);
849
+    #endif
850
+    #if EXTRUDERS > 2
851
+      #if TEMP_SENSOR_2 != 0
852
+        MENU_ITEM_EDIT(int3, MSG_NOZZLE " 3", &target_temperature[2], 0, HEATER_2_MAXTEMP - 15);
853
+      #endif
854
+      #if EXTRUDERS > 2
855
+        #if TEMP_SENSOR_3 != 0
856
+          MENU_ITEM_EDIT(int3, MSG_NOZZLE " 4", &target_temperature[3], 0, HEATER_3_MAXTEMP - 15);
857
+        #endif
858
+      #endif
859
+    #endif
860
+  #endif
861
+  #if TEMP_SENSOR_BED != 0
862
+    MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 15);
863
+  #endif
833 864
   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);
865
+  #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
866
+    MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
867
+    MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
868
+    MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
869
+    MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
870
+  #endif
871
+  #ifdef PIDTEMP
872
+    // set up temp variables - undo the default scaling
873
+    raw_Ki = unscalePID_i(PID_PARAM(Ki,0));
874
+    raw_Kd = unscalePID_d(PID_PARAM(Kd,0));
875
+    MENU_ITEM_EDIT(float52, MSG_PID_P, &PID_PARAM(Kp,0), 1, 9990);
876
+    // i is typically a small value so allows values below 1
877
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E1);
878
+    MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D, &raw_Kd, 1, 9990, copy_and_scalePID_d_E1);
849 879
     #ifdef PID_ADD_EXTRUSION_RATE
850
-	  MENU_ITEM_EDIT(float3, MSG_PID_C, &PID_PARAM(Kc,0), 1, 9990);
880
+      MENU_ITEM_EDIT(float3, MSG_PID_C, &PID_PARAM(Kc,0), 1, 9990);
851 881
     #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);
882
+    #ifdef PID_PARAMS_PER_EXTRUDER
883
+      #if EXTRUDERS > 1
884
+        // set up temp variables - undo the default scaling
885
+        raw_Ki = unscalePID_i(PID_PARAM(Ki,1));
886
+        raw_Kd = unscalePID_d(PID_PARAM(Kd,1));
887
+        MENU_ITEM_EDIT(float52, MSG_PID_P " E2", &PID_PARAM(Kp,1), 1, 9990);
888
+        // i is typically a small value so allows values below 1
889
+        MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E2", &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E2);
890
+        MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E2", &raw_Kd, 1, 9990, copy_and_scalePID_d_E2);
875 891
         #ifdef PID_ADD_EXTRUSION_RATE
876
-	      MENU_ITEM_EDIT(float3, MSG_PID_C " E3", &PID_PARAM(Kc,2), 1, 9990);
892
+          MENU_ITEM_EDIT(float3, MSG_PID_C " E2", &PID_PARAM(Kc,1), 1, 9990);
877 893
         #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();
894
+
895
+        #if EXTRUDERS > 2
896
+          // set up temp variables - undo the default scaling
897
+          raw_Ki = unscalePID_i(PID_PARAM(Ki,2));
898
+          raw_Kd = unscalePID_d(PID_PARAM(Kd,2));
899
+          MENU_ITEM_EDIT(float52, MSG_PID_P " E3", &PID_PARAM(Kp,2), 1, 9990);
900
+          // i is typically a small value so allows values below 1
901
+          MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E3", &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E3);
902
+          MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E3", &raw_Kd, 1, 9990, copy_and_scalePID_d_E3);
903
+          #ifdef PID_ADD_EXTRUSION_RATE
904
+            MENU_ITEM_EDIT(float3, MSG_PID_C " E3", &PID_PARAM(Kc,2), 1, 9990);
905
+          #endif//PID_ADD_EXTRUSION_RATE
906
+
907
+          #if EXTRUDERS > 3
908
+            // set up temp variables - undo the default scaling
909
+            raw_Ki = unscalePID_i(PID_PARAM(Ki,3));
910
+            raw_Kd = unscalePID_d(PID_PARAM(Kd,3));
911
+            MENU_ITEM_EDIT(float52, MSG_PID_P " E4", &PID_PARAM(Kp,3), 1, 9990);
912
+            // i is typically a small value so allows values below 1
913
+            MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I " E4", &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E4);
914
+            MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D " E4", &raw_Kd, 1, 9990, copy_and_scalePID_d_E4);
915
+            #ifdef PID_ADD_EXTRUSION_RATE
916
+              MENU_ITEM_EDIT(float3, MSG_PID_C " E4", &PID_PARAM(Kc,3), 1, 9990);
917
+            #endif//PID_ADD_EXTRUSION_RATE
918
+          #endif//EXTRUDERS > 3
919
+        #endif//EXTRUDERS > 2
920
+      #endif//EXTRUDERS > 1
921
+    #endif //PID_PARAMS_PER_EXTRUDER
922
+  #endif//PIDTEMP
923
+  MENU_ITEM(submenu, MSG_PREHEAT_PLA_SETTINGS, lcd_control_temperature_preheat_pla_settings_menu);
924
+  MENU_ITEM(submenu, MSG_PREHEAT_ABS_SETTINGS, lcd_control_temperature_preheat_abs_settings_menu);
925
+  END_MENU();
884 926
 }
885 927
 
886 928
 static void lcd_control_temperature_preheat_pla_settings_menu()
@@ -1805,24 +1847,4 @@ char *ftostr52(const float &x)
1805 1847
   return conv;
1806 1848
 }
1807 1849
 
1808
-// Callback for after editing PID i value
1809
-// grab the PID i value out of the temp variable; scale it; then update the PID driver
1810
-void copy_and_scalePID_i()
1811
-{
1812
-#ifdef PIDTEMP
1813
-  PID_PARAM(Ki, pid_current_extruder) = scalePID_i(raw_Ki);
1814
-  updatePID();
1815
-#endif
1816
-}
1817
-
1818
-// Callback for after editing PID d value
1819
-// grab the PID d value out of the temp variable; scale it; then update the PID driver
1820
-void copy_and_scalePID_d()
1821
-{
1822
-#ifdef PIDTEMP
1823
-	PID_PARAM(Kd, pid_current_extruder) = scalePID_d(raw_Kd);
1824
-  updatePID();
1825
-#endif
1826
-}
1827
-
1828 1850
 #endif //ULTRA_LCD

Loading…
Cancelar
Guardar