Skip to content

Commit

Permalink
Nextion display is queried to know it's layout so the new binary can …
Browse files Browse the repository at this point in the history
…function with 'old' and 'new' layouts.

It is done in a way to acommodate future layout changes (the display sends it's 'layout version')
  • Loading branch information
on7lds committed Oct 22, 2017
1 parent 8c9afa6 commit ea5be21
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 44 deletions.
123 changes: 79 additions & 44 deletions Nextion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,7 @@
#include <cstring>
#include <ctime>
#include <clocale>

/*
#include "Nextion.h"
#include "Log.h"
#include <cstdio>
#include <cassert>
#include <cstring>
#include <ctime>
#include <clocale>
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
//#include <sys/socket.h>
#include <netdb.h>
//#include <ifaddrs.h>
//#include <linux/if_link.h>
*/

#include <unistd.h>

const unsigned int DSTAR_RSSI_COUNT = 3U; // 3 * 420ms = 1260ms
const unsigned int DSTAR_BER_COUNT = 63U; // 63 * 20ms = 1260ms
Expand Down Expand Up @@ -107,6 +85,7 @@ bool CNextion::open()
m_ipaddress = (char*)info;

sendCommand("bkcmd=0");
m_screenLayout=100;

setIdle();

Expand All @@ -116,24 +95,25 @@ bool CNextion::open()

void CNextion::setIdleInt()
{
char text[30U];

sendCommand("page MMDVM");

char command[30];
::sprintf(command, "dim=%u", m_idleBrightness);
sendCommand(command);

::sprintf(command, "t0.txt=\"%s/%u\"", m_callsign.c_str(), m_dmrid);

sendCommand(command);
sendCommand("t1.txt=\"MMDVM IDLE\"");

char text[30U];
::sprintf(text, "t3.txt=\"%s\"", m_ipaddress.c_str());
sendCommand(text);

m_clockDisplayTimer.start();

m_mode = MODE_IDLE;

if (m_screenLayout==100) checkScreenLayout();
}

void CNextion::setErrorInt(const char* text)
Expand Down Expand Up @@ -267,12 +247,16 @@ void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro
sendCommand("page DMR");

if (slotNo == 1U) {
sendCommand("t2.pco=0");
sendCommand("t2.font=4");
if (m_screenLayout==2) {
sendCommand("t2.pco=0");
sendCommand("t2.font=4");
}
sendCommand("t2.txt=\"2 Listening\"");
} else {
sendCommand("t0.pco=0");
sendCommand("t0.font=4");
if (m_screenLayout==2) {
sendCommand("t0.pco=0");
sendCommand("t0.font=4");
}
sendCommand("t0.txt=\"1 Listening\"");
}
}
Expand All @@ -283,18 +267,20 @@ void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro

if (slotNo == 1U) {
::sprintf(text, "t0.txt=\"1 %s %s\"", type, src.c_str());
sendCommand("t0.pco=0");
sendCommand("t0.font=4");
if (m_screenLayout==2) {
sendCommand("t0.pco=0");
sendCommand("t0.font=4");
}
sendCommand(text);

::sprintf(text, "t1.txt=\"%s%s\"", group ? "TG" : "", dst.c_str());
sendCommand(text);
} else {
::sprintf(text, "t2.txt=\"2 %s %s\"", type, src.c_str());
sendCommand("t2.pco=0");
sendCommand("t2.font=4");
if (m_screenLayout==2) {
sendCommand("t2.pco=0");
sendCommand("t2.font=4");
}
sendCommand(text);

::sprintf(text, "t3.txt=\"%s%s\"", group ? "TG" : "", dst.c_str());
sendCommand(text);
}
Expand Down Expand Up @@ -371,16 +357,20 @@ void CNextion::writeDMRTAInt(unsigned int slotNo, unsigned char* talkerAlias, c

if (slotNo == 1U) {
::sprintf(text, "t0.txt=\"1 %s %s\"",type,talkerAlias);
if (strlen((char*)talkerAlias)>16-4) sendCommand("t0.font=3");
if (strlen((char*)talkerAlias)>20-4) sendCommand("t0.font=2");
if (strlen((char*)talkerAlias)>24-4) sendCommand("t0.font=1");
if (m_screenLayout==2) {
if (strlen((char*)talkerAlias)>16-4) sendCommand("t0.font=3");
if (strlen((char*)talkerAlias)>20-4) sendCommand("t0.font=2");
if (strlen((char*)talkerAlias)>24-4) sendCommand("t0.font=1");
}
sendCommand("t0.pco=1024");
sendCommand(text);
} else {
::sprintf(text, "t2.txt=\"2 %s %s\"",type,talkerAlias);
if (strlen((char*)talkerAlias)>16-4) sendCommand("t2.font=3");
if (strlen((char*)talkerAlias)>20-4) sendCommand("t2.font=2");
if (strlen((char*)talkerAlias)>24-4) sendCommand("t2.font=1");
if (m_screenLayout==2) {
if (strlen((char*)talkerAlias)>16-4) sendCommand("t2.font=3");
if (strlen((char*)talkerAlias)>20-4) sendCommand("t2.font=2");
if (strlen((char*)talkerAlias)>24-4) sendCommand("t2.font=1");
}
sendCommand("t2.pco=1024");
sendCommand(text);
}
Expand Down Expand Up @@ -435,14 +425,18 @@ void CNextion::clearDMRInt(unsigned int slotNo)
if (slotNo == 1U) {
sendCommand("t0.txt=\"1 Listening\"");
sendCommand("t0.pco=0");
sendCommand("t0.font=4");
if (m_screenLayout==2) {
sendCommand("t0.font=4");
}
sendCommand("t1.txt=\"\"");
sendCommand("t4.txt=\"\"");
sendCommand("t6.txt=\"\"");
} else {
sendCommand("t2.txt=\"2 Listening\"");
sendCommand("t2.pco=0");
sendCommand("t2.font=4");
if (m_screenLayout==2) {
sendCommand("t2.font=4");
}
sendCommand("t3.txt=\"\"");
sendCommand("t5.txt=\"\"");
sendCommand("t7.txt=\"\"");
Expand Down Expand Up @@ -666,3 +660,44 @@ void CNextion::sendCommand(const char* command)
m_serial->write((unsigned char*)command, ::strlen(command));
m_serial->write((unsigned char*)"\xFF\xFF\xFF", 3U);
}



void CNextion::checkScreenLayout()
{
unsigned int res;
int pos,length,screen;
unsigned char data[25];

memset(data,0,25);
pos=0;
length=1;
screen=0;

sendCommand("bkcmd=2");
res=1; while (m_serial->read(&data[0],1)>0) {;}
sendCommand("get MMDVM.screenLayout.val");
sleep(1); //have to wait for answer

while (length>0) {
length=m_serial->read(&data[pos],1);
if (length>0) {
// LogMessage("Nextion %d data received %02X ",length,(char)data[pos]);
pos++;
}
}
if (pos>0) {
if ((data[0]==0x71)&&(pos>4)) screen=data[1]+(data[2]<<8)+(data[3]<<16)+(data[4]<<24);
// LogMessage("Result value %d",screen);
}

if ((res==0x1A)||(screen==0)) {
m_screenLayout=1;
LogMessage(" Display Layout: %d (G4KLX)",screen);
} else {
m_screenLayout=2;
LogMessage(" Display Layout: %d (ON7LDS)",screen);
}
sendCommand("bkcmd=0");
}

3 changes: 3 additions & 0 deletions Nextion.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ class CNextion : public CDisplay
unsigned int m_rssiCount2;
unsigned int m_berCount1;
unsigned int m_berCount2;
unsigned char m_screenLayout;

void sendCommand(const char* command);
void checkScreenLayout();

};

#endif
Binary file modified Nextion_ON7LDS/NX3224T024-ON7LDS.HMI
Binary file not shown.
Binary file modified Nextion_ON7LDS/NX3224T024-ON7LDS.tft
Binary file not shown.
Binary file modified Nextion_ON7LDS/NX3224T028-ON7LDS.HMI
Binary file not shown.
Binary file modified Nextion_ON7LDS/NX3224T028-ON7LDS.tft
Binary file not shown.
Binary file modified Nextion_ON7LDS/NX4024T032-ON7LDS.HMI
Binary file not shown.
Binary file modified Nextion_ON7LDS/NX4024T032-ON7LDS.tft
Binary file not shown.
Binary file modified Nextion_ON7LDS/NX4832T035-ON7LDS.HMI
Binary file not shown.
Binary file modified Nextion_ON7LDS/NX4832T035-ON7LDS.tft
Binary file not shown.

0 comments on commit ea5be21

Please sign in to comment.