Browse Source

Merge pull request #5060 from thinkyhead/rc_fix_ugly_code

Reduce, clean up MINTEMP / MAXTEMP test code
Scott Lahteine 7 years ago
parent
commit
cfb47929ca

+ 1
- 1
Marlin/Marlin_main.cpp View File

@@ -3145,7 +3145,7 @@ inline void gcode_G4() {
3145 3145
       if (DEBUGGING(LEVELING)) DEBUG_POS(">>> home_delta", current_position);
3146 3146
     #endif
3147 3147
     // Init the current position of all carriages to 0,0,0
3148
-    memset(current_position, 0, sizeof(current_position));
3148
+    ZERO(current_position);
3149 3149
     sync_plan_position();
3150 3150
 
3151 3151
     // Move all carriages together linearly until an endstop is hit.

+ 1
- 1
Marlin/SdBaseFile.cpp View File

@@ -674,7 +674,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile,
674 674
       index = 0;
675 675
     }
676 676
     // initialize as empty file
677
-    memset(p, 0, sizeof(dir_t));
677
+    ZERO(p);
678 678
     memcpy(p->name, dname, 11);
679 679
 
680 680
     // set timestamps

+ 1
- 1
Marlin/cardreader.cpp View File

@@ -36,7 +36,7 @@ CardReader::CardReader() {
36 36
   sdpos = 0;
37 37
   workDirDepth = 0;
38 38
   file_subcall_ctr = 0;
39
-  memset(workDirParents, 0, sizeof(workDirParents));
39
+  ZERO(workDirParents);
40 40
 
41 41
   autostart_stilltocheck = true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
42 42
   autostart_index = 0;

+ 0
- 1
Marlin/configuration_store.cpp View File

@@ -40,7 +40,6 @@
40 40
 
41 41
 // Change EEPROM version if these are changed:
42 42
 #define EEPROM_OFFSET 100
43
-#define MAX_EXTRUDERS 4
44 43
 
45 44
 /**
46 45
  * V24 EEPROM Layout:

+ 1
- 0
Marlin/macros.h View File

@@ -78,6 +78,7 @@
78 78
 #define NUMERIC(a) ((a) >= '0' && '9' >= (a))
79 79
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
80 80
 #define COUNT(a) (sizeof(a)/sizeof(*a))
81
+#define ZERO(a) memset(a,0,sizeof(a))
81 82
 
82 83
 // Macros for initializing arrays
83 84
 #define ARRAY_6(v1, v2, v3, v4, v5, v6, args...) { v1, v2, v3, v4, v5, v6 }

+ 1
- 1
Marlin/mesh_bed_leveling.cpp View File

@@ -31,7 +31,7 @@
31 31
   void mesh_bed_leveling::reset() {
32 32
     status = MBL_STATUS_NONE;
33 33
     z_offset = 0;
34
-    memset(z_values, 0, sizeof(z_values));
34
+    ZERO(z_values);
35 35
   }
36 36
 
37 37
 #endif  // MESH_BED_LEVELING

+ 4
- 0
Marlin/pins.h View File

@@ -275,6 +275,10 @@
275 275
   #define SUICIDE_PIN -1
276 276
 #endif
277 277
 
278
+#ifndef MAX_EXTRUDERS
279
+  #define MAX_EXTRUDERS 4
280
+#endif
281
+
278 282
 // Marlin needs to account for pins that equal -1
279 283
 #define marlinAnalogInputToDigitalPin(p) ((p) == -1 ? -1 : analogInputToDigitalPin(p))
280 284
 

+ 3
- 3
Marlin/planner.cpp View File

@@ -137,8 +137,8 @@ Planner::Planner() { init(); }
137 137
 
138 138
 void Planner::init() {
139 139
   block_buffer_head = block_buffer_tail = 0;
140
-  memset(position, 0, sizeof(position));
141
-  memset(previous_speed, 0, sizeof(previous_speed));
140
+  ZERO(position);
141
+  ZERO(previous_speed);
142 142
   previous_nominal_speed = 0.0;
143 143
   #if ABL_PLANAR
144 144
     bed_level_matrix.set_to_identity();
@@ -1266,7 +1266,7 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
1266 1266
   stepper.set_position(na, nb, nc, ne);
1267 1267
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1268 1268
 
1269
-  memset(previous_speed, 0, sizeof(previous_speed));
1269
+  ZERO(previous_speed);
1270 1270
 }
1271 1271
 
1272 1272
 void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {

+ 35
- 63
Marlin/temperature.cpp View File

@@ -151,7 +151,7 @@ volatile bool Temperature::temp_meas_ready = false;
151 151
   millis_t Temperature::next_bed_check_ms;
152 152
 #endif
153 153
 
154
-unsigned long Temperature::raw_temp_value[4] = { 0 };
154
+unsigned long Temperature::raw_temp_value[MAX_EXTRUDERS] = { 0 };
155 155
 unsigned long Temperature::raw_temp_bed_value = 0;
156 156
 
157 157
 // Init min and max temp with extreme values to prevent false errors during startup
@@ -1758,6 +1758,9 @@ void Temperature::isr() {
1758 1758
   } // switch(temp_state)
1759 1759
 
1760 1760
   if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256)  = 164ms.
1761
+
1762
+    temp_count = 0;
1763
+
1761 1764
     // Update the raw values if they've been read. Else we could be updating them during reading.
1762 1765
     if (!temp_meas_ready) set_current_temp_raw();
1763 1766
 
@@ -1766,85 +1769,54 @@ void Temperature::isr() {
1766 1769
       current_raw_filwidth = raw_filwidth_value >> 10;  // Divide to get to 0-16384 range since we used 1/128 IIR filter approach
1767 1770
     #endif
1768 1771
 
1769
-    temp_count = 0;
1770
-    for (int i = 0; i < 4; i++) raw_temp_value[i] = 0;
1772
+    ZERO(raw_temp_value);
1771 1773
     raw_temp_bed_value = 0;
1772 1774
 
1773
-    #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
1774
-      #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1775
-        #define GE0 <=
1775
+    int constexpr temp_dir[] = {
1776
+      #if ENABLED(HEATER_0_USES_MAX6675)
1777
+         0
1778
+      #elif HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1779
+        -1
1776 1780
       #else
1777
-        #define GE0 >=
1781
+         1
1778 1782
       #endif
1779
-      if (current_temperature_raw[0] GE0 maxttemp_raw[0]) max_temp_error(0);
1780
-      if (minttemp_raw[0] GE0 current_temperature_raw[0] && !is_preheating(0) && target_temperature[0] > 0.0f) {
1781
-        #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1782
-          if (++consecutive_low_temperature_error[0] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
1783
+      #if HAS_TEMP_1 && HOTENDS > 1
1784
+        #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
1785
+          , -1
1786
+        #else
1787
+          ,  1
1783 1788
         #endif
1784
-            min_temp_error(0);
1785
-      }
1786
-      #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1787
-        else
1788
-          consecutive_low_temperature_error[0] = 0;
1789 1789
       #endif
1790
-    #endif
1791
-
1792
-    #if HAS_TEMP_1 && HOTENDS > 1
1793
-      #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
1794
-        #define GE1 <=
1795
-      #else
1796
-        #define GE1 >=
1797
-      #endif
1798
-      if (current_temperature_raw[1] GE1 maxttemp_raw[1]) max_temp_error(1);
1799
-      if (minttemp_raw[1] GE1 current_temperature_raw[1] && !is_preheating(1) && target_temperature[1] > 0.0f) {
1800
-        #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1801
-          if (++consecutive_low_temperature_error[1] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
1790
+      #if HAS_TEMP_2 && HOTENDS > 2
1791
+        #if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
1792
+          , -1
1793
+        #else
1794
+          ,  1
1802 1795
         #endif
1803
-          min_temp_error(1);
1804
-      }
1805
-      #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1806
-        else
1807
-          consecutive_low_temperature_error[1] = 0;
1808
-      #endif
1809
-    #endif // TEMP_SENSOR_1
1810
-
1811
-    #if HAS_TEMP_2 && HOTENDS > 2
1812
-      #if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
1813
-        #define GE2 <=
1814
-      #else
1815
-        #define GE2 >=
1816 1796
       #endif
1817
-      if (current_temperature_raw[2] GE2 maxttemp_raw[2]) max_temp_error(2);
1818
-      if (minttemp_raw[2] GE2 current_temperature_raw[2] && !is_preheating(2) && target_temperature[2] > 0.0f) {
1819
-        #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1820
-          if (++consecutive_low_temperature_error[2] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
1797
+      #if HAS_TEMP_3 && HOTENDS > 3
1798
+        #if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP
1799
+          , -1
1800
+        #else
1801
+          ,  1
1821 1802
         #endif
1822
-          min_temp_error(2);
1823
-      }
1824
-      #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1825
-        else
1826
-          consecutive_low_temperature_error[2] = 0;
1827 1803
       #endif
1828
-    #endif // TEMP_SENSOR_2
1804
+    };
1829 1805
 
1830
-    #if HAS_TEMP_3 && HOTENDS > 3
1831
-      #if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP
1832
-        #define GE3 <=
1833
-      #else
1834
-        #define GE3 >=
1835
-      #endif
1836
-      if (current_temperature_raw[3] GE3 maxttemp_raw[3]) max_temp_error(3);
1837
-      if (minttemp_raw[3] GE3 current_temperature_raw[3] && !is_preheating(3) && target_temperature[3] > 0.0f) {
1806
+    for (uint8_t e = 0; e < COUNT(temp_dir); e++) {
1807
+      const int tdir = temp_dir[e], rawtemp = current_temperature_raw[e] * tdir;
1808
+      if (rawtemp > maxttemp_raw[e] * tdir) max_temp_error(e);
1809
+      if (rawtemp < minttemp_raw[e] * tdir && !is_preheating(e) && target_temperature[e] > 0.0f) {
1838 1810
         #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1839
-          if (++consecutive_low_temperature_error[3] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
1811
+          if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
1840 1812
         #endif
1841
-          min_temp_error(3);
1813
+            min_temp_error(e);
1842 1814
       }
1843 1815
       #ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
1844 1816
         else
1845
-          consecutive_low_temperature_error[3] = 0;
1817
+          consecutive_low_temperature_error[e] = 0;
1846 1818
       #endif
1847
-    #endif // TEMP_SENSOR_3
1819
+    }
1848 1820
 
1849 1821
     #if HAS_TEMP_BED
1850 1822
       #if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP

Loading…
Cancel
Save