Skip to content

Commit

Permalink
Add Config option to dim Nextion display in idle
Browse files Browse the repository at this point in the history
state
  • Loading branch information
phl0 committed Jun 24, 2016
1 parent 18fa0df commit 7e906f3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ m_nextionBrightness(50U),
m_nextionDisplayClock(false),
m_nextionUTC(false),
m_nextionDateFormat("English"),
m_nextionDimOnIdle(false),
m_oledType(3),
m_oledBrightness(0),
m_oledInvert(0)
Expand Down Expand Up @@ -467,6 +468,8 @@ bool CConf::read()
m_nextionUTC = ::atoi(value) == 1;
else if (::strcmp(key, "DateFormat") == 0)
m_nextionDateFormat = value;
else if (::strcmp(key, "DimOnIdle") == 0)
m_nextionDimOnIdle = ::atoi(value) == 1;
} else if (section == SECTION_OLED) {
if (::strcmp(key, "Type") == 0)
m_oledType = (unsigned char)::atoi(value);
Expand Down Expand Up @@ -942,6 +945,11 @@ std::string CConf::getNextionDateFormat() const
return m_nextionDateFormat;
}

bool CConf::getNextionDimOnIdle() const
{
return m_nextionDimOnIdle;
}

unsigned char CConf::getOLEDType() const
{
return m_oledType;
Expand Down
2 changes: 2 additions & 0 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class CConf
bool getNextionDisplayClock() const;
bool getNextionUTC() const;
std::string getNextionDateFormat() const;
bool getNextionDimOnIdle() const;

// The OLED section
unsigned char getOLEDType() const;
Expand Down Expand Up @@ -264,6 +265,7 @@ class CConf
bool m_nextionDisplayClock;
bool m_nextionUTC;
std::string m_nextionDateFormat;
bool m_nextionDimOnIdle;

unsigned char m_oledType;
unsigned char m_oledBrightness;
Expand Down
1 change: 1 addition & 0 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Brightness=50
DisplayClock=1
UTC=0
DateFormat=English
DimOnIdle=1

[OLED]
Type=3
Expand Down
3 changes: 2 additions & 1 deletion MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,15 @@ void CMMDVMHost::createDisplay()
bool displayClock = m_conf.getNextionDisplayClock();
bool utc = m_conf.getNextionUTC();
std::string dateformat = m_conf.getNextionDateFormat();
bool dimOnIdle = m_conf.getNextionDimOnIdle();

LogInfo(" Port: %s", port.c_str());
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, displayClock, utc, dateformat);
m_display = new CNextion(m_callsign, dmrid, port, brightness, displayClock, utc, dateformat, dimOnIdle);
#if defined(HD44780)
} else if (type == "HD44780") {
unsigned int rows = m_conf.getHD44780Rows();
Expand Down
36 changes: 27 additions & 9 deletions Nextion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <cstring>
#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) :
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) :
CDisplay(),
m_callsign(callsign),
m_dmrid(dmrid),
Expand All @@ -34,6 +34,7 @@ m_mode(MODE_IDLE),
m_displayClock(displayClock),
m_utc(utc),
m_dateformat(dateformat),
m_dimOnIdle(dimOnIdle),
m_clockDisplayTimer(1000U, 0U, 400U)
{
assert(brightness >= 0U && brightness <= 100U);
Expand All @@ -53,10 +54,6 @@ bool CNextion::open()

sendCommand("bkcmd=0");

char command[20U];
::sprintf(command, "dim=%u", m_brightness);
sendCommand(command);

setIdle();

return true;
Expand All @@ -67,6 +64,14 @@ void CNextion::setIdleInt()
sendCommand("page MMDVM");

char command[30];

if (m_dimOnIdle) {
::sprintf(command, "dim=%u", (m_brightness/4));
} else {
::sprintf(command, "dim=%u", m_brightness);
}
sendCommand(command);

::sprintf(command, "t0.txt=\"%-6s / %u\"", m_callsign.c_str(), m_dmrid);

sendCommand(command);
Expand All @@ -84,6 +89,9 @@ void CNextion::setErrorInt(const char* text)
sendCommand("page MMDVM");

char command[20];
::sprintf(command, "dim=%u", m_brightness);
sendCommand(command);

::sprintf(command, "t0.txt=\"%s\"", text);

sendCommand(command);
Expand All @@ -98,6 +106,10 @@ void CNextion::setLockoutInt()
{
sendCommand("page MMDVM");

char command[20];
::sprintf(command, "dim=%u", m_brightness);
sendCommand(command);

sendCommand("t0.txt=\"LOCKOUT\"");

m_clockDisplayTimer.stop();
Expand All @@ -117,6 +129,9 @@ void CNextion::writeDStarInt(const char* my1, const char* my2, const char* your,
sendCommand("page DStar");

char text[30U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);

::sprintf(text, "t0.txt=\"%s %.8s/%4.4s\"", type, my1, my2);
sendCommand(text);

Expand Down Expand Up @@ -153,17 +168,17 @@ void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro
sendCommand("t0.txt=\"1 Listening\"");
}

if (slotNo == 1U) {
char text[30U];
char text[30U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);

if (slotNo == 1U) {
::sprintf(text, "t0.txt=\"1 %s %s\"", type, src.c_str());
sendCommand(text);

::sprintf(text, "t1.txt=\"%s%s\"", group ? "TG" : "", dst.c_str());
sendCommand(text);
} else {
char text[30U];

::sprintf(text, "t2.txt=\"2 %s %s\"", type, src.c_str());
sendCommand(text);

Expand Down Expand Up @@ -198,6 +213,9 @@ void CNextion::writeFusionInt(const char* source, const char* dest, const char*
sendCommand("page YSF");

char text[30U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);

::sprintf(text, "t0.txt=\"%s %.10s\"", type, source);
sendCommand(text);

Expand Down
3 changes: 2 additions & 1 deletion Nextion.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class CNextion : public CDisplay
{
public:
CNextion(const std::string& callsign, unsigned int dmrid, const std::string& port, unsigned int brightness, bool displayClock, bool utc, const std::string& dateformat);
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);
virtual ~CNextion();

virtual bool open();
Expand Down Expand Up @@ -61,6 +61,7 @@ class CNextion : public CDisplay
bool m_displayClock;
bool m_utc;
std::string m_dateformat;
bool m_dimOnIdle;
CTimer m_clockDisplayTimer;

void sendCommand(const char* command);
Expand Down

0 comments on commit 7e906f3

Please sign in to comment.