Add a clock to the idle screen

This commit is contained in:
Tony Corbett
2016-05-28 23:29:30 +03:00
parent 9dfba5095c
commit 35c0a83d37
6 changed files with 80 additions and 20 deletions

View File

@@ -119,6 +119,8 @@ m_hd44780PWM(false),
m_hd44780PWMPin(), m_hd44780PWMPin(),
m_hd44780PWMBright(), m_hd44780PWMBright(),
m_hd44780PWMDim(), m_hd44780PWMDim(),
m_hd44780DisplayClock(false),
m_hd44780UTC(false),
m_nextionPort("/dev/ttyAMA0"), m_nextionPort("/dev/ttyAMA0"),
m_nextionBrightness(50U), m_nextionBrightness(50U),
m_oledType(3), m_oledType(3),
@@ -370,6 +372,10 @@ bool CConf::read()
m_hd44780PWMBright = (unsigned int)::atoi(value); m_hd44780PWMBright = (unsigned int)::atoi(value);
else if (::strcmp(key, "PWMDim") == 0) else if (::strcmp(key, "PWMDim") == 0)
m_hd44780PWMDim = (unsigned int)::atoi(value); 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) { else if (::strcmp(key, "Pins") == 0) {
char* p = ::strtok(value, ",\r\n"); char* p = ::strtok(value, ",\r\n");
while (p != NULL) { while (p != NULL) {
@@ -754,6 +760,16 @@ unsigned int CConf::getHD44780PWMDim() const
return m_hd44780PWMDim; return m_hd44780PWMDim;
} }
bool CConf::getHD44780DisplayClock() const
{
return m_hd44780DisplayClock;
}
bool CConf::getHD44780UTC() const
{
return m_hd44780UTC;
}
std::string CConf::getNextionPort() const std::string CConf::getNextionPort() const
{ {
return m_nextionPort; return m_nextionPort;

4
Conf.h
View File

@@ -126,6 +126,8 @@ public:
unsigned int getHD44780PWMPin() const; unsigned int getHD44780PWMPin() const;
unsigned int getHD44780PWMBright() const; unsigned int getHD44780PWMBright() const;
unsigned int getHD44780PWMDim() const; unsigned int getHD44780PWMDim() const;
bool getHD44780DisplayClock() const;
bool getHD44780UTC() const;
// The Nextion section // The Nextion section
std::string getNextionPort() const; std::string getNextionPort() const;
@@ -221,6 +223,8 @@ private:
unsigned int m_hd44780PWMPin; unsigned int m_hd44780PWMPin;
unsigned int m_hd44780PWMBright; unsigned int m_hd44780PWMBright;
unsigned int m_hd44780PWMDim; unsigned int m_hd44780PWMDim;
bool m_hd44780DisplayClock;
bool m_hd44780UTC;
std::string m_nextionPort; std::string m_nextionPort;
unsigned int m_nextionBrightness; unsigned int m_nextionBrightness;

View File

@@ -31,7 +31,7 @@
const char* LISTENING = "Listening "; const char* LISTENING = "Listening ";
const char* DEADSPACE = " "; const char* DEADSPACE = " ";
CHD44780::CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector<unsigned int>& 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<unsigned int>& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex) :
CDisplay(), CDisplay(),
m_rows(rows), m_rows(rows),
m_cols(cols), m_cols(cols),
@@ -47,11 +47,13 @@ m_pwm(pwm),
m_pwmPin(pwmPin), m_pwmPin(pwmPin),
m_pwmBright(pwmBright), m_pwmBright(pwmBright),
m_pwmDim(pwmDim), m_pwmDim(pwmDim),
m_displayClock(displayClock),
m_utc(utc),
m_duplex(duplex), m_duplex(duplex),
//m_duplex(true), // uncomment to force duplex display for testing! //m_duplex(true), // uncomment to force duplex display for testing!
m_fd(-1), m_fd(-1),
m_dmr(false), m_dmr(false),
m_timer(1000U, 0U, 250U) // 250ms m_clockDisplayTimer(1000U, 0U, 75U) // Update the clock display every 75ms
{ {
assert(rows > 1U); assert(rows > 1U);
assert(cols > 15U); assert(cols > 15U);
@@ -288,6 +290,7 @@ void CHD44780::adafruitLCDColour(ADAFRUIT_COLOUR colour)
void CHD44780::setIdleInt() void CHD44780::setIdleInt()
{ {
m_clockDisplayTimer.start(); // Start the clock display in IDLE only
::lcdClear(m_fd); ::lcdClear(m_fd);
#ifdef ADAFRUIT_DISPLAY #ifdef ADAFRUIT_DISPLAY
@@ -302,7 +305,9 @@ void CHD44780::setIdleInt()
} }
::lcdPosition(m_fd, 0, 0); ::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); ::lcdPosition(m_fd, 0, 1);
::lcdPutchar(m_fd, 2); ::lcdPutchar(m_fd, 2);
@@ -310,7 +315,8 @@ void CHD44780::setIdleInt()
::lcdPutchar(m_fd, 3); ::lcdPutchar(m_fd, 3);
::lcdPutchar(m_fd, 4); ::lcdPutchar(m_fd, 4);
::lcdPutchar(m_fd, 2); ::lcdPutchar(m_fd, 2);
::lcdPuts(m_fd, " Idle"); if (!m_displayClock || m_cols > 16)
::lcdPuts(m_fd, " Idle");
m_dmr = false; m_dmr = false;
} }
@@ -323,6 +329,7 @@ void CHD44780::setErrorInt(const char* text)
adafruitLCDColour(AC_RED); adafruitLCDColour(AC_RED);
#endif #endif
m_clockDisplayTimer.stop(); // Stop the clock display
::lcdClear(m_fd); ::lcdClear(m_fd);
if (m_pwm) { if (m_pwm) {
@@ -351,6 +358,7 @@ void CHD44780::setLockoutInt()
adafruitLCDColour(AC_RED); adafruitLCDColour(AC_RED);
#endif #endif
m_clockDisplayTimer.stop(); // Stop the clock display
::lcdClear(m_fd); ::lcdClear(m_fd);
if (m_pwm) { if (m_pwm) {
@@ -385,6 +393,7 @@ void CHD44780::writeDStarInt(const char* my1, const char* my2, const char* your,
adafruitLCDColour(AC_RED); adafruitLCDColour(AC_RED);
#endif #endif
m_clockDisplayTimer.stop(); // Stop the clock display
::lcdClear(m_fd); ::lcdClear(m_fd);
if (m_pwm) { if (m_pwm) {
@@ -448,6 +457,8 @@ void CHD44780::clearDStarInt()
adafruitLCDColour(AC_PURPLE); adafruitLCDColour(AC_PURPLE);
#endif #endif
m_clockDisplayTimer.stop(); // Stop the clock display
if (m_rows == 2U && m_cols == 16U) { if (m_rows == 2U && m_cols == 16U) {
::lcdPosition(m_fd, 0, 1); ::lcdPosition(m_fd, 0, 1);
::lcdPrintf(m_fd, "%.*s", m_cols, LISTENING); ::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); assert(type != NULL);
if (!m_dmr) { if (!m_dmr) {
m_clockDisplayTimer.stop(); // Stop the clock display
::lcdClear(m_fd); ::lcdClear(m_fd);
#ifdef ADAFRUIT_DISPLAY #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); ::lcdPosition(m_fd, 0, (m_rows / 2) - 1);
::lcdPuts(m_fd, "1 "); ::lcdPuts(m_fd, "1 ");
::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); ::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE);
// Thread this out?
::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer); ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer);
if (m_cols > 16) { 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)); ::lcdPosition(m_fd, 0, (m_rows / 2));
::lcdPuts(m_fd, "2 "); ::lcdPuts(m_fd, "2 ");
::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE); ::sprintf(buffer, "%s > %s%s", src.c_str(), dst.c_str(), DEADSPACE);
// Thread this out?
::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer); ::lcdPrintf(m_fd, "%.*s", m_cols - 2U, buffer);
if (m_cols > 16) { if (m_cols > 16) {
@@ -577,6 +585,7 @@ void CHD44780::clearDMRInt(unsigned int slotNo)
adafruitLCDColour(AC_PURPLE); adafruitLCDColour(AC_PURPLE);
#endif #endif
m_clockDisplayTimer.stop(); // Stop the clock display
if (m_duplex) { if (m_duplex) {
if (slotNo == 1U) { if (slotNo == 1U) {
::lcdPosition(m_fd, 0, 0); ::lcdPosition(m_fd, 0, 0);
@@ -605,6 +614,7 @@ void CHD44780::writeFusionInt(const char* source, const char* dest, const char*
adafruitLCDColour(AC_RED); adafruitLCDColour(AC_RED);
#endif #endif
m_clockDisplayTimer.stop(); // Stop the clock display
::lcdClear(m_fd); ::lcdClear(m_fd);
if (m_pwm) { if (m_pwm) {
@@ -657,6 +667,8 @@ void CHD44780::clearFusionInt()
adafruitLCDColour(AC_PURPLE); adafruitLCDColour(AC_PURPLE);
#endif #endif
m_clockDisplayTimer.stop(); // Stop the clock display
if (m_rows == 2U && m_cols == 16U) { if (m_rows == 2U && m_cols == 16U) {
::lcdPosition(m_fd, 0, 1); ::lcdPosition(m_fd, 0, 1);
::lcdPrintf(m_fd, "%.*s", m_cols, LISTENING); ::lcdPrintf(m_fd, "%.*s", m_cols, LISTENING);
@@ -680,13 +692,29 @@ void CHD44780::clearFusionInt()
void CHD44780::clockInt(unsigned int ms) void CHD44780::clockInt(unsigned int ms)
{ {
m_timer.clock(ms); // Update the clock display in IDLE mode every 75ms
if (m_timer.isRunning() && m_timer.hasExpired()) { m_clockDisplayTimer.clock(ms);
// Do work every 250ms here if (m_displayClock && m_clockDisplayTimer.isRunning() && m_clockDisplayTimer.hasExpired()) {
time_t currentTime;
struct tm *Time;
time(&currentTime); // Get the current time
// Start the timer with m_timer.start(); if (m_utc){
// and stop it with m_timer.stop(); Time = gmtime(&currentTime);
m_timer.start(); } 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;
::lcdPosition(m_fd, m_cols - 8, 1);
::lcdPrintf(m_fd, "%02d:%02d:%02d", Hour, Min, Sec);
m_clockDisplayTimer.start(); // restart the clock display timer
} }
} }

View File

@@ -53,7 +53,7 @@ enum ADAFRUIT_COLOUR {
class CHD44780 : public CDisplay class CHD44780 : public CDisplay
{ {
public: public:
CHD44780(unsigned int rows, unsigned int cols, const std::string& callsign, unsigned int dmrid, const std::vector<unsigned int>& 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<unsigned int>& pins, bool pwm, unsigned int pwmPin, unsigned int pwmBright, unsigned int pwmDim, bool displayClock, bool utc, bool duplex);
virtual ~CHD44780(); virtual ~CHD44780();
virtual bool open(); virtual bool open();
@@ -91,10 +91,12 @@ private:
unsigned int m_pwmPin; unsigned int m_pwmPin;
unsigned int m_pwmBright; unsigned int m_pwmBright;
unsigned int m_pwmDim; unsigned int m_pwmDim;
bool m_displayClock;
bool m_utc;
bool m_duplex; bool m_duplex;
int m_fd; int m_fd;
bool m_dmr; bool m_dmr;
CTimer m_timer; CTimer m_clockDisplayTimer;
#ifdef ADAFRUIT_DISPLAY #ifdef ADAFRUIT_DISPLAY
void adafruitLCDSetup(); void adafruitLCDSetup();

View File

@@ -95,12 +95,16 @@ Pins=11,10,0,1,2,3
# For Adafruit i2c HD44780 # For Adafruit i2c HD44780
# Pins=115,113,112,111,110,109 # Pins=115,113,112,111,110,109
# PWM brightness control # PWM backlight
PWM=1 PWM=0
PWMPin=21 PWMPin=21
PWMBright=100 PWMBright=100
PWMDim=16 PWMDim=16
# Display a clock when in IDLE? (HD44780 ONLY!)
DisplayClock=1
ZuluClock=0
[Nextion] [Nextion]
Port=/dev/ttyAMA0 Port=/dev/ttyAMA0
Brightness=50 Brightness=50

View File

@@ -801,20 +801,26 @@ void CMMDVMHost::createDisplay()
unsigned int pwmPin = m_conf.getHD44780PWMPin(); unsigned int pwmPin = m_conf.getHD44780PWMPin();
unsigned int pwmBright = m_conf.getHD44780PWMBright(); unsigned int pwmBright = m_conf.getHD44780PWMBright();
unsigned int pwmDim = m_conf.getHD44780PWMDim(); unsigned int pwmDim = m_conf.getHD44780PWMDim();
bool displayClock = m_conf.getHD44780DisplayClock();
bool utc = m_conf.getHD44780UTC();
if (pins.size() == 6U) { if (pins.size() == 6U) {
LogInfo(" Rows: %u", rows); LogInfo(" Rows: %u", rows);
LogInfo(" Columns: %u", columns); 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(" 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) { if (pwm) {
LogInfo("PWM Brightness Control Enabled");
LogInfo(" PWM Pin: %u", pwmPin); LogInfo(" PWM Pin: %u", pwmPin);
LogInfo(" PWM Bright: %u", pwmBright); LogInfo(" PWM Bright: %u", pwmBright);
LogInfo(" PWM Dim: %u", pwmDim); 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 #endif
#if defined(OLED) #if defined(OLED)