diff --git a/Conf.cpp b/Conf.cpp index 0ef34a5..6342006 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -40,7 +40,8 @@ enum SECTION { SECTION_DMR_NETWORK, SECTION_FUSION_NETWORK, SECTION_TFTSERIAL, - SECTION_HD44780 + SECTION_HD44780, + SECTION_NEXTION }; CConf::CConf(const std::string& file) : @@ -107,7 +108,9 @@ m_tftSerialPort(), m_tftSerialBrightness(50U), m_hd44780Rows(2U), m_hd44780Columns(16U), -m_hd44780Pins() +m_hd44780Pins(), +m_nextionPort(), +m_nextionBrightness(50U) { } @@ -155,6 +158,8 @@ bool CConf::read() section = SECTION_TFTSERIAL; else if (::strncmp(buffer, "[HD44780]", 9U) == 0) section = SECTION_HD44780; + else if (::strncmp(buffer, "[Nextion]", 9U) == 0) + section = SECTION_NEXTION; else section = SECTION_NONE; @@ -334,6 +339,11 @@ bool CConf::read() p = ::strtok(NULL, ",\r\n"); } } + } else if (section == SECTION_NEXTION) { + if (::strcmp(key, "Port") == 0) + m_nextionPort = value; + else if (::strcmp(key, "Brightness") == 0) + m_nextionBrightness = (unsigned int)::atoi(value); } } @@ -656,3 +666,13 @@ std::vector CConf::getHD44780Pins() const { return m_hd44780Pins; } + +std::string CConf::getNextionPort() const +{ + return m_nextionPort; +} + +unsigned int CConf::getNextionBrightness() const +{ + return m_nextionBrightness; +} diff --git a/Conf.h b/Conf.h index fca75e0..65ff3fd 100644 --- a/Conf.h +++ b/Conf.h @@ -117,6 +117,10 @@ public: unsigned int getHD44780Columns() const; std::vector getHD44780Pins() const; + // The Nextion section + std::string getNextionPort() const; + unsigned int getNextionBrightness() const; + private: std::string m_file; std::string m_callsign; @@ -193,6 +197,9 @@ private: unsigned int m_hd44780Rows; unsigned int m_hd44780Columns; std::vector m_hd44780Pins; + + std::string m_nextionPort; + unsigned int m_nextionBrightness; }; #endif diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 8fa5b41..1d8ae76 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -26,6 +26,7 @@ #include "TFTSerial.h" #include "NullDisplay.h" #include "YSFControl.h" +#include "Nextion.h" #if defined(HD44780) #include "HD44780.h" @@ -571,13 +572,21 @@ void CMMDVMHost::createDisplay() LogInfo(" Type: %s", type.c_str()); if (type == "TFT Serial") { - std::string port = m_conf.getTFTSerialPort(); + std::string port = m_conf.getTFTSerialPort(); unsigned int brightness = m_conf.getTFTSerialBrightness(); LogInfo(" Port: %s", port.c_str()); LogInfo(" Brightness: %u", brightness); m_display = new CTFTSerial(port, brightness); + } else if (type == "Nextion") { + std::string port = m_conf.getNextionPort(); + unsigned int brightness = m_conf.getNextionBrightness(); + + LogInfo(" Port: %s", port.c_str()); + LogInfo(" Brightness: %u", brightness); + + m_display = new CNextion(port, brightness); #if defined(HD44780) } else if (type == "HD44780") { unsigned int rows = m_conf.getHD44780Rows(); diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index 66a0715..ffdc777 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -176,6 +176,7 @@ + @@ -225,6 +226,7 @@ + diff --git a/MMDVMHost.vcxproj.filters b/MMDVMHost.vcxproj.filters index 2f865e0..d1c0428 100644 --- a/MMDVMHost.vcxproj.filters +++ b/MMDVMHost.vcxproj.filters @@ -161,6 +161,9 @@ Header Files + + Header Files + @@ -295,5 +298,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/Makefile b/Makefile index 3cf12f9..289f016 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,9 @@ LDFLAGS = -g OBJECTS = \ AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLC.o DMRShortLC.o \ - DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o NullDisplay.o \ - QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o YSFFICH.o \ - YSFParrot.o YSFPayload.o + DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o Nextion.o \ + NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o \ + YSFFICH.o YSFParrot.o YSFPayload.o all: MMDVMHost diff --git a/Makefile.Pi b/Makefile.Pi index 3851ec8..5aac706 100644 --- a/Makefile.Pi +++ b/Makefile.Pi @@ -9,8 +9,8 @@ LDFLAGS = -g -L/usr/local/lib OBJECTS = \ AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLC.o DMRShortLC.o \ DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o Modem.o \ - NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o \ - YSFFICH.o YSFParrot.o YSFPayload.o + Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o Trellis.o UDPSocket.o Utils.o YSFControl.o \ + YSFConvolution.o YSFFICH.o YSFParrot.o YSFPayload.o all: MMDVMHost diff --git a/Nextion.cpp b/Nextion.cpp new file mode 100644 index 0000000..2f2012c --- /dev/null +++ b/Nextion.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2016 by Jonathan Naylor G4KLX + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "Nextion.h" +#include "Log.h" + +#include +#include +#include + +CNextion::CNextion(const std::string& port, unsigned int brightness) : +m_serial(port, SERIAL_9600), +m_brightness(brightness) +{ + assert(brightness >= 0U && brightness <= 100U); +} + +CNextion::~CNextion() +{ +} + +bool CNextion::open() +{ + bool ret = m_serial.open(); + if (!ret) { + LogError("Cannot open the port for the Nextion display"); + return false; + } + + sendCommand("bkcmd=0"); + + char command[20U]; + ::sprintf(command, "dim=%u", m_brightness); + sendCommand(command); + + setIdle(); + + return true; +} + +void CNextion::setIdle() +{ + sendCommand("page MMDVM"); + + sendCommand("t0.txt=\"IDLE\""); +} + +void CNextion::setError(const char* text) +{ + assert(text != NULL); + + sendCommand("page MMDVM"); + + char command[20]; + ::sprintf(command, "t0.txt=\"%s\"", text); + + sendCommand(command); + sendCommand("t1.txt=\"ERROR\""); +} + +void CNextion::setLockout() +{ + sendCommand("page MMDVM"); + + sendCommand("t0.txt=\"LOCKOUT\""); +} + +void CNextion::setDStar() +{ + sendCommand("page DStar"); + + sendCommand("t0.txt=\"Listening\""); +} + +void CNextion::writeDStar(const char* my1, const char* my2, const char* your) +{ + assert(my1 != NULL); + assert(my2 != NULL); + assert(your != NULL); + + char text[30U]; + ::sprintf(text, "t0.txt=\"%.8s/%4.4s\"", my1, my2); + sendCommand(text); + + ::sprintf(text, "t1.txt=\"%.8s\"", your); + sendCommand(text); +} + +void CNextion::clearDStar() +{ + sendCommand("t0.txt=\"Listening\""); + sendCommand("t1.txt=\"\""); +} + +void CNextion::setDMR() +{ + sendCommand("page DMR"); + + sendCommand("t0.txt=\"1 Listening\""); + sendCommand("t2.txt=\"2 Listening\""); +} + +void CNextion::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId, const char* type) +{ + assert(type != NULL); + + if (slotNo == 1U) { + char text[30U]; + + ::sprintf(text, "t0.txt=\"1 %s %u\"", type, srcId); + sendCommand(text); + + ::sprintf(text, "t1.txt=\"%s%u\"", group ? "TG" : "", dstId); + sendCommand(text); + } else { + char text[30U]; + + ::sprintf(text, "t2.txt=\"2 %s %u\"", type, srcId); + sendCommand(text); + + ::sprintf(text, "t3.txt=\"%s%u\"", group ? "TG" : "", dstId); + sendCommand(text); + } +} + +void CNextion::clearDMR(unsigned int slotNo) +{ + if (slotNo == 1U) { + sendCommand("t0.txt=\"1 Listening\""); + sendCommand("t1.txt=\"\""); + } else { + sendCommand("t2.txt=\"2 Listening\""); + sendCommand("t3.txt=\"\""); + } +} + +void CNextion::setFusion() +{ + sendCommand("page YSF"); + + sendCommand("t0.txt=\"Listening\""); +} + +void CNextion::writeFusion(const char* source, const char* dest) +{ + assert(source != NULL); + assert(dest != NULL); + + char text[30U]; + ::sprintf(text, "t0.txt=\"%.10s\"", source); + sendCommand(text); + + ::sprintf(text, "t1.txt=\"%.10s\"", dest); + sendCommand(text); +} + +void CNextion::clearFusion() +{ + sendCommand("t0.txt=\"Listening\""); + sendCommand("t1.txt=\"\""); +} + +void CNextion::close() +{ + m_serial.close(); +} + +void CNextion::sendCommand(const char* command) +{ + assert(command != NULL); + + m_serial.write((unsigned char*)command, ::strlen(command)); + m_serial.write((unsigned char*)"\xFF\xFF\xFF", 3U); +} diff --git a/Nextion.h b/Nextion.h new file mode 100644 index 0000000..ad60f95 --- /dev/null +++ b/Nextion.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2016 by Jonathan Naylor G4KLX + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#if !defined(NEXTION_H) +#define NEXTION_H + +#include "Display.h" +#include "SerialController.h" + +#include + +class CNextion : public IDisplay +{ +public: + CNextion(const std::string& port, unsigned int brightness); + virtual ~CNextion(); + + virtual bool open(); + + virtual void setIdle(); + + virtual void setError(const char* text); + virtual void setLockout(); + + virtual void setDStar(); + virtual void writeDStar(const char* my1, const char* my2, const char* your); + virtual void clearDStar(); + + virtual void setDMR(); + virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type); + virtual void clearDMR(unsigned int slotNo); + + virtual void setFusion(); + virtual void writeFusion(const char* source, const char* dest); + virtual void clearFusion(); + + virtual void close(); + +private: + CSerialController m_serial; + unsigned int m_brightness; + + void sendCommand(const char* command); +}; + +#endif diff --git a/Nextion/MMDVM.HMI b/Nextion/MMDVM.HMI new file mode 100644 index 0000000..051b9aa Binary files /dev/null and b/Nextion/MMDVM.HMI differ