Save 92b PROGMEM, 14b SRAM with extruder auto fan

This commit is contained in:
Scott Lahteine 2017-06-06 06:33:06 -05:00
parent c9e3caf928
commit b7dc4d9973

View file

@ -472,8 +472,8 @@ int Temperature::getHeaterPower(int heater) {
#if HAS_AUTO_FAN #if HAS_AUTO_FAN
void Temperature::checkExtruderAutoFans() { void Temperature::checkExtruderAutoFans() {
constexpr int8_t fanPin[] = { E0_AUTO_FAN_PIN, E1_AUTO_FAN_PIN, E2_AUTO_FAN_PIN, E3_AUTO_FAN_PIN, E4_AUTO_FAN_PIN }; static const int8_t fanPin[] PROGMEM = { E0_AUTO_FAN_PIN, E1_AUTO_FAN_PIN, E2_AUTO_FAN_PIN, E3_AUTO_FAN_PIN, E4_AUTO_FAN_PIN };
constexpr int fanBit[] = { static const uint8_t fanBit[] PROGMEM = {
0, 0,
AUTO_1_IS_0 ? 0 : 1, AUTO_1_IS_0 ? 0 : 1,
AUTO_2_IS_0 ? 0 : AUTO_2_IS_1 ? 1 : 2, AUTO_2_IS_0 ? 0 : AUTO_2_IS_1 ? 1 : 2,
@ -482,20 +482,20 @@ int Temperature::getHeaterPower(int heater) {
}; };
uint8_t fanState = 0; uint8_t fanState = 0;
HOTEND_LOOP() { HOTEND_LOOP()
if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE)
SBI(fanState, fanBit[e]); SBI(fanState, pgm_read_byte(&fanBit[e]));
}
uint8_t fanDone = 0; uint8_t fanDone = 0;
for (uint8_t f = 0; f < COUNT(fanPin); f++) { for (uint8_t f = 0; f < COUNT(fanPin); f++) {
int8_t pin = fanPin[f]; int8_t pin = pgm_read_byte(&fanPin[f]);
if (pin >= 0 && !TEST(fanDone, fanBit[f])) { const uint8_t bit = pgm_read_byte(&fanBit[f]);
uint8_t newFanSpeed = TEST(fanState, fanBit[f]) ? EXTRUDER_AUTO_FAN_SPEED : 0; if (pin >= 0 && !TEST(fanDone, bit)) {
uint8_t newFanSpeed = TEST(fanState, bit) ? EXTRUDER_AUTO_FAN_SPEED : 0;
// this idiom allows both digital and PWM fan outputs (see M42 handling). // this idiom allows both digital and PWM fan outputs (see M42 handling).
digitalWrite(pin, newFanSpeed); digitalWrite(pin, newFanSpeed);
analogWrite(pin, newFanSpeed); analogWrite(pin, newFanSpeed);
SBI(fanDone, fanBit[f]); SBI(fanDone, bit);
} }
} }
} }