Browse Source

Limit user thermistor to 999, fix thermistor table macro (#14080)

doggyfan 6 years ago
parent
commit
594f6b14be
1 changed files with 24 additions and 11 deletions
  1. 24
    11
      Marlin/src/module/temperature.cpp

+ 24
- 11
Marlin/src/module/temperature.cpp View File

@@ -68,6 +68,10 @@
68 68
   #include "tool_change.h"
69 69
 #endif
70 70
 
71
+#if HAS_BUZZER
72
+  #include "../libs/buzzer.h"
73
+#endif
74
+
71 75
 #if HOTEND_USES_THERMISTOR
72 76
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
73 77
     static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
@@ -750,10 +754,22 @@ void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P
750 754
     else SERIAL_ECHOPGM(MSG_HEATER_BED);
751 755
     SERIAL_EOL();
752 756
   }
757
+
753 758
   #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
754 759
     if (!killed) {
755 760
       Running = false;
756 761
       killed = true;
762
+
763
+      disable_all_heaters();
764
+
765
+      #if HAS_BUZZER && PIN_EXISTS(BEEPER)
766
+        for (uint8_t i = 20; i--;) {
767
+          WRITE(BEEPER_PIN, HIGH); delay(25);
768
+          WRITE(BEEPER_PIN, LOW); delay(80);
769
+        }
770
+        WRITE(BEEPER_PIN, HIGH);
771
+      #endif
772
+
757 773
       kill(lcd_msg);
758 774
     }
759 775
     else
@@ -1175,15 +1191,17 @@ void Temperature::manage_heater() {
1175 1191
 #define SCAN_THERMISTOR_TABLE(TBL,LEN) do{                             \
1176 1192
   uint8_t l = 0, r = LEN, m;                                           \
1177 1193
   for (;;) {                                                           \
1178
-    m = (l + r) >> 1;                                                  \
1179
-    if (m == l || m == r) return (short)pgm_read_word(&TBL[LEN-1][1]); \
1194
+    m = l + r;                                                         \
1195
+    if (!m) return short(pgm_read_word(&TBL[0][1]));                   \
1196
+    m >>= 1;                                                           \
1197
+    if (m == l || m == r) return short(pgm_read_word(&TBL[LEN-1][1])); \
1180 1198
     short v00 = pgm_read_word(&TBL[m-1][0]),                           \
1181 1199
           v10 = pgm_read_word(&TBL[m-0][0]);                           \
1182 1200
          if (raw < v00) r = m;                                         \
1183 1201
     else if (raw > v10) l = m;                                         \
1184 1202
     else {                                                             \
1185
-      const short v01 = (short)pgm_read_word(&TBL[m-1][1]),            \
1186
-                  v11 = (short)pgm_read_word(&TBL[m-0][1]);            \
1203
+      const short v01 = short(pgm_read_word(&TBL[m-1][1])),            \
1204
+                  v11 = short(pgm_read_word(&TBL[m-0][1]));            \
1187 1205
       return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00);  \
1188 1206
     }                                                                  \
1189 1207
   }                                                                    \
@@ -1301,12 +1319,6 @@ void Temperature::manage_heater() {
1301 1319
       value += user_thermistor[t_index].sh_c_coeff * log_resistance * log_resistance * log_resistance;
1302 1320
     value = 1.0f / value;
1303 1321
 
1304
-    // Convert to degrees C
1305
-    float deg_c = value + THERMISTOR_ABS_ZERO_C;
1306
-
1307
-    // Test only
1308
-    //deg_c = constrain(deg_c, 6, 100);
1309
-
1310 1322
     //#if (MOTHERBOARD == BOARD_RAMPS_14_EFB)
1311 1323
     //  int32_t clocks = TCNT5 - tcnt5;
1312 1324
     //  if (clocks >= 0) {
@@ -1315,7 +1327,8 @@ void Temperature::manage_heater() {
1315 1327
     //  }
1316 1328
     //#endif
1317 1329
 
1318
-    return deg_c;
1330
+    // Return degrees C (up to 999, as the LCD only displays 3 digits)
1331
+    return MIN(value + THERMISTOR_ABS_ZERO_C, 999);
1319 1332
   }
1320 1333
 #endif
1321 1334
 

Loading…
Cancel
Save