Make the Nextion idle brightness level configurable.

This commit is contained in:
Jonathan Naylor
2016-06-24 10:33:28 +01:00
parent 2dc581bd25
commit 6745168688
6 changed files with 22 additions and 27 deletions

View File

@@ -142,8 +142,7 @@ m_nextionBrightness(50U),
m_nextionDisplayClock(false), m_nextionDisplayClock(false),
m_nextionUTC(false), m_nextionUTC(false),
m_nextionDateFormat("British"), m_nextionDateFormat("British"),
m_nextionDimOnIdle(false), m_nextionIdleBrightness(20U),
m_oledType(3), m_oledType(3),
m_oledBrightness(0), m_oledBrightness(0),
m_oledInvert(0) m_oledInvert(0)
@@ -467,15 +466,15 @@ bool CConf::read()
if (::strcmp(key, "Port") == 0) if (::strcmp(key, "Port") == 0)
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_nextionIdleBrightness = m_nextionBrightness = (unsigned int)::atoi(value);
else if (::strcmp(key, "DisplayClock") == 0) else if (::strcmp(key, "DisplayClock") == 0)
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) else if (::strcmp(key, "DateFormat") == 0)
m_nextionDateFormat = value; m_nextionDateFormat = value;
else if (::strcmp(key, "DimOnIdle") == 0) else if (::strcmp(key, "IdleBrightness") == 0)
m_nextionDimOnIdle = ::atoi(value) == 1; m_nextionIdleBrightness = (unsigned int)::atoi(value);
} 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);
@@ -956,9 +955,9 @@ std::string CConf::getNextionDateFormat() const
return m_nextionDateFormat; return m_nextionDateFormat;
} }
bool CConf::getNextionDimOnIdle() const unsigned int CConf::getNextionIdleBrightness() const
{ {
return m_nextionDimOnIdle; return m_nextionIdleBrightness;
} }
unsigned char CConf::getOLEDType() const unsigned char CConf::getOLEDType() const

4
Conf.h
View File

@@ -151,7 +151,7 @@ public:
bool getNextionDisplayClock() const; bool getNextionDisplayClock() const;
bool getNextionUTC() const; bool getNextionUTC() const;
std::string getNextionDateFormat() const; std::string getNextionDateFormat() const;
bool getNextionDimOnIdle() const; unsigned int getNextionIdleBrightness() const;
// The OLED section // The OLED section
unsigned char getOLEDType() const; unsigned char getOLEDType() const;
@@ -267,7 +267,7 @@ private:
bool m_nextionDisplayClock; bool m_nextionDisplayClock;
bool m_nextionUTC; bool m_nextionUTC;
std::string m_nextionDateFormat; std::string m_nextionDateFormat;
bool m_nextionDimOnIdle; unsigned int m_nextionIdleBrightness;
unsigned char m_oledType; unsigned char m_oledType;
unsigned char m_oledBrightness; unsigned char m_oledBrightness;

View File

@@ -128,7 +128,7 @@ Brightness=50
DisplayClock=1 DisplayClock=1
UTC=0 UTC=0
DateFormat=British DateFormat=British
DimOnIdle=1 IdleBrightness=20
[OLED] [OLED]
Type=3 Type=3

View File

@@ -856,20 +856,21 @@ void CMMDVMHost::createDisplay()
m_display = new CTFTSerial(m_callsign, dmrid, port, brightness); m_display = new CTFTSerial(m_callsign, dmrid, port, brightness);
} 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 displayClock = m_conf.getNextionDisplayClock();
bool utc = m_conf.getNextionUTC(); bool utc = m_conf.getNextionUTC();
std::string dateformat = m_conf.getNextionDateFormat(); std::string dateformat = m_conf.getNextionDateFormat();
bool dimOnIdle = m_conf.getNextionDimOnIdle(); unsigned int idleBrightness = m_conf.getNextionIdleBrightness();
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"); LogInfo(" Clock Display: %s", displayClock ? "yes" : "no");
if (displayClock) if (displayClock)
LogInfo(" Display UTC: %s", utc ? "yes" : "no"); LogInfo(" Display UTC: %s", utc ? "yes" : "no");
LogInfo(" Idle Brightness: %u", idleBrightness);
m_display = new CNextion(m_callsign, dmrid, port, brightness, displayClock, utc, dateformat, dimOnIdle); m_display = new CNextion(m_callsign, dmrid, port, brightness, displayClock, utc, dateformat, 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();

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, bool dimOnIdle) : 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) :
CDisplay(), CDisplay(),
m_callsign(callsign), m_callsign(callsign),
m_dmrid(dmrid), m_dmrid(dmrid),
@@ -34,7 +34,7 @@ m_mode(MODE_IDLE),
m_displayClock(displayClock), m_displayClock(displayClock),
m_utc(utc), m_utc(utc),
m_dateformat(dateformat), m_dateformat(dateformat),
m_dimOnIdle(dimOnIdle), m_idleBrightness(idleBrightness),
m_clockDisplayTimer(1000U, 0U, 400U) m_clockDisplayTimer(1000U, 0U, 400U)
{ {
assert(brightness >= 0U && brightness <= 100U); assert(brightness >= 0U && brightness <= 100U);
@@ -64,12 +64,7 @@ void CNextion::setIdleInt()
sendCommand("page MMDVM"); sendCommand("page MMDVM");
char command[30]; char command[30];
::sprintf(command, "dim=%u", m_idleBrightness);
if (m_dimOnIdle) {
::sprintf(command, "dim=%u", (m_brightness/4));
} else {
::sprintf(command, "dim=%u", m_brightness);
}
sendCommand(command); sendCommand(command);
::sprintf(command, "t0.txt=\"%-6s / %u\"", m_callsign.c_str(), m_dmrid); ::sprintf(command, "t0.txt=\"%-6s / %u\"", m_callsign.c_str(), m_dmrid);

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, bool dimOnIdle); 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);
virtual ~CNextion(); virtual ~CNextion();
virtual bool open(); virtual bool open();
@@ -61,7 +61,7 @@ private:
bool m_displayClock; bool m_displayClock;
bool m_utc; bool m_utc;
std::string m_dateformat; std::string m_dateformat;
bool m_dimOnIdle; unsigned int m_idleBrightness;
CTimer m_clockDisplayTimer; CTimer m_clockDisplayTimer;
void sendCommand(const char* command); void sendCommand(const char* command);