2016-04-06 18:53:25 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2016-04-08 11:47:05 +00:00
|
|
|
CNextion::CNextion(const char* callsign, unsigned int dmrid, const std::string& port, unsigned int brightness) :
|
|
|
|
m_callsign(callsign),
|
|
|
|
m_dmrid(dmrid),
|
2016-04-06 18:53:25 +00:00
|
|
|
m_serial(port, SERIAL_9600),
|
2016-04-11 11:21:46 +00:00
|
|
|
m_brightness(brightness),
|
|
|
|
m_mode(MODE_IDLE)
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
2016-04-18 18:54:31 +00:00
|
|
|
assert(callsign != NULL);
|
2016-04-06 18:53:25 +00:00
|
|
|
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");
|
|
|
|
|
2016-04-08 11:47:05 +00:00
|
|
|
char command[30];
|
|
|
|
::sprintf(command, "t0.txt=\"%-6s / %u\"", m_callsign, m_dmrid);
|
|
|
|
|
|
|
|
sendCommand(command);
|
|
|
|
sendCommand("t1.txt=\"MMDVM IDLE\"");
|
2016-04-11 11:21:46 +00:00
|
|
|
|
|
|
|
m_mode = MODE_IDLE;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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\"");
|
2016-04-11 11:21:46 +00:00
|
|
|
|
|
|
|
m_mode = MODE_ERROR;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CNextion::setLockout()
|
|
|
|
{
|
|
|
|
sendCommand("page MMDVM");
|
|
|
|
|
|
|
|
sendCommand("t0.txt=\"LOCKOUT\"");
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
m_mode = MODE_LOCKOUT;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-04-16 19:45:49 +00:00
|
|
|
void CNextion::writeDStar(const char* my1, const char* my2, const char* your, const char* type, const char* reflector)
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
assert(my1 != NULL);
|
|
|
|
assert(my2 != NULL);
|
|
|
|
assert(your != NULL);
|
2016-04-12 16:46:48 +00:00
|
|
|
assert(type != NULL);
|
2016-04-16 20:20:18 +00:00
|
|
|
assert(reflector != NULL);
|
2016-04-06 18:53:25 +00:00
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
if (m_mode != MODE_DSTAR)
|
|
|
|
sendCommand("page DStar");
|
|
|
|
|
2016-04-06 18:53:25 +00:00
|
|
|
char text[30U];
|
2016-04-12 06:18:01 +00:00
|
|
|
::sprintf(text, "t0.txt=\"%s %.8s/%4.4s\"", type, my1, my2);
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
2016-04-16 20:20:18 +00:00
|
|
|
if (strcmp(reflector, " ") == 0) {
|
|
|
|
::sprintf(text, "t1.txt=\"%.8s\"", your);
|
|
|
|
} else {
|
|
|
|
::sprintf(text, "t1.txt=\"%.8s <- %-8s\"", your, reflector);
|
|
|
|
}
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
2016-04-11 11:21:46 +00:00
|
|
|
|
|
|
|
m_mode = MODE_DSTAR;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CNextion::clearDStar()
|
|
|
|
{
|
|
|
|
sendCommand("t0.txt=\"Listening\"");
|
|
|
|
sendCommand("t1.txt=\"\"");
|
|
|
|
}
|
|
|
|
|
2016-04-15 13:35:45 +00:00
|
|
|
void CNextion::writeDMR(unsigned int slotNo, const char* src, bool group, const char* dst, const char* type)
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
2016-04-12 17:26:13 +00:00
|
|
|
assert(src != NULL);
|
2016-04-18 18:54:31 +00:00
|
|
|
assert(dst != NULL);
|
2016-04-06 18:53:25 +00:00
|
|
|
assert(type != NULL);
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
if (m_mode != MODE_DMR) {
|
|
|
|
sendCommand("page DMR");
|
|
|
|
|
|
|
|
if (slotNo == 1U)
|
|
|
|
sendCommand("t2.txt=\"2 Listening\"");
|
|
|
|
else
|
|
|
|
sendCommand("t0.txt=\"1 Listening\"");
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:53:25 +00:00
|
|
|
if (slotNo == 1U) {
|
|
|
|
char text[30U];
|
|
|
|
|
2016-04-12 17:26:13 +00:00
|
|
|
::sprintf(text, "t0.txt=\"1 %s %s\"", type, src);
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
2016-04-15 13:35:45 +00:00
|
|
|
::sprintf(text, "t1.txt=\"%s%s\"", group ? "TG" : "", dst);
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
} else {
|
|
|
|
char text[30U];
|
|
|
|
|
2016-04-12 17:26:13 +00:00
|
|
|
::sprintf(text, "t2.txt=\"2 %s %s\"", type, src);
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
2016-04-15 13:35:45 +00:00
|
|
|
::sprintf(text, "t3.txt=\"%s%s\"", group ? "TG" : "", dst);
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
}
|
2016-04-11 11:21:46 +00:00
|
|
|
|
|
|
|
m_mode = MODE_DMR;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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::writeFusion(const char* source, const char* dest)
|
|
|
|
{
|
|
|
|
assert(source != NULL);
|
|
|
|
assert(dest != NULL);
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
if (m_mode != MODE_YSF)
|
|
|
|
sendCommand("page YSF");
|
|
|
|
|
2016-04-06 18:53:25 +00:00
|
|
|
char text[30U];
|
|
|
|
::sprintf(text, "t0.txt=\"%.10s\"", source);
|
|
|
|
sendCommand(text);
|
|
|
|
|
|
|
|
::sprintf(text, "t1.txt=\"%.10s\"", dest);
|
|
|
|
sendCommand(text);
|
2016-04-11 11:21:46 +00:00
|
|
|
|
|
|
|
m_mode = MODE_YSF;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|