I know this is herecy, but I like the 4x20 display, I just wish I could get it in red.
//Copyright 2021-2022(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM
//LiDisplay (HMI) Serial Functions
#include "libcm.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void LiDisplay_begin(void)
{
Serial.print(F("\nLiDisplay BEGIN"));
Serial1.begin(9600,SERIAL_8E1);
Serial1.print("page0.t1.txt=" + String('"') + String(FW_VERSION) + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.print("page0.n0.val=" + String('"') + SoC_getBatteryStateNow_percent() + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.print("page0.j0.val=" + String('"') + SoC_getBatteryStateNow_percent() + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial.print(F("\nLiDisplay SENT"));
//LiDisplay_writeByte(SoC_getBatteryStateNow_percent());
//LiDisplay_writeByte(SoC_getBatteryStateNow_percent());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_bytesAvailableForWrite(void)
{
return Serial1.availableForWrite();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_writeByte(uint8_t data)
{
Serial1.write(data);
return data;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_readByte(void)
{
return Serial1.read();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_bytesAvailableToRead()
{
return Serial1.available();
}
//Copyright 2021-2022(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM
//LiDisplay (HMI) Serial Functions
#include "libcm.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void LiDisplay_begin(void)
{
Serial.print(F("\nLiDisplay BEGIN"));
Serial1.begin(9600,SERIAL_8E1);
Serial1.print("page0.t1.txt=" + String('"') + String(FW_VERSION) + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.print("page0.n0.val=" + String('"') + String(SoC_getBatteryStateNow_percent()) + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
/* Serial1.print("page0.j0.val=" + String('"') + String(SoC_getBatteryStateNow_percent()) + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF); */
Serial.print(F("\nLiDisplay SENT"));
//LiDisplay_writeByte(SoC_getBatteryStateNow_percent());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_bytesAvailableForWrite(void)
{
return Serial1.availableForWrite();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_writeByte(uint8_t data)
{
Serial1.write(data);
return data;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_readByte(void)
{
return Serial1.read();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_bytesAvailableToRead()
{
return Serial1.available();
}
//Copyright 2021-2022(c) John Sullivan
//github.com/doppelhub/Honda_Insight_LiBCM
//LiDisplay (HMI) Serial Functions
#include "libcm.h"
bool versionAlreadyDisplayed = false;
uint8_t LiDisplayElementToUpdate = 0;
const String typeMap[3] = {
"j", "n", "t"
};
const String attrMap[2] = {
"txt", "val"
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void LiDisplay_begin(void)
{
#ifdef LIDISPLAY_CONNECTED
Serial.print(F("\nLiDisplay BEGIN"));
Serial1.begin(9600,SERIAL_8E1);
LiDisplayElementToUpdate = 0;
/* Serial1.print("page0.j0.val=" + String('"') + String(SoC_getBatteryStateNow_percent()) + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF); */
//LiDisplay_writeByte(SoC_getBatteryStateNow_percent());
#endif
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void LiDisplay_updateElement(uint8_t page, uint8_t elementTypeIndex, uint8_t elementId, uint8_t elementAttrIndex, String value) {
#ifdef LIDISPLAY_CONNECTED
static String LiDisplay_Data_Str;
LiDisplay_Data_Str = "page" + String(page) + "." + typeMap[elementTypeIndex] + elementId + "." + attrMap[elementAttrIndex] + "=" + String('"') + value + String('"');
Serial1.print(LiDisplay_Data_Str);
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
/*
Serial1.print("page0.t1.txt=" + String('"') + String(FW_VERSION) + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.print("page0.n0.val=" + String('"') + String(SoC_getBatteryStateNow_percent()) + String('"'));
Serial1.write(0xFF);
Serial1.write(0xFF);
Serial1.write(0xFF);
*/
#endif
}
void LiDisplay_refresh(void)
{
#ifdef LIDISPLAY_CONNECTED
//static uint8_t LiDisplayElementToUpdate = LCDUPDATE_NUMERRORS; //init round-robin with least likely state to have changed
static uint32_t millis_previous = 0;
#define LIDISPLAY_UPDATE_RATE_MILLIS 256 //one element is updated each time
if(millis() - millis_previous > LIDISPLAY_UPDATE_RATE_MILLIS)
{
millis_previous = millis();
switch(LiDisplayElementToUpdate)
{
case 0:
//LiDisplay_updateElement(0, 1, 0, 1, String(SoC_getBatteryStateNow_percent()));
LiDisplay_updateElement(0, 2, 1, 0, String(FW_VERSION));
break;
case 1:
//LiDisplay_updateElement(0, 2, 1, 0, String(555));
LiDisplay_updateElement(0, 1, 0, 1, String(SoC_getBatteryStateNow_percent()));
break;
case 2:
//LiDisplay_updateElement(0, 2, 1, 0, String(666));
LiDisplay_updateElement(0, 0, 0, 1, String(SoC_getBatteryStateNow_percent()));
break;
}
LiDisplayElementToUpdate += 1;
if (LiDisplayElementToUpdate > 2) {
LiDisplayElementToUpdate = 0;
}
/*
uint8_t updateAttempts = 0;
do
{
if( (++LiDisplayElementToUpdate) > LIDISPLAYUPDATE_MAX_VALUE ) { LiDisplayElementToUpdate = 1; } //reset to first element
updateAttempts++;
} while( (lcd_updateValue(LiDisplayElementToUpdate) == SCREEN_DIDNT_UPDATE) && (updateAttempts < MAX_LIDISPLAYUPDATE_ATTEMPTS) );
*/
}
#endif
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_bytesAvailableForWrite(void)
{
return Serial1.availableForWrite();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_writeByte(uint8_t data)
{
Serial1.write(data);
return data;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_readByte(void)
{
return Serial1.read();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t LiDisplay_bytesAvailableToRead()
{
return Serial1.available();
}
# Touch Screen Inputs:If you are going to use touchscreen inputs... it is sensitive to the polling interval so you can end up hanging the screen if you don't poll it often enough etc... the stock Nextion library is very prone to this.
I ended up using EasyNextion which handles alittle of the work of getting the thing to work reliably .... you put a bit of code in each button and it triggers predefined functions eg trigger0() etc... when you press a button that is printing the correct bytes to UART. The other nextion libraries are all nice and use objects and such but they this is the only library I got working reliably.
You can put
In the Program.s to set the baud rate to a permanently higher or lower rate... I have tested higher rates and they can only really be done over short cables, 38400 is a good compromise speed. I also changed all the names of my screen objects to single letters... so I could maximize sceen update speed and minimze serial errors.Code:bauds=38400
I implemented a progress guage for the project I did (it was QT tester for an industrial board).... it also had an encoder my board was using and displaying the output to a graph with, something like add 0,23,0,data here to add plot points... I can dig up the code if curious.