🐛 E3V2 Brightness followup (#22821)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
		
				
					committed by
					
						
						Scott Lahteine
					
				
			
			
				
	
			
			
			
						parent
						
							e705a7724e
						
					
				
				
					commit
					89898181bd
				
			@@ -376,12 +376,9 @@ void MarlinUI::clear_lcd() {
 | 
			
		||||
  lcd.clear_buffer();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int16_t MarlinUI::contrast; // Initialized by settings.load()
 | 
			
		||||
 | 
			
		||||
void MarlinUI::set_contrast(const int16_t value) {
 | 
			
		||||
  contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
 | 
			
		||||
  lcd.setContrast(contrast);
 | 
			
		||||
}
 | 
			
		||||
#if HAS_LCD_CONTRAST
 | 
			
		||||
  void MarlinUI::_set_contrast() { lcd.setContrast(contrast); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static void center_text_P(PGM_P pstart, uint8_t y) {
 | 
			
		||||
  uint8_t len = utf8_strlen_P(pstart);
 | 
			
		||||
 
 | 
			
		||||
@@ -93,14 +93,7 @@ U8G_CLASS u8g;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_CONTRAST
 | 
			
		||||
 | 
			
		||||
  int16_t MarlinUI::contrast = DEFAULT_LCD_CONTRAST;
 | 
			
		||||
 | 
			
		||||
  void MarlinUI::set_contrast(const int16_t value) {
 | 
			
		||||
    contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
 | 
			
		||||
    u8g.setContrast(contrast);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void MarlinUI::_set_contrast() { u8g.setContrast(contrast); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void MarlinUI::set_font(const MarlinFont font_nr) {
 | 
			
		||||
 
 | 
			
		||||
@@ -78,14 +78,16 @@ bool DWIN_Handshake() {
 | 
			
		||||
        && databuf[3] == 'K' );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Set the backlight brightness
 | 
			
		||||
//  brightness: (0x00-0x1F)
 | 
			
		||||
void DWIN_LCD_Brightness(const uint8_t brightness) {
 | 
			
		||||
  size_t i = 0;
 | 
			
		||||
  DWIN_Byte(i, 0x30);
 | 
			
		||||
  DWIN_Byte(i, _MAX(brightness, 0x1F));
 | 
			
		||||
  DWIN_Send(i);
 | 
			
		||||
}
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  // Set LCD backlight (from DWIN Enhanced)
 | 
			
		||||
  //  brightness: 0x00-0xFF
 | 
			
		||||
  void DWIN_LCD_Brightness(const uint8_t brightness) {
 | 
			
		||||
    size_t i = 0;
 | 
			
		||||
    DWIN_Byte(i, 0x30);
 | 
			
		||||
    DWIN_Byte(i, brightness);
 | 
			
		||||
    DWIN_Send(i);
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Set screen display direction
 | 
			
		||||
//  dir: 0=0°, 1=90°, 2=180°, 3=270°
 | 
			
		||||
 
 | 
			
		||||
@@ -90,9 +90,11 @@ bool DWIN_Handshake();
 | 
			
		||||
// DWIN startup
 | 
			
		||||
void DWIN_Startup();
 | 
			
		||||
 | 
			
		||||
// Set the backlight brightness
 | 
			
		||||
//  brightness: (0x00-0xFF)
 | 
			
		||||
void DWIN_LCD_Brightness(const uint8_t brightness);
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  // Set the backlight brightness
 | 
			
		||||
  //  brightness: (0x00-0xFF)
 | 
			
		||||
  void DWIN_LCD_Brightness(const uint8_t brightness);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Set screen display direction
 | 
			
		||||
//  dir: 0=0°, 1=90°, 2=180°, 3=270°
 | 
			
		||||
 
 | 
			
		||||
@@ -1816,6 +1816,10 @@ void HMI_SDCardInit() { card.cdroot(); }
 | 
			
		||||
 | 
			
		||||
void MarlinUI::refresh() { /* Nothing to see here */ }
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if ENABLED(SCROLL_LONG_FILENAMES)
 | 
			
		||||
 | 
			
		||||
  char shift_name[LONG_FILENAME_LENGTH + 1];
 | 
			
		||||
 
 | 
			
		||||
@@ -865,6 +865,10 @@ void HMI_SDCardInit() { card.cdroot(); }
 | 
			
		||||
 | 
			
		||||
void MarlinUI::refresh() { /* Nothing to see here */ }
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define ICON_Folder ICON_More
 | 
			
		||||
 | 
			
		||||
#if ENABLED(SCROLL_LONG_FILENAMES)
 | 
			
		||||
@@ -2186,9 +2190,8 @@ void SetPID(celsius_t t, heater_id_t h) {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  void ApplyBrightness() { ui.set_brightness(HMI_value.Value); }
 | 
			
		||||
  void LiveBrightness() { DWIN_LCD_Brightness(HMI_value.Value); }
 | 
			
		||||
  void SetBrightness() { SetIntOnClick(MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, ui.brightness, ApplyBrightness, LiveBrightness); }
 | 
			
		||||
  void LiveBrightness() { ui.set_brightness(HMI_value.Value); }
 | 
			
		||||
  void SetBrightness() { SetIntOnClick(LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.brightness, nullptr, LiveBrightness); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if ENABLED(SOUND_MENU_ITEM)
 | 
			
		||||
 
 | 
			
		||||
@@ -2717,7 +2717,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
 | 
			
		||||
            Draw_Float(ui.brightness, row, false, 1);
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
            Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness);
 | 
			
		||||
            Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness);
 | 
			
		||||
          break;
 | 
			
		||||
        case VISUAL_TIME_FORMAT:
 | 
			
		||||
          if (draw) {
 | 
			
		||||
@@ -3879,7 +3879,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
 | 
			
		||||
            Draw_Float(ui.brightness, row, false, 1);
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
            Modify_Value(ui.brightness, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, 1, ui.refresh_brightness);
 | 
			
		||||
            Modify_Value(ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, 1, ui.refresh_brightness);
 | 
			
		||||
          break;
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
@@ -4800,6 +4800,10 @@ void CrealityDWINClass::Update() {
 | 
			
		||||
 | 
			
		||||
void MarlinUI::update() { CrealityDWIN.Update(); }
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void CrealityDWINClass::State_Update() {
 | 
			
		||||
  if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) {
 | 
			
		||||
    if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid()));
 | 
			
		||||
 
 | 
			
		||||
@@ -254,6 +254,10 @@ void MarlinUI::draw_status_message(const bool blink) {
 | 
			
		||||
  #endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_MENU
 | 
			
		||||
 | 
			
		||||
  #include "../../menu/menu.h"
 | 
			
		||||
 
 | 
			
		||||
@@ -95,16 +95,23 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_CONTRAST
 | 
			
		||||
  uint8_t MarlinUI::contrast; // Initialized by settings.load()
 | 
			
		||||
 | 
			
		||||
  void MarlinUI::set_contrast(const uint8_t value) {
 | 
			
		||||
    contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
 | 
			
		||||
    _set_contrast();
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if HAS_LCD_BRIGHTNESS
 | 
			
		||||
  uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS;
 | 
			
		||||
  bool MarlinUI::backlight = true;
 | 
			
		||||
 | 
			
		||||
  void MarlinUI::set_brightness(const uint8_t value) {
 | 
			
		||||
    backlight = !!value;
 | 
			
		||||
    if (backlight) brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS);
 | 
			
		||||
    // Set brightness on enabled LCD here
 | 
			
		||||
    TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_LCD_Brightness(brightness));
 | 
			
		||||
    TERN_(DWIN_CREALITY_LCD_JYERSUI, DWIN_LCD_Brightness(backlight ? brightness : 0));
 | 
			
		||||
    if (backlight) brightness = constrain(value, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX);
 | 
			
		||||
    _set_brightness();
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -247,17 +247,18 @@ public:
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #if HAS_LCD_BRIGHTNESS
 | 
			
		||||
    #ifndef MIN_LCD_BRIGHTNESS
 | 
			
		||||
      #define MIN_LCD_BRIGHTNESS   1
 | 
			
		||||
    #ifndef LCD_BRIGHTNESS_MIN
 | 
			
		||||
      #define LCD_BRIGHTNESS_MIN   1
 | 
			
		||||
    #endif
 | 
			
		||||
    #ifndef MAX_LCD_BRIGHTNESS
 | 
			
		||||
      #define MAX_LCD_BRIGHTNESS 255
 | 
			
		||||
    #ifndef LCD_BRIGHTNESS_MAX
 | 
			
		||||
      #define LCD_BRIGHTNESS_MAX 255
 | 
			
		||||
    #endif
 | 
			
		||||
    #ifndef DEFAULT_LCD_BRIGHTNESS
 | 
			
		||||
      #define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS
 | 
			
		||||
      #define DEFAULT_LCD_BRIGHTNESS LCD_BRIGHTNESS_MAX
 | 
			
		||||
    #endif
 | 
			
		||||
    static uint8_t brightness;
 | 
			
		||||
    static bool backlight;
 | 
			
		||||
    static void _set_brightness(); // Implementation-specific
 | 
			
		||||
    static void set_brightness(const uint8_t value);
 | 
			
		||||
    FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
 | 
			
		||||
  #endif
 | 
			
		||||
@@ -425,8 +426,9 @@ public:
 | 
			
		||||
      static uint8_t lcd_status_update_delay;
 | 
			
		||||
 | 
			
		||||
      #if HAS_LCD_CONTRAST
 | 
			
		||||
        static int16_t contrast;
 | 
			
		||||
        static void set_contrast(const int16_t value);
 | 
			
		||||
        static uint8_t contrast;
 | 
			
		||||
        static void _set_contrast(); // Implementation-specific
 | 
			
		||||
        static void set_contrast(const uint8_t value);
 | 
			
		||||
        FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
 | 
			
		||||
      #endif
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -528,8 +528,11 @@ void menu_configuration() {
 | 
			
		||||
    #endif
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #if HAS_LCD_BRIGHTNESS
 | 
			
		||||
    EDIT_ITEM_FAST(uint8, MSG_BRIGHTNESS, &ui.brightness, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.refresh_brightness, true);
 | 
			
		||||
  #endif
 | 
			
		||||
  #if HAS_LCD_CONTRAST
 | 
			
		||||
    EDIT_ITEM(int3, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true);
 | 
			
		||||
    EDIT_ITEM_FAST(uint8, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true);
 | 
			
		||||
  #endif
 | 
			
		||||
  #if ENABLED(FWRETRACT)
 | 
			
		||||
    SUBMENU(MSG_RETRACT, menu_config_retract);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user