Add HAS_HEATED_BED conditional (#10495)

This commit is contained in:
Scott Lahteine
2018-04-23 17:13:01 -05:00
committed by GitHub
parent 10a25f733e
commit cb46cb8480
19 changed files with 303 additions and 260 deletions

View File

@ -63,7 +63,7 @@ Temperature thermalManager;
* Macros to include the heater id in temp errors. The compiler's dead-code
* elimination should (hopefully) optimize out the unused strings.
*/
#if HAS_TEMP_BED
#if HAS_HEATED_BED
#define TEMP_ERR_PSTR(MSG, E) \
(E) == -1 ? PSTR(MSG ## _BED) : \
(HOTENDS > 1 && (E) == 1) ? PSTR(MSG_E2 " " MSG) : \
@ -82,21 +82,51 @@ Temperature thermalManager;
// public:
float Temperature::current_temperature[HOTENDS] = { 0.0 },
Temperature::current_temperature_chamber = 0.0,
Temperature::current_temperature_bed = 0.0;
float Temperature::current_temperature[HOTENDS] = { 0.0 };
int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
Temperature::target_temperature[HOTENDS] = { 0 },
Temperature::current_temperature_chamber_raw = 0,
Temperature::current_temperature_bed_raw = 0;
Temperature::target_temperature[HOTENDS] = { 0 };
#if ENABLED(AUTO_POWER_E_FANS)
int16_t Temperature::autofan_speed[HOTENDS] = { 0 };
#endif
#if HAS_HEATER_BED
int16_t Temperature::target_temperature_bed = 0;
#if HAS_HEATED_BED
float Temperature::current_temperature_bed = 0.0;
int16_t Temperature::current_temperature_bed_raw = 0,
Temperature::target_temperature_bed = 0;
uint8_t Temperature::soft_pwm_amount_bed;
#ifdef BED_MINTEMP
int16_t Temperature::bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
#endif
#ifdef BED_MAXTEMP
int16_t Temperature::bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
#endif
#if WATCH_THE_BED
uint16_t Temperature::watch_target_bed_temp = 0;
millis_t Temperature::watch_bed_next_ms = 0;
#endif
#if ENABLED(PIDTEMPBED)
float Temperature::bedKp, Temperature::bedKi, Temperature::bedKd, // Initialized by settings.load()
Temperature::temp_iState_bed = { 0 },
Temperature::temp_dState_bed = { 0 },
Temperature::pTerm_bed,
Temperature::iTerm_bed,
Temperature::dTerm_bed,
Temperature::pid_error_bed;
#else
millis_t Temperature::next_bed_check_ms;
#endif
uint16_t Temperature::raw_temp_bed_value = 0;
#if HEATER_IDLE_HANDLER
millis_t Temperature::bed_idle_timeout_ms = 0;
bool Temperature::bed_idle_timeout_exceeded = false;
#endif
#endif // HAS_HEATED_BED
#if HAS_TEMP_CHAMBER
float Temperature::current_temperature_chamber = 0.0;
int16_t Temperature::current_temperature_chamber_raw = 0;
uint16_t Temperature::raw_temp_chamber_value = 0;
#endif
// Initialized by settings.load()
@ -114,11 +144,6 @@ int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
#endif
#endif
// Initialized by settings.load()
#if ENABLED(PIDTEMPBED)
float Temperature::bedKp, Temperature::bedKi, Temperature::bedKd;
#endif
#if ENABLED(BABYSTEPPING)
volatile int Temperature::babystepsTodo[XYZ] = { 0 };
#endif
@ -128,11 +153,6 @@ int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
millis_t Temperature::watch_heater_next_ms[HOTENDS] = { 0 };
#endif
#if WATCH_THE_BED
uint16_t Temperature::watch_target_bed_temp = 0;
millis_t Temperature::watch_bed_next_ms = 0;
#endif
#if ENABLED(PREVENT_COLD_EXTRUSION)
bool Temperature::allow_cold_extrude = false;
int16_t Temperature::extrude_min_temp = EXTRUDE_MINTEMP;
@ -169,20 +189,7 @@ volatile bool Temperature::temp_meas_ready = false;
bool Temperature::pid_reset[HOTENDS];
#endif
#if ENABLED(PIDTEMPBED)
float Temperature::temp_iState_bed = { 0 },
Temperature::temp_dState_bed = { 0 },
Temperature::pTerm_bed,
Temperature::iTerm_bed,
Temperature::dTerm_bed,
Temperature::pid_error_bed;
#else
millis_t Temperature::next_bed_check_ms;
#endif
uint16_t Temperature::raw_temp_value[MAX_EXTRUDERS] = { 0 },
Temperature::raw_temp_chamber_value = 0,
Temperature::raw_temp_bed_value = 0;
uint16_t Temperature::raw_temp_value[MAX_EXTRUDERS] = { 0 };
// Init min and max temp with extreme values to prevent false errors during startup
int16_t Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP, HEATER_3_RAW_LO_TEMP, HEATER_4_RAW_LO_TEMP),
@ -198,14 +205,6 @@ int16_t Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TE
millis_t Temperature::preheat_end_time[HOTENDS] = { 0 };
#endif
#ifdef BED_MINTEMP
int16_t Temperature::bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
#endif
#ifdef BED_MAXTEMP
int16_t Temperature::bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
int8_t Temperature::meas_shift_index; // Index of a delayed sample in buffer
#endif
@ -214,8 +213,7 @@ int16_t Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TE
millis_t Temperature::next_auto_fan_check_ms = 0;
#endif
uint8_t Temperature::soft_pwm_amount[HOTENDS],
Temperature::soft_pwm_amount_bed;
uint8_t Temperature::soft_pwm_amount[HOTENDS];
#if ENABLED(FAN_SOFT_PWM)
uint8_t Temperature::soft_pwm_amount_fan[FAN_COUNT],
@ -233,10 +231,6 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
#if HEATER_IDLE_HANDLER
millis_t Temperature::heater_idle_timeout_ms[HOTENDS] = { 0 };
bool Temperature::heater_idle_timeout_exceeded[HOTENDS] = { false };
#if HAS_TEMP_BED
millis_t Temperature::bed_idle_timeout_ms = 0;
bool Temperature::bed_idle_timeout_exceeded = false;
#endif
#endif
#if ENABLED(ADC_KEYPAD)
@ -546,8 +540,13 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
Temperature::Temperature() { }
int Temperature::getHeaterPower(int heater) {
return heater < 0 ? soft_pwm_amount_bed : soft_pwm_amount[heater];
int Temperature::getHeaterPower(const int heater) {
return (
#if HAS_HEATED_BED
heater < 0 ? soft_pwm_amount_bed :
#endif
soft_pwm_amount[heater]
);
}
#if HAS_AUTO_FAN
@ -618,6 +617,7 @@ void Temperature::_temp_error(const int8_t e, const char * const serial_msg, con
void Temperature::max_temp_error(const int8_t e) {
_temp_error(e, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, e));
}
void Temperature::min_temp_error(const int8_t e) {
_temp_error(e, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, e));
}
@ -857,29 +857,29 @@ void Temperature::manage_heater() {
}
#endif // FILAMENT_WIDTH_SENSOR
#if WATCH_THE_BED
// Make sure temperature is increasing
if (watch_bed_next_ms && ELAPSED(ms, watch_bed_next_ms)) { // Time to check the bed?
if (degBed() < watch_target_bed_temp) // Failed to increase enough?
_temp_error(-1, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, -1));
else // Start again if the target is still far off
start_watching_bed();
}
#endif // WATCH_THE_BED
#if HAS_HEATED_BED
#if DISABLED(PIDTEMPBED)
if (PENDING(ms, next_bed_check_ms)
#if WATCH_THE_BED
// Make sure temperature is increasing
if (watch_bed_next_ms && ELAPSED(ms, watch_bed_next_ms)) { // Time to check the bed?
if (degBed() < watch_target_bed_temp) // Failed to increase enough?
_temp_error(-1, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, -1));
else // Start again if the target is still far off
start_watching_bed();
}
#endif // WATCH_THE_BED
#if DISABLED(PIDTEMPBED)
if (PENDING(ms, next_bed_check_ms)
#if ENABLED(PROBING_HEATERS_OFF) && ENABLED(BED_LIMIT_SWITCHING)
&& paused == last_pause_state
#endif
) return;
next_bed_check_ms = ms + BED_CHECK_INTERVAL;
#if ENABLED(PROBING_HEATERS_OFF) && ENABLED(BED_LIMIT_SWITCHING)
&& paused == last_pause_state
last_pause_state = paused;
#endif
) return;
next_bed_check_ms = ms + BED_CHECK_INTERVAL;
#if ENABLED(PROBING_HEATERS_OFF) && ENABLED(BED_LIMIT_SWITCHING)
last_pause_state = paused;
#endif
#endif
#if HAS_TEMP_BED
#if HEATER_IDLE_HANDLER
if (!bed_idle_timeout_exceeded && bed_idle_timeout_ms && ELAPSED(ms, bed_idle_timeout_ms))
@ -920,7 +920,7 @@ void Temperature::manage_heater() {
}
#endif
}
#endif // HAS_TEMP_BED
#endif // HAS_HEATED_BED
}
#define PGM_RD_W(x) (short)pgm_read_word(&x)
@ -968,7 +968,7 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
}
#if HAS_TEMP_BED
#if HAS_HEATED_BED
// Derived from RepRap FiveD extruder::getTemperature()
// For bed temperature measurement.
float Temperature::analog2tempBed(const int raw) {
@ -1002,7 +1002,7 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
#endif
}
#endif // HAS_TEMP_BED
#endif // HAS_HEATED_BED
#if HAS_TEMP_CHAMBER
// Derived from RepRap FiveD extruder::getTemperature()
@ -1052,7 +1052,7 @@ void Temperature::updateTemperaturesFromRawValues() {
#endif
HOTEND_LOOP()
current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
#if HAS_TEMP_BED
#if HAS_HEATED_BED
current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
#endif
#if HAS_TEMP_CHAMBER
@ -1149,7 +1149,7 @@ void Temperature::init() {
#if HAS_HEATER_4
OUT_WRITE(HEATER_3_PIN, HEATER_4_INVERTING);
#endif
#if HAS_HEATER_BED
#if HAS_HEATED_BED
OUT_WRITE(HEATER_BED_PIN, HEATER_BED_INVERTING);
#endif
@ -1204,7 +1204,7 @@ void Temperature::init() {
#if HAS_TEMP_4
HAL_ANALOG_SELECT(TEMP_4_PIN);
#endif
#if HAS_TEMP_BED
#if HAS_HEATED_BED
HAL_ANALOG_SELECT(TEMP_BED_PIN);
#endif
#if HAS_TEMP_CHAMBER
@ -1345,7 +1345,7 @@ void Temperature::init() {
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_TEMP_BED
#if HAS_HEATED_BED
#ifdef BED_MINTEMP
while (analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) {
#if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
@ -1364,7 +1364,7 @@ void Temperature::init() {
#endif
}
#endif // BED_MAXTEMP
#endif // HAS_TEMP_BED
#endif // HAS_HEATED_BED
#if ENABLED(PROBING_HEATERS_OFF)
paused = false;
@ -1483,7 +1483,7 @@ void Temperature::init() {
#if HEATER_IDLE_HANDLER
// If the heater idle timeout expires, restart
if ((heater_id >= 0 && heater_idle_timeout_exceeded[heater_id])
#if HAS_TEMP_BED
#if HAS_HEATED_BED
|| (heater_id < 0 && bed_idle_timeout_exceeded)
#endif
) {
@ -1529,7 +1529,10 @@ void Temperature::disable_all_heaters() {
#endif
HOTEND_LOOP() setTargetHotend(0, e);
setTargetBed(0);
#if HAS_HEATED_BED
setTargetBed(0);
#endif
// Unpause and reset everything
#if ENABLED(PROBING_HEATERS_OFF)
@ -1561,10 +1564,10 @@ void Temperature::disable_all_heaters() {
#endif // HOTENDS > 1
#endif
#if HAS_TEMP_BED
#if HAS_HEATED_BED
target_temperature_bed = 0;
soft_pwm_amount_bed = 0;
#if HAS_HEATER_BED
#if HAS_HEATED_BED
WRITE_HEATER_BED(LOW);
#endif
#endif
@ -1577,13 +1580,13 @@ void Temperature::disable_all_heaters() {
paused = p;
if (p) {
HOTEND_LOOP() start_heater_idle_timer(e, 0); // timeout immediately
#if HAS_TEMP_BED
#if HAS_HEATED_BED
start_bed_idle_timer(0); // timeout immediately
#endif
}
else {
HOTEND_LOOP() reset_heater_idle_timer(e);
#if HAS_TEMP_BED
#if HAS_HEATED_BED
reset_bed_idle_timer();
#endif
}
@ -1687,8 +1690,13 @@ void Temperature::set_current_temp_raw() {
#endif
#endif
#endif
current_temperature_bed_raw = raw_temp_bed_value;
current_temperature_chamber_raw = raw_temp_chamber_value;
#if HAS_HEATED_BED
current_temperature_bed_raw = raw_temp_bed_value;
#endif
#if HAS_TEMP_CHAMBER
current_temperature_chamber_raw = raw_temp_chamber_value;
#endif
temp_meas_ready = true;
}
@ -1759,7 +1767,7 @@ void Temperature::isr() {
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
#if HAS_HEATED_BED
ISR_STATICS(BED);
#endif
@ -1800,7 +1808,7 @@ void Temperature::isr() {
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
#if HAS_HEATED_BED
soft_pwm_count_BED = (soft_pwm_count_BED & pwm_mask) + soft_pwm_amount_bed;
WRITE_HEATER_BED(soft_pwm_count_BED > pwm_mask ? HIGH : LOW);
#endif
@ -1835,7 +1843,7 @@ void Temperature::isr() {
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
#if HAS_HEATED_BED
if (soft_pwm_count_BED <= pwm_count_tmp) WRITE_HEATER_BED(LOW);
#endif
@ -1916,7 +1924,7 @@ void Temperature::isr() {
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
#if HAS_HEATED_BED
_SLOW_PWM_ROUTINE(BED, soft_pwm_amount_bed); // BED
#endif
@ -1935,7 +1943,7 @@ void Temperature::isr() {
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
#if HAS_HEATED_BED
PWM_OFF_ROUTINE(BED); // BED
#endif
@ -1995,7 +2003,7 @@ void Temperature::isr() {
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
#if HAS_HEATED_BED
if (state_timer_heater_BED > 0) state_timer_heater_BED--;
#endif
} // ((pwm_count >> SOFT_PWM_SCALE) & 0x3F) == 0
@ -2044,7 +2052,7 @@ void Temperature::isr() {
break;
#endif
#if HAS_TEMP_BED
#if HAS_HEATED_BED
case PrepareTemp_BED:
HAL_START_ADC(TEMP_BED_PIN);
break;
@ -2147,8 +2155,14 @@ void Temperature::isr() {
#endif
ZERO(raw_temp_value);
raw_temp_bed_value = 0;
raw_temp_chamber_value = 0;
#if HAS_HEATED_BED
raw_temp_bed_value = 0;
#endif
#if HAS_TEMP_CHAMBER
raw_temp_chamber_value = 0;
#endif
#define TEMPDIR(N) ((HEATER_##N##_RAW_LO_TEMP) > (HEATER_##N##_RAW_HI_TEMP) ? -1 : 1)
@ -2194,7 +2208,7 @@ void Temperature::isr() {
#endif
}
#if HAS_TEMP_BED
#if HAS_HEATED_BED
#if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
#define GEBED <=
#else
@ -2262,15 +2276,15 @@ void Temperature::isr() {
#endif
, const int8_t e=-3
) {
#if !(HAS_TEMP_BED && HAS_TEMP_HOTEND && HAS_TEMP_CHAMBER) && HOTENDS <= 1
#if !(HAS_HEATED_BED && HAS_TEMP_HOTEND && HAS_TEMP_CHAMBER) && HOTENDS <= 1
UNUSED(e);
#endif
SERIAL_PROTOCOLCHAR_P(port, ' ');
SERIAL_PROTOCOLCHAR_P(port,
#if HAS_TEMP_CHAMBER && HAS_TEMP_BED && HAS_TEMP_HOTEND
#if HAS_TEMP_CHAMBER && HAS_HEATED_BED && HAS_TEMP_HOTEND
e == -2 ? 'C' : e == -1 ? 'B' : 'T'
#elif HAS_TEMP_BED && HAS_TEMP_HOTEND
#elif HAS_HEATED_BED && HAS_TEMP_HOTEND
e == -1 ? 'B' : 'T'
#elif HAS_TEMP_HOTEND
'T'
@ -2306,7 +2320,7 @@ void Temperature::isr() {
#endif
);
#endif
#if HAS_TEMP_BED
#if HAS_HEATED_BED
print_heater_state(degBed(), degTargetBed()
#if ENABLED(SHOW_TEMP_ADC_VALUES)
, rawBedTemp()
@ -2338,7 +2352,7 @@ void Temperature::isr() {
#endif
SERIAL_PROTOCOLPGM_P(port, " @:");
SERIAL_PROTOCOL_P(port, getHeaterPower(gcode.target_extruder));
#if HAS_TEMP_BED
#if HAS_HEATED_BED
SERIAL_PROTOCOLPGM_P(port, " B@:");
SERIAL_PROTOCOL_P(port, getHeaterPower(-1));
#endif