Browse Source

Reduce, clean up code for mintemp/maxtemp tests

Scott Lahteine 7 years ago
parent
commit
f888597197
1 changed files with 34 additions and 62 deletions
  1. 34
    62
      Marlin/temperature.cpp

+ 34
- 62
Marlin/temperature.cpp View File

@@ -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