Skip to content

Commit

Permalink
clean up _draw_heater_status
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 15, 2023
1 parent fa0b78a commit 92c619c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void MarlinUI::draw_status_message(const bool blink) {
}
const bool hash_changed = hash != old_hash;
old_hash = hash;
return hash_changed || !ui.did_first_redraw;
return hash_changed || !did_first_redraw;
};

#if ENABLED(STATUS_MESSAGE_SCROLLING)
Expand Down
80 changes: 33 additions & 47 deletions Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
#define STATUS_CHR_WIDTH 14
#define STATUS_CHR_HEIGHT 28

bool old_is_printing;

//
// Before homing, blink '123' <-> '???'.
// Homed but unknown... '123' <-> ' '.
// Homed and known, display constantly.
//
FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink, const uint16_t x, const uint16_t y) {
const bool x_redraw = !ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning();
void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink, const uint16_t x, const uint16_t y) {
const bool x_redraw = !ui.did_first_redraw || old_is_printing != print_job_timer.isRunning();
if (x_redraw) {
dwin_string.set('X' + axis);
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black,
Expand Down Expand Up @@ -106,9 +108,9 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const

#if ENABLED(LCD_SHOW_E_TOTAL)

FORCE_INLINE void _draw_e_value(const_float_t value, const uint16_t x, const uint16_t y) {
void _draw_e_value(const_float_t value, const uint16_t x, const uint16_t y) {
const uint8_t scale = value >= 100000.0f ? 10 : 1; // show cm after 99,999mm
const bool e_redraw = !ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning();
const bool e_redraw = !ui.did_first_redraw || old_is_printing != print_job_timer.isRunning();

#if ENABLED(DWIN_MARLINUI_PORTRAIT)

Expand Down Expand Up @@ -187,72 +189,56 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
#endif
#endif

#if HAS_HOTEND && HAS_HEATED_BED
celsius_float_t tc, tt;
bool c_draw, t_draw, i_draw, ta;
const bool isBed = heater < 0;
if (isBed) {
celsius_float_t tc = 0, tt = 0;
bool isBed = (DISABLED(HAS_HOTEND) && ENABLED(HAS_HEATED_BED)) || (BOTH(HAS_HOTEND, HAS_HEATED_BED) && heater < 0),
ta = false, c_draw, t_draw, i_draw;
c_draw = t_draw = i_draw = !ui.did_first_redraw;
if (isBed) {
#if HAS_HEATED_BED
tc = thermalManager.degBed();
tt = thermalManager.degTargetBed();
ta = thermalManager.isHeatingBed();
c_draw = tc != old_bed_temp;
t_draw = tt != old_bed_target;
i_draw = ta != old_bed_on;
c_draw |= tc != old_bed_temp;
t_draw |= tt != old_bed_target;
i_draw |= ta != old_bed_on;
old_bed_temp = tc;
old_bed_target = tt;
old_bed_on = ta;
}
else {
#if HAS_LEVELING
i_draw |= planner.leveling_active != old_leveling_on;
old_leveling_on = planner.leveling_active;
#endif
#endif
}
else {
#if HAS_HOTEND
tc = thermalManager.degHotend(heater);
tt = thermalManager.degTargetHotend(heater);
ta = thermalManager.isHeatingHotend(heater);
c_draw = tc != old_temp[heater];
t_draw = tt != old_target[heater];
i_draw = ta != old_on[heater];
c_draw |= tc != old_temp[heater];
t_draw |= tt != old_target[heater];
i_draw |= ta != old_on[heater];
old_temp[heater] = tc;
old_target[heater] = tt;
old_on[heater] = ta;
}
#elif HAS_HOTEND
constexpr bool isBed = false;
const celsius_float_t tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
const bool ta = thermalManager.isHeatingHotend(heater);
bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta;
#elif HAS_HEATED_BED
constexpr bool isBed = true;
const celsius_float_t tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
const bool ta = thermalManager.isHeatingBed();
bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
#else
bool c_draw = false, t_draw = false, i_draw = false;
constexpr celsius_float_t tc = 0, tt = 0;
constexpr bool ta = 0;
#endif

#if HAS_HEATED_BED && HAS_LEVELING
if (isBed) {
i_draw |= (planner.leveling_active != old_leveling_on);
old_leveling_on = planner.leveling_active;
}
#endif
#endif
}

// Draw target temperature, if needed
if (!ui.did_first_redraw || t_draw) {
if (t_draw) {
dwin_string.set(i16tostr3rj(tt + 0.5));
dwin_string.add(LCD_STR_DEGREE);
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string()));
}

// Draw heater icon with on / off / leveled states
if (!ui.did_first_redraw || i_draw) {
if (i_draw) {
const uint8_t ico = isBed ? (TERN0(HAS_LEVELING, planner.leveling_active) ? ICON_BedLevelOff : ICON_BedOff) : ICON_HotendOff;
DWIN_ICON_Show(ICON, ico + ta, x, y + STATUS_CHR_HEIGHT + 2);
}

// Draw current temperature, if needed
if (!ui.did_first_redraw || c_draw) {
if (c_draw) {
dwin_string.set(i16tostr3rj(tc + 0.5));
dwin_string.add(LCD_STR_DEGREE);
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 70, S(dwin_string.string()));
Expand Down Expand Up @@ -394,7 +380,7 @@ void MarlinUI::draw_status_screen() {
}
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 378, 170, S(dwin_string.string()));
}
else if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
else if (!ui.did_first_redraw || old_is_printing != print_job_timer.isRunning()) {
dwin_string.set(F(" "));
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(dwin_string.string()));
}
Expand Down Expand Up @@ -450,7 +436,7 @@ void MarlinUI::draw_status_screen() {
draw_status_message(blink);

ui.did_first_redraw = true;
ui.old_is_printing = print_job_timer.isRunning();
old_is_printing = print_job_timer.isRunning();
}

#endif // IS_DWIN_MARLINUI
1 change: 0 additions & 1 deletion Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ void MarlinUI::init() {

#if IS_DWIN_MARLINUI
bool MarlinUI::did_first_redraw;
bool MarlinUI::old_is_printing;
#endif

#if ENABLED(SDSUPPORT)
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 @@ -503,7 +503,6 @@ class MarlinUI {

#if IS_DWIN_MARLINUI
static bool did_first_redraw;
static bool old_is_printing;
#endif

#if EITHER(BABYSTEP_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
Expand Down

0 comments on commit 92c619c

Please sign in to comment.