Further reduction when HOTENDS == 1

This commit is contained in:
Scott Lahteine 2016-07-09 21:11:17 -07:00
parent 3e1bbd5e27
commit ee0983ab57
5 changed files with 72 additions and 62 deletions

View file

@ -4365,7 +4365,7 @@ inline void gcode_M104() {
SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1); SERIAL_PROTOCOL_F(thermalManager.degTargetBed(), 1);
#endif #endif
#if HOTENDS > 1 #if HOTENDS > 1
for (int8_t e = 0; e < HOTENDS; ++e) { HOTEND_LOOP() {
SERIAL_PROTOCOLPGM(" T"); SERIAL_PROTOCOLPGM(" T");
SERIAL_PROTOCOL(e); SERIAL_PROTOCOL(e);
SERIAL_PROTOCOLCHAR(':'); SERIAL_PROTOCOLCHAR(':');
@ -4391,7 +4391,7 @@ inline void gcode_M104() {
SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder)); SERIAL_PROTOCOL(thermalManager.getHeaterPower(target_extruder));
#endif #endif
#if HOTENDS > 1 #if HOTENDS > 1
for (int8_t e = 0; e < HOTENDS; ++e) { HOTEND_LOOP() {
SERIAL_PROTOCOLPGM(" @"); SERIAL_PROTOCOLPGM(" @");
SERIAL_PROTOCOL(e); SERIAL_PROTOCOL(e);
SERIAL_PROTOCOLCHAR(':'); SERIAL_PROTOCOLCHAR(':');
@ -4410,13 +4410,13 @@ inline void gcode_M104() {
SERIAL_PROTOCOLPGM("C->"); SERIAL_PROTOCOLPGM("C->");
SERIAL_PROTOCOL_F(thermalManager.rawBedTemp() / OVERSAMPLENR, 0); SERIAL_PROTOCOL_F(thermalManager.rawBedTemp() / OVERSAMPLENR, 0);
#endif #endif
for (int8_t cur_hotend = 0; cur_hotend < HOTENDS; ++cur_hotend) { HOTEND_LOOP() {
SERIAL_PROTOCOLPGM(" T"); SERIAL_PROTOCOLPGM(" T");
SERIAL_PROTOCOL(cur_hotend); SERIAL_PROTOCOL(e);
SERIAL_PROTOCOLCHAR(':'); SERIAL_PROTOCOLCHAR(':');
SERIAL_PROTOCOL_F(thermalManager.degHotend(cur_hotend), 1); SERIAL_PROTOCOL_F(thermalManager.degHotend(e), 1);
SERIAL_PROTOCOLPGM("C->"); SERIAL_PROTOCOLPGM("C->");
SERIAL_PROTOCOL_F(thermalManager.rawHotendTemp(cur_hotend) / OVERSAMPLENR, 0); SERIAL_PROTOCOL_F(thermalManager.rawHotendTemp(e) / OVERSAMPLENR, 0);
} }
#endif #endif
} }
@ -5436,7 +5436,7 @@ inline void gcode_M206() {
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPGM(MSG_HOTEND_OFFSET); SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
for (int e = 0; e < HOTENDS; e++) { HOTEND_LOOP() {
SERIAL_CHAR(' '); SERIAL_CHAR(' ');
SERIAL_ECHO(hotend_offset[X_AXIS][e]); SERIAL_ECHO(hotend_offset[X_AXIS][e]);
SERIAL_CHAR(','); SERIAL_CHAR(',');
@ -7968,8 +7968,9 @@ void prepare_move_to_destination() {
float max_temp = 0.0; float max_temp = 0.0;
if (ELAPSED(millis(), next_status_led_update_ms)) { if (ELAPSED(millis(), next_status_led_update_ms)) {
next_status_led_update_ms += 500; // Update every 0.5s next_status_led_update_ms += 500; // Update every 0.5s
for (int8_t cur_hotend = 0; cur_hotend < HOTENDS; ++cur_hotend) HOTEND_LOOP() {
max_temp = max(max(max_temp, thermalManager.degHotend(cur_hotend)), thermalManager.degTargetHotend(cur_hotend)); max_temp = max(max(max_temp, thermalManager.degHotend(e)), thermalManager.degTargetHotend(e));
}
#if HAS_TEMP_BED #if HAS_TEMP_BED
max_temp = max(max(max_temp, thermalManager.degTargetBed()), thermalManager.degBed()); max_temp = max(max(max_temp, thermalManager.degTargetBed()), thermalManager.degBed());
#endif #endif

View file

@ -618,7 +618,7 @@ void Config_ResetDefault() {
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
#if ENABLED(PID_PARAMS_PER_HOTEND) #if ENABLED(PID_PARAMS_PER_HOTEND)
for (uint8_t e = 0; e < HOTENDS; e++) HOTEND_LOOP
#else #else
int e = 0; UNUSED(e); // only need to write once int e = 0; UNUSED(e); // only need to write once
#endif #endif
@ -834,15 +834,15 @@ void Config_PrintSettings(bool forReplay) {
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
#if HOTENDS > 1 #if HOTENDS > 1
if (forReplay) { if (forReplay) {
for (uint8_t i = 0; i < HOTENDS; i++) { HOTEND_LOOP() {
CONFIG_ECHO_START; CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M301 E", i); SERIAL_ECHOPAIR(" M301 E", e);
SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, i)); SERIAL_ECHOPAIR(" P", PID_PARAM(Kp, e));
SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, i))); SERIAL_ECHOPAIR(" I", unscalePID_i(PID_PARAM(Ki, e)));
SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, i))); SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, e)));
#if ENABLED(PID_ADD_EXTRUSION_RATE) #if ENABLED(PID_ADD_EXTRUSION_RATE)
SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, i)); SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
if (i == 0) SERIAL_ECHOPAIR(" L", lpq_len); if (e == 0) SERIAL_ECHOPAIR(" L", lpq_len);
#endif #endif
SERIAL_EOL; SERIAL_EOL;
} }

View file

@ -392,7 +392,7 @@ static void lcd_implementation_status_screen() {
#endif #endif
// Extruders // Extruders
for (int i = 0; i < HOTENDS; i++) _draw_heater_status(5 + i * 25, i); HOTEND_LOOP() _draw_heater_status(5 + e * 25, e);
// Heated bed // Heated bed
#if HOTENDS < 4 && HAS_TEMP_BED #if HOTENDS < 4 && HAS_TEMP_BED

View file

@ -436,7 +436,7 @@ Temperature::Temperature() { }
void Temperature::updatePID() { void Temperature::updatePID() {
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
for (int e = 0; e < HOTENDS; e++) { HOTEND_LOOP() {
temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e); temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
#if ENABLED(PID_ADD_EXTRUSION_RATE) #if ENABLED(PID_ADD_EXTRUSION_RATE)
last_position[e] = 0; last_position[e] = 0;
@ -465,12 +465,12 @@ int Temperature::getHeaterPower(int heater) {
EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3 EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN ? 2 : 3
}; };
uint8_t fanState = 0; uint8_t fanState = 0;
for (int f = 0; f < HOTENDS; f++) { HOTEND_LOOP() {
if (current_temperature[f] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE)
SBI(fanState, fanBit[f]); SBI(fanState, fanBit[e]);
} }
uint8_t fanDone = 0; uint8_t fanDone = 0;
for (int f = 0; f <= 3; f++) { for (int8_t f = 0; f <= 3; f++) {
int8_t pin = fanPin[f]; int8_t pin = fanPin[f];
if (pin >= 0 && !TEST(fanDone, fanBit[f])) { if (pin >= 0 && !TEST(fanDone, fanBit[f])) {
unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0; unsigned char newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0;
@ -507,10 +507,16 @@ void Temperature::_temp_error(int e, const char* serial_msg, const char* lcd_msg
} }
void Temperature::max_temp_error(uint8_t e) { void Temperature::max_temp_error(uint8_t e) {
_temp_error(e, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP)); #if HOTENDS == 1
UNUSED(e);
#endif
_temp_error(HOTEND_INDEX, PSTR(MSG_T_MAXTEMP), PSTR(MSG_ERR_MAXTEMP));
} }
void Temperature::min_temp_error(uint8_t e) { void Temperature::min_temp_error(uint8_t e) {
_temp_error(e, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP)); #if HOTENDS == 1
UNUSED(e);
#endif
_temp_error(HOTEND_INDEX, PSTR(MSG_T_MINTEMP), PSTR(MSG_ERR_MINTEMP));
} }
float Temperature::get_pid_output(int e) { float Temperature::get_pid_output(int e) {
@ -670,7 +676,7 @@ void Temperature::manage_heater() {
#endif #endif
// Loop through all hotends // Loop through all hotends
for (uint8_t e = 0; e < HOTENDS; e++) { HOTEND_LOOP() {
#if ENABLED(THERMAL_PROTECTION_HOTENDS) #if ENABLED(THERMAL_PROTECTION_HOTENDS)
thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS); thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
@ -877,7 +883,7 @@ void Temperature::updateTemperaturesFromRawValues() {
#if ENABLED(HEATER_0_USES_MAX6675) #if ENABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = read_max6675(); current_temperature_raw[0] = read_max6675();
#endif #endif
for (uint8_t e = 0; e < HOTENDS; e++) { HOTEND_LOOP() {
current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e); current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
} }
current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw); current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
@ -931,7 +937,7 @@ void Temperature::init() {
#endif #endif
// Finish init of mult hotend arrays // Finish init of mult hotend arrays
for (int e = 0; e < HOTENDS; e++) { HOTEND_LOOP() {
// populate with the first value // populate with the first value
maxttemp[e] = maxttemp[0]; maxttemp[e] = maxttemp[0];
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
@ -1138,13 +1144,16 @@ void Temperature::init() {
* their target temperature by a configurable margin. * their target temperature by a configurable margin.
* This is called when the temperature is set. (M104, M109) * This is called when the temperature is set. (M104, M109)
*/ */
void Temperature::start_watching_heater(int e) { void Temperature::start_watching_heater(uint8_t e) {
if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) { #if HOTENDS == 1
watch_target_temp[e] = degHotend(e) + WATCH_TEMP_INCREASE; UNUSED(e);
watch_heater_next_ms[e] = millis() + (WATCH_TEMP_PERIOD) * 1000UL; #endif
if (degHotend(HOTEND_INDEX) < degTargetHotend(HOTEND_INDEX) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
watch_target_temp[HOTEND_INDEX] = degHotend(HOTEND_INDEX) + WATCH_TEMP_INCREASE;
watch_heater_next_ms[HOTEND_INDEX] = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
} }
else else
watch_heater_next_ms[e] = 0; watch_heater_next_ms[HOTEND_INDEX] = 0;
} }
#endif #endif
@ -1222,7 +1231,7 @@ void Temperature::init() {
#endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED #endif // THERMAL_PROTECTION_HOTENDS || THERMAL_PROTECTION_BED
void Temperature::disable_all_heaters() { void Temperature::disable_all_heaters() {
for (int i = 0; i < HOTENDS; i++) setTargetHotend(0, i); HOTEND_LOOP() setTargetHotend(0, e);
setTargetBed(0); setTargetBed(0);
// If all heaters go down then for sure our print job has stopped // If all heaters go down then for sure our print job has stopped

View file

@ -39,13 +39,13 @@
#endif #endif
#if HOTENDS == 1 #if HOTENDS == 1
#define HOTEND_ARG 0 #define HOTEND_LOOP() const uint8_t e = 0;
#define HOTEND_INDEX 0 #define HOTEND_INDEX 0
#define EXTRUDER_ARG 0 #define EXTRUDER_IDX 0
#else #else
#define HOTEND_ARG hotend #define HOTEND_LOOP() for (int8_t e = 0; e < HOTENDS; e++)
#define HOTEND_INDEX e #define HOTEND_INDEX e
#define EXTRUDER_ARG active_extruder #define EXTRUDER_IDX active_extruder
#endif #endif
class Temperature { class Temperature {
@ -245,47 +245,47 @@ class Temperature {
//inline so that there is no performance decrease. //inline so that there is no performance decrease.
//deg=degreeCelsius //deg=degreeCelsius
static float degHotend(uint8_t hotend) { static float degHotend(uint8_t e) {
#if HOTENDS == 1 #if HOTENDS == 1
UNUSED(hotend); UNUSED(e);
#endif #endif
return current_temperature[HOTEND_ARG]; return current_temperature[HOTEND_INDEX];
} }
static float degBed() { return current_temperature_bed; } static float degBed() { return current_temperature_bed; }
#if ENABLED(SHOW_TEMP_ADC_VALUES) #if ENABLED(SHOW_TEMP_ADC_VALUES)
static float rawHotendTemp(uint8_t hotend) { static float rawHotendTemp(uint8_t e) {
#if HOTENDS == 1 #if HOTENDS == 1
UNUSED(hotend); UNUSED(e);
#endif #endif
return current_temperature_raw[HOTEND_ARG]; return current_temperature_raw[HOTEND_INDEX];
} }
static float rawBedTemp() { return current_temperature_bed_raw; } static float rawBedTemp() { return current_temperature_bed_raw; }
#endif #endif
static float degTargetHotend(uint8_t hotend) { static float degTargetHotend(uint8_t e) {
#if HOTENDS == 1 #if HOTENDS == 1
UNUSED(hotend); UNUSED(e);
#endif #endif
return target_temperature[HOTEND_ARG]; return target_temperature[HOTEND_INDEX];
} }
static float degTargetBed() { return target_temperature_bed; } static float degTargetBed() { return target_temperature_bed; }
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0 #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
static void start_watching_heater(int e = 0); static void start_watching_heater(uint8_t e = 0);
#endif #endif
#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0 #if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0
static void start_watching_bed(); static void start_watching_bed();
#endif #endif
static void setTargetHotend(const float& celsius, uint8_t hotend) { static void setTargetHotend(const float& celsius, uint8_t e) {
#if HOTENDS == 1 #if HOTENDS == 1
UNUSED(hotend); UNUSED(e);
#endif #endif
target_temperature[HOTEND_ARG] = celsius; target_temperature[HOTEND_INDEX] = celsius;
#if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0 #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0
start_watching_heater(HOTEND_ARG); start_watching_heater(HOTEND_INDEX);
#endif #endif
} }
@ -296,19 +296,19 @@ class Temperature {
#endif #endif
} }
static bool isHeatingHotend(uint8_t hotend) { static bool isHeatingHotend(uint8_t e) {
#if HOTENDS == 1 #if HOTENDS == 1
UNUSED(hotend); UNUSED(e);
#endif #endif
return target_temperature[HOTEND_ARG] > current_temperature[HOTEND_ARG]; return target_temperature[HOTEND_INDEX] > current_temperature[HOTEND_INDEX];
} }
static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; } static bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
static bool isCoolingHotend(uint8_t hotend) { static bool isCoolingHotend(uint8_t e) {
#if HOTENDS == 1 #if HOTENDS == 1
UNUSED(hotend); UNUSED(e);
#endif #endif
return target_temperature[HOTEND_ARG] < current_temperature[HOTEND_ARG]; return target_temperature[HOTEND_INDEX] < current_temperature[HOTEND_INDEX];
} }
static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; } static bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
@ -338,8 +338,8 @@ class Temperature {
#if ENABLED(AUTOTEMP) #if ENABLED(AUTOTEMP)
if (planner.autotemp_enabled) { if (planner.autotemp_enabled) {
planner.autotemp_enabled = false; planner.autotemp_enabled = false;
if (degTargetHotend(EXTRUDER_ARG) > planner.autotemp_min) if (degTargetHotend(EXTRUDER_IDX) > planner.autotemp_min)
setTargetHotend(0, EXTRUDER_ARG); setTargetHotend(0, EXTRUDER_IDX);
} }
#endif #endif
} }