From 3a16d573fa8b2f568a3a2462db6e8ccffb3bd106 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Sep 2022 00:27:38 -0500 Subject: [PATCH] misc. cleanup, style --- Marlin/Configuration.h | 17 +++++++++------- Marlin/Configuration_adv.h | 4 +--- Marlin/src/feature/leds/leds.cpp | 35 ++++++++++++++------------------ Marlin/src/module/motion.cpp | 10 ++++----- 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 018343ebe2ea..07c6247219b6 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -3251,18 +3251,19 @@ * luminance values can be set from 0 to 255. * For NeoPixel LED an overall brightness parameter is also available. * - * *** CAUTION *** + * === CAUTION === * LED Strips require a MOSFET Chip between PWM lines and LEDs, * as the Arduino cannot handle the current the LEDs will require. * Failure to follow this precaution can destroy your Arduino! + * * NOTE: A separate 5V power supply is required! The NeoPixel LED needs * more current than the Arduino 5V linear regulator can produce. - * *** CAUTION *** * - * LED Type. Enable only one of the following two options. - * Require PWM frequency between 50 <> 100hz (Check hal or variant settings) - * Use FAST_PWM_FAN if possible, fans can be noisy. + * Requires PWM frequency between 50 <> 100Hz (Check HAL or variant) + * Use FAST_PWM_FAN, if possible, to reduce fan noise. */ + +// LED Type. Enable only one of the following two options: //#define RGB_LED //#define RGBW_LED @@ -3271,8 +3272,10 @@ //#define RGB_LED_G_PIN 43 //#define RGB_LED_B_PIN 35 //#define RGB_LED_W_PIN -1 - #define RGB_STARTUP_TEST // If pwm pins, fade between all colors if not only switch. - #define RGB_STARTUP_TEST_SLOWING_MS 10 // (ms) Reduce or increase fading speed. + //#define RGB_STARTUP_TEST // For PWM pins, fade between all colors + #if ENABLED(RGB_STARTUP_TEST) + #define RGB_STARTUP_TEST_INNER_MS 10 // (ms) Reduce or increase fading speed + #endif #endif // Support for Adafruit NeoPixel LED driver diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index d59b8ecbaa27..70e8a98a7695 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -870,12 +870,10 @@ #define HOMING_BUMP_DIVISOR { 2, 2, 4 } // Re-Bump Speed Divisor (Divides the Homing Feedrate) //#define HOMING_BACKOFF_POST_MM { 2, 2, 2 } // (linear=mm, rotational=°) Backoff from endstops after homing +//#define XY_COUNTERPART_BACKOFF_MM 0 // (mm) Backoff X after homing Y, and vice-versa //#define QUICK_HOME // If G28 contains XY do a diagonal move first //#define HOME_Y_BEFORE_X // If G28 contains XY home Y before X -#if ENABLED(HOME_Y_BEFORE_X) - #define OPPOSITE_AXIS_BACKOFF_MM 10 // (linear=mm, rotational=°) Backoff X before Y homing or inverse (prevent colision with opposite axis endstop) -#endif //#define HOME_Z_FIRST // Home Z first. Requires a Z-MIN endstop (not a probe). //#define CODEPENDENT_XY_HOMING // If X/Y can't home without homing Y/X first diff --git a/Marlin/src/feature/leds/leds.cpp b/Marlin/src/feature/leds/leds.cpp index 5a1b1ceba73e..2cf040925625 100644 --- a/Marlin/src/feature/leds/leds.cpp +++ b/Marlin/src/feature/leds/leds.cpp @@ -69,32 +69,27 @@ void LEDLights::setup() { #if ENABLED(RGBW_LED) if (PWM_PIN(RGB_LED_W_PIN)) SET_PWM(RGB_LED_W_PIN); else SET_OUTPUT(RGB_LED_W_PIN); #endif - #ifdef RGB_STARTUP_TEST + #if ENABLED(RGB_STARTUP_TEST) int8_t led_pin_count = 0; - uint16_t led_pwm; - if (PWM_PIN(RGB_LED_R_PIN) && PWM_PIN(RGB_LED_G_PIN) && PWM_PIN(RGB_LED_B_PIN)) led_pin_count = 3; + if (PWM_PIN(RGB_LED_R_PIN) && PWM_PIN(RGB_LED_G_PIN) && PWM_PIN(RGB_LED_B_PIN)) led_pin_count = 3; #if ENABLED(RGBW_LED) if (PWM_PIN(RGB_LED_W_PIN) && led_pin_count) led_pin_count++; #endif - //Startup animation - if (led_pin_count){ - for (uint8_t i = 0; i < led_pin_count; i++) { - for (uint8_t b = 0; b < 201; b++) { - if (b <= 100) led_pwm = b; - if (b > 100) --led_pwm ; - LIMIT(led_pwm,0,100); - if (i == 0 && PWM_PIN(RGB_LED_R_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_R_PIN), led_pwm); else WRITE(RGB_LED_R_PIN, b < 100 ? HIGH : LOW); - if (i == 0 && PWM_PIN(RGB_LED_G_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_G_PIN), led_pwm); else WRITE(RGB_LED_G_PIN, b < 100 ? HIGH : LOW); - if (i == 0 && PWM_PIN(RGB_LED_B_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_B_PIN), led_pwm); else WRITE(RGB_LED_B_PIN, b < 100 ? HIGH : LOW); - #if ENABLED(RGBW_LED) - if (i == 0 && PWM_PIN(RGB_LED_W_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_W_PIN), led_pwm); else WRITE(RGB_LED_W_PIN, b < 100 ? HIGH : LOW); - #endif - delay(RGB_STARTUP_TEST_SLOWING_MS); - } + // Startup animation + LOOP_L_N(i, led_pin_count) { + LOOP_LE_N(b, 200) { + const uint16_t led_pwm = b <= 100 ? b : 200 - b; + if (i == 0 && PWM_PIN(RGB_LED_R_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_R_PIN), led_pwm); else WRITE(RGB_LED_R_PIN, b < 100 ? HIGH : LOW); + if (i == 0 && PWM_PIN(RGB_LED_G_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_G_PIN), led_pwm); else WRITE(RGB_LED_G_PIN, b < 100 ? HIGH : LOW); + if (i == 0 && PWM_PIN(RGB_LED_B_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_B_PIN), led_pwm); else WRITE(RGB_LED_B_PIN, b < 100 ? HIGH : LOW); + #if ENABLED(RGBW_LED) + if (i == 0 && PWM_PIN(RGB_LED_W_PIN)) hal.set_pwm_duty(pin_t(RGB_LED_W_PIN), led_pwm); else WRITE(RGB_LED_W_PIN, b < 100 ? HIGH : LOW); + #endif + delay(RGB_STARTUP_TEST_INNER_MS); } - delay(1000); } - #endif//RGB_STARTUP_TEST + if (led_pin_count) delay(1000); + #endif // RGB_STARTUP_TEST #endif TERN_(NEOPIXEL_LED, neo.init()); TERN_(PCA9533, PCA9533_init()); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 8040cd9094ef..1e2620f31aab 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -1997,11 +1997,11 @@ void prepare_line_to_destination() { // // Back away to prevent opposite endstop damage // - #if !defined(SENSORLESS_BACKOFF_MM) && defined(OPPOSITE_AXIS_BACKOFF_MM) - if (axis == Y_AXIS || axis == X_AXIS ){ - const AxisEnum opposite_axis = axis == Y_AXIS ? X_AXIS : Y_AXIS ; - const float backoff_length = -ABS(OPPOSITE_AXIS_BACKOFF_MM) * home_dir(opposite_axis); - do_homing_move(opposite_axis, backoff_length, homing_feedrate(opposite_axis)); + #if !defined(SENSORLESS_BACKOFF_MM) && XY_COUNTERPART_BACKOFF_MM + if (axis == X_AXIS || axis == Y_AXIS) { + const AxisEnum opposite_axis = axis == X_AXIS ? Y_AXIS : X_AXIS; + const float backoff_length = -ABS(XY_COUNTERPART_BACKOFF_MM) * home_dir(opposite_axis); + do_homing_move(opposite_axis, backoff_length, homing_feedrate(opposite_axis)); } #endif