🩹 Relocate Fan conditionals, sanity-checks (#25731)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Jason Smith 2023-04-22 20:27:01 -07:00 committed by GitHub
parent 95cfc98fe4
commit ce85b98db4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 49 deletions

View file

@ -1233,17 +1233,6 @@
#define CANNOT_EMBED_CONFIGURATION defined(__AVR__)
#endif
// Fan Kickstart
#if FAN_KICKSTART_TIME && !defined(FAN_KICKSTART_POWER)
#define FAN_KICKSTART_POWER 180
#endif
#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255
#define CALC_FAN_SPEED(f) (f ?: FAN_OFF_PWM)
#else
#define CALC_FAN_SPEED(f) (f ? map(f, 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
#endif
// Input shaping
#if EITHER(INPUT_SHAPING_X, INPUT_SHAPING_Y)
#define HAS_ZV_SHAPING 1

View file

@ -2719,37 +2719,8 @@
#define HAS_FAN 1
#endif
/**
* Part Cooling fan multipliexer
*/
#if PIN_EXISTS(FANMUX0)
#define HAS_FANMUX 1
#endif
/**
* MIN/MAX fan PWM scaling
*/
#ifndef FAN_OFF_PWM
#define FAN_OFF_PWM 0
#endif
#ifndef FAN_MIN_PWM
#if FAN_OFF_PWM > 0
#define FAN_MIN_PWM (FAN_OFF_PWM + 1)
#else
#define FAN_MIN_PWM 0
#endif
#endif
#ifndef FAN_MAX_PWM
#define FAN_MAX_PWM 255
#endif
#if FAN_MIN_PWM < 0 || FAN_MIN_PWM > 255
#error "FAN_MIN_PWM must be a value from 0 to 255."
#elif FAN_MAX_PWM < 0 || FAN_MAX_PWM > 255
#error "FAN_MAX_PWM must be a value from 0 to 255."
#elif FAN_MIN_PWM > FAN_MAX_PWM
#error "FAN_MIN_PWM must be less than or equal to FAN_MAX_PWM."
#elif FAN_OFF_PWM > FAN_MIN_PWM
#error "FAN_OFF_PWM must be less than or equal to FAN_MIN_PWM."
#define HAS_FANMUX 1 // Part Cooling fan multipliexer
#endif
/**
@ -2773,6 +2744,35 @@
#endif
#endif
/**
* MIN/MAX fan PWM scaling
*/
#if EITHER(HAS_FAN, USE_CONTROLLER_FAN)
#ifndef FAN_OFF_PWM
#define FAN_OFF_PWM 0
#endif
#ifndef FAN_MIN_PWM
#if FAN_OFF_PWM > 0
#define FAN_MIN_PWM (FAN_OFF_PWM + 1)
#else
#define FAN_MIN_PWM 0
#endif
#endif
#ifndef FAN_MAX_PWM
#define FAN_MAX_PWM 255
#endif
#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255
#define CALC_FAN_SPEED(f) (f ?: FAN_OFF_PWM)
#else
#define CALC_FAN_SPEED(f) (f ? map(f, 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
#endif
#endif
// Fan Kickstart
#if FAN_KICKSTART_TIME && !defined(FAN_KICKSTART_POWER)
#define FAN_KICKSTART_POWER 180
#endif
// Servos
#if PIN_EXISTS(SERVO0) && NUM_SERVOS > 0
#define HAS_SERVO_0 1

View file

@ -1560,11 +1560,11 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
/**
* Part-Cooling Fan Multiplexer requirements
*/
#if PIN_EXISTS(FANMUX1)
#if !HAS_FANMUX
#error "FANMUX0_PIN must be set before FANMUX1_PIN can be set."
#endif
#elif PIN_EXISTS(FANMUX2)
#if HAS_FANMUX && !HAS_FAN0
#error "FAN0_PIN must be defined to use Fan Multiplexing."
#elif PIN_EXISTS(FANMUX1) && !PIN_EXISTS(FANMUX0)
#error "FANMUX0_PIN must be set before FANMUX1_PIN can be set."
#elif PIN_EXISTS(FANMUX2) && !PINS_EXIST(FANMUX0, FANMUX1)
#error "FANMUX0_PIN and FANMUX1_PIN must be set before FANMUX2_PIN can be set."
#endif
@ -1608,7 +1608,7 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#endif
#if ENABLED(MPC_INCLUDE_FAN)
#if FAN_COUNT < 1
#if !HAS_FAN
#error "MPC_INCLUDE_FAN requires at least one fan."
#endif
#if FAN_COUNT < HOTENDS
@ -1627,8 +1627,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#error "To use BED_LIMIT_SWITCHING you must disable PIDTEMPBED."
#endif
// Fan Kickstart
#if FAN_KICKSTART_TIME && defined(FAN_KICKSTART_POWER) && !WITHIN(FAN_KICKSTART_POWER, 64, 255)
// Fan Kickstart power
#if FAN_KICKSTART_TIME && !WITHIN(FAN_KICKSTART_POWER, 64, 255)
#error "FAN_KICKSTART_POWER must be an integer from 64 to 255."
#endif
@ -2454,6 +2454,21 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#endif
#endif
/**
* Make sure FAN_*_PWM values are sensible
*/
#if EITHER(HAS_FAN, USE_CONTROLLER_FAN)
#if !WITHIN(FAN_MIN_PWM, 0, 255)
#error "FAN_MIN_PWM must be a value from 0 to 255."
#elif !WITHIN(FAN_MAX_PWM, 0, 255)
#error "FAN_MAX_PWM must be a value from 0 to 255."
#elif FAN_MIN_PWM > FAN_MAX_PWM
#error "FAN_MIN_PWM must be less than or equal to FAN_MAX_PWM."
#elif FAN_OFF_PWM > FAN_MIN_PWM
#error "FAN_OFF_PWM must be less than or equal to FAN_MIN_PWM."
#endif
#endif
#ifdef REDUNDANT_PART_COOLING_FAN
#if FAN_COUNT < 2
#error "REDUNDANT_PART_COOLING_FAN requires a board with at least two PWM fans."