Skip to content

Commit

Permalink
🩹 Fan Menu / Status fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 17, 2023
1 parent 71e6f70 commit c3b037e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 118 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
164 changes: 65 additions & 99 deletions Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,72 +61,54 @@
#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) {

#if ENABLED(DWIN_MARLINUI_PORTRAIT)

uint8_t vallen = utf8_strlen(value);
if (!ui.did_first_redraw) {
dwin_string.set('X' + axis);
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (vallen * 14 - 14) / 2, y + 2, S(dwin_string.string()));
}

dwin_string.set();
if (blink)
dwin_string.add(value);
else if (!TEST(axes_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axes_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
dwin_string.add(value);

// For E_TOTAL there may be some characters to cover up
if (BOTH(DWIN_MARLINUI_PORTRAIT, LCD_SHOW_E_TOTAL) && axis == X_AXIS)
dwin_string.add(F(" "));

DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));

#else // !DWIN_MARLINUI_PORTRAIT

if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
dwin_string.set('X' + axis);
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
}

dwin_string.set();
if (blink)
dwin_string.add(value);
else {
if (!TEST(axes_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else {
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
if (!TEST(axes_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
#endif
dwin_string.add(value);
}
}

// For E_TOTAL there may be some characters to cover up
if (ENABLED(LCD_SHOW_E_TOTAL) && (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) && axis == X_AXIS)
dwin_string.add(F(" "));

DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 32, y + 4, S(dwin_string.string()));
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,
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
x + (utf8_strlen(value) * 14 - 14) / 2, y + 2
#else
x, y
#endif
, S(dwin_string.string())
);
}

#endif // !DWIN_MARLINUI_PORTRAIT
dwin_string.set();
if (blink)
dwin_string.add(value);
else if (!TEST(axes_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axes_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
dwin_string.add(value);

// For E_TOTAL there may be some characters to cover up
if (TERN0(LCD_SHOW_E_TOTAL, x_redraw && axis == X_AXIS))
dwin_string.add(F(" "));

DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black,
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
x, y + 32
#else
x + 32, y + 4
#endif
, S(dwin_string.string())
);
}

#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

#if ENABLED(DWIN_MARLINUI_PORTRAIT)
Expand Down Expand Up @@ -207,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
float 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 float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
const uint8_t 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 float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
const uint8_t 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 float tc = 0, tt = 0;
constexpr uint8_t 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 @@ -414,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 @@ -470,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
8 changes: 0 additions & 8 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,3 @@ namespace Language_en {
LSTR MSG_PID_F_E = _UxGT("PID-F *");
LSTR MSG_BACKLASH_N = _UxGT("@");
}

#if FAN_COUNT == 1
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED
#else
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED_N
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED_N
#endif
1 change: 0 additions & 1 deletion Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,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 @@ -501,7 +501,6 @@ class MarlinUI {

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

#if EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
Expand Down
8 changes: 8 additions & 0 deletions Marlin/src/lcd/menu/menu_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ class MenuItem_bool : public MenuEditItemBase {
#define EDIT_EXTRA_FAN_SPEED(...)
#endif

#if FAN_COUNT == 1
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED
#else
#define MSG_FIRST_FAN_SPEED MSG_FAN_SPEED_N
#define MSG_EXTRA_FIRST_FAN_SPEED MSG_EXTRA_FAN_SPEED_N
#endif

#define _FAN_EDIT_ITEMS(F,L) do{ \
editable.uint8 = thermalManager.fan_speed[F]; \
EDIT_ITEM_FAST_N(percent, F, MSG_##L, &editable.uint8, 0, 255, on_fan_update); \
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/lcd/menu/menu_tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,37 +156,37 @@ void menu_tune() {
#if HAS_FAN0
_FAN_EDIT_ITEMS(0,FIRST_FAN_SPEED);
#endif
#if HAS_FAN1
#if HAS_FAN1 && REDUNDANT_PART_COOLING_FAN != 1
FAN_EDIT_ITEMS(1);
#elif SNFAN(1)
singlenozzle_item(1);
#endif
#if HAS_FAN2
#if HAS_FAN2 && REDUNDANT_PART_COOLING_FAN != 2
FAN_EDIT_ITEMS(2);
#elif SNFAN(2)
singlenozzle_item(2);
#endif
#if HAS_FAN3
#if HAS_FAN3 && REDUNDANT_PART_COOLING_FAN != 3
FAN_EDIT_ITEMS(3);
#elif SNFAN(3)
singlenozzle_item(3);
#endif
#if HAS_FAN4
#if HAS_FAN4 && REDUNDANT_PART_COOLING_FAN != 4
FAN_EDIT_ITEMS(4);
#elif SNFAN(4)
singlenozzle_item(4);
#endif
#if HAS_FAN5
#if HAS_FAN5 && REDUNDANT_PART_COOLING_FAN != 5
FAN_EDIT_ITEMS(5);
#elif SNFAN(5)
singlenozzle_item(5);
#endif
#if HAS_FAN6
#if HAS_FAN6 && REDUNDANT_PART_COOLING_FAN != 6
FAN_EDIT_ITEMS(6);
#elif SNFAN(6)
singlenozzle_item(6);
#endif
#if HAS_FAN7
#if HAS_FAN7 && REDUNDANT_PART_COOLING_FAN != 7
FAN_EDIT_ITEMS(7);
#elif SNFAN(7)
singlenozzle_item(7);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "touch.h"

#include "../marlinui.h" // for ui methods
#include "../menu/menu_item.h" // for touch_screen_calibration
#include "../menu/menu_item.h" // for MSG_FIRST_FAN_SPEED

#include "../../module/temperature.h"
#include "../../module/planner.h"
Expand Down

0 comments on commit c3b037e

Please sign in to comment.