diff --git a/src/main.cpp b/src/main.cpp index ce1606b..6b76f37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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: diff --git a/src/methods/methods.cpp b/src/methods/methods.cpp new file mode 100644 index 0000000..7958208 --- /dev/null +++ b/src/methods/methods.cpp @@ -0,0 +1,44 @@ +#include "methods.h" +#include "Arduino.h" +#include "logger.h" +#include "UIComponent.h" +#include "UIScreen.h" +#include + +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 { +}; diff --git a/src/methods/methods.h b/src/methods/methods.h new file mode 100644 index 0000000..7644773 --- /dev/null +++ b/src/methods/methods.h @@ -0,0 +1,25 @@ +#ifndef __METHODS__ +#define __METHODS__ + +#include +#include +#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 diff --git a/src/ui.cpp b/src/ui.cpp index 6ab3abf..5ee08af 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1,27 +1,26 @@ -#include "ui.h" -#include "HardwareSerial.h" -#include "data.h" -#include - -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 +// +// 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); +// } +// } diff --git a/src/ui.h b/src/ui.h index ba984e8..6ef547a 100644 --- a/src/ui.h +++ b/src/ui.h @@ -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