Browse Source

Reduce code with no heated bed

Scott Lahteine 7 years ago
parent
commit
f36f91dfb5
2 changed files with 53 additions and 46 deletions
  1. 48
    44
      Marlin/temperature.cpp
  2. 5
    2
      Marlin/temperature.h

+ 48
- 44
Marlin/temperature.cpp View File

@@ -874,7 +874,7 @@ void Temperature::manage_heater() {
874 874
 
875 875
 // Derived from RepRap FiveD extruder::getTemperature()
876 876
 // For hot end temperature measurement.
877
-float Temperature::analog2temp(int raw, uint8_t e) {
877
+float Temperature::analog2temp(const int raw, const uint8_t e) {
878 878
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
879 879
     if (e > HOTENDS)
880 880
   #else
@@ -915,39 +915,41 @@ float Temperature::analog2temp(int raw, uint8_t e) {
915 915
   return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
916 916
 }
917 917
 
918
-// Derived from RepRap FiveD extruder::getTemperature()
919
-// For bed temperature measurement.
920
-float Temperature::analog2tempBed(const int raw) {
921
-  #if ENABLED(BED_USES_THERMISTOR)
922
-    float celsius = 0;
923
-    byte i;
924
-
925
-    for (i = 1; i < BEDTEMPTABLE_LEN; i++) {
926
-      if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) {
927
-        celsius  = PGM_RD_W(BEDTEMPTABLE[i - 1][1]) +
928
-                   (raw - PGM_RD_W(BEDTEMPTABLE[i - 1][0])) *
929
-                   (float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i - 1][1])) /
930
-                   (float)(PGM_RD_W(BEDTEMPTABLE[i][0]) - PGM_RD_W(BEDTEMPTABLE[i - 1][0]));
931
-        break;
918
+#if HAS_TEMP_BED
919
+  // Derived from RepRap FiveD extruder::getTemperature()
920
+  // For bed temperature measurement.
921
+  float Temperature::analog2tempBed(const int raw) {
922
+    #if ENABLED(BED_USES_THERMISTOR)
923
+      float celsius = 0;
924
+      byte i;
925
+
926
+      for (i = 1; i < BEDTEMPTABLE_LEN; i++) {
927
+        if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) {
928
+          celsius  = PGM_RD_W(BEDTEMPTABLE[i - 1][1]) +
929
+                     (raw - PGM_RD_W(BEDTEMPTABLE[i - 1][0])) *
930
+                     (float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i - 1][1])) /
931
+                     (float)(PGM_RD_W(BEDTEMPTABLE[i][0]) - PGM_RD_W(BEDTEMPTABLE[i - 1][0]));
932
+          break;
933
+        }
932 934
       }
933
-    }
934 935
 
935
-    // Overflow: Set to last value in the table
936
-    if (i == BEDTEMPTABLE_LEN) celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]);
936
+      // Overflow: Set to last value in the table
937
+      if (i == BEDTEMPTABLE_LEN) celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]);
937 938
 
938
-    return celsius;
939
+      return celsius;
939 940
 
940
-  #elif defined(BED_USES_AD595)
941
+    #elif defined(BED_USES_AD595)
941 942
 
942
-    return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
943
+      return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
943 944
 
944
-  #else
945
+    #else
945 946
 
946
-    UNUSED(raw);
947
-    return 0;
947
+      UNUSED(raw);
948
+      return 0;
948 949
 
949
-  #endif
950
-}
950
+    #endif
951
+  }
952
+#endif // HAS_TEMP_BED
951 953
 
952 954
 /**
953 955
  * Get the raw values into the actual temperatures.
@@ -1234,24 +1236,26 @@ void Temperature::init() {
1234 1236
     #endif // HOTENDS > 2
1235 1237
   #endif // HOTENDS > 1
1236 1238
 
1237
-  #ifdef BED_MINTEMP
1238
-    while (analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) {
1239
-      #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
1240
-        bed_minttemp_raw += OVERSAMPLENR;
1241
-      #else
1242
-        bed_minttemp_raw -= OVERSAMPLENR;
1243
-      #endif
1244
-    }
1245
-  #endif // BED_MINTEMP
1246
-  #ifdef BED_MAXTEMP
1247
-    while (analog2tempBed(bed_maxttemp_raw) > BED_MAXTEMP) {
1248
-      #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
1249
-        bed_maxttemp_raw -= OVERSAMPLENR;
1250
-      #else
1251
-        bed_maxttemp_raw += OVERSAMPLENR;
1252
-      #endif
1253
-    }
1254
-  #endif // BED_MAXTEMP
1239
+  #if HAS_TEMP_BED
1240
+    #ifdef BED_MINTEMP
1241
+      while (analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) {
1242
+        #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
1243
+          bed_minttemp_raw += OVERSAMPLENR;
1244
+        #else
1245
+          bed_minttemp_raw -= OVERSAMPLENR;
1246
+        #endif
1247
+      }
1248
+    #endif // BED_MINTEMP
1249
+    #ifdef BED_MAXTEMP
1250
+      while (analog2tempBed(bed_maxttemp_raw) > BED_MAXTEMP) {
1251
+        #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
1252
+          bed_maxttemp_raw -= OVERSAMPLENR;
1253
+        #else
1254
+          bed_maxttemp_raw += OVERSAMPLENR;
1255
+        #endif
1256
+      }
1257
+    #endif // BED_MAXTEMP
1258
+  #endif //HAS_TEMP_BED
1255 1259
 
1256 1260
   #if ENABLED(PROBING_HEATERS_OFF)
1257 1261
     paused = false;

+ 5
- 2
Marlin/temperature.h View File

@@ -293,8 +293,11 @@ class Temperature {
293 293
     /**
294 294
      * Static (class) methods
295 295
      */
296
-    static float analog2temp(int raw, uint8_t e);
297
-    static float analog2tempBed(int raw);
296
+    static float analog2temp(const int raw, const uint8_t e);
297
+
298
+    #if HAS_TEMP_BED
299
+      static float analog2tempBed(const int raw);
300
+    #endif
298 301
 
299 302
     /**
300 303
      * Called from the Temperature ISR

Loading…
Cancel
Save