Browse Source

Make LCD preheat vars an array to reduce code size

Scott Lahteine 8 years ago
parent
commit
1a2310c494
4 changed files with 70 additions and 119 deletions
  1. 14
    34
      Marlin/Marlin_main.cpp
  2. 26
    37
      Marlin/configuration_store.cpp
  3. 29
    42
      Marlin/ultralcd.cpp
  4. 1
    6
      Marlin/ultralcd.h

+ 14
- 34
Marlin/Marlin_main.cpp View File

@@ -5519,46 +5519,26 @@ inline void gcode_M140() {
5519 5519
    */
5520 5520
   inline void gcode_M145() {
5521 5521
     int8_t material = code_seen('S') ? (int8_t)code_value_int() : 0;
5522
-    if (material < 0 || material > 1) {
5522
+    if (material < 0 || material >= COUNT(lcd_preheat_hotend_temp)) {
5523 5523
       SERIAL_ERROR_START;
5524 5524
       SERIAL_ERRORLNPGM(MSG_ERR_MATERIAL_INDEX);
5525 5525
     }
5526 5526
     else {
5527 5527
       int v;
5528
-      switch (material) {
5529
-        case 0:
5530
-          if (code_seen('H')) {
5531
-            v = code_value_int();
5532
-            preheatHotendTemp1 = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
5533
-          }
5534
-          if (code_seen('F')) {
5535
-            v = code_value_int();
5536
-            preheatFanSpeed1 = constrain(v, 0, 255);
5537
-          }
5538
-          #if TEMP_SENSOR_BED != 0
5539
-            if (code_seen('B')) {
5540
-              v = code_value_int();
5541
-              preheatBedTemp1 = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
5542
-            }
5543
-          #endif
5544
-          break;
5545
-        case 1:
5546
-          if (code_seen('H')) {
5547
-            v = code_value_int();
5548
-            preheatHotendTemp2 = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
5549
-          }
5550
-          if (code_seen('F')) {
5551
-            v = code_value_int();
5552
-            preheatFanSpeed2 = constrain(v, 0, 255);
5553
-          }
5554
-          #if TEMP_SENSOR_BED != 0
5555
-            if (code_seen('B')) {
5556
-              v = code_value_int();
5557
-              preheatBedTemp2 = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
5558
-            }
5559
-          #endif
5560
-          break;
5528
+      if (code_seen('H')) {
5529
+        v = code_value_int();
5530
+        lcd_preheat_hotend_temp[material] = constrain(v, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - 15);
5561 5531
       }
5532
+      if (code_seen('F')) {
5533
+        v = code_value_int();
5534
+        lcd_preheat_fan_speed[material] = constrain(v, 0, 255);
5535
+      }
5536
+      #if TEMP_SENSOR_BED != 0
5537
+        if (code_seen('B')) {
5538
+          v = code_value_int();
5539
+          lcd_preheat_bed_temp[material] = constrain(v, BED_MINTEMP, BED_MAXTEMP - 15);
5540
+        }
5541
+      #endif
5562 5542
     }
5563 5543
   }
5564 5544
 

+ 26
- 37
Marlin/configuration_store.cpp View File

@@ -86,12 +86,9 @@
86 86
  *  301  M666 Z    z_endstop_adj (float)
87 87
  *
88 88
  * ULTIPANEL:
89
- *  305  M145 S0 H preheatHotendTemp1 (int)
90
- *  307  M145 S0 B preheatBedTemp1 (int)
91
- *  309  M145 S0 F preheatFanSpeed1 (int)
92
- *  311  M145 S1 H preheatHotendTemp2 (int)
93
- *  313  M145 S1 B preheatBedTemp2 (int)
94
- *  315  M145 S1 F preheatFanSpeed2 (int)
89
+ *  305  M145 S0 H lcd_preheat_hotend_temp (int x2)
90
+ *  309  M145 S0 B lcd_preheat_bed_temp (int x2)
91
+ *  313  M145 S0 F lcd_preheat_fan_speed (int x2)
95 92
  *
96 93
  * PIDTEMP:
97 94
  *  317  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
@@ -277,16 +274,14 @@ void Config_Postprocess() {
277 274
     #endif
278 275
 
279 276
     #if DISABLED(ULTIPANEL)
280
-      int preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND, preheatBedTemp1 = PREHEAT_1_TEMP_BED, preheatFanSpeed1 = PREHEAT_1_FAN_SPEED,
281
-          preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND, preheatBedTemp2 = PREHEAT_2_TEMP_BED, preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
277
+      const int lcd_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
278
+                lcd_preheat_bed_temp[2] = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED },
279
+                lcd_preheat_fan_speed[2] = { PREHEAT_1_FAN_SPEED, PREHEAT_2_FAN_SPEED };
282 280
     #endif // !ULTIPANEL
283 281
 
284
-    EEPROM_WRITE(preheatHotendTemp1);
285
-    EEPROM_WRITE(preheatBedTemp1);
286
-    EEPROM_WRITE(preheatFanSpeed1);
287
-    EEPROM_WRITE(preheatHotendTemp2);
288
-    EEPROM_WRITE(preheatBedTemp2);
289
-    EEPROM_WRITE(preheatFanSpeed2);
282
+    EEPROM_WRITE(lcd_preheat_hotend_temp);
283
+    EEPROM_WRITE(lcd_preheat_bed_temp);
284
+    EEPROM_WRITE(lcd_preheat_fan_speed);
290 285
 
291 286
     for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
292 287
 
@@ -465,16 +460,12 @@ void Config_Postprocess() {
465 460
       #endif
466 461
 
467 462
       #if DISABLED(ULTIPANEL)
468
-        int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
469
-            preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2;
463
+        int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
470 464
       #endif
471 465
 
472
-      EEPROM_READ(preheatHotendTemp1);
473
-      EEPROM_READ(preheatBedTemp1);
474
-      EEPROM_READ(preheatFanSpeed1);
475
-      EEPROM_READ(preheatHotendTemp2);
476
-      EEPROM_READ(preheatBedTemp2);
477
-      EEPROM_READ(preheatFanSpeed2);
466
+      EEPROM_READ(lcd_preheat_hotend_temp);
467
+      EEPROM_READ(lcd_preheat_bed_temp);
468
+      EEPROM_READ(lcd_preheat_fan_speed);
478 469
 
479 470
       #if ENABLED(PIDTEMP)
480 471
         for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
@@ -639,12 +630,12 @@ void Config_ResetDefault() {
639 630
   #endif
640 631
 
641 632
   #if ENABLED(ULTIPANEL)
642
-    preheatHotendTemp1 = PREHEAT_1_TEMP_HOTEND;
643
-    preheatBedTemp1 = PREHEAT_1_TEMP_BED;
644
-    preheatFanSpeed1 = PREHEAT_1_FAN_SPEED;
645
-    preheatHotendTemp2 = PREHEAT_2_TEMP_HOTEND;
646
-    preheatBedTemp2 = PREHEAT_2_TEMP_BED;
647
-    preheatFanSpeed2 = PREHEAT_2_FAN_SPEED;
633
+    lcd_preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
634
+    lcd_preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
635
+    lcd_preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
636
+    lcd_preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
637
+    lcd_preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
638
+    lcd_preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
648 639
   #endif
649 640
 
650 641
   #if HAS_LCD_CONTRAST
@@ -863,15 +854,13 @@ void Config_ResetDefault() {
863 854
         SERIAL_ECHOLNPGM("Material heatup parameters:");
864 855
         CONFIG_ECHO_START;
865 856
       }
866
-      SERIAL_ECHOPAIR("  M145 S0 H", preheatHotendTemp1);
867
-      SERIAL_ECHOPAIR(" B", preheatBedTemp1);
868
-      SERIAL_ECHOPAIR(" F", preheatFanSpeed1);
869
-      SERIAL_EOL;
870
-      CONFIG_ECHO_START;
871
-      SERIAL_ECHOPAIR("  M145 S1 H", preheatHotendTemp2);
872
-      SERIAL_ECHOPAIR(" B", preheatBedTemp2);
873
-      SERIAL_ECHOPAIR(" F", preheatFanSpeed2);
874
-      SERIAL_EOL;
857
+      for (uint8_t i = 0; i < COUNT(lcd_preheat_hotend_temp); i++) {
858
+        SERIAL_ECHOPAIR("  M145 S", (int)i);
859
+        SERIAL_ECHOPAIR(" H", lcd_preheat_hotend_temp[i]);
860
+        SERIAL_ECHOPAIR(" B", lcd_preheat_bed_temp[i]);
861
+        SERIAL_ECHOPAIR(" F", lcd_preheat_fan_speed[i]);
862
+        SERIAL_EOL;
863
+      }
875 864
     #endif // ULTIPANEL
876 865
 
877 866
     #if HAS_PID_HEATING

+ 29
- 42
Marlin/ultralcd.cpp View File

@@ -43,8 +43,7 @@
43 43
   #include "duration_t.h"
44 44
 #endif
45 45
 
46
-int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
47
-    preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2;
46
+int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
48 47
 
49 48
 #if ENABLED(FILAMENT_LCD_DISPLAY)
50 49
   millis_t previous_lcd_status_ms = 0;
@@ -887,29 +886,29 @@ void kill_screen(const char* lcd_msg) {
887 886
   }
888 887
 
889 888
   #if TEMP_SENSOR_0 != 0
890
-    void lcd_preheat_pla0() { _lcd_preheat(0, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
891
-    void lcd_preheat_abs0() { _lcd_preheat(0, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
889
+    void lcd_preheat_pla0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
890
+    void lcd_preheat_abs0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
892 891
   #endif
893 892
 
894 893
   #if HOTENDS > 1
895
-    void lcd_preheat_pla1() { _lcd_preheat(1, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
896
-    void lcd_preheat_abs1() { _lcd_preheat(1, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
894
+    void lcd_preheat_pla1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
895
+    void lcd_preheat_abs1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
897 896
     #if HOTENDS > 2
898
-      void lcd_preheat_pla2() { _lcd_preheat(2, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
899
-      void lcd_preheat_abs2() { _lcd_preheat(2, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
897
+      void lcd_preheat_pla2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
898
+      void lcd_preheat_abs2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
900 899
       #if HOTENDS > 3
901
-        void lcd_preheat_pla3() { _lcd_preheat(3, preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1); }
902
-        void lcd_preheat_abs3() { _lcd_preheat(3, preheatHotendTemp2, preheatBedTemp2, preheatFanSpeed2); }
900
+        void lcd_preheat_pla3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
901
+        void lcd_preheat_abs3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
903 902
       #endif
904 903
     #endif
905 904
 
906 905
     void lcd_preheat_pla0123() {
907 906
       #if HOTENDS > 1
908
-        thermalManager.setTargetHotend(preheatHotendTemp1, 1);
907
+        thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 1);
909 908
         #if HOTENDS > 2
910
-          thermalManager.setTargetHotend(preheatHotendTemp1, 2);
909
+          thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 2);
911 910
           #if HOTENDS > 3
912
-            thermalManager.setTargetHotend(preheatHotendTemp1, 3);
911
+            thermalManager.setTargetHotend(lcd_preheat_hotend_temp[0], 3);
913 912
           #endif
914 913
         #endif
915 914
       #endif
@@ -917,11 +916,11 @@ void kill_screen(const char* lcd_msg) {
917 916
     }
918 917
     void lcd_preheat_abs0123() {
919 918
       #if HOTENDS > 1
920
-        thermalManager.setTargetHotend(preheatHotendTemp2, 1);
919
+        thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 1);
921 920
         #if HOTENDS > 2
922
-          thermalManager.setTargetHotend(preheatHotendTemp2, 2);
921
+          thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 2);
923 922
           #if HOTENDS > 3
924
-            thermalManager.setTargetHotend(preheatHotendTemp2, 3);
923
+            thermalManager.setTargetHotend(lcd_preheat_hotend_temp[1], 3);
925 924
           #endif
926 925
         #endif
927 926
       #endif
@@ -931,8 +930,8 @@ void kill_screen(const char* lcd_msg) {
931 930
   #endif // HOTENDS > 1
932 931
 
933 932
   #if TEMP_SENSOR_BED != 0
934
-    void lcd_preheat_pla_bedonly() { _lcd_preheat(0, 0, preheatBedTemp1, preheatFanSpeed1); }
935
-    void lcd_preheat_abs_bedonly() { _lcd_preheat(0, 0, preheatBedTemp2, preheatFanSpeed2); }
933
+    void lcd_preheat_pla_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
934
+    void lcd_preheat_abs_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
936 935
   #endif
937 936
 
938 937
   #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_BED != 0)
@@ -1766,20 +1765,15 @@ void kill_screen(const char* lcd_msg) {
1766 1765
     END_MENU();
1767 1766
   }
1768 1767
 
1769
-  /**
1770
-   *
1771
-   * "Temperature" > "Preheat PLA conf" submenu
1772
-   *
1773
-   */
1774
-  static void lcd_control_temperature_preheat_pla_settings_menu() {
1768
+  static void _lcd_control_temperature_preheat_settings_menu(uint8_t material) {
1775 1769
     START_MENU();
1776 1770
     MENU_BACK(MSG_TEMPERATURE);
1777
-    MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &preheatFanSpeed1, 0, 255);
1771
+    MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
1778 1772
     #if TEMP_SENSOR_0 != 0
1779
-      MENU_ITEM_EDIT(int3, MSG_NOZZLE, &preheatHotendTemp1, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
1773
+      MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
1780 1774
     #endif
1781 1775
     #if TEMP_SENSOR_BED != 0
1782
-      MENU_ITEM_EDIT(int3, MSG_BED, &preheatBedTemp1, BED_MINTEMP, BED_MAXTEMP - 15);
1776
+      MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
1783 1777
     #endif
1784 1778
     #if ENABLED(EEPROM_SETTINGS)
1785 1779
       MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
@@ -1789,24 +1783,17 @@ void kill_screen(const char* lcd_msg) {
1789 1783
 
1790 1784
   /**
1791 1785
    *
1786
+   * "Temperature" > "Preheat PLA conf" submenu
1787
+   *
1788
+   */
1789
+  static void lcd_control_temperature_preheat_pla_settings_menu() { _lcd_control_temperature_preheat_settings_menu(0); }
1790
+
1791
+  /**
1792
+   *
1792 1793
    * "Temperature" > "Preheat ABS conf" submenu
1793 1794
    *
1794 1795
    */
1795
-  static void lcd_control_temperature_preheat_abs_settings_menu() {
1796
-    START_MENU();
1797
-    MENU_BACK(MSG_TEMPERATURE);
1798
-    MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &preheatFanSpeed2, 0, 255);
1799
-    #if TEMP_SENSOR_0 != 0
1800
-      MENU_ITEM_EDIT(int3, MSG_NOZZLE, &preheatHotendTemp2, HEATER_0_MINTEMP, HEATER_0_MAXTEMP - 15);
1801
-    #endif
1802
-    #if TEMP_SENSOR_BED != 0
1803
-      MENU_ITEM_EDIT(int3, MSG_BED, &preheatBedTemp2, BED_MINTEMP, BED_MAXTEMP - 15);
1804
-    #endif
1805
-    #if ENABLED(EEPROM_SETTINGS)
1806
-      MENU_ITEM(function, MSG_STORE_EPROM, Config_StoreSettings);
1807
-    #endif
1808
-    END_MENU();
1809
-  }
1796
+  static void lcd_control_temperature_preheat_abs_settings_menu() { _lcd_control_temperature_preheat_settings_menu(1); }
1810 1797
 
1811 1798
   static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
1812 1799
   static void _planner_refresh_positioning() { planner.refresh_positioning(); }

+ 1
- 6
Marlin/ultralcd.h View File

@@ -30,12 +30,7 @@
30 30
   #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
31 31
   #define BUTTON_PRESSED(BN) !READ(BTN_## BN)
32 32
 
33
-  extern int preheatHotendTemp1,
34
-             preheatBedTemp1,
35
-             preheatFanSpeed1,
36
-             preheatHotendTemp2,
37
-             preheatBedTemp2,
38
-             preheatFanSpeed2;
33
+  extern int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
39 34
 
40 35
   int lcd_strlen(const char* s);
41 36
   int lcd_strlen_P(const char* s);

Loading…
Cancel
Save