Time/date format by system locale (HD44780 & Nextion)

This commit is contained in:
Tony Corbett G0WFV 2016-06-24 16:08:28 +01:00
parent 2d35ee5121
commit da53f06197
8 changed files with 18 additions and 66 deletions

View file

@ -136,12 +136,10 @@ m_hd44780PWMBright(),
m_hd44780PWMDim(), m_hd44780PWMDim(),
m_hd44780DisplayClock(false), m_hd44780DisplayClock(false),
m_hd44780UTC(false), m_hd44780UTC(false),
m_hd44780DateFormat("British"),
m_nextionPort("/dev/ttyAMA0"), m_nextionPort("/dev/ttyAMA0"),
m_nextionBrightness(50U), m_nextionBrightness(50U),
m_nextionDisplayClock(false), m_nextionDisplayClock(false),
m_nextionUTC(false), m_nextionUTC(false),
m_nextionDateFormat("British"),
m_nextionIdleBrightness(20U), m_nextionIdleBrightness(20U),
m_oledType(3), m_oledType(3),
m_oledBrightness(0), m_oledBrightness(0),
@ -452,8 +450,6 @@ bool CConf::read()
m_hd44780DisplayClock = ::atoi(value) == 1; m_hd44780DisplayClock = ::atoi(value) == 1;
else if (::strcmp(key, "UTC") == 0) else if (::strcmp(key, "UTC") == 0)
m_hd44780UTC = ::atoi(value) == 1; m_hd44780UTC = ::atoi(value) == 1;
else if (::strcmp(key, "DateFormat") == 0)
m_hd44780DateFormat = value;
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) {
@ -471,8 +467,6 @@ bool CConf::read()
m_nextionDisplayClock = ::atoi(value) == 1; m_nextionDisplayClock = ::atoi(value) == 1;
else if (::strcmp(key, "UTC") == 0) else if (::strcmp(key, "UTC") == 0)
m_nextionUTC = ::atoi(value) == 1; m_nextionUTC = ::atoi(value) == 1;
else if (::strcmp(key, "DateFormat") == 0)
m_nextionDateFormat = value;
else if (::strcmp(key, "IdleBrightness") == 0) else if (::strcmp(key, "IdleBrightness") == 0)
m_nextionIdleBrightness = (unsigned int)::atoi(value); m_nextionIdleBrightness = (unsigned int)::atoi(value);
} else if (section == SECTION_OLED) { } else if (section == SECTION_OLED) {
@ -925,11 +919,6 @@ bool CConf::getHD44780UTC() const
return m_hd44780UTC; return m_hd44780UTC;
} }
std::string CConf::getHD44780DateFormat() const
{
return m_hd44780DateFormat;
}
std::string CConf::getNextionPort() const std::string CConf::getNextionPort() const
{ {
return m_nextionPort; return m_nextionPort;
@ -950,11 +939,6 @@ bool CConf::getNextionUTC() const
return m_nextionUTC; return m_nextionUTC;
} }
std::string CConf::getNextionDateFormat() const
{
return m_nextionDateFormat;
}
unsigned int CConf::getNextionIdleBrightness() const unsigned int CConf::getNextionIdleBrightness() const
{ {
return m_nextionIdleBrightness; return m_nextionIdleBrightness;

4
Conf.h
View file

@ -143,14 +143,12 @@ public:
unsigned int getHD44780PWMDim() const; unsigned int getHD44780PWMDim() const;
bool getHD44780DisplayClock() const; bool getHD44780DisplayClock() const;
bool getHD44780UTC() const; bool getHD44780UTC() const;
std::string getHD44780DateFormat() const;
// 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 getNextionDisplayClock() const;
bool getNextionUTC() const; bool getNextionUTC() const;
std::string getNextionDateFormat() const;
unsigned int getNextionIdleBrightness() const; unsigned int getNextionIdleBrightness() const;
// The OLED section // The OLED section
@ -260,13 +258,11 @@ private:
unsigned int m_hd44780PWMDim; unsigned int m_hd44780PWMDim;
bool m_hd44780DisplayClock; bool m_hd44780DisplayClock;
bool m_hd44780UTC; bool m_hd44780UTC;
std::string m_hd44780DateFormat;
std::string m_nextionPort; std::string m_nextionPort;
unsigned int m_nextionBrightness; unsigned int m_nextionBrightness;
bool m_nextionDisplayClock; bool m_nextionDisplayClock;
bool m_nextionUTC; bool m_nextionUTC;
std::string m_nextionDateFormat;
unsigned int m_nextionIdleBrightness; unsigned int m_nextionIdleBrightness;
unsigned char m_oledType; unsigned char m_oledType;

View file

@ -36,7 +36,7 @@ char m_buffer2[128U];
char m_buffer3[128U]; char m_buffer3[128U];
char m_buffer4[128U]; char m_buffer4[128U];
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, const std::string& dateformat) : 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),
@ -56,7 +56,6 @@ m_displayClock(displayClock),
m_utc(utc), 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_dateformat(dateformat),
m_fd(-1), m_fd(-1),
m_dmr(false), m_dmr(false),
m_clockDisplayTimer(1000U, 0U, 75U), // Update the clock display every 75ms m_clockDisplayTimer(1000U, 0U, 75U), // Update the clock display every 75ms
@ -719,29 +718,21 @@ void CHD44780::clockInt(unsigned int ms)
Time = localtime(&currentTime); Time = localtime(&currentTime);
} }
int Day = Time->tm_mday; setlocale(LC_ALL,"");
int Month = Time->tm_mon + 1; strftime(m_buffer1, 128, "%X", Time); // Time
int Year = Time->tm_year + 1900; strftime(m_buffer2, 128, "%x", Time); // Date
int Hour = Time->tm_hour;
int Min = Time->tm_min;
int Sec = Time->tm_sec;
if (m_cols == 16U && m_rows == 2U) { if (m_cols == 16U && m_rows == 2U) {
::lcdPosition(m_fd, m_cols - 8, 1); ::lcdPosition(m_fd, m_cols - 10, 1);
::lcdPrintf(m_fd, "%s%.*s", strlen(m_buffer1) > 8 ? "" : " ", 10, m_buffer1);
} else { } else {
::lcdPosition(m_fd, (m_cols - 8) / 2, m_rows == 2 ? 1 : 2); ::lcdPosition(m_fd, (m_cols - strlen(m_buffer1) > 8 ? 10 : 8) / 2, m_rows == 2 ? 1 : 2);
::lcdPrintf(m_fd, "%.*s", strlen(m_buffer1) > 8 ? 10 : 8, m_buffer1);
} }
::lcdPrintf(m_fd, "%02d:%02d:%02d", Hour, Min, Sec);
if (m_cols != 16U && m_rows != 2U) { if (m_cols != 16U && m_rows != 2U) {
::lcdPosition(m_fd, (m_cols - 8) / 2, m_rows == 2 ? 0 : 1); ::lcdPosition(m_fd, (m_cols - strlen(m_buffer2)) / 2, m_rows == 2 ? 0 : 1);
if (strcmp(m_dateformat.c_str(), "British") == 0) { ::lcdPrintf(m_fd, "%s", m_buffer2);
::lcdPrintf(m_fd, "%02d/%02d/%2d", Day, Month, Year%100);
} else if (strcmp(m_dateformat.c_str(), "German") == 0) {
::lcdPrintf(m_fd, "%02d.%02d.%2d", Day, Month, Year%100);
} else if (strcmp(m_dateformat.c_str(), "American") == 0) {
::lcdPrintf(m_fd, "%02d/%02d/%2d", Month, Day, Year%100);
}
} }
m_clockDisplayTimer.start(); m_clockDisplayTimer.start();
} }

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 displayClock, bool utc, bool duplex, const std::string& dateformat); 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();
@ -94,7 +94,6 @@ private:
bool m_displayClock; bool m_displayClock;
bool m_utc; bool m_utc;
bool m_duplex; bool m_duplex;
std::string m_dateformat;
int m_fd; int m_fd;
bool m_dmr; bool m_dmr;
CTimer m_clockDisplayTimer; CTimer m_clockDisplayTimer;

View file

@ -120,14 +120,12 @@ PWMBright=100
PWMDim=16 PWMDim=16
DisplayClock=1 DisplayClock=1
UTC=0 UTC=0
DateFormat=British
[Nextion] [Nextion]
Port=/dev/ttyAMA0 Port=/dev/ttyAMA0
Brightness=50 Brightness=50
DisplayClock=1 DisplayClock=1
UTC=0 UTC=0
DateFormat=British
IdleBrightness=20 IdleBrightness=20
[OLED] [OLED]

View file

@ -860,7 +860,6 @@ void CMMDVMHost::createDisplay()
unsigned int brightness = m_conf.getNextionBrightness(); unsigned int brightness = m_conf.getNextionBrightness();
bool displayClock = m_conf.getNextionDisplayClock(); bool displayClock = m_conf.getNextionDisplayClock();
bool utc = m_conf.getNextionUTC(); bool utc = m_conf.getNextionUTC();
std::string dateformat = m_conf.getNextionDateFormat();
unsigned int idleBrightness = m_conf.getNextionIdleBrightness(); unsigned int idleBrightness = m_conf.getNextionIdleBrightness();
LogInfo(" Port: %s", port.c_str()); LogInfo(" Port: %s", port.c_str());
@ -870,7 +869,7 @@ void CMMDVMHost::createDisplay()
LogInfo(" Display UTC: %s", utc ? "yes" : "no"); LogInfo(" Display UTC: %s", utc ? "yes" : "no");
LogInfo(" Idle Brightness: %u", idleBrightness); LogInfo(" Idle Brightness: %u", idleBrightness);
m_display = new CNextion(m_callsign, dmrid, port, brightness, displayClock, utc, dateformat, idleBrightness); m_display = new CNextion(m_callsign, dmrid, port, brightness, displayClock, utc, idleBrightness);
#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();
@ -882,7 +881,6 @@ void CMMDVMHost::createDisplay()
unsigned int pwmDim = m_conf.getHD44780PWMDim(); unsigned int pwmDim = m_conf.getHD44780PWMDim();
bool displayClock = m_conf.getHD44780DisplayClock(); bool displayClock = m_conf.getHD44780DisplayClock();
bool utc = m_conf.getHD44780UTC(); bool utc = m_conf.getHD44780UTC();
std::string dateformat = m_conf.getHD44780DateFormat();
if (pins.size() == 6U) { if (pins.size() == 6U) {
LogInfo(" Rows: %u", rows); LogInfo(" Rows: %u", rows);
@ -900,7 +898,7 @@ void CMMDVMHost::createDisplay()
if (displayClock) if (displayClock)
LogInfo(" Display UTC: %s", utc ? "yes" : "no"); 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, dateformat); 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)

View file

@ -24,7 +24,7 @@
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
CNextion::CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc, const std::string& dateformat, unsigned int idleBrightness) : CNextion::CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness) :
CDisplay(), CDisplay(),
m_callsign(callsign), m_callsign(callsign),
m_dmrid(dmrid), m_dmrid(dmrid),
@ -33,7 +33,6 @@ m_brightness(brightness),
m_mode(MODE_IDLE), m_mode(MODE_IDLE),
m_displayClock(displayClock), m_displayClock(displayClock),
m_utc(utc), m_utc(utc),
m_dateformat(dateformat),
m_idleBrightness(idleBrightness), m_idleBrightness(idleBrightness),
m_clockDisplayTimer(1000U, 0U, 400U) m_clockDisplayTimer(1000U, 0U, 400U)
{ {
@ -247,21 +246,9 @@ void CNextion::clockInt(unsigned int ms)
else else
Time = ::localtime(&currentTime); Time = ::localtime(&currentTime);
int Day = Time->tm_mday; setlocale(LC_ALL,"");
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]; char text[50U];
if (strcmp(m_dateformat.c_str(), "British") == 0) { strftime(text, 50, "t2.txt=\"%x %X\"", Time);
::sprintf(text, "t2.txt=\"%02d:%02d:%02d %02d/%02d/%2d\"", Hour, Min, Sec, Day, Month, Year % 100);
} else if (strcmp(m_dateformat.c_str(), "German") == 0) {
::sprintf(text, "t2.txt=\"%02d:%02d:%02d %02d.%02d.%2d\"", Hour, Min, Sec, Day, Month, Year % 100);
} else if (strcmp(m_dateformat.c_str(), "American") == 0) {
::sprintf(text, "t2.txt=\"%02d:%02d:%02d %02d/%02d/%2d\"", Hour, Min, Sec, Month, Day, Year % 100);
}
sendCommand(text); sendCommand(text);
m_clockDisplayTimer.start(); // restart the clock display timer m_clockDisplayTimer.start(); // restart the clock display timer

View file

@ -29,7 +29,7 @@
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, bool displayClock, bool utc, const std::string& dateformat, unsigned int idleBrightness); CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness);
virtual ~CNextion(); virtual ~CNextion();
virtual bool open(); virtual bool open();
@ -60,7 +60,6 @@ private:
unsigned char m_mode; unsigned char m_mode;
bool m_displayClock; bool m_displayClock;
bool m_utc; bool m_utc;
std::string m_dateformat;
unsigned int m_idleBrightness; unsigned int m_idleBrightness;
CTimer m_clockDisplayTimer; CTimer m_clockDisplayTimer;