From 35c0a83d379905c41d934413fc413e44595fe0f6 Mon Sep 17 00:00:00 2001 From: Tony Corbett Date: Sat, 28 May 2016 23:29:30 +0300 Subject: [PATCH 1/3] 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) From 124f465a5818734038841e8b13dddd1afcdcaabf Mon Sep 17 00:00:00 2001 From: Tony Corbett Date: Sat, 28 May 2016 23:36:04 +0300 Subject: [PATCH 2/3] Correct MMDVM.ini flag error for UTC clock display --- MMDVM.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMDVM.ini b/MMDVM.ini index c859b73..fc475e7 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -103,7 +103,7 @@ PWMDim=16 # Display a clock when in IDLE? (HD44780 ONLY!) DisplayClock=1 -ZuluClock=0 +UTC=0 [Nextion] Port=/dev/ttyAMA0 From 26fabb2b68945218bc4a39941763f2ee03bb3d9e Mon Sep 17 00:00:00 2001 From: Tony Corbett Date: Sun, 29 May 2016 10:13:43 +0300 Subject: [PATCH 3/3] Impliment clock on all HD44780 sizes and redesigned IDLE screen --- HD44780.cpp | 130 +++++++++++++++++++++++++++--------------------- HD44780.layouts | 58 +++++++++++++++++++++ 2 files changed, 130 insertions(+), 58 deletions(-) create mode 100644 HD44780.layouts diff --git a/HD44780.cpp b/HD44780.cpp index 8504eb9..339a3c8 100644 --- a/HD44780.cpp +++ b/HD44780.cpp @@ -31,6 +31,9 @@ const char* LISTENING = "Listening "; const char* DEADSPACE = " "; +char m_buffer1[128U]; +char m_buffer2[128U]; + 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), @@ -304,19 +307,21 @@ void CHD44780::setIdleInt() ::pwmWrite(m_pwmPin, (m_pwmDim / 100) * 1024); } + // Print callsign and ID at on top row for all screen sizes ::lcdPosition(m_fd, 0, 0); ::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); + // Print MMDVM and Idle on bottom row for all screen sizes + ::lcdPosition(m_fd, 0, m_rows - 1); ::lcdPutchar(m_fd, 2); ::lcdPutchar(m_fd, 2); ::lcdPutchar(m_fd, 3); ::lcdPutchar(m_fd, 4); ::lcdPutchar(m_fd, 2); - if (!m_displayClock || m_cols > 16) - ::lcdPuts(m_fd, " Idle"); + ::lcdPosition(m_fd, m_cols - 4, m_rows - 1); + ::lcdPuts(m_fd, "Idle"); // Gets overwritten by clock on 2 line screen m_dmr = false; } @@ -407,45 +412,45 @@ void CHD44780::writeDStarInt(const char* my1, const char* my2, const char* your, ::lcdPuts(m_fd, "D-Star"); if (m_rows == 2U && m_cols == 16U) { - char buffer[16U]; - ::sprintf(buffer, "%s %.8s/%.4s", type, my1, my2); +// char buffer[16U]; + ::sprintf(m_buffer1, "%s %.8s/%.4s", type, my1, my2); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } else if (m_rows == 4U && m_cols == 16U) { - char buffer[16U]; - ::sprintf(buffer, "%s %.8s/%.4s", type, my1, my2); +// char buffer[16U]; + ::sprintf(m_buffer1, "%s %.8s/%.4s", type, my1, my2); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); if (strcmp(reflector, " ") == 0) - ::sprintf(buffer, "%.8s", your); + ::sprintf(m_buffer1, "%.8s", your); else - ::sprintf(buffer, "%.8s<%.8s", your, reflector); + ::sprintf(m_buffer1, "%.8s<%.8s", your, reflector); ::lcdPosition(m_fd, 0, 2); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } else if (m_rows == 4U && m_cols == 20U) { - char buffer[20U]; - ::sprintf(buffer, "%s %.8s/%.4s >", type, my1, my2); + char m_buffer1[20U]; + ::sprintf(m_buffer1, "%s %.8s/%.4s >", type, my1, my2); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); if (strcmp(reflector, " ") == 0) - ::sprintf(buffer, "%.8s", your); + ::sprintf(m_buffer1, "%.8s", your); else - ::sprintf(buffer, "%.8s <- %.8s", your, reflector); + ::sprintf(m_buffer1, "%.8s <- %.8s", your, reflector); ::lcdPosition(m_fd, 0, 2); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } else if (m_rows == 2 && m_cols == 40U) { - char buffer[40U]; + char m_buffer1[40U]; if (strcmp(reflector, " ") == 0) - ::sprintf(buffer, "%s %.8s/%.4s > %.8s", type, my1, my2, your); + ::sprintf(m_buffer1, "%s %.8s/%.4s > %.8s", type, my1, my2, your); else - ::sprintf(buffer, "%s %.8s/%.4s > %.8s via %.8s", type, my1, my2, your, reflector); + ::sprintf(m_buffer1, "%s %.8s/%.4s > %.8s via %.8s", type, my1, my2, your, reflector); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } m_dmr = false; @@ -482,7 +487,7 @@ void CHD44780::clearDStarInt() void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type) { - char buffer[128]; // force 128 char buffer - we're never getting that far but stops us overflowing it! +// char buffer[128]; // force 128 char buffer - we're never getting that far but stops us overflowing it! assert(type != NULL); if (!m_dmr) { @@ -503,8 +508,8 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro if (m_duplex) { if (m_rows > 2U) { ::lcdPosition(m_fd, 0, (m_rows / 2) - 2); - ::sprintf(buffer, "%s%s", "DMR", DEADSPACE); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::sprintf(m_buffer1, "%s%s", "DMR", DEADSPACE); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } if (slotNo == 1U) { @@ -516,8 +521,8 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro } } else { ::lcdPosition(m_fd, 0, (m_rows / 2) - 1); - ::sprintf(buffer, "%s%s", "DMR", DEADSPACE); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::sprintf(m_buffer1, "%s%s", "DMR", DEADSPACE); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); ::lcdPosition(m_fd, 0, (m_rows / 2)); ::lcdPrintf(m_fd, "%.*s", m_cols, LISTENING); } @@ -531,8 +536,8 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro if (slotNo == 1U) { ::lcdPosition(m_fd, 0, (m_rows / 2) - 1); ::lcdPuts(m_fd, "1 "); - ::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); - ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer); + ::sprintf(m_buffer1, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); + ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, m_buffer1); if (m_cols > 16) { ::lcdCharDef(m_fd, 6, group ? tgChar : privChar); @@ -545,8 +550,8 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro } else { ::lcdPosition(m_fd, 0, (m_rows / 2)); ::lcdPuts(m_fd, "2 "); - ::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); - ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer); + ::sprintf(m_buffer2, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); + ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, m_buffer2); if (m_cols > 16) { ::lcdCharDef(m_fd, 6, group ? tgChar : privChar); @@ -560,16 +565,16 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro } else { ::lcdPosition(m_fd, 0, (m_rows / 2) - 1); ::lcdPutchar(m_fd, 0); - ::sprintf(buffer, " %s%s", src.c_str(), DEADSPACE); - ::lcdPrintf(m_fd, "%.*s", m_cols - 4U, buffer); + ::sprintf(m_buffer2, " %s%s", src.c_str(), DEADSPACE); + ::lcdPrintf(m_fd, "%.*s", m_cols - 4U, m_buffer2); ::lcdCharDef(m_fd, 5, strcmp(type, "R") == 0 ? rfChar : ipChar); ::lcdPosition(m_fd, m_cols - 1U, (m_rows / 2) - 1); ::lcdPutchar(m_fd, 5); ::lcdPosition(m_fd, 0, (m_rows / 2)); ::lcdPutchar(m_fd, 1); - ::sprintf(buffer, " %s%s", dst.c_str(), DEADSPACE); - ::lcdPrintf(m_fd, "%.*s", m_cols - 4U, buffer); + ::sprintf(m_buffer2, " %s%s", dst.c_str(), DEADSPACE); + ::lcdPrintf(m_fd, "%.*s", m_cols - 4U, m_buffer2); ::lcdCharDef(m_fd, 6, group ? tgChar : privChar); ::lcdPosition(m_fd, m_cols - 1U, (m_rows / 2)); ::lcdPutchar(m_fd, 6); @@ -579,7 +584,7 @@ void CHD44780::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro void CHD44780::clearDMRInt(unsigned int slotNo) { - char buffer[128]; // force 128 char buffer - we're never getting that far but stops us overflowing it! +// char buffer[128]; // force 128 char buffer - we're never getting that far but stops us overflowing it! #ifdef ADAFRUIT_DISPLAY adafruitLCDColour(AC_PURPLE); @@ -596,8 +601,8 @@ void CHD44780::clearDMRInt(unsigned int slotNo) } } else { ::lcdPosition(m_fd, 0, (m_rows / 2) - 1); - ::sprintf(buffer, "%s%s", "DMR", DEADSPACE); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::sprintf(m_buffer2, "%s%s", "DMR", DEADSPACE); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer2); ::lcdPosition(m_fd, 0, (m_rows / 2)); ::lcdPrintf(m_fd, "%.*s", m_cols, LISTENING); } @@ -628,34 +633,34 @@ void CHD44780::writeFusionInt(const char* source, const char* dest, const char* ::lcdPuts(m_fd, "System Fusion"); if (m_rows == 2U && m_cols == 16U) { - char buffer[16U]; - ::sprintf(buffer, "%.10s >", source); + char m_buffer1[16U]; + ::sprintf(m_buffer1, "%.10s >", source); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } else if (m_rows == 4U && m_cols == 16U) { - char buffer[16U]; - ::sprintf(buffer, "%.10s >", source); + char m_buffer1[16U]; + ::sprintf(m_buffer1, "%.10s >", source); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); - ::sprintf(buffer, "%.10s", dest); + ::sprintf(m_buffer1, "%.10s", dest); ::lcdPosition(m_fd, 0, 2); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } else if (m_rows == 4U && m_cols == 20U) { - char buffer[20U]; - ::sprintf(buffer, "%.10s >", source); + char m_buffer1[20U]; + ::sprintf(m_buffer1, "%.10s >", source); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); - ::sprintf(buffer, "%.10s", dest); + ::sprintf(m_buffer1, "%.10s", dest); ::lcdPosition(m_fd, 0, 2); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } else if (m_rows == 2 && m_cols == 40U) { - char buffer[40U]; - ::sprintf(buffer, "%.10s > %.10s", source, dest); + char m_buffer1[40U]; + ::sprintf(m_buffer1, "%.10s > %.10s", source, dest); ::lcdPosition(m_fd, 0, 1); - ::lcdPrintf(m_fd, "%.*s", m_cols, buffer); + ::lcdPrintf(m_fd, "%.*s", m_cols, m_buffer1); } m_dmr = false; @@ -705,15 +710,24 @@ void CHD44780::clockInt(unsigned int ms) Time = localtime(¤tTime); } - //int Day = Time->tm_mday; - //int Month = Time->tm_mon + 1; - //int Year = Time->tm_year + 1900; + 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); + if (m_cols == 16U && m_rows == 2U) { + ::lcdPosition(m_fd, m_cols - 8, 1); + } else { + ::lcdPosition(m_fd, (m_cols - 8) / 2, m_rows == 2 ? 1 : 2); + } ::lcdPrintf(m_fd, "%02d:%02d:%02d", Hour, Min, Sec); + + if (m_cols != 16U && m_rows != 2U) { + ::lcdPosition(m_fd, (m_cols - 8) / 2, m_rows == 2 ? 0 : 1); + ::lcdPrintf(m_fd, "%02d/%02d/%2d", Day, Month, Year%100); + } m_clockDisplayTimer.start(); // restart the clock display timer } } diff --git a/HD44780.layouts b/HD44780.layouts new file mode 100644 index 0000000..03560cf --- /dev/null +++ b/HD44780.layouts @@ -0,0 +1,58 @@ +IDLE SCREEN LAYOUTS +------------------- + +16 x 2 +------ + + With clock Without clock + ---------- ------------- + + 0 1 0 1 + 0123456789012345 0123456789012345 + +----------------+ +----------------+ +0|AAAAAA NNNNNNN| 0|AAAAAA NNNNNNN| +1|MMDVM HH:MM:SS| 1|MMDVM Idle| + +----------------+ +----------------+ + +40 x 2 +------ + + With clock Without clock + ---------- ------------- + + 0 1 2 3 0 1 2 3 + 0123456789012345678901234567890123456789 0123456789012345678901234567890123456789 + +----------------------------------------+ +----------------------------------------+ +0|AAAAAA DD/MM/YY NNNNNNN| 0|AAAAAA NNNNNNN| +1|MMDVM HH:MM:SS Idle| 1|MMDVM Idle| + +----------------------------------------+ +----------------------------------------+ + +16 x 4 +------ + + With clock Without clock + ---------- ------------- + + 0 1 0 1 + 0123456789012345 0123456789012345 + +----------------+ +----------------+ +0|AAAAAA NNNNNNN| 0|AAAAAA NNNNNNN| +1| DD/MM/YY | 1| | +2| HH:MM:SS | 2| | +3|MMDVM Idle| 3|MMDVM Idle| + +----------------+ +----------------+ + +20 x 4 +------ + + With clock Without clock + ---------- ------------- + + 0 1 0 1 + 01234567890123456479 01234567890123456789 + +--------------------+ +--------------------+ +0|AAAAAA NNNNNNN| 0|AAAAAA NNNNNNN| +1| DD/MM/YY | 1| | +2| HH:MM:SS | 2| | +3|MMDVM Idle| 3|MMDVM Idle| + +--------------------+ +--------------------+