Dynamic Tables
This commit is contained in:
@@ -7,11 +7,14 @@
|
|||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
|
||||||
UITable::UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor,
|
UITable::UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor,
|
||||||
char *title)
|
int nRows, int nCols, int *colWidths, char *title)
|
||||||
: UIElement(gfx, dims, decor, title) {
|
: UIElement(gfx, dims, decor, title) {
|
||||||
this->type = TABLE;
|
this->type = TABLE;
|
||||||
this->tableData = new UIString*[ROWS * COLUMNS];
|
this->nRows = nRows;
|
||||||
|
this->nColumns = nCols;
|
||||||
|
this->tableData = new UIString *[this->nRows * this->nColumns];
|
||||||
|
this->colWidths = colWidths;
|
||||||
|
|
||||||
// Default decoration for every cell
|
// Default decoration for every cell
|
||||||
this->decor->textSize = 2;
|
this->decor->textSize = 2;
|
||||||
|
|
||||||
@@ -27,11 +30,16 @@ UITable::UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor,
|
|||||||
int cellH = CHR_HEIGHT(this->decor->textSize) + CELL_MARGIN;
|
int cellH = CHR_HEIGHT(this->decor->textSize) + CELL_MARGIN;
|
||||||
|
|
||||||
// Initialize the table dimensions
|
// Initialize the table dimensions
|
||||||
|
//// Calculate the height
|
||||||
this->dims.height = ROWS * cellH + this->getTitleAreaHeight() +
|
this->dims.height = ROWS * cellH + this->getTitleAreaHeight() +
|
||||||
DEFAULT_MARGIN + DEFAULT_BORDER_THICKNESS;
|
DEFAULT_MARGIN + DEFAULT_BORDER_THICKNESS;
|
||||||
this->dims.width =
|
|
||||||
(DEFAULT_BORDER_THICKNESS + DEFAULT_MARGIN) * 2 +
|
//// Calculate the width
|
||||||
(CHR_WIDTH(this->decor->textSize) + CELL_MARGIN) * (3 + 18 + 12);
|
for (int c = 0; c < this->nColumns; c++) {
|
||||||
|
this->dims.width +=
|
||||||
|
(CHR_WIDTH(this->decor->textSize) + CELL_MARGIN) * this->colWidths[c];
|
||||||
|
}
|
||||||
|
this->dims.width += (DEFAULT_BORDER_THICKNESS + DEFAULT_MARGIN) * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t UITable::getContentAreaHeight() {
|
uint16_t UITable::getContentAreaHeight() {
|
||||||
@@ -39,16 +47,11 @@ uint16_t UITable::getContentAreaHeight() {
|
|||||||
this->getTitleAreaHeight();
|
this->getTitleAreaHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Very shitty hardcoded function to get this going, only works for th
|
/*
|
||||||
* relative
|
* This was hardcoded for the relative and had a warning for that but
|
||||||
* POS NAME DELTA
|
* I recon its dynamic enough for now
|
||||||
* 3 | 24 | 5
|
|
||||||
*/
|
*/
|
||||||
void UITable::setup() {
|
void UITable::setup() {
|
||||||
// Define the cell dimensions
|
|
||||||
int tableCellW[] = {3 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN),
|
|
||||||
18 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN),
|
|
||||||
12 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN)};
|
|
||||||
int cellH = CHR_HEIGHT(this->decor->textSize) + CELL_MARGIN;
|
int cellH = CHR_HEIGHT(this->decor->textSize) + CELL_MARGIN;
|
||||||
|
|
||||||
// Initialize the cells
|
// Initialize the cells
|
||||||
@@ -61,11 +64,13 @@ void UITable::setup() {
|
|||||||
this->tableData[r * COLUMNS + c]->dims.x = xOffset + CELL_MARGIN;
|
this->tableData[r * COLUMNS + c]->dims.x = xOffset + CELL_MARGIN;
|
||||||
this->tableData[r * COLUMNS + c]->dims.y = (cellH * r) + yOffset;
|
this->tableData[r * COLUMNS + c]->dims.y = (cellH * r) + yOffset;
|
||||||
this->tableData[r * COLUMNS + c]->dims.height = cellH;
|
this->tableData[r * COLUMNS + c]->dims.height = cellH;
|
||||||
this->tableData[r * COLUMNS + c]->dims.width = tableCellW[c];
|
this->tableData[r * COLUMNS + c]->dims.width =
|
||||||
|
this->colWidths[c] * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN);
|
||||||
memset(this->tableData[r * COLUMNS + c]->value, 0,
|
memset(this->tableData[r * COLUMNS + c]->value, 0,
|
||||||
this->tableData[r * COLUMNS + c]->bufferSize);
|
this->tableData[r * COLUMNS + c]->bufferSize);
|
||||||
|
|
||||||
xOffset += tableCellW[c];
|
xOffset +=
|
||||||
|
this->colWidths[c] * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
this->tableData[r * COLUMNS + c]->drawBox();
|
this->tableData[r * COLUMNS + c]->drawBox();
|
||||||
|
|||||||
@@ -13,11 +13,13 @@
|
|||||||
*/
|
*/
|
||||||
struct UITable : UIElement {
|
struct UITable : UIElement {
|
||||||
// will hold rows * columns UIStrings to fill the table
|
// will hold rows * columns UIStrings to fill the table
|
||||||
int rows = ROWS;
|
int nRows = 0;
|
||||||
int columns = COLUMNS;
|
int nColumns = 0;
|
||||||
|
int *colWidths;
|
||||||
UIString **tableData;
|
UIString **tableData;
|
||||||
|
|
||||||
UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor, char *t);
|
UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor, int nR,
|
||||||
|
int nC, int *cWidth, char *t);
|
||||||
|
|
||||||
// void Update(StandingLine standings[5]);
|
// void Update(StandingLine standings[5]);
|
||||||
void setup();
|
void setup();
|
||||||
|
|||||||
+8
-3
@@ -11,14 +11,17 @@ const int speedLen = 5;
|
|||||||
const int gearLen = 3;
|
const int gearLen = 3;
|
||||||
const int rpmLen = 6;
|
const int rpmLen = 6;
|
||||||
const int lapNumberLen = 5;
|
const int lapNumberLen = 5;
|
||||||
|
const int DeltaToBestLapLen = 6;
|
||||||
|
const int bestLapTimeLen = 10;
|
||||||
const int currLapTimeLen = 10;
|
const int currLapTimeLen = 10;
|
||||||
const int lastLapTimeLen = 10;
|
const int lastLapTimeLen = 10;
|
||||||
const int DriverNameLen = 24;
|
|
||||||
const int TimeBehindStringLen = 16;
|
|
||||||
const int LapStringLen = 4;
|
|
||||||
const int FuelTankLen = 15;
|
const int FuelTankLen = 15;
|
||||||
const int FuelEstLen = 15;
|
const int FuelEstLen = 15;
|
||||||
|
|
||||||
|
const int LapStringLen = 4;
|
||||||
|
const int DriverNameLen = 24;
|
||||||
|
const int TimeBehindStringLen = 8;
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct StandingLine {
|
struct StandingLine {
|
||||||
char Lap[LapStringLen];
|
char Lap[LapStringLen];
|
||||||
@@ -32,6 +35,8 @@ struct DataPacket {
|
|||||||
char gear[gearLen];
|
char gear[gearLen];
|
||||||
char rpm[rpmLen];
|
char rpm[rpmLen];
|
||||||
char LapNumber[lapNumberLen];
|
char LapNumber[lapNumberLen];
|
||||||
|
char DeltaToBestLap[DeltaToBestLapLen];
|
||||||
|
char bestLapTime[bestLapTimeLen];
|
||||||
char currLapTime[currLapTimeLen];
|
char currLapTime[currLapTimeLen];
|
||||||
char lastLapTime[lastLapTimeLen];
|
char lastLapTime[lastLapTimeLen];
|
||||||
char FuelEst[FuelEstLen];
|
char FuelEst[FuelEstLen];
|
||||||
|
|||||||
+34
-17
@@ -48,6 +48,7 @@ DashUI *ui = new DashUI();
|
|||||||
UIDecorations *rpmTextDecor = new UIDecorations();
|
UIDecorations *rpmTextDecor = new UIDecorations();
|
||||||
UIDecorations *speedTextDecor = new UIDecorations();
|
UIDecorations *speedTextDecor = new UIDecorations();
|
||||||
UIDecorations *gearTextDecor = new UIDecorations();
|
UIDecorations *gearTextDecor = new UIDecorations();
|
||||||
|
UIDecorations *lapDeltaDecor = new UIDecorations();
|
||||||
UIDecorations *bestLapDecor = new UIDecorations();
|
UIDecorations *bestLapDecor = new UIDecorations();
|
||||||
UIDecorations *lastLapDecor = new UIDecorations();
|
UIDecorations *lastLapDecor = new UIDecorations();
|
||||||
UIDecorations *curLapDecor = new UIDecorations();
|
UIDecorations *curLapDecor = new UIDecorations();
|
||||||
@@ -60,6 +61,8 @@ UIString speedText(gfx, UIDimensions(0, 0, 0, 0), speedTextDecor,
|
|||||||
(char *)"Speed");
|
(char *)"Speed");
|
||||||
UIString gearText(gfx, UIDimensions(0, 0, 0, 0), rpmTextDecor, (char *)"Gear");
|
UIString gearText(gfx, UIDimensions(0, 0, 0, 0), rpmTextDecor, (char *)"Gear");
|
||||||
|
|
||||||
|
UIString lapDelta(gfx, UIDimensions(0, 0, 0, 0), lapDeltaDecor,
|
||||||
|
(char *)"Delta");
|
||||||
UIString bestLap(gfx, UIDimensions(0, 0, 0, 0), bestLapDecor,
|
UIString bestLap(gfx, UIDimensions(0, 0, 0, 0), bestLapDecor,
|
||||||
(char *)"Best Lap");
|
(char *)"Best Lap");
|
||||||
UIString lastLap(gfx, UIDimensions(0, 0, 0, 0), lastLapDecor,
|
UIString lastLap(gfx, UIDimensions(0, 0, 0, 0), lastLapDecor,
|
||||||
@@ -69,8 +72,6 @@ UIString fuelTank(gfx, UIDimensions(0, 0, 0, 0), fuelTankDecor,
|
|||||||
(char *)"Fuel Tank");
|
(char *)"Fuel Tank");
|
||||||
UIString fuelConsumption(gfx, UIDimensions(0, 0, 0, 0), fuelConsumptionDecor,
|
UIString fuelConsumption(gfx, UIDimensions(0, 0, 0, 0), fuelConsumptionDecor,
|
||||||
(char *)"Fuel Consumption");
|
(char *)"Fuel Consumption");
|
||||||
UITable relative(gfx, UIDimensions(250, 250, 0, 0), relativeDecor,
|
|
||||||
(char *)"Relative");
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
psramInit();
|
psramInit();
|
||||||
@@ -86,14 +87,20 @@ void setup() {
|
|||||||
initialDisplaySetup(gfx);
|
initialDisplaySetup(gfx);
|
||||||
|
|
||||||
// Setup the relative
|
// Setup the relative
|
||||||
|
// Define the width of the columns in number of chars
|
||||||
|
int *colW = (int *)malloc(sizeof(int) * 3);
|
||||||
|
colW[0] = 3;
|
||||||
|
colW[1] = 18;
|
||||||
|
colW[2] = 9;
|
||||||
|
UITable *relative =
|
||||||
|
new UITable(gfx, UIDimensions(250, 250, 0, 0), relativeDecor, 5, 3, colW,
|
||||||
|
(char *)"Relative");
|
||||||
relativeDecor->textSize = 2;
|
relativeDecor->textSize = 2;
|
||||||
relative.dims.x = gfx->width() - relative.dims.width;
|
relative->dims.x = gfx->width() - relative->dims.width;
|
||||||
relative.dims.y = gfx->height() - relative.dims.height;
|
relative->dims.y = gfx->height() - relative->dims.height;
|
||||||
// relative.dims.x = 250;
|
relative->setup();
|
||||||
// relative.dims.y = 250;
|
relative->drawBox();
|
||||||
relative.setup();
|
ui->relative = relative;
|
||||||
relative.drawBox();
|
|
||||||
ui->relative = &relative;
|
|
||||||
|
|
||||||
// Setup the rpmText box
|
// Setup the rpmText box
|
||||||
rpmTextDecor->textSize = 7;
|
rpmTextDecor->textSize = 7;
|
||||||
@@ -103,7 +110,7 @@ void setup() {
|
|||||||
rpmText.horizontalCenter();
|
rpmText.horizontalCenter();
|
||||||
ui->digiTacho = &rpmText;
|
ui->digiTacho = &rpmText;
|
||||||
ui->digiTacho->drawBox();
|
ui->digiTacho->drawBox();
|
||||||
ui->digiTacho->Update("12345");
|
ui->digiTacho->Update("-----");
|
||||||
|
|
||||||
// Setup the speedText box
|
// Setup the speedText box
|
||||||
speedTextDecor->textSize = 4;
|
speedTextDecor->textSize = 4;
|
||||||
@@ -113,7 +120,7 @@ void setup() {
|
|||||||
speedText.placeRight(&rpmText);
|
speedText.placeRight(&rpmText);
|
||||||
ui->digiSpeedo = &speedText;
|
ui->digiSpeedo = &speedText;
|
||||||
ui->digiSpeedo->drawBox();
|
ui->digiSpeedo->drawBox();
|
||||||
ui->digiSpeedo->Update("253");
|
ui->digiSpeedo->Update("---");
|
||||||
|
|
||||||
// Setup the gear text box
|
// Setup the gear text box
|
||||||
gearTextDecor->textSize = 7;
|
gearTextDecor->textSize = 7;
|
||||||
@@ -124,7 +131,17 @@ void setup() {
|
|||||||
gearText.dims.y = rpmText.dims.height + 5;
|
gearText.dims.y = rpmText.dims.height + 5;
|
||||||
ui->digiGear = &gearText;
|
ui->digiGear = &gearText;
|
||||||
ui->digiGear->drawBox();
|
ui->digiGear->drawBox();
|
||||||
ui->digiGear->Update("3");
|
ui->digiGear->Update("-");
|
||||||
|
|
||||||
|
// Setup the lap delta box
|
||||||
|
lapDeltaDecor->textSize = 3;
|
||||||
|
lapDelta.dims.height =
|
||||||
|
calculateHeight(lapDeltaDecor->titleSize, lapDeltaDecor->textSize, 1);
|
||||||
|
lapDelta.dims.width = calculateWidth(lapDeltaDecor->textSize, 6);
|
||||||
|
lapDelta.placeBelow(&gearText);
|
||||||
|
ui->lapDelta = &lapDelta;
|
||||||
|
ui->lapDelta->drawBox();
|
||||||
|
ui->lapDelta->Update("--.-");
|
||||||
|
|
||||||
// Setup the best lap box
|
// Setup the best lap box
|
||||||
bestLapDecor->textSize = 3;
|
bestLapDecor->textSize = 3;
|
||||||
@@ -133,7 +150,7 @@ void setup() {
|
|||||||
bestLap.dims.width = calculateWidth(bestLapDecor->textSize, 8);
|
bestLap.dims.width = calculateWidth(bestLapDecor->textSize, 8);
|
||||||
ui->bestLap = &bestLap;
|
ui->bestLap = &bestLap;
|
||||||
ui->bestLap->drawBox();
|
ui->bestLap->drawBox();
|
||||||
ui->bestLap->Update("01:24.39");
|
ui->bestLap->Update("--:--.--");
|
||||||
|
|
||||||
// Setup the last lap box
|
// Setup the last lap box
|
||||||
lastLapDecor->textSize = 3;
|
lastLapDecor->textSize = 3;
|
||||||
@@ -143,7 +160,7 @@ void setup() {
|
|||||||
lastLap.placeBelow(&bestLap);
|
lastLap.placeBelow(&bestLap);
|
||||||
ui->lastLap = &lastLap;
|
ui->lastLap = &lastLap;
|
||||||
ui->lastLap->drawBox();
|
ui->lastLap->drawBox();
|
||||||
ui->lastLap->Update("01:24.87");
|
ui->lastLap->Update("--:--.--");
|
||||||
|
|
||||||
// Setup the cur lap box
|
// Setup the cur lap box
|
||||||
curLapDecor->textSize = 3;
|
curLapDecor->textSize = 3;
|
||||||
@@ -153,7 +170,7 @@ void setup() {
|
|||||||
curLap.placeBelow(&lastLap);
|
curLap.placeBelow(&lastLap);
|
||||||
ui->curLap = &curLap;
|
ui->curLap = &curLap;
|
||||||
ui->curLap->drawBox();
|
ui->curLap->drawBox();
|
||||||
ui->curLap->Update("00:54.21");
|
ui->curLap->Update("--:--.--");
|
||||||
|
|
||||||
// Fuel tank
|
// Fuel tank
|
||||||
fuelTankDecor->textSize = 3;
|
fuelTankDecor->textSize = 3;
|
||||||
@@ -163,7 +180,7 @@ void setup() {
|
|||||||
fuelTank.placeBelow(&curLap);
|
fuelTank.placeBelow(&curLap);
|
||||||
ui->fuelTank = &fuelTank;
|
ui->fuelTank = &fuelTank;
|
||||||
ui->fuelTank->drawBox();
|
ui->fuelTank->drawBox();
|
||||||
ui->fuelTank->Update("123 / 320");
|
ui->fuelTank->Update("--- / ---");
|
||||||
|
|
||||||
// Fuel consumption
|
// Fuel consumption
|
||||||
fuelConsumptionDecor->textSize = 3;
|
fuelConsumptionDecor->textSize = 3;
|
||||||
@@ -174,7 +191,7 @@ void setup() {
|
|||||||
fuelConsumption.placeBelow(&fuelTank);
|
fuelConsumption.placeBelow(&fuelTank);
|
||||||
ui->fuelConsumption = &fuelConsumption;
|
ui->fuelConsumption = &fuelConsumption;
|
||||||
ui->fuelConsumption->drawBox();
|
ui->fuelConsumption->drawBox();
|
||||||
ui->fuelConsumption->Update("10.4 | 11.2");
|
ui->fuelConsumption->Update("--.- | --.-");
|
||||||
|
|
||||||
// const char *words[] = {"hel", "wor", "why", "is", "thi", "hap", "to",
|
// const char *words[] = {"hel", "wor", "why", "is", "thi", "hap", "to",
|
||||||
// "me"};
|
// "me"};
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,4 @@
|
|||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
#include "UIDecorations.h"
|
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
DashUI::DashUI() {}
|
DashUI::DashUI() {}
|
||||||
@@ -9,6 +7,8 @@ void DashUI::Update(DataPacket *p) {
|
|||||||
this->digiSpeedo->Update(p->speed);
|
this->digiSpeedo->Update(p->speed);
|
||||||
this->digiTacho->Update(p->rpm);
|
this->digiTacho->Update(p->rpm);
|
||||||
this->digiGear->Update(p->gear);
|
this->digiGear->Update(p->gear);
|
||||||
|
this->lapDelta->Update(p->DeltaToBestLap);
|
||||||
|
this->bestLap->Update(p->bestLapTime);
|
||||||
this->curLap->Update(p->currLapTime);
|
this->curLap->Update(p->currLapTime);
|
||||||
this->lastLap->Update(p->lastLapTime);
|
this->lastLap->Update(p->lastLapTime);
|
||||||
this->fuelConsumption->Update(p->FuelEst);
|
this->fuelConsumption->Update(p->FuelEst);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ struct DashUI {
|
|||||||
UIString *digiTacho;
|
UIString *digiTacho;
|
||||||
UIString *digiSpeedo;
|
UIString *digiSpeedo;
|
||||||
UIString *digiGear;
|
UIString *digiGear;
|
||||||
|
UIString *lapDelta;
|
||||||
UIString *bestLap;
|
UIString *bestLap;
|
||||||
UIString *lastLap;
|
UIString *lastLap;
|
||||||
UIString *curLap;
|
UIString *curLap;
|
||||||
|
|||||||
Reference in New Issue
Block a user