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
   #include "tool_change.h"
68
   #include "tool_change.h"
69
 #endif
69
 #endif
70
 
70
 
71
+#if HAS_BUZZER
72
+  #include "../libs/buzzer.h"
73
+#endif
74
+
71
 #if HOTEND_USES_THERMISTOR
75
 #if HOTEND_USES_THERMISTOR
72
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
76
   #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
73
     static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
77
     static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
750
     else SERIAL_ECHOPGM(MSG_HEATER_BED);
754
     else SERIAL_ECHOPGM(MSG_HEATER_BED);
751
     SERIAL_EOL();
755
     SERIAL_EOL();
752
   }
756
   }
757
+
753
   #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
758
   #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
754
     if (!killed) {
759
     if (!killed) {
755
       Running = false;
760
       Running = false;
756
       killed = true;
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
       kill(lcd_msg);
773
       kill(lcd_msg);
758
     }
774
     }
759
     else
775
     else
1175
 #define SCAN_THERMISTOR_TABLE(TBL,LEN) do{                             \
1191
 #define SCAN_THERMISTOR_TABLE(TBL,LEN) do{                             \
1176
   uint8_t l = 0, r = LEN, m;                                           \
1192
   uint8_t l = 0, r = LEN, m;                                           \
1177
   for (;;) {                                                           \
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
     short v00 = pgm_read_word(&TBL[m-1][0]),                           \
1198
     short v00 = pgm_read_word(&TBL[m-1][0]),                           \
1181
           v10 = pgm_read_word(&TBL[m-0][0]);                           \
1199
           v10 = pgm_read_word(&TBL[m-0][0]);                           \
1182
          if (raw < v00) r = m;                                         \
1200
          if (raw < v00) r = m;                                         \
1183
     else if (raw > v10) l = m;                                         \
1201
     else if (raw > v10) l = m;                                         \
1184
     else {                                                             \
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
       return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00);  \
1205
       return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00);  \
1188
     }                                                                  \
1206
     }                                                                  \
1189
   }                                                                    \
1207
   }                                                                    \
1301
       value += user_thermistor[t_index].sh_c_coeff * log_resistance * log_resistance * log_resistance;
1319
       value += user_thermistor[t_index].sh_c_coeff * log_resistance * log_resistance * log_resistance;
1302
     value = 1.0f / value;
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
     //#if (MOTHERBOARD == BOARD_RAMPS_14_EFB)
1322
     //#if (MOTHERBOARD == BOARD_RAMPS_14_EFB)
1311
     //  int32_t clocks = TCNT5 - tcnt5;
1323
     //  int32_t clocks = TCNT5 - tcnt5;
1312
     //  if (clocks >= 0) {
1324
     //  if (clocks >= 0) {
1315
     //  }
1327
     //  }
1316
     //#endif
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
 #endif
1333
 #endif
1321
 
1334
 

Loading…
Cancel
Save