♻️ Adjust LCD init, contrast default, settings load

This commit is contained in:
Scott Lahteine 2022-01-22 10:14:47 -06:00
parent de0bc19230
commit 99f3b8b4a8
19 changed files with 137 additions and 154 deletions

View file

@ -113,7 +113,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#define _IS_RX1_1 IS_RX1
#if IS_TX1(TMC_SW_SCK)
#error "Serial port pins (1) conflict with other pins!"
#elif HAS_WIRED_LCD
#elif HAS_ROTARY_ENCODER
#if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1)
#error "Serial port pins (1) conflict with Encoder Buttons!"
#elif ANY_TX(1, SD_SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK_PIN) \

View file

@ -1294,16 +1294,7 @@ void setup() {
// UI must be initialized before EEPROM
// (because EEPROM code calls the UI).
#if HAS_DWIN_E3V2_BASIC
SETUP_RUN(DWIN_Startup());
#else
SETUP_RUN(ui.init());
#if BOTH(HAS_WIRED_LCD, SHOW_BOOTSCREEN)
SETUP_RUN(ui.show_bootscreen());
const millis_t bootscreen_ms = millis();
#endif
SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.)
#endif
#if PIN_EXISTS(SAFE_POWER)
#if HAS_DRIVER_SAFE_POWER_PROTECT
@ -1314,10 +1305,6 @@ void setup() {
#endif
#endif
#if ENABLED(PROBE_TARE)
SETUP_RUN(probe.tare_init());
#endif
#if BOTH(SDSUPPORT, SDCARD_EEPROM_EMULATION)
SETUP_RUN(card.mount()); // Mount media with settings before first_load
#endif
@ -1325,6 +1312,15 @@ void setup() {
SETUP_RUN(settings.first_load()); // Load data from EEPROM if available (or use defaults)
// This also updates variables in the planner, elsewhere
#if BOTH(HAS_WIRED_LCD, SHOW_BOOTSCREEN)
SETUP_RUN(ui.show_bootscreen());
const millis_t bootscreen_ms = millis();
#endif
#if ENABLED(PROBE_TARE)
SETUP_RUN(probe.tare_init());
#endif
#if HAS_ETHERNET
SETUP_RUN(ethernet.init());
#endif

View file

@ -31,7 +31,7 @@
* M250: Read and optionally set the LCD contrast
*/
void GcodeSuite::M250() {
if (parser.seenval('C'))
if (LCD_CONTRAST_MIN < LCD_CONTRAST_MAX && parser.seenval('C'))
ui.set_contrast(parser.value_byte());
else
M250_report();

View file

@ -237,7 +237,7 @@
#define LCD_HEIGHT 10 // Character lines
#define LCD_CONTRAST_MIN 127
#define LCD_CONTRAST_MAX 255
#define DEFAULT_LCD_CONTRAST 250
#define LCD_CONTRAST_DEFAULT 250
#define CONVERT_TO_EXT_ASCII // Use extended 128-255 symbols from ASCII table.
// At this time present conversion only for cyrillic - bg, ru and uk languages.
// First 7 ASCII symbols in panel font must be replaced with Marlin's special symbols.

View file

@ -376,7 +376,6 @@
#elif EITHER(MKS_MINI_12864_V3, BTT_MINI_12864_V1)
#define _LCD_CONTRAST_MIN 255
#define _LCD_CONTRAST_INIT 255
#define _LCD_CONTRAST_MAX 255
#elif ENABLED(FYSETC_MINI_12864)
#define _LCD_CONTRAST_INIT 220
#elif ENABLED(ULTI_CONTROLLER)
@ -389,18 +388,12 @@
#elif ENABLED(ZONESTAR_12864OLED)
#define _LCD_CONTRAST_MIN 64
#define _LCD_CONTRAST_INIT 128
#define _LCD_CONTRAST_MAX 255
#elif IS_TFTGLCD_PANEL
#define _LCD_CONTRAST_MIN 0
#define _LCD_CONTRAST_INIT 250
#define _LCD_CONTRAST_MAX 255
#endif
#ifdef _LCD_CONTRAST_INIT
#define HAS_LCD_CONTRAST 1
#endif
#if HAS_LCD_CONTRAST
#ifndef LCD_CONTRAST_MIN
#ifdef _LCD_CONTRAST_MIN
#define LCD_CONTRAST_MIN _LCD_CONTRAST_MIN
@ -420,8 +413,8 @@
#define LCD_CONTRAST_MAX 63 // ST7567 6-bits contrast
#endif
#endif
#ifndef DEFAULT_LCD_CONTRAST
#define DEFAULT_LCD_CONTRAST LCD_CONTRAST_INIT
#ifndef LCD_CONTRAST_DEFAULT
#define LCD_CONTRAST_DEFAULT LCD_CONTRAST_INIT
#endif
#endif

View file

@ -559,3 +559,7 @@
#if CANNOT_EMBED_CONFIGURATION
#warning "Disabled CONFIGURATION_EMBEDDING because the target usually has less flash storage. Define FORCE_CONFIG_EMBED to override."
#endif
#if HAS_LCD_CONTRAST && LCD_CONTRAST_MIN >= LCD_CONTRAST_MAX
#warning "Contrast cannot be changed when LCD_CONTRAST_MIN >= LCD_CONTRAST_MAX."
#endif

View file

@ -1834,6 +1834,9 @@ void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT)
void HMI_SDCardInit() { card.cdroot(); }
// Initialize or re-initialize the LCD
void MarlinUI::init_lcd() { DWIN_Startup(); }
void MarlinUI::refresh() { /* Nothing to see here */ }
#if HAS_LCD_BRIGHTNESS

View file

@ -888,6 +888,9 @@ void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT)
void HMI_SDCardInit() { card.cdroot(); }
// Initialize or re-initialize the LCD
void MarlinUI::init_lcd() { DWIN_Startup(); }
void MarlinUI::refresh() { /* Nothing to see here */ }
#if HAS_LCD_BRIGHTNESS

View file

@ -4980,7 +4980,7 @@ void CrealityDWINClass::Reset_Settings() {
Redraw_Screen();
}
void MarlinUI::init() {
void MarlinUI::init_lcd() {
delay(800);
SERIAL_ECHOPGM("\nDWIN handshake ");
if (DWIN_Handshake()) SERIAL_ECHOLNPGM("ok."); else SERIAL_ECHOLNPGM("error.");

View file

@ -79,9 +79,7 @@ void MarlinUI::set_font(const uint8_t font_nr) {
bool MarlinUI::detected() { return true; }
// Initialize or re-initialize the LCD
void MarlinUI::init_lcd() {
DWIN_Startup();
}
void MarlinUI::init_lcd() { DWIN_Startup(); }
// This LCD should clear where it will draw anew
void MarlinUI::clear_lcd() {

View file

@ -1144,7 +1144,7 @@ namespace ExtUI {
// At the moment we hook into MarlinUI methods, but this could be cleaned up in the future
void MarlinUI::init() { ExtUI::onStartup(); }
void MarlinUI::init_lcd() { ExtUI::onStartup(); }
void MarlinUI::update() { ExtUI::onIdle(); }

View file

@ -43,7 +43,6 @@ MarlinUI ui;
#if HAS_DISPLAY
#include "../gcode/queue.h"
#include "fontutils.h"
#include "../sd/cardreader.h"
#endif
#if ENABLED(DWIN_CREALITY_LCD)
@ -176,6 +175,77 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#endif
// Encoder Handling
#if HAS_ENCODER_ACTION
uint32_t MarlinUI::encoderPosition;
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
#endif
void MarlinUI::init() {
init_lcd();
#if HAS_DIGITAL_BUTTONS
#if BUTTON_EXISTS(EN1)
SET_INPUT_PULLUP(BTN_EN1);
#endif
#if BUTTON_EXISTS(EN2)
SET_INPUT_PULLUP(BTN_EN2);
#endif
#if BUTTON_EXISTS(ENC)
SET_INPUT_PULLUP(BTN_ENC);
#endif
#if BUTTON_EXISTS(ENC_EN)
SET_INPUT_PULLUP(BTN_ENC_EN);
#endif
#if BUTTON_EXISTS(BACK)
SET_INPUT_PULLUP(BTN_BACK);
#endif
#if BUTTON_EXISTS(UP)
SET_INPUT(BTN_UP);
#endif
#if BUTTON_EXISTS(DWN)
SET_INPUT(BTN_DWN);
#endif
#if BUTTON_EXISTS(LFT)
SET_INPUT(BTN_LFT);
#endif
#if BUTTON_EXISTS(RT)
SET_INPUT(BTN_RT);
#endif
#endif
#if HAS_SHIFT_ENCODER
#if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
SET_OUTPUT(SR_DATA_PIN);
SET_OUTPUT(SR_CLK_PIN);
#elif PIN_EXISTS(SHIFT_CLK)
SET_OUTPUT(SHIFT_CLK_PIN);
OUT_WRITE(SHIFT_LD_PIN, HIGH);
#if PIN_EXISTS(SHIFT_EN)
OUT_WRITE(SHIFT_EN_PIN, LOW);
#endif
SET_INPUT_PULLUP(SHIFT_OUT_PIN);
#endif
#endif // HAS_SHIFT_ENCODER
#if BOTH(HAS_ENCODER_ACTION, HAS_SLOW_BUTTONS)
slow_buttons = 0;
#endif
update_buttons();
TERN_(HAS_ENCODER_ACTION, encoderDiff = 0);
reset_status(); // Set welcome message
}
#if HAS_WIRED_LCD
#if HAS_MARLINUI_U8GLIB
@ -184,8 +254,6 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#include "lcdprint.h"
#include "../sd/cardreader.h"
#include "../module/temperature.h"
#include "../module/planner.h"
#include "../module/motion.h"
@ -247,16 +315,8 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
bool MarlinUI::old_is_printing;
#endif
// Encoder Handling
#if HAS_ENCODER_ACTION
uint32_t MarlinUI::encoderPosition;
volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
#endif
#if ENABLED(SDSUPPORT)
#include "../sd/cardreader.h"
#if MARLINUI_SCROLL_NAME
uint8_t MarlinUI::filename_scroll_pos, MarlinUI::filename_scroll_max;
#endif
@ -393,69 +453,6 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#endif // HAS_LCD_MENU
void MarlinUI::init() {
init_lcd();
#if HAS_DIGITAL_BUTTONS
#if BUTTON_EXISTS(EN1)
SET_INPUT_PULLUP(BTN_EN1);
#endif
#if BUTTON_EXISTS(EN2)
SET_INPUT_PULLUP(BTN_EN2);
#endif
#if BUTTON_EXISTS(ENC)
SET_INPUT_PULLUP(BTN_ENC);
#endif
#if BUTTON_EXISTS(ENC_EN)
SET_INPUT_PULLUP(BTN_ENC_EN);
#endif
#if BUTTON_EXISTS(BACK)
SET_INPUT_PULLUP(BTN_BACK);
#endif
#if BUTTON_EXISTS(UP)
SET_INPUT(BTN_UP);
#endif
#if BUTTON_EXISTS(DWN)
SET_INPUT(BTN_DWN);
#endif
#if BUTTON_EXISTS(LFT)
SET_INPUT(BTN_LFT);
#endif
#if BUTTON_EXISTS(RT)
SET_INPUT(BTN_RT);
#endif
#endif
#if HAS_SHIFT_ENCODER
#if ENABLED(SR_LCD_2W_NL) // Non latching 2 wire shift register
SET_OUTPUT(SR_DATA_PIN);
SET_OUTPUT(SR_CLK_PIN);
#elif PIN_EXISTS(SHIFT_CLK)
SET_OUTPUT(SHIFT_CLK_PIN);
OUT_WRITE(SHIFT_LD_PIN, HIGH);
#if PIN_EXISTS(SHIFT_EN)
OUT_WRITE(SHIFT_EN_PIN, LOW);
#endif
SET_INPUT_PULLUP(SHIFT_OUT_PIN);
#endif
#endif // HAS_SHIFT_ENCODER
#if BOTH(HAS_ENCODER_ACTION, HAS_SLOW_BUTTONS)
slow_buttons = 0;
#endif
update_buttons();
TERN_(HAS_ENCODER_ACTION, encoderDiff = 0);
}
////////////////////////////////////////////
///////////// Keypad Handling //////////////
////////////////////////////////////////////
@ -629,9 +626,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
next_filament_display = millis() + 5000UL; // Show status message for 5s
#endif
goto_screen(menu_main);
#if DISABLED(NO_LCD_REINIT)
init_lcd(); // May revive the LCD if static electricity killed it
#endif
IF_DISABLED(NO_LCD_REINIT, init_lcd()); // May revive the LCD if static electricity killed it
return;
}

View file

@ -21,6 +21,7 @@
*/
#pragma once
#include "../sd/cardreader.h"
#include "../module/motion.h"
#include "buttons.h"
@ -30,10 +31,6 @@
#include "../libs/buzzer.h"
#endif
#if ENABLED(SDSUPPORT)
#include "../sd/cardreader.h"
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "tft_io/touch_calibration.h"
#endif
@ -204,6 +201,20 @@ public:
TERN_(HAS_LCD_MENU, currentScreen = status_screen);
}
static void init();
#if HAS_DISPLAY || HAS_DWIN_E3V2
static void init_lcd();
#else
static void init_lcd() {}
#endif
#if HAS_WIRED_LCD
static bool detected();
#else
static bool detected() { return true; }
#endif
#if HAS_MULTI_LANGUAGE
static uint8_t language;
static void set_language(const uint8_t lang);
@ -270,14 +281,6 @@ public:
}
#endif
#if HAS_WIRED_LCD
static bool detected();
static void init_lcd();
#else
static bool detected() { return true; }
static void init_lcd() {}
#endif
#if HAS_PRINT_PROGRESS
#if HAS_PRINT_PROGRESS_PERMYRIAD
typedef uint16_t progress_t;
@ -365,7 +368,6 @@ public:
#if HAS_DISPLAY
static void init();
static void update();
static void abort_print();
@ -480,7 +482,6 @@ public:
#else // No LCD
static void init() {}
static void update() {}
static void return_to_status() {}

View file

@ -538,7 +538,7 @@ void menu_configuration() {
#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 && LCD_CONTRAST_MIN < LCD_CONTRAST_MAX
EDIT_ITEM_FAST(uint8, MSG_CONTRAST, &ui.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, ui.refresh_contrast, true);
#endif
#if ENABLED(FWRETRACT)

View file

@ -1965,8 +1965,10 @@ void MarlinSettings::postprocess() {
//
#if HAS_USER_THERMISTORS
{
user_thermistor_t user_thermistor[USER_THERMISTORS];
_FIELD_TEST(user_thermistor);
EEPROM_READ(thermalManager.user_thermistor);
EEPROM_READ(user_thermistor);
if (!validating) COPY(thermalManager.user_thermistor, user_thermistor);
}
#endif
@ -1974,13 +1976,10 @@ void MarlinSettings::postprocess() {
// Power monitor
//
{
#if HAS_POWER_MONITOR
uint8_t &power_monitor_flags = power_monitor.flags;
#else
uint8_t power_monitor_flags;
#endif
_FIELD_TEST(power_monitor_flags);
EEPROM_READ(power_monitor_flags);
TERN_(HAS_POWER_MONITOR, if (!validating) power_monitor.flags = power_monitor_flags);
}
//
@ -1997,7 +1996,6 @@ void MarlinSettings::postprocess() {
// LCD Brightness
//
{
_FIELD_TEST(lcd_brightness);
uint8_t lcd_brightness;
EEPROM_READ(lcd_brightness);
TERN_(HAS_LCD_BRIGHTNESS, if (!validating) ui.set_brightness(lcd_brightness));
@ -2007,45 +2005,37 @@ void MarlinSettings::postprocess() {
// Controller Fan
//
{
_FIELD_TEST(controllerFan_settings);
#if ENABLED(CONTROLLER_FAN_EDITABLE)
const controllerFan_settings_t &cfs = controllerFan.settings;
#else
controllerFan_settings_t cfs = { 0 };
#endif
_FIELD_TEST(controllerFan_settings);
EEPROM_READ(cfs);
TERN_(CONTROLLER_FAN_EDITABLE, if (!validating) controllerFan.settings = cfs);
}
//
// Power-Loss Recovery
//
{
_FIELD_TEST(recovery_enabled);
#if ENABLED(POWER_LOSS_RECOVERY)
const bool &recovery_enabled = recovery.enabled;
#else
bool recovery_enabled;
#endif
_FIELD_TEST(recovery_enabled);
EEPROM_READ(recovery_enabled);
TERN_(POWER_LOSS_RECOVERY, if (!validating) recovery.enabled = recovery_enabled);
}
//
// Firmware Retraction
//
{
fwretract_settings_t fwretract_settings;
bool autoretract_enabled;
_FIELD_TEST(fwretract_settings);
EEPROM_READ(fwretract_settings);
EEPROM_READ(autoretract_enabled);
#if ENABLED(FWRETRACT)
EEPROM_READ(fwretract.settings);
#else
fwretract_settings_t fwretract_settings;
EEPROM_READ(fwretract_settings);
#endif
#if BOTH(FWRETRACT, FWRETRACT_AUTORETRACT)
EEPROM_READ(fwretract.autoretract_enabled);
#else
bool autoretract_enabled;
EEPROM_READ(autoretract_enabled);
if (!validating) {
fwretract.settings = fwretract_settings;
TERN_(FWRETRACT_AUTORETRACT, fwretract.autoretract_enabled = autoretract_enabled);
}
#endif
}

View file

@ -127,7 +127,7 @@
#define LCD_RESET_PIN 16
#define DEFAULT_LCD_CONTRAST 220
#define LCD_CONTRAST_DEFAULT 220
#define LCD_BACKLIGHT_PIN -1
#else

View file

@ -107,7 +107,7 @@
#define LCD_CONTRAST_MIN 0
#define LCD_CONTRAST_MAX 100
#define DEFAULT_LCD_CONTRAST 30
#define LCD_CONTRAST_DEFAULT 30
//#define LCD_SCREEN_ROTATE 180 // 0, 90, 180, 270
#if IS_NEWPANEL

View file

@ -157,7 +157,7 @@
#define NEOPIXEL_PIN PB9
#endif
#define DEFAULT_LCD_CONTRAST 255
#define LCD_CONTRAST_DEFAULT 255
#else
#define LCD_PINS_RS PC15
#define LCD_PINS_ENABLE PB6