First commit

I shall move all this to another branch -> master_vendored or something
This commit is contained in:
2025-03-12 21:42:39 +00:00
commit f9d0bfa4d9
226 changed files with 240315 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
#include "backlightControl.h"
#include "esp32-hal-ledc.h"
#include <Arduino.h>
void setBrightness(uint32_t value, uint32_t valueMax) {
uint32_t duty = (4095 / valueMax) * min(value, valueMax);
ledcWrite(BRIGHTNESS_CHANNEL, duty);
}
void backlightSetup() {
ledcSetup(BRIGHTNESS_CHANNEL, PWM_FREQUENCY, PWM_RESOLUTION);
ledcAttachPin(TFT_BL, BRIGHTNESS_CHANNEL);
setBrightness(DEFAULT_BRIGHTNESS);
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef __BLCTL
#define __BLCTL
#include <stdint.h>
#define TFT_BL 2
#define DEFAULT_BRIGHTNESS 255
#define BRIGHTNESS_CHANNEL 0
#define PWM_FREQUENCY 5000
#define PWM_RESOLUTION 12
void backlightSetup();
void setBrightness(uint32_t value, uint32_t valueMax = 255);
#endif
+33
View File
@@ -0,0 +1,33 @@
#ifndef __DASH_DISPLAY_DATA
#define __DASH_DISPLAY_DATA
#include <stdint.h>
const int DriverNameLen = 24;
const int TimeBehindStringLen = 16;
const int LapStringLen = 4;
const int FuelTankLen = 15;
const int FuelEstLen = 15;
struct StandingLine {
char Lap[LapStringLen];
char DriverName[DriverNameLen];
char TimeBehindString[TimeBehindStringLen];
};
struct DataPacket {
int32_t speed;
int32_t gear;
int32_t rpm;
char LapNumber[5];
// char lapDelta[10];
char currLapTime[10];
// char bestLapTime[10];
char lastLapTime[10];
// char FuelTank[FuelTankLen];
char FuelEst[FuelEstLen];
// int32_t position;
StandingLine standings[5];
};
#endif
+153
View File
@@ -0,0 +1,153 @@
#include "Arduino_GFX.h"
#include "HardwareSerial.h"
#include "UIDecorations.h"
#include "UIDrawing.h"
#include "UIString.h"
#include "backlightControl.h"
#include "data.h"
#include "esp32-hal-psram.h"
#include "ui.h"
#include <Arduino.h>
#include <Arduino_GFX_Library.h>
#include <cstdint>
#include <cstring>
// #include <U8g2lib.h>
#define UART1_TX 19
#define UART1_RX 18
#define SCREEN_ORIENTATION 2
#define SCREEN_LANDSCAPE // comment out for portrait
Arduino_ESP32RGBPanel *panel = new Arduino_ESP32RGBPanel(
40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 42 /* DCLK */, 45 /* R0 */,
48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */, 5 /* G0 */, 6 /* G1 */,
7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */, 8 /* B0 */, 3 /* B1 */,
46 /* B2 */, 9 /* B3 */, 1 /* B4 */, 0 /*hsync_polarity*/,
8 /* hsync_front_porch*/, 4 /* hsync_pulse_width*/,
43 /* hsync_back_porch*/, 0 /*vsync_polarity*/, 8 /*vsync_front_porch*/,
4 /*vsync_pulse_width*/, 12 /*vsync_back_porch*/, 1 /*pclk_active_neg*/,
16000000 /*prefer_speed*/, false /*useBigEndian*/, 0 /*de_idle_high*/,
0 /*pclk_idle_high*/
);
/* More display class:
* https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
// bus, DF_GFX_RST, 0 /* rotation */, false /* IPS */);
/*Set to your screen resolution*/
#define TFT_HOR_RES 800
#define TFT_VER_RES 480
//
Arduino_GFX *gfx = new Arduino_RGB_Display(TFT_HOR_RES, TFT_VER_RES, panel, 16);
HardwareSerial debugSerial(1);
// UIelements
DashUI *ui = new DashUI();
UIDecorations *rpmTextDecor = new UIDecorations();
UIString rpmText(gfx, UIDimensions(37, 35, 333, 111), rpmTextDecor,
(char *)"RPM");
void initialDisplaySetup() {
psramInit();
gfx->begin();
// gfx->setFont(u8g2_font_9x18_tf);
// Set screen & touch to the same rotation
debugSerial.println(F("* Setting up display"));
gfx->setRotation(SCREEN_ORIENTATION);
backlightSetup();
gfx->fillScreen(MAIN_BG_COLOR);
gfx->setTextColor(MAIN_FG_COLOR);
}
void setup() {
// psramInit();
uint64_t start = millis();
debugSerial.begin(115200, SERIAL_8N1, UART1_RX, UART1_TX);
Serial.begin(115200);
// Serial.begin(115200);
debugSerial.println(F("=== ESP32 SimRacing DashDisplay ==="));
debugSerial.println(F("* Initiating display"));
initialDisplaySetup();
// Setup the rpmText box
rpmTextDecor->textSize = 4;
rpmText.dims.height =
calculateHeight(rpmTextDecor->titleSize, rpmTextDecor->textSize, 1);
rpmText.dims.width = calculateWidth(rpmTextDecor->textSize, 5);
ui->rpmText = &rpmText;
ui->rpmText->drawBox();
ui->rpmText->Update("12345");
}
uint64_t lastDataRead = 0;
uint8_t packetBuffer[sizeof(DataPacket)];
int bufferIndex = 0;
void loop(void) {
// Read bytes one by one
while (Serial.available() > 0) {
packetBuffer[bufferIndex] = Serial.read();
bufferIndex++;
// Check if we have a complete packet
if (bufferIndex >= sizeof(DataPacket)) {
// Copy the buffer into the struct
DataPacket packet;
memcpy(&packet, packetBuffer, sizeof(DataPacket));
// Reset the buffer index
bufferIndex = 0;
// gfx->setCursor(20, 20);
// gfx->println(packet.speed);
// gfx->setCursor(20, 40);
// gfx->println(packet.rpm);
// gfx->setCursor(20, 60);
// gfx->println(packet.gear);
// gfx->setCursor(20, 80);
// gfx->println(packet.FuelEst);
// gfx->setCursor(20, 100);
// gfx->println(packet.LapNumber);
// gfx->setCursor(20, 120);
// gfx->println(packet.currLapTime);
// gfx->setCursor(20, 140);
// gfx->println(packet.lastLapTime);
// Process the packet
// if (millis() - lastDataPrint > 50) {
// debugDataPacket(&packet);
// lastDataPrint = millis();
// }
// ui.speedometer->Update(packet.speed);
//
// ui.gear->Update(packet.gear);
// ui.numberTach->Update(packet.rpm);
// ui.barTach->Update(packet.rpm);
// ui.relative->Update(packet.standings);
for (int k = 0; k < 15; k += 3) {
// ui.relative->tableData[k + 0].Update(packet.standings[k / 3].Lap);
// ui.relative->tableData[k + 1].Update(
// packet.standings[k / 3].DriverName);
// ui.relative->tableData[k + 2].Update(
// packet.standings[k / 3].TimeBehindString);
}
lastDataRead = millis();
}
}
// If no data is received for 5 seconds, reset the display
if (millis() - lastDataRead >= 5000) {
// ui.speedometer->Update(0);
// ui.numberTach->Update(0);
// ui.gear->Update(0);
// ui.barTach->Update(0);
}
}
+10
View File
@@ -0,0 +1,10 @@
#include "ui.h"
#include "UIDecorations.h"
DashUI::DashUI() {}
void DashUI::dashUISetup(Arduino_GFX *gfx) {
// rpmTextDecorations
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef __DASH_DISPLAY_UI
#define __DASH_DISPLAY_UI
#include "Arduino_GFX.h"
#include "UIString.h"
struct DashUI {
UIString *rpmText;
DashUI();
void dashUISetup(Arduino_GFX *gfx);
};
#endif