Added the window update packet and command
This commit is contained in:
@@ -9,7 +9,8 @@ typedef enum : uint8_t {
|
|||||||
CmdAckID = 2,
|
CmdAckID = 2,
|
||||||
CmdCreateWindow = 3,
|
CmdCreateWindow = 3,
|
||||||
CmdDestroyWindow = 4,
|
CmdDestroyWindow = 4,
|
||||||
CmdUpdateWinDims = 5
|
CmdUpdateWinDims = 5, // NOTE: change this to a move cmd instead
|
||||||
|
CmdUpdateWin = 6
|
||||||
} Command;
|
} Command;
|
||||||
|
|
||||||
char* CommandToStr(Command id);
|
char* CommandToStr(Command id);
|
||||||
|
|||||||
+15
-3
@@ -12,6 +12,7 @@ to have more ways to run analytics
|
|||||||
#include "UIComponent.h"
|
#include "UIComponent.h"
|
||||||
#include "UIDecorations.h"
|
#include "UIDecorations.h"
|
||||||
#include "UIDimensions.h"
|
#include "UIDimensions.h"
|
||||||
|
#include "UIDrawing.h"
|
||||||
#include "UIScreen.h"
|
#include "UIScreen.h"
|
||||||
#include "communication/commands.h"
|
#include "communication/commands.h"
|
||||||
#include "communication/packets.h"
|
#include "communication/packets.h"
|
||||||
@@ -133,10 +134,21 @@ void loop(void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CmdUpdateWinDims: {
|
case CmdUpdateWinDims: {
|
||||||
LOG_INFO(F("Updating Win\n"));
|
LOG_INFO(F("Updating Win DIMS\n"));
|
||||||
Window::UpdateDims(payload, &mainScreen);
|
bool res = Window::UpdateDims(payload, &mainScreen);
|
||||||
|
if (!res) {
|
||||||
|
LOG_WARN(F("Failed to update window dims\n"));
|
||||||
|
}
|
||||||
break;
|
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: {
|
case CmdDestroyWindow: {
|
||||||
uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen);
|
uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen);
|
||||||
if (destroyedWinID < 0) {
|
if (destroyedWinID < 0) {
|
||||||
|
|||||||
+39
-8
@@ -1,5 +1,6 @@
|
|||||||
#include "methods.h"
|
#include "methods.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "UIDecorations.h"
|
||||||
#include "UIDrawing.h"
|
#include "UIDrawing.h"
|
||||||
#include "communication/packets.h"
|
#include "communication/packets.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@@ -18,17 +19,21 @@ namespace Window {
|
|||||||
LOG_INFO(F(" Height: %d\n"), dims->height);
|
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) {
|
void printUIWindowPacket(UICreateWindowPacket *win) {
|
||||||
LOG_INFO(F("New window:\n"));
|
LOG_INFO(F("New window:\n"));
|
||||||
printUIDimsPacket(&win->dims);
|
printUIDimsPacket(&win->dims);
|
||||||
LOG_INFO(F(" Decorations:\n"));
|
printUIDecorPacket(&win->decor);
|
||||||
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);
|
|
||||||
LOG_INFO(F(" Title: %s\n"), win->title);
|
LOG_INFO(F(" Title: %s\n"), win->title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +97,32 @@ namespace Window {
|
|||||||
return true;
|
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
|
// Window destruction
|
||||||
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) {
|
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) {
|
||||||
LOG_INFO(F("Destroy window:\n"));
|
LOG_INFO(F("Destroy window:\n"));
|
||||||
|
|||||||
+10
-1
@@ -29,7 +29,9 @@ namespace Window {
|
|||||||
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win);
|
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win);
|
||||||
int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen);
|
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 {
|
struct UpdateDimsPacket {
|
||||||
int16_t wID;
|
int16_t wID;
|
||||||
UIDimensions dims;
|
UIDimensions dims;
|
||||||
@@ -37,6 +39,13 @@ namespace Window {
|
|||||||
|
|
||||||
void printUpdateDimsPacket(UpdateDimsPacket *pkt);
|
void printUpdateDimsPacket(UpdateDimsPacket *pkt);
|
||||||
bool UpdateDims(uint8_t *payload, Curses::Screen *mainScreen);
|
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 {
|
namespace Screen {
|
||||||
|
|||||||
Reference in New Issue
Block a user