Add fan percent accessors

This commit is contained in:
Scott Lahteine 2021-04-13 04:00:39 -05:00 committed by Scott Lahteine
parent ed477abbd5
commit 562f3e43bc
9 changed files with 32 additions and 33 deletions

View file

@ -944,7 +944,7 @@ void MarlinUI::draw_status_screen() {
#if ENABLED(ADAPTIVE_FAN_SLOWING) #if ENABLED(ADAPTIVE_FAN_SLOWING)
else { c = '*'; spd = thermalManager.scaledFanSpeed(0, spd); } else { c = '*'; spd = thermalManager.scaledFanSpeed(0, spd); }
#endif #endif
per = thermalManager.fanPercent(spd); per = thermalManager.pwmToPercent(spd);
} }
else else
#endif #endif

View file

@ -750,7 +750,7 @@ void MarlinUI::draw_status_screen() {
#if HOTENDS > 2 #if HOTENDS > 2
_draw_heater_status(H_E2, "HE3", blink); // Hotend 3 Temperature _draw_heater_status(H_E2, "HE3", blink); // Hotend 3 Temperature
#endif #endif
#endif // HOTENDS <= 1 #endif
#if HAS_HEATED_BED #if HAS_HEATED_BED
#if HAS_LEVELING #if HAS_LEVELING
@ -758,16 +758,15 @@ void MarlinUI::draw_status_screen() {
#else #else
_draw_heater_status(H_BED, "BED", blink); _draw_heater_status(H_BED, "BED", blink);
#endif #endif
#endif // HAS_HEATED_BED #endif
#if HAS_FAN #if HAS_FAN
uint16_t spd = thermalManager.fan_speed[0]; uint16_t spd = thermalManager.fan_speed[0];
#if ENABLED(ADAPTIVE_FAN_SLOWING) #if ENABLED(ADAPTIVE_FAN_SLOWING)
if (!blink) spd = thermalManager.scaledFanSpeed(0, spd); if (!blink) spd = thermalManager.scaledFanSpeed(0, spd);
#endif #endif
uint16_t per = thermalManager.pwmToPercent(spd);
uint16_t per = thermalManager.fanPercent(spd);
#if HOTENDS < 2 #if HOTENDS < 2
#define FANX 11 #define FANX 11
#else #else

View file

@ -696,7 +696,7 @@ void MarlinUI::draw_status_screen() {
c = '*'; c = '*';
} }
#endif #endif
lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.fanPercent(spd))); lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.pwmToPercent(spd)));
lcd_put_wchar(c); lcd_put_wchar(c);
} }
} }

View file

@ -733,14 +733,12 @@ void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) {
TERN_(HAS_MULTI_HOTEND, draw_extruder_2_temp(extruder_2_temp, extruder_2_target, forceUpdate)); TERN_(HAS_MULTI_HOTEND, draw_extruder_2_temp(extruder_2_temp, extruder_2_target, forceUpdate));
TERN_(HAS_HEATED_BED, draw_bed_temp(bed_temp, bed_target, forceUpdate)); TERN_(HAS_HEATED_BED, draw_bed_temp(bed_temp, bed_target, forceUpdate));
uint16_t spd = thermalManager.fan_speed[0]; uint8_t spd = thermalManager.fan_speed[0];
#if ENABLED(ADAPTIVE_FAN_SLOWING) #if ENABLED(ADAPTIVE_FAN_SLOWING)
if (!blink && thermalManager.fan_speed_scaler[0] < 128) if (!blink && thermalManager.fan_speed_scaler[0] < 128)
spd = thermalManager.scaledFanSpeed(0, spd); spd = thermalManager.scaledFanSpeed(0, spd);
#endif #endif
draw_fan_speed(thermalManager.pwmToPercent(spd));
draw_fan_speed(thermalManager.fanPercent(spd));
// Draw elapsed/remaining time // Draw elapsed/remaining time
const bool show_remaining = ENABLED(SHOW_REMAINING_TIME) && (DISABLED(ROTATE_PROGRESS_DISPLAY) || blink); const bool show_remaining = ENABLED(SHOW_REMAINING_TIME) && (DISABLED(ROTATE_PROGRESS_DISPLAY) || blink);

View file

@ -236,7 +236,7 @@ void disp_bed_temp() {
} }
void disp_fan_speed() { void disp_fan_speed() {
sprintf_P(public_buf_l, PSTR("%d%%"), thermalManager.fanPercent(thermalManager.fan_speed[0])); sprintf_P(public_buf_l, PSTR("%d%%"), thermalManager.fanSpeedPercent(0));
lv_label_set_text(labelFan, public_buf_l); lv_label_set_text(labelFan, public_buf_l);
} }

View file

@ -241,7 +241,7 @@ void lv_draw_ready_print() {
lv_obj_align(labelBedTarget, buttonBedstate, LV_ALIGN_CENTER, 0, TARGET_LABEL_MOD_Y); lv_obj_align(labelBedTarget, buttonBedstate, LV_ALIGN_CENTER, 0, TARGET_LABEL_MOD_Y);
#endif #endif
sprintf_P(buf, PSTR("%d%%"), thermalManager.fanPercent(thermalManager.fan_speed[0])); sprintf_P(buf, PSTR("%d%%"), (int)thermalManager.fanSpeedPercent(0));
lv_label_set_text(labelFan, buf); lv_label_set_text(labelFan, buf);
lv_obj_align(labelFan, buttonFanstate, LV_ALIGN_CENTER, 0, LABEL_MOD_Y); lv_obj_align(labelFan, buttonFanstate, LV_ALIGN_CENTER, 0, LABEL_MOD_Y);
} }

View file

@ -297,7 +297,7 @@ namespace ExtUI {
float getTargetFan_percent(const fan_t fan) { float getTargetFan_percent(const fan_t fan) {
#if HAS_FAN #if HAS_FAN
return thermalManager.fanPercent(thermalManager.fan_speed[fan - FAN0]); return thermalManager.fanSpeedPercent(fan - FAN0);
#else #else
UNUSED(fan); UNUSED(fan);
return 0; return 0;
@ -306,7 +306,7 @@ namespace ExtUI {
float getActualFan_percent(const fan_t fan) { float getActualFan_percent(const fan_t fan) {
#if HAS_FAN #if HAS_FAN
return thermalManager.fanPercent(thermalManager.scaledFanSpeed(fan - FAN0)); return thermalManager.scaledFanSpeedPercent(fan - FAN0);
#else #else
UNUSED(fan); UNUSED(fan);
return 0; return 0;

View file

@ -315,34 +315,34 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY,
/** /**
* Set the print fan speed for a target extruder * Set the print fan speed for a target extruder
*/ */
void Temperature::set_fan_speed(uint8_t target, uint16_t speed) { void Temperature::set_fan_speed(uint8_t fan, uint16_t speed) {
NOMORE(speed, 255U); NOMORE(speed, 255U);
#if ENABLED(SINGLENOZZLE_STANDBY_FAN) #if ENABLED(SINGLENOZZLE_STANDBY_FAN)
if (target != active_extruder) { if (fan != active_extruder) {
if (target < EXTRUDERS) singlenozzle_fan_speed[target] = speed; if (fan < EXTRUDERS) singlenozzle_fan_speed[fan] = speed;
return; return;
} }
#endif #endif
TERN_(SINGLENOZZLE, target = 0); // Always use fan index 0 with SINGLENOZZLE TERN_(SINGLENOZZLE, fan = 0); // Always use fan index 0 with SINGLENOZZLE
if (target >= FAN_COUNT) return; if (fan >= FAN_COUNT) return;
fan_speed[target] = speed; fan_speed[fan] = speed;
TERN_(REPORT_FAN_CHANGE, report_fan_speed(target)); TERN_(REPORT_FAN_CHANGE, report_fan_speed(fan));
} }
#if ENABLED(REPORT_FAN_CHANGE) #if ENABLED(REPORT_FAN_CHANGE)
/** /**
* Report print fan speed for a target extruder * Report print fan speed for a target extruder
*/ */
void Temperature::report_fan_speed(const uint8_t target) { void Temperature::report_fan_speed(const uint8_t fan) {
if (target >= FAN_COUNT) return; if (fan >= FAN_COUNT) return;
PORT_REDIRECT(SerialMask::All); PORT_REDIRECT(SerialMask::All);
SERIAL_ECHOLNPAIR("M106 P", target, " S", fan_speed[target]); SERIAL_ECHOLNPAIR("M106 P", fan, " S", fan_speed[fan]);
} }
#endif #endif

View file

@ -553,10 +553,10 @@ class Temperature {
static uint8_t fan_speed[FAN_COUNT]; static uint8_t fan_speed[FAN_COUNT];
#define FANS_LOOP(I) LOOP_L_N(I, FAN_COUNT) #define FANS_LOOP(I) LOOP_L_N(I, FAN_COUNT)
static void set_fan_speed(const uint8_t target, const uint16_t speed); static void set_fan_speed(const uint8_t fan, const uint16_t speed);
#if ENABLED(REPORT_FAN_CHANGE) #if ENABLED(REPORT_FAN_CHANGE)
static void report_fan_speed(const uint8_t target); static void report_fan_speed(const uint8_t fan);
#endif #endif
#if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE) #if EITHER(PROBING_FANS_OFF, ADVANCED_PAUSE_FANS_PAUSE)
@ -564,21 +564,23 @@ class Temperature {
static uint8_t saved_fan_speed[FAN_COUNT]; static uint8_t saved_fan_speed[FAN_COUNT];
#endif #endif
static constexpr inline uint8_t fanPercent(const uint8_t speed) { return ui8_to_percent(speed); }
#if ENABLED(ADAPTIVE_FAN_SLOWING) #if ENABLED(ADAPTIVE_FAN_SLOWING)
static uint8_t fan_speed_scaler[FAN_COUNT]; static uint8_t fan_speed_scaler[FAN_COUNT];
#endif #endif
static inline uint8_t scaledFanSpeed(const uint8_t target, const uint8_t fs) { static inline uint8_t scaledFanSpeed(const uint8_t fan, const uint8_t fs) {
UNUSED(target); // Potentially unused! UNUSED(fan); // Potentially unused!
return (fs * uint16_t(TERN(ADAPTIVE_FAN_SLOWING, fan_speed_scaler[target], 128))) >> 7; return (fs * uint16_t(TERN(ADAPTIVE_FAN_SLOWING, fan_speed_scaler[fan], 128))) >> 7;
} }
static inline uint8_t scaledFanSpeed(const uint8_t target) { static inline uint8_t scaledFanSpeed(const uint8_t fan) {
return scaledFanSpeed(target, fan_speed[target]); return scaledFanSpeed(fan, fan_speed[fan]);
} }
static constexpr inline uint8_t pwmToPercent(const uint8_t speed) { return ui8_to_percent(speed); }
static inline uint8_t fanSpeedPercent(const uint8_t fan) { return ui8_to_percent(fan_speed[fan]); }
static inline uint8_t scaledFanSpeedPercent(const uint8_t fan) { return ui8_to_percent(scaledFanSpeed(fan)); }
#if ENABLED(EXTRA_FAN_SPEED) #if ENABLED(EXTRA_FAN_SPEED)
typedef struct { uint8_t saved, speed; } extra_fan_t; typedef struct { uint8_t saved, speed; } extra_fan_t;
static extra_fan_t extra_fan_speed[FAN_COUNT]; static extra_fan_t extra_fan_speed[FAN_COUNT];