From e194c2c48c58cb2ae3bbca61adc38456d0542858 Mon Sep 17 00:00:00 2001 From: pelgraine <140762863+pelgraine@users.noreply.github.com> Date: Thu, 29 Jan 2026 18:28:19 +1100 Subject: [PATCH] Replace Serial.print with MESH_DEBUG macros for cleaner debug output in main cpp, tdeckboard cpp and target cpp --- examples/companion_radio/main.cpp | 114 ++++++++++------------- variants/lilygo_tdeck_pro/TDeckBoard.cpp | 25 +++-- variants/lilygo_tdeck_pro/target.cpp | 26 ++---- 3 files changed, 65 insertions(+), 100 deletions(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index f2b7d5ae..c1bd1d6d 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -110,14 +110,14 @@ void halt() { void setup() { Serial.begin(115200); delay(100); // Give serial time to initialize - Serial.println("=== setup() - STARTING ==="); + MESH_DEBUG_PRINTLN("=== setup() - STARTING ==="); board.begin(); - Serial.println("setup() - board.begin() done"); + MESH_DEBUG_PRINTLN("setup() - board.begin() done"); #ifdef DISPLAY_CLASS DisplayDriver* disp = NULL; - Serial.println("setup() - about to call display.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call display.begin()"); // ========================================================================= // T-Deck Pro V1.1: Initialize E-Ink reset pin BEFORE display.begin() @@ -127,7 +127,7 @@ void setup() { // Initialize E-Ink reset pin (GPIO 16) pinMode(PIN_DISPLAY_RST, OUTPUT); digitalWrite(PIN_DISPLAY_RST, HIGH); - Serial.println("setup() - E-Ink reset pin initialized"); + MESH_DEBUG_PRINTLN("setup() - E-Ink reset pin initialized"); // Initialize Touch reset pin (GPIO 38) #ifdef CST328_PIN_RST @@ -138,13 +138,13 @@ void setup() { delay(80); digitalWrite(CST328_PIN_RST, HIGH); delay(20); - Serial.println("setup() - Touch reset pin initialized"); + MESH_DEBUG_PRINTLN("setup() - Touch reset pin initialized"); #endif #endif // ========================================================================= if (display.begin()) { - Serial.println("setup() - display.begin() returned true"); + MESH_DEBUG_PRINTLN("setup() - display.begin() returned true"); disp = &display; disp->startFrame(); #ifdef ST7789 @@ -152,25 +152,25 @@ void setup() { #endif disp->drawTextCentered(disp->width() / 2, 28, "Loading..."); disp->endFrame(); - Serial.println("setup() - Loading screen drawn"); + MESH_DEBUG_PRINTLN("setup() - Loading screen drawn"); } else { - Serial.println("setup() - display.begin() returned false!"); + MESH_DEBUG_PRINTLN("setup() - display.begin() returned false!"); } #endif - Serial.println("setup() - about to call radio_init()"); + MESH_DEBUG_PRINTLN("setup() - about to call radio_init()"); if (!radio_init()) { - Serial.println("setup() - radio_init() FAILED! Halting."); + MESH_DEBUG_PRINTLN("setup() - radio_init() FAILED! Halting."); halt(); } - Serial.println("setup() - radio_init() done"); + MESH_DEBUG_PRINTLN("setup() - radio_init() done"); - Serial.println("setup() - about to call fast_rng.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call fast_rng.begin()"); fast_rng.begin(radio_get_rng_seed()); - Serial.println("setup() - fast_rng.begin() done"); + MESH_DEBUG_PRINTLN("setup() - fast_rng.begin() done"); #if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM) - Serial.println("setup() - NRF52/STM32 filesystem init"); + MESH_DEBUG_PRINTLN("setup() - NRF52/STM32 filesystem init"); InternalFS.begin(); #if defined(QSPIFLASH) if (!QSPIFlash.begin()) { @@ -183,11 +183,11 @@ void setup() { ExtraFS.begin(); #endif #endif - Serial.println("setup() - about to call store.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call store.begin()"); store.begin(); - Serial.println("setup() - store.begin() done"); + MESH_DEBUG_PRINTLN("setup() - store.begin() done"); - Serial.println("setup() - about to call the_mesh.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call the_mesh.begin()"); the_mesh.begin( #ifdef DISPLAY_CLASS disp != NULL @@ -195,27 +195,27 @@ void setup() { false #endif ); - Serial.println("setup() - the_mesh.begin() done"); + MESH_DEBUG_PRINTLN("setup() - the_mesh.begin() done"); #ifdef BLE_PIN_CODE - Serial.println("setup() - about to call serial_interface.begin() with BLE"); + MESH_DEBUG_PRINTLN("setup() - about to call serial_interface.begin() with BLE"); serial_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin()); - Serial.println("setup() - serial_interface.begin() done"); + MESH_DEBUG_PRINTLN("setup() - serial_interface.begin() done"); #else serial_interface.begin(Serial); #endif - Serial.println("setup() - about to call the_mesh.startInterface()"); + MESH_DEBUG_PRINTLN("setup() - about to call the_mesh.startInterface()"); the_mesh.startInterface(serial_interface); - Serial.println("setup() - the_mesh.startInterface() done"); + MESH_DEBUG_PRINTLN("setup() - the_mesh.startInterface() done"); #elif defined(RP2040_PLATFORM) - Serial.println("setup() - RP2040 filesystem init"); + MESH_DEBUG_PRINTLN("setup() - RP2040 filesystem init"); LittleFS.begin(); - Serial.println("setup() - about to call store.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call store.begin()"); store.begin(); - Serial.println("setup() - store.begin() done"); + MESH_DEBUG_PRINTLN("setup() - store.begin() done"); - Serial.println("setup() - about to call the_mesh.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call the_mesh.begin()"); the_mesh.begin( #ifdef DISPLAY_CLASS disp != NULL @@ -223,7 +223,7 @@ void setup() { false #endif ); - Serial.println("setup() - the_mesh.begin() done"); + MESH_DEBUG_PRINTLN("setup() - the_mesh.begin() done"); //#ifdef WIFI_SSID // WiFi.begin(WIFI_SSID, WIFI_PWD); @@ -239,20 +239,20 @@ void setup() { #else serial_interface.begin(Serial); #endif - Serial.println("setup() - about to call the_mesh.startInterface()"); + MESH_DEBUG_PRINTLN("setup() - about to call the_mesh.startInterface()"); the_mesh.startInterface(serial_interface); - Serial.println("setup() - the_mesh.startInterface() done"); + MESH_DEBUG_PRINTLN("setup() - the_mesh.startInterface() done"); #elif defined(ESP32) - Serial.println("setup() - ESP32 filesystem init - calling SPIFFS.begin()"); + MESH_DEBUG_PRINTLN("setup() - ESP32 filesystem init - calling SPIFFS.begin()"); SPIFFS.begin(true); - Serial.println("setup() - SPIFFS.begin() done"); + MESH_DEBUG_PRINTLN("setup() - SPIFFS.begin() done"); - Serial.println("setup() - about to call store.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call store.begin()"); store.begin(); - Serial.println("setup() - store.begin() done"); + MESH_DEBUG_PRINTLN("setup() - store.begin() done"); - Serial.println("setup() - about to call the_mesh.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call the_mesh.begin()"); the_mesh.begin( #ifdef DISPLAY_CLASS disp != NULL @@ -260,16 +260,16 @@ void setup() { false #endif ); - Serial.println("setup() - the_mesh.begin() done"); + MESH_DEBUG_PRINTLN("setup() - the_mesh.begin() done"); #ifdef WIFI_SSID - Serial.println("setup() - WiFi mode"); + MESH_DEBUG_PRINTLN("setup() - WiFi mode"); WiFi.begin(WIFI_SSID, WIFI_PWD); serial_interface.begin(TCP_PORT); #elif defined(BLE_PIN_CODE) - Serial.println("setup() - about to call serial_interface.begin() with BLE"); + MESH_DEBUG_PRINTLN("setup() - about to call serial_interface.begin() with BLE"); serial_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin()); - Serial.println("setup() - serial_interface.begin() done"); + MESH_DEBUG_PRINTLN("setup() - serial_interface.begin() done"); #elif defined(SERIAL_RX) companion_serial.setPins(SERIAL_RX, SERIAL_TX); companion_serial.begin(115200); @@ -277,30 +277,30 @@ void setup() { #else serial_interface.begin(Serial); #endif - Serial.println("setup() - about to call the_mesh.startInterface()"); + MESH_DEBUG_PRINTLN("setup() - about to call the_mesh.startInterface()"); the_mesh.startInterface(serial_interface); - Serial.println("setup() - the_mesh.startInterface() done"); + MESH_DEBUG_PRINTLN("setup() - the_mesh.startInterface() done"); #else #error "need to define filesystem" #endif - Serial.println("setup() - about to call sensors.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call sensors.begin()"); sensors.begin(); - Serial.println("setup() - sensors.begin() done"); + MESH_DEBUG_PRINTLN("setup() - sensors.begin() done"); // IMPORTANT: sensors.begin() calls initBasicGPS() which steals the GPS pins for Serial1 // We need to reinitialize Serial2 to reclaim them #if HAS_GPS Serial2.end(); // Close any existing Serial2 Serial2.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); - Serial.println("setup() - Reinitialized Serial2 for GPS after sensors.begin()"); + MESH_DEBUG_PRINTLN("setup() - Reinitialized Serial2 for GPS after sensors.begin()"); #endif #ifdef DISPLAY_CLASS - Serial.println("setup() - about to call ui_task.begin()"); + MESH_DEBUG_PRINTLN("setup() - about to call ui_task.begin()"); ui_task.begin(disp, &sensors, the_mesh.getNodePrefs()); - Serial.println("setup() - ui_task.begin() done"); + MESH_DEBUG_PRINTLN("setup() - ui_task.begin() done"); #endif // Enable GPS by default on T-Deck Pro @@ -309,10 +309,10 @@ void setup() { sensors.setSettingValue("gps", "1"); the_mesh.getNodePrefs()->gps_enabled = 1; the_mesh.savePrefs(); - Serial.println("setup() - GPS enabled by default"); + MESH_DEBUG_PRINTLN("setup() - GPS enabled by default"); #endif - Serial.println("=== setup() - COMPLETE ==="); + MESH_DEBUG_PRINTLN("=== setup() - COMPLETE ==="); } void loop() { @@ -322,24 +322,4 @@ void loop() { ui_task.loop(); #endif rtc_clock.tick(); - - // Debug: Check for GPS data on Serial2 - #if HAS_GPS - static unsigned long lastGpsDebug = 0; - if (millis() - lastGpsDebug > 5000) { // Every 5 seconds - lastGpsDebug = millis(); - Serial.print("GPS Debug - Serial2 available: "); - Serial.print(Serial2.available()); - Serial.print(" bytes"); - LocationProvider* loc = sensors.getLocationProvider(); - if (loc) { - Serial.print(", valid: "); - Serial.print(loc->isValid() ? "YES" : "NO"); - Serial.print(", sats: "); - Serial.println(loc->satellitesCount()); - } else { - Serial.println(", LocationProvider: NULL"); - } - } - #endif } \ No newline at end of file diff --git a/variants/lilygo_tdeck_pro/TDeckBoard.cpp b/variants/lilygo_tdeck_pro/TDeckBoard.cpp index 0542c107..145e7076 100644 --- a/variants/lilygo_tdeck_pro/TDeckBoard.cpp +++ b/variants/lilygo_tdeck_pro/TDeckBoard.cpp @@ -1,24 +1,25 @@ #include #include "variant.h" #include "TDeckBoard.h" +#include // For MESH_DEBUG_PRINTLN uint32_t deviceOnline = 0x00; void TDeckBoard::begin() { - Serial.println("TDeckBoard::begin() - starting"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - starting"); // Enable peripheral power (keyboard, sensors, etc.) FIRST // This powers the BQ27220 fuel gauge and other I2C devices pinMode(PIN_PERF_POWERON, OUTPUT); digitalWrite(PIN_PERF_POWERON, HIGH); delay(50); // Allow peripherals to power up before I2C init - Serial.println("TDeckBoard::begin() - peripheral power enabled"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - peripheral power enabled"); // Initialize I2C with correct pins for T-Deck Pro Wire.begin(I2C_SDA, I2C_SCL); Wire.setClock(100000); // 100kHz for reliable fuel gauge communication - Serial.println("TDeckBoard::begin() - I2C initialized"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - I2C initialized"); // Now call parent class begin (after power and I2C are ready) ESP32Board::begin(); @@ -28,7 +29,7 @@ void TDeckBoard::begin() { pinMode(P_LORA_EN, OUTPUT); digitalWrite(P_LORA_EN, HIGH); delay(10); // Allow module to power up - Serial.println("TDeckBoard::begin() - LoRa power enabled"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - LoRa power enabled"); #endif // Enable GPS module power and initialize Serial2 @@ -37,14 +38,12 @@ void TDeckBoard::begin() { pinMode(PIN_GPS_EN, OUTPUT); digitalWrite(PIN_GPS_EN, GPS_EN_ACTIVE); // GPS_EN_ACTIVE is 1 (HIGH) delay(100); // Allow GPS to power up - Serial.println("TDeckBoard::begin() - GPS power enabled"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - GPS power enabled"); #endif // Initialize Serial2 for GPS with correct pins Serial2.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); - Serial.print("TDeckBoard::begin() - GPS Serial2 initialized at "); - Serial.print(GPS_BAUDRATE); - Serial.println(" baud"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - GPS Serial2 initialized at %d baud", GPS_BAUDRATE); #endif // Configure user button @@ -68,12 +67,10 @@ void TDeckBoard::begin() { // Test BQ27220 communication #if HAS_BQ27220 uint16_t voltage = getBattMilliVolts(); - Serial.print("TDeckBoard::begin() - Battery voltage: "); - Serial.print(voltage); - Serial.println(" mV"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - Battery voltage: %d mV", voltage); #endif - Serial.println("TDeckBoard::begin() - complete"); + MESH_DEBUG_PRINTLN("TDeckBoard::begin() - complete"); } uint16_t TDeckBoard::getBattMilliVolts() { @@ -81,13 +78,13 @@ uint16_t TDeckBoard::getBattMilliVolts() { Wire.beginTransmission(BQ27220_I2C_ADDR); Wire.write(BQ27220_REG_VOLTAGE); if (Wire.endTransmission(false) != 0) { - Serial.println("BQ27220: I2C error reading voltage"); + MESH_DEBUG_PRINTLN("BQ27220: I2C error reading voltage"); return 0; } uint8_t count = Wire.requestFrom((uint8_t)BQ27220_I2C_ADDR, (uint8_t)2); if (count != 2) { - Serial.println("BQ27220: Read error - wrong byte count"); + MESH_DEBUG_PRINTLN("BQ27220: Read error - wrong byte count"); return 0; } diff --git a/variants/lilygo_tdeck_pro/target.cpp b/variants/lilygo_tdeck_pro/target.cpp index a0455909..8b2de485 100644 --- a/variants/lilygo_tdeck_pro/target.cpp +++ b/variants/lilygo_tdeck_pro/target.cpp @@ -19,10 +19,8 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock); #if HAS_GPS MicroNMEALocationProvider gps(Serial2, &rtc_clock); EnvironmentSensorManager sensors(gps); - #pragma message "GPS enabled - using EnvironmentSensorManager with MicroNMEALocationProvider" #else SensorManager sensors; - #pragma message "GPS disabled - using basic SensorManager" #endif #ifdef DISPLAY_CLASS @@ -31,37 +29,27 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock); #endif bool radio_init() { - Serial.println("radio_init() - starting"); + MESH_DEBUG_PRINTLN("radio_init() - starting"); // NOTE: board.begin() is called by main.cpp setup() before radio_init() // I2C is already initialized there with correct pins fallback_clock.begin(); - Serial.println("radio_init() - fallback_clock started"); + MESH_DEBUG_PRINTLN("radio_init() - fallback_clock started"); // Wire already initialized in board.begin() - just use it for RTC rtc_clock.begin(Wire); - Serial.println("radio_init() - rtc_clock started"); - - // Debug GPS status - #if HAS_GPS - Serial.println("radio_init() - HAS_GPS is defined"); - Serial.print("radio_init() - gps object address: "); - Serial.println((uint32_t)&gps, HEX); - #else - Serial.println("radio_init() - HAS_GPS is NOT defined"); - #endif + MESH_DEBUG_PRINTLN("radio_init() - rtc_clock started"); #if defined(P_LORA_SCLK) - Serial.println("radio_init() - initializing LoRa SPI..."); + MESH_DEBUG_PRINTLN("radio_init() - initializing LoRa SPI..."); loraSpi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI, P_LORA_NSS); - Serial.println("radio_init() - SPI initialized, calling radio.std_init()..."); + MESH_DEBUG_PRINTLN("radio_init() - SPI initialized, calling radio.std_init()..."); bool result = radio.std_init(&loraSpi); - Serial.print("radio_init() - radio.std_init() returned: "); - Serial.println(result ? "SUCCESS" : "FAILED"); + MESH_DEBUG_PRINTLN("radio_init() - radio.std_init() returned: %s", result ? "SUCCESS" : "FAILED"); return result; #else - Serial.println("radio_init() - calling radio.std_init() without custom SPI..."); + MESH_DEBUG_PRINTLN("radio_init() - calling radio.std_init() without custom SPI..."); return radio.std_init(); #endif }