Skip to content

Commit

Permalink
🐛 E3V2 Brightness followup (MarlinFirmware#22821)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
  • Loading branch information
2 people authored and mh-dm committed May 15, 2022
1 parent 9d65534 commit 886e631
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/gcode/lcd/M250.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
void GcodeSuite::M250() {
if (parser.seenval('C'))
ui.set_contrast(parser.value_int());
ui.set_contrast(parser.value_byte());
else
M250_report();
}
Expand Down
25 changes: 14 additions & 11 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,20 @@
#define HAS_DWIN_E3V2 1
#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
#define HAS_WIRED_LCD 1
#if ENABLED(DOGLCD)
Expand Down Expand Up @@ -1111,17 +1125,6 @@
#define HAS_ETHERNET 1
#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
#ifndef X_DRIVER_TYPE
#define X_DRIVER_TYPE A4988
Expand Down
5 changes: 0 additions & 5 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,6 @@
#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
* and enable sharing of onboard SD host drives (all platforms but AGCM4)
Expand Down
9 changes: 3 additions & 6 deletions Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 10 additions & 8 deletions Marlin/src/lcd/e3v2/common/dwin_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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°
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/e3v2/common/dwin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,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°
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/lcd/e3v2/creality/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 6 additions & 3 deletions Marlin/src/lcd/e3v2/enhanced/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 11 additions & 4 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 9 additions & 7 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,18 @@ class MarlinUI {
#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
Expand Down Expand Up @@ -425,8 +426,9 @@ class MarlinUI {
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

Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ typedef struct SettingsDataStruct {
//
// HAS_LCD_CONTRAST
//
int16_t lcd_contrast; // M250 C
uint8_t lcd_contrast; // M250 C

//
// HAS_LCD_BRIGHTNESS
Expand Down Expand Up @@ -1017,7 +1017,7 @@ void MarlinSettings::postprocess() {
//
{
_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);
}

Expand Down Expand Up @@ -1884,7 +1884,7 @@ void MarlinSettings::postprocess() {
//
{
_FIELD_TEST(lcd_contrast);
int16_t lcd_contrast;
uint8_t lcd_contrast;
EEPROM_READ(lcd_contrast);
if (!validating) {
TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));
Expand Down
2 changes: 1 addition & 1 deletion buildroot/tests/STM32F103RET6_creality
Original file line number Diff line number Diff line change
Expand Up @@ -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"

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"

restore_configs
Expand Down

0 comments on commit 886e631

Please sign in to comment.