From 4e31fa66e2f402ac574ec4afa52447824444d90d Mon Sep 17 00:00:00 2001 From: Dmitry Pogrebnyak <aterlux@mail.ru> Date: Fri, 4 Aug 2023 22:59:17 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20STATUS=5FHEAT=5FPOWER=20(#25268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration_adv.h | 3 + Marlin/src/inc/SanityCheck.h | 4 ++ Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 74 +++++++++++++--------- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 6c29900cdf4..2577c27557e 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1967,7 +1967,10 @@ //#define STATUS_ALT_BED_BITMAP // Use the alternative bed bitmap //#define STATUS_ALT_FAN_BITMAP // Use the alternative fan bitmap //#define STATUS_FAN_FRAMES 3 // :[0,1,2,3,4] Number of fan animation frames + + // Only one STATUS_HEAT_* option can be enabled //#define STATUS_HEAT_PERCENT // Show heating in a progress bar + //#define STATUS_HEAT_POWER // Show heater output power as a vertical bar // Frivolous Game Options //#define MARLIN_BRICKOUT diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 5933c8c396a..ee23fc42707 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -404,6 +404,10 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L #error "CUSTOM_STATUS_SCREEN_IMAGE requires a 128x64 DOGM B/W Graphical LCD." #endif +#if ALL(STATUS_HEAT_PERCENT, STATUS_HEAT_POWER) + #error "Only enable STATUS_HEAT_PERCENT or STATUS_HEAT_POWER, but not both." +#endif + /** * LCD Lightweight Screen Style */ diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index 2067a8428da..d38d28c8cd3 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -247,14 +247,13 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co const celsius_t temp = thermalManager.wholeDegHotend(heater_id), target = thermalManager.degTargetHotend(heater_id); - #if DISABLED(STATUS_HOTEND_ANIM) - #define STATIC_HOTEND true - #define HOTEND_DOT isHeat - #else - #define STATIC_HOTEND false - #define HOTEND_DOT false + #if ENABLED(STATUS_HEAT_POWER) + const uint16_t power = thermalManager.getHeaterPower(heater_id); #endif + #define STATIC_HOTEND DISABLED(STATUS_HOTEND_ANIM) + #define HOTEND_DOT TERN(STATUS_HOTEND_ANIM, false, isHeat) + #if ENABLED(STATUS_HOTEND_NUMBERLESS) #define OFF_BMP(N) TERN(STATUS_HOTEND_INVERTED, status_hotend_b_bmp, status_hotend_a_bmp) #define ON_BMP(N) TERN(STATUS_HOTEND_INVERTED, status_hotend_a_bmp, status_hotend_b_bmp) @@ -285,23 +284,34 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co #define BAR_TALL (STATUS_HEATERS_HEIGHT - 2) - const float prop = target - 20, - perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0; - uint8_t tall = uint8_t(perc * BAR_TALL + 0.5f); - NOMORE(tall, BAR_TALL); - // Draw hotend bitmap, either whole or split by the heating percent const uint8_t hx = STATUS_HOTEND_X(heater_id), bw = STATUS_HOTEND_BYTEWIDTH(heater_id); - #if ENABLED(STATUS_HEAT_PERCENT) - if (isHeat && tall <= BAR_TALL) { + #if ANY(STATUS_HEAT_PERCENT, STATUS_HEAT_POWER) + uint8_t tall = 0; + #if ENABLED(STATUS_HEAT_POWER) + // Rounded int. At least 1 pixel tall on minimal PWM. + tall = power ? (power >= 127 ? BAR_TALL : (uint16_t((uint8_t(power) * BAR_TALL) + 127U) / 128U)) : 0; + #elif ENABLED(STATUS_HEAT_PERCENT) + const float prop = target - 20, + perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0; + tall = uint8_t(perc * BAR_TALL + 0.5f); + #endif + + NOMORE(tall, BAR_TALL); + + const bool draw_partial = isHeat && tall < BAR_TALL; + if (draw_partial) { const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall; u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(TERN(HAS_MMU, active_extruder, heater_id), false)); u8g.drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(TERN(HAS_MMU, active_extruder, heater_id), true) + ph * bw); } - else + #else + constexpr bool draw_partial = false; #endif - u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(TERN(HAS_MMU, active_extruder, heater_id), isHeat)); + + if (!draw_partial) + u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(TERN(HAS_MMU, active_extruder, heater_id), isHeat)); } // PAGE_CONTAINS @@ -342,29 +352,31 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co const celsius_t temp = thermalManager.wholeDegBed(), target = thermalManager.degTargetBed(); - #if ENABLED(STATUS_HEAT_PERCENT) || DISABLED(STATUS_BED_ANIM) + #if ANY(STATUS_HEAT_PERCENT, STATUS_HEAT_POWER) || DISABLED(STATUS_BED_ANIM) const bool isHeat = BED_ALT(); #endif - #if DISABLED(STATUS_BED_ANIM) - #define STATIC_BED true - #define BED_DOT isHeat - #else - #define STATIC_BED false - #define BED_DOT false - #endif + #define STATIC_BED DISABLED(STATUS_BED_ANIM) + #define BED_DOT TERN(STATUS_BED_ANIM, false, isHeat) if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_BOT)) { #define BAR_TALL (STATUS_HEATERS_HEIGHT - 2) - const float prop = target - 20, - perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0; - uint8_t tall = uint8_t(perc * BAR_TALL + 0.5f); - NOMORE(tall, BAR_TALL); // Draw a heating progress bar, if specified - #if ENABLED(STATUS_HEAT_PERCENT) + #if ANY(STATUS_HEAT_PERCENT, STATUS_HEAT_POWER) + uint8_t tall = 0; + #if ENABLED(STATUS_HEAT_POWER) + const uint16_t power = thermalManager.getHeaterPower(H_BED); + tall = power ? (power >= 127) ? BAR_TALL : uint16_t((uint8_t(power) * BAR_TALL) + 127U) / 128U : 0; + #elif ENABLED(STATUS_HEAT_PERCENT) + const float prop = target - 20, + perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0; + tall = uint8_t(perc * BAR_TALL + 0.5f); + #endif + + NOMORE(tall, BAR_TALL); if (isHeat) { const uint8_t bx = STATUS_BED_X + STATUS_BED_WIDTH; @@ -538,9 +550,11 @@ void MarlinUI::draw_status_screen() { #if ANIM_HBCC uint8_t new_bits = 0; #if ANIM_HOTEND - HOTEND_LOOP() if (thermalManager.isHeatingHotend(e)) SBI(new_bits, DRAWBIT_HOTEND + e); + HOTEND_LOOP() if (thermalManager.TERN(STATUS_HEAT_POWER, getHeaterPower(heater_id_t(e)), isHeatingHotend(e))) SBI(new_bits, DRAWBIT_HOTEND + e); + #endif + #if ANIM_BED + if (TERN(STATUS_HEAT_POWER, (thermalManager.degTargetBed() || thermalManager.getHeaterPower(H_BED)), thermalManager.isHeatingBed())) SBI(new_bits, DRAWBIT_BED); #endif - if (TERN0(ANIM_BED, thermalManager.isHeatingBed())) SBI(new_bits, DRAWBIT_BED); #if DO_DRAW_CHAMBER && HAS_HEATED_CHAMBER if (thermalManager.isHeatingChamber()) SBI(new_bits, DRAWBIT_CHAMBER); #endif