|
@@ -42,22 +42,22 @@ class Temperature {
|
42
|
42
|
|
43
|
43
|
public:
|
44
|
44
|
|
45
|
|
- int current_temperature_raw[EXTRUDERS] = { 0 };
|
46
|
|
- float current_temperature[EXTRUDERS] = { 0.0 };
|
47
|
|
- int target_temperature[EXTRUDERS] = { 0 };
|
|
45
|
+ static int current_temperature_raw[EXTRUDERS];
|
|
46
|
+ static float current_temperature[EXTRUDERS];
|
|
47
|
+ static int target_temperature[EXTRUDERS];
|
48
|
48
|
|
49
|
|
- int current_temperature_bed_raw = 0;
|
50
|
|
- float current_temperature_bed = 0.0;
|
51
|
|
- int target_temperature_bed = 0;
|
|
49
|
+ static int current_temperature_bed_raw;
|
|
50
|
+ static float current_temperature_bed;
|
|
51
|
+ static int target_temperature_bed;
|
52
|
52
|
|
53
|
53
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
54
|
|
- float redundant_temperature = 0.0;
|
|
54
|
+ static float redundant_temperature;
|
55
|
55
|
#endif
|
56
|
56
|
|
57
|
|
- unsigned char soft_pwm_bed;
|
|
57
|
+ static unsigned char soft_pwm_bed;
|
58
|
58
|
|
59
|
59
|
#if ENABLED(FAN_SOFT_PWM)
|
60
|
|
- unsigned char fanSpeedSoftPwm[FAN_COUNT];
|
|
60
|
+ static unsigned char fanSpeedSoftPwm[FAN_COUNT];
|
61
|
61
|
#endif
|
62
|
62
|
|
63
|
63
|
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
|
|
@@ -70,7 +70,7 @@ class Temperature {
|
70
|
70
|
|
71
|
71
|
static float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS];
|
72
|
72
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
73
|
|
- float Kc[EXTRUDERS];
|
|
73
|
+ static float Kc[EXTRUDERS];
|
74
|
74
|
#endif
|
75
|
75
|
#define PID_PARAM(param, e) Temperature::param[e]
|
76
|
76
|
|
|
@@ -93,118 +93,110 @@ class Temperature {
|
93
|
93
|
#endif
|
94
|
94
|
|
95
|
95
|
#if ENABLED(PIDTEMPBED)
|
96
|
|
- float bedKp = DEFAULT_bedKp,
|
97
|
|
- bedKi = ((DEFAULT_bedKi) * PID_dT),
|
98
|
|
- bedKd = ((DEFAULT_bedKd) / PID_dT);
|
|
96
|
+ static float bedKp, bedKi, bedKd;
|
99
|
97
|
#endif
|
100
|
98
|
|
101
|
99
|
#if ENABLED(BABYSTEPPING)
|
102
|
|
- volatile int babystepsTodo[3] = { 0 };
|
|
100
|
+ static volatile int babystepsTodo[3];
|
103
|
101
|
#endif
|
104
|
102
|
|
105
|
103
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
|
106
|
|
- int watch_target_temp[EXTRUDERS] = { 0 };
|
107
|
|
- millis_t watch_heater_next_ms[EXTRUDERS] = { 0 };
|
|
104
|
+ static int watch_target_temp[EXTRUDERS];
|
|
105
|
+ static millis_t watch_heater_next_ms[EXTRUDERS];
|
108
|
106
|
#endif
|
109
|
107
|
|
110
|
108
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_BED_TEMP_PERIOD > 0
|
111
|
|
- int watch_target_bed_temp = 0;
|
112
|
|
- millis_t watch_bed_next_ms = 0;
|
|
109
|
+ static int watch_target_bed_temp;
|
|
110
|
+ static millis_t watch_bed_next_ms;
|
113
|
111
|
#endif
|
114
|
112
|
|
115
|
113
|
#if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
|
116
|
|
- float extrude_min_temp = EXTRUDE_MINTEMP;
|
117
|
|
- FORCE_INLINE bool tooColdToExtrude(uint8_t e) { return degHotend(e) < extrude_min_temp; }
|
|
114
|
+ static float extrude_min_temp;
|
|
115
|
+ static bool tooColdToExtrude(uint8_t e) { return degHotend(e) < extrude_min_temp; }
|
118
|
116
|
#else
|
119
|
|
- FORCE_INLINE bool tooColdToExtrude(uint8_t e) { UNUSED(e); return false; }
|
|
117
|
+ static bool tooColdToExtrude(uint8_t e) { UNUSED(e); return false; }
|
120
|
118
|
#endif
|
121
|
119
|
|
122
|
120
|
private:
|
123
|
121
|
|
124
|
122
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
125
|
|
- int redundant_temperature_raw = 0;
|
126
|
|
- float redundant_temperature = 0.0;
|
|
123
|
+ static int redundant_temperature_raw;
|
|
124
|
+ static float redundant_temperature;
|
127
|
125
|
#endif
|
128
|
126
|
|
129
|
|
- volatile bool temp_meas_ready = false;
|
|
127
|
+ static volatile bool temp_meas_ready;
|
130
|
128
|
|
131
|
129
|
#if ENABLED(PIDTEMP)
|
132
|
|
- float temp_iState[EXTRUDERS] = { 0 };
|
133
|
|
- float temp_dState[EXTRUDERS] = { 0 };
|
134
|
|
- float pTerm[EXTRUDERS];
|
135
|
|
- float iTerm[EXTRUDERS];
|
136
|
|
- float dTerm[EXTRUDERS];
|
|
130
|
+ static float temp_iState[EXTRUDERS];
|
|
131
|
+ static float temp_dState[EXTRUDERS];
|
|
132
|
+ static float pTerm[EXTRUDERS];
|
|
133
|
+ static float iTerm[EXTRUDERS];
|
|
134
|
+ static float dTerm[EXTRUDERS];
|
137
|
135
|
|
138
|
136
|
#if ENABLED(PID_ADD_EXTRUSION_RATE)
|
139
|
|
- float cTerm[EXTRUDERS];
|
140
|
|
- long last_position[EXTRUDERS];
|
141
|
|
- long lpq[LPQ_MAX_LEN];
|
142
|
|
- int lpq_ptr = 0;
|
|
137
|
+ static float cTerm[EXTRUDERS];
|
|
138
|
+ static long last_position[EXTRUDERS];
|
|
139
|
+ static long lpq[LPQ_MAX_LEN];
|
|
140
|
+ static int lpq_ptr;
|
143
|
141
|
#endif
|
144
|
142
|
|
145
|
|
- float pid_error[EXTRUDERS];
|
146
|
|
- float temp_iState_min[EXTRUDERS];
|
147
|
|
- float temp_iState_max[EXTRUDERS];
|
148
|
|
- bool pid_reset[EXTRUDERS];
|
|
143
|
+ static float pid_error[EXTRUDERS];
|
|
144
|
+ static float temp_iState_min[EXTRUDERS];
|
|
145
|
+ static float temp_iState_max[EXTRUDERS];
|
|
146
|
+ static bool pid_reset[EXTRUDERS];
|
149
|
147
|
#endif
|
150
|
148
|
|
151
|
149
|
#if ENABLED(PIDTEMPBED)
|
152
|
|
- float temp_iState_bed = { 0 };
|
153
|
|
- float temp_dState_bed = { 0 };
|
154
|
|
- float pTerm_bed;
|
155
|
|
- float iTerm_bed;
|
156
|
|
- float dTerm_bed;
|
157
|
|
- float pid_error_bed;
|
158
|
|
- float temp_iState_min_bed;
|
159
|
|
- float temp_iState_max_bed;
|
|
150
|
+ static float temp_iState_bed;
|
|
151
|
+ static float temp_dState_bed;
|
|
152
|
+ static float pTerm_bed;
|
|
153
|
+ static float iTerm_bed;
|
|
154
|
+ static float dTerm_bed;
|
|
155
|
+ static float pid_error_bed;
|
|
156
|
+ static float temp_iState_min_bed;
|
|
157
|
+ static float temp_iState_max_bed;
|
160
|
158
|
#else
|
161
|
|
- millis_t next_bed_check_ms;
|
|
159
|
+ static millis_t next_bed_check_ms;
|
162
|
160
|
#endif
|
163
|
161
|
|
164
|
|
- unsigned long raw_temp_value[4] = { 0 };
|
165
|
|
- unsigned long raw_temp_bed_value = 0;
|
|
162
|
+ static unsigned long raw_temp_value[4];
|
|
163
|
+ static unsigned long raw_temp_bed_value;
|
166
|
164
|
|
167
|
165
|
// Init min and max temp with extreme values to prevent false errors during startup
|
168
|
|
- int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP, HEATER_3_RAW_LO_TEMP);
|
169
|
|
- int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS(HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP, HEATER_3_RAW_HI_TEMP);
|
170
|
|
- int minttemp[EXTRUDERS] = { 0 };
|
171
|
|
- int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(16383);
|
|
166
|
+ static int minttemp_raw[EXTRUDERS];
|
|
167
|
+ static int maxttemp_raw[EXTRUDERS];
|
|
168
|
+ static int minttemp[EXTRUDERS];
|
|
169
|
+ static int maxttemp[EXTRUDERS];
|
172
|
170
|
|
173
|
171
|
#ifdef BED_MINTEMP
|
174
|
|
- int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
|
|
172
|
+ static int bed_minttemp_raw;
|
175
|
173
|
#endif
|
176
|
174
|
|
177
|
175
|
#ifdef BED_MAXTEMP
|
178
|
|
- int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
|
|
176
|
+ static int bed_maxttemp_raw;
|
179
|
177
|
#endif
|
180
|
178
|
|
181
|
179
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
182
|
|
- int meas_shift_index; // Index of a delayed sample in buffer
|
|
180
|
+ static int meas_shift_index; // Index of a delayed sample in buffer
|
183
|
181
|
#endif
|
184
|
182
|
|
185
|
183
|
#if HAS_AUTO_FAN
|
186
|
|
- millis_t next_auto_fan_check_ms;
|
|
184
|
+ static millis_t next_auto_fan_check_ms;
|
187
|
185
|
#endif
|
188
|
186
|
|
189
|
|
- unsigned char soft_pwm[EXTRUDERS];
|
|
187
|
+ static unsigned char soft_pwm[EXTRUDERS];
|
190
|
188
|
|
191
|
189
|
#if ENABLED(FAN_SOFT_PWM)
|
192
|
|
- unsigned char soft_pwm_fan[FAN_COUNT];
|
|
190
|
+ static unsigned char soft_pwm_fan[FAN_COUNT];
|
193
|
191
|
#endif
|
194
|
192
|
|
195
|
193
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
196
|
|
- int current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only
|
|
194
|
+ static int current_raw_filwidth; //Holds measured filament diameter - one extruder only
|
197
|
195
|
#endif
|
198
|
196
|
|
199
|
197
|
public:
|
200
|
198
|
|
201
|
199
|
/**
|
202
|
|
- * Static (class) methods
|
203
|
|
- */
|
204
|
|
- static float analog2temp(int raw, uint8_t e);
|
205
|
|
- static float analog2tempBed(int raw);
|
206
|
|
-
|
207
|
|
- /**
|
208
|
200
|
* Instance Methods
|
209
|
201
|
*/
|
210
|
202
|
|
|
@@ -213,18 +205,24 @@ class Temperature {
|
213
|
205
|
void init();
|
214
|
206
|
|
215
|
207
|
/**
|
|
208
|
+ * Static (class) methods
|
|
209
|
+ */
|
|
210
|
+ static float analog2temp(int raw, uint8_t e);
|
|
211
|
+ static float analog2tempBed(int raw);
|
|
212
|
+
|
|
213
|
+ /**
|
216
|
214
|
* Called from the Temperature ISR
|
217
|
215
|
*/
|
218
|
|
- void isr();
|
|
216
|
+ static void isr();
|
219
|
217
|
|
220
|
218
|
/**
|
221
|
219
|
* Call periodically to manage heaters
|
222
|
220
|
*/
|
223
|
|
- void manage_heater();
|
|
221
|
+ static void manage_heater();
|
224
|
222
|
|
225
|
223
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
226
|
|
- float analog2widthFil(); // Convert raw Filament Width to millimeters
|
227
|
|
- int widthFil_to_size_ratio(); // Convert raw Filament Width to an extrusion ratio
|
|
224
|
+ static float analog2widthFil(); // Convert raw Filament Width to millimeters
|
|
225
|
+ static int widthFil_to_size_ratio(); // Convert raw Filament Width to an extrusion ratio
|
228
|
226
|
#endif
|
229
|
227
|
|
230
|
228
|
|
|
@@ -232,68 +230,68 @@ class Temperature {
|
232
|
230
|
//inline so that there is no performance decrease.
|
233
|
231
|
//deg=degreeCelsius
|
234
|
232
|
|
235
|
|
- FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
|
236
|
|
- FORCE_INLINE float degBed() { return current_temperature_bed; }
|
|
233
|
+ static float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
|
|
234
|
+ static float degBed() { return current_temperature_bed; }
|
237
|
235
|
|
238
|
236
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
239
|
|
- FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
|
240
|
|
- FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
|
|
237
|
+ static float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
|
|
238
|
+ static float rawBedTemp() { return current_temperature_bed_raw; }
|
241
|
239
|
#endif
|
242
|
240
|
|
243
|
|
- FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
|
244
|
|
- FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
|
|
241
|
+ static float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
|
|
242
|
+ static float degTargetBed() { return target_temperature_bed; }
|
245
|
243
|
|
246
|
244
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
|
247
|
|
- void start_watching_heater(int e = 0);
|
|
245
|
+ static void start_watching_heater(int e = 0);
|
248
|
246
|
#endif
|
249
|
247
|
|
250
|
248
|
#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
|
251
|
|
- void start_watching_bed();
|
|
249
|
+ static void start_watching_bed();
|
252
|
250
|
#endif
|
253
|
251
|
|
254
|
|
- FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t extruder) {
|
|
252
|
+ static void setTargetHotend(const float& celsius, uint8_t extruder) {
|
255
|
253
|
target_temperature[extruder] = celsius;
|
256
|
254
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
|
257
|
255
|
start_watching_heater(extruder);
|
258
|
256
|
#endif
|
259
|
257
|
}
|
260
|
258
|
|
261
|
|
- FORCE_INLINE void setTargetBed(const float& celsius) {
|
|
259
|
+ static void setTargetBed(const float& celsius) {
|
262
|
260
|
target_temperature_bed = celsius;
|
263
|
261
|
#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
|
264
|
262
|
start_watching_bed();
|
265
|
263
|
#endif
|
266
|
264
|
}
|
267
|
265
|
|
268
|
|
- FORCE_INLINE bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
|
269
|
|
- FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
|
|
266
|
+ static bool isHeatingHotend(uint8_t extruder) { return target_temperature[extruder] > current_temperature[extruder]; }
|
|
267
|
+ static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
|
270
|
268
|
|
271
|
|
- FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
|
272
|
|
- FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
|
|
269
|
+ static bool isCoolingHotend(uint8_t extruder) { return target_temperature[extruder] < current_temperature[extruder]; }
|
|
270
|
+ static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
|
273
|
271
|
|
274
|
272
|
/**
|
275
|
273
|
* The software PWM power for a heater
|
276
|
274
|
*/
|
277
|
|
- int getHeaterPower(int heater);
|
|
275
|
+ static int getHeaterPower(int heater);
|
278
|
276
|
|
279
|
277
|
/**
|
280
|
278
|
* Switch off all heaters, set all target temperatures to 0
|
281
|
279
|
*/
|
282
|
|
- void disable_all_heaters();
|
|
280
|
+ static void disable_all_heaters();
|
283
|
281
|
|
284
|
282
|
/**
|
285
|
283
|
* Perform auto-tuning for hotend or bed in response to M303
|
286
|
284
|
*/
|
287
|
285
|
#if HAS_PID_HEATING
|
288
|
|
- void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
|
|
286
|
+ static void PID_autotune(float temp, int extruder, int ncycles, bool set_result=false);
|
289
|
287
|
#endif
|
290
|
288
|
|
291
|
289
|
/**
|
292
|
290
|
* Update the temp manager when PID values change
|
293
|
291
|
*/
|
294
|
|
- void updatePID();
|
|
292
|
+ static void updatePID();
|
295
|
293
|
|
296
|
|
- FORCE_INLINE void autotempShutdown() {
|
|
294
|
+ static void autotempShutdown() {
|
297
|
295
|
#if ENABLED(AUTOTEMP)
|
298
|
296
|
if (planner.autotemp_enabled) {
|
299
|
297
|
planner.autotemp_enabled = false;
|
|
@@ -305,7 +303,7 @@ class Temperature {
|
305
|
303
|
|
306
|
304
|
#if ENABLED(BABYSTEPPING)
|
307
|
305
|
|
308
|
|
- FORCE_INLINE void babystep_axis(AxisEnum axis, int distance) {
|
|
306
|
+ static void babystep_axis(AxisEnum axis, int distance) {
|
309
|
307
|
#if ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
|
310
|
308
|
#if ENABLED(BABYSTEP_XY)
|
311
|
309
|
switch (axis) {
|
|
@@ -337,40 +335,40 @@ class Temperature {
|
337
|
335
|
|
338
|
336
|
private:
|
339
|
337
|
|
340
|
|
- void set_current_temp_raw();
|
|
338
|
+ static void set_current_temp_raw();
|
341
|
339
|
|
342
|
|
- void updateTemperaturesFromRawValues();
|
|
340
|
+ static void updateTemperaturesFromRawValues();
|
343
|
341
|
|
344
|
342
|
#if ENABLED(HEATER_0_USES_MAX6675)
|
345
|
|
- int read_max6675();
|
|
343
|
+ static int read_max6675();
|
346
|
344
|
#endif
|
347
|
345
|
|
348
|
|
- void checkExtruderAutoFans();
|
|
346
|
+ static void checkExtruderAutoFans();
|
349
|
347
|
|
350
|
|
- float get_pid_output(int e);
|
|
348
|
+ static float get_pid_output(int e);
|
351
|
349
|
|
352
|
350
|
#if ENABLED(PIDTEMPBED)
|
353
|
|
- float get_pid_output_bed();
|
|
351
|
+ static float get_pid_output_bed();
|
354
|
352
|
#endif
|
355
|
353
|
|
356
|
|
- void _temp_error(int e, const char* serial_msg, const char* lcd_msg);
|
357
|
|
- void min_temp_error(uint8_t e);
|
358
|
|
- void max_temp_error(uint8_t e);
|
|
354
|
+ static void _temp_error(int e, const char* serial_msg, const char* lcd_msg);
|
|
355
|
+ static void min_temp_error(uint8_t e);
|
|
356
|
+ static void max_temp_error(uint8_t e);
|
359
|
357
|
|
360
|
358
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED
|
361
|
359
|
|
362
|
360
|
typedef enum TRState { TRInactive, TRFirstHeating, TRStable, TRRunaway } TRstate;
|
363
|
361
|
|
364
|
|
- void thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
|
|
362
|
+ static void thermal_runaway_protection(TRState* state, millis_t* timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
|
365
|
363
|
|
366
|
364
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
367
|
|
- TRState thermal_runaway_state_machine[EXTRUDERS] = { TRInactive };
|
368
|
|
- millis_t thermal_runaway_timer[EXTRUDERS] = { 0 };
|
|
365
|
+ static TRState thermal_runaway_state_machine[EXTRUDERS];
|
|
366
|
+ static millis_t thermal_runaway_timer[EXTRUDERS];
|
369
|
367
|
#endif
|
370
|
368
|
|
371
|
369
|
#if HAS_THERMALLY_PROTECTED_BED
|
372
|
|
- TRState thermal_runaway_bed_state_machine = TRInactive;
|
373
|
|
- millis_t thermal_runaway_bed_timer;
|
|
370
|
+ static TRState thermal_runaway_bed_state_machine;
|
|
371
|
+ static millis_t thermal_runaway_bed_timer;
|
374
|
372
|
#endif
|
375
|
373
|
|
376
|
374
|
#endif // THERMAL_PROTECTION
|