diff --git a/Conf.cpp b/Conf.cpp index 12c333a..4735f75 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -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; diff --git a/Conf.h b/Conf.h index b74e14e..5f0a359 100644 --- a/Conf.h +++ b/Conf.h @@ -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; diff --git a/MMDVM.ini b/MMDVM.ini index fc475e7..a92d104 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -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 - diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index c1d047f..954c2bf 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -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(); diff --git a/Nextion.cpp b/Nextion.cpp index a3e777c..4cc22f8 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -22,14 +22,18 @@ #include #include #include +#include -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(¤tTime); // Get the current time + + if (m_utc) + Time = ::gmtime(¤tTime); + else + Time = ::localtime(¤tTime); + + 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(); diff --git a/Nextion.h b/Nextion.h index 86667e6..319b23d 100644 --- a/Nextion.h +++ b/Nextion.h @@ -22,13 +22,14 @@ #include "Display.h" #include "Defines.h" #include "SerialController.h" +#include "Timer.h" #include 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); };