mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-24 01:25:41 +08:00
Add initial support for the Nextion display.
This commit is contained in:
24
Conf.cpp
24
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<unsigned int> CConf::getHD44780Pins() const
|
||||
{
|
||||
return m_hd44780Pins;
|
||||
}
|
||||
|
||||
std::string CConf::getNextionPort() const
|
||||
{
|
||||
return m_nextionPort;
|
||||
}
|
||||
|
||||
unsigned int CConf::getNextionBrightness() const
|
||||
{
|
||||
return m_nextionBrightness;
|
||||
}
|
||||
|
||||
7
Conf.h
7
Conf.h
@@ -117,6 +117,10 @@ public:
|
||||
unsigned int getHD44780Columns() const;
|
||||
std::vector<unsigned int> 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<unsigned int> m_hd44780Pins;
|
||||
|
||||
std::string m_nextionPort;
|
||||
unsigned int m_nextionBrightness;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "TFTSerial.h"
|
||||
#include "NullDisplay.h"
|
||||
#include "YSFControl.h"
|
||||
#include "Nextion.h"
|
||||
|
||||
#if defined(HD44780)
|
||||
#include "HD44780.h"
|
||||
@@ -578,6 +579,14 @@ void CMMDVMHost::createDisplay()
|
||||
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();
|
||||
|
||||
@@ -176,6 +176,7 @@
|
||||
<ClInclude Include="Log.h" />
|
||||
<ClInclude Include="MMDVMHost.h" />
|
||||
<ClInclude Include="Modem.h" />
|
||||
<ClInclude Include="Nextion.h" />
|
||||
<ClInclude Include="NullDisplay.h" />
|
||||
<ClInclude Include="QR1676.h" />
|
||||
<ClInclude Include="RingBuffer.h" />
|
||||
@@ -225,6 +226,7 @@
|
||||
<ClCompile Include="Log.cpp" />
|
||||
<ClCompile Include="MMDVMHost.cpp" />
|
||||
<ClCompile Include="Modem.cpp" />
|
||||
<ClCompile Include="Nextion.cpp" />
|
||||
<ClCompile Include="NullDisplay.cpp" />
|
||||
<ClCompile Include="QR1676.cpp" />
|
||||
<ClCompile Include="RS129.cpp" />
|
||||
|
||||
@@ -161,6 +161,9 @@
|
||||
<ClInclude Include="Trellis.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Nextion.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="BPTC19696.cpp">
|
||||
@@ -295,5 +298,8 @@
|
||||
<ClCompile Include="Trellis.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Nextion.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
6
Makefile
6
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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
189
Nextion.cpp
Normal file
189
Nextion.cpp
Normal file
@@ -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 <cstdio>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
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);
|
||||
}
|
||||
61
Nextion.h
Normal file
61
Nextion.h
Normal file
@@ -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 <string>
|
||||
|
||||
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
|
||||
BIN
Nextion/MMDVM.HMI
Normal file
BIN
Nextion/MMDVM.HMI
Normal file
Binary file not shown.
Reference in New Issue
Block a user