Add fan percent accessors

This commit is contained in:
Scott Lahteine
2021-04-13 04:00:39 -05:00
parent 4e314ef6d4
commit fd99ea09ec
9 changed files with 32 additions and 33 deletions

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
*/
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);
#if ENABLED(SINGLENOZZLE_STANDBY_FAN)
if (target != active_extruder) {
if (target < EXTRUDERS) singlenozzle_fan_speed[target] = speed;
if (fan != active_extruder) {
if (fan < EXTRUDERS) singlenozzle_fan_speed[fan] = speed;
return;
}
#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)
/**
* Report print fan speed for a target extruder
*/
void Temperature::report_fan_speed(const uint8_t target) {
if (target >= FAN_COUNT) return;
void Temperature::report_fan_speed(const uint8_t fan) {
if (fan >= FAN_COUNT) return;
PORT_REDIRECT(SerialMask::All);
SERIAL_ECHOLNPAIR("M106 P", target, " S", fan_speed[target]);
SERIAL_ECHOLNPAIR("M106 P", fan, " S", fan_speed[fan]);
}
#endif

View File

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