Fixed teh window create method

This commit is contained in:
2025-12-31 16:42:28 +00:00
parent 7a4d543561
commit e6f05a18dd
5 changed files with 131 additions and 94 deletions
+8 -39
View File
@@ -19,10 +19,10 @@ to have more ways to run analytics
#include "logger.h"
#include "values.h"
#include "windowPool.h"
#include "methods/methods.h"
// #include "UIDrawing.h"
#include "UIString.h"
// #include "UITable.h"
// #include "data.h"
#include "displaySetup.h"
#include "esp32-hal-psram.h"
// #include "ui.h"
@@ -156,24 +156,6 @@ uint64_t lastDataRead = 0;
bool gotAck = false;
struct UICreateWindowPacket {
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
};
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(" Title : %s\n"), win->title);
}
uint64_t lastSent = 0;
void loop(void) {
uint64_t cur = millis();
@@ -201,29 +183,16 @@ void loop(void) {
WalkieTalkie::SendData(&papers);
break;
case CmdCreateWindow: {
// Here we parse the payload a a UIWindowPacket
UICreateWindowPacket win;
memcpy(&win, payload, sizeof(UICreateWindowPacket));
printUIWindowPacket(&win);
UIElement *mainWindow = mainScreen.mainWindowHandle;
int16_t childID = mainWindow->AddChild(STRING);
if (childID < 0) {
uint8_t newWindowID = CreateWindow::Create(payload, &mainScreen);
if (newWindowID < 0) {
LOG_WARN(F("Failed to add new window!\n"));
} else {
LOG_INFO(F("Successfully added a new window: %d\n"), childID);
UIElement *childComponent = mainWindow->GetChild(childID);
childComponent->SetTitle((char *)"%s [%2d]", (const char *)win.title, childID);
childComponent->SetUIDecorations(UIDecorations());
childComponent->SetUIDimensions(UIDimensions(20, 20, 300, 300));
childComponent->SetDisplay(mainScreen.display);
childComponent->drawBox();
break;
}
LOG_INFO(F("Successfully added a new window: %d\n"), newWindowID);
// Now we return the ID of this new window - esdi should expect it
break;
}
default:
+44
View File
@@ -0,0 +1,44 @@
#include "methods.h"
#include "Arduino.h"
#include "logger.h"
#include "UIComponent.h"
#include "UIScreen.h"
#include <string.h>
namespace CreateWindow {
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(" Title : %s\n"), win->title);
}
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) {
// Load the payload into a struct
CreateWindow::UICreateWindowPacket win;
memcpy(&win, payload, sizeof(CreateWindow::UICreateWindowPacket));
printUIWindowPacket(&win);
UIElement *mainWindow = mainScreen->mainWindowHandle;
int16_t childID = mainWindow->AddChild(STRING);
if (childID < 0) {
return -1;
}
UIElement *childComponent = mainWindow->GetChild(childID);
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->SetDisplay(mainScreen->display);
childComponent->drawBox();
return childID;
}
};
namespace DestroyWindow {
};
+25
View File
@@ -0,0 +1,25 @@
#ifndef __METHODS__
#define __METHODS__
#include <cstdint>
#include <stdint.h>
#include "UIScreen.h"
namespace CreateWindow {
struct UICreateWindowPacket {
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
};
void printUIWindowPacket(UICreateWindowPacket *win);
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen);
};
namespace DestroyWindow {
};
#endif
+26 -27
View File
@@ -1,27 +1,26 @@
#include "ui.h"
#include "HardwareSerial.h"
#include "data.h"
#include <cstdint>
DashUI::DashUI() {}
void DashUI::Update(DataPacket *p) {
this->barTacho->Update(p->rpm);
this->digiTacho->Update(p->rpm);
this->digiSpeedo->Update(p->speed);
this->digiGear->Update(p->gear);
this->lapDelta->Update(p->DeltaToBestLap);
this->bestLap->Update(p->bestLapTime);
this->curLap->Update(p->currLapTime);
this->lastLap->Update(p->lastLapTime);
this->fuelConsumption->Update(p->FuelEst);
this->brakeBias->Update(p->brakeBias);
for (int row = 0; row < ROWS; row++) {
this->relative->tableData[row * COLUMNS + 0]->Update(p->standings[row].Lap);
this->relative->tableData[row * COLUMNS + 1]->Update(
p->standings[row].DriverName);
this->relative->tableData[row * COLUMNS + 2]->Update(
p->standings[row].TimeBehindString);
}
}
// #include "ui.h"
// #include "HardwareSerial.h"
// #include <cstdint>
//
// DashUI::DashUI() {}
//
// void DashUI::Update(DataPacket *p) {
// this->barTacho->Update(p->rpm);
// this->digiTacho->Update(p->rpm);
// this->digiSpeedo->Update(p->speed);
// this->digiGear->Update(p->gear);
// this->lapDelta->Update(p->DeltaToBestLap);
// this->bestLap->Update(p->bestLapTime);
// this->curLap->Update(p->currLapTime);
// this->lastLap->Update(p->lastLapTime);
// this->fuelConsumption->Update(p->FuelEst);
// this->brakeBias->Update(p->brakeBias);
//
// for (int row = 0; row < ROWS; row++) {
// this->relative->tableData[row * COLUMNS + 0]->Update(p->standings[row].Lap);
// this->relative->tableData[row * COLUMNS + 1]->Update(
// p->standings[row].DriverName);
// this->relative->tableData[row * COLUMNS + 2]->Update(
// p->standings[row].TimeBehindString);
// }
// }
+28 -28
View File
@@ -1,28 +1,28 @@
#ifndef __DASH_DISPLAY_UI
#define __DASH_DISPLAY_UI
#include "Arduino_GFX.h"
#include "UIString.h"
#include "UITable.h"
#include "UIBar.h"
#include "data.h"
struct DashUI {
UIBar *barTacho;
UIString *digiTacho;
UIString *digiSpeedo;
UIString *digiGear;
UIString *lapDelta;
UIString *bestLap;
UIString *lastLap;
UIString *curLap;
UIString *fuelTank;
UIString *fuelConsumption;
UIString *brakeBias;
UITable *relative;
DashUI();
void Update(DataPacket *p);
};
#endif
// #ifndef __DASH_DISPLAY_UI
// #define __DASH_DISPLAY_UI
//
// #include "Arduino_GFX.h"
// #include "UIString.h"
// #include "UITable.h"
// #include "UIBar.h"
// #include "data.h"
//
// struct DashUI {
// UIBar *barTacho;
// UIString *digiTacho;
// UIString *digiSpeedo;
// UIString *digiGear;
// UIString *lapDelta;
// UIString *bestLap;
// UIString *lastLap;
// UIString *curLap;
// UIString *fuelTank;
// UIString *fuelConsumption;
// UIString *brakeBias;
// UITable *relative;
//
// DashUI();
// void Update(DataPacket *p);
// };
//
// #endif