Added the create window command
This commit is contained in:
@@ -10,7 +10,7 @@ char* CommandToStr(Command id) {
|
|||||||
return (char*)"CmdCreateWindow";
|
return (char*)"CmdCreateWindow";
|
||||||
case CmdDestroyWindow:
|
case CmdDestroyWindow:
|
||||||
return (char*)"CmdDestroyWindow";
|
return (char*)"CmdDestroyWindow";
|
||||||
|
default:
|
||||||
|
return (char*)"CmdUnknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char*)"CmdInvalid";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
#include "data.h"
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
uint8_t packetBuffer[sizeof(DataPacket)] = {0};
|
|
||||||
int bufferIndex = 0;
|
|
||||||
bool isReceiving = false;
|
|
||||||
|
|
||||||
void SendDataRequest() {
|
|
||||||
DataReq req = {5};
|
|
||||||
Serial.write((uint8_t *)&req, sizeof(req));
|
|
||||||
Serial.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
int RecvDataPacket(DataPacket *p) {
|
|
||||||
while (Serial.available() > 0) {
|
|
||||||
uint8_t byte = Serial.read();
|
|
||||||
|
|
||||||
if (!isReceiving) {
|
|
||||||
if (byte == 0x02) {
|
|
||||||
isReceiving = true;
|
|
||||||
bufferIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
packetBuffer[bufferIndex++] = byte;
|
|
||||||
|
|
||||||
if (bufferIndex >= sizeof(DataPacket)) {
|
|
||||||
Serial.flush();
|
|
||||||
bufferIndex = 0;
|
|
||||||
isReceiving = false;
|
|
||||||
|
|
||||||
memcpy(p, packetBuffer, sizeof(DataPacket));
|
|
||||||
|
|
||||||
if (p->EndMarker != 0x03) {
|
|
||||||
// Serial2.println(F("\r////////////// DATA IS MALFORMED
|
|
||||||
// //////////////"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
// for(int k = 0; k < sizeof(DataPacket); k++) {
|
|
||||||
// if (k % 8 == 0) {
|
|
||||||
// Serial2.printf("\r\n");
|
|
||||||
// }
|
|
||||||
// Serial2.printf(" 0x%02x", packetBuffer[k]);
|
|
||||||
// }
|
|
||||||
// Serial2.printf("\r\n");
|
|
||||||
|
|
||||||
// Serial2.printf("%d / %d [%2d] || %d / %d [%2d]\n\n\r",
|
|
||||||
// ESP.getFreeHeap(),
|
|
||||||
// ESP.getHeapSize(),
|
|
||||||
// (int)(((float)(ESP.getHeapSize() - ESP.getFreeHeap()) /
|
|
||||||
// ESP.getHeapSize()) *
|
|
||||||
// 100),
|
|
||||||
// ESP.getFreePsram(), ESP.getPsramSize(),
|
|
||||||
// (int)(((float)(ESP.getPsramSize() - ESP.getFreePsram())
|
|
||||||
// /
|
|
||||||
// ESP.getPsramSize()) *
|
|
||||||
// 100));
|
|
||||||
|
|
||||||
// debugDataPacket(&packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebugDataPacket(DataPacket *p) {
|
|
||||||
Serial2.printf("\rSize: %zu\n", sizeof(struct DataPacket));
|
|
||||||
Serial2.printf("\rStartMarker: 0x%02x\n", p->StartMarker);
|
|
||||||
Serial2.printf("\rSpeed: %s\n", p->speed);
|
|
||||||
Serial2.printf("\rGear: %s\n", p->gear);
|
|
||||||
Serial2.printf("\rRPM: %s\n", p->rpm);
|
|
||||||
Serial2.printf("\rLapNumber: %s\n", p->LapNumber);
|
|
||||||
Serial2.printf("\rcurrLapTime: %s\n", p->currLapTime);
|
|
||||||
Serial2.printf("\rlastLapTime: %s\n", p->lastLapTime);
|
|
||||||
Serial2.printf("\rfuelEst: %s\n", p->FuelEst);
|
|
||||||
Serial2.printf("\rStandings:\n");
|
|
||||||
for (int k = 0; k < 5; k++) {
|
|
||||||
Serial2.printf("\r Lap: %s\n", p->standings[k].Lap);
|
|
||||||
Serial2.printf("\r DriverName: %s\n", p->standings[k].DriverName);
|
|
||||||
Serial2.printf("\r TimeBehind: %s\n", p->standings[k].TimeBehindString);
|
|
||||||
}
|
|
||||||
Serial2.printf("\rEndMarker: 0x%02x\n\n", p->EndMarker);
|
|
||||||
}
|
|
||||||
-59
@@ -1,59 +0,0 @@
|
|||||||
#ifndef __DASH_DISPLAY_DATA
|
|
||||||
#define __DASH_DISPLAY_DATA
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
struct DataReq {
|
|
||||||
uint8_t type;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Car data
|
|
||||||
const int speedLen = 5;
|
|
||||||
const int gearLen = 3;
|
|
||||||
const int rpmLen = 6;
|
|
||||||
const int brakeBiasLen = 6;
|
|
||||||
|
|
||||||
// Lap data
|
|
||||||
const int lapNumberLen = 5;
|
|
||||||
const int DeltaToBestLapLen = 6;
|
|
||||||
const int bestLapTimeLen = 10;
|
|
||||||
const int currLapTimeLen = 10;
|
|
||||||
const int lastLapTimeLen = 10;
|
|
||||||
|
|
||||||
// Fuel data
|
|
||||||
const int FuelTankLen = 15;
|
|
||||||
const int FuelEstLen = 15;
|
|
||||||
|
|
||||||
const int LapStringLen = 4;
|
|
||||||
const int DriverNameLen = 24;
|
|
||||||
const int TimeBehindStringLen = 8;
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
struct StandingLine {
|
|
||||||
char Lap[LapStringLen];
|
|
||||||
char DriverName[DriverNameLen];
|
|
||||||
char TimeBehindString[TimeBehindStringLen];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DataPacket {
|
|
||||||
uint8_t StartMarker;
|
|
||||||
char speed[speedLen];
|
|
||||||
char gear[gearLen];
|
|
||||||
char rpm[rpmLen];
|
|
||||||
char brakeBias[brakeBiasLen];
|
|
||||||
char LapNumber[lapNumberLen];
|
|
||||||
char DeltaToBestLap[DeltaToBestLapLen];
|
|
||||||
char bestLapTime[bestLapTimeLen];
|
|
||||||
char currLapTime[currLapTimeLen];
|
|
||||||
char lastLapTime[lastLapTimeLen];
|
|
||||||
char FuelEst[FuelEstLen];
|
|
||||||
StandingLine standings[5];
|
|
||||||
uint8_t EndMarker;
|
|
||||||
};
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
void DebugDataPacket(DataPacket *p);
|
|
||||||
int RecvDataPacket(DataPacket *p);
|
|
||||||
void SendDataRequest();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+38
-5
@@ -156,21 +156,28 @@ uint64_t lastDataRead = 0;
|
|||||||
|
|
||||||
bool gotAck = false;
|
bool gotAck = false;
|
||||||
|
|
||||||
struct UIWindowPacket {
|
struct UICreateWindowPacket {
|
||||||
uint8_t StartMarker;
|
|
||||||
uint16_t x0;
|
uint16_t x0;
|
||||||
uint16_t y0;
|
uint16_t y0;
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
uint16_t height;
|
uint16_t height;
|
||||||
uint8_t EndMarker;
|
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;
|
uint64_t lastSent = 0;
|
||||||
void loop(void) {
|
void loop(void) {
|
||||||
uint64_t cur = millis();
|
uint64_t cur = millis();
|
||||||
|
|
||||||
// with this new way of reading data, we are just gonna read a payload
|
|
||||||
// and get a command
|
|
||||||
Command cmd = CmdUnknown;
|
Command cmd = CmdUnknown;
|
||||||
uint8_t payload[256] = {0};
|
uint8_t payload[256] = {0};
|
||||||
|
|
||||||
@@ -193,6 +200,32 @@ void loop(void) {
|
|||||||
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
|
initIdentificationPacket(&papers, ESLABS_DEVICE_NAME, ESLABS_DEVICE_ID);
|
||||||
WalkieTalkie::SendData(&papers);
|
WalkieTalkie::SendData(&papers);
|
||||||
break;
|
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) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LOG_WARN(F("Command: `%s` has not been implemented yet."), CommandToStr(cmd));
|
LOG_WARN(F("Command: `%s` has not been implemented yet."), CommandToStr(cmd));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user