New Controller Fan options and M710 gcode (#17149)
This commit is contained in:
@ -24,60 +24,79 @@
|
||||
|
||||
#if ENABLED(USE_CONTROLLER_FAN)
|
||||
|
||||
#include "controllerfan.h"
|
||||
#include "../module/stepper/indirection.h"
|
||||
#include "../module/temperature.h"
|
||||
|
||||
uint8_t controllerfan_speed;
|
||||
ControllerFan controllerFan;
|
||||
|
||||
void controllerfan_update() {
|
||||
static millis_t lastMotorOn = 0, // Last time a motor was turned on
|
||||
uint8_t ControllerFan::speed;
|
||||
|
||||
#if ENABLED(CONTROLLER_FAN_EDITABLE)
|
||||
controllerFan_settings_t ControllerFan::settings; // {0}
|
||||
#endif
|
||||
|
||||
void ControllerFan::setup() {
|
||||
SET_OUTPUT(CONTROLLER_FAN_PIN);
|
||||
init();
|
||||
}
|
||||
|
||||
void ControllerFan::set_fan_speed(const uint8_t s) {
|
||||
speed = s < (CONTROLLERFAN_SPEED_MIN) ? 0 : s; // Fan OFF below minimum
|
||||
}
|
||||
|
||||
void ControllerFan::update() {
|
||||
static millis_t lastMotorOn = 0, // Last time a motor was turned on
|
||||
nextMotorCheck = 0; // Last time the state was checked
|
||||
const millis_t ms = millis();
|
||||
if (ELAPSED(ms, nextMotorCheck)) {
|
||||
nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
|
||||
|
||||
const bool xory = X_ENABLE_READ() == bool(X_ENABLE_ON) || Y_ENABLE_READ() == bool(Y_ENABLE_ON);
|
||||
#define MOTOR_IS_ON(A,B) (A##_ENABLE_READ() == bool(B##_ENABLE_ON))
|
||||
#define _OR_ENABLED_E(N) || MOTOR_IS_ON(E##N,E)
|
||||
|
||||
const bool
|
||||
xy_motor_on = MOTOR_IS_ON(X,X) || MOTOR_IS_ON(Y,Y)
|
||||
#if HAS_X2_ENABLE
|
||||
|| MOTOR_IS_ON(X2,X)
|
||||
#endif
|
||||
#if HAS_Y2_ENABLE
|
||||
|| MOTOR_IS_ON(Y2,Y)
|
||||
#endif
|
||||
,
|
||||
z_motor_on = MOTOR_IS_ON(Z,Z)
|
||||
#if HAS_Z2_ENABLE
|
||||
|| MOTOR_IS_ON(Z2,Z)
|
||||
#endif
|
||||
#if HAS_Z3_ENABLE
|
||||
|| MOTOR_IS_ON(Z3,Z)
|
||||
#endif
|
||||
#if HAS_Z4_ENABLE
|
||||
|| MOTOR_IS_ON(Z4,Z)
|
||||
#endif
|
||||
;
|
||||
|
||||
// If any of the drivers or the bed are enabled...
|
||||
if (xory || Z_ENABLE_READ() == bool(Z_ENABLE_ON)
|
||||
if (xy_motor_on || z_motor_on
|
||||
#if HAS_HEATED_BED
|
||||
|| thermalManager.temp_bed.soft_pwm_amount > 0
|
||||
#endif
|
||||
#if HAS_X2_ENABLE
|
||||
|| X2_ENABLE_READ() == bool(X_ENABLE_ON)
|
||||
#endif
|
||||
#if HAS_Y2_ENABLE
|
||||
|| Y2_ENABLE_READ() == bool(Y_ENABLE_ON)
|
||||
#endif
|
||||
#if HAS_Z2_ENABLE
|
||||
|| Z2_ENABLE_READ() == bool(Z_ENABLE_ON)
|
||||
#endif
|
||||
#if HAS_Z3_ENABLE
|
||||
|| Z3_ENABLE_READ() == bool(Z_ENABLE_ON)
|
||||
#endif
|
||||
#if HAS_Z4_ENABLE
|
||||
|| Z4_ENABLE_READ() == bool(Z_ENABLE_ON)
|
||||
#endif
|
||||
#if E_STEPPERS
|
||||
#define _OR_ENABLED_E(N) || E##N##_ENABLE_READ() == bool(E_ENABLE_ON)
|
||||
REPEAT(E_STEPPERS, _OR_ENABLED_E)
|
||||
#endif
|
||||
) {
|
||||
lastMotorOn = ms; //... set time to NOW so the fan will turn on
|
||||
}
|
||||
) lastMotorOn = ms; //... set time to NOW so the fan will turn on
|
||||
|
||||
// Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
|
||||
controllerfan_speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : (
|
||||
#ifdef CONTROLLERFAN_SPEED_Z_ONLY
|
||||
xory ? CONTROLLERFAN_SPEED : CONTROLLERFAN_SPEED_Z_ONLY
|
||||
#else
|
||||
CONTROLLERFAN_SPEED
|
||||
#endif
|
||||
// Fan Settings. Set fan > 0:
|
||||
// - If AutoMode is on and steppers have been enabled for CONTROLLERFAN_IDLE_TIME seconds.
|
||||
// - If System is on idle and idle fan speed settings is activated.
|
||||
set_fan_speed(
|
||||
settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + settings.duration * 1000UL)
|
||||
? settings.active_speed : settings.idle_speed
|
||||
);
|
||||
|
||||
// Allow digital or PWM fan output (see M42 handling)
|
||||
WRITE(CONTROLLER_FAN_PIN, controllerfan_speed);
|
||||
analogWrite(pin_t(CONTROLLER_FAN_PIN), controllerfan_speed);
|
||||
WRITE(CONTROLLER_FAN_PIN, speed);
|
||||
analogWrite(pin_t(CONTROLLER_FAN_PIN), speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,4 +21,56 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
void controllerfan_update();
|
||||
#include "../inc/MarlinConfigPre.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t active_speed, // 0-255 (fullspeed); Speed with enabled stepper motors
|
||||
idle_speed; // 0-255 (fullspeed); Speed after idle period with all motors are disabled
|
||||
uint16_t duration; // Duration in seconds for the fan to run after all motors are disabled
|
||||
bool auto_mode; // Default true
|
||||
} controllerFan_settings_t;
|
||||
|
||||
#ifndef CONTROLLERFAN_SPEED_ACTIVE
|
||||
#define CONTROLLERFAN_SPEED_ACTIVE 255
|
||||
#endif
|
||||
#ifndef CONTROLLERFAN_SPEED_IDLE
|
||||
#define CONTROLLERFAN_SPEED_IDLE 0
|
||||
#endif
|
||||
#ifndef CONTROLLERFAN_IDLE_TIME
|
||||
#define CONTROLLERFAN_IDLE_TIME 60
|
||||
#endif
|
||||
|
||||
static constexpr controllerFan_settings_t controllerFan_defaults = {
|
||||
CONTROLLERFAN_SPEED_ACTIVE,
|
||||
CONTROLLERFAN_SPEED_IDLE,
|
||||
CONTROLLERFAN_IDLE_TIME,
|
||||
true
|
||||
};
|
||||
|
||||
#if ENABLED(USE_CONTROLLER_FAN)
|
||||
|
||||
class ControllerFan {
|
||||
private:
|
||||
static uint8_t speed;
|
||||
static void set_fan_speed(const uint8_t s);
|
||||
|
||||
public:
|
||||
#if ENABLED(CONTROLLER_FAN_EDITABLE)
|
||||
static controllerFan_settings_t settings;
|
||||
#else
|
||||
static const controllerFan_settings_t &settings = controllerFan_defaults;
|
||||
#endif
|
||||
static inline bool state() { return speed > 0; }
|
||||
static inline void init() { reset(); }
|
||||
static inline void reset() {
|
||||
#if ENABLED(CONTROLLER_FAN_EDITABLE)
|
||||
settings = controllerFan_defaults;
|
||||
#endif
|
||||
}
|
||||
static void setup();
|
||||
static void update();
|
||||
};
|
||||
|
||||
extern ControllerFan controllerFan;
|
||||
|
||||
#endif
|
||||
|
@ -46,8 +46,8 @@ bool Power::is_power_needed() {
|
||||
HOTEND_LOOP() if (thermalManager.autofan_speed[e]) return true;
|
||||
#endif
|
||||
|
||||
#if ENABLED(AUTO_POWER_CONTROLLERFAN, USE_CONTROLLER_FAN) && HAS_CONTROLLER_FAN
|
||||
if (controllerfan_speed) return true;
|
||||
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
|
||||
if (controllerFan.state()) return true;
|
||||
#endif
|
||||
|
||||
#if ENABLED(AUTO_POWER_CHAMBER_FAN)
|
||||
|
Reference in New Issue
Block a user