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-06-01 10:55:24 +00:00
|
|
|
#include <ctime>
|
2016-09-09 09:42:01 +00:00
|
|
|
#include <clocale>
|
2016-04-06 18:53:25 +00:00
|
|
|
|
2016-06-24 15:08:28 +00:00
|
|
|
CNextion::CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness) :
|
2016-05-09 17:14:27 +00:00
|
|
|
CDisplay(),
|
2016-04-08 11:47:05 +00:00
|
|
|
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),
|
2016-06-01 10:55:24 +00:00
|
|
|
m_mode(MODE_IDLE),
|
|
|
|
m_displayClock(displayClock),
|
|
|
|
m_utc(utc),
|
2016-06-24 09:33:28 +00:00
|
|
|
m_idleBrightness(idleBrightness),
|
2016-06-01 10:55:24 +00:00
|
|
|
m_clockDisplayTimer(1000U, 0U, 400U)
|
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");
|
|
|
|
|
|
|
|
setIdle();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::setIdleInt()
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
sendCommand("page MMDVM");
|
|
|
|
|
2016-04-08 11:47:05 +00:00
|
|
|
char command[30];
|
2016-06-24 09:33:28 +00:00
|
|
|
::sprintf(command, "dim=%u", m_idleBrightness);
|
2016-06-24 07:30:46 +00:00
|
|
|
sendCommand(command);
|
|
|
|
|
2016-04-20 19:23:51 +00:00
|
|
|
::sprintf(command, "t0.txt=\"%-6s / %u\"", m_callsign.c_str(), m_dmrid);
|
2016-04-08 11:47:05 +00:00
|
|
|
|
|
|
|
sendCommand(command);
|
|
|
|
sendCommand("t1.txt=\"MMDVM IDLE\"");
|
2016-04-11 11:21:46 +00:00
|
|
|
|
2016-06-01 10:55:24 +00:00
|
|
|
m_clockDisplayTimer.start();
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
m_mode = MODE_IDLE;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::setErrorInt(const char* text)
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
assert(text != NULL);
|
|
|
|
|
|
|
|
sendCommand("page MMDVM");
|
|
|
|
|
|
|
|
char command[20];
|
2016-06-24 07:30:46 +00:00
|
|
|
::sprintf(command, "dim=%u", m_brightness);
|
|
|
|
sendCommand(command);
|
|
|
|
|
2016-04-06 18:53:25 +00:00
|
|
|
::sprintf(command, "t0.txt=\"%s\"", text);
|
|
|
|
|
|
|
|
sendCommand(command);
|
|
|
|
sendCommand("t1.txt=\"ERROR\"");
|
2016-04-11 11:21:46 +00:00
|
|
|
|
2016-06-01 10:55:24 +00:00
|
|
|
m_clockDisplayTimer.stop();
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
m_mode = MODE_ERROR;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::setLockoutInt()
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
sendCommand("page MMDVM");
|
|
|
|
|
2016-06-24 07:30:46 +00:00
|
|
|
char command[20];
|
|
|
|
::sprintf(command, "dim=%u", m_brightness);
|
|
|
|
sendCommand(command);
|
|
|
|
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand("t0.txt=\"LOCKOUT\"");
|
|
|
|
|
2016-06-01 10:55:24 +00:00
|
|
|
m_clockDisplayTimer.stop();
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
m_mode = MODE_LOCKOUT;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::writeDStarInt(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-06-24 07:30:46 +00:00
|
|
|
::sprintf(text, "dim=%u", m_brightness);
|
|
|
|
sendCommand(text);
|
|
|
|
|
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-05-23 17:36:53 +00:00
|
|
|
::sprintf(text, "t1.txt=\"%.8s\"", your);
|
|
|
|
sendCommand(text);
|
|
|
|
|
|
|
|
if (::strcmp(reflector, " ") != 0) {
|
|
|
|
::sprintf(text, "t2.txt=\"via %.8s\"", reflector);
|
2016-04-27 19:48:20 +00:00
|
|
|
sendCommand(text);
|
2016-04-16 20:20:18 +00:00
|
|
|
}
|
2016-04-11 11:21:46 +00:00
|
|
|
|
2016-06-01 10:55:24 +00:00
|
|
|
m_clockDisplayTimer.stop();
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
m_mode = MODE_DSTAR;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::clearDStarInt()
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
sendCommand("t0.txt=\"Listening\"");
|
|
|
|
sendCommand("t1.txt=\"\"");
|
2016-05-23 17:36:53 +00:00
|
|
|
sendCommand("t2.txt=\"\"");
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type)
|
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-06-24 07:30:46 +00:00
|
|
|
char text[30U];
|
|
|
|
::sprintf(text, "dim=%u", m_brightness);
|
|
|
|
sendCommand(text);
|
2016-04-06 18:53:25 +00:00
|
|
|
|
2016-06-24 07:30:46 +00:00
|
|
|
if (slotNo == 1U) {
|
2016-04-21 12:01:53 +00:00
|
|
|
::sprintf(text, "t0.txt=\"1 %s %s\"", type, src.c_str());
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
2016-04-21 12:01:53 +00:00
|
|
|
::sprintf(text, "t1.txt=\"%s%s\"", group ? "TG" : "", dst.c_str());
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
} else {
|
2016-04-21 12:01:53 +00:00
|
|
|
::sprintf(text, "t2.txt=\"2 %s %s\"", type, src.c_str());
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
2016-04-21 12:01:53 +00:00
|
|
|
::sprintf(text, "t3.txt=\"%s%s\"", group ? "TG" : "", dst.c_str());
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
}
|
2016-04-11 11:21:46 +00:00
|
|
|
|
2016-06-01 10:55:24 +00:00
|
|
|
m_clockDisplayTimer.stop();
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
m_mode = MODE_DMR;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::clearDMRInt(unsigned int slotNo)
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
if (slotNo == 1U) {
|
|
|
|
sendCommand("t0.txt=\"1 Listening\"");
|
|
|
|
sendCommand("t1.txt=\"\"");
|
|
|
|
} else {
|
|
|
|
sendCommand("t2.txt=\"2 Listening\"");
|
|
|
|
sendCommand("t3.txt=\"\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 18:08:48 +00:00
|
|
|
void CNextion::writeFusionInt(const char* source, const char* dest, const char* type, const char* origin)
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
assert(source != NULL);
|
|
|
|
assert(dest != NULL);
|
2016-05-16 20:57:32 +00:00
|
|
|
assert(type != NULL);
|
2016-05-19 18:08:48 +00:00
|
|
|
assert(origin != NULL);
|
2016-04-06 18:53:25 +00:00
|
|
|
|
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];
|
2016-06-24 07:30:46 +00:00
|
|
|
::sprintf(text, "dim=%u", m_brightness);
|
|
|
|
sendCommand(text);
|
|
|
|
|
2016-05-16 20:57:32 +00:00
|
|
|
::sprintf(text, "t0.txt=\"%s %.10s\"", type, source);
|
2016-04-06 18:53:25 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
2016-05-21 11:52:56 +00:00
|
|
|
::sprintf(text, "t1.txt=\"%.10s\"", dest);
|
|
|
|
sendCommand(text);
|
|
|
|
if (::strcmp(origin, " ") != 0) {
|
2016-05-23 17:04:17 +00:00
|
|
|
::sprintf(text, "t2.txt=\"at %.10s\"", origin);
|
2016-05-19 18:08:48 +00:00
|
|
|
sendCommand(text);
|
|
|
|
}
|
2016-04-11 11:21:46 +00:00
|
|
|
|
2016-06-01 10:55:24 +00:00
|
|
|
m_clockDisplayTimer.stop();
|
|
|
|
|
2016-04-11 11:21:46 +00:00
|
|
|
m_mode = MODE_YSF;
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 17:14:27 +00:00
|
|
|
void CNextion::clearFusionInt()
|
2016-04-06 18:53:25 +00:00
|
|
|
{
|
|
|
|
sendCommand("t0.txt=\"Listening\"");
|
|
|
|
sendCommand("t1.txt=\"\"");
|
2016-05-21 11:52:56 +00:00
|
|
|
sendCommand("t2.txt=\"\"");
|
2016-04-06 18:53:25 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 19:23:50 +00:00
|
|
|
void CNextion::writeP25Int(const char* source, bool group, unsigned int dest, const char* type)
|
2016-09-12 17:12:32 +00:00
|
|
|
{
|
|
|
|
assert(source != NULL);
|
|
|
|
assert(type != NULL);
|
|
|
|
|
|
|
|
if (m_mode != MODE_P25)
|
|
|
|
sendCommand("page P25");
|
|
|
|
|
|
|
|
char text[30U];
|
|
|
|
::sprintf(text, "dim=%u", m_brightness);
|
|
|
|
sendCommand(text);
|
|
|
|
|
|
|
|
::sprintf(text, "t0.txt=\"%s %.10s\"", type, source);
|
|
|
|
sendCommand(text);
|
|
|
|
|
2016-09-12 19:23:50 +00:00
|
|
|
::sprintf(text, "t1.txt=\"%s%u\"", group ? "TG" : "", dest);
|
2016-09-12 17:12:32 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
|
|
|
m_clockDisplayTimer.stop();
|
|
|
|
|
|
|
|
m_mode = MODE_P25;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNextion::clearP25Int()
|
|
|
|
{
|
|
|
|
sendCommand("t0.txt=\"Listening\"");
|
|
|
|
sendCommand("t1.txt=\"\"");
|
|
|
|
sendCommand("t2.txt=\"\"");
|
|
|
|
}
|
|
|
|
|
2016-09-15 08:58:55 +00:00
|
|
|
void CNextion::writeCWInt()
|
2016-09-15 08:44:21 +00:00
|
|
|
{
|
2016-09-15 14:28:56 +00:00
|
|
|
sendCommand("t1.txt=\"Sending CW Ident\"");
|
2016-09-15 13:17:51 +00:00
|
|
|
|
2016-09-15 14:57:10 +00:00
|
|
|
m_clockDisplayTimer.start();
|
2016-09-15 13:17:51 +00:00
|
|
|
|
|
|
|
m_mode = MODE_CW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNextion::clearCWInt()
|
|
|
|
{
|
2016-09-15 14:27:06 +00:00
|
|
|
sendCommand("t1.txt=\"MMDVM IDLE\"");
|
2016-09-15 08:44:21 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 10:55:24 +00:00
|
|
|
void CNextion::clockInt(unsigned int ms)
|
|
|
|
{
|
|
|
|
// Update the clock display in IDLE mode every 400ms
|
|
|
|
m_clockDisplayTimer.clock(ms);
|
2016-09-15 14:57:10 +00:00
|
|
|
if (m_displayClock && (m_mode == MODE_IDLE || m_mode == MODE_CW) && m_clockDisplayTimer.isRunning() && m_clockDisplayTimer.hasExpired()) {
|
2016-06-01 10:55:24 +00:00
|
|
|
time_t currentTime;
|
|
|
|
struct tm *Time;
|
|
|
|
::time(¤tTime); // Get the current time
|
|
|
|
|
|
|
|
if (m_utc)
|
|
|
|
Time = ::gmtime(¤tTime);
|
|
|
|
else
|
|
|
|
Time = ::localtime(¤tTime);
|
|
|
|
|
2016-07-02 23:14:31 +00:00
|
|
|
setlocale(LC_TIME,"");
|
2016-06-01 10:55:24 +00:00
|
|
|
char text[50U];
|
2016-06-24 15:08:28 +00:00
|
|
|
strftime(text, 50, "t2.txt=\"%x %X\"", Time);
|
2016-06-01 10:55:24 +00:00
|
|
|
sendCommand(text);
|
|
|
|
|
|
|
|
m_clockDisplayTimer.start(); // restart the clock display timer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:53:25 +00:00
|
|
|
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);
|
|
|
|
}
|