diff --git a/Conf.cpp b/Conf.cpp index 7264a39..74ac69d 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -91,7 +91,8 @@ m_fusionNetworkEnabled(false), m_fusionNetworkAddress(), m_fusionNetworkPort(0U), m_fusionNetworkDebug(false), -m_tftSerialPort() +m_tftSerialPort(), +m_tftSerialBrightness(50U) { } @@ -259,6 +260,8 @@ bool CConf::read() } else if (section == SECTION_TFTSERIAL) { if (::strcmp(key, "Port") == 0) m_tftSerialPort = value; + else if (::strcmp(key, "Brightness") == 0) + m_tftSerialBrightness = (unsigned int)::atoi(value); } } @@ -516,3 +519,8 @@ std::string CConf::getTFTSerialPort() const { return m_tftSerialPort; } + +unsigned int CConf::getTFTSerialBrightness() const +{ + return m_tftSerialBrightness; +} diff --git a/Conf.h b/Conf.h index a35f043..bddf0b2 100644 --- a/Conf.h +++ b/Conf.h @@ -100,6 +100,7 @@ public: // The TFTSERIAL section std::string getTFTSerialPort() const; + unsigned int getTFTSerialBrightness() const; private: std::string m_file; @@ -163,6 +164,7 @@ private: bool m_fusionNetworkDebug; std::string m_tftSerialPort; + unsigned int m_tftSerialBrightness; }; #endif diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 8e3d889..2a9ff13 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -144,7 +144,7 @@ void CDMRSlot::writeModem(unsigned char *data) setShortLC(m_slotNo, m_lc->getDstId(), m_lc->getFLCO(), true); - m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId()); + m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId(), "RV"); LogMessage("DMR Slot %u, received RF voice header from %u to %s%u", m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP ? "TG " : "", m_lc->getDstId()); } else if (dataType == DT_VOICE_PI_HEADER) { @@ -236,7 +236,7 @@ void CDMRSlot::writeModem(unsigned char *data) setShortLC(m_slotNo, m_lc->getDstId(), gi ? FLCO_GROUP : FLCO_USER_USER, false); - m_display->writeDMR(m_slotNo, srcId, gi, dstId); + m_display->writeDMR(m_slotNo, srcId, gi, dstId, "RD"); LogMessage("DMR Slot %u, received RF data header from %u to %s%u, %u blocks", m_slotNo, srcId, gi ? "TG ": "", dstId, m_frames); } else if (dataType == DT_CSBK) { @@ -416,7 +416,7 @@ void CDMRSlot::writeModem(unsigned char *data) setShortLC(m_slotNo, m_lc->getDstId(), m_lc->getFLCO(), true); - m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId()); + m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId(), "RV"); LogMessage("DMR Slot %u, received RF late entry from %u to %s%u", m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP ? "TG " : "", m_lc->getDstId()); } @@ -540,7 +540,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) setShortLC(m_slotNo, m_lc->getDstId(), m_lc->getFLCO(), true); - m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId()); + m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId(), "NV"); #if defined(DUMP_DMR) openFile(); @@ -639,7 +639,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) setShortLC(m_slotNo, dmrData.getDstId(), gi ? FLCO_GROUP : FLCO_USER_USER, false); - m_display->writeDMR(m_slotNo, dmrData.getSrcId(), gi, dmrData.getDstId()); + m_display->writeDMR(m_slotNo, dmrData.getSrcId(), gi, dmrData.getDstId(), "ND"); LogMessage("DMR Slot %u, received network data header from %u to %s%u, %u blocks", m_slotNo, dmrData.getSrcId(), gi ? "TG ": "", dmrData.getDstId(), m_frames); } else if (dataType == DT_VOICE_SYNC) { @@ -664,7 +664,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) setShortLC(m_slotNo, m_lc->getDstId(), m_lc->getFLCO(), true); - m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId()); + m_display->writeDMR(m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP, m_lc->getDstId(), "NV"); LogMessage("DMR Slot %u, received network late entry from %u to %s%u", m_slotNo, m_lc->getSrcId(), m_lc->getFLCO() == FLCO_GROUP ? "TG " : "", m_lc->getDstId()); } diff --git a/DStarControl.cpp b/DStarControl.cpp index e9aa4bf..e245c36 100644 --- a/DStarControl.cpp +++ b/DStarControl.cpp @@ -171,7 +171,7 @@ bool CDStarControl::writeModem(unsigned char *data) m_state = RS_RELAYING_RF_AUDIO; - m_display->writeDStar(std::string((char*)my1, 8U), std::string((char*)my2, 4U)); + m_display->writeDStar((char*)my1, (char*)my2, (char*)your); LogMessage("D-Star, received RF header from %8.8s/%4.4s to %8.8s", my1, my2, your); } else if (m_state == RS_RELAYING_NETWORK_AUDIO) { @@ -351,7 +351,7 @@ bool CDStarControl::writeModem(unsigned char *data) m_state = RS_RELAYING_RF_AUDIO; - m_display->writeDStar(std::string((char*)my1, 8U), std::string((char*)my2, 4U)); + m_display->writeDStar((char*)my1, (char*)my2, (char*)your); LogMessage("D-Star, received RF late entry from %8.8s/%4.4s to %8.8s", my1, my2, your); } @@ -449,7 +449,7 @@ void CDStarControl::writeNetwork() #endif m_state = RS_RELAYING_NETWORK_AUDIO; - m_display->writeDStar(std::string((char*)my1, 8U), std::string((char*)my2, 4U)); + m_display->writeDStar((char*)my1, (char*)my2, (char*)your); LogMessage("D-Star, received network header from %8.8s/%4.4s to %8.8s", my1, my2, your); } else if (type == TAG_EOT) { diff --git a/Display.h b/Display.h index 1318832..4f6fc59 100644 --- a/Display.h +++ b/Display.h @@ -31,11 +31,11 @@ public: virtual void setIdle() = 0; virtual void setDStar() = 0; - virtual void writeDStar(const std::string& call1, const std::string& call2) = 0; + virtual void writeDStar(const char* my1, const char* my2, const char* your) = 0; virtual void clearDStar() = 0; virtual void setDMR() = 0; - virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId) = 0; + virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type) = 0; virtual void clearDMR(unsigned int slotNo) = 0; virtual void setFusion() = 0; diff --git a/MMDVM.ini b/MMDVM.ini index c358a8d..8748b28 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -71,3 +71,4 @@ Debug=1 [TFT Serial] Port=/dev/ttyAMA0 +Brightness=50 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index e06f8a7..afe522e 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -514,11 +514,13 @@ void CMMDVMHost::createDisplay() LogInfo(" Type: %s", type.c_str()); if (type == "TFT Serial") { - std::string port = m_conf.getTFTSerialPort(); + std::string port = m_conf.getTFTSerialPort(); + unsigned int brightness = m_conf.getTFTSerialBrightness(); LogInfo(" Port: %s", port.c_str()); + LogInfo(" Brightness: %s", brightness); - m_display = new CTFTSerial(port); + m_display = new CTFTSerial(port, brightness); } else { m_display = new CNullDisplay; } diff --git a/NullDisplay.cpp b/NullDisplay.cpp index 2f6c58d..fc5ce61 100644 --- a/NullDisplay.cpp +++ b/NullDisplay.cpp @@ -39,7 +39,7 @@ void CNullDisplay::setDStar() { } -void CNullDisplay::writeDStar(const std::string& call1, const std::string& call2) +void CNullDisplay::writeDStar(const char* my1, const char* my2, const char* your) { } @@ -51,7 +51,7 @@ void CNullDisplay::setDMR() { } -void CNullDisplay::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId) +void CNullDisplay::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId, const char* type) { } diff --git a/NullDisplay.h b/NullDisplay.h index 715f24c..d546158 100644 --- a/NullDisplay.h +++ b/NullDisplay.h @@ -34,11 +34,11 @@ public: virtual void setIdle(); virtual void setDStar(); - virtual void writeDStar(const std::string& call1, const std::string& call2); + virtual void writeDStar(const char* my1, const char* my2, const char* your); virtual void clearDStar(); virtual void setDMR(); - virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId); + virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type); virtual void clearDMR(unsigned int slotNo); virtual void setFusion(); diff --git a/TFTSerial.cpp b/TFTSerial.cpp index bd97a9c..aee0b5f 100644 --- a/TFTSerial.cpp +++ b/TFTSerial.cpp @@ -19,11 +19,15 @@ #include "TFTSerial.h" #include "Log.h" +#include +#include #include -CTFTSerial::CTFTSerial(const std::string& port) : -m_serial(port, SERIAL_9600) +CTFTSerial::CTFTSerial(const std::string& port, unsigned int brightness) : +m_serial(port, SERIAL_9600), +m_brightness(brightness) { + assert(brightness >= 0U && brightness <= 100U); } CTFTSerial::~CTFTSerial() @@ -38,11 +42,17 @@ bool CTFTSerial::open() return false; } + setRotation(3U); + + setFontSize(1U); + + setBrightness(m_brightness); + // Set background white - m_serial.write((unsigned char*)"\x1B\x02\x07\xFF", 4U); + setBackground(7U); // Set foreground black - m_serial.write((unsigned char*)"\x1B\x01\x00\xFF", 4U); + setForeground(0U); setIdle(); @@ -55,10 +65,10 @@ void CTFTSerial::setIdle() clearScreen(); // Draw MMDVM logo - writeImage(0U, 0U, "MMDVM_sm.bmp"); + displayImage(0U, 0U, "MMDVM_sm.bmp"); // Draw all mode insignias - writeImage(0U, 30U, "ALL_sm.bmp"); + displayImage(0U, 30U, "ALL_sm.bmp"); } void CTFTSerial::setDStar() @@ -67,31 +77,35 @@ void CTFTSerial::setDStar() clearScreen(); // Draw MMDVM logo - writeImage(0U, 0U, "MMDVM_sm.bmp"); + displayImage(0U, 0U, "MMDVM_sm.bmp"); // Draw D-Star insignia - writeImage(0U, 30U, "DStar_sm.bmp"); + displayImage(0U, 30U, "DStar_sm.bmp"); - writeText(0U, 8U, "Listening"); + displayText(0U, 8U, "Listening"); } -void CTFTSerial::writeDStar(const std::string& call1, const std::string& call2) +void CTFTSerial::writeDStar(const char* my1, const char* my2, const char* your) { - char text[20U]; - ::sprintf(text, "%s/%s", call1.c_str(), call2.c_str()); + assert(my1 != NULL); + assert(my2 != NULL); + assert(your != NULL); - writeText(0U, 8U, text); + char text[20U]; + ::sprintf(text, "%8.8s/%4.4s -> %8.8s", my1, my2, your); + + displayText(0U, 8U, text); } void CTFTSerial::clearDStar() { // Draw MMDVM logo - writeImage(0U, 0U, "MMDVM_sm.bmp"); + displayImage(0U, 0U, "MMDVM_sm.bmp"); // Draw D-Star insignia - writeImage(0U, 30U, "DStar_sm.bmp"); + displayImage(0U, 30U, "DStar_sm.bmp"); - writeText(0U, 8U, "Listening"); + displayText(0U, 8U, "Listening"); } void CTFTSerial::setDMR() @@ -100,32 +114,34 @@ void CTFTSerial::setDMR() clearScreen(); // Draw MMDVM logo - writeImage(0U, 0U, "MMDVM_sm.bmp"); + displayImage(0U, 0U, "MMDVM_sm.bmp"); // Draw DMR insignia - writeImage(0U, 30U, "DMR_sm.bmp"); + displayImage(0U, 30U, "DMR_sm.bmp"); - writeText(0U, 8U, "1: Listening"); - writeText(0U, 9U, "2: Listening"); + displayText(0U, 8U, "1: Listening"); + displayText(0U, 9U, "2: Listening"); } -void CTFTSerial::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId) +void CTFTSerial::writeDMR(unsigned int slotNo, unsigned int srcId, bool group, unsigned int dstId, const char* type) { + assert(type != NULL); + char text[20U]; - ::sprintf(text, "%u: %u %s%u", slotNo, srcId, group ? "TG " : "", dstId); + ::sprintf(text, "%u: %s %u -> %s%u", slotNo, type, srcId, group ? "TG" : "", dstId); if (slotNo == 1U) - writeText(0U, 8U, text); + displayText(0U, 8U, text); else - writeText(0U, 9U, text); + displayText(0U, 9U, text); } void CTFTSerial::clearDMR(unsigned int slotNo) { if (slotNo == 1U) - writeText(0U, 8U, "1: Listening"); + displayText(0U, 8U, "1: Listening"); else - writeText(0U, 9U, "2: Listening"); + displayText(0U, 9U, "2: Listening"); } void CTFTSerial::setFusion() @@ -134,12 +150,12 @@ void CTFTSerial::setFusion() clearScreen(); // Draw MMDVM logo - writeImage(0U, 0U, "MMDVM_sm.bmp"); + displayImage(0U, 0U, "MMDVM_sm.bmp"); // Draw the System Fusion insignia - writeImage(0U, 30U, "YSF_sm.bmp"); + displayImage(0U, 30U, "YSF_sm.bmp"); - writeText(0U, 8U, "Listening"); + displayText(0U, 8U, "Listening"); } void CTFTSerial::writeFusion(const std::string& callsign) @@ -147,18 +163,18 @@ void CTFTSerial::writeFusion(const std::string& callsign) char text[20U]; ::sprintf(text, "%s", callsign.c_str()); - writeText(0U, 8U, text); + displayText(0U, 8U, text); } void CTFTSerial::clearFusion() { // Draw MMDVM logo - writeImage(0U, 0U, "MMDVM_sm.bmp"); + displayImage(0U, 0U, "MMDVM_sm.bmp"); // Draw the System Fusion insignia - writeImage(0U, 30U, "YSF_sm.bmp"); + displayImage(0U, 30U, "YSF_sm.bmp"); - writeText(0U, 8U, "Listening"); + displayText(0U, 8U, "Listening"); } void CTFTSerial::close() @@ -171,8 +187,46 @@ void CTFTSerial::clearScreen() m_serial.write((unsigned char*)"\x1B\x00\xFF", 3U); } -void CTFTSerial::writeText(unsigned char x, unsigned char y, const char* text) +void CTFTSerial::setForeground(unsigned char colour) { + assert(colour >= 0U && colour <= 7U); + + m_serial.write((unsigned char*)"\x1B\x01", 2U); + m_serial.write(&colour, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} + +void CTFTSerial::setBackground(unsigned char colour) +{ + assert(colour >= 0U && colour <= 7U); + + m_serial.write((unsigned char*)"\x1B\x02", 2U); + m_serial.write(&colour, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} + +void CTFTSerial::setRotation(unsigned char rotation) +{ + assert(rotation >= 0U && rotation <= 3U); + + m_serial.write((unsigned char*)"\x1B\x03", 2U); + m_serial.write(&rotation, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} + +void CTFTSerial::setFontSize(unsigned char size) +{ + assert(size >= 0U && size <= 2U); + + m_serial.write((unsigned char*)"\x1B\x04", 2U); + m_serial.write(&size, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} + +void CTFTSerial::displayText(unsigned char x, unsigned char y, const char* text) +{ + assert(text != NULL); + m_serial.write((unsigned char*)"\x1B\x06", 2U); m_serial.write(&x, 1U); m_serial.write(&y, 1U); @@ -180,11 +234,59 @@ void CTFTSerial::writeText(unsigned char x, unsigned char y, const char* text) m_serial.write((unsigned char*)text, ::strlen(text)); } -void CTFTSerial::writeImage(unsigned char x, unsigned char y, const char* filename) +void CTFTSerial::drawLine(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2) { + m_serial.write((unsigned char*)"\x1B\x08", 2U); + m_serial.write(&x1, 1U); + m_serial.write(&y1, 1U); + m_serial.write(&x2, 1U); + m_serial.write(&y2, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} + +void CTFTSerial::drawBox(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bool filled) +{ + if (filled) + m_serial.write((unsigned char*)"\x1B\x0A", 2U); + else + m_serial.write((unsigned char*)"\x1B\x09", 2U); + + m_serial.write(&x1, 1U); + m_serial.write(&y1, 1U); + m_serial.write(&x2, 1U); + m_serial.write(&y2, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} + +void CTFTSerial::drawCircle(unsigned char x, unsigned char y, unsigned char radius, bool filled) +{ + if (filled) + m_serial.write((unsigned char*)"\x1B\x0C", 2U); + else + m_serial.write((unsigned char*)"\x1B\x0B", 2U); + + m_serial.write(&x, 1U); + m_serial.write(&y, 1U); + m_serial.write(&radius, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} + +void CTFTSerial::displayImage(unsigned char x, unsigned char y, const char* filename) +{ + assert(filename != NULL); + m_serial.write((unsigned char*)"\x1B\x0D", 2U); m_serial.write(&x, 1U); m_serial.write(&y, 1U); m_serial.write((unsigned char*)filename, ::strlen(filename)); m_serial.write((unsigned char*)"\xFF", 1U); } + +void CTFTSerial::setBrightness(unsigned char brightness) +{ + assert(brightness >= 0U && brightness <= 100U); + + m_serial.write((unsigned char*)"\x1B\x0E", 2U); + m_serial.write(&brightness, 1U); + m_serial.write((unsigned char*)"\xFF", 1U); +} diff --git a/TFTSerial.h b/TFTSerial.h index 79c71f6..8e62e70 100644 --- a/TFTSerial.h +++ b/TFTSerial.h @@ -27,7 +27,7 @@ class CTFTSerial : public IDisplay { public: - CTFTSerial(const std::string& port); + CTFTSerial(const std::string& port, unsigned int brightness); virtual ~CTFTSerial(); virtual bool open(); @@ -35,11 +35,11 @@ public: virtual void setIdle(); virtual void setDStar(); - virtual void writeDStar(const std::string& call1, const std::string& call2); + virtual void writeDStar(const char* my1, const char* my2, const char* your); virtual void clearDStar(); virtual void setDMR(); - virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId); + virtual void writeDMR(unsigned int slotNo, unsigned int srdId, bool group, unsigned int dstId, const char* type); virtual void clearDMR(unsigned int slotNo); virtual void setFusion(); @@ -50,10 +50,19 @@ public: private: CSerialController m_serial; + unsigned int m_brightness; void clearScreen(); - void writeText(unsigned char x, unsigned char y, const char* text); - void writeImage(unsigned char x, unsigned char y, const char* filename); + void setBackground(unsigned char colour); + void setForeground(unsigned char colour); + void setRotation(unsigned char rotation); + void setFontSize(unsigned char size); + void displayText(unsigned char x, unsigned char y, const char* text); + void drawLine(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2); + void drawBox(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bool filled); + void drawCircle(unsigned char x, unsigned char y, unsigned char radius, bool filled); + void displayImage(unsigned char x, unsigned char y, const char* filename); + void setBrightness(unsigned char brightness); }; #endif