Browse Source

Tweaks to temperature code

Scott Lahteine 7 years ago
parent
commit
7769a22064
3 changed files with 22 additions and 22 deletions
  1. 12
    12
      Marlin/temperature.cpp
  2. 4
    4
      Marlin/temperature.h
  3. 6
    6
      Marlin/thermistortable_20.h

+ 12
- 12
Marlin/temperature.cpp View File

421
           bedKp = workKp; \
421
           bedKp = workKp; \
422
           bedKi = scalePID_i(workKi); \
422
           bedKi = scalePID_i(workKi); \
423
           bedKd = scalePID_d(workKd); \
423
           bedKd = scalePID_d(workKd); \
424
-          updatePID(); } while(0)
424
+          updatePID(); }while(0)
425
 
425
 
426
         #define _SET_EXTRUDER_PID() do { \
426
         #define _SET_EXTRUDER_PID() do { \
427
           PID_PARAM(Kp, hotend) = workKp; \
427
           PID_PARAM(Kp, hotend) = workKp; \
428
           PID_PARAM(Ki, hotend) = scalePID_i(workKi); \
428
           PID_PARAM(Ki, hotend) = scalePID_i(workKi); \
429
           PID_PARAM(Kd, hotend) = scalePID_d(workKd); \
429
           PID_PARAM(Kd, hotend) = scalePID_d(workKd); \
430
-          updatePID(); } while(0)
430
+          updatePID(); }while(0)
431
 
431
 
432
         // Use the result? (As with "M303 U1")
432
         // Use the result? (As with "M303 U1")
433
         if (set_result) {
433
         if (set_result) {
505
 //
505
 //
506
 // Temperature Error Handlers
506
 // Temperature Error Handlers
507
 //
507
 //
508
-void Temperature::_temp_error(int e, const char* serial_msg, const char* lcd_msg) {
508
+void Temperature::_temp_error(const int8_t e, const char * const serial_msg, const char * const lcd_msg) {
509
   static bool killed = false;
509
   static bool killed = false;
510
   if (IsRunning()) {
510
   if (IsRunning()) {
511
     SERIAL_ERROR_START();
511
     SERIAL_ERROR_START();
524
   #endif
524
   #endif
525
 }
525
 }
526
 
526
 
527
-void Temperature::max_temp_error(int8_t e) {
527
+void Temperature::max_temp_error(const int8_t e) {
528
   #if HAS_TEMP_BED
528
   #if HAS_TEMP_BED
529
     _temp_error(e, PSTR(MSG_T_MAXTEMP), e >= 0 ? PSTR(MSG_ERR_MAXTEMP) : PSTR(MSG_ERR_MAXTEMP_BED));
529
     _temp_error(e, PSTR(MSG_T_MAXTEMP), e >= 0 ? PSTR(MSG_ERR_MAXTEMP) : PSTR(MSG_ERR_MAXTEMP_BED));
530
   #else
530
   #else
534
     #endif
534
     #endif
535
   #endif
535
   #endif
536
 }
536
 }
537
-void Temperature::min_temp_error(int8_t e) {
537
+void Temperature::min_temp_error(const int8_t e) {
538
   #if HAS_TEMP_BED
538
   #if HAS_TEMP_BED
539
     _temp_error(e, PSTR(MSG_T_MINTEMP), e >= 0 ? PSTR(MSG_ERR_MINTEMP) : PSTR(MSG_ERR_MINTEMP_BED));
539
     _temp_error(e, PSTR(MSG_T_MINTEMP), e >= 0 ? PSTR(MSG_ERR_MINTEMP) : PSTR(MSG_ERR_MINTEMP_BED));
540
   #else
540
   #else
545
   #endif
545
   #endif
546
 }
546
 }
547
 
547
 
548
-float Temperature::get_pid_output(int e) {
548
+float Temperature::get_pid_output(const int8_t e) {
549
   #if HOTENDS == 1
549
   #if HOTENDS == 1
550
     UNUSED(e);
550
     UNUSED(e);
551
     #define _HOTEND_TEST     true
551
     #define _HOTEND_TEST     true
890
 
890
 
891
 // Derived from RepRap FiveD extruder::getTemperature()
891
 // Derived from RepRap FiveD extruder::getTemperature()
892
 // For bed temperature measurement.
892
 // For bed temperature measurement.
893
-float Temperature::analog2tempBed(int raw) {
893
+float Temperature::analog2tempBed(const int raw) {
894
   #if ENABLED(BED_USES_THERMISTOR)
894
   #if ENABLED(BED_USES_THERMISTOR)
895
     float celsius = 0;
895
     float celsius = 0;
896
     byte i;
896
     byte i;
1148
 
1148
 
1149
   #define TEMP_MIN_ROUTINE(NR) \
1149
   #define TEMP_MIN_ROUTINE(NR) \
1150
     minttemp[NR] = HEATER_ ##NR## _MINTEMP; \
1150
     minttemp[NR] = HEATER_ ##NR## _MINTEMP; \
1151
-    while(analog2temp(minttemp_raw[NR], NR) < HEATER_ ##NR## _MINTEMP) { \
1151
+    while (analog2temp(minttemp_raw[NR], NR) < HEATER_ ##NR## _MINTEMP) { \
1152
       if (HEATER_ ##NR## _RAW_LO_TEMP < HEATER_ ##NR## _RAW_HI_TEMP) \
1152
       if (HEATER_ ##NR## _RAW_LO_TEMP < HEATER_ ##NR## _RAW_HI_TEMP) \
1153
         minttemp_raw[NR] += OVERSAMPLENR; \
1153
         minttemp_raw[NR] += OVERSAMPLENR; \
1154
       else \
1154
       else \
1156
     }
1156
     }
1157
   #define TEMP_MAX_ROUTINE(NR) \
1157
   #define TEMP_MAX_ROUTINE(NR) \
1158
     maxttemp[NR] = HEATER_ ##NR## _MAXTEMP; \
1158
     maxttemp[NR] = HEATER_ ##NR## _MAXTEMP; \
1159
-    while(analog2temp(maxttemp_raw[NR], NR) > HEATER_ ##NR## _MAXTEMP) { \
1159
+    while (analog2temp(maxttemp_raw[NR], NR) > HEATER_ ##NR## _MAXTEMP) { \
1160
       if (HEATER_ ##NR## _RAW_LO_TEMP < HEATER_ ##NR## _RAW_HI_TEMP) \
1160
       if (HEATER_ ##NR## _RAW_LO_TEMP < HEATER_ ##NR## _RAW_HI_TEMP) \
1161
         maxttemp_raw[NR] -= OVERSAMPLENR; \
1161
         maxttemp_raw[NR] -= OVERSAMPLENR; \
1162
       else \
1162
       else \
1203
   #endif // HOTENDS > 1
1203
   #endif // HOTENDS > 1
1204
 
1204
 
1205
   #ifdef BED_MINTEMP
1205
   #ifdef BED_MINTEMP
1206
-    while(analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) {
1206
+    while (analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) {
1207
       #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
1207
       #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
1208
         bed_minttemp_raw += OVERSAMPLENR;
1208
         bed_minttemp_raw += OVERSAMPLENR;
1209
       #else
1209
       #else
1292
         SERIAL_EOL();
1292
         SERIAL_EOL();
1293
     */
1293
     */
1294
 
1294
 
1295
-    int heater_index = heater_id >= 0 ? heater_id : HOTENDS;
1295
+    const int heater_index = heater_id >= 0 ? heater_id : HOTENDS;
1296
 
1296
 
1297
     #if HEATER_IDLE_HANDLER
1297
     #if HEATER_IDLE_HANDLER
1298
       // If the heater idle timeout expires, restart
1298
       // If the heater idle timeout expires, restart
1922
     case SensorsReady: {
1922
     case SensorsReady: {
1923
       // All sensors have been read. Stay in this state for a few
1923
       // All sensors have been read. Stay in this state for a few
1924
       // ISRs to save on calls to temp update/checking code below.
1924
       // ISRs to save on calls to temp update/checking code below.
1925
-      constexpr int extra_loops = MIN_ADC_ISR_LOOPS - (int)SensorsReady;
1925
+      constexpr int8_t extra_loops = MIN_ADC_ISR_LOOPS - (int8_t)SensorsReady;
1926
       static uint8_t delay_count = 0;
1926
       static uint8_t delay_count = 0;
1927
       if (extra_loops > 0) {
1927
       if (extra_loops > 0) {
1928
         if (delay_count == 0) delay_count = extra_loops;   // Init this delay
1928
         if (delay_count == 0) delay_count = extra_loops;   // Init this delay

+ 4
- 4
Marlin/temperature.h View File

535
 
535
 
536
     static void checkExtruderAutoFans();
536
     static void checkExtruderAutoFans();
537
 
537
 
538
-    static float get_pid_output(int e);
538
+    static float get_pid_output(const int8_t e);
539
 
539
 
540
     #if ENABLED(PIDTEMPBED)
540
     #if ENABLED(PIDTEMPBED)
541
       static float get_pid_output_bed();
541
       static float get_pid_output_bed();
542
     #endif
542
     #endif
543
 
543
 
544
-    static void _temp_error(int e, const char* serial_msg, const char* lcd_msg);
545
-    static void min_temp_error(int8_t e);
546
-    static void max_temp_error(int8_t e);
544
+    static void _temp_error(const int8_t e, const char * const serial_msg, const char * const lcd_msg);
545
+    static void min_temp_error(const int8_t e);
546
+    static void max_temp_error(const int8_t e);
547
 
547
 
548
     #if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
548
     #if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
549
 
549
 

+ 6
- 6
Marlin/thermistortable_20.h View File

23
 // PT100 with INA826 amp on Ultimaker v2.0 electronics
23
 // PT100 with INA826 amp on Ultimaker v2.0 electronics
24
 // The PT100 in the Ultimaker v2.0 electronics has a high sample value for a high temperature.
24
 // The PT100 in the Ultimaker v2.0 electronics has a high sample value for a high temperature.
25
 // This does not match the normal thermistor behaviour so we need to set the following defines
25
 // This does not match the normal thermistor behaviour so we need to set the following defines
26
-#if (THERMISTORHEATER_0 == 20)
26
+#if THERMISTORHEATER_0 == 20
27
   #define HEATER_0_RAW_HI_TEMP 16383
27
   #define HEATER_0_RAW_HI_TEMP 16383
28
   #define HEATER_0_RAW_LO_TEMP 0
28
   #define HEATER_0_RAW_LO_TEMP 0
29
 #endif
29
 #endif
30
-#if (THERMISTORHEATER_1 == 20)
30
+#if THERMISTORHEATER_1 == 20
31
   #define HEATER_1_RAW_HI_TEMP 16383
31
   #define HEATER_1_RAW_HI_TEMP 16383
32
   #define HEATER_1_RAW_LO_TEMP 0
32
   #define HEATER_1_RAW_LO_TEMP 0
33
 #endif
33
 #endif
34
-#if (THERMISTORHEATER_2 == 20)
34
+#if THERMISTORHEATER_2 == 20
35
   #define HEATER_2_RAW_HI_TEMP 16383
35
   #define HEATER_2_RAW_HI_TEMP 16383
36
   #define HEATER_2_RAW_LO_TEMP 0
36
   #define HEATER_2_RAW_LO_TEMP 0
37
 #endif
37
 #endif
38
-#if (THERMISTORHEATER_3 == 20)
38
+#if THERMISTORHEATER_3 == 20
39
   #define HEATER_3_RAW_HI_TEMP 16383
39
   #define HEATER_3_RAW_HI_TEMP 16383
40
   #define HEATER_3_RAW_LO_TEMP 0
40
   #define HEATER_3_RAW_LO_TEMP 0
41
 #endif
41
 #endif
42
-#if (THERMISTORHEATER_4 == 20)
42
+#if THERMISTORHEATER_4 == 20
43
   #define HEATER_4_RAW_HI_TEMP 16383
43
   #define HEATER_4_RAW_HI_TEMP 16383
44
   #define HEATER_4_RAW_LO_TEMP 0
44
   #define HEATER_4_RAW_LO_TEMP 0
45
 #endif
45
 #endif
46
-#if (THERMISTORBED == 20)
46
+#if THERMISTORBED == 20
47
   #define HEATER_BED_RAW_HI_TEMP 16383
47
   #define HEATER_BED_RAW_HI_TEMP 16383
48
   #define HEATER_BED_RAW_LO_TEMP 0
48
   #define HEATER_BED_RAW_LO_TEMP 0
49
 #endif
49
 #endif

Loading…
Cancel
Save