【Open-Source】Car Head-Up Display Solution Based on T5L Smart Screen
——From DWIN Developer Forum
Today, we are highlighting an award-winning case from the DWIN developer forum, the car head-up display solution powered by T5L. The solution integrates DWIN's COF screen and T5L CAN port to display real-time vehicle speed and RPM data, directly sourced from the OBDII diagnostic port. This provides drivers with a convenient and intuitive visual aid during their journey.
[UI Material Demonstration]
[GUI Project Design]
[Program Code Design]
Obtain vehicle speed and RPM data through the T5L CAN interface. A portion of the reference code is as follows:
void main(void)
{
T5LInit();
T0_Init(); // Set up Timer 0
EA = 1;
// Wait for power supply to stabilize
TimerExtDelayMs(2000);
GaugeViewInit();
while (1)
{
//obdii System initiates recognition process
if (ObdiiSysEnter())
{
break;
}
}
//HUD Primary Function Entry
GaugeViewFunc();
}
void GaugeViewFunc(void)
{
uint8_t rawDataBuff[256];
uint8_t resultBuff[5];
float vehicleSpeed = 0;
float rotateSpeed = 0;
uint32_t tempData = 0;
while (1)
{
memset(rawDataBuff, 0, 256);
// read vehicle speed
if (ObdiiReadPid(rawDataBuff, 2, 0x01, 0x0C))
{
ObdiiLdsCalResult(0x0C, rawDataBuff, resultBuff);
tempData = resultBuff[3];
tempData = resultBuff[2] + (tempData << 8);
tempData = resultBuff[1] + (tempData << 8);
tempData = resultBuff[0] + (tempData << 8);
rotateSpeed = (float)tempData;
GaugeViewRotateSpeedSet(rotateSpeed);
}
memset(rawDataBuff, 0, 256);
// Read Vehicle Speed
if (ObdiiReadPid(rawDataBuff, 2, 0x01, 0x0D))
{
ObdiiLdsCalResult(0x0D, rawDataBuff, resultBuff);
tempData = resultBuff[3];
tempData = resultBuff[2] + (tempData << 8);
tempData = resultBuff[1] + (tempData << 8);
tempData = resultBuff[0] + (tempData << 8);
vehicleSpeed = (float)tempData;
GaugeViewPointerSet((uint8_t)vehicleSpeed);
GaugeViewVehicleSpeedSet(vehicleSpeed);
}
}
}
void GaugeViewFunc(void)
{
uint8_t rawDataBuff[256];
uint8_t resultBuff[5];
float vehicleSpeed = 0;
float rotateSpeed = 0;
uint32_t tempData = 0;
while (1)
{
memset(rawDataBuff, 0, 256);
// Read RPM
if (ObdiiReadPid(rawDataBuff, 2, 0x01, 0x0C))
{
ObdiiLdsCalResult(0x0C, rawDataBuff, resultBuff);
tempData = resultBuff[3];
tempData = resultBuff[2] + (tempData << 8);
tempData = resultBuff[1] + (tempData << 8);
tempData = resultBuff[0] + (tempData << 8);
rotateSpeed = (float)tempData;
GaugeViewRotateSpeedSet(rotateSpeed);
}
memset(rawDataBuff, 0, 256);
// Read vehicle speed
if (ObdiiReadPid(rawDataBuff, 2, 0x01, 0x0D))
{
ObdiiLdsCalResult(0x0D, rawDataBuff, resultBuff);
tempData = resultBuff[3];
tempData = resultBuff[2] + (tempData << 8);
tempData = resultBuff[1] + (tempData << 8);
tempData = resultBuff[0] + (tempData << 8);
vehicleSpeed = (float)tempData;
GaugeViewPointerSet((uint8_t)vehicleSpeed);
GaugeViewVehicleSpeedSet(vehicleSpeed);
}
}
}