From 8ccb066d1f77801f3152661fdc501aac428f0426 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Fri, 13 Feb 2026 23:39:22 +0000 Subject: [PATCH] Added the window update packet and command --- src/communication/commands.h | 3 ++- src/main.cpp | 18 +++++++++++--- src/methods/methods.cpp | 47 ++++++++++++++++++++++++++++++------ src/methods/methods.h | 11 ++++++++- 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/communication/commands.h b/src/communication/commands.h index 3af6021..9944fff 100644 --- a/src/communication/commands.h +++ b/src/communication/commands.h @@ -9,7 +9,8 @@ typedef enum : uint8_t { CmdAckID = 2, CmdCreateWindow = 3, CmdDestroyWindow = 4, - CmdUpdateWinDims = 5 + CmdUpdateWinDims = 5, // NOTE: change this to a move cmd instead + CmdUpdateWin = 6 } Command; char* CommandToStr(Command id); diff --git a/src/main.cpp b/src/main.cpp index 0451ce6..52b1076 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ to have more ways to run analytics #include "UIComponent.h" #include "UIDecorations.h" #include "UIDimensions.h" +#include "UIDrawing.h" #include "UIScreen.h" #include "communication/commands.h" #include "communication/packets.h" @@ -133,10 +134,21 @@ void loop(void) { break; } case CmdUpdateWinDims: { - LOG_INFO(F("Updating Win\n")); - Window::UpdateDims(payload, &mainScreen); + LOG_INFO(F("Updating Win DIMS\n")); + bool res = Window::UpdateDims(payload, &mainScreen); + if (!res) { + LOG_WARN(F("Failed to update window dims\n")); + } break; - } + }; + case CmdUpdateWin: { + LOG_INFO(F("UPDATEING WINDOW\n")); + bool res = Window::UpdateWindow(payload, &mainScreen); + if (!res) { + LOG_WARN(F("Failed to update window\n")); + } + break; + } case CmdDestroyWindow: { uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen); if (destroyedWinID < 0) { diff --git a/src/methods/methods.cpp b/src/methods/methods.cpp index 60ae01f..e7bae2d 100644 --- a/src/methods/methods.cpp +++ b/src/methods/methods.cpp @@ -1,5 +1,6 @@ #include "methods.h" #include "Arduino.h" +#include "UIDecorations.h" #include "UIDrawing.h" #include "communication/packets.h" #include "logger.h" @@ -18,17 +19,21 @@ namespace Window { LOG_INFO(F(" Height: %d\n"), dims->height); } + void printUIDecorPacket(UIDecorations *decor) { + LOG_INFO(F(" Decorations:\n")); + LOG_INFO(F(" HasBorder : %d\n"), decor->hasBorder); + LOG_INFO(F(" BGColour : %d\n"), decor->bgColor); + LOG_INFO(F(" FGColour : %d\n"), decor->fgColor); + LOG_INFO(F(" TitleColour : %d\n"), decor->titleColor); + LOG_INFO(F(" BorderColour: %d\n"), decor->borderColor); + LOG_INFO(F(" TitleSize : %d\n"), decor->titleSize); + LOG_INFO(F(" TextSize : %d\n"), decor->textSize); + } + void printUIWindowPacket(UICreateWindowPacket *win) { LOG_INFO(F("New window:\n")); printUIDimsPacket(&win->dims); - LOG_INFO(F(" Decorations:\n")); - LOG_INFO(F(" HasBorder : %d\n"), win->decor.hasBorder); - LOG_INFO(F(" BGColour : %d\n"), win->decor.bgColor); - LOG_INFO(F(" FGColour : %d\n"), win->decor.fgColor); - LOG_INFO(F(" TitleColour : %d\n"), win->decor.titleColor); - LOG_INFO(F(" BorderColour: %d\n"), win->decor.borderColor); - LOG_INFO(F(" TitleSize : %d\n"), win->decor.titleSize); - LOG_INFO(F(" TextSize : %d\n"), win->decor.textSize); + printUIDecorPacket(&win->decor); LOG_INFO(F(" Title: %s\n"), win->title); } @@ -92,6 +97,32 @@ namespace Window { return true; } + bool UpdateWindow(uint8_t *payload, Curses::Screen *mainScreen) { + UIUpdateWindowPacket pkt; + memcpy((void*)&pkt, payload, sizeof(UICreateWindowPacket)); + + printUIWindowPacket(&pkt.data); + + UIElement* mainWindow = mainScreen->mainWindowHandle; + UIElement* win = mainWindow->GetChild(pkt.WinID); + if (win == NULL) { + return false; + } + + // Delete the old window + fillRect(win->dims.x, win->dims.y, win->dims.width, + win->dims.height, win->decor.bgColor, win->display); + + // Update the windows dimensons, decor and title + win->dims = pkt.data.dims; + win->decor = pkt.data.decor; + win->SetTitle((char*)"%s [ %d]", pkt.data.title, pkt.WinID); + + win->drawBox(); + + return true; + } + // Window destruction void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) { LOG_INFO(F("Destroy window:\n")); diff --git a/src/methods/methods.h b/src/methods/methods.h index 3cc6a90..f48b75d 100644 --- a/src/methods/methods.h +++ b/src/methods/methods.h @@ -29,7 +29,9 @@ namespace Window { void printUIDestroyWindowPacket(UIDestroyWindowPacket *win); int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen); - // Window Updates + // NOTE: if I make the window update send these fields with the current + // values I can reduce the code for this to a single struct instead I reckon + // Window Dimensions Updates struct UpdateDimsPacket { int16_t wID; UIDimensions dims; @@ -37,6 +39,13 @@ namespace Window { void printUpdateDimsPacket(UpdateDimsPacket *pkt); bool UpdateDims(uint8_t *payload, Curses::Screen *mainScreen); + + struct UIUpdateWindowPacket { + int16_t WinID; + UICreateWindowPacket data; + }; + + bool UpdateWindow(uint8_t *payload, Curses::Screen *mainScreen); }; namespace Screen {