From 35c0a83d379905c41d934413fc413e44595fe0f6 Mon Sep 17 00:00:00 2001 From: Tony Corbett Date: Sat, 28 May 2016 23:29:30 +0300 Subject: [PATCH] Add a clock to the idle screen --- Conf.cpp | 16 +++++++++++++++ Conf.h | 4 ++++ HD44780.cpp | 56 ++++++++++++++++++++++++++++++++++++++------------- HD44780.h | 6 ++++-- MMDVM.ini | 8 ++++++-- MMDVMHost.cpp | 10 +++++++-- 6 files changed, 80 insertions(+), 20 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index fbfd217..12c333a 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -119,6 +119,8 @@ m_hd44780PWM(false), m_hd44780PWMPin(), m_hd44780PWMBright(), m_hd44780PWMDim(), +m_hd44780DisplayClock(false), +m_hd44780UTC(false), m_nextionPort("/dev/ttyAMA0"), m_nextionBrightness(50U), m_oledType(3), @@ -370,6 +372,10 @@ bool CConf::read() m_hd44780PWMBright = (unsigned int)::atoi(value); else if (::strcmp(key, "PWMDim") == 0) m_hd44780PWMDim = (unsigned int)::atoi(value); + else if (::strcmp(key, "DisplayClock") == 0) + m_hd44780DisplayClock = ::atoi(value) == 1; + else if (::strcmp(key, "UTC") == 0) + m_hd44780UTC = ::atoi(value) == 1; else if (::strcmp(key, "Pins") == 0) { char* p = ::strtok(value, ",\r\n"); while (p != NULL) { @@ -754,6 +760,16 @@ unsigned int CConf::getHD44780PWMDim() const return m_hd44780PWMDim; } +bool CConf::getHD44780DisplayClock() const +{ + return m_hd44780DisplayClock; +} + +bool CConf::getHD44780UTC() const +{ + return m_hd44780UTC; +} + std::string CConf::getNextionPort() const { return m_nextionPort; diff --git a/Conf.h b/Conf.h index 3ee3a3e..b74e14e 100644 --- a/Conf.h +++ b/Conf.h @@ -126,6 +126,8 @@ public: unsigned int getHD44780PWMPin() const; unsigned int getHD44780PWMBright() const; unsigned int getHD44780PWMDim() const; + bool getHD44780DisplayClock() const; + bool getHD44780UTC() const; // The Nextion section std::string getNextionPort() const; @@ -221,6 +223,8 @@ private: unsigned int m_hd44780PWMPin; unsigned int m_hd44780PWMBright; unsigned int m_hd44780PWMDim; + bool m_hd44780DisplayClock; + bool m_hd44780UTC; std::string m_nextionPort; unsigned int m_nextionBrightness; diff --git a/HD44780.cpp b/HD44780.cpp index 821d41d..8504eb9 100644 --- a/HD44780.cpp +++ b/HD44780.cpp @@ -31,7 +31,7 @@ const char* LISTENING = "Listening "; const char* DEADSPACE = " "; -CHD44780::CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool duplex) : +CHD44780::CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex) : CDisplay(), m_rows(rows), m_cols(cols), @@ -47,11 +47,13 @@ m_pwm(pwm), m_pwmPin(pwmPin), m_pwmBright(pwmBright), m_pwmDim(pwmDim), +m_displayClock(displayClock), +m_utc(utc), m_duplex(duplex), //m_duplex(true), // uncomment to force duplex display for testing! m_fd(-1), m_dmr(false), -m_timer(1000U, 0U, 250U) // 250ms +m_clockDisplayTimer(1000U, 0U, 75U) // Update the clock display every 75ms { assert(rows > 1U); assert(cols > 15U); @@ -288,6 +290,7 @@ void CHD44780::adafruitLCDColour(ADAFRUIT_COLOUR colour) void CHD44780::setIdleInt() { + m_clockDisplayTimer.start(); // Start the clock display in IDLE only ::lcdClear(m_fd); #ifdef ADAFRUIT_DISPLAY @@ -302,7 +305,9 @@ void CHD44780::setIdleInt() } ::lcdPosition(m_fd, 0, 0); - ::lcdPrintf(m_fd, "%-6s / %u", m_callsign.c_str(), m_dmrid); + ::lcdPrintf(m_fd, "%-6s", m_callsign.c_str()); + ::lcdPosition(m_fd, m_cols - 7, 0); + ::lcdPrintf(m_fd, "%7u", m_dmrid); ::lcdPosition(m_fd, 0, 1); ::lcdPutchar(m_fd, 2); @@ -310,7 +315,8 @@ void CHD44780::setIdleInt() ::lcdPutchar(m_fd, 3); ::lcdPutchar(m_fd, 4); ::lcdPutchar(m_fd, 2); - ::lcdPuts(m_fd, " Idle"); + if (!m_displayClock || m_cols > 16) + ::lcdPuts(m_fd, " Idle"); m_dmr = false; } @@ -323,6 +329,7 @@ void CHD44780::setErrorInt(const char* text) adafruitLCDColour(AC_RED); #endif + m_clockDisplayTimer.stop(); // Stop the clock display ::lcdClear(m_fd); if (m_pwm) { @@ -351,6 +358,7 @@ void CHD44780::setLockoutInt() adafruitLCDColour(AC_RED); #endif + m_clockDisplayTimer.stop(); // Stop the clock display ::lcdClear(m_fd); if (m_pwm) { @@ -385,6 +393,7 @@ void CHD44780::writeDStarInt(const char* my1, const char* my2, const char* your, adafruitLCDColour(AC_RED); #endif + m_clockDisplayTimer.stop(); // Stop the clock display ::lcdClear(m_fd); if (m_pwm) { @@ -448,6 +457,8 @@ void CHD44780::clearDStarInt() adafruitLCDColour(AC_PURPLE); #endif + m_clockDisplayTimer.stop(); // Stop the clock display + if (m_rows == 2U && m_cols == 16U) { ::lcdPosition(m_fd, 0, 1); ::lcdPrintf(m_fd, "%.*s", m_cols, LISTENING); @@ -475,6 +486,7 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro assert(type != NULL); if (!m_dmr) { + m_clockDisplayTimer.stop(); // Stop the clock display ::lcdClear(m_fd); #ifdef ADAFRUIT_DISPLAY @@ -520,8 +532,6 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro ::lcdPosition(m_fd, 0, (m_rows / 2) - 1); ::lcdPuts(m_fd, "1 "); ::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); - - // Thread this out? ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer); if (m_cols > 16) { @@ -536,8 +546,6 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro ::lcdPosition(m_fd, 0, (m_rows / 2)); ::lcdPuts(m_fd, "2 "); ::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); - - // Thread this out? ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer); if (m_cols > 16) { @@ -577,6 +585,7 @@ void CHD44780::clearDMRInt(unsigned int slotNo) adafruitLCDColour(AC_PURPLE); #endif + m_clockDisplayTimer.stop(); // Stop the clock display if (m_duplex) { if (slotNo == 1U) { ::lcdPosition(m_fd, 0, 0); @@ -605,6 +614,7 @@ void CHD44780::writeFusionInt(const char* source, const char* dest, const char* adafruitLCDColour(AC_RED); #endif + m_clockDisplayTimer.stop(); // Stop the clock display ::lcdClear(m_fd); if (m_pwm) { @@ -657,6 +667,8 @@ void CHD44780::clearFusionInt() adafruitLCDColour(AC_PURPLE); #endif + m_clockDisplayTimer.stop(); // Stop the clock display + if (m_rows == 2U && m_cols == 16U) { ::lcdPosition(m_fd, 0, 1); ::lcdPrintf(m_fd, "%.*s", m_cols, LISTENING); @@ -680,13 +692,29 @@ void CHD44780::clearFusionInt() void CHD44780::clockInt(unsigned int ms) { - m_timer.clock(ms); - if (m_timer.isRunning() && m_timer.hasExpired()) { - // Do work every 250ms here + // Update the clock display in IDLE mode every 75ms + m_clockDisplayTimer.clock(ms); + if (m_displayClock && m_clockDisplayTimer.isRunning() && m_clockDisplayTimer.hasExpired()) { + time_t currentTime; + struct tm *Time; + time(¤tTime); // Get the current time - // Start the timer with m_timer.start(); - // and stop it with m_timer.stop(); - m_timer.start(); + 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; + + ::lcdPosition(m_fd, m_cols - 8, 1); + ::lcdPrintf(m_fd, "%02d:%02d:%02d", Hour, Min, Sec); + m_clockDisplayTimer.start(); // restart the clock display timer } } diff --git a/HD44780.h b/HD44780.h index 332a14f..a776413 100644 --- a/HD44780.h +++ b/HD44780.h @@ -53,7 +53,7 @@ enum ADAFRUIT_COLOUR { class CHD44780 : public CDisplay { public: - CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool duplex); + CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex); virtual ~CHD44780(); virtual bool open(); @@ -91,10 +91,12 @@ private: unsigned int m_pwmPin; unsigned int m_pwmBright; unsigned int m_pwmDim; + bool m_displayClock; + bool m_utc; bool m_duplex; int m_fd; bool m_dmr; - CTimer m_timer; + CTimer m_clockDisplayTimer; #ifdef ADAFRUIT_DISPLAY void adafruitLCDSetup(); diff --git a/MMDVM.ini b/MMDVM.ini index 5cb9235..c859b73 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -95,12 +95,16 @@ Pins=11,10,0,1,2,3 # For Adafruit i2c HD44780 # Pins=115,113,112,111,110,109 -# PWM brightness control -PWM=1 +# PWM backlight +PWM=0 PWMPin=21 PWMBright=100 PWMDim=16 +# Display a clock when in IDLE? (HD44780 ONLY!) +DisplayClock=1 +ZuluClock=0 + [Nextion] Port=/dev/ttyAMA0 Brightness=50 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 514605b..c1d047f 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -801,20 +801,26 @@ void CMMDVMHost::createDisplay() unsigned int pwmPin = m_conf.getHD44780PWMPin(); unsigned int pwmBright = m_conf.getHD44780PWMBright(); unsigned int pwmDim = m_conf.getHD44780PWMDim(); + bool displayClock = m_conf.getHD44780DisplayClock(); + bool utc = m_conf.getHD44780UTC(); if (pins.size() == 6U) { LogInfo(" Rows: %u", rows); LogInfo(" Columns: %u", columns); LogInfo(" Pins: %u,%u,%u,%u,%u,%u", pins.at(0U), pins.at(1U), pins.at(2U), pins.at(3U), pins.at(4U), pins.at(5U)); + LogInfo(" PWM Backlight: %s", pwm ? "yes" : "no"); if (pwm) { - LogInfo("PWM Brightness Control Enabled"); LogInfo(" PWM Pin: %u", pwmPin); LogInfo(" PWM Bright: %u", pwmBright); LogInfo(" PWM Dim: %u", pwmDim); } - m_display = new CHD44780(rows, columns, m_callsign, dmrid, pins, pwm, pwmPin, pwmBright, pwmDim, m_duplex); + LogInfo(" Clock Display: %s", displayClock ? "yes" : "no"); + if (displayClock) + LogInfo(" Display UTC: %s", utc ? "yes" : "no"); + + m_display = new CHD44780(rows, columns, m_callsign, dmrid, pins, pwm, pwmPin, pwmBright, pwmDim, displayClock, utc, m_duplex); } #endif #if defined(OLED)