Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jan 20, 2022
1 parent 4343cdd commit d88a840
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 55 deletions.
3 changes: 0 additions & 3 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,6 @@

#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
Expand Down
7 changes: 1 addition & 6 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,7 @@ void MarlinUI::init_lcd() {
WRITE(LCD_BACKLIGHT_PIN, HIGH);
#endif

#if HAS_LCD_CONTRAST
if (contrast_set)
refresh_contrast();
else
u8g.setContrast(DEFAULT_LCD_CONTRAST);
#endif
TERN_(HAS_LCD_CONTRAST, refresh_contrast());

#if LCD_SCREEN_ROTATE == 90
u8g.setRot90();
Expand Down
9 changes: 2 additions & 7 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#endif

#if HAS_LCD_CONTRAST
uint8_t MarlinUI::contrast; // Initialized by settings.load()
bool MarlinUI::contrast_set; // Ditto
uint8_t MarlinUI::contrast; // Initialized by settings.load()
void MarlinUI::set_contrast(const uint8_t value) {
if (!contrast_set) {
contrast = DEFAULT_LCD_CONTRAST;
contrast_set = true; // will now be sticky on NVRAM save
} else
contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
_set_contrast();
}
#endif
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ class MarlinUI {

#if HAS_LCD_CONTRAST
static uint8_t contrast;
static bool contrast_set;
static void _set_contrast(); // Implementation-specific
static void set_contrast(const uint8_t value);
FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
Expand Down
58 changes: 20 additions & 38 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,6 @@ typedef struct SettingsDataStruct {
// HAS_LCD_CONTRAST
//
uint8_t lcd_contrast; // M250 C
bool lcd_contrast_set; // flag determines if ui save occured.


//
// HAS_LCD_BRIGHTNESS
Expand Down Expand Up @@ -1090,9 +1088,6 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(lcd_contrast);
const uint8_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
EEPROM_WRITE(lcd_contrast);
_FIELD_TEST(lcd_contrast_set);
const bool lcd_contrast_set = TERN(HAS_LCD_CONTRAST, ui.contrast_set, false);
EEPROM_WRITE(lcd_contrast_set);
}

//
Expand Down Expand Up @@ -1970,44 +1965,39 @@ 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

//
// Power monitor
//
{
#if HAS_POWER_MONITOR
uint8_t &power_monitor_flags = power_monitor.flags;
#else
uint8_t power_monitor_flags;
#endif
uint8_t power_monitor_flags;
_FIELD_TEST(power_monitor_flags);
EEPROM_READ(power_monitor_flags);
TERN_(HAS_POWER_MONITOR, if (!validating) power_monitor.flags = power_monitor_flags);
}

//
// LCD Contrast
//
{
_FIELD_TEST(lcd_contrast);
uint8_t lcd_contrast;
_FIELD_TEST(lcd_contrast);
EEPROM_READ(lcd_contrast);
TERN_(HAS_LCD_CONTRAST, ui.contrast = lcd_contrast);
_FIELD_TEST(lcd_contrast_set);
bool lcd_contrast_set;
EEPROM_READ(lcd_contrast_set);
TERN_(HAS_LCD_CONTRAST, ui.contrast_set = lcd_contrast_set);
TERN_(HAS_LCD_CONTRAST, if (!validating) ui.set_contrast(lcd_contrast));
}

//
// LCD Brightness
//
{
_FIELD_TEST(lcd_brightness);
uint8_t lcd_brightness;
_FIELD_TEST(lcd_brightness);
EEPROM_READ(lcd_brightness);
TERN_(HAS_LCD_BRIGHTNESS, if (!validating) ui.set_brightness(lcd_brightness));
}
Expand All @@ -2016,45 +2006,37 @@ void MarlinSettings::postprocess() {
// Controller Fan
//
{
controllerFan_settings_t cfs = { 0 };
_FIELD_TEST(controllerFan_settings);
#if ENABLED(CONTROLLER_FAN_EDITABLE)
const controllerFan_settings_t &cfs = controllerFan.settings;
#else
controllerFan_settings_t cfs = { 0 };
#endif
EEPROM_READ(cfs);
TERN_(CONTROLLER_FAN_EDITABLE, if (!validating) controllerFan.settings = cfs);
}

//
// Power-Loss Recovery
//
{
bool recovery_enabled;
_FIELD_TEST(recovery_enabled);
#if ENABLED(POWER_LOSS_RECOVERY)
const bool &recovery_enabled = recovery.enabled;
#else
bool recovery_enabled;
#endif
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
}

Expand Down

0 comments on commit d88a840

Please sign in to comment.