Add whole-degree accessors, simplify some temperature-related features (#21685)
This commit is contained in:
@ -40,9 +40,9 @@ PrinterEventLEDs printerEventLEDs;
|
||||
|
||||
uint8_t PrinterEventLEDs::old_intensity = 0;
|
||||
|
||||
inline uint8_t pel_intensity(const_float_t start, const_float_t current, const_float_t target) {
|
||||
if (uint16_t(start) == uint16_t(target)) return 255;
|
||||
return (uint8_t)map(constrain(current, start, target), start, target, 0.f, 255.f);
|
||||
inline uint8_t pel_intensity(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
if (start == target) return 255;
|
||||
return (uint8_t)map(constrain(current, start, target), start, target, 0, 255);
|
||||
}
|
||||
|
||||
inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b) {
|
||||
@ -58,7 +58,7 @@ PrinterEventLEDs printerEventLEDs;
|
||||
|
||||
#if HAS_TEMP_HOTEND
|
||||
|
||||
void PrinterEventLEDs::onHotendHeating(const_float_t start, const_float_t current, const_float_t target) {
|
||||
void PrinterEventLEDs::onHotendHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
const uint8_t blue = pel_intensity(start, current, target);
|
||||
if (blue != old_intensity) {
|
||||
old_intensity = blue;
|
||||
@ -70,7 +70,7 @@ PrinterEventLEDs printerEventLEDs;
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
|
||||
void PrinterEventLEDs::onBedHeating(const_float_t start, const_float_t current, const_float_t target) {
|
||||
void PrinterEventLEDs::onBedHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
const uint8_t red = pel_intensity(start, current, target);
|
||||
if (red != old_intensity) {
|
||||
old_intensity = red;
|
||||
@ -82,7 +82,7 @@ PrinterEventLEDs printerEventLEDs;
|
||||
|
||||
#if HAS_HEATED_CHAMBER
|
||||
|
||||
void PrinterEventLEDs::onChamberHeating(const_float_t start, const_float_t current, const_float_t target) {
|
||||
void PrinterEventLEDs::onChamberHeating(const celsius_t start, const celsius_t current, const celsius_t target) {
|
||||
const uint8_t green = pel_intensity(start, current, target);
|
||||
if (green != old_intensity) {
|
||||
old_intensity = green;
|
||||
|
@ -41,21 +41,21 @@ private:
|
||||
public:
|
||||
#if HAS_TEMP_HOTEND
|
||||
static inline LEDColor onHotendHeatingStart() { old_intensity = 0; return leds.get_color(); }
|
||||
static void onHotendHeating(const_float_t start, const_float_t current, const_float_t target);
|
||||
static void onHotendHeating(const celsius_t start, const celsius_t current, const celsius_t target);
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
static inline LEDColor onBedHeatingStart() { old_intensity = 127; return leds.get_color(); }
|
||||
static void onBedHeating(const_float_t start, const_float_t current, const_float_t target);
|
||||
static void onBedHeating(const celsius_t start, const celsius_t current, const celsius_t target);
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_CHAMBER
|
||||
static inline LEDColor onChamberHeatingStart() { old_intensity = 127; return leds.get_color(); }
|
||||
static void onChamberHeating(const_float_t start, const_float_t current, const_float_t target);
|
||||
static void onChamberHeating(const celsius_t start, const celsius_t current, const celsius_t target);
|
||||
#endif
|
||||
|
||||
#if HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_HEATED_CHAMBER
|
||||
static inline void onHeatingDone() { leds.set_white(); }
|
||||
static inline void onHeatingDone() { leds.set_white(); }
|
||||
static inline void onPidTuningDone(LEDColor c) { leds.set_color(c); }
|
||||
#endif
|
||||
|
||||
|
@ -36,10 +36,10 @@ void handle_status_leds() {
|
||||
static millis_t next_status_led_update_ms = 0;
|
||||
if (ELAPSED(millis(), next_status_led_update_ms)) {
|
||||
next_status_led_update_ms += 500; // Update every 0.5s
|
||||
float max_temp = TERN0(HAS_HEATED_BED, _MAX(thermalManager.degTargetBed(), thermalManager.degBed()));
|
||||
celsius_t max_temp = TERN0(HAS_HEATED_BED, _MAX(thermalManager.degTargetBed(), thermalManager.wholeDegBed()));
|
||||
HOTEND_LOOP()
|
||||
max_temp = _MAX(max_temp, thermalManager.degHotend(e), thermalManager.degTargetHotend(e));
|
||||
const int8_t new_red = (max_temp > 55.0) ? HIGH : (max_temp < 54.0 || old_red < 0) ? LOW : old_red;
|
||||
max_temp = _MAX(max_temp, thermalManager.wholeDegHotend(e), thermalManager.degTargetHotend(e));
|
||||
const int8_t new_red = (max_temp > 55) ? HIGH : (max_temp < 54 || old_red < 0) ? LOW : old_red;
|
||||
if (new_red != old_red) {
|
||||
old_red = new_red;
|
||||
#if PIN_EXISTS(STAT_LED_RED)
|
||||
|
@ -143,7 +143,7 @@ static bool ensure_safe_temperature(const bool wait=true, const PauseMode mode=P
|
||||
|
||||
// Allow interruption by Emergency Parser M108
|
||||
wait_for_heatup = TERN1(PREVENT_COLD_EXTRUSION, !thermalManager.allow_cold_extrude);
|
||||
while (wait_for_heatup && ABS(thermalManager.degHotend(active_extruder) - thermalManager.degTargetHotend(active_extruder)) > TEMP_WINDOW)
|
||||
while (wait_for_heatup && ABS(thermalManager.wholeDegHotend(active_extruder) - thermalManager.degTargetHotend(active_extruder)) > (TEMP_WINDOW))
|
||||
idle();
|
||||
wait_for_heatup = false;
|
||||
|
||||
|
@ -71,7 +71,7 @@ bool ProbeTempComp::set_offset(const TempSensorID tsi, const uint8_t idx, const
|
||||
|
||||
void ProbeTempComp::print_offsets() {
|
||||
LOOP_L_N(s, TSI_COUNT) {
|
||||
float temp = cali_info[s].start_temp;
|
||||
celsius_t temp = cali_info[s].start_temp;
|
||||
for (int16_t i = -1; i < cali_info[s].measurements; ++i) {
|
||||
SERIAL_ECHOPGM_P(s == TSI_BED ? PSTR("Bed") :
|
||||
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
|
||||
@ -114,8 +114,8 @@ bool ProbeTempComp::finish_calibration(const TempSensorID tsi) {
|
||||
}
|
||||
|
||||
const uint8_t measurements = cali_info[tsi].measurements;
|
||||
const float start_temp = cali_info[tsi].start_temp,
|
||||
res_temp = cali_info[tsi].temp_res;
|
||||
const celsius_t start_temp = cali_info[tsi].start_temp,
|
||||
res_temp = cali_info[tsi].temp_res;
|
||||
int16_t * const data = sensor_z_offsets[tsi];
|
||||
|
||||
// Extrapolate
|
||||
@ -159,19 +159,19 @@ bool ProbeTempComp::finish_calibration(const TempSensorID tsi) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const_float_t temp, float &meas_z) {
|
||||
void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z) {
|
||||
if (WITHIN(temp, cali_info[tsi].start_temp, cali_info[tsi].end_temp))
|
||||
meas_z -= get_offset_for_temperature(tsi, temp);
|
||||
}
|
||||
|
||||
float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const_float_t temp) {
|
||||
float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const celsius_t temp) {
|
||||
const uint8_t measurements = cali_info[tsi].measurements;
|
||||
const float start_temp = cali_info[tsi].start_temp,
|
||||
res_temp = cali_info[tsi].temp_res;
|
||||
const celsius_t start_temp = cali_info[tsi].start_temp,
|
||||
res_temp = cali_info[tsi].temp_res;
|
||||
const int16_t * const data = sensor_z_offsets[tsi];
|
||||
|
||||
auto point = [&](uint8_t i) {
|
||||
return xy_float_t({start_temp + i*res_temp, static_cast<float>(data[i])});
|
||||
auto point = [&](uint8_t i) -> xy_float_t {
|
||||
return xy_float_t({ static_cast<float>(start_temp) + i * res_temp, static_cast<float>(data[i]) });
|
||||
};
|
||||
|
||||
auto linear_interp = [](const_float_t x, xy_float_t p1, xy_float_t p2) {
|
||||
@ -207,17 +207,18 @@ bool ProbeTempComp::linear_regression(const TempSensorID tsi, float &k, float &d
|
||||
|
||||
if (!WITHIN(calib_idx, 2, cali_info[tsi].measurements)) return false;
|
||||
|
||||
const float start_temp = cali_info[tsi].start_temp,
|
||||
res_temp = cali_info[tsi].temp_res;
|
||||
const celsius_t start_temp = cali_info[tsi].start_temp,
|
||||
res_temp = cali_info[tsi].temp_res;
|
||||
const int16_t * const data = sensor_z_offsets[tsi];
|
||||
|
||||
float sum_x = start_temp,
|
||||
sum_x2 = sq(start_temp),
|
||||
sum_xy = 0, sum_y = 0;
|
||||
|
||||
float xi = static_cast<float>(start_temp);
|
||||
LOOP_L_N(i, calib_idx) {
|
||||
const float xi = start_temp + (i + 1) * res_temp,
|
||||
yi = static_cast<float>(data[i]);
|
||||
const float yi = static_cast<float>(data[i]);
|
||||
xi += res_temp;
|
||||
sum_x += xi;
|
||||
sum_x2 += sq(xi);
|
||||
sum_xy += xi * yi;
|
||||
|
@ -34,9 +34,9 @@ enum TempSensorID : uint8_t {
|
||||
|
||||
typedef struct {
|
||||
uint8_t measurements; // Max. number of measurements to be stored (35 - 80°C)
|
||||
float temp_res, // Resolution in °C between measurements
|
||||
start_temp, // Base measurement; z-offset == 0
|
||||
end_temp;
|
||||
celsius_t temp_res, // Resolution in °C between measurements
|
||||
start_temp, // Base measurement; z-offset == 0
|
||||
end_temp;
|
||||
} temp_calib_t;
|
||||
|
||||
/**
|
||||
@ -50,25 +50,25 @@ typedef struct {
|
||||
#define PTC_SAMPLE_COUNT 10U
|
||||
#endif
|
||||
#ifndef PTC_SAMPLE_RES
|
||||
#define PTC_SAMPLE_RES 5.0f
|
||||
#define PTC_SAMPLE_RES 5
|
||||
#endif
|
||||
#ifndef PTC_SAMPLE_START
|
||||
#define PTC_SAMPLE_START 30.0f
|
||||
#define PTC_SAMPLE_START 30
|
||||
#endif
|
||||
#define PTC_SAMPLE_END ((PTC_SAMPLE_START) + (PTC_SAMPLE_COUNT) * (PTC_SAMPLE_RES))
|
||||
|
||||
// Bed temperature calibration constants
|
||||
#ifndef BTC_PROBE_TEMP
|
||||
#define BTC_PROBE_TEMP 30.0f
|
||||
#define BTC_PROBE_TEMP 30
|
||||
#endif
|
||||
#ifndef BTC_SAMPLE_COUNT
|
||||
#define BTC_SAMPLE_COUNT 10U
|
||||
#endif
|
||||
#ifndef BTC_SAMPLE_STEP
|
||||
#define BTC_SAMPLE_RES 5.0f
|
||||
#define BTC_SAMPLE_RES 5
|
||||
#endif
|
||||
#ifndef BTC_SAMPLE_START
|
||||
#define BTC_SAMPLE_START 60.0f
|
||||
#define BTC_SAMPLE_START 60
|
||||
#endif
|
||||
#define BTC_SAMPLE_END ((BTC_SAMPLE_START) + (BTC_SAMPLE_COUNT) * (BTC_SAMPLE_RES))
|
||||
|
||||
@ -77,7 +77,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef PTC_PROBE_RAISE
|
||||
#define PTC_PROBE_RAISE 10.0f
|
||||
#define PTC_PROBE_RAISE 10
|
||||
#endif
|
||||
|
||||
static constexpr temp_calib_t cali_info_init[TSI_COUNT] = {
|
||||
@ -124,7 +124,7 @@ class ProbeTempComp {
|
||||
static void prepare_new_calibration(const_float_t init_meas_z);
|
||||
static void push_back_new_measurement(const TempSensorID tsi, const_float_t meas_z);
|
||||
static bool finish_calibration(const TempSensorID tsi);
|
||||
static void compensate_measurement(const TempSensorID tsi, const_float_t temp, float &meas_z);
|
||||
static void compensate_measurement(const TempSensorID tsi, const celsius_t temp, float &meas_z);
|
||||
|
||||
private:
|
||||
static uint8_t calib_idx;
|
||||
@ -135,7 +135,7 @@ class ProbeTempComp {
|
||||
*/
|
||||
static float init_measurement;
|
||||
|
||||
static float get_offset_for_temperature(const TempSensorID tsi, const_float_t temp);
|
||||
static float get_offset_for_temperature(const TempSensorID tsi, const celsius_t temp);
|
||||
|
||||
/**
|
||||
* Fit a linear function in measured temperature offsets
|
||||
|
Reference in New Issue
Block a user