mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 23:45:49 +08:00
Add the idle clock to the Nextion display.
This commit is contained in:
16
Conf.cpp
16
Conf.cpp
@@ -123,6 +123,8 @@ m_hd44780DisplayClock(false),
|
|||||||
m_hd44780UTC(false),
|
m_hd44780UTC(false),
|
||||||
m_nextionPort("/dev/ttyAMA0"),
|
m_nextionPort("/dev/ttyAMA0"),
|
||||||
m_nextionBrightness(50U),
|
m_nextionBrightness(50U),
|
||||||
|
m_nextionDisplayClock(false),
|
||||||
|
m_nextionUTC(false),
|
||||||
m_oledType(3),
|
m_oledType(3),
|
||||||
m_oledBrightness(0),
|
m_oledBrightness(0),
|
||||||
m_oledInvert(0)
|
m_oledInvert(0)
|
||||||
@@ -389,6 +391,10 @@ bool CConf::read()
|
|||||||
m_nextionPort = value;
|
m_nextionPort = value;
|
||||||
else if (::strcmp(key, "Brightness") == 0)
|
else if (::strcmp(key, "Brightness") == 0)
|
||||||
m_nextionBrightness = (unsigned int)::atoi(value);
|
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) {
|
} else if (section == SECTION_OLED) {
|
||||||
if (::strcmp(key, "Type") == 0)
|
if (::strcmp(key, "Type") == 0)
|
||||||
m_oledType = (unsigned char)::atoi(value);
|
m_oledType = (unsigned char)::atoi(value);
|
||||||
@@ -780,6 +786,16 @@ unsigned int CConf::getNextionBrightness() const
|
|||||||
return m_nextionBrightness;
|
return m_nextionBrightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CConf::getNextionDisplayClock() const
|
||||||
|
{
|
||||||
|
return m_nextionDisplayClock;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CConf::getNextionUTC() const
|
||||||
|
{
|
||||||
|
return m_nextionUTC;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char CConf::getOLEDType() const
|
unsigned char CConf::getOLEDType() const
|
||||||
{
|
{
|
||||||
return m_oledType;
|
return m_oledType;
|
||||||
|
|||||||
4
Conf.h
4
Conf.h
@@ -132,6 +132,8 @@ public:
|
|||||||
// The Nextion section
|
// The Nextion section
|
||||||
std::string getNextionPort() const;
|
std::string getNextionPort() const;
|
||||||
unsigned int getNextionBrightness() const;
|
unsigned int getNextionBrightness() const;
|
||||||
|
bool getNextionDisplayClock() const;
|
||||||
|
bool getNextionUTC() const;
|
||||||
|
|
||||||
// The OLED section
|
// The OLED section
|
||||||
unsigned char getOLEDType() const;
|
unsigned char getOLEDType() const;
|
||||||
@@ -228,6 +230,8 @@ private:
|
|||||||
|
|
||||||
std::string m_nextionPort;
|
std::string m_nextionPort;
|
||||||
unsigned int m_nextionBrightness;
|
unsigned int m_nextionBrightness;
|
||||||
|
bool m_nextionDisplayClock;
|
||||||
|
bool m_nextionUTC;
|
||||||
|
|
||||||
unsigned char m_oledType;
|
unsigned char m_oledType;
|
||||||
unsigned char m_oledBrightness;
|
unsigned char m_oledBrightness;
|
||||||
|
|||||||
@@ -100,17 +100,16 @@ PWM=0
|
|||||||
PWMPin=21
|
PWMPin=21
|
||||||
PWMBright=100
|
PWMBright=100
|
||||||
PWMDim=16
|
PWMDim=16
|
||||||
|
|
||||||
# Display a clock when in IDLE? (HD44780 ONLY!)
|
|
||||||
DisplayClock=1
|
DisplayClock=1
|
||||||
UTC=0
|
UTC=0
|
||||||
|
|
||||||
[Nextion]
|
[Nextion]
|
||||||
Port=/dev/ttyAMA0
|
Port=/dev/ttyAMA0
|
||||||
Brightness=50
|
Brightness=50
|
||||||
|
DisplayClock=1
|
||||||
|
UTC=0
|
||||||
|
|
||||||
[OLED]
|
[OLED]
|
||||||
Type=3
|
Type=3
|
||||||
Brightness=0
|
Brightness=0
|
||||||
Invert=0
|
Invert=0
|
||||||
|
|
||||||
|
|||||||
@@ -787,11 +787,16 @@ void CMMDVMHost::createDisplay()
|
|||||||
} else if (type == "Nextion") {
|
} else if (type == "Nextion") {
|
||||||
std::string port = m_conf.getNextionPort();
|
std::string port = m_conf.getNextionPort();
|
||||||
unsigned int brightness = m_conf.getNextionBrightness();
|
unsigned int brightness = m_conf.getNextionBrightness();
|
||||||
|
bool displayClock = m_conf.getNextionDisplayClock();
|
||||||
|
bool utc = m_conf.getNextionUTC();
|
||||||
|
|
||||||
LogInfo(" Port: %s", port.c_str());
|
LogInfo(" Port: %s", port.c_str());
|
||||||
LogInfo(" Brightness: %u", brightness);
|
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)
|
#if defined(HD44780)
|
||||||
} else if (type == "HD44780") {
|
} else if (type == "HD44780") {
|
||||||
unsigned int rows = m_conf.getHD44780Rows();
|
unsigned int rows = m_conf.getHD44780Rows();
|
||||||
|
|||||||
49
Nextion.cpp
49
Nextion.cpp
@@ -22,14 +22,18 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#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(),
|
CDisplay(),
|
||||||
m_callsign(callsign),
|
m_callsign(callsign),
|
||||||
m_dmrid(dmrid),
|
m_dmrid(dmrid),
|
||||||
m_serial(port, SERIAL_9600),
|
m_serial(port, SERIAL_9600),
|
||||||
m_brightness(brightness),
|
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);
|
assert(brightness >= 0U && brightness <= 100U);
|
||||||
}
|
}
|
||||||
@@ -67,6 +71,8 @@ void CNextion::setIdleInt()
|
|||||||
sendCommand(command);
|
sendCommand(command);
|
||||||
sendCommand("t1.txt=\"MMDVM IDLE\"");
|
sendCommand("t1.txt=\"MMDVM IDLE\"");
|
||||||
|
|
||||||
|
m_clockDisplayTimer.start();
|
||||||
|
|
||||||
m_mode = MODE_IDLE;
|
m_mode = MODE_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +88,8 @@ void CNextion::setErrorInt(const char* text)
|
|||||||
sendCommand(command);
|
sendCommand(command);
|
||||||
sendCommand("t1.txt=\"ERROR\"");
|
sendCommand("t1.txt=\"ERROR\"");
|
||||||
|
|
||||||
|
m_clockDisplayTimer.stop();
|
||||||
|
|
||||||
m_mode = MODE_ERROR;
|
m_mode = MODE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +99,8 @@ void CNextion::setLockoutInt()
|
|||||||
|
|
||||||
sendCommand("t0.txt=\"LOCKOUT\"");
|
sendCommand("t0.txt=\"LOCKOUT\"");
|
||||||
|
|
||||||
|
m_clockDisplayTimer.stop();
|
||||||
|
|
||||||
m_mode = MODE_LOCKOUT;
|
m_mode = MODE_LOCKOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +127,8 @@ void CNextion::writeDStarInt(const char* my1, const char* my2, const char* your,
|
|||||||
sendCommand(text);
|
sendCommand(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_clockDisplayTimer.stop();
|
||||||
|
|
||||||
m_mode = MODE_DSTAR;
|
m_mode = MODE_DSTAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +170,8 @@ void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro
|
|||||||
sendCommand(text);
|
sendCommand(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_clockDisplayTimer.stop();
|
||||||
|
|
||||||
m_mode = MODE_DMR;
|
m_mode = MODE_DMR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +207,8 @@ void CNextion::writeFusionInt(const char* source, const char* dest, const char*
|
|||||||
sendCommand(text);
|
sendCommand(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_clockDisplayTimer.stop();
|
||||||
|
|
||||||
m_mode = MODE_YSF;
|
m_mode = MODE_YSF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +219,35 @@ void CNextion::clearFusionInt()
|
|||||||
sendCommand("t2.txt=\"\"");
|
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()
|
void CNextion::close()
|
||||||
{
|
{
|
||||||
m_serial.close();
|
m_serial.close();
|
||||||
|
|||||||
@@ -22,13 +22,14 @@
|
|||||||
#include "Display.h"
|
#include "Display.h"
|
||||||
#include "Defines.h"
|
#include "Defines.h"
|
||||||
#include "SerialController.h"
|
#include "SerialController.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class CNextion : public CDisplay
|
class CNextion : public CDisplay
|
||||||
{
|
{
|
||||||
public:
|
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 ~CNextion();
|
||||||
|
|
||||||
virtual bool open();
|
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 writeFusionInt(const char* source, const char* dest, const char* type, const char* origin);
|
||||||
virtual void clearFusionInt();
|
virtual void clearFusionInt();
|
||||||
|
|
||||||
|
virtual void clockInt(unsigned int ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_callsign;
|
std::string m_callsign;
|
||||||
unsigned int m_dmrid;
|
unsigned int m_dmrid;
|
||||||
CSerialController m_serial;
|
CSerialController m_serial;
|
||||||
unsigned int m_brightness;
|
unsigned int m_brightness;
|
||||||
unsigned char m_mode;
|
unsigned char m_mode;
|
||||||
|
bool m_displayClock;
|
||||||
|
bool m_utc;
|
||||||
|
CTimer m_clockDisplayTimer;
|
||||||
|
|
||||||
void sendCommand(const char* command);
|
void sendCommand(const char* command);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user