Browse Source

Add fan percent accessors

vanilla_fb_2.0.x
Scott Lahteine 3 years ago
parent
commit
fd99ea09ec
  1. 2
      Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
  2. 7
      Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
  3. 2
      Marlin/src/lcd/dogm/status_screen_DOGM.cpp
  4. 6
      Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp
  5. 2
      Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp
  6. 2
      Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp
  7. 4
      Marlin/src/lcd/extui/ui_api.cpp
  8. 20
      Marlin/src/module/temperature.cpp
  9. 20
      Marlin/src/module/temperature.h

2
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp

@ -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

7
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp

@ -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

2
Marlin/src/lcd/dogm/status_screen_DOGM.cpp

@ -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);
} }
} }

6
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp

@ -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);

2
Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp

@ -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);
} }

2
Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp

@ -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);
} }

4
Marlin/src/lcd/extui/ui_api.cpp

@ -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;

20
Marlin/src/module/temperature.cpp

@ -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

20
Marlin/src/module/temperature.h

@ -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];

Loading…
Cancel
Save