From e557beba52833f31db14f9ca822615cf050bdb1c Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 19 Mar 2020 22:02:24 +0100 Subject: [PATCH] make use of function overriding (c++) --- LoRa_APRS_iGate/LoRa_APRS_iGate.ino | 32 ++++++++++++++--------------- LoRa_APRS_iGate/display.cpp | 12 +++++------ LoRa_APRS_iGate/display.h | 12 +++++------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/LoRa_APRS_iGate/LoRa_APRS_iGate.ino b/LoRa_APRS_iGate/LoRa_APRS_iGate.ino index c7fc4ae..787fc6a 100644 --- a/LoRa_APRS_iGate/LoRa_APRS_iGate.ino +++ b/LoRa_APRS_iGate/LoRa_APRS_iGate.ino @@ -20,27 +20,27 @@ int next_update = -1; void setup() { Serial.begin(115200); - init_display(); + setup_display(); delay(500); Serial.println("[INFO] LoRa APRS iGate by OE5BPA (Peter Buchegger)"); - show_display_2("OE5BPA", "LoRa APRS iGate", "by Peter Buchegger", 2000); + show_display("OE5BPA", "LoRa APRS iGate", "by Peter Buchegger", 2000); WiFi.setHostname("LoRa_APRS_iGate"); WiFiMulti.addAP(WIFI_NAME, WIFI_KEY); Serial.print("[INFO] Waiting for WiFi"); - show_display_1("INFO", "Waiting for WiFi"); + show_display("INFO", "Waiting for WiFi"); while(WiFiMulti.run() != WL_CONNECTED) { Serial.print("."); - show_display_2("INFO", "Waiting for WiFi", "...."); + show_display("INFO", "Waiting for WiFi", "...."); delay(500); } Serial.println(""); Serial.println("[INFO] WiFi connected"); Serial.print("[INFO] IP address: "); Serial.println(WiFi.localIP()); - show_display_3("INFO", "WiFi connected", "IP: ", WiFi.localIP().toString(), 2000); + show_display("INFO", "WiFi connected", "IP: ", WiFi.localIP().toString(), 2000); ArduinoOTA .onStart([]() @@ -80,7 +80,7 @@ void setup() Serial.println(freq); if (!LoRa.begin(freq)) { Serial.println("[ERROR] Starting LoRa failed!"); - show_display_1("ERROR", "Starting LoRa failed!"); + show_display("ERROR", "Starting LoRa failed!"); while (1); } LoRa.setSpreadingFactor(12); @@ -88,16 +88,16 @@ void setup() LoRa.setCodingRate4(5); LoRa.enableCrc(); Serial.println("[INFO] LoRa init done!"); - show_display_1("INFO", "LoRa init done!", 2000); + show_display("INFO", "LoRa init done!", 2000); timeClient.begin(); if(!timeClient.forceUpdate()) { Serial.println("[WARN] NTP Client force update issue!"); - show_display_1("WARN", "NTP Client force update issue!", 2000); + show_display("WARN", "NTP Client force update issue!", 2000); } Serial.println("[INFO] NTP Client init done!"); - show_display_1("INFO", "NTP Client init done!", 2000); + show_display("INFO", "NTP Client init done!", 2000); delay(500); } @@ -109,7 +109,7 @@ void loop() if(WiFiMulti.run() != WL_CONNECTED) { Serial.println("[ERROR] WiFi not connected!"); - show_display_1("ERROR", "WiFi not connected!"); + show_display("ERROR", "WiFi not connected!"); delay(1000); return; } @@ -119,13 +119,13 @@ void loop() Serial.print(SERVER); Serial.print(" on port: "); Serial.println(PORT); - //show_display_3("INFO", "Connecting to server", SERVER, PORT, 2000); - show_display_1("INFO", "Connecting to server"); + //show_display("INFO", "Connecting to server", SERVER, PORT, 2000); + show_display("INFO", "Connecting to server"); if(!aprs_is.connect(SERVER, PORT, FILTER)) { Serial.println("[ERROR] Connection failed."); Serial.println("[INFO] Waiting 5 seconds before retrying..."); - show_display_2("ERROR", "Server connection failed!", "waiting 5 sec"); + show_display("ERROR", "Server connection failed!", "waiting 5 sec"); delay(5000); return; } @@ -133,7 +133,7 @@ void loop() } if(next_update == timeClient.getMinutes() || next_update == -1) { - show_display_1(call, "Broadcast to Server..."); + show_display(call, "Broadcast to Server..."); Serial.print("[" + timeClient.getFormattedTime() + "] "); aprs_is.sendMessage(BROADCAST_MESSAGE); next_update = (timeClient.getMinutes() + BROADCAST_TIMEOUT) % 60; @@ -143,7 +143,7 @@ void loop() String str = aprs_is.getMessage(); Serial.print("[" + timeClient.getFormattedTime() + "] "); Serial.println(str); - show_display_2(call, timeClient.getFormattedTime(), str, 0); + show_display(call, timeClient.getFormattedTime(), str, 0); } int packetSize = LoRa.parsePacket(); if(packetSize) @@ -167,6 +167,6 @@ void loop() Serial.println(msg.toString());*/ aprs_is.sendMessage(str); - show_display_4(call, timeClient.getFormattedTime(), "RSSI: " + String(LoRa.packetRssi()), "SNR: " + String(LoRa.packetSnr()), str, 0); + show_display(call, timeClient.getFormattedTime(), "RSSI: " + String(LoRa.packetRssi()), "SNR: " + String(LoRa.packetSnr()), str, 0); } } diff --git a/LoRa_APRS_iGate/display.cpp b/LoRa_APRS_iGate/display.cpp index 3e0ecd7..7f82e79 100644 --- a/LoRa_APRS_iGate/display.cpp +++ b/LoRa_APRS_iGate/display.cpp @@ -13,7 +13,7 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST); -void init_display() +void setup_display() { pinMode(OLED_RST, OUTPUT); digitalWrite(OLED_RST, LOW); @@ -46,7 +46,7 @@ void show_display(String header, int wait) delay(wait); } -void show_display_1(String header, String line1, int wait) +void show_display(String header, String line1, int wait) { display.clearDisplay(); display.setTextColor(WHITE); @@ -60,7 +60,7 @@ void show_display_1(String header, String line1, int wait) delay(wait); } -void show_display_2(String header, String line1, String line2, int wait) +void show_display(String header, String line1, String line2, int wait) { display.clearDisplay(); display.setTextColor(WHITE); @@ -76,7 +76,7 @@ void show_display_2(String header, String line1, String line2, int wait) delay(wait); } -void show_display_3(String header, String line1, String line2, String line3, int wait) +void show_display(String header, String line1, String line2, String line3, int wait) { display.clearDisplay(); display.setTextColor(WHITE); @@ -94,7 +94,7 @@ void show_display_3(String header, String line1, String line2, String line3, int delay(wait); } -void show_display_4(String header, String line1, String line2, String line3, String line4, int wait) +void show_display(String header, String line1, String line2, String line3, String line4, int wait) { display.clearDisplay(); display.setTextColor(WHITE); @@ -114,7 +114,7 @@ void show_display_4(String header, String line1, String line2, String line3, Str delay(wait); } -void show_display_5(String header, String line1, String line2, String line3, String line4, String line5, int wait) +void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait) { display.clearDisplay(); display.setTextColor(WHITE); diff --git a/LoRa_APRS_iGate/display.h b/LoRa_APRS_iGate/display.h index a7b5ee0..2aec8de 100644 --- a/LoRa_APRS_iGate/display.h +++ b/LoRa_APRS_iGate/display.h @@ -2,13 +2,13 @@ #ifndef DISPLAY_H_ #define DISPLAY_H_ -void init_display(); +void setup_display(); void show_display(String header, int wait = 0); -void show_display_1(String header, String line1, int wait = 0); -void show_display_2(String header, String line1, String line2, int wait = 0); -void show_display_3(String header, String line1, String line2, String line3, int wait = 0); -void show_display_4(String header, String line1, String line2, String line3, String line4, int wait = 0); -void show_display_5(String header, String line1, String line2, String line3, String line4, String line5, int wait = 0); +void show_display(String header, String line1, int wait = 0); +void show_display(String header, String line1, String line2, int wait = 0); +void show_display(String header, String line1, String line2, String line3, int wait = 0); +void show_display(String header, String line1, String line2, String line3, String line4, int wait = 0); +void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait = 0); #endif