♻️ 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

@@ -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)