Should I manually copy bytes?
This commit is contained in:
@@ -40,7 +40,7 @@ namespace WalkieTalkie {
|
||||
}
|
||||
|
||||
static inline void RecvPayloadRoutine(uint8_t *payload, byte *b) {
|
||||
LOG_TRACE(F("Reading payload: %d %s %d\n"), bufferIndex, " - ", *b);
|
||||
LOG_TRACE(F("Reading payload: %-.3d %s 0x%02x\n"), bufferIndex, " - ", *b);
|
||||
|
||||
buffer[bufferIndex++] = *b;
|
||||
if (bufferIndex == len) {
|
||||
|
||||
+2
-68
@@ -55,7 +55,6 @@ Arduino_ESP32RGBPanel *panel = new Arduino_ESP32RGBPanel(
|
||||
//
|
||||
Arduino_GFX *gfx = new Arduino_RGB_Display(TFT_HOR_RES, TFT_VER_RES, panel, 16);
|
||||
|
||||
// HardwareSerial debugSerial(1);
|
||||
Curses::Screen mainScreen(gfx, UIDimensions(0, 0, TFT_HOR_RES, TFT_VER_RES),
|
||||
UIDecorations());
|
||||
|
||||
@@ -85,78 +84,13 @@ void setup() {
|
||||
|
||||
// Only setup the main screen after initializing the Serial2
|
||||
mainScreen.Setup("Main Window");
|
||||
|
||||
// Grab a handle for the main window of the screen
|
||||
UIElement *mainWindow = mainScreen.mainWindowHandle;
|
||||
mainWindow->drawBox();
|
||||
|
||||
// int16_t childID = mainWindow->AddChild(STRING);
|
||||
// if (childID < 0) {
|
||||
// Serial2.println("Failed to add new window!");
|
||||
// } else {
|
||||
// Serial2.print("Successfully added a new window: ");
|
||||
// Serial2.println(childID);
|
||||
//
|
||||
// UIElement *childComponent = mainWindow->GetChild(childID);
|
||||
//
|
||||
// childComponent->SetTitle((char *)"%s [%2d]", (const char *)"Child Window",
|
||||
// childID);
|
||||
// childComponent->SetUIDecorations(UIDecorations());
|
||||
// childComponent->SetUIDimensions(UIDimensions(20, 20, 300, 300));
|
||||
// childComponent->SetDisplay(mainScreen.display);
|
||||
//
|
||||
// childComponent->drawBox();
|
||||
// }
|
||||
//
|
||||
// childID = mainWindow->AddChild(STRING);
|
||||
// if (childID < 0) {
|
||||
// Serial2.println("Failed to add new window!");
|
||||
// } else {
|
||||
// Serial2.print("Successfully added a new window: ");
|
||||
// Serial2.println(childID);
|
||||
//
|
||||
// UIElement *childComponent = mainWindow->GetChild(childID);
|
||||
//
|
||||
// childComponent->SetTitle((char *)"%s [%2d]", (const char *)"Second Child",
|
||||
// childID);
|
||||
// childComponent->SetUIDecorations(UIDecorations());
|
||||
// childComponent->SetUIDimensions(UIDimensions(330, 20, 300, 300));
|
||||
// childComponent->SetDisplay(mainScreen.display);
|
||||
//
|
||||
// childComponent->drawBox();
|
||||
// }
|
||||
//
|
||||
// mainWindow->RemoveChild(1);
|
||||
//
|
||||
// childID = mainWindow->AddChild(STRING);
|
||||
// if (childID < 0) {
|
||||
// Serial2.println("Failed to add new window!");
|
||||
// } else {
|
||||
// Serial2.print("Successfully added a new window: ");
|
||||
// Serial2.println(childID);
|
||||
//
|
||||
// UIElement *childComponent = mainWindow->GetChild(childID);
|
||||
//
|
||||
// childComponent->SetTitle((char *)"%s [%2d]", (const char *)"Third Child",
|
||||
// childID);
|
||||
// childComponent->SetUIDecorations(UIDecorations());
|
||||
// childComponent->SetUIDimensions(UIDimensions(20, 20, 300, 300));
|
||||
// childComponent->SetDisplay(mainScreen.display);
|
||||
//
|
||||
// childComponent->drawBox();
|
||||
// }
|
||||
|
||||
WindowPool::PrintInUse();
|
||||
|
||||
delay(500);
|
||||
LOG_INFO(F("* Ready for loop"));
|
||||
}
|
||||
|
||||
uint64_t lastDataRead = 0;
|
||||
|
||||
bool gotAck = false;
|
||||
|
||||
uint64_t lastSent = 0;
|
||||
void loop(void) {
|
||||
uint64_t cur = millis();
|
||||
|
||||
@@ -183,7 +117,7 @@ void loop(void) {
|
||||
WalkieTalkie::SendData(&papers);
|
||||
break;
|
||||
case CmdCreateWindow: {
|
||||
uint8_t newWindowID = CreateWindow::Create(payload, &mainScreen);
|
||||
uint8_t newWindowID = Window::Create(payload, &mainScreen);
|
||||
if (newWindowID < 0) {
|
||||
LOG_WARN(F("Failed to add new window!\n"));
|
||||
break;
|
||||
@@ -196,7 +130,7 @@ void loop(void) {
|
||||
break;
|
||||
}
|
||||
case CmdDestroyWindow: {
|
||||
uint8_t destroyedWinID = DestroyWindow::Destroy(payload, &mainScreen);
|
||||
uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen);
|
||||
if (destroyedWinID < 0) {
|
||||
LOG_WARN(F("Failed to destroy window\n"));
|
||||
break;
|
||||
|
||||
+28
-12
@@ -3,22 +3,38 @@
|
||||
#include "logger.h"
|
||||
#include "UIComponent.h"
|
||||
#include "UIScreen.h"
|
||||
#include <cstdint>
|
||||
#include <string.h>
|
||||
|
||||
namespace CreateWindow {
|
||||
namespace Window {
|
||||
// Window creation
|
||||
void printUIWindowPacket(UICreateWindowPacket *win) {
|
||||
LOG_INFO(F("New window:\n"));
|
||||
LOG_INFO(F(" X0 : %d\n"), win->x0);
|
||||
LOG_INFO(F(" Y0 : %d\n"), win->y0);
|
||||
LOG_INFO(F(" Width : %d\n"), win->width);
|
||||
LOG_INFO(F(" Height: %d\n"), win->height);
|
||||
LOG_INFO(F(" Dimensions:\n"));
|
||||
LOG_INFO(F(" X0 : %d\n"), win->dims.x);
|
||||
LOG_INFO(F(" Y0 : %d\n"), win->dims.y);
|
||||
LOG_INFO(F(" Width : %d\n"), win->dims.width);
|
||||
LOG_INFO(F(" Height: %d\n"), win->dims.height);
|
||||
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);
|
||||
LOG_INFO(F(" Title: %s\n"), win->title);
|
||||
}
|
||||
|
||||
UICreateWindowPacket::UICreateWindowPacket() {}
|
||||
|
||||
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) {
|
||||
// Load the payload into a struct
|
||||
CreateWindow::UICreateWindowPacket win;
|
||||
memcpy(&win, payload, sizeof(CreateWindow::UICreateWindowPacket));
|
||||
// UICreateWindowPacket* win;
|
||||
UICreateWindowPacket win;
|
||||
// Maybe find a better way to copy this - if we had metadata to the payload
|
||||
// for example
|
||||
memcpy((void*)&win, payload, sizeof(UICreateWindowPacket));
|
||||
printUIWindowPacket(&win);
|
||||
|
||||
UIElement *mainWindow = mainScreen->mainWindowHandle;
|
||||
@@ -31,24 +47,24 @@ namespace CreateWindow {
|
||||
|
||||
childComponent->SetTitle((char *)"%s [%2d]", (const char *)win.title, childID);
|
||||
childComponent->SetUIDecorations(UIDecorations());
|
||||
childComponent->SetUIDimensions(UIDimensions(win.x0, win.y0, win.width, win.height));
|
||||
childComponent->SetUIDimensions(UIDimensions(win.dims.x, win.dims.y,
|
||||
win.dims.width, win.dims.height));
|
||||
childComponent->SetDisplay(mainScreen->display);
|
||||
|
||||
childComponent->drawBox();
|
||||
|
||||
return childID;
|
||||
}
|
||||
};
|
||||
|
||||
namespace DestroyWindow {
|
||||
// Window destruction
|
||||
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) {
|
||||
LOG_INFO(F("Destroy window:\n"));
|
||||
LOG_INFO(F(" WinID: %d\n"), win->WinID);
|
||||
}
|
||||
|
||||
int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen) {
|
||||
DestroyWindow::UIDestroyWindowPacket win;
|
||||
memcpy(&win, payload, sizeof(DestroyWindow::UIDestroyWindowPacket));
|
||||
UIDestroyWindowPacket win;
|
||||
memcpy(&win, payload, sizeof(UIDestroyWindowPacket));
|
||||
printUIDestroyWindowPacket(&win);
|
||||
|
||||
UIElement *mainWindow = mainScreen->mainWindowHandle;
|
||||
|
||||
+20
-7
@@ -4,22 +4,24 @@
|
||||
#include <cstdint>
|
||||
#include <stdint.h>
|
||||
#include "UIScreen.h"
|
||||
#include "UIDimensions.h"
|
||||
#include "UIDecorations.h"
|
||||
|
||||
namespace CreateWindow {
|
||||
namespace Window {
|
||||
// Window creation
|
||||
struct UICreateWindowPacket {
|
||||
uint16_t x0;
|
||||
uint16_t y0;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
UIDimensions dims;
|
||||
UIDecorations decor;
|
||||
char title[32]; // Note: we optimize this type of data transfer if necessary
|
||||
// we are sending 32 - len(title) extra bytes everytime
|
||||
|
||||
UICreateWindowPacket();
|
||||
};
|
||||
|
||||
void printUIWindowPacket(UICreateWindowPacket *win);
|
||||
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen);
|
||||
};
|
||||
|
||||
namespace DestroyWindow {
|
||||
// Window destruction
|
||||
struct UIDestroyWindowPacket {
|
||||
int16_t WinID;
|
||||
};
|
||||
@@ -28,4 +30,15 @@ namespace DestroyWindow {
|
||||
int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen);
|
||||
};
|
||||
|
||||
namespace Screen {
|
||||
struct UICreateScreenPacket{
|
||||
uint16_t x0;
|
||||
uint16_t y0;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
char title[32]; // Note: we optimize this type of data transfer if necessary
|
||||
// we are sending 32 - len(title) extra bytes everytime
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user