diff --git a/CASTInfo.cpp b/CASTInfo.cpp index 071f3205..1c347cca 100644 --- a/CASTInfo.cpp +++ b/CASTInfo.cpp @@ -42,11 +42,11 @@ void CCASTInfo::setIdleInt() unsigned char info[100U]; CNetworkInfo* m_network; - passCounter ++; + passCounter++; if (passCounter > 253U) networkInfoInitialized = false; - if (! networkInfoInitialized) { + if (!networkInfoInitialized) { //LogMessage("Initialize CNetworkInfo"); info[0]=0; m_network = new CNetworkInfo; @@ -60,8 +60,6 @@ void CCASTInfo::setIdleInt() networkInfoInitialized = true; passCounter = 0; } - - } void CCASTInfo::setErrorInt(const char* text) diff --git a/CASTInfo.h b/CASTInfo.h index 41e3955f..07401970 100644 --- a/CASTInfo.h +++ b/CASTInfo.h @@ -41,7 +41,7 @@ class CCASTInfo : public CDisplay virtual void setErrorInt(const char* text); virtual void setLockoutInt(); virtual void setQuitInt(); - virtual void setFMInt(); + virtual void setFMInt(); virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); virtual void clearDStarInt(); diff --git a/Display.h b/Display.h index 109b0ca2..314c9dbc 100644 --- a/Display.h +++ b/Display.h @@ -50,7 +50,7 @@ class CDisplay void clearDStar(); void writeDMR(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); - void writeDMR(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type); + void writeDMR(unsigned int slotNo, const CUserDBentry& src, bool group, const std::string& dst, const char* type); void writeDMRRSSI(unsigned int slotNo, unsigned char rssi); void writeDMRBER(unsigned int slotNo, float ber); void writeDMRTA(unsigned int slotNo, const unsigned char* talkerAlias, const char* type); @@ -67,7 +67,7 @@ class CDisplay void clearP25(); void writeNXDN(const char* source, bool group, unsigned int dest, const char* type); - void writeNXDN(const class CUserDBentry& source, bool group, unsigned int dest, const char* type); + void writeNXDN(const CUserDBentry& source, bool group, unsigned int dest, const char* type); void writeNXDNRSSI(unsigned char rssi); void writeNXDNBER(float ber); void clearNXDN(); @@ -101,7 +101,7 @@ class CDisplay virtual void clearDStarInt() = 0; virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type) = 0; - virtual int writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type); + virtual int writeDMRIntEx(unsigned int slotNo, const CUserDBentry& src, bool group, const std::string& dst, const char* type); virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi); virtual void writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type); virtual void writeDMRBERInt(unsigned int slotNo, float ber); @@ -118,7 +118,7 @@ class CDisplay virtual void clearP25Int() = 0; virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type) = 0; - virtual int writeNXDNIntEx(const class CUserDBentry& source, bool group, unsigned int dest, const char* type); + virtual int writeNXDNIntEx(const CUserDBentry& source, bool group, unsigned int dest, const char* type); virtual void writeNXDNRSSIInt(unsigned char rssi); virtual void writeNXDNBERInt(float ber); virtual void clearNXDNInt() = 0; diff --git a/LCDproc.h b/LCDproc.h index aee82142..b702493d 100644 --- a/LCDproc.h +++ b/LCDproc.h @@ -28,51 +28,51 @@ class CLCDproc : public CDisplay { public: - CLCDproc(std::string address, unsigned int port, unsigned short localPort, const std::string& callsign, unsigned int dmrid, bool displayClock, bool utc, bool duplex, bool dimOnIdle); - virtual ~CLCDproc(); + CLCDproc(std::string address, unsigned int port, unsigned short localPort, const std::string& callsign, unsigned int dmrid, bool displayClock, bool utc, bool duplex, bool dimOnIdle); + virtual ~CLCDproc(); - virtual bool open(); + virtual bool open(); - virtual void close(); + virtual void close(); protected: - virtual void setIdleInt(); - virtual void setErrorInt(const char* text); - virtual void setLockoutInt(); - virtual void setQuitInt(); - virtual void setFMInt(); + virtual void setIdleInt(); + virtual void setErrorInt(const char* text); + virtual void setLockoutInt(); + virtual void setQuitInt(); + virtual void setFMInt(); - virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); - virtual void writeDStarRSSIInt(unsigned char rssi); - virtual void clearDStarInt(); + virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); + virtual void writeDStarRSSIInt(unsigned char rssi); + virtual void clearDStarInt(); - virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); - virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi); - virtual void clearDMRInt(unsigned int slotNo); + virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); + virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi); + virtual void clearDMRInt(unsigned int slotNo); - virtual void writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); - virtual void writeFusionRSSIInt(unsigned char rssi); - virtual void clearFusionInt(); + virtual void writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); + virtual void writeFusionRSSIInt(unsigned char rssi); + virtual void clearFusionInt(); - virtual void writeP25Int(const char* source, bool group, unsigned int dest, const char* type); - virtual void writeP25RSSIInt(unsigned char rssi); - virtual void clearP25Int(); + virtual void writeP25Int(const char* source, bool group, unsigned int dest, const char* type); + virtual void writeP25RSSIInt(unsigned char rssi); + virtual void clearP25Int(); - virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type); - virtual void writeNXDNRSSIInt(unsigned char rssi); - virtual void clearNXDNInt(); + virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type); + virtual void writeNXDNRSSIInt(unsigned char rssi); + virtual void clearNXDNInt(); - virtual void writeM17Int(const char* source, const char* dest, const char* type); - virtual void writeM17RSSIInt(unsigned char rssi); - virtual void clearM17Int(); + virtual void writeM17Int(const char* source, const char* dest, const char* type); + virtual void writeM17RSSIInt(unsigned char rssi); + virtual void clearM17Int(); - virtual void writePOCSAGInt(uint32_t ric, const std::string& message); - virtual void clearPOCSAGInt(); + virtual void writePOCSAGInt(uint32_t ric, const std::string& message); + virtual void clearPOCSAGInt(); - virtual void writeCWInt(); - virtual void clearCWInt(); + virtual void writeCWInt(); + virtual void clearCWInt(); - virtual void clockInt(unsigned int ms); + virtual void clockInt(unsigned int ms); private: std::string m_address; diff --git a/Nextion.cpp b/Nextion.cpp index 89dc30e8..a48aa71d 100644 --- a/Nextion.cpp +++ b/Nextion.cpp @@ -137,7 +137,7 @@ void CNextion::setIdleInt() sendCommand("page MMDVM"); sendCommandAction(1U); - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(command, "dim=%u", m_idleBrightness); sendCommand(command); } @@ -203,7 +203,7 @@ void CNextion::setErrorInt(const char* text) sendCommandAction(1U); char command[20]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(command, "dim=%u", m_brightness); sendCommand(command); } @@ -226,7 +226,7 @@ void CNextion::setLockoutInt() sendCommandAction(1U); char command[20]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(command, "dim=%u", m_brightness); sendCommand(command); } @@ -245,7 +245,7 @@ void CNextion::setQuitInt() sendCommandAction(1U); char command[100]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(command, "dim=%u", m_idleBrightness); sendCommand(command); } @@ -268,7 +268,7 @@ void CNextion::setFMInt() sendCommandAction(1U); char command[20]; - if (m_brightness > 0) { + if (m_brightness > 0U) { ::sprintf(command, "dim=%u", m_brightness); sendCommand(command); } @@ -295,7 +295,7 @@ void CNextion::writeDStarInt(const char* my1, const char* my2, const char* your, } char text[50U]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(text, "dim=%u", m_brightness); sendCommand(text); } @@ -396,7 +396,7 @@ void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro } char text[50U]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(text, "dim=%u", m_brightness); sendCommand(text); } @@ -614,7 +614,7 @@ void CNextion::writeFusionInt(const char* source, const char* dest, unsigned cha char text[30U]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(text, "dim=%u", m_brightness); sendCommand(text); } @@ -693,7 +693,7 @@ void CNextion::writeP25Int(const char* source, bool group, unsigned int dest, co } char text[30U]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(text, "dim=%u", m_brightness); sendCommand(text); } @@ -765,7 +765,7 @@ void CNextion::writeNXDNInt(const char* source, bool group, unsigned int dest, c } char text[30U]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(text, "dim=%u", m_brightness); sendCommand(text); } @@ -838,7 +838,7 @@ void CNextion::writeM17Int(const char* source, const char* dest, const char* typ } char text[30U]; - if (m_brightness > 0) { + if (m_brightness > 0U) { ::sprintf(text, "dim=%u", m_brightness); sendCommand(text); } @@ -907,7 +907,7 @@ void CNextion::writePOCSAGInt(uint32_t ric, const std::string& message) } char text[200U]; - if (m_brightness>0) { + if (m_brightness > 0U) { ::sprintf(text, "dim=%u", m_brightness); sendCommand(text); } @@ -978,13 +978,14 @@ void CNextion::close() void CNextion::sendCommandAction(unsigned int status) { - if (!(m_screenLayout & LAYOUT_DIY)) + if (!(m_screenLayout & LAYOUT_DIY)) return; - char text[30U]; - ::sprintf(text, "MMDVM.status.val=%d", status); - sendCommand(text); - sendCommand("click S0,1"); + char text[30U]; + ::sprintf(text, "MMDVM.status.val=%d", status); + sendCommand(text); + + sendCommand("click S0,1"); } void CNextion::sendCommand(const char* command) @@ -993,8 +994,10 @@ void CNextion::sendCommand(const char* command) m_serial->write((unsigned char*)command, (unsigned int)::strlen(command)); m_serial->write((unsigned char*)"\xFF\xFF\xFF", 3U); + // Since we just firing commands at the display, and not listening for the response, // we must add a bit of a delay to allow the display to process the commands, else some are getting mangled. // 10 ms is just a guess, but seems to be sufficient. - CThread::sleep(10U); + CThread::sleep(10U); } + diff --git a/Nextion.h b/Nextion.h index d4405263..27820972 100644 --- a/Nextion.h +++ b/Nextion.h @@ -29,87 +29,87 @@ class CNextion : public CDisplay { public: - CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF); - virtual ~CNextion(); + CNextion(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool displayClock, bool utc, unsigned int idleBrightness, unsigned int screenLayout, unsigned int txFrequency, unsigned int rxFrequency, bool displayTempInF); + virtual ~CNextion(); - virtual bool open(); + virtual bool open(); - virtual void close(); + virtual void close(); protected: - virtual void setIdleInt(); - virtual void setErrorInt(const char* text); - virtual void setLockoutInt(); - virtual void setQuitInt(); - virtual void setFMInt(); - - virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); - virtual void writeDStarRSSIInt(unsigned char rssi); - virtual void writeDStarBERInt(float ber); - virtual void clearDStarInt(); - - virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); - virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi); - virtual void writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type); - virtual void writeDMRBERInt(unsigned int slotNo, float ber); - virtual void clearDMRInt(unsigned int slotNo); - - virtual void writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); - virtual void writeFusionRSSIInt(unsigned char rssi); - virtual void writeFusionBERInt(float ber); - virtual void clearFusionInt(); - - virtual void writeP25Int(const char* source, bool group, unsigned int dest, const char* type); - virtual void writeP25RSSIInt(unsigned char rssi); - virtual void writeP25BERInt(float ber); - virtual void clearP25Int(); - - virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type); - virtual void writeNXDNRSSIInt(unsigned char rssi); - virtual void writeNXDNBERInt(float ber); - virtual void clearNXDNInt(); - - virtual void writeM17Int(const char* source, const char* dest, const char* type); - virtual void writeM17RSSIInt(unsigned char rssi); - virtual void writeM17BERInt(float ber); - virtual void clearM17Int(); - - virtual void writePOCSAGInt(uint32_t ric, const std::string& message); - virtual void clearPOCSAGInt(); - - virtual void writeCWInt(); - virtual void clearCWInt(); - - virtual void clockInt(unsigned int ms); + virtual void setIdleInt(); + virtual void setErrorInt(const char* text); + virtual void setLockoutInt(); + virtual void setQuitInt(); + virtual void setFMInt(); + + virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); + virtual void writeDStarRSSIInt(unsigned char rssi); + virtual void writeDStarBERInt(float ber); + virtual void clearDStarInt(); + + virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); + virtual void writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi); + virtual void writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type); + virtual void writeDMRBERInt(unsigned int slotNo, float ber); + virtual void clearDMRInt(unsigned int slotNo); + + virtual void writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); + virtual void writeFusionRSSIInt(unsigned char rssi); + virtual void writeFusionBERInt(float ber); + virtual void clearFusionInt(); + + virtual void writeP25Int(const char* source, bool group, unsigned int dest, const char* type); + virtual void writeP25RSSIInt(unsigned char rssi); + virtual void writeP25BERInt(float ber); + virtual void clearP25Int(); + + virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type); + virtual void writeNXDNRSSIInt(unsigned char rssi); + virtual void writeNXDNBERInt(float ber); + virtual void clearNXDNInt(); + + virtual void writeM17Int(const char* source, const char* dest, const char* type); + virtual void writeM17RSSIInt(unsigned char rssi); + virtual void writeM17BERInt(float ber); + virtual void clearM17Int(); + + virtual void writePOCSAGInt(uint32_t ric, const std::string& message); + virtual void clearPOCSAGInt(); + + virtual void writeCWInt(); + virtual void clearCWInt(); + + virtual void clockInt(unsigned int ms); private: - std::string m_callsign; - std::string m_ipaddress; - unsigned int m_dmrid; - ISerialPort* m_serial; - unsigned int m_brightness; - unsigned char m_mode; - bool m_displayClock; - bool m_utc; - unsigned int m_idleBrightness; - unsigned int m_screenLayout; - CTimer m_clockDisplayTimer; - unsigned int m_rssiAccum1; - unsigned int m_rssiAccum2; - float m_berAccum1; - float m_berAccum2; - unsigned int m_rssiCount1; - unsigned int m_rssiCount2; - unsigned int m_berCount1; - unsigned int m_berCount2; - unsigned int m_txFrequency; - unsigned int m_rxFrequency; - double m_fl_txFrequency; - double m_fl_rxFrequency; - bool m_displayTempInF; - - void sendCommand(const char* command); - void sendCommandAction(unsigned int status); + std::string m_callsign; + std::string m_ipaddress; + unsigned int m_dmrid; + ISerialPort* m_serial; + unsigned int m_brightness; + unsigned char m_mode; + bool m_displayClock; + bool m_utc; + unsigned int m_idleBrightness; + unsigned int m_screenLayout; + CTimer m_clockDisplayTimer; + unsigned int m_rssiAccum1; + unsigned int m_rssiAccum2; + float m_berAccum1; + float m_berAccum2; + unsigned int m_rssiCount1; + unsigned int m_rssiCount2; + unsigned int m_berCount1; + unsigned int m_berCount2; + unsigned int m_txFrequency; + unsigned int m_rxFrequency; + double m_fl_txFrequency; + double m_fl_rxFrequency; + bool m_displayTempInF; + + void sendCommand(const char* command); + void sendCommandAction(unsigned int status); }; #endif diff --git a/NullDisplay.h b/NullDisplay.h index c53dc083..e49eac36 100644 --- a/NullDisplay.h +++ b/NullDisplay.h @@ -26,19 +26,19 @@ class CNullDisplay : public CDisplay { public: - CNullDisplay(); - virtual ~CNullDisplay(); + CNullDisplay(); + virtual ~CNullDisplay(); - virtual bool open(); + virtual bool open(); - virtual void close(); + virtual void close(); protected: virtual void setIdleInt(); virtual void setErrorInt(const char* text); virtual void setLockoutInt(); virtual void setQuitInt(); - virtual void setFMInt(); + virtual void setFMInt(); virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); virtual void clearDStarInt(); diff --git a/OLED.cpp b/OLED.cpp index dfb133c9..57a2b2eb 100644 --- a/OLED.cpp +++ b/OLED.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2023 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,7 @@ #include "Log.h" static bool networkInfoInitialized = false; -static unsigned char passCounter = 0; +static unsigned char passCounter = 0U; //Logo MMDVM for Idle Screen static unsigned char logo_glcd_bmp[] = @@ -86,7 +86,7 @@ static unsigned char logo_dmr_bmp[] = }; //Logo Fusion 128x16 -const unsigned char logo_fusion_bmp [] = +const unsigned char logo_fusion_bmp[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -107,7 +107,7 @@ const unsigned char logo_fusion_bmp [] = }; //Logo P25 128x16px -const unsigned char logo_P25_bmp [] = +const unsigned char logo_P25_bmp[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, @@ -128,7 +128,7 @@ const unsigned char logo_P25_bmp [] = }; // Logo NXDN_sm, 128x16px -const unsigned char logo_NXDN_bmp [] = +const unsigned char logo_NXDN_bmp[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -149,7 +149,7 @@ const unsigned char logo_NXDN_bmp [] = }; // Logo M17_sm, 128x16px -const unsigned char logo_M17_bmp [] = +const unsigned char logo_M17_bmp[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -170,7 +170,7 @@ const unsigned char logo_M17_bmp [] = }; // Logo POCASG/DAPNET, 128x16px -const unsigned char logo_POCSAG_bmp [] = +const unsigned char logo_POCSAG_bmp[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x7f, 0xfe, 0x03, 0xfe, 0xfe, 0x03, 0xdf, 0xf6, 0x00, 0x00, 0x1f, 0xff, @@ -191,6 +191,7 @@ const unsigned char logo_POCSAG_bmp [] = }; COLED::COLED(unsigned char displayType, unsigned char displayBrightness, bool displayInvert, bool displayScroll, bool displayRotate, bool displayLogoScreensaver, bool duplex) : +CDisplay(), m_displayType(displayType), m_displayBrightness(displayBrightness), m_displayInvert(displayInvert), @@ -198,7 +199,6 @@ m_displayScroll(displayScroll), m_displayRotate(displayRotate), m_displayLogoScreensaver(displayLogoScreensaver), m_duplex(duplex), -//m_duplex(true), // uncomment to force duplex display for testing! m_ipaddress(), m_display() { @@ -210,641 +210,642 @@ COLED::~COLED() bool COLED::open() { + // SPI + if (m_display.oled_is_spi_proto(m_displayType)) { + // SPI change parameters to fit to your LCD + if (!m_display.init(OLED_SPI_DC, OLED_SPI_RESET, OLED_SPI_CS, m_displayType)) + return false; + } else { + // I2C change parameters to fit to your LCD + if (!m_display.init(OLED_I2C_RESET, m_displayType)) + return false; + } + + m_display.begin(); + + m_display.invertDisplay(m_displayInvert ? 1 : 0); + if (m_displayBrightness > 0U) + m_display.setBrightness(m_displayBrightness); + + if (m_displayRotate > 0U) { + m_display.sendCommand(0xC0); + m_display.sendCommand(0xA0); + } + + // Init done + m_display.setTextWrap(false); // disable text wrap as default + m_display.clearDisplay(); // clears the screen buffer + m_display.display(); // display it (clear display) - // SPI - if (m_display.oled_is_spi_proto(m_displayType)) - { - // SPI change parameters to fit to your LCD - if ( !m_display.init(OLED_SPI_DC,OLED_SPI_RESET,OLED_SPI_CS, m_displayType) ) - return false; - } - else - { - // I2C change parameters to fit to your LCD - if ( !m_display.init(OLED_I2C_RESET, m_displayType) ) - return false; - } - - - m_display.begin(); - - m_display.invertDisplay(m_displayInvert ? 1 : 0); - if (m_displayBrightness > 0U) - m_display.setBrightness(m_displayBrightness); - - if (m_displayRotate > 0U) { - m_display.sendCommand(0xC0); - m_display.sendCommand(0xA0); - } - - // init done - m_display.setTextWrap(false); // disable text wrap as default - m_display.clearDisplay(); // clears the screen buffer - m_display.display(); // display it (clear display) - - OLED_statusbar(); - m_display.setCursor(0,OLED_LINE4); - m_display.setTextSize(1); - m_display.print(" -Initializing-"); - m_display.display(); - - return true; + OLED_statusbar(); + + m_display.setCursor(0, OLED_LINE4); + m_display.setTextSize(1); + m_display.print(" -Initializing-"); + m_display.display(); + + return true; } float COLED::readTemperature(const std::string& filePath) { - std::ifstream file(filePath); - if (!file.is_open()) { - std::cerr << "Error: Could not open file " << filePath << std::endl; - return -1.0F; // Return a negative value to indicate that CPU temp is not available - } + std::ifstream file(filePath); + if (!file.is_open()) { + std::cerr << "Error: Could not open file " << filePath << std::endl; + return -1.0F; // Return a negative value to indicate that CPU temp is not available + } - float temperature; - file >> temperature; + float temperature; + file >> temperature; - file.close(); + file.close(); - return temperature / 1000.0F; // The temperature is stored in millidegrees Celsius, so a bit of conversion + return temperature / 1000.0F; // The temperature is stored in millidegrees Celsius, so a bit of conversion } void COLED::setIdleInt() { - m_mode = MODE_IDLE; + m_mode = MODE_IDLE; - m_display.clearDisplay(); - OLED_statusbar(); + m_display.clearDisplay(); - if (m_displayScroll && m_displayLogoScreensaver) - m_display.startscrolldiagleft(0x00,0x0f); //the MMDVM logo scrolls the whole screen + OLED_statusbar(); - unsigned char info[100U]; - CNetworkInfo* m_network; + if (m_displayScroll && m_displayLogoScreensaver) + m_display.startscrolldiagleft(0x00, 0x0f); //the MMDVM logo scrolls the whole screen - passCounter ++; - if (passCounter > 253U) - networkInfoInitialized = false; + unsigned char info[100U]; + CNetworkInfo* m_network; - if (! networkInfoInitialized) { - //LogMessage("Initialize CNetworkInfo"); - info[0]=0; - m_network = new CNetworkInfo; - m_network->getNetworkInterface(info); - m_ipaddress = (char*)info; - delete m_network; + passCounter++; + if (passCounter > 253U) + networkInfoInitialized = false; - networkInfoInitialized = true; - passCounter = 0; - } + if (!networkInfoInitialized) { + //LogMessage("Initialize CNetworkInfo"); + info[0] = 0; + m_network = new CNetworkInfo; + m_network->getNetworkInterface(info); + m_ipaddress = (char*)info; + delete m_network; - // Let's let the users know if they are in Auto-AP mode... - if (m_ipaddress.find("wlan0_ap") != std::string::npos) { - size_t pos = m_ipaddress.find("wlan0_ap"); - if (pos != std::string::npos) { - m_ipaddress.erase(pos, 9); // remove redundant/superfluous "wlan0_ap" from string - } - // Read ssid value from /etc/hostapd.conf if it exists... - std::string ssid; - std::ifstream configFile("/etc/hostapd/hostapd.conf"); - if (configFile.is_open()) { - std::string line; - while (std::getline(configFile, line)) { - if (line.find("ssid=") != std::string::npos) { - std::istringstream iss(line); - std::string key, value; - if (std::getline(iss, key, '=') && std::getline(iss, value)) { - ssid = value; - break; - } - } - } - configFile.close(); - } else { - ssid = "Unknown"; // `/etc/hostapd.conf` does not exist... + networkInfoInitialized = true; + passCounter = 0U; } - if (m_displayLogoScreensaver) { - m_display.setCursor(0, OLED_LINE3); - m_display.setTextSize(1); - m_display.printf("Auto-AP Running..."); - m_display.setCursor(0, OLED_LINE5); - m_display.setTextSize(1); - m_display.printf("SSID: %s", ssid.c_str()); - m_display.setCursor(0, OLED_LINE6); - m_display.setTextSize(1); - m_display.printf("IP: %s", m_ipaddress.c_str()); + // Let's let the users know if they are in Auto-AP mode... + if (m_ipaddress.find("wlan0_ap") != std::string::npos) { + size_t pos = m_ipaddress.find("wlan0_ap"); + if (pos != std::string::npos) + m_ipaddress.erase(pos, 9); // remove redundant/superfluous "wlan0_ap" from string + + // Read ssid value from /etc/hostapd.conf if it exists... + std::string ssid; + std::ifstream configFile("/etc/hostapd/hostapd.conf"); + if (configFile.is_open()) { + std::string line; + while (std::getline(configFile, line)) { + if (line.find("ssid=") != std::string::npos) { + std::istringstream iss(line); + std::string key, value; + if (std::getline(iss, key, '=') && std::getline(iss, value)) { + ssid = value; + break; + } + } + } + + configFile.close(); + } else { + ssid = "Unknown"; // `/etc/hostapd.conf` does not exist... + } + + if (m_displayLogoScreensaver) { + m_display.setCursor(0, OLED_LINE3); + m_display.setTextSize(1); + m_display.printf("Auto-AP Running..."); + m_display.setCursor(0, OLED_LINE5); + m_display.setTextSize(1); + m_display.printf("SSID: %s", ssid.c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.setTextSize(1); + m_display.printf("IP: %s", m_ipaddress.c_str()); + } + } else { // Connected to network - no Auto-AP mode; normal display layout... + if (m_displayLogoScreensaver) { + m_display.setCursor(0, OLED_LINE2); + m_display.setTextSize(1); + m_display.print(" -IDLE-"); + m_display.setCursor(0, OLED_LINE4); + m_display.printf("%s", m_ipaddress.c_str()); + + // Display temperature + float tempCelsius = readTemperature("/sys/class/thermal/thermal_zone0/temp"); + if (tempCelsius >= 0.0F) { + // Convert to Fahrenheit + float tempFahrenheit = (tempCelsius * 9.0F / 5.0F) + 32.0F; + m_display.setCursor(0, OLED_LINE5); + m_display.setTextSize(1); + m_display.printf("Temp: %.0fF / %.0fC ", tempFahrenheit, tempCelsius); + } + } } - } else { // Connected to network - no Auto-AP mode; normal display layout... - if (m_displayLogoScreensaver) { - m_display.setCursor(0,OLED_LINE2); - m_display.setTextSize(1); - m_display.print(" -IDLE-"); - m_display.setCursor(0, OLED_LINE4); - m_display.printf("%s", m_ipaddress.c_str()); - - // Display temperature - float tempCelsius = readTemperature("/sys/class/thermal/thermal_zone0/temp"); - if (tempCelsius >= 0.0F) { - // Convert to Fahrenheit - float tempFahrenheit = (tempCelsius * 9.0F / 5.0F) + 32.0F; - m_display.setCursor(0, OLED_LINE5); - m_display.setTextSize(1); - m_display.printf("Temp: %.0fF / %.0fC ", tempFahrenheit, tempCelsius); - } - } - } - m_display.display(); + m_display.display(); } void COLED::setErrorInt(const char* text) { - m_mode = MODE_ERROR; + m_mode = MODE_ERROR; - m_display.clearDisplay(); - OLED_statusbar(); + m_display.clearDisplay(); + OLED_statusbar(); - m_display.setTextWrap(true); // text wrap temorally enable - m_display.setCursor(0,OLED_LINE1); - m_display.printf("%s\n",text); - m_display.setTextWrap(false); + m_display.setTextWrap(true); // text wrap temorally enable + m_display.setCursor(0, OLED_LINE1); + m_display.printf("%s\n", text); + m_display.setTextWrap(false); - m_display.display(); + m_display.display(); } void COLED::setLockoutInt() { - m_mode = MODE_LOCKOUT; + m_mode = MODE_LOCKOUT; - m_display.clearDisplay(); - OLED_statusbar(); + m_display.clearDisplay(); + OLED_statusbar(); - m_display.setCursor(0,30); - m_display.setTextSize(3); - m_display.print("Lockout"); + m_display.setCursor(0, 30); + m_display.setTextSize(3); + m_display.print("Lockout"); - m_display.setTextSize(1); - m_display.display(); + m_display.setTextSize(1); + m_display.display(); } void COLED::setQuitInt() { - m_mode = MODE_QUIT; + m_mode = MODE_QUIT; - m_display.clearDisplay(); - OLED_statusbar(); + m_display.clearDisplay(); + OLED_statusbar(); - m_display.setCursor(0,30); - m_display.setTextSize(2); - m_display.print(" Stopping"); + m_display.setCursor(0, 30); + m_display.setTextSize(2); + m_display.print(" Stopping"); - m_display.setTextSize(1); - m_display.display(); - sleep(2); + m_display.setTextSize(1); + m_display.display(); + sleep(2); } void COLED::setFMInt() { - m_mode = MODE_FM; + m_mode = MODE_FM; - m_display.clearDisplay(); - OLED_statusbar(); + m_display.clearDisplay(); + OLED_statusbar(); - m_display.setCursor(0,30); - m_display.setTextSize(3); - m_display.print("FM"); + m_display.setCursor(0, 30); + m_display.setTextSize(3); + m_display.print("FM"); - m_display.setTextSize(1); - m_display.display(); + m_display.setTextSize(1); + m_display.display(); } void COLED::writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector) { - m_mode = MODE_DSTAR; + m_mode = MODE_DSTAR; + + m_display.clearDisplay(); + m_display.fillRect(0, OLED_LINE3, m_display.width(), m_display.height(), BLACK); //clear everything beneath logo - m_display.clearDisplay(); - m_display.fillRect(0,OLED_LINE3,m_display.width(),m_display.height(),BLACK); //clear everything beneath logo + m_display.setCursor(0, OLED_LINE3); + m_display.printf("%s %.8s/%4.4s", type, my1, my2); - m_display.setCursor(0,OLED_LINE3); - m_display.printf("%s %.8s/%4.4s",type,my1,my2); + m_display.setCursor(0, OLED_LINE4); + m_display.printf("-> %.8s", your); - m_display.setCursor(0,OLED_LINE4); - m_display.printf("-> %.8s",your); + m_display.setCursor(0, OLED_LINE5); + m_display.printf("via %.8s", reflector); - m_display.setCursor(0,OLED_LINE5); - m_display.printf("via %.8s",reflector); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); + OLED_statusbar(); - OLED_statusbar(); - m_display.display(); + m_display.display(); } void COLED::clearDStarInt() { - m_display.fillRect(0,OLED_LINE3, m_display.width(),m_display.height(),BLACK); //clear everything beneath the logo + m_display.fillRect(0, OLED_LINE3, m_display.width(),m_display.height(), BLACK); //clear everything beneath the logo - m_display.setCursor(40,OLED_LINE3); - m_display.print("Standby"); + m_display.setCursor(40, OLED_LINE3); + m_display.print("Standby"); - m_display.setCursor(0,OLED_LINE5); - m_display.printf("%s",m_ipaddress.c_str()); + m_display.setCursor(0, OLED_LINE5); + m_display.printf("%s", m_ipaddress.c_str()); - m_display.display(); + m_display.display(); } -void COLED::writeDMRInt(unsigned int slotNo,const std::string& src,bool group,const std::string& dst,const char* type) +void COLED::writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type) { - CUserDBentry tmp; + CUserDB entry tmp; - tmp.set(keyCALLSIGN, src); - writeDMRIntEx(slotNo, tmp, group, dst, type); + tmp.set(keyCALLSIGN, src); + + writeDMRIntEx(slotNo, tmp, group, dst, type); } #define CALLandNAME(u) ((u).get(keyCALLSIGN) + " " + (u).get(keyFIRST_NAME)) -int COLED::writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type) -{ - - if (m_mode != MODE_DMR) { - m_display.clearDisplay(); - m_mode = MODE_DMR; - clearDMRInt(slotNo); - } - // if both slots, use lines 2-3 for slot 1, lines 4-5 for slot 2 - // if single slot, use lines 2-3 - if ( m_duplex ) { - - if (slotNo == 1U) { - m_display.fillRect(0,OLED_LINE2,m_display.width(),40,BLACK); - m_display.setCursor(0,OLED_LINE2); - m_display.printf("%s",CALLandNAME(src).c_str()); - m_display.setCursor(0,OLED_LINE3); - m_display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); - } - else - { - m_display.fillRect(0,OLED_LINE4,m_display.width(),40,BLACK); - m_display.setCursor(0,OLED_LINE4); - m_display.printf("%s",CALLandNAME(src).c_str()); - m_display.setCursor(0,OLED_LINE5); - m_display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); - } - - m_display.fillRect(0,OLED_LINE6,m_display.width(),20,BLACK); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); - } - else - { - m_display.fillRect(0,OLED_LINE2,m_display.width(),m_display.height(),BLACK); - m_display.setCursor(0,OLED_LINE2); - m_display.printf("%s",CALLandNAME(src).c_str()); - m_display.setCursor(0,OLED_LINE3); - m_display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); - m_display.setCursor(0,OLED_LINE4); - m_display.printf("%s",src.get(keyCITY).c_str()); - m_display.setCursor(0,OLED_LINE5); - m_display.printf("%s",src.get(keySTATE).c_str()); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",src.get(keyCOUNTRY).c_str()); - } - - OLED_statusbar(); - m_display.display(); - - // must be 0, to avoid calling writeDMRInt() from CDisplay::writeDMR() - return 0; +int COLED::writeDMRIntEx(unsigned int slotNo, const CUserDBentry& src, bool group, const std::string& dst, const char* type) +{ + if (m_mode != MODE_DMR) { + m_display.clearDisplay(); + m_mode = MODE_DMR; + clearDMRInt(slotNo); + } + + // if both slots, use lines 2-3 for slot 1, lines 4-5 for slot 2 + // if single slot, use lines 2-3 + if (m_duplex) { + if (slotNo == 1U) { + m_display.fillRect(0, OLED_LINE2, m_display.width(), 40, BLACK); + m_display.setCursor(0, OLED_LINE2); + m_display.printf("%s", CALLandNAME(src).c_str()); + m_display.setCursor(0, OLED_LINE3); + m_display.printf("Slot: %i %s %s%s", slotNo, type.c_str(), group ? "TG: " : "", dst.c_str()); + } else { + m_display.fillRect(0, OLED_LINE4, m_display.width(), 40, BLACK); + m_display.setCursor(0, OLED_LINE4); + m_display.printf("%s", CALLandNAME(src).c_str()); + m_display.setCursor(0, OLED_LINE5); + m_display.printf("Slot: %i %s %s%s", slotNo, type.c_str(), group ? "TG: " : "", dst.c_str()); + } + + m_display.fillRect(0, OLED_LINE6, m_display.width(), 20, BLACK); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); + } else { + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.setCursor(0, OLED_LINE2); + m_display.printf("%s", CALLandNAME(src).c_str()); + m_display.setCursor(0, OLED_LINE3); + m_display.printf("Slot: %i %s %s%s", slotNo, type.c_str(), group ? "TG: " : "", dst.c_str()); + m_display.setCursor(0, OLED_LINE4); + m_display.printf("%s", src.get(keyCITY).c_str()); + m_display.setCursor(0, OLED_LINE5); + m_display.printf("%s", src.get(keySTATE).c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", src.get(keyCOUNTRY).c_str()); + } + + OLED_statusbar(); + + m_display.display(); + + // must be 0, to avoid calling writeDMRInt() from CDisplay::writeDMR() + return 0; } void COLED::clearDMRInt(unsigned int slotNo) { - // if both slots, use lines 2-3 for slot 1, lines 4-5 for slot 2 - // if single slot, use lines 2-3 - if ( m_duplex ){ - if (slotNo == 1U) { - m_display.fillRect(0, OLED_LINE3, m_display.width(), 40, BLACK); - m_display.setCursor(0,OLED_LINE3); - m_display.print("Slot: 1 Standby"); - } - else { - m_display.fillRect(0, OLED_LINE5, m_display.width(), 40, BLACK); - m_display.setCursor(0, OLED_LINE5); - m_display.print("Slot: 2 Standby"); - } - } - else { - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(0,OLED_LINE3); - m_display.printf("Slot: %i Standby",slotNo); - } - - m_display.fillRect(0, OLED_LINE6, m_display.width(), 20, BLACK); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); - m_display.display(); + // if both slots, use lines 2-3 for slot 1, lines 4-5 for slot 2 + // if single slot, use lines 2-3 + if (m_duplex){ + if (slotNo == 1U) { + m_display.fillRect(0, OLED_LINE3, m_display.width(), 40, BLACK); + m_display.setCursor(0, OLED_LINE3); + m_display.print("Slot: 1 Standby"); + } else { + m_display.fillRect(0, OLED_LINE5, m_display.width(), 40, BLACK); + m_display.setCursor(0, OLED_LINE5); + m_display.print("Slot: 2 Standby"); + } + } else { + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.setCursor(0, OLED_LINE3); + m_display.printf("Slot: %i Standby", slotNo); + } + + m_display.fillRect(0, OLED_LINE6, m_display.width(), 20, BLACK); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); + + m_display.display(); } void COLED::writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin) { - m_mode = MODE_YSF; + m_mode = MODE_YSF; - m_display.clearDisplay(); - m_display.fillRect(0,OLED_LINE2,m_display.width(),m_display.height(),BLACK); + m_display.clearDisplay(); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(0,OLED_LINE4); - m_display.printf("%s %.10s", type, source); + m_display.setCursor(0, OLED_LINE4); + m_display.printf("%s %.10s", type, source); - m_display.setCursor(0,OLED_LINE5); - m_display.printf(" DG-ID %u", dgid); + m_display.setCursor(0, OLED_LINE5); + m_display.printf(" DG-ID %u", dgid); - OLED_statusbar(); + OLED_statusbar(); - m_display.display(); + m_display.display(); } void COLED::clearFusionInt() { - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(40,OLED_LINE4); - m_display.print("Standby"); + m_display.setCursor(40, OLED_LINE4); + m_display.print("Standby"); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); - m_display.display(); + m_display.display(); } void COLED::writeP25Int(const char* source, bool group, unsigned int dest, const char* type) { - m_mode = MODE_P25; + m_mode = MODE_P25; - m_display.clearDisplay(); - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.clearDisplay(); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(0,OLED_LINE3); - m_display.printf("%s %.10s", type, source); + m_display.setCursor(0, OLED_LINE3); + m_display.printf("%s %.10s", type, source); - m_display.setCursor(0,OLED_LINE4); - m_display.printf(" %s%u", group ? "TG" : "", dest); + m_display.setCursor(0, OLED_LINE4); + m_display.printf(" %s%u", group ? "TG" : "", dest); - OLED_statusbar(); - m_display.display(); + OLED_statusbar(); + + m_display.display(); } void COLED::clearP25Int() { - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(40,OLED_LINE4); - m_display.print("Standby"); + m_display.setCursor(40, OLED_LINE4); + m_display.print("Standby"); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); - m_display.display(); + m_display.display(); } void COLED::writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type) { - CUserDBentry tmp; + CUserDBentry tmp; + + tmp.set(keyCALLSIGN, source); - tmp.set(keyCALLSIGN, source); - writeNXDNIntEx(tmp, group, dest, type); + writeNXDNIntEx(tmp, group, dest, type); } -int COLED::writeNXDNIntEx(const class CUserDBentry& source, bool group, unsigned int dest, const char* type) +int COLED::writeNXDNIntEx(const CUserDBentry& source, bool group, unsigned int dest, const char* type) { - m_mode = MODE_NXDN; - - m_display.clearDisplay(); - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_mode = MODE_NXDN; - m_display.setCursor(0,OLED_LINE2); - m_display.printf("%s %s", type, CALLandNAME(source).c_str()); + m_display.clearDisplay(); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(0,OLED_LINE3); - m_display.printf(" %s%u", group ? "TG" : "", dest); + m_display.setCursor(0, OLED_LINE2); + m_display.printf("%s %s", type, CALLandNAME(source).c_str()); - m_display.setCursor(0,OLED_LINE4); - m_display.printf("%s",source.get(keyCITY).c_str()); + m_display.setCursor(0, OLED_LINE3); + m_display.printf(" %s%u", group ? "TG" : "", dest); - m_display.setCursor(0,OLED_LINE5); - m_display.printf("%s",source.get(keySTATE).c_str()); + m_display.setCursor(0, OLED_LINE4); + m_display.printf("%s", source.get(keyCITY).c_str()); + + m_display.setCursor(0, OLED_LINE5); + m_display.printf("%s", source.get(keySTATE).c_str()); + + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", source.get(keyCOUNTRY).c_str()); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",source.get(keyCOUNTRY).c_str()); + OLED_statusbar(); - OLED_statusbar(); - m_display.display(); + m_display.display(); - // must be 0, to avoid calling writeNXDNInt() from CDisplay::writeNXDN() - return 0; + // must be 0, to avoid calling writeNXDNInt() from CDisplay::writeNXDN() + return 0; } void COLED::clearNXDNInt() { - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(40,OLED_LINE3); - m_display.print("Standby"); + m_display.setCursor(40, OLED_LINE3); + m_display.print("Standby"); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); - m_display.display(); + m_display.display(); } void COLED::writeM17Int(const char* source, const char* dest, const char* type) { - m_mode = MODE_M17; + m_mode = MODE_M17; - m_display.clearDisplay(); - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.clearDisplay(); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(0,OLED_LINE3); - m_display.printf("from: %s %s", type, source); + m_display.setCursor(0, OLED_LINE3); + m_display.printf("from: %s %s", type, source); - m_display.setCursor(0,OLED_LINE4); - m_display.printf("to: %s", dest); + m_display.setCursor(0, OLED_LINE4); + m_display.printf("to: %s", dest); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); + OLED_statusbar(); - OLED_statusbar(); - m_display.display(); + m_display.display(); } void COLED::clearM17Int() { - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(40,OLED_LINE4); - m_display.print("Standby"); + m_display.setCursor(40, OLED_LINE4); + m_display.print("Standby"); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); - m_display.display(); + m_display.display(); } void COLED::writePOCSAGInt(uint32_t ric, const std::string& message) { - int pos; - int length = message.length(); - std::string rublic; - - // extract rublic index "(xx-xx)" - switch (ric) { - case 4512U: - case 4520U: - if (length) { - std::string::size_type start = message.find("("); - std::string::size_type end = message.find(") "); - if (start != std::string::npos && end != std::string::npos) { - rublic = message.substr(start, end - start + 1); - pos = end + 2; - break; - } - } - /*FALLTHROUGH*/ - default: - rublic = ""; - pos = 0; - break; - } - - // remove double-quotation leading/trailing message - if (length && message.at(pos) == '\"' && message.at(length - 1) == '\"') { - pos++; - length--; - } - - m_mode = MODE_POCSAG; - - m_display.clearDisplay(); - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - - m_display.setCursor(0,OLED_LINE2); - m_display.printf("RIC: %u", ric); - if (!rublic.empty()) { - m_display.printf(" / %s", rublic.c_str()); - } - - m_display.setTextWrap(true); // text wrap temorally enable - m_display.setCursor(0,OLED_LINE3); - // no room to display "MSG: " header - - // due to limitation of AdaFruit_GFX::vprintf() (in ArduiPi_OLED), - // the maximum string length displayed by single printf() call is 63. - // to avoid this, divide POCSAG (max 80 chars) message into some pieces. - while (pos < length) { - int remain = length - pos; - int n = (remain < 40) ? remain : 40; - m_display.printf("%s", message.substr(pos, n).c_str()); - pos += n; - } - m_display.setTextWrap(false); - - OLED_statusbar(); - m_display.display(); + int pos; + int length = message.length(); + std::string rublic; + + // extract rublic index "(xx-xx)" + switch (ric) { + case 4512U: + case 4520U: + if (length) { + std::string::size_type start = message.find("("); + std::string::size_type end = message.find(") "); + if (start != std::string::npos && end != std::string::npos) { + rublic = message.substr(start, end - start + 1); + pos = end + 2; + break; + } + } + /*FALLTHROUGH*/ + default: + rublic = ""; + pos = 0; + break; + } + + // remove double-quotation leading/trailing message + if (length && message.at(pos) == '\"' && message.at(length - 1) == '\"') { + pos++; + length--; + } + + m_mode = MODE_POCSAG; + + m_display.clearDisplay(); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + + m_display.setCursor(0, OLED_LINE2); + m_display.printf("RIC: %u", ric); + if (!rublic.empty()) + m_display.printf(" / %s", rublic.c_str()); + + m_display.setTextWrap(true); // text wrap temorally enable + m_display.setCursor(0, OLED_LINE3); + // no room to display "MSG: " header + + // due to limitation of AdaFruit_GFX::vprintf() (in ArduiPi_OLED), + // the maximum string length displayed by single printf() call is 63. + // to avoid this, divide POCSAG (max 80 chars) message into some pieces. + while (pos < length) { + int remain = length - pos; + int n = (remain < 40) ? remain : 40; + m_display.printf("%s", message.substr(pos, n).c_str()); + pos += n; + } + m_display.setTextWrap(false); + + OLED_statusbar(); + + m_display.display(); } void COLED::clearPOCSAGInt() { - m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); + m_display.fillRect(0, OLED_LINE2, m_display.width(), m_display.height(), BLACK); - m_display.setCursor(40,OLED_LINE3); - m_display.print("Standby"); + m_display.setCursor(40, OLED_LINE3); + m_display.print("Standby"); - m_display.setCursor(0,OLED_LINE6); - m_display.printf("%s",m_ipaddress.c_str()); + m_display.setCursor(0, OLED_LINE6); + m_display.printf("%s", m_ipaddress.c_str()); - m_display.display(); + m_display.display(); } void COLED::writeCWInt() { - m_display.clearDisplay(); + m_display.clearDisplay(); - m_display.setCursor(0,30); - m_display.setTextSize(2); - m_display.print("CW ID TX"); + m_display.setCursor(0, 30); + m_display.setTextSize(2); + m_display.print("CW ID TX"); - m_display.setTextSize(1); - m_display.display(); - if (m_displayScroll) - m_display.startscrollleft(0x02,0x0f); + m_display.setTextSize(1); + m_display.display(); + + if (m_displayScroll) + m_display.startscrollleft(0x02, 0x0f); } void COLED::clearCWInt() { - m_display.clearDisplay(); - - m_display.setCursor(0,OLED_LINE1); - m_display.setTextSize(2); - m_display.setTextSize(1); - m_display.print(" -IDLE-"); - m_display.setCursor(0,OLED_LINE3); - m_display.printf("%s",m_ipaddress.c_str()); - - // Display temperature - float tempCelsius = readTemperature("/sys/class/thermal/thermal_zone0/temp"); - if (tempCelsius >= 0.0F) { - // Convert to Fahrenheit - float tempFahrenheit = (tempCelsius * 9.0F / 5.0F) + 32.0F; - m_display.setCursor(0, OLED_LINE5); - m_display.setTextSize(1); - m_display.printf("Temp: %.0fF / %.0fC ", tempFahrenheit, tempCelsius); - } - - if (m_displayScroll) - m_display.startscrolldiagleft(0x00,0x0f); - m_display.display(); + m_display.clearDisplay(); + + m_display.setCursor(0, OLED_LINE1); + m_display.setTextSize(2); + m_display.setTextSize(1); + m_display.print(" -IDLE-"); + m_display.setCursor(0, OLED_LINE3); + m_display.printf("%s", m_ipaddress.c_str()); + + // Display temperature + float tempCelsius = readTemperature("/sys/class/thermal/thermal_zone0/temp"); + if (tempCelsius >= 0.0F) { + // Convert to Fahrenheit + float tempFahrenheit = (tempCelsius * 9.0F / 5.0F) + 32.0F; + m_display.setCursor(0, OLED_LINE5); + m_display.setTextSize(1); + m_display.printf("Temp: %.0fF / %.0fC ", tempFahrenheit, tempCelsius); + } + if (m_displayScroll) + m_display.startscrolldiagleft(0x00, 0x0f); + m_display.display(); } void COLED::close() { - m_display.clearDisplay(); - m_display.fillRect(0, 0, m_display.width(), 16, BLACK); - if (m_displayScroll) - m_display.startscrollleft(0x00,0x01); - m_display.setCursor(0,OLED_LINE3); - m_display.setTextSize(2); - m_display.print(" -OFFLINE-"); - m_display.display(); + m_display.clearDisplay(); + m_display.fillRect(0, 0, m_display.width(), 16, BLACK); + + if (m_displayScroll) + m_display.startscrollleft(0x00, 0x01); - m_display.close(); + m_display.setCursor(0, OLED_LINE3); + m_display.setTextSize(2); + m_display.print(" -OFFLINE-"); + m_display.display(); + + m_display.close(); } void COLED::OLED_statusbar() { - m_display.stopscroll(); - m_display.fillRect(0, 0, m_display.width(), 16, BLACK); - m_display.setTextColor(WHITE); - - m_display.setCursor(0,0); - if (m_mode == MODE_DMR) - m_display.drawBitmap(0, 0, logo_dmr_bmp, 128, 16, WHITE); - else if (m_mode == MODE_DSTAR) - m_display.drawBitmap(0, 0, logo_dstar_bmp, 128, 16, WHITE); - else if (m_mode == MODE_YSF) - m_display.drawBitmap(0, 0, logo_fusion_bmp, 128, 16, WHITE); - else if (m_mode == MODE_P25) - m_display.drawBitmap(0, 0, logo_P25_bmp, 128, 16, WHITE); - else if (m_mode == MODE_NXDN) - m_display.drawBitmap(0, 0, logo_NXDN_bmp, 128, 16, WHITE); - else if (m_mode == MODE_M17) - m_display.drawBitmap(0, 0, logo_M17_bmp, 128, 16, WHITE); - else if (m_mode == MODE_POCSAG) - m_display.drawBitmap(0, 0, logo_POCSAG_bmp, 128, 16, WHITE); - else if (m_displayLogoScreensaver) - m_display.drawBitmap(0, 0, logo_glcd_bmp, 128, 16, WHITE); - - if (m_displayScroll) - m_display.startscrollleft(0x00,0x01); + m_display.stopscroll(); + m_display.fillRect(0, 0, m_display.width(), 16, BLACK); + m_display.setTextColor(WHITE); + + m_display.setCursor(0,0); + if (m_mode == MODE_DMR) + m_display.drawBitmap(0, 0, logo_dmr_bmp, 128, 16, WHITE); + else if (m_mode == MODE_DSTAR) + m_display.drawBitmap(0, 0, logo_dstar_bmp, 128, 16, WHITE); + else if (m_mode == MODE_YSF) + m_display.drawBitmap(0, 0, logo_fusion_bmp, 128, 16, WHITE); + else if (m_mode == MODE_P25) + m_display.drawBitmap(0, 0, logo_P25_bmp, 128, 16, WHITE); + else if (m_mode == MODE_NXDN) + m_display.drawBitmap(0, 0, logo_NXDN_bmp, 128, 16, WHITE); + else if (m_mode == MODE_M17) + m_display.drawBitmap(0, 0, logo_M17_bmp, 128, 16, WHITE); + else if (m_mode == MODE_POCSAG) + m_display.drawBitmap(0, 0, logo_POCSAG_bmp, 128, 16, WHITE); + else if (m_displayLogoScreensaver) + m_display.drawBitmap(0, 0, logo_glcd_bmp, 128, 16, WHITE); + + if (m_displayScroll) + m_display.startscrollleft(0x00, 0x01); } + diff --git a/OLED.h b/OLED.h index 55c3d518..b782b5c2 100644 --- a/OLED.h +++ b/OLED.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2018,2020,2023 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,63 +45,64 @@ class COLED : public CDisplay { public: - COLED(unsigned char displayType, unsigned char displayBrighness, bool displayInvert, bool displayScroll, bool displayRotate, bool displayLogoScreensaver, bool duplex); - virtual ~COLED(); + COLED(char displayType, unsigned char displayBrighness, bool displayInvert, bool displayScroll, bool displayRotate, bool displayLogoScreensaver, bool duplex); + virtual ~COLED(); - virtual bool open(); + virtual bool open(); - virtual void setIdleInt(); + virtual void close(); - virtual void setErrorInt(const char* text); - virtual void setLockoutInt(); - virtual void setQuitInt(); - virtual void setFMInt(); +protected: + virtual void setIdleInt(); + virtual void setErrorInt(const char* text); + virtual void setLockoutInt(); + virtual void setQuitInt(); + virtual void setFMInt(); - virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); - virtual void clearDStarInt(); + virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); + virtual void clearDStarInt(); - virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); - virtual int writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type); - virtual void clearDMRInt(unsigned int slotNo); + virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); + virtual int writeDMRIntEx(unsigned int slotNo, const CUserDBentry& src, bool group, const std::string& dst, const char* type); + virtual void clearDMRInt(unsigned int slotNo); - virtual void writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); - virtual void clearFusionInt(); + virtual void writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); + virtual void clearFusionInt(); - virtual void writeP25Int(const char* source, bool group, unsigned int dest, const char* type); - virtual void clearP25Int(); + virtual void writeP25Int(const char* source, bool group, unsigned int dest, const char* type); + virtual void clearP25Int(); - virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type); - virtual int writeNXDNIntEx(const class CUserDBentry& source, bool group, unsigned int dest, const char* type); - virtual void clearNXDNInt(); + virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type); + virtual int writeNXDNIntEx(const CUserDBentry& source, bool group, unsigned int dest, const char* type); + virtual void clearNXDNInt(); - virtual void writeM17Int(const char* source, const char* dest, const char* type); - virtual void clearM17Int(); + virtual void writeM17Int(const char* source, const char* dest, const char* type); + virtual void clearM17Int(); - virtual void writePOCSAGInt(uint32_t ric, const std::string& message); - virtual void clearPOCSAGInt(); + virtual void writePOCSAGInt(uint32_t ric, const std::string& message); + virtual void clearPOCSAGInt(); - virtual void writeCWInt(); - virtual void clearCWInt(); - - virtual void close(); + virtual void writeCWInt(); + virtual void clearCWInt(); private: - const char* m_slot1_state; - const char* m_slot2_state; - unsigned char m_mode; - unsigned char m_displayType; - unsigned char m_displayBrightness; - bool m_displayInvert; - bool m_displayScroll; - bool m_displayRotate; - bool m_displayLogoScreensaver; - bool m_duplex; - std::string m_ipaddress; - ArduiPi_OLED m_display; - - float readTemperature(const std::string& filePath); - - void OLED_statusbar(); + const char* m_slot1_state; + const char* m_slot2_state; + unsigned char m_mode; + unsigned char m_displayType; + unsigned char m_displayBrightness; + bool m_displayInvert; + bool m_displayScroll; + bool m_displayRotate; + bool m_displayLogoScreensaver; + bool m_duplex; + std::string m_ipaddress; + ArduiPi_OLED m_display; + + float readTemperature(const char* filePath); + + void OLED_statusbar(); }; #endif + diff --git a/TFTSurenoo.cpp b/TFTSurenoo.cpp index af6c3403..ca627c32 100644 --- a/TFTSurenoo.cpp +++ b/TFTSurenoo.cpp @@ -235,7 +235,7 @@ void CTFTSurenoo::writeDMRInt(unsigned int slotNo, const std::string& src, bool m_mode = MODE_DMR; } -int CTFTSurenoo::writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type) +int CTFTSurenoo::writeDMRIntEx(unsigned int slotNo, const CUserDBentry& src, bool group, const std::string& dst, const char* type) { assert(type != NULL); @@ -335,7 +335,7 @@ void CTFTSurenoo::writeNXDNInt(const char* source, bool group, unsigned int dest m_mode = MODE_NXDN; } -int CTFTSurenoo::writeNXDNIntEx(const class CUserDBentry& source, bool group, unsigned int dest, const char* type) +int CTFTSurenoo::writeNXDNIntEx(const CUserDBentry& source, bool group, unsigned int dest, const char* type) { assert(type != NULL); diff --git a/TFTSurenoo.h b/TFTSurenoo.h index 2e9abdbb..0a0a7e74 100644 --- a/TFTSurenoo.h +++ b/TFTSurenoo.h @@ -30,25 +30,25 @@ class CTFTSurenoo : public CDisplay { public: - CTFTSurenoo(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool duplex); - virtual ~CTFTSurenoo(); + CTFTSurenoo(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool duplex); + virtual ~CTFTSurenoo(); - virtual bool open(); + virtual bool open(); - virtual void close(); + virtual void close(); protected: virtual void setIdleInt(); virtual void setErrorInt(const char* text); virtual void setLockoutInt(); virtual void setQuitInt(); - virtual void setFMInt(); + virtual void setFMInt(); virtual void writeDStarInt(const char* my1, const char* my2, const char* your, const char* type, const char* reflector); virtual void clearDStarInt(); virtual void writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type); - virtual int writeDMRIntEx(unsigned int slotNo, const class CUserDBentry& src, bool group, const std::string& dst, const char* type); + virtual int writeDMRIntEx(unsigned int slotNo, const CUserDBentry& src, bool group, const std::string& dst, const char* type); virtual void clearDMRInt(unsigned int slotNo); virtual void writeFusionInt(const char* source, const char* dest, unsigned char dgid, const char* type, const char* origin); @@ -58,7 +58,7 @@ class CTFTSurenoo : public CDisplay virtual void clearP25Int(); virtual void writeNXDNInt(const char* source, bool group, unsigned int dest, const char* type); - virtual int writeNXDNIntEx(const class CUserDBentry& source, bool group, unsigned int dest, const char* type); + virtual int writeNXDNIntEx(const CUserDBentry& source, bool group, unsigned int dest, const char* type); virtual void clearNXDNInt(); virtual void writeM17Int(const char* source, const char* dest, const char* type); @@ -73,27 +73,27 @@ class CTFTSurenoo : public CDisplay virtual void clockInt(unsigned int ms); private: - std::string m_callsign; - unsigned int m_dmrid; - ISerialPort* m_serial; - unsigned int m_brightness; - unsigned char m_mode; - bool m_duplex; - bool m_refresh; - CTimer m_refreshTimer; - char* m_lineBuf; - char m_temp[128]; - - void setLineBuffer(char *buf, const char *text, int maxchar); - void setModeLine(const char *text); - void setStatusLine(unsigned int line, const char *text); - void refreshDisplay(void); - - void lcdReset(void); - void clearScreen(unsigned char colour); - void setBackground(unsigned char colour); - void setRotation(unsigned char rotation); - void setBrightness(unsigned char brightness); + std::string m_callsign; + unsigned int m_dmrid; + ISerialPort* m_serial; + unsigned int m_brightness; + unsigned char m_mode; + bool m_duplex; + bool m_refresh; + CTimer m_refreshTimer; + char* m_lineBuf; + char m_temp[128]; + + void setLineBuffer(char *buf, const char *text, int maxchar); + void setModeLine(const char *text); + void setStatusLine(unsigned int line, const char *text); + void refreshDisplay(); + + void lcdReset(); + void clearScreen(unsigned char colour); + void setBackground(unsigned char colour); + void setRotation(unsigned char rotation); + void setBrightness(unsigned char brightness); }; #endif