diff --git a/platformio.ini b/platformio.ini index 5d39e49..cb79964 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,6 +17,8 @@ build_flags = -Iinclude/ -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -std=gnu++17 + +build_unflags = -std=gnu++11 # -Ilib/u8g2/csrc # -Ilib/u8g2/cppsrc board_build.arduino.memory_type = qio_opi diff --git a/src/communication/communication.cpp b/src/communication/communication.cpp new file mode 100644 index 0000000..f8f6332 --- /dev/null +++ b/src/communication/communication.cpp @@ -0,0 +1 @@ +#include "communication.h" diff --git a/src/communication/communication.h b/src/communication/communication.h new file mode 100644 index 0000000..3478033 --- /dev/null +++ b/src/communication/communication.h @@ -0,0 +1,6 @@ +#ifndef __COMMUNICATION__ +#define __COMMUNICATION__ + +int router(); + +#endif diff --git a/src/communication/identificationPacket.h b/src/communication/identificationPacket.h index 21d1ae3..6c59143 100644 --- a/src/communication/identificationPacket.h +++ b/src/communication/identificationPacket.h @@ -15,7 +15,7 @@ struct __attribute__((packed)) IdentificationPacket { }; void initIdentificationPacket(IdentificationPacket* packet, const char* name, - uint8_t id); + uint8_t id); void sendIdentificationPacket(IdentificationPacket* packet); #endif diff --git a/src/main.cpp b/src/main.cpp index 89b528b..e0ed5d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,8 @@ to have more ways to run analytics */ #include "UIComponent.h" +#include "values.h" +#include "windowPool.h" #include "UIScreen.h" #include "UIDecorations.h" #include "UIDimensions.h" @@ -54,22 +56,22 @@ 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 mainSreen( +Curses::Screen mainScreen( gfx, UIDimensions(0, 0, TFT_HOR_RES, TFT_VER_RES), UIDecorations() ); // UIelements -UIDecorations *gearTextDecor = new UIDecorations(); -UIString gearText(gfx, UIDimensions(0, 0, 0, 0), gearTextDecor, (char *)"Gear"); - -UIElement mainWindow( - gfx, - UIDimensions(0, 0, TFT_HOR_RES, TFT_VER_RES), - gearTextDecor, - (char*)"MAIN WINDOW" -); +// UIDecorations *gearTextDecor = new UIDecorations(); +// UIString gearText(gfx, UIDimensions(0, 0, 0, 0), gearTextDecor, (char *)"Gear"); +// +// UIElement mainWindow( +// gfx, +// UIDimensions(0, 0, TFT_HOR_RES, TFT_VER_RES), +// gearTextDecor, +// (char*)"MAIN WINDOW" +// ); void setup() { psramInit(); @@ -84,35 +86,68 @@ void setup() { Serial2.print(F("* Initiating display\r\n")); initialDisplaySetup(gfx); - // Setup the gear text box - // gearTextDecor->textSize = 7; - // gearText.dims.height = - // calculateHeight(gearTextDecor->titleSize, gearTextDecor->textSize, 1); - // gearText.dims.width = calculateWidth(gearTextDecor->textSize, 2); - // gearText.drawBox(); - // gearText.Update("Disconnected"); - mainWindow.drawBox(); + // Only setup the main screen after initializing the Serial2 + mainScreen.Setup("Main Window"); - int16_t childID = mainWindow.AddChild(); - if (!childID) { + // 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); + UIElement* childComponent = mainWindow->GetChild(childID); childComponent->SetTitle((char*)"%s [%2d]", (const char*)"Child Window", childID); - childComponent->decor = gearTextDecor; - childComponent->display = mainSreen.display; - childComponent->dims.x = 30; - childComponent->dims.y = 30; - childComponent->dims.width = 300; - childComponent->dims.height = 300; + 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); Serial2.println("* Ready for loop"); } @@ -132,17 +167,26 @@ void loop(void) { if (Serial.available() >= 1) { uint8_t cmd = Serial.read(); - if (cmd == CmdRequestID) { - Serial2.println("Got identification request!"); - // gearText.Update("Connecting"); + switch (cmd) { + case CmdRequestID: + Serial2.println("Got identification request!"); + // gearText.Update("Connecting"); - IdentificationPacket papers; - initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID); - sendIdentificationPacket(&papers); - } else if (cmd == CmdAckID) { - Serial2.println("Got ack!"); - // gearText.Update("Connected"); - gotAck = true;; + IdentificationPacket papers; + initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID); + sendIdentificationPacket(&papers); + break; + case CmdAckID: + Serial2.println("Got ack!"); + // gearText.Update("Connected"); + gotAck = true;; + break; + case NewWindow: + Serial2.println("Received request to create window"); + break; + case DestroyWindow: + Serial2.println("Received request to destroy window"); + break; } }