Add the idle clock to the Nextion display.

This commit is contained in:
Jonathan Naylor 2016-06-01 11:55:24 +01:00
parent ed8ea92468
commit dad34ada69
6 changed files with 86 additions and 11 deletions

View File

@ -123,6 +123,8 @@ m_hd44780DisplayClock(false),
m_hd44780UTC(false),
m_nextionPort("/dev/ttyAMA0"),
m_nextionBrightness(50U),
m_nextionDisplayClock(false),
m_nextionUTC(false),
m_oledType(3),
m_oledBrightness(0),
m_oledInvert(0)
@ -389,6 +391,10 @@ bool CConf::read()
m_nextionPort = value;
else if (::strcmp(key, "Brightness") == 0)
m_nextionBrightness = (unsigned int)::atoi(value);
else if (::strcmp(key, "DisplayClock") == 0)
m_nextionDisplayClock = ::atoi(value) == 1;
else if (::strcmp(key, "UTC") == 0)
m_nextionUTC = ::atoi(value) == 1;
} else if (section == SECTION_OLED) {
if (::strcmp(key, "Type") == 0)
m_oledType = (unsigned char)::atoi(value);
@ -780,6 +786,16 @@ unsigned int CConf::getNextionBrightness() const
return m_nextionBrightness;
}
bool CConf::getNextionDisplayClock() const
{
return m_nextionDisplayClock;
}
bool CConf::getNextionUTC() const
{
return m_nextionUTC;
}
unsigned char CConf::getOLEDType() const
{
return m_oledType;

12
Conf.h
View File

@ -126,12 +126,14 @@ public:
unsigned int getHD44780PWMPin() const;
unsigned int getHD44780PWMBright() const;
unsigned int getHD44780PWMDim() const;
bool getHD44780DisplayClock() const;
bool getHD44780UTC() const;
bool getHD44780DisplayClock() const;
bool getHD44780UTC() const;
// The Nextion section
std::string getNextionPort() const;
unsigned int getNextionBrightness() const;
bool getNextionDisplayClock() const;
bool getNextionUTC() const;
// The OLED section
unsigned char getOLEDType() const;
@ -223,11 +225,13 @@ private:
unsigned int m_hd44780PWMPin;
unsigned int m_hd44780PWMBright;
unsigned int m_hd44780PWMDim;
bool m_hd44780DisplayClock;
bool m_hd44780UTC;
bool m_hd44780DisplayClock;
bool m_hd44780UTC;
std::string m_nextionPort;
unsigned int m_nextionBrightness;
bool m_nextionDisplayClock;
bool m_nextionUTC;
unsigned char m_oledType;
unsigned char m_oledBrightness;

View File

@ -100,17 +100,16 @@ PWM=0
PWMPin=21
PWMBright=100
PWMDim=16
# Display a clock when in IDLE? (HD44780 ONLY!)
DisplayClock=1
UTC=0
[Nextion]
Port=/dev/ttyAMA0
Brightness=50
DisplayClock=1
UTC=0
[OLED]
Type=3
Brightness=0
Invert=0

View File

@ -787,11 +787,16 @@ void CMMDVMHost::createDisplay()
} else if (type == "Nextion") {
std::string port = m_conf.getNextionPort();
unsigned int brightness = m_conf.getNextionBrightness();
bool displayClock = m_conf.getNextionDisplayClock();
bool utc = m_conf.getNextionUTC();
LogInfo(" Port: %s", port.c_str());
LogInfo(" Brightness: %u", brightness);
LogInfo(" Clock Display: %s", displayClock ? "yes" : "no");
if (displayClock)
LogInfo(" Display UTC: %s", utc ? "yes" : "no");
m_display = new CNextion(m_callsign, dmrid, port, brightness);
m_display = new CNextion(m_callsign, dmrid, port, brightness, displayClock, utc);
#if defined(HD44780)
} else if (type == "HD44780") {
unsigned int rows = m_conf.getHD44780Rows();

View File

@ -22,14 +22,18 @@
#include <cstdio>
#include <cassert>
#include <cstring>
#include <ctime>
CNextion::CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness) :
CNextion::CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc) :
CDisplay(),
m_callsign(callsign),
m_dmrid(dmrid),
m_serial(port, SERIAL_9600),
m_brightness(brightness),
m_mode(MODE_IDLE)
m_mode(MODE_IDLE),
m_displayClock(displayClock),
m_utc(utc),
m_clockDisplayTimer(1000U, 0U, 400U)
{
assert(brightness >= 0U && brightness <= 100U);
}
@ -67,6 +71,8 @@ void CNextion::setIdleInt()
sendCommand(command);
sendCommand("t1.txt=\"MMDVM IDLE\"");
m_clockDisplayTimer.start();
m_mode = MODE_IDLE;
}
@ -82,6 +88,8 @@ void CNextion::setErrorInt(const char* text)
sendCommand(command);
sendCommand("t1.txt=\"ERROR\"");
m_clockDisplayTimer.stop();
m_mode = MODE_ERROR;
}
@ -91,6 +99,8 @@ void CNextion::setLockoutInt()
sendCommand("t0.txt=\"LOCKOUT\"");
m_clockDisplayTimer.stop();
m_mode = MODE_LOCKOUT;
}
@ -117,6 +127,8 @@ void CNextion::writeDStarInt(const char* my1, const char* my2, const char* your,
sendCommand(text);
}
m_clockDisplayTimer.stop();
m_mode = MODE_DSTAR;
}
@ -158,6 +170,8 @@ void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro
sendCommand(text);
}
m_clockDisplayTimer.stop();
m_mode = MODE_DMR;
}
@ -193,6 +207,8 @@ void CNextion::writeFusionInt(const char* source, const char* dest, const char*
sendCommand(text);
}
m_clockDisplayTimer.stop();
m_mode = MODE_YSF;
}
@ -203,6 +219,35 @@ void CNextion::clearFusionInt()
sendCommand("t2.txt=\"\"");
}
void CNextion::clockInt(unsigned int ms)
{
// Update the clock display in IDLE mode every 400ms
m_clockDisplayTimer.clock(ms);
if (m_displayClock && m_mode == MODE_IDLE && m_clockDisplayTimer.isRunning() && m_clockDisplayTimer.hasExpired()) {
time_t currentTime;
struct tm *Time;
::time(&currentTime); // Get the current time
if (m_utc)
Time = ::gmtime(&currentTime);
else
Time = ::localtime(&currentTime);
int Day = Time->tm_mday;
int Month = Time->tm_mon + 1;
int Year = Time->tm_year + 1900;
int Hour = Time->tm_hour;
int Min = Time->tm_min;
int Sec = Time->tm_sec;
char text[50U];
::sprintf(text, "t2.txt=\"%02d:%02d:%02d %02d/%02d/%2d\"", Hour, Min, Sec, Day, Month, Year % 100);
sendCommand(text);
m_clockDisplayTimer.start(); // restart the clock display timer
}
}
void CNextion::close()
{
m_serial.close();

View File

@ -22,13 +22,14 @@
#include "Display.h"
#include "Defines.h"
#include "SerialController.h"
#include "Timer.h"
#include <string>
class CNextion : public CDisplay
{
public:
CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness);
CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc);
virtual ~CNextion();
virtual bool open();
@ -49,12 +50,17 @@ protected:
virtual void writeFusionInt(const char* source, const char* dest, const char* type, const char* origin);
virtual void clearFusionInt();
virtual void clockInt(unsigned int ms);
private:
std::string m_callsign;
unsigned int m_dmrid;
CSerialController m_serial;
unsigned int m_brightness;
unsigned char m_mode;
bool m_displayClock;
bool m_utc;
CTimer m_clockDisplayTimer;
void sendCommand(const char* command);
};