From bc696ae5b2ff88c85847b969b5c6a0fdae3eb4ac Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Tue, 14 Jul 2026 23:51:24 +0200 Subject: [PATCH] Power off: CRT-style collapse animation Replace the 'Power Off' / 73 message on colour displays with a shut-off animation that collapses the current screen towards the middle (vertical squeeze to a line, then horizontal collapse to a centre dot) like an old CRT. Snapshots the live framebuffer into the (idle) notification offscreen buffer so no extra RAM is needed; runs blocking with vTaskDelay between frames. Mono displays keep the existing message. Docs updated. Co-Authored-By: Claude Fable 5 --- CHANGELOG.md | 6 ++ MANUAL.md | 5 + .../include/user_interface/menuSystem.h | 3 + .../source/user_interface/uiNotification.c | 9 ++ .../source/user_interface/uiPowerOff.c | 100 ++++++++++++++++-- README.md | 2 + 6 files changed, 119 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f02664..d9276bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ single running list until the first versioned release. _Nothing yet._ +## 0.11.0 + +- **CRT-style shut-off animation** — when powering off, the current screen + collapses towards the middle (squeezed to a line, then a dot) like an old CRT + switching off, replacing the "Power Off" message. (Colour displays only.) + ## 0.10.1 - **Fix:** the muted **"M"** indicator in the status bar overlapped the GPS text diff --git a/MANUAL.md b/MANUAL.md index e98999d..077f369 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -59,6 +59,11 @@ Optionally dims the backlight after inactivity to **100 / 50 / 30 / 15 %** of th configured brightness (only in **Auto** backlight mode). Any activity restores full brightness. Set it in **Menu → Options → Display Options → Screen Dim**. +### Shut-off animation — 🟢 [FreeTRX] +Powering off collapses whatever is on screen towards the middle — squeezed to a +line, then a dot — like an old CRT switching off, in place of the "Power Off" +message. (Once the animation starts, the power-off is committed.) + ### Theme presets — 🟢 [FreeTRX] Pick a colour theme on the radio at **Menu → Options → Display Options → "Theme"** (◀/▶ to change; the screen updates live): diff --git a/MDUV380_firmware/application/include/user_interface/menuSystem.h b/MDUV380_firmware/application/include/user_interface/menuSystem.h index f003f88..9ca51f0 100644 --- a/MDUV380_firmware/application/include/user_interface/menuSystem.h +++ b/MDUV380_firmware/application/include/user_interface/menuSystem.h @@ -267,6 +267,9 @@ bool uiNotificationHasTimedOut(void); bool uiNotificationIsVisible(void); void uiNotificationHide(bool immediateRender); uiNotificationID_t uiNotificationGetId(void); +#if defined(HAS_COLOURS) +uint16_t *uiNotificationGetOffscreenBuffer(void); // full-screen scratch (borrowed by the shutdown animation) +#endif #if defined(HAS_GPS) diff --git a/MDUV380_firmware/application/source/user_interface/uiNotification.c b/MDUV380_firmware/application/source/user_interface/uiNotification.c index 396be5b..5686707 100644 --- a/MDUV380_firmware/application/source/user_interface/uiNotification.c +++ b/MDUV380_firmware/application/source/user_interface/uiNotification.c @@ -351,6 +351,15 @@ uiNotificationID_t uiNotificationGetId(void) return notificationData.id; } +#if defined(HAS_COLOURS) +// Expose the full-screen offscreen buffer so the shutdown animation can borrow +// it as scratch (no notification is active while powering off). +uint16_t *uiNotificationGetOffscreenBuffer(void) +{ + return screenNotificationBufData; +} +#endif + static void displayMessage(void) { char msg[SCREEN_LINE_BUFFER_SIZE]; diff --git a/MDUV380_firmware/application/source/user_interface/uiPowerOff.c b/MDUV380_firmware/application/source/user_interface/uiPowerOff.c index a92203e..f1897a3 100644 --- a/MDUV380_firmware/application/source/user_interface/uiPowerOff.c +++ b/MDUV380_firmware/application/source/user_interface/uiPowerOff.c @@ -25,18 +25,25 @@ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ +#include #include "user_interface/uiGlobals.h" #include "user_interface/menuSystem.h" #include "user_interface/uiLocalisation.h" +#include "functions/ticks.h" #if defined(PLATFORM_MD9600) || defined(PLATFORM_MD380) || defined(PLATFORM_MDUV380) || defined(PLATFORM_RT84_DM1701) || defined(PLATFORM_MD2017) #include "interfaces/batteryAndPowerManagement.h" #include "hardware/radioHardwareInterface.h" #endif +const uint32_t POWEROFF_DURATION_MILLISECONDS = 500; + +#if defined(HAS_COLOURS) +static void crtShutdownAnimation(void); +#else +static uint32_t initialEventTime; static void updateScreen(void); static void handleEvent(uiEvent_t *ev); -static uint32_t initialEventTime; -const uint32_t POWEROFF_DURATION_MILLISECONDS = 500; +#endif menuStatus_t uiPowerOff(uiEvent_t *ev, bool isFirstRun) { @@ -49,23 +56,103 @@ menuStatus_t uiPowerOff(uiEvent_t *ev, bool isFirstRun) } #endif +#if defined(HAS_COLOURS) + // Old-CRT-style collapse of whatever is currently on screen; replaces + // the "Power Off" / 73 message, then shuts down. + crtShutdownAnimation(); + powerOffFinalStage(false, false); +#else updateScreen(); initialEventTime = ev->time; +#endif } else { +#if !defined(HAS_COLOURS) handleEvent(ev); +#endif } return MENU_STATUS_SUCCESS; } +#if defined(HAS_COLOURS) +static void crtShutdownAnimation(void) +{ + const int W = DISPLAY_SIZE_X; + const int H = DISPLAY_SIZE_Y; + const int cx = W / 2; + const int cy = H / 2; + const int VSTEPS = 12; + const int HSTEPS = 12; + const uint16_t white = 0xFFFF; + + displayRestorePrimaryScreenBuffer(); + + uint16_t *fb = displayGetPrimaryScreenBuffer(); + uint16_t *snap = uiNotificationGetOffscreenBuffer(); + + // snapshot the screen as it is right now + memcpy(snap, fb, W * H * sizeof(uint16_t)); + + // Phase 1: squeeze the whole image vertically into a thin central band. + for (int step = 1; step <= VSTEPS; step++) + { + int bandH = H - ((H - 2) * step) / VSTEPS; // 128 -> 2 + int top = cy - (bandH / 2); + + memset(fb, 0, W * H * sizeof(uint16_t)); + + for (int dy = 0; dy < bandH; dy++) + { + int srcY = (dy * H) / bandH; + + if (srcY >= H) + { + srcY = H - 1; + } + memcpy(&fb[(top + dy) * W], &snap[srcY * W], W * sizeof(uint16_t)); + } + + displayRender(); + vTaskDelay((15 / portTICK_PERIOD_MS)); + } + + // Phase 2: the band becomes a bright line that collapses horizontally. + for (int step = 1; step <= HSTEPS; step++) + { + int lineW = W - ((W - 2) * step) / HSTEPS; // 160 -> 2 + int left = cx - (lineW / 2); + + memset(fb, 0, W * H * sizeof(uint16_t)); + + for (int dx = 0; dx < lineW; dx++) + { + fb[((cy - 1) * W) + (left + dx)] = white; + fb[(cy * W) + (left + dx)] = white; + } + + displayRender(); + vTaskDelay((15 / portTICK_PERIOD_MS)); + } + + // Phase 3: a brief central dot, then black. + memset(fb, 0, W * H * sizeof(uint16_t)); + fb[((cy - 1) * W) + (cx - 1)] = white; + fb[((cy - 1) * W) + cx] = white; + fb[(cy * W) + (cx - 1)] = white; + fb[(cy * W) + cx] = white; + displayRender(); + vTaskDelay((70 / portTICK_PERIOD_MS)); + + memset(fb, 0, W * H * sizeof(uint16_t)); + displayRender(); +} +#endif + +#if !defined(HAS_COLOURS) static void updateScreen(void) { -#if defined(HAS_COLOURS) - bool dblHeight = settingsIsOptionBitSet(BIT_UI_USES_DOUBLE_HEIGHT); -#else const bool dblHeight = false; -#endif uint16_t fontHeight = (FONT_SIZE_3_HEIGHT * (dblHeight ? 2 : 1)); displayClearBuf(); @@ -104,3 +191,4 @@ static void handleEvent(uiEvent_t *ev) } } +#endif diff --git a/README.md b/README.md index e2a1878..bc2122d 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ FreeTRX keeps OpenGD77's core (DMR/FM, hotspot, CPS compatibility) and adds: or **Pride** (rainbow background). CPS edits only affect Custom. - **On-radio channel management** — create and delete channels directly from the Channel quick menu, no PC/CPS required (see [Managing channels](#managing-channels-on-the-radio)). +- **CRT-style shut-off animation** — the current screen collapses to a line and + then a dot, like an old CRT switching off (replaces the "Power Off" message). - **DMR reliability fix** — resolves a hard-fault (freeze needing a battery pull) on the DMR path that affected recent self-built OpenGD77 revisions.