From b56f037c0f48b62de232a540f3c2a309dc900d58 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 13 Jun 2018 13:07:06 +0200 Subject: [PATCH] Make the code more readable --- OLED.cpp | 293 +++++++++++++++++++++++++++---------------------------- 1 file changed, 145 insertions(+), 148 deletions(-) diff --git a/OLED.cpp b/OLED.cpp index 5b9afe1..0fe5a11 100644 --- a/OLED.cpp +++ b/OLED.cpp @@ -106,45 +106,45 @@ const unsigned char logo_fusion_bmp [] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - //Logo P25 128x16px - const unsigned char logo_P25_bmp [] = - { -0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, -0xf8, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x7f, -0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x7f, -0xf8, 0x00, 0xe0, 0x00, 0x00, 0xff, 0x00, 0x07, 0xc0, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xff, -0xf0, 0x01, 0xff, 0xfc, 0x00, 0x7e, 0x00, 0x3f, 0xf8, 0x00, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xff, -0xf0, 0x01, 0xff, 0xfe, 0x00, 0x7c, 0x00, 0x7f, 0xfc, 0x00, 0x7f, 0xe0, 0x0f, 0xff, 0xff, 0xff, -0xf0, 0x01, 0xff, 0xfe, 0x00, 0x7e, 0x00, 0x7f, 0xf8, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, -0xf0, 0x01, 0xff, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xe0, 0x01, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x1f, -0xf0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0x00, 0x07, 0xff, 0xff, 0x9f, 0xff, 0x80, 0x07, -0xf0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x03, -0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x03, -0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xc0, 0x03, -0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x0f, 0xfe, 0x00, 0x0f, -0xf0, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x3f, -0xf0, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x03, 0xff, +//Logo P25 128x16px +const unsigned char logo_P25_bmp [] = +{ +0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, +0xf8, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x7f, +0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x7f, +0xf8, 0x00, 0xe0, 0x00, 0x00, 0xff, 0x00, 0x07, 0xc0, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xff, +0xf0, 0x01, 0xff, 0xfc, 0x00, 0x7e, 0x00, 0x3f, 0xf8, 0x00, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xff, +0xf0, 0x01, 0xff, 0xfe, 0x00, 0x7c, 0x00, 0x7f, 0xfc, 0x00, 0x7f, 0xe0, 0x0f, 0xff, 0xff, 0xff, +0xf0, 0x01, 0xff, 0xfe, 0x00, 0x7e, 0x00, 0x7f, 0xf8, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x01, 0xff, +0xf0, 0x01, 0xff, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xe0, 0x01, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x1f, +0xf0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0x00, 0x07, 0xff, 0xff, 0x9f, 0xff, 0x80, 0x07, +0xf0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x03, +0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x03, +0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xc0, 0x03, +0xf0, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x0f, 0xfe, 0x00, 0x0f, +0xf0, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x3f, +0xf0, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff - }; - +}; + // Logo NXDN_sm, 128x16px 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, -0xff, 0xf0, 0x1f, 0xf8, 0x0f, 0x00, 0xff, 0x80, 0x7c, 0x00, 0x0f, 0xff, 0x80, 0x7f, 0xe0, 0x7f, -0xff, 0xe0, 0x0f, 0xf0, 0x1f, 0x80, 0x7e, 0x01, 0xf8, 0x00, 0x00, 0x7f, 0x00, 0x3f, 0xc0, 0x7f, -0xff, 0xc0, 0x07, 0xe0, 0x3f, 0x80, 0x38, 0x07, 0xf0, 0x00, 0x00, 0x3e, 0x00, 0x3f, 0x80, 0xff, -0xff, 0x80, 0x03, 0xc0, 0x3f, 0xc0, 0x00, 0x3f, 0xe0, 0x1f, 0x80, 0x3e, 0x00, 0x1f, 0x01, 0xff, -0xff, 0x00, 0x03, 0x80, 0x7f, 0xe0, 0x00, 0xff, 0xc0, 0x3f, 0x80, 0x3c, 0x00, 0x0e, 0x03, 0xff, -0xfe, 0x00, 0x01, 0x00, 0xff, 0xe0, 0x03, 0xff, 0x80, 0x7f, 0x80, 0x78, 0x08, 0x04, 0x03, 0xff, -0xfc, 0x03, 0x00, 0x01, 0xff, 0x80, 0x01, 0xff, 0x00, 0xff, 0x00, 0xf0, 0x1c, 0x00, 0x07, 0xff, -0xfc, 0x07, 0x80, 0x03, 0xfc, 0x00, 0x01, 0xfe, 0x01, 0xfc, 0x01, 0xe0, 0x1e, 0x00, 0x0f, 0xff, -0xf8, 0x0f, 0xc0, 0x07, 0xf0, 0x0e, 0x00, 0xfc, 0x00, 0x00, 0x07, 0xc0, 0x3f, 0x00, 0x1f, 0xff, -0xf0, 0x1f, 0xe0, 0x0f, 0x80, 0x3f, 0x00, 0x7c, 0x00, 0x00, 0x3f, 0xc0, 0x7f, 0x80, 0x3f, 0xff, -0xe0, 0x3f, 0xf0, 0x0e, 0x01, 0xff, 0x80, 0x38, 0x00, 0x07, 0xff, 0x80, 0xff, 0x80, 0x7f, 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, 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, 0xff, +0xff, 0xf0, 0x1f, 0xf8, 0x0f, 0x00, 0xff, 0x80, 0x7c, 0x00, 0x0f, 0xff, 0x80, 0x7f, 0xe0, 0x7f, +0xff, 0xe0, 0x0f, 0xf0, 0x1f, 0x80, 0x7e, 0x01, 0xf8, 0x00, 0x00, 0x7f, 0x00, 0x3f, 0xc0, 0x7f, +0xff, 0xc0, 0x07, 0xe0, 0x3f, 0x80, 0x38, 0x07, 0xf0, 0x00, 0x00, 0x3e, 0x00, 0x3f, 0x80, 0xff, +0xff, 0x80, 0x03, 0xc0, 0x3f, 0xc0, 0x00, 0x3f, 0xe0, 0x1f, 0x80, 0x3e, 0x00, 0x1f, 0x01, 0xff, +0xff, 0x00, 0x03, 0x80, 0x7f, 0xe0, 0x00, 0xff, 0xc0, 0x3f, 0x80, 0x3c, 0x00, 0x0e, 0x03, 0xff, +0xfe, 0x00, 0x01, 0x00, 0xff, 0xe0, 0x03, 0xff, 0x80, 0x7f, 0x80, 0x78, 0x08, 0x04, 0x03, 0xff, +0xfc, 0x03, 0x00, 0x01, 0xff, 0x80, 0x01, 0xff, 0x00, 0xff, 0x00, 0xf0, 0x1c, 0x00, 0x07, 0xff, +0xfc, 0x07, 0x80, 0x03, 0xfc, 0x00, 0x01, 0xfe, 0x01, 0xfc, 0x01, 0xe0, 0x1e, 0x00, 0x0f, 0xff, +0xf8, 0x0f, 0xc0, 0x07, 0xf0, 0x0e, 0x00, 0xfc, 0x00, 0x00, 0x07, 0xc0, 0x3f, 0x00, 0x1f, 0xff, +0xf0, 0x1f, 0xe0, 0x0f, 0x80, 0x3f, 0x00, 0x7c, 0x00, 0x00, 0x3f, 0xc0, 0x7f, 0x80, 0x3f, 0xff, +0xe0, 0x3f, 0xf0, 0x0e, 0x01, 0xff, 0x80, 0x38, 0x00, 0x07, 0xff, 0x80, 0xff, 0x80, 0x7f, 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, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; @@ -176,10 +176,10 @@ bool COLED::open() { // I2C change parameters to fit to your LCD if ( !display.init(OLED_I2C_RESET, m_displayType) ) - return false; + return false; } - + display.begin(); display.invertDisplay(m_displayInvert ? 1 : 0); @@ -200,7 +200,7 @@ bool COLED::open() void COLED::setIdleInt() { - m_mode = MODE_IDLE; + m_mode = MODE_IDLE; display.clearDisplay(); OLED_statusbar(); @@ -212,26 +212,26 @@ void COLED::setIdleInt() // display.setTextSize(1); display.startscrolldiagright(0x00,0x0f); //the MMDVM logo scrolls the whole screen display.display(); - - unsigned char info[100U]; - CNetworkInfo* m_network; - - passCounter ++; - if (passCounter > 253U) - networkInfoInitialized = false; - - if (! networkInfoInitialized) { - //LogMessage("Initialize CNetworkInfo"); - info[0]=0; - m_network = new CNetworkInfo; - m_network->getNetworkInterface(info); - m_ipaddress = (char*)info; - delete m_network; - - networkInfoInitialized = true; - passCounter = 0; - } - + + unsigned char info[100U]; + CNetworkInfo* m_network; + + passCounter ++; + if (passCounter > 253U) + networkInfoInitialized = false; + + if (! networkInfoInitialized) { + //LogMessage("Initialize CNetworkInfo"); + info[0]=0; + m_network = new CNetworkInfo; + m_network->getNetworkInterface(info); + m_ipaddress = (char*)info; + delete m_network; + + networkInfoInitialized = true; + passCounter = 0; + } + } void COLED::setErrorInt(const char* text) @@ -277,9 +277,9 @@ void COLED::writeDStarInt(const char* my1, const char* my2, const char* your, co display.setCursor(0,OLED_LINE5); display.printf("via %.8s",reflector); - - display.setCursor(0,OLED_LINE6); - display.printf("%s",m_ipaddress.c_str()); + + display.setCursor(0,OLED_LINE6); + display.printf("%s",m_ipaddress.c_str()); OLED_statusbar(); display.display(); @@ -291,9 +291,9 @@ void COLED::clearDStarInt() display.setCursor(40,OLED_LINE3); display.print("Listening"); - - display.setCursor(0,OLED_LINE5); - display.printf("%s",m_ipaddress.c_str()); + + display.setCursor(0,OLED_LINE5); + display.printf("%s",m_ipaddress.c_str()); display.display(); } @@ -302,77 +302,74 @@ void COLED::writeDMRInt(unsigned int slotNo,const std::string& src,bool group,co { if (m_mode != MODE_DMR) { - 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 3-4 - if ( m_slot1Enabled && m_slot2Enabled ) { + 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 3-4 + if ( m_slot1Enabled && m_slot2Enabled ) { - if (slotNo == 1U) { - display.fillRect(0,OLED_LINE2,display.width(),40,BLACK); - display.setCursor(0,OLED_LINE2); - display.printf("%s",src.c_str()); - display.setCursor(0,OLED_LINE3); - display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); - } - else - { - display.fillRect(0,OLED_LINE4,display.width(),40,BLACK); - display.setCursor(0,OLED_LINE4); - display.printf("%s",src.c_str()); - display.setCursor(0,OLED_LINE5); - display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); - } + if (slotNo == 1U) { + display.fillRect(0,OLED_LINE2,display.width(),40,BLACK); + display.setCursor(0,OLED_LINE2); + display.printf("%s",src.c_str()); + display.setCursor(0,OLED_LINE3); + display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); + } + else + { + display.fillRect(0,OLED_LINE4,display.width(),40,BLACK); + display.setCursor(0,OLED_LINE4); + display.printf("%s",src.c_str()); + display.setCursor(0,OLED_LINE5); + display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); + } - } - else - { - display.fillRect(0,OLED_LINE3,display.width(),20,BLACK); - display.setCursor(0,OLED_LINE3); - display.printf("%s",src.c_str()); - display.setCursor(0,OLED_LINE4); - display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); - } + } + else + { + display.fillRect(0,OLED_LINE3,display.width(),20,BLACK); + display.setCursor(0,OLED_LINE3); + display.printf("%s",src.c_str()); + display.setCursor(0,OLED_LINE4); + display.printf("Slot: %i %s %s%s",slotNo,type,group ? "TG: " : "",dst.c_str()); + } + + display.fillRect(0,OLED_LINE6,display.width(),20,BLACK); + display.setCursor(0,OLED_LINE6); + display.printf("%s",m_ipaddress.c_str()); - display.fillRect(0,OLED_LINE6,display.width(),20,BLACK); - display.setCursor(0,OLED_LINE6); - display.printf("%s",m_ipaddress.c_str()); - OLED_statusbar(); display.display(); - } + } 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 3-4 - if ( m_slot1Enabled && m_slot2Enabled ){ - if (slotNo == 1U) - { - display.fillRect(0, OLED_LINE3, display.width(), 40, BLACK); - display.setCursor(0,OLED_LINE3); - display.print("Slot: 1 Listening"); - } - else - { - display.fillRect(0, OLED_LINE5, display.width(), 40, BLACK); - display.setCursor(0, OLED_LINE5); - display.print("Slot: 2 Listening"); - } - } - else { - display.fillRect(0, OLED_LINE4, display.width(), 40, BLACK); - display.setCursor(0,OLED_LINE4); - display.printf("Slot: %i Listening",slotNo); - } + // if both slots, use lines 2-3 for slot 1, lines 4-5 for slot 2 + // if single slot, use lines 3-4 + if ( m_slot1Enabled && m_slot2Enabled ){ + if (slotNo == 1U) { + display.fillRect(0, OLED_LINE3, display.width(), 40, BLACK); + display.setCursor(0,OLED_LINE3); + display.print("Slot: 1 Listening"); + } + else { + display.fillRect(0, OLED_LINE5, display.width(), 40, BLACK); + display.setCursor(0, OLED_LINE5); + display.print("Slot: 2 Listening"); + } + } + else { + display.fillRect(0, OLED_LINE4, display.width(), 40, BLACK); + display.setCursor(0,OLED_LINE4); + display.printf("Slot: %i Listening",slotNo); + } - - display.fillRect(0, OLED_LINE6, display.width(), 20, BLACK); - display.setCursor(0,OLED_LINE6); - display.printf("%s",m_ipaddress.c_str()); + display.fillRect(0, OLED_LINE6, display.width(), 20, BLACK); + display.setCursor(0,OLED_LINE6); + display.printf("%s",m_ipaddress.c_str()); display.display(); } @@ -400,9 +397,9 @@ void COLED::clearFusionInt() display.setCursor(40,OLED_LINE4); display.print("Listening"); - - display.setCursor(0,OLED_LINE6); - display.printf("%s",m_ipaddress.c_str()); + + display.setCursor(0,OLED_LINE6); + display.printf("%s",m_ipaddress.c_str()); display.display(); } @@ -430,9 +427,9 @@ void COLED::clearP25Int() display.setCursor(40,OLED_LINE4); display.print("Listening"); - - display.setCursor(0,OLED_LINE6); - display.printf("%s",m_ipaddress.c_str()); + + display.setCursor(0,OLED_LINE6); + display.printf("%s",m_ipaddress.c_str()); display.display(); } @@ -460,9 +457,9 @@ void COLED::clearNXDNInt() display.setCursor(40,OLED_LINE4); display.print("Listening"); - - display.setCursor(0,OLED_LINE6); - display.printf("%s",m_ipaddress.c_str()); + + display.setCursor(0,OLED_LINE6); + display.printf("%s",m_ipaddress.c_str()); display.display(); } @@ -490,9 +487,9 @@ void COLED::clearPOCSAGInt() display.setCursor(40,OLED_LINE4); display.print("Listening"); - - display.setCursor(0,OLED_LINE6); - display.printf("%s",m_ipaddress.c_str()); + + display.setCursor(0,OLED_LINE6); + display.printf("%s",m_ipaddress.c_str()); display.display(); } @@ -526,13 +523,13 @@ void COLED::clearCWInt() void COLED::close() { display.clearDisplay(); - display.fillRect(0, 0, display.width(), 16, BLACK); - display.startscrollright(0x00,0x01); + display.fillRect(0, 0, display.width(), 16, BLACK); + display.startscrollright(0x00,0x01); display.setCursor(0,00); display.setTextSize(2); display.print("-CLOSE-"); display.display(); - + display.close(); } @@ -544,18 +541,18 @@ void COLED::OLED_statusbar() display.setCursor(0,0); if (m_mode == MODE_DMR) - display.drawBitmap(0, 0, logo_dmr_bmp, 128, 16, WHITE); + display.drawBitmap(0, 0, logo_dmr_bmp, 128, 16, WHITE); else if (m_mode == MODE_DSTAR) - display.drawBitmap(0, 0, logo_dstar_bmp, 128, 16, WHITE); + display.drawBitmap(0, 0, logo_dstar_bmp, 128, 16, WHITE); else if (m_mode == MODE_YSF) - display.drawBitmap(0, 0, logo_fusion_bmp, 128, 16, WHITE); + display.drawBitmap(0, 0, logo_fusion_bmp, 128, 16, WHITE); else if (m_mode == MODE_P25) - display.drawBitmap(0, 0, logo_P25_bmp, 128, 16, WHITE); + display.drawBitmap(0, 0, logo_P25_bmp, 128, 16, WHITE); else if (m_mode == MODE_NXDN) - display.drawBitmap(0, 0, logo_NXDN_bmp, 128, 16, WHITE); + display.drawBitmap(0, 0, logo_NXDN_bmp, 128, 16, WHITE); else - display.drawBitmap(0, 0, logo_glcd_bmp, 128, 16, WHITE); + display.drawBitmap(0, 0, logo_glcd_bmp, 128, 16, WHITE); if (m_displayScroll) - display.startscrollright(0x00,0x02); + display.startscrollright(0x00,0x02); }