Skip to content

Commit

Permalink
🚸 Case Light, LED menus for E3V2 DWIN Enhanced UI (MarlinFirmware#23590)
Browse files Browse the repository at this point in the history
  • Loading branch information
GHGiampy authored and Omkar Dhekne committed Mar 25, 2024
1 parent abb0c4a commit 8815520
Show file tree
Hide file tree
Showing 19 changed files with 278 additions and 112 deletions.
5 changes: 3 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@
//#define PS_OFF_SOUND // Beep 1s when power off
#define PSU_ACTIVE_STATE LOW // Set 'LOW' for ATX, 'HIGH' for X-Box

//#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80
//#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power
//#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80
//#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power
//#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay

//#define POWER_OFF_TIMER // Enable M81 D<seconds> to power off after a delay
//#define POWER_OFF_WAIT_FOR_COOLDOWN // Enable M81 S to power off only after cooldown
Expand Down
54 changes: 27 additions & 27 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,6 @@

#if HAS_MARLINUI_MENU

// Add Probe Z Offset calibration to the Z Probe Offsets menu
#if BOTH(HAS_BED_PROBE, AUTO_BED_LEVELING_BILINEAR)
// Add calibration in the Probe Offsets menu to compensate for X-axis twist.
//#define X_AXIS_TWIST_COMPENSATION
Expand All @@ -1319,32 +1318,6 @@
// BACK menu items keep the highlight at the top
//#define TURBO_BACK_MENU_ITEM

/**
* LED Control Menu
* Add LED Control to the LCD menu
*/
//#define LED_CONTROL_MENU
#if ENABLED(LED_CONTROL_MENU)
#define LED_COLOR_PRESETS // Enable the Preset Color menu option
//#define NEO2_COLOR_PRESETS // Enable a second NeoPixel Preset Color menu option
#if ENABLED(LED_COLOR_PRESETS)
#define LED_USER_PRESET_RED 255 // User defined RED value
#define LED_USER_PRESET_GREEN 128 // User defined GREEN value
#define LED_USER_PRESET_BLUE 0 // User defined BLUE value
#define LED_USER_PRESET_WHITE 255 // User defined WHITE value
#define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity
//#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
#endif
#if ENABLED(NEO2_COLOR_PRESETS)
#define NEO2_USER_PRESET_RED 255 // User defined RED value
#define NEO2_USER_PRESET_GREEN 128 // User defined GREEN value
#define NEO2_USER_PRESET_BLUE 0 // User defined BLUE value
#define NEO2_USER_PRESET_WHITE 255 // User defined WHITE value
#define NEO2_USER_PRESET_BRIGHTNESS 255 // User defined intensity
//#define NEO2_USER_PRESET_STARTUP // Have the printer display the user preset color on startup for the second strip
#endif
#endif

// Insert a menu for preheating at the top level to allow for quick access
//#define PREHEAT_SHORTCUT_MENU_ITEM

Expand Down Expand Up @@ -1376,6 +1349,33 @@

// Show the E position (filament used) during printing
//#define LCD_SHOW_E_TOTAL

/**
* LED Control Menu
* Add LED Control to the LCD menu
*/
//#define LED_CONTROL_MENU
#if ENABLED(LED_CONTROL_MENU)
#define LED_COLOR_PRESETS // Enable the Preset Color menu option
//#define NEO2_COLOR_PRESETS // Enable a second NeoPixel Preset Color menu option
#if ENABLED(LED_COLOR_PRESETS)
#define LED_USER_PRESET_RED 255 // User defined RED value
#define LED_USER_PRESET_GREEN 128 // User defined GREEN value
#define LED_USER_PRESET_BLUE 0 // User defined BLUE value
#define LED_USER_PRESET_WHITE 255 // User defined WHITE value
#define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity
//#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
#endif
#if ENABLED(NEO2_COLOR_PRESETS)
#define NEO2_USER_PRESET_RED 255 // User defined RED value
#define NEO2_USER_PRESET_GREEN 128 // User defined GREEN value
#define NEO2_USER_PRESET_BLUE 0 // User defined BLUE value
#define NEO2_USER_PRESET_WHITE 255 // User defined WHITE value
#define NEO2_USER_PRESET_BRIGHTNESS 255 // User defined intensity
//#define NEO2_USER_PRESET_STARTUP // Have the printer display the user preset color on startup for the second strip
#endif
#endif

#endif

// LCD Print Progress options
Expand Down
12 changes: 11 additions & 1 deletion Marlin/src/feature/caselight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ void CaseLight::update(const bool sflag) {
#endif

#if CASE_LIGHT_IS_COLOR_LED
leds.set_color(LEDColor(color.r, color.g, color.b OPTARG(HAS_WHITE_LED, color.w) OPTARG(NEOPIXEL_LED, n10ct)));
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
if (on)
// Use current color of (NeoPixel) leds and new brightness level
leds.set_color(LEDColor(leds.color.r, leds.color.g, leds.color.b OPTARG(HAS_WHITE_LED, leds.color.w) OPTARG(NEOPIXEL_LED, n10ct)));
else
// Switch off leds
leds.set_off();
#else
// Use CaseLight color (CASE_LIGHT_DEFAULT_COLOR) and new brightness level
leds.set_color(LEDColor(color.r, color.g, color.b OPTARG(HAS_WHITE_LED, color.w) OPTARG(NEOPIXEL_LED, n10ct)));
#endif
#else // !CASE_LIGHT_IS_COLOR_LED

#if CASELIGHT_USES_BRIGHTNESS
Expand Down
4 changes: 0 additions & 4 deletions Marlin/src/feature/caselight.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
#include "leds/leds.h" // for LEDColor
#endif

#if NONE(CASE_LIGHT_NO_BRIGHTNESS, CASE_LIGHT_IS_COLOR_LED) || ENABLED(CASE_LIGHT_USE_NEOPIXEL)
#define CASELIGHT_USES_BRIGHTNESS 1
#endif

class CaseLight {
public:
static bool on;
Expand Down
12 changes: 10 additions & 2 deletions Marlin/src/feature/leds/leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "pca9533.h"
#endif

#if ENABLED(CASE_LIGHT_USE_RGB_LED)
#if EITHER(CASE_LIGHT_USE_RGB_LED, CASE_LIGHT_USE_NEOPIXEL)
#include "../../feature/caselight.h"
#endif

Expand Down Expand Up @@ -95,6 +95,10 @@ void LEDLights::set_color(const LEDColor &incol
#endif
#endif

#if BOTH(CASE_LIGHT_MENU, CASE_LIGHT_USE_NEOPIXEL)
// Update brightness only if caselight is ON or switching leds off
if (caselight.on || incol.is_off())
#endif
neo.set_brightness(incol.i);

#if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
Expand All @@ -106,6 +110,10 @@ void LEDLights::set_color(const LEDColor &incol
}
#endif

#if BOTH(CASE_LIGHT_MENU, CASE_LIGHT_USE_NEOPIXEL)
// Update color only if caselight is ON or switching leds off
if (caselight.on || incol.is_off())
#endif
neo.set_color(neocolor);

#endif
Expand Down Expand Up @@ -150,7 +158,7 @@ void LEDLights::set_color(const LEDColor &incol
void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
#endif

#ifdef LED_BACKLIGHT_TIMEOUT
#if LED_POWEROFF_TIMEOUT > 0

millis_t LEDLights::led_off_time; // = 0

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/leds/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ class LEDLights {
static void update() { set_color(color); }
#endif

#ifdef LED_BACKLIGHT_TIMEOUT
#if LED_POWEROFF_TIMEOUT > 0
private:
static millis_t led_off_time;
public:
static void reset_timeout(const millis_t &ms) {
led_off_time = ms + LED_BACKLIGHT_TIMEOUT;
led_off_time = ms + LED_POWEROFF_TIMEOUT;
if (!lights_on) update();
}
static void update_timeout(const bool power_on);
Expand Down
4 changes: 1 addition & 3 deletions Marlin/src/feature/leds/neopixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
* NeoPixel support
*/

#define MAX_NEOPIXELS 127

#ifndef _NEOPIXEL_INCLUDE_
#error "Always include 'leds.h' and not 'neopixel.h' directly."
#endif
Expand Down Expand Up @@ -68,7 +66,7 @@
// Types
// ------------------------

typedef IF<(MAX_NEOPIXELS > 127), int16_t, int8_t>::type pixel_index_t;
typedef IF<(TERN0(NEOPIXEL_LED, NEOPIXEL_PIXELS > 127)), int16_t, int8_t>::type pixel_index_t;

// ------------------------
// Classes
Expand Down
41 changes: 8 additions & 33 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@

// This helps to implement HAS_ADC_BUTTONS menus
#define REVERSE_MENU_DIRECTION
#define ENCODER_PULSES_PER_STEP 1
#define ENCODER_STEPS_PER_MENU_ITEM 1
#define STD_ENCODER_PULSES_PER_STEP 1
#define STD_ENCODER_STEPS_PER_MENU_ITEM 1
#define ENCODER_FEEDRATE_DEADZONE 2

#elif ENABLED(ZONESTAR_12864LCD)
Expand All @@ -97,7 +97,7 @@

#elif ENABLED(RADDS_DISPLAY)
#define IS_ULTIPANEL 1
#define ENCODER_PULSES_PER_STEP 2
#define STD_ENCODER_PULSES_PER_STEP 2

#elif ANY(miniVIKI, VIKI2, WYH_L12864, ELB_FULL_GRAPHIC_CONTROLLER, AZSMZ_12864)

Expand Down Expand Up @@ -158,44 +158,19 @@
#define IS_RRD_SC 1
#define U8GLIB_SH1106

#define LED_CONTROL_MENU
#define NEOPIXEL_LED
#undef NEOPIXEL_TYPE
#define NEOPIXEL_TYPE NEO_RGB
#if NEOPIXEL_PIXELS < 3
#undef NEOPIXELS_PIXELS
#define NEOPIXEL_PIXELS 3
#endif
#ifndef NEOPIXEL_BRIGHTNESS
#define NEOPIXEL_BRIGHTNESS 127
#endif

#if ENABLED(PSU_CONTROL)
#define LED_BACKLIGHT_TIMEOUT 10000
#endif

#elif ANY(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1, FYSETC_GENERIC_12864_1_1)

#define FYSETC_MINI_12864
#define DOGLCD
#define IS_ULTIPANEL 1
#define LED_COLORS_REDUCE_GREEN
#if ENABLED(PSU_CONTROL) && EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
#define LED_BACKLIGHT_TIMEOUT 10000
#endif

// Require LED backlighting enabled
#if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0)
#define RGB_LED
#elif ENABLED(FYSETC_MINI_12864_2_1)
#define LED_CONTROL_MENU
#define NEOPIXEL_LED
#undef NEOPIXEL_TYPE
#define NEOPIXEL_TYPE NEO_RGB
#if NEOPIXEL_PIXELS < 3
#undef NEOPIXELS_PIXELS
#define NEOPIXEL_PIXELS 3
#endif
#if ENABLED(FYSETC_MINI_12864_2_1)
#ifndef NEOPIXEL_BRIGHTNESS
#define NEOPIXEL_BRIGHTNESS 127
#endif
Expand All @@ -207,8 +182,8 @@
#define IS_ULTIPANEL 1
#define U8GLIB_SSD1309
#define LCD_RESET_PIN LCD_PINS_D6 // This controller need a reset pin
#define ENCODER_PULSES_PER_STEP 4
#define ENCODER_STEPS_PER_MENU_ITEM 1
#define STD_ENCODER_PULSES_PER_STEP 4
#define STD_ENCODER_STEPS_PER_MENU_ITEM 1
#ifndef PCA9632
#define PCA9632
#endif
Expand Down Expand Up @@ -305,8 +280,8 @@
#define PCA9632_BUZZER
#define PCA9632_BUZZER_DATA { 0x09, 0x02 }

#define ENCODER_PULSES_PER_STEP 1 // Overlord uses buttons
#define ENCODER_STEPS_PER_MENU_ITEM 1
#define STD_ENCODER_PULSES_PER_STEP 1 // Overlord uses buttons
#define STD_ENCODER_STEPS_PER_MENU_ITEM 1
#endif

// 128x64 I2C OLED LCDs - SSD1306/SSD1309/SH1106
Expand Down
10 changes: 7 additions & 3 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@

#if ANY(BLINKM, RGB_LED, RGBW_LED, PCA9632, PCA9533, NEOPIXEL_LED)
#define HAS_COLOR_LEDS 1
#else
#undef LED_POWEROFF_TIMEOUT
#endif
#if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, SDSUPPORT)
#define HAS_LEDS_OFF_FLAG 1
Expand Down Expand Up @@ -738,9 +740,6 @@
#endif

#if EITHER(FYSETC_MINI_12864_2_1, FYSETC_242_OLED_12864)
#define LED_CONTROL_MENU
#define LED_USER_PRESET_STARTUP
#define LED_COLOR_PRESETS
#ifndef LED_USER_PRESET_GREEN
#define LED_USER_PRESET_GREEN 128
#endif
Expand Down Expand Up @@ -981,6 +980,11 @@
#endif
#endif

// Flags for Case Light having a brightness property
#if ENABLED(CASE_LIGHT_ENABLE) && (NONE(CASE_LIGHT_NO_BRIGHTNESS, CASE_LIGHT_IS_COLOR_LED) || ENABLED(CASE_LIGHT_USE_NEOPIXEL))
#define CASELIGHT_USES_BRIGHTNESS 1
#endif

// Flag whether least_squares_fit.cpp is used
#if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
#define NEED_LSF 1
Expand Down
39 changes: 22 additions & 17 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2330,17 +2330,31 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#endif

/**
* LED Control Menu
* FYSETC LCD Requirements
*/
#if ENABLED(LED_CONTROL_MENU) && !HAS_COLOR_LEDS
#error "LED_CONTROL_MENU requires BLINKM, RGB_LED, RGBW_LED, PCA9533, PCA9632, or NEOPIXEL_LED."
#if EITHER(FYSETC_242_OLED_12864, FYSETC_MINI_12864_2_1)
#ifndef NEO_RGB
#define NEO_RGB 123
#define FAUX_RGB 1
#endif
#if defined(NEOPIXEL_TYPE) && NEOPIXEL_TYPE != NEO_RGB
#error "Your FYSETC Mini Panel requires NEOPIXEL_TYPE to be NEO_RGB."
#elif defined(NEOPIXEL_PIXELS) && NEOPIXEL_PIXELS < 3
#error "Your FYSETC Mini Panel requires NEOPIXEL_PIXELS >= 3."
#endif
#if FAUX_RGB
#undef NEO_RGB
#undef FAUX_RGB
#endif
#elif EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) && !DISABLED(RGB_LED)
#error "Your FYSETC Mini Panel requires RGB_LED."
#endif

/**
* LED Backlight Timeout
* LED Control Menu requirements
*/
#if defined(LED_BACKLIGHT_TIMEOUT) && !(ENABLED(PSU_CONTROL) && ANY(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1, FYSETC_242_OLED_12864))
#error "LED_BACKLIGHT_TIMEOUT requires a FYSETC Mini Panel and a Power Switch."
#if ENABLED(LED_CONTROL_MENU) && !HAS_COLOR_LEDS
#error "LED_CONTROL_MENU requires BLINKM, RGB_LED, RGBW_LED, PCA9533, PCA9632, or NEOPIXEL_LED."
#endif

/**
Expand Down Expand Up @@ -2883,15 +2897,6 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#endif
#endif

/**
* FYSETC Mini 12864 RGB backlighting required
*/
#if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) && DISABLED(RGB_LED)
#error "RGB_LED is required for FYSETC_MINI_12864 1.2 and 2.0."
#elif EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1) && DISABLED(LED_USER_PRESET_STARTUP)
#error "LED_USER_PRESET_STARTUP is required for FYSETC_MINI_12864 2.x displays."
#endif

/**
* Check existing CS pins against enabled TMC SPI drivers.
*/
Expand Down Expand Up @@ -3411,8 +3416,8 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
#error "A very large BLOCK_BUFFER_SIZE is not needed and takes longer to drain the buffer on pause / cancel."
#endif

#if ENABLED(LED_CONTROL_MENU) && !IS_ULTIPANEL
#error "LED_CONTROL_MENU requires an LCD controller."
#if ENABLED(LED_CONTROL_MENU) && NONE(HAS_MARLINUI_MENU, DWIN_CREALITY_LCD_ENHANCED)
#error "LED_CONTROL_MENU requires an LCD controller that implements the menu."
#endif

#if ENABLED(CASE_LIGHT_USE_NEOPIXEL) && DISABLED(NEOPIXEL_LED)
Expand Down
17 changes: 17 additions & 0 deletions Marlin/src/inc/Warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,23 @@
#warning "Contrast cannot be changed when LCD_CONTRAST_MIN >= LCD_CONTRAST_MAX."
#endif

/**
* FYSETC backlighting
*/
#if EITHER(FYSETC_242_OLED_12864, FYSETC_MINI_12864_2_1) && !ALL(NEOPIXEL_LED, LED_CONTROL_MENU, LED_USER_PRESET_STARTUP, LED_COLOR_PRESETS)
#warning "Your FYSETC Mini Panel works best with NEOPIXEL_LED, LED_CONTROL_MENU, LED_USER_PRESET_STARTUP, and LED_COLOR_PRESETS."
#endif

#if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) && DISABLED(RGB_LED)
#warning "Your FYSETC Mini Panel works best with RGB_LED."
#elif EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1) && DISABLED(LED_USER_PRESET_STARTUP)
#warning "Your FYSETC Mini Panel works best with LED_USER_PRESET_STARTUP."
#endif

#if EITHER(FYSETC_242_OLED_12864, FYSETC_MINI_12864) && BOTH(PSU_CONTROL, HAS_COLOR_LEDS) && !LED_POWEROFF_TIMEOUT
#warning "Your FYSETC display with PSU_CONTROL works best with LED_POWEROFF_TIMEOUT."
#endif

/**
* Maple environment
*/
Expand Down
Loading

0 comments on commit 8815520

Please sign in to comment.