🐛 E3V2 Brightness followup (#22821)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
Miguel Risco-Castillo 2021-09-25 05:59:43 -05:00 committed by Scott Lahteine
parent e705a7724e
commit 89898181bd
16 changed files with 82 additions and 63 deletions

View File

@ -31,7 +31,7 @@
*/ */
void GcodeSuite::M250() { void GcodeSuite::M250() {
if (parser.seenval('C')) if (parser.seenval('C'))
ui.set_contrast(parser.value_int()); ui.set_contrast(parser.value_byte());
else else
M250_report(); M250_report();
} }

View File

@ -500,6 +500,20 @@
#define HAS_DWIN_E3V2 1 #define HAS_DWIN_E3V2 1
#endif #endif
// E3V2 extras
#if HAS_DWIN_E3V2 || IS_DWIN_MARLINUI
#define SERIAL_CATCHALL 0
#ifndef LCD_SERIAL_PORT
#if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO)
#define LCD_SERIAL_PORT 1
#else
#define LCD_SERIAL_PORT 3 // Creality 4.x board
#endif
#endif
#define HAS_LCD_BRIGHTNESS 1
#define LCD_BRIGHTNESS_MAX 250
#endif
#if IS_ULTRA_LCD #if IS_ULTRA_LCD
#define HAS_WIRED_LCD 1 #define HAS_WIRED_LCD 1
#if ENABLED(DOGLCD) #if ENABLED(DOGLCD)
@ -1111,17 +1125,6 @@
#define HAS_ETHERNET 1 #define HAS_ETHERNET 1
#endif #endif
#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
#define SERIAL_CATCHALL 0
#ifndef LCD_SERIAL_PORT
#if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO)
#define LCD_SERIAL_PORT 1
#else
#define LCD_SERIAL_PORT 3 // Creality 4.x board
#endif
#endif
#endif
// Fallback Stepper Driver types that don't depend on Configuration_adv.h // Fallback Stepper Driver types that don't depend on Configuration_adv.h
#ifndef X_DRIVER_TYPE #ifndef X_DRIVER_TYPE
#define X_DRIVER_TYPE A4988 #define X_DRIVER_TYPE A4988

View File

@ -421,11 +421,6 @@
#endif #endif
#endif #endif
#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
#define HAS_LCD_BRIGHTNESS 1
#define MAX_LCD_BRIGHTNESS 31
#endif
/** /**
* Override the SD_DETECT_STATE set in Configuration_adv.h * Override the SD_DETECT_STATE set in Configuration_adv.h
* and enable sharing of onboard SD host drives (all platforms but AGCM4) * and enable sharing of onboard SD host drives (all platforms but AGCM4)

View File

@ -376,12 +376,9 @@ void MarlinUI::clear_lcd() {
lcd.clear_buffer(); lcd.clear_buffer();
} }
int16_t MarlinUI::contrast; // Initialized by settings.load() #if HAS_LCD_CONTRAST
void MarlinUI::_set_contrast() { lcd.setContrast(contrast); }
void MarlinUI::set_contrast(const int16_t value) { #endif
contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
lcd.setContrast(contrast);
}
static void center_text_P(PGM_P pstart, uint8_t y) { static void center_text_P(PGM_P pstart, uint8_t y) {
uint8_t len = utf8_strlen_P(pstart); uint8_t len = utf8_strlen_P(pstart);

View File

@ -93,14 +93,7 @@ U8G_CLASS u8g;
#endif #endif
#if HAS_LCD_CONTRAST #if HAS_LCD_CONTRAST
void MarlinUI::_set_contrast() { u8g.setContrast(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);
}
#endif #endif
void MarlinUI::set_font(const MarlinFont font_nr) { void MarlinUI::set_font(const MarlinFont font_nr) {

View File

@ -78,14 +78,16 @@ bool DWIN_Handshake() {
&& databuf[3] == 'K' ); && databuf[3] == 'K' );
} }
// Set the backlight brightness #if HAS_LCD_BRIGHTNESS
// brightness: (0x00-0x1F) // Set LCD backlight (from DWIN Enhanced)
void DWIN_LCD_Brightness(const uint8_t brightness) { // brightness: 0x00-0xFF
size_t i = 0; void DWIN_LCD_Brightness(const uint8_t brightness) {
DWIN_Byte(i, 0x30); size_t i = 0;
DWIN_Byte(i, _MAX(brightness, 0x1F)); DWIN_Byte(i, 0x30);
DWIN_Send(i); DWIN_Byte(i, brightness);
} DWIN_Send(i);
}
#endif
// Set screen display direction // Set screen display direction
// dir: 0=0°, 1=90°, 2=180°, 3=270° // dir: 0=0°, 1=90°, 2=180°, 3=270°

View File

@ -90,9 +90,11 @@ bool DWIN_Handshake();
// DWIN startup // DWIN startup
void DWIN_Startup(); void DWIN_Startup();
// Set the backlight brightness #if HAS_LCD_BRIGHTNESS
// brightness: (0x00-0xFF) // Set the backlight brightness
void DWIN_LCD_Brightness(const uint8_t brightness); // brightness: (0x00-0xFF)
void DWIN_LCD_Brightness(const uint8_t brightness);
#endif
// Set screen display direction // Set screen display direction
// dir: 0=0°, 1=90°, 2=180°, 3=270° // dir: 0=0°, 1=90°, 2=180°, 3=270°

View File

@ -1816,6 +1816,10 @@ void HMI_SDCardInit() { card.cdroot(); }
void MarlinUI::refresh() { /* Nothing to see here */ } 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) #if ENABLED(SCROLL_LONG_FILENAMES)
char shift_name[LONG_FILENAME_LENGTH + 1]; char shift_name[LONG_FILENAME_LENGTH + 1];

View File

@ -865,6 +865,10 @@ void HMI_SDCardInit() { card.cdroot(); }
void MarlinUI::refresh() { /* Nothing to see here */ } 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 #define ICON_Folder ICON_More
#if ENABLED(SCROLL_LONG_FILENAMES) #if ENABLED(SCROLL_LONG_FILENAMES)
@ -2186,9 +2190,8 @@ void SetPID(celsius_t t, heater_id_t h) {
#endif #endif
#if HAS_LCD_BRIGHTNESS #if HAS_LCD_BRIGHTNESS
void ApplyBrightness() { ui.set_brightness(HMI_value.Value); } void LiveBrightness() { ui.set_brightness(HMI_value.Value); }
void LiveBrightness() { DWIN_LCD_Brightness(HMI_value.Value); } void SetBrightness() { SetIntOnClick(LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX, ui.brightness, nullptr, LiveBrightness); }
void SetBrightness() { SetIntOnClick(MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS, ui.brightness, ApplyBrightness, LiveBrightness); }
#endif #endif
#if ENABLED(SOUND_MENU_ITEM) #if ENABLED(SOUND_MENU_ITEM)

View File

@ -2717,7 +2717,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
Draw_Float(ui.brightness, row, false, 1); Draw_Float(ui.brightness, row, false, 1);
} }
else 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;
case VISUAL_TIME_FORMAT: case VISUAL_TIME_FORMAT:
if (draw) { 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); Draw_Float(ui.brightness, row, false, 1);
} }
else 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;
} }
break; break;
@ -4800,6 +4800,10 @@ void CrealityDWINClass::Update() {
void MarlinUI::update() { CrealityDWIN.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() { void CrealityDWINClass::State_Update() {
if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) { if ((print_job_timer.isRunning() || print_job_timer.isPaused()) != printing) {
if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid())); if (!printing) Start_Print(card.isFileOpen() || TERN0(POWER_LOSS_RECOVERY, recovery.valid()));

View File

@ -254,6 +254,10 @@ void MarlinUI::draw_status_message(const bool blink) {
#endif #endif
} }
#if HAS_LCD_BRIGHTNESS
void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
#endif
#if HAS_LCD_MENU #if HAS_LCD_MENU
#include "../../menu/menu.h" #include "../../menu/menu.h"

View File

@ -95,16 +95,23 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
} }
#endif #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 #if HAS_LCD_BRIGHTNESS
uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS; uint8_t MarlinUI::brightness = DEFAULT_LCD_BRIGHTNESS;
bool MarlinUI::backlight = true; bool MarlinUI::backlight = true;
void MarlinUI::set_brightness(const uint8_t value) { void MarlinUI::set_brightness(const uint8_t value) {
backlight = !!value; backlight = !!value;
if (backlight) brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS); if (backlight) brightness = constrain(value, LCD_BRIGHTNESS_MIN, LCD_BRIGHTNESS_MAX);
// Set brightness on enabled LCD here _set_brightness();
TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_LCD_Brightness(brightness));
TERN_(DWIN_CREALITY_LCD_JYERSUI, DWIN_LCD_Brightness(backlight ? brightness : 0));
} }
#endif #endif

View File

@ -247,17 +247,18 @@ public:
#endif #endif
#if HAS_LCD_BRIGHTNESS #if HAS_LCD_BRIGHTNESS
#ifndef MIN_LCD_BRIGHTNESS #ifndef LCD_BRIGHTNESS_MIN
#define MIN_LCD_BRIGHTNESS 1 #define LCD_BRIGHTNESS_MIN 1
#endif #endif
#ifndef MAX_LCD_BRIGHTNESS #ifndef LCD_BRIGHTNESS_MAX
#define MAX_LCD_BRIGHTNESS 255 #define LCD_BRIGHTNESS_MAX 255
#endif #endif
#ifndef DEFAULT_LCD_BRIGHTNESS #ifndef DEFAULT_LCD_BRIGHTNESS
#define DEFAULT_LCD_BRIGHTNESS MAX_LCD_BRIGHTNESS #define DEFAULT_LCD_BRIGHTNESS LCD_BRIGHTNESS_MAX
#endif #endif
static uint8_t brightness; static uint8_t brightness;
static bool backlight; static bool backlight;
static void _set_brightness(); // Implementation-specific
static void set_brightness(const uint8_t value); static void set_brightness(const uint8_t value);
FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); } FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); }
#endif #endif
@ -425,8 +426,9 @@ public:
static uint8_t lcd_status_update_delay; static uint8_t lcd_status_update_delay;
#if HAS_LCD_CONTRAST #if HAS_LCD_CONTRAST
static int16_t contrast; static uint8_t contrast;
static void set_contrast(const int16_t value); static void _set_contrast(); // Implementation-specific
static void set_contrast(const uint8_t value);
FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); } FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
#endif #endif

View File

@ -528,8 +528,11 @@ void menu_configuration() {
#endif #endif
#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 #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 #endif
#if ENABLED(FWRETRACT) #if ENABLED(FWRETRACT)
SUBMENU(MSG_RETRACT, menu_config_retract); SUBMENU(MSG_RETRACT, menu_config_retract);

View File

@ -345,7 +345,7 @@ typedef struct SettingsDataStruct {
// //
// HAS_LCD_CONTRAST // HAS_LCD_CONTRAST
// //
int16_t lcd_contrast; // M250 C uint8_t lcd_contrast; // M250 C
// //
// HAS_LCD_BRIGHTNESS // HAS_LCD_BRIGHTNESS
@ -1006,7 +1006,7 @@ void MarlinSettings::postprocess() {
// //
{ {
_FIELD_TEST(lcd_contrast); _FIELD_TEST(lcd_contrast);
const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127); const uint8_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
EEPROM_WRITE(lcd_contrast); EEPROM_WRITE(lcd_contrast);
} }
@ -1869,7 +1869,7 @@ void MarlinSettings::postprocess() {
// //
{ {
_FIELD_TEST(lcd_contrast); _FIELD_TEST(lcd_contrast);
int16_t lcd_contrast; uint8_t lcd_contrast;
EEPROM_READ(lcd_contrast); EEPROM_READ(lcd_contrast);
if (!validating) { if (!validating) {
TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast)); TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));

View File

@ -24,7 +24,7 @@ opt_enable DWIN_CREALITY_LCD_JYERSUI AUTO_BED_LEVELING_BILINEAR PROBE_MANUALLY
exec_test $1 $2 "Ender 3 v2 with JyersUI" "$3" exec_test $1 $2 "Ender 3 v2 with JyersUI" "$3"
use_example_configs "Creality/Ender-3 V2/MarlinUI" use_example_configs "Creality/Ender-3 V2/MarlinUI"
opt_add SDCARD_EEPROM_EMULATION NOZZLE_AS_PROBE AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING opt_add SDCARD_EEPROM_EMULATION AUTO_BED_LEVELING_BILINEAR Z_SAFE_HOMING
exec_test $1 $2 "Ender 3 v2 with MarlinUI" "$3" exec_test $1 $2 "Ender 3 v2 with MarlinUI" "$3"
restore_configs restore_configs