Browse Source

Update temperature types

Scott Lahteine 4 years ago
parent
commit
72e3d2492f

+ 11
- 9
Marlin/src/core/types.h View File

77
 // For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100
77
 // For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100
78
 //
78
 //
79
 typedef int16_t celsius_t;
79
 typedef int16_t celsius_t;
80
+typedef float celsius_float_t;
80
 
81
 
81
 //
82
 //
82
 // On AVR pointers are only 2 bytes so use 'const float &' for 'const float'
83
 // On AVR pointers are only 2 bytes so use 'const float &' for 'const float'
87
   typedef const float const_float_t;
88
   typedef const float const_float_t;
88
 #endif
89
 #endif
89
 typedef const_float_t const_feedRate_t;
90
 typedef const_float_t const_feedRate_t;
91
+typedef const_float_t const_celsius_float_t;
90
 
92
 
91
 // Conversion macros
93
 // Conversion macros
92
-#define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f)
93
-#define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f)
94
+#define MMM_TO_MMS(MM_M) feedRate_t(static_cast<float>(MM_M) / 60.0f)
95
+#define MMS_TO_MMM(MM_S) (static_cast<float>(MM_S) * 60.0f)
94
 
96
 
95
 //
97
 //
96
 // Coordinates structures for XY, XYZ, XYZE...
98
 // Coordinates structures for XY, XYZ, XYZE...
97
 //
99
 //
98
 
100
 
99
 // Helpers
101
 // Helpers
100
-#define _RECIP(N) ((N) ? 1.0f / float(N) : 0.0f)
102
+#define _RECIP(N) ((N) ? 1.0f / static_cast<float>(N) : 0.0f)
101
 #define _ABS(N) ((N) < 0 ? -(N) : (N))
103
 #define _ABS(N) ((N) < 0 ? -(N) : (N))
102
 #define _LS(N)  (N = (T)(uint32_t(N) << v))
104
 #define _LS(N)  (N = (T)(uint32_t(N) << v))
103
 #define _RS(N)  (N = (T)(uint32_t(N) >> v))
105
 #define _RS(N)  (N = (T)(uint32_t(N) >> v))
214
   FI XYval<int32_t>   asLong()                    const { return { int32_t(x), int32_t(y) }; }
216
   FI XYval<int32_t>   asLong()                    const { return { int32_t(x), int32_t(y) }; }
215
   FI XYval<int32_t>   ROUNDL()                          { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
217
   FI XYval<int32_t>   ROUNDL()                          { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
216
   FI XYval<int32_t>   ROUNDL()                    const { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
218
   FI XYval<int32_t>   ROUNDL()                    const { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; }
217
-  FI XYval<float>    asFloat()                          { return {   float(x),   float(y) }; }
218
-  FI XYval<float>    asFloat()                    const { return {   float(x),   float(y) }; }
219
+  FI XYval<float>    asFloat()                          { return { static_cast<float>(x), static_cast<float>(y) }; }
220
+  FI XYval<float>    asFloat()                    const { return { static_cast<float>(x), static_cast<float>(y) }; }
219
   FI XYval<float> reciprocal()                    const { return {  _RECIP(x),  _RECIP(y) }; }
221
   FI XYval<float> reciprocal()                    const { return {  _RECIP(x),  _RECIP(y) }; }
220
   FI XYval<float>  asLogical()                    const { XYval<float> o = asFloat(); toLogical(o); return o; }
222
   FI XYval<float>  asLogical()                    const { XYval<float> o = asFloat(); toLogical(o); return o; }
221
   FI XYval<float>   asNative()                    const { XYval<float> o = asFloat(); toNative(o);  return o; }
223
   FI XYval<float>   asNative()                    const { XYval<float> o = asFloat(); toNative(o);  return o; }
325
   FI XYZval<int32_t>  asLong()                   const { return { int32_t(x), int32_t(y), int32_t(z) }; }
327
   FI XYZval<int32_t>  asLong()                   const { return { int32_t(x), int32_t(y), int32_t(z) }; }
326
   FI XYZval<int32_t>  ROUNDL()                         { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
328
   FI XYZval<int32_t>  ROUNDL()                         { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
327
   FI XYZval<int32_t>  ROUNDL()                   const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
329
   FI XYZval<int32_t>  ROUNDL()                   const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)) }; }
328
-  FI XYZval<float>   asFloat()                         { return {   float(x),   float(y),   float(z) }; }
329
-  FI XYZval<float>   asFloat()                   const { return {   float(x),   float(y),   float(z) }; }
330
+  FI XYZval<float>   asFloat()                         { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z) }; }
331
+  FI XYZval<float>   asFloat()                   const { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z) }; }
330
   FI XYZval<float> reciprocal()                  const { return {  _RECIP(x),  _RECIP(y),  _RECIP(z) }; }
332
   FI XYZval<float> reciprocal()                  const { return {  _RECIP(x),  _RECIP(y),  _RECIP(z) }; }
331
   FI XYZval<float> asLogical()                   const { XYZval<float> o = asFloat(); toLogical(o); return o; }
333
   FI XYZval<float> asLogical()                   const { XYZval<float> o = asFloat(); toLogical(o); return o; }
332
   FI XYZval<float>  asNative()                   const { XYZval<float> o = asFloat(); toNative(o);  return o; }
334
   FI XYZval<float>  asNative()                   const { XYZval<float> o = asFloat(); toNative(o);  return o; }
436
   FI XYZEval<int32_t>  asLong()                         const { return { int32_t(x), int32_t(y), int32_t(z), int32_t(e) }; }
438
   FI XYZEval<int32_t>  asLong()                         const { return { int32_t(x), int32_t(y), int32_t(z), int32_t(e) }; }
437
   FI XYZEval<int32_t>  ROUNDL()                               { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
439
   FI XYZEval<int32_t>  ROUNDL()                               { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
438
   FI XYZEval<int32_t>  ROUNDL()                         const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
440
   FI XYZEval<int32_t>  ROUNDL()                         const { return { int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(e)) }; }
439
-  FI XYZEval<float>   asFloat()                               { return {   float(x),   float(y),   float(z),   float(e) }; }
440
-  FI XYZEval<float>   asFloat()                         const { return {   float(x),   float(y),   float(z),   float(e) }; }
441
+  FI XYZEval<float>   asFloat()                               { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(e) }; }
442
+  FI XYZEval<float>   asFloat()                         const { return { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(e) }; }
441
   FI XYZEval<float> reciprocal()                        const { return {  _RECIP(x),  _RECIP(y),  _RECIP(z),  _RECIP(e) }; }
443
   FI XYZEval<float> reciprocal()                        const { return {  _RECIP(x),  _RECIP(y),  _RECIP(z),  _RECIP(e) }; }
442
   FI XYZEval<float> asLogical()                         const { XYZEval<float> o = asFloat(); toLogical(o); return o; }
444
   FI XYZEval<float> asLogical()                         const { XYZEval<float> o = asFloat(); toLogical(o); return o; }
443
   FI XYZEval<float>  asNative()                         const { XYZEval<float> o = asFloat(); toNative(o);  return o; }
445
   FI XYZEval<float>  asNative()                         const { XYZEval<float> o = asFloat(); toNative(o);  return o; }

+ 3
- 3
Marlin/src/feature/probe_temp_comp.cpp View File

52
 
52
 
53
 constexpr xyz_pos_t ProbeTempComp::park_point;
53
 constexpr xyz_pos_t ProbeTempComp::park_point;
54
 constexpr xy_pos_t ProbeTempComp::measure_point;
54
 constexpr xy_pos_t ProbeTempComp::measure_point;
55
-constexpr int ProbeTempComp::probe_calib_bed_temp;
55
+constexpr celsius_t ProbeTempComp::probe_calib_bed_temp;
56
 
56
 
57
 uint8_t ProbeTempComp::calib_idx; // = 0
57
 uint8_t ProbeTempComp::calib_idx; // = 0
58
 float ProbeTempComp::init_measurement; // = 0.0
58
 float ProbeTempComp::init_measurement; // = 0.0
126
       SERIAL_ECHOPGM("Applying linear extrapolation");
126
       SERIAL_ECHOPGM("Applying linear extrapolation");
127
       calib_idx--;
127
       calib_idx--;
128
       for (; calib_idx < measurements; ++calib_idx) {
128
       for (; calib_idx < measurements; ++calib_idx) {
129
-        const float temp = start_temp + float(calib_idx) * res_temp;
129
+        const celsius_float_t temp = start_temp + float(calib_idx) * res_temp;
130
         data[calib_idx] = static_cast<int16_t>(k * temp + d);
130
         data[calib_idx] = static_cast<int16_t>(k * temp + d);
131
       }
131
       }
132
     }
132
     }
174
     return xy_float_t({start_temp + i*res_temp, static_cast<float>(data[i])});
174
     return xy_float_t({start_temp + i*res_temp, static_cast<float>(data[i])});
175
   };
175
   };
176
 
176
 
177
-  auto linear_interp = [](float x, xy_float_t p1, xy_float_t p2) {
177
+  auto linear_interp = [](const_float_t x, xy_float_t p1, xy_float_t p2) {
178
     return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y;
178
     return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y;
179
   };
179
   };
180
 
180
 

+ 2
- 2
Marlin/src/feature/probe_temp_comp.h View File

100
     static constexpr xy_pos_t measure_point    = PTC_PROBE_POS;     // Coordinates to probe
100
     static constexpr xy_pos_t measure_point    = PTC_PROBE_POS;     // Coordinates to probe
101
                             //measure_point    = { 12.0f, 7.3f };   // Coordinates for the MK52 magnetic heatbed
101
                             //measure_point    = { 12.0f, 7.3f };   // Coordinates for the MK52 magnetic heatbed
102
 
102
 
103
-    static constexpr int  probe_calib_bed_temp = BED_MAX_TARGET,  // Bed temperature while calibrating probe
104
-                          bed_calib_probe_temp = BTC_PROBE_TEMP;  // Probe temperature while calibrating bed
103
+    static constexpr celsius_t probe_calib_bed_temp = BED_MAX_TARGET,  // Bed temperature while calibrating probe
104
+                               bed_calib_probe_temp = BTC_PROBE_TEMP;  // Probe temperature while calibrating bed
105
 
105
 
106
     static int16_t *sensor_z_offsets[TSI_COUNT],
106
     static int16_t *sensor_z_offsets[TSI_COUNT],
107
                    z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm)
107
                    z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm)

+ 6
- 6
Marlin/src/gcode/calibrate/G76_M192_M871.cpp View File

110
     return false;
110
     return false;
111
   };
111
   };
112
 
112
 
113
-  auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) {
113
+  auto g76_probe = [](const TempSensorID sid, celsius_t &targ, const xy_pos_t &nozpos) {
114
     do_z_clearance(5.0); // Raise nozzle before probing
114
     do_z_clearance(5.0); // Raise nozzle before probing
115
     const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
115
     const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false);  // verbose=0, probe_relative=false
116
     if (isnan(measured_z))
116
     if (isnan(measured_z))
170
   // Report temperatures every second and handle heating timeouts
170
   // Report temperatures every second and handle heating timeouts
171
   millis_t next_temp_report = millis() + 1000;
171
   millis_t next_temp_report = millis() + 1000;
172
 
172
 
173
-  auto report_targets = [&](const uint16_t tb, const uint16_t tp) {
173
+  auto report_targets = [&](const celsius_t tb, const celsius_t tp) {
174
     SERIAL_ECHOLNPAIR("Target Bed:", tb, " Probe:", tp);
174
     SERIAL_ECHOLNPAIR("Target Bed:", tb, " Probe:", tp);
175
   };
175
   };
176
 
176
 
177
   if (do_bed_cal) {
177
   if (do_bed_cal) {
178
 
178
 
179
-    uint16_t target_bed = cali_info_init[TSI_BED].start_temp,
180
-             target_probe = temp_comp.bed_calib_probe_temp;
179
+    celsius_t target_bed = cali_info_init[TSI_BED].start_temp,
180
+            target_probe = temp_comp.bed_calib_probe_temp;
181
 
181
 
182
     say_waiting_for(); SERIAL_ECHOLNPGM(" cooling.");
182
     say_waiting_for(); SERIAL_ECHOLNPGM(" cooling.");
183
     while (thermalManager.degBed() > target_bed || thermalManager.degProbe() > target_probe)
183
     while (thermalManager.degBed() > target_bed || thermalManager.degProbe() > target_probe)
236
     do_blocking_move_to(parkpos);
236
     do_blocking_move_to(parkpos);
237
 
237
 
238
     // Initialize temperatures
238
     // Initialize temperatures
239
-    const uint16_t target_bed = temp_comp.probe_calib_bed_temp;
239
+    const celsius_t target_bed = temp_comp.probe_calib_bed_temp;
240
     thermalManager.setTargetBed(target_bed);
240
     thermalManager.setTargetBed(target_bed);
241
 
241
 
242
-    uint16_t target_probe = cali_info_init[TSI_PROBE].start_temp;
242
+    celsius_t target_probe = cali_info_init[TSI_PROBE].start_temp;
243
 
243
 
244
     report_targets(target_bed, target_probe);
244
     report_targets(target_bed, target_probe);
245
 
245
 

+ 2
- 2
Marlin/src/gcode/temp/M303.cpp View File

57
   #endif
57
   #endif
58
 
58
 
59
   const heater_id_t hid = (heater_id_t)parser.intval('E');
59
   const heater_id_t hid = (heater_id_t)parser.intval('E');
60
-  int16_t default_temp;
60
+  celsius_t default_temp;
61
   switch (hid) {
61
   switch (hid) {
62
     #if ENABLED(PIDTEMP)
62
     #if ENABLED(PIDTEMP)
63
       case 0 ... HOTENDS - 1: default_temp = PREHEAT_1_TEMP_HOTEND; break;
63
       case 0 ... HOTENDS - 1: default_temp = PREHEAT_1_TEMP_HOTEND; break;
74
       return;
74
       return;
75
   }
75
   }
76
 
76
 
77
-  const int16_t temp = parser.celsiusval('S', default_temp);
77
+  const celsius_t temp = parser.celsiusval('S', default_temp);
78
   const int c = parser.intval('C', 5);
78
   const int c = parser.intval('C', 5);
79
   const bool u = parser.boolval('U');
79
   const bool u = parser.boolval('U');
80
 
80
 

+ 1
- 2
Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp View File

373
 
373
 
374
 void ChironTFT::CheckHeaters() {
374
 void ChironTFT::CheckHeaters() {
375
   uint8_t faultDuration = 0;
375
   uint8_t faultDuration = 0;
376
-  float temp = 0;
377
 
376
 
378
   // if the hotend temp is abnormal, confirm state before signalling panel
377
   // if the hotend temp is abnormal, confirm state before signalling panel
379
-  temp = getActualTemp_celsius(E0);
378
+  celsius_float_t temp = getActualTemp_celsius(E0);
380
   while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) {
379
   while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) {
381
     faultDuration++;
380
     faultDuration++;
382
     if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) {
381
     if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) {

+ 10
- 8
Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp View File

534
   #endif
534
   #endif
535
 }
535
 }
536
 
536
 
537
+#define ROUND(val) int((val)+0.5f)
538
+
537
 void AnycubicTFTClass::GetCommandFromTFT() {
539
 void AnycubicTFTClass::GetCommandFromTFT() {
538
   char *starpos = nullptr;
540
   char *starpos = nullptr;
539
   while (LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
541
   while (LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
560
 
562
 
561
         switch (a_command) {
563
         switch (a_command) {
562
           case 0: { // A0 GET HOTEND TEMP
564
           case 0: { // A0 GET HOTEND TEMP
563
-            const float hotendActualTemp = getActualTemp_celsius(E0);
564
-            SEND_PGM_VAL("A0V ", int(hotendActualTemp + 0.5));
565
+            const celsius_float_t hotendActualTemp = getActualTemp_celsius(E0);
566
+            SEND_PGM_VAL("A0V ", ROUND(hotendActualTemp));
565
           }
567
           }
566
           break;
568
           break;
567
 
569
 
568
           case 1: { // A1  GET HOTEND TARGET TEMP
570
           case 1: { // A1  GET HOTEND TARGET TEMP
569
-            const float hotendTargetTemp = getTargetTemp_celsius(E0);
570
-            SEND_PGM_VAL("A1V ", int(hotendTargetTemp + 0.5));
571
+            const celsius_float_t hotendTargetTemp = getTargetTemp_celsius(E0);
572
+            SEND_PGM_VAL("A1V ", ROUND(hotendTargetTemp));
571
           }
573
           }
572
           break;
574
           break;
573
 
575
 
574
           case 2: { // A2 GET HOTBED TEMP
576
           case 2: { // A2 GET HOTBED TEMP
575
-            const float heatedBedActualTemp = getActualTemp_celsius(BED);
576
-            SEND_PGM_VAL("A2V ", int(heatedBedActualTemp + 0.5));
577
+            const celsius_float_t heatedBedActualTemp = getActualTemp_celsius(BED);
578
+            SEND_PGM_VAL("A2V ", ROUND(heatedBedActualTemp));
577
           }
579
           }
578
           break;
580
           break;
579
 
581
 
580
           case 3: { // A3 GET HOTBED TARGET TEMP
582
           case 3: { // A3 GET HOTBED TARGET TEMP
581
-            const float heatedBedTargetTemp = getTargetTemp_celsius(BED);
582
-            SEND_PGM_VAL("A3V ", int(heatedBedTargetTemp + 0.5));
583
+            const celsius_float_t heatedBedTargetTemp = getTargetTemp_celsius(BED);
584
+            SEND_PGM_VAL("A3V ", ROUND(heatedBedTargetTemp));
583
           } break;
585
           } break;
584
 
586
 
585
           case 4: { // A4 GET FAN SPEED
587
           case 4: { // A4 GET FAN SPEED

+ 4
- 4
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.cpp View File

33
 /**
33
 /**
34
  * Formats a temperature string (e.g. "100°C")
34
  * Formats a temperature string (e.g. "100°C")
35
  */
35
  */
36
-void format_temp(char *str, float t1) {
36
+void format_temp(char *str, const_celsius_float_t t1) {
37
   sprintf_P(str, PSTR("%3d" S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C));
37
   sprintf_P(str, PSTR("%3d" S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C));
38
 }
38
 }
39
 
39
 
40
 /**
40
 /**
41
  * Formats a temperature string for an idle heater (e.g. "100 °C / idle")
41
  * Formats a temperature string for an idle heater (e.g. "100 °C / idle")
42
  */
42
  */
43
-void format_temp_and_idle(char *str, float t1) {
43
+void format_temp_and_idle(char *str, const_celsius_float_t t1) {
44
   sprintf_P(str, PSTR("%3d" S_FMT " / " S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C), GET_TEXT(MSG_IDLE));
44
   sprintf_P(str, PSTR("%3d" S_FMT " / " S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C), GET_TEXT(MSG_IDLE));
45
 }
45
 }
46
 
46
 
47
 /**
47
 /**
48
  * Formats a temperature string for an active heater (e.g. "100 / 200°C")
48
  * Formats a temperature string for an active heater (e.g. "100 / 200°C")
49
  */
49
  */
50
-void format_temp_and_temp(char *str, float t1, float t2) {
50
+void format_temp_and_temp(char *str, const_celsius_float_t t1, const_celsius_float_t t2) {
51
   sprintf_P(str, PSTR("%3d / %3d" S_FMT), ROUND(t1), ROUND(t2), GET_TEXT(MSG_UNITS_C));
51
   sprintf_P(str, PSTR("%3d / %3d" S_FMT), ROUND(t1), ROUND(t2), GET_TEXT(MSG_UNITS_C));
52
 }
52
 }
53
 
53
 
54
 /**
54
 /**
55
  * Formats a temperature string for a material (e.g. "100°C (PLA)")
55
  * Formats a temperature string for a material (e.g. "100°C (PLA)")
56
  */
56
  */
57
-void format_temp_and_material(char *str, float t1, const char *material) {
57
+void format_temp_and_material(char *str, const_celsius_float_t t1, const char *material) {
58
   sprintf_P(str, PSTR("%3d" S_FMT " (" S_FMT ")"), ROUND(t1), GET_TEXT(MSG_UNITS_C), material);
58
   sprintf_P(str, PSTR("%3d" S_FMT " (" S_FMT ")"), ROUND(t1), GET_TEXT(MSG_UNITS_C), material);
59
 }
59
 }
60
 
60
 

+ 4
- 4
Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/string_format.h View File

21
 
21
 
22
 #pragma once
22
 #pragma once
23
 
23
 
24
-void format_temp(char *str, float t1);
25
-void format_temp_and_idle(char *str, float t1);
26
-void format_temp_and_temp(char *str, float t1, float t2);
27
-void format_temp_and_material(char *str, float t1, const char *material);
24
+void format_temp(char *str, const_celsius_float_t t1);
25
+void format_temp_and_idle(char *str, const_celsius_float_t t1);
26
+void format_temp_and_temp(char *str, const_celsius_float_t t1, const_celsius_float_t t2);
27
+void format_temp_and_material(char *str, const_celsius_float_t t1, const char *material);
28
 void format_position(char *str, float p, uint8_t decimals = 1);
28
 void format_position(char *str, float p, uint8_t decimals = 1);
29
 void format_position(char *str, float x, float y, float z);
29
 void format_position(char *str, float x, float y, float z);

+ 2
- 2
Marlin/src/lcd/extui/lib/nextion/nextion_tft.cpp View File

595
 void NextionTFT::UpdateOnChange() {
595
 void NextionTFT::UpdateOnChange() {
596
   const millis_t ms = millis();
596
   const millis_t ms = millis();
597
   static millis_t next_event_ms = 0;
597
   static millis_t next_event_ms = 0;
598
-  static float last_degBed = 999, last_degHotend0 = 999, last_degHotend1 = 999,
599
-               last_degTargetBed = 999, last_degTargetHotend0 = 999, last_degTargetHotend1 = 999;
598
+  static celsius_float_t last_degBed = 999, last_degHotend0 = 999, last_degHotend1 = 999,
599
+                         last_degTargetBed = 999, last_degTargetHotend0 = 999, last_degTargetHotend1 = 999;
600
 
600
 
601
   // tmppage Temperature
601
   // tmppage Temperature
602
   if (!WITHIN(last_degHotend0 - getActualTemp_celsius(E0), -0.2, 0.2) || !WITHIN(last_degTargetHotend0 - getTargetTemp_celsius(E0), -0.5, 0.5)) {
602
   if (!WITHIN(last_degHotend0 - getActualTemp_celsius(E0), -0.2, 0.2) || !WITHIN(last_degTargetHotend0 - getTargetTemp_celsius(E0), -0.5, 0.5)) {

+ 4
- 4
Marlin/src/lcd/extui/ui_api.cpp View File

263
     #define GET_TEMP_ADJUSTMENT(A) A
263
     #define GET_TEMP_ADJUSTMENT(A) A
264
   #endif
264
   #endif
265
 
265
 
266
-  float getActualTemp_celsius(const heater_t heater) {
266
+  celsius_float_t getActualTemp_celsius(const heater_t heater) {
267
     switch (heater) {
267
     switch (heater) {
268
       #if ENABLED(HAS_HEATED_BED)
268
       #if ENABLED(HAS_HEATED_BED)
269
         case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degBed());
269
         case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degBed());
275
     }
275
     }
276
   }
276
   }
277
 
277
 
278
-  float getActualTemp_celsius(const extruder_t extruder) {
278
+  celsius_float_t getActualTemp_celsius(const extruder_t extruder) {
279
     return GET_TEMP_ADJUSTMENT(thermalManager.degHotend(extruder - E0));
279
     return GET_TEMP_ADJUSTMENT(thermalManager.degHotend(extruder - E0));
280
   }
280
   }
281
 
281
 
282
-  float getTargetTemp_celsius(const heater_t heater) {
282
+  celsius_float_t getTargetTemp_celsius(const heater_t heater) {
283
     switch (heater) {
283
     switch (heater) {
284
       #if ENABLED(HAS_HEATED_BED)
284
       #if ENABLED(HAS_HEATED_BED)
285
         case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetBed());
285
         case BED: return GET_TEMP_ADJUSTMENT(thermalManager.degTargetBed());
291
     }
291
     }
292
   }
292
   }
293
 
293
 
294
-  float getTargetTemp_celsius(const extruder_t extruder) {
294
+  celsius_float_t getTargetTemp_celsius(const extruder_t extruder) {
295
     return GET_TEMP_ADJUSTMENT(thermalManager.degTargetHotend(extruder - E0));
295
     return GET_TEMP_ADJUSTMENT(thermalManager.degTargetHotend(extruder - E0));
296
   }
296
   }
297
 
297
 

+ 4
- 4
Marlin/src/lcd/extui/ui_api.h View File

109
     void setTMCBumpSensitivity(const_float_t , const axis_t);
109
     void setTMCBumpSensitivity(const_float_t , const axis_t);
110
   #endif
110
   #endif
111
 
111
 
112
-  float getActualTemp_celsius(const heater_t);
113
-  float getActualTemp_celsius(const extruder_t);
114
-  float getTargetTemp_celsius(const heater_t);
115
-  float getTargetTemp_celsius(const extruder_t);
112
+  celsius_float_t getActualTemp_celsius(const heater_t);
113
+  celsius_float_t getActualTemp_celsius(const extruder_t);
114
+  celsius_float_t getTargetTemp_celsius(const heater_t);
115
+  celsius_float_t getTargetTemp_celsius(const extruder_t);
116
   float getTargetFan_percent(const fan_t);
116
   float getTargetFan_percent(const fan_t);
117
   float getActualFan_percent(const fan_t);
117
   float getActualFan_percent(const fan_t);
118
   float getAxisPosition_mm(const axis_t);
118
   float getAxisPosition_mm(const axis_t);

+ 4
- 4
Marlin/src/module/probe.cpp View File

352
    *  - If a preheat input is higher than the current target, raise the target temperature.
352
    *  - If a preheat input is higher than the current target, raise the target temperature.
353
    *  - If a preheat input is higher than the current temperature, wait for stabilization.
353
    *  - If a preheat input is higher than the current temperature, wait for stabilization.
354
    */
354
    */
355
-  void Probe::preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp) {
355
+  void Probe::preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp) {
356
     #if HAS_HOTEND && (PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP)
356
     #if HAS_HOTEND && (PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP)
357
       #define WAIT_FOR_NOZZLE_HEAT
357
       #define WAIT_FOR_NOZZLE_HEAT
358
     #endif
358
     #endif
363
     DEBUG_ECHOPGM("Preheating ");
363
     DEBUG_ECHOPGM("Preheating ");
364
 
364
 
365
     #if ENABLED(WAIT_FOR_NOZZLE_HEAT)
365
     #if ENABLED(WAIT_FOR_NOZZLE_HEAT)
366
-      const int16_t hotendPreheat = hotend_temp > thermalManager.degTargetHotend(0) ? hotend_temp : 0;
366
+      const celsius_t hotendPreheat = hotend_temp > thermalManager.degTargetHotend(0) ? hotend_temp : 0;
367
       if (hotendPreheat) {
367
       if (hotendPreheat) {
368
         DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")");
368
         DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")");
369
         thermalManager.setTargetHotend(hotendPreheat, 0);
369
         thermalManager.setTargetHotend(hotendPreheat, 0);
370
       }
370
       }
371
     #elif ENABLED(WAIT_FOR_BED_HEAT)
371
     #elif ENABLED(WAIT_FOR_BED_HEAT)
372
-      constexpr int16_t hotendPreheat = 0;
372
+      constexpr celsius_t hotendPreheat = 0;
373
     #endif
373
     #endif
374
 
374
 
375
     #if ENABLED(WAIT_FOR_BED_HEAT)
375
     #if ENABLED(WAIT_FOR_BED_HEAT)
376
-      const int16_t bedPreheat = bed_temp > thermalManager.degTargetBed() ? bed_temp : 0;
376
+      const celsius_t bedPreheat = bed_temp > thermalManager.degTargetBed() ? bed_temp : 0;
377
       if (bedPreheat) {
377
       if (bedPreheat) {
378
         if (hotendPreheat) DEBUG_ECHOPGM(" and ");
378
         if (hotendPreheat) DEBUG_ECHOPGM(" and ");
379
         DEBUG_ECHOPAIR("bed (", bedPreheat, ")");
379
         DEBUG_ECHOPAIR("bed (", bedPreheat, ")");

+ 1
- 1
Marlin/src/module/probe.h View File

61
     static xyz_pos_t offset;
61
     static xyz_pos_t offset;
62
 
62
 
63
     #if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING)
63
     #if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING)
64
-      static void preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp);
64
+      static void preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp);
65
     #endif
65
     #endif
66
 
66
 
67
     static bool set_deployed(const bool deploy);
67
     static bool set_deployed(const bool deploy);

+ 29
- 20
Marlin/src/module/temperature.cpp View File

382
   chamber_info_t Temperature::temp_chamber; // = { 0 }
382
   chamber_info_t Temperature::temp_chamber; // = { 0 }
383
   #if HAS_HEATED_CHAMBER
383
   #if HAS_HEATED_CHAMBER
384
     millis_t next_cool_check_ms_2 = 0;
384
     millis_t next_cool_check_ms_2 = 0;
385
-    float old_temp = 9999;
385
+    celsius_float_t old_temp = 9999;
386
     int16_t Temperature::mintemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_LO_TEMP,
386
     int16_t Temperature::mintemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_LO_TEMP,
387
             Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP;
387
             Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP;
388
     TERN_(WATCH_CHAMBER, chamber_watch_t Temperature::watch_chamber{0});
388
     TERN_(WATCH_CHAMBER, chamber_watch_t Temperature::watch_chamber{0});
395
   #if HAS_COOLER
395
   #if HAS_COOLER
396
     bool flag_cooler_state;
396
     bool flag_cooler_state;
397
     //bool flag_cooler_excess = false;
397
     //bool flag_cooler_excess = false;
398
-    float previous_temp = 9999;
398
+    celsius_float_t previous_temp = 9999;
399
     int16_t Temperature::mintemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_LO_TEMP,
399
     int16_t Temperature::mintemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_LO_TEMP,
400
             Temperature::maxtemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_HI_TEMP;
400
             Temperature::maxtemp_raw_COOLER = TEMP_SENSOR_COOLER_RAW_HI_TEMP;
401
     #if WATCH_COOLER
401
     #if WATCH_COOLER
421
 #endif
421
 #endif
422
 
422
 
423
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
423
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
424
-  celsius_t Temperature::redundant_temperature_raw = 0;
425
-  float Temperature::redundant_temperature = 0.0;
424
+  int16_t Temperature::redundant_temperature_raw = 0;
425
+  celsius_float_t Temperature::redundant_temperature = 0.0;
426
 #endif
426
 #endif
427
 
427
 
428
 volatile bool Temperature::raw_temps_ready = false;
428
 volatile bool Temperature::raw_temps_ready = false;
508
     long t_high = 0, t_low = 0;
508
     long t_high = 0, t_low = 0;
509
 
509
 
510
     PID_t tune_pid = { 0, 0, 0 };
510
     PID_t tune_pid = { 0, 0, 0 };
511
-    float maxT = 0, minT = 10000;
511
+    celsius_float_t maxT = 0, minT = 10000;
512
 
512
 
513
     const bool isbed = (heater_id == H_BED);
513
     const bool isbed = (heater_id == H_BED);
514
     const bool ischamber = (heater_id == H_CHAMBER);
514
     const bool ischamber = (heater_id == H_CHAMBER);
544
       #define GTV(C,B,H) C_GTV(ischamber, C, B_GTV(isbed, B, H))
544
       #define GTV(C,B,H) C_GTV(ischamber, C, B_GTV(isbed, B, H))
545
       const uint16_t watch_temp_period = GTV(WATCH_CHAMBER_TEMP_PERIOD, WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
545
       const uint16_t watch_temp_period = GTV(WATCH_CHAMBER_TEMP_PERIOD, WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
546
       const uint8_t watch_temp_increase = GTV(WATCH_CHAMBER_TEMP_INCREASE, WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
546
       const uint8_t watch_temp_increase = GTV(WATCH_CHAMBER_TEMP_INCREASE, WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
547
-      const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_CHAMBER_HYSTERESIS, TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
547
+      const celsius_float_t watch_temp_target = celsius_float_t(target - watch_temp_increase + GTV(TEMP_CHAMBER_HYSTERESIS, TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
548
       millis_t temp_change_ms = next_temp_ms + SEC_TO_MS(watch_temp_period);
548
       millis_t temp_change_ms = next_temp_ms + SEC_TO_MS(watch_temp_period);
549
-      float next_watch_temp = 0.0;
549
+      celsius_float_t next_watch_temp = 0.0;
550
       bool heated = false;
550
       bool heated = false;
551
     #endif
551
     #endif
552
 
552
 
567
     SHV(bias);
567
     SHV(bias);
568
 
568
 
569
     #if ENABLED(PRINTER_EVENT_LEDS)
569
     #if ENABLED(PRINTER_EVENT_LEDS)
570
-      const float start_temp = GHV(temp_chamber.celsius, temp_bed.celsius, temp_hotend[heater_id].celsius);
570
+      const celsius_float_t start_temp = GHV(temp_chamber.celsius, temp_bed.celsius, temp_hotend[heater_id].celsius);
571
       LEDColor color = ONHEATINGSTART();
571
       LEDColor color = ONHEATINGSTART();
572
     #endif
572
     #endif
573
 
573
 
2338
    *
2338
    *
2339
    * TODO: Embed the last 3 parameters during init, if not less optimal
2339
    * TODO: Embed the last 3 parameters during init, if not less optimal
2340
    */
2340
    */
2341
-  void Temperature::tr_state_machine_t::run(const_float_t current, const_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc) {
2341
+  void Temperature::tr_state_machine_t::run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc) {
2342
 
2342
 
2343
     #if HEATER_IDLE_HANDLER
2343
     #if HEATER_IDLE_HANDLER
2344
       // Convert the given heater_id_t to an idle array index
2344
       // Convert the given heater_id_t to an idle array index
3373
 
3373
 
3374
   #include "../gcode/gcode.h"
3374
   #include "../gcode/gcode.h"
3375
 
3375
 
3376
-  static void print_heater_state(const_float_t c, const_float_t t
3376
+  /**
3377
+   * Print a single heater state in the form:
3378
+   *        Bed: " B:nnn.nn /nnn.nn"
3379
+   *    Chamber: " C:nnn.nn /nnn.nn"
3380
+   *      Probe: " P:nnn.nn /nnn.nn"
3381
+   *     Cooler: " L:nnn.nn /nnn.nn"
3382
+   *   Extruder: " T0:nnn.nn /nnn.nn"
3383
+   *   With ADC: " T0:nnn.nn /nnn.nn (nnn.nn)"
3384
+   */
3385
+  static void print_heater_state(const_celsius_float_t c, const_celsius_float_t t
3377
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
3386
     #if ENABLED(SHOW_TEMP_ADC_VALUES)
3378
       , const float r
3387
       , const float r
3379
     #endif
3388
     #endif
3557
       #endif
3566
       #endif
3558
 
3567
 
3559
       #if ENABLED(PRINTER_EVENT_LEDS)
3568
       #if ENABLED(PRINTER_EVENT_LEDS)
3560
-        const float start_temp = degHotend(target_extruder);
3569
+        const celsius_float_t start_temp = degHotend(target_extruder);
3561
         printerEventLEDs.onHotendHeatingStart();
3570
         printerEventLEDs.onHotendHeatingStart();
3562
       #endif
3571
       #endif
3563
 
3572
 
3564
       bool wants_to_cool = false;
3573
       bool wants_to_cool = false;
3565
-      float target_temp = -1.0, old_temp = 9999.0;
3574
+      celsius_float_t target_temp = -1.0, old_temp = 9999.0;
3566
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
3575
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
3567
       wait_for_heatup = true;
3576
       wait_for_heatup = true;
3568
       do {
3577
       do {
3592
         idle();
3601
         idle();
3593
         gcode.reset_stepper_timeout(); // Keep steppers powered
3602
         gcode.reset_stepper_timeout(); // Keep steppers powered
3594
 
3603
 
3595
-        const float temp = degHotend(target_extruder);
3604
+        const celsius_float_t temp = degHotend(target_extruder);
3596
 
3605
 
3597
         #if ENABLED(PRINTER_EVENT_LEDS)
3606
         #if ENABLED(PRINTER_EVENT_LEDS)
3598
           // Gradually change LED strip from violet to red as nozzle heats up
3607
           // Gradually change LED strip from violet to red as nozzle heats up
3601
 
3610
 
3602
         #if TEMP_RESIDENCY_TIME > 0
3611
         #if TEMP_RESIDENCY_TIME > 0
3603
 
3612
 
3604
-          const float temp_diff = ABS(target_temp - temp);
3613
+          const celsius_float_t temp_diff = ABS(target_temp - temp);
3605
 
3614
 
3606
           if (!residency_start_ms) {
3615
           if (!residency_start_ms) {
3607
             // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
3616
             // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
3695
       #endif
3704
       #endif
3696
 
3705
 
3697
       #if ENABLED(PRINTER_EVENT_LEDS)
3706
       #if ENABLED(PRINTER_EVENT_LEDS)
3698
-        const float start_temp = degBed();
3707
+        const celsius_float_t start_temp = degBed();
3699
         printerEventLEDs.onBedHeatingStart();
3708
         printerEventLEDs.onBedHeatingStart();
3700
       #endif
3709
       #endif
3701
 
3710
 
3702
       bool wants_to_cool = false;
3711
       bool wants_to_cool = false;
3703
-      float target_temp = -1, old_temp = 9999;
3712
+      celsius_float_t target_temp = -1, old_temp = 9999;
3704
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
3713
       millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
3705
       wait_for_heatup = true;
3714
       wait_for_heatup = true;
3706
       do {
3715
       do {
3730
         idle();
3739
         idle();
3731
         gcode.reset_stepper_timeout(); // Keep steppers powered
3740
         gcode.reset_stepper_timeout(); // Keep steppers powered
3732
 
3741
 
3733
-        const float temp = degBed();
3742
+        const celsius_float_t temp = degBed();
3734
 
3743
 
3735
         #if ENABLED(PRINTER_EVENT_LEDS)
3744
         #if ENABLED(PRINTER_EVENT_LEDS)
3736
           // Gradually change LED strip from blue to violet as bed heats up
3745
           // Gradually change LED strip from blue to violet as bed heats up
3739
 
3748
 
3740
         #if TEMP_BED_RESIDENCY_TIME > 0
3749
         #if TEMP_BED_RESIDENCY_TIME > 0
3741
 
3750
 
3742
-          const float temp_diff = ABS(target_temp - temp);
3751
+          const celsius_float_t temp_diff = ABS(target_temp - temp);
3743
 
3752
 
3744
           if (!residency_start_ms) {
3753
           if (!residency_start_ms) {
3745
             // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
3754
             // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
4021
         idle();
4030
         idle();
4022
         gcode.reset_stepper_timeout(); // Keep steppers powered
4031
         gcode.reset_stepper_timeout(); // Keep steppers powered
4023
 
4032
 
4024
-        const float current_temp = degCooler();
4033
+        const celsius_float_t current_temp = degCooler();
4025
 
4034
 
4026
         #if TEMP_COOLER_RESIDENCY_TIME > 0
4035
         #if TEMP_COOLER_RESIDENCY_TIME > 0
4027
 
4036
 
4028
-          const float temp_diff = ABS(target_temp - temp);
4037
+          const celsius_float_t temp_diff = ABS(target_temp - temp);
4029
 
4038
 
4030
           if (!residency_start_ms) {
4039
           if (!residency_start_ms) {
4031
             // Start the TEMP_COOLER_RESIDENCY_TIME timer when we reach target temp for the first time.
4040
             // Start the TEMP_COOLER_RESIDENCY_TIME timer when we reach target temp for the first time.

+ 1
- 1
Marlin/src/module/temperature.h View File

961
         millis_t timer = 0;
961
         millis_t timer = 0;
962
         TRState state = TRInactive;
962
         TRState state = TRInactive;
963
         float running_temp;
963
         float running_temp;
964
-        void run(const_float_t current, const_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc);
964
+        void run(const_celsius_float_t current, const_celsius_float_t target, const heater_id_t heater_id, const uint16_t period_seconds, const celsius_t hysteresis_degc);
965
       } tr_state_machine_t;
965
       } tr_state_machine_t;
966
 
966
 
967
       static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];
967
       static tr_state_machine_t tr_state_machine[NR_HEATER_RUNAWAY];

Loading…
Cancel
Save