Added the window update packet and command

This commit is contained in:
2026-02-13 23:39:22 +00:00
parent 0f41e348c2
commit 8ccb066d1f
4 changed files with 66 additions and 13 deletions
+2 -1
View File
@@ -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);
+15 -3
View File
@@ -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) {
+39 -8
View File
@@ -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"));
+10 -1
View File
@@ -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 {