From b19c46ff2c7a5ffd4445443587305cfc27ad9285 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 21 Mar 2016 22:47:58 +0000 Subject: [PATCH] Add an error display. --- Defines.h | 1 + Display.h | 1 + HD44780.cpp | 13 +++++++++++++ HD44780.h | 1 + MMDVMHost.cpp | 18 ++++++++++++++++++ Modem.cpp | 10 +++++++++- Modem.h | 2 ++ NullDisplay.cpp | 4 ++++ NullDisplay.h | 1 + TFTSerial.cpp | 25 +++++++++++++++++++++++-- TFTSerial.h | 1 + 11 files changed, 74 insertions(+), 3 deletions(-) diff --git a/Defines.h b/Defines.h index eb0c9f3..542bac1 100644 --- a/Defines.h +++ b/Defines.h @@ -24,6 +24,7 @@ const unsigned char MODE_DSTAR = 1U; const unsigned char MODE_DMR = 2U; const unsigned char MODE_YSF = 3U; const unsigned char MODE_LOCKOUT = 99U; +const unsigned char MODE_ERROR = 100U; const unsigned char TAG_HEADER = 0x00U; const unsigned char TAG_DATA = 0x01U; diff --git a/Display.h b/Display.h index c786a47..f831af9 100644 --- a/Display.h +++ b/Display.h @@ -31,6 +31,7 @@ public: virtual void setIdle() = 0; virtual void setLockout() = 0; + virtual void setError(const char* text) = 0; virtual void setDStar() = 0; virtual void writeDStar(const char* my1, const char* my2, const char* your) = 0; diff --git a/HD44780.cpp b/HD44780.cpp index 4cf69ae..b6af698 100644 --- a/HD44780.cpp +++ b/HD44780.cpp @@ -68,6 +68,19 @@ void CHD44780::setIdle() ::lcdPuts(m_fd, "Idle"); } +void CHD44780::setError(const char* text) +{ + assert(text != NULL); + + ::lcdClear(m_fd); + + ::lcdPosition(m_fd, 0, 0); + ::lcdPuts(m_fd, "MMDVM"); + + ::lcdPosition(m_fd, 0, 1); + ::lcdPrintf(m_fd, "%s ERROR", text); +} + void CHD44780::setLockout() { ::lcdClear(m_fd); diff --git a/HD44780.h b/HD44780.h index 2a5a013..a5b1cc5 100644 --- a/HD44780.h +++ b/HD44780.h @@ -33,6 +33,7 @@ public: virtual void setIdle(); + virtual void setError(const char* text); virtual void setLockout(); virtual void setDStar(); diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index b1c4ced..5d0e84e 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -192,6 +192,12 @@ int CMMDVMHost::run() else if (!lockout && m_mode == MODE_LOCKOUT) setMode(MODE_IDLE); + bool error = m_modem->hasError(); + if (error && m_mode != MODE_ERROR) + setMode(MODE_ERROR); + else if (!error && m_mode == MODE_ERROR) + setMode(MODE_IDLE); + unsigned char data[200U]; unsigned int len; bool ret; @@ -632,6 +638,18 @@ void CMMDVMHost::setMode(unsigned char mode, bool logging) m_modeTimer.stop(); break; + case MODE_ERROR: + if (logging) + LogMessage("Mode set to Error"); + if (m_dstarNetwork != NULL) + m_dstarNetwork->enable(false); + if (m_dmrNetwork != NULL) + m_dmrNetwork->enable(false); + m_display->setError("MODEM"); + m_mode = MODE_ERROR; + m_modeTimer.stop(); + break; + default: if (logging) LogMessage("Mode set to Idle"); diff --git a/Modem.cpp b/Modem.cpp index b23b200..32febbf 100644 --- a/Modem.cpp +++ b/Modem.cpp @@ -108,7 +108,8 @@ m_dmrSpace1(0U), m_dmrSpace2(0U), m_ysfSpace(0U), m_tx(false), -m_lockout(false) +m_lockout(false), +m_error(false) { assert(!port.empty()); @@ -169,6 +170,7 @@ bool CModem::open() m_statusTimer.start(); m_inactivityTimer.start(); + m_error = false; m_offset = 0U; return true; @@ -186,6 +188,7 @@ void CModem::clock(unsigned int ms) m_inactivityTimer.clock(ms); if (m_inactivityTimer.hasExpired()) { LogError("No reply from the modem for some time, resetting it"); + m_error = true; close(); #if defined(_WIN32) || defined(_WIN64) ::Sleep(2000UL); // 2s @@ -643,6 +646,11 @@ bool CModem::hasLockout() const return m_lockout; } +bool CModem::hasError() const +{ + return m_error; +} + bool CModem::writeYSFData(const unsigned char* data, unsigned int length) { assert(data != NULL); diff --git a/Modem.h b/Modem.h index d6ea23e..cb4a71b 100644 --- a/Modem.h +++ b/Modem.h @@ -53,6 +53,7 @@ public: bool hasYSFSpace() const; bool hasLockout() const; + bool hasError() const; bool writeDStarData(const unsigned char* data, unsigned int length); bool writeDMRData1(const unsigned char* data, unsigned int length); @@ -105,6 +106,7 @@ private: unsigned int m_ysfSpace; bool m_tx; bool m_lockout; + bool m_error; bool readVersion(); bool readStatus(); diff --git a/NullDisplay.cpp b/NullDisplay.cpp index 015b5e2..59b45ef 100644 --- a/NullDisplay.cpp +++ b/NullDisplay.cpp @@ -35,6 +35,10 @@ void CNullDisplay::setIdle() { } +void CNullDisplay::setError(const char* text) +{ +} + void CNullDisplay::setLockout() { } diff --git a/NullDisplay.h b/NullDisplay.h index 8514f81..abcfa6e 100644 --- a/NullDisplay.h +++ b/NullDisplay.h @@ -33,6 +33,7 @@ public: virtual void setIdle(); + virtual void setError(const char* text); virtual void setLockout(); virtual void setDStar(); diff --git a/TFTSerial.cpp b/TFTSerial.cpp index be87b23..8901f6e 100644 --- a/TFTSerial.cpp +++ b/TFTSerial.cpp @@ -67,10 +67,8 @@ bool CTFTSerial::open() setBrightness(m_brightness); - // Set background white setBackground(COLOUR_WHITE); - // Set foreground black setForeground(COLOUR_BLACK); setIdle(); @@ -92,6 +90,29 @@ void CTFTSerial::setIdle() displayText("IDLE"); } +void CTFTSerial::setError(const char* text) +{ + assert(text != NULL); + + // Clear the screen + clearScreen(); + + setFontSize(FONT_MEDIUM); + + // Draw MMDVM logo + displayBitmap(0U, 0U, "MMDVM_sm.bmp"); + + setForeground(COLOUR_RED); + + gotoPosPixel(18U, 55U); + displayText(text); + + gotoPosPixel(18U, 90U); + displayText("ERROR"); + + setForeground(COLOUR_BLACK); +} + void CTFTSerial::setLockout() { // Clear the screen diff --git a/TFTSerial.h b/TFTSerial.h index ad04b6d..6378379 100644 --- a/TFTSerial.h +++ b/TFTSerial.h @@ -34,6 +34,7 @@ public: virtual void setIdle(); + virtual void setError(const char* text); virtual void setLockout(); virtual void setDStar();