Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 10 additions & 33 deletions Firmware/GPAD_API/GPAD_API/GPAD_API.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "GPAD_HAL.h"
#include "gpad_utility.h"
#include "gpad_serial.h"
#include "gpad_debug.h"
#include "Wink.h"
#include <math.h>

Expand Down Expand Up @@ -176,9 +177,8 @@ WifiOTA::Manager wifiManager(WiFi, debugSerial);

#define DEBUG_SPI 0

// #define DEBUG 0
#define DEBUG 1
// #define DEBUG 4
// Debug level now set at runtime via LCD menu or serial command d0-d3.
// See gpad_debug.h

unsigned long last_command_ms;

Expand Down Expand Up @@ -333,10 +333,7 @@ void publishOnLineMsg(void)
float rssi = WiFi.RSSI();
char rssiString[8];

#if (DEBUG > 1)
debugSerial.print("Publish RSSI: ");
debugSerial.println(rssi);
#endif
if (gpad_debug_level > 1) { debugSerial.print("Publish RSSI: "); debugSerial.println(rssi); }

dtostrf(rssi, 1, 2, rssiString);
char onLineMsg[32] = " online, RSSI:";
Expand Down Expand Up @@ -1095,11 +1092,7 @@ void callback(char *topic, byte *payload, unsigned int length)
}
mbuff[m] = '\0';

#if (DEBUG > 0)
debugSerial.print("|");
debugSerial.print(mbuff);
debugSerial.println("|");
#endif
if (gpad_debug_level > 0) { debugSerial.print("|"); debugSerial.print(mbuff); debugSerial.println("|"); }

debugSerial.println("Received MQTT Msg.");
const String payloadText = String(mbuff);
Expand Down Expand Up @@ -1634,9 +1627,7 @@ void setup()
publish_Ack_Topic[0] = '\0';
macAddressString[0] = '\0';

#if (DEBUG > 1)
debugSerial.println("Call: GPAD_HAL_setup(&debugSerial)");
#endif
if (gpad_debug_level > 1) debugSerial.println("Call: GPAD_HAL_setup(&debugSerial)");

// Setup and present LCD splash screen
// Setup the SWITCH_MUTE
Expand All @@ -1650,10 +1641,7 @@ void setup()
IPAddress deviceAddress = wifiManager.getAddress();
GPAD_HAL_setup(&debugSerial, wifiManager.getMode(), deviceAddress);

#if (DEBUG > 0)
debugSerial.println("MAC: ");
debugSerial.println(macAddressString);
#endif
if (gpad_debug_level > 0) { debugSerial.println("MAC: "); debugSerial.println(macAddressString); }

debugSerial.setTimeout(SERIAL_TIMEOUT_MS);
strncpy(mqtt_broker_name, DEFAULT_MQTT_BROKER_NAME, MQTT_BROKER_MAX_LEN - 1);
Expand All @@ -1665,9 +1653,7 @@ void setup()
client.setServer(mqtt_broker_name, 1883); // Default MQTT port, this is a TCP port.
client.setCallback(callback);

#if (DEBUG > 0)
debugSerial.println("Starting WiFi as STA");
#endif
if (gpad_debug_level > 0) debugSerial.println("Starting WiFi as STA");

// Note: On Krake SN#3 only, performing this
// while the Splash is on causes a reset, presumably
Expand All @@ -1691,11 +1677,7 @@ void setup()
char buff[13];
sprintf(buff, MACSTR_PLN, MAC2STR(mac));

#if (DEBUG > 0)
printf("My mac is " MACSTR "\n", MAC2STR(mac));
debugSerial.print("MAC as char array: ");
debugSerial.println(buff);
#endif
if (gpad_debug_level > 0) { printf("My mac is " MACSTR "\n", MAC2STR(mac)); debugSerial.print("MAC as char array: "); debugSerial.println(buff); }

strcpy(macAddressString, buff);
macAddressString[12] = '\0';
Expand All @@ -1707,12 +1689,7 @@ void setup()
loadMqttConfig();
client.setServer(mqtt_broker_name, 1883);

#if (DEBUG > 1)
debugSerial.println("XXXXXXX");
debugSerial.println(subscribe_Alarm_Topic);
debugSerial.println(publish_Ack_Topic);
debugSerial.println("XXXXXXX");
#endif
if (gpad_debug_level > 1) { debugSerial.println("XXXXXXX"); debugSerial.println(subscribe_Alarm_Topic); debugSerial.println(publish_Ack_Topic); debugSerial.println("XXXXXXX"); }
// Setup SSID length is the length of the prefix, 'Krake_', which is 7
// plus the length of the MAC address string, MAC_ADDRESS_STRING_LENGTH
const size_t SETUP_SSID_LENGTH = 7 + MAC_ADDRESS_STRING_LENGTH;
Expand Down
59 changes: 28 additions & 31 deletions Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "GPAD_HAL.h"
#include "alarm_api.h"
#include "gpad_utility.h"
#include "gpad_debug.h"
#include <SPI.h>
#include "WiFiManagerOTA.h"
#include "GPAD_menu.h"
Expand Down Expand Up @@ -120,16 +121,8 @@ volatile boolean process;

byte received_signal_raw_bytes[MAX_BUFFER_SIZE];

// Local DEBUG defines, GPAD_HAL
#define DEBUG 0
// #define DEBUG 1

#if (DEBUG > 0)
Serial.println("Debug defined >0")
#endif

const int NUM_PREFICES = 6;
char legal_prefices[NUM_PREFICES] = {'h', 's', 'a', 'u', 'i', 'r'};
const int NUM_PREFICES = 7;
char legal_prefices[NUM_PREFICES] = {'h', 's', 'a', 'u', 'i', 'r', 'd'};

void setup_spi()
{
Expand Down Expand Up @@ -193,7 +186,7 @@ void receive_byte(byte c)

void updateFromSPI()
{
if (DEBUG > 0)
if (gpad_debug_level > 0)
{
if (process)
{
Expand All @@ -210,7 +203,7 @@ void updateFromSPI()
event.msg[i] = (char)received_signal_raw_bytes[1 + i];
}

if (DEBUG > 1)
if (gpad_debug_level > 1)
{
Serial.print(F("LVL: "));
Serial.println(event.lvl);
Expand Down Expand Up @@ -340,31 +333,22 @@ void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceI
Real_lcd.init();


#if (DEBUG > 0)
serialport->println(F("Clear LCD"));
#endif
if (gpad_debug_level > 0) serialport->println(F("Clear LCD"));
clearLCD();
delay(100);
#if (DEBUG > 0)
serialport->println(F("Start LCD splash"));
#endif
if (gpad_debug_level > 0) serialport->println(F("Start LCD splash"));

splashLCD(wifiMode, deviceIp);

#if (DEBUG > 0)
serialport->println(F("EndLCD splash"));
#endif
if (gpad_debug_level > 0) serialport->println(F("EndLCD splash"));

// Setup GPIO pins, Mute and lights
pinMode(SWITCH_MUTE, INPUT_PULLUP); // The SWITCH_MUTE is different on Atmega vs ESP32. Is this redundant?
pinMode(SWITCH_ENCODER, INPUT_PULLUP); // The SWITCH_ENCODER is new to Krake. Is this redundant?

for (int i = 0; i < NUM_LIGHTS; i++)
{
#if (DEBUG > 0)
serialport->print(LIGHT[i]);
serialport->print(", ");
#endif
if (gpad_debug_level > 0) { serialport->print(LIGHT[i]); serialport->print(", "); }
pinMode(LIGHT[i], OUTPUT);
// Rob trying to prevent resets
// This is necessary on SN#3
Expand Down Expand Up @@ -394,18 +378,14 @@ void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceI
uartSerial1.begin(UART1_BAUD_RATE, SERIAL_8N1, RXD1, TXD1); // UART setup. On Homework2, LCD goes blank early
uartSerial1.flush(); // Clear any Serial1 crud at reset.

#if (DEBUG > 0)
serialport->println(F("uartSerial1 Setup"));
#endif
if (gpad_debug_level > 0) serialport->println(F("uartSerial1 Setup"));
#endif

// Here initialize the UART2
pinMode(RXD2, INPUT_PULLUP);
uartSerial2.begin(UART2_BAUD_RATE, SERIAL_8N1, RXD2, TXD2); // UART setup
uartSerial2.flush();
#if (DEBUG > 0)
serialport->println(F("uartSerial2 Setup"));
#endif
if (gpad_debug_level > 0) serialport->println(F("uartSerial2 Setup"));
} // end GPAD_HAL_setup()

// This routine should be refactored so that it only "interprets"
Expand Down Expand Up @@ -440,6 +420,23 @@ void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *clie
return;
}

if (buf[0] == 'd')
{
if (rlen >= 2 && buf[1] >= '0' && buf[1] <= '3')
{
gpad_debug_level = buf[1] - '0';
serialport->print(F("Debug level set to: "));
serialport->println(gpad_debug_level);
}
else
{
serialport->print(F("Debug level is: "));
serialport->println(gpad_debug_level);
serialport->println(F("Usage: d0=off d1=basic d2=verbose d3=trace"));
}
return;
}

const auto protocolMessage = gpap_message::GPAPMessage::deserialize(buf, rlen);

serialport->print(F("Command: "));
Expand Down
15 changes: 13 additions & 2 deletions Firmware/GPAD_API/GPAD_API/GPAD_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "RickmanLiquidCrystal_I2C.h"
#include "DFPlayer.h"
#include "alarm_api.h"
#include "gpad_debug.h"

using namespace Menu;

Expand Down Expand Up @@ -90,6 +91,16 @@ result action5(eventMask e)



result actionDebugLevel(eventMask e)
{
if (e == eventMask::enterEvent)
{
Serial.print(F("Debug level set to: "));
Serial.println(gpad_debug_level);
}
return proceed;
}

result actionResetConfirm(eventMask e)
{
if (e == eventMask::enterEvent)
Expand All @@ -111,8 +122,8 @@ MENU(mainMenu, "Krake Menu", Menu::doNothing, Menu::noEvent, Menu::wrapStyle,
OP("Dismiss", action2, enterEvent),
OP("Shelve", action3, enterEvent),
FIELD(volumeDFPlayer, "Volume", "%", 0, 30, 10, 1, action4, anyEvent, wrapStyle),
SUBMENU(resetConfirmMenu),
FIELD(gpad_debug_level, "Debug Lvl", "", 0, 3, 1, 1, actionDebugLevel, enterEvent, wrapStyle),
SUBMENU(resetConfirmMenu),
OP("Exit Menu", action5, enterEvent)
);

Expand Down
5 changes: 2 additions & 3 deletions Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "WiFiManagerOTA.h"
#include <LittleFS.h>
#include "gpad_debug.h"

namespace
{
Expand Down Expand Up @@ -434,9 +435,7 @@ void WifiOTA::initLittleFS()
}
else
{
#if (DEBUG > 1)
Serial.println("LittleFS mounted successfully.");
#endif
if (gpad_debug_level > 1) Serial.println("LittleFS mounted successfully.");
}
}

Expand Down
3 changes: 3 additions & 0 deletions Firmware/GPAD_API/GPAD_API/gpad_debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "gpad_debug.h"

int gpad_debug_level = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Initialize debug level before boot-time logging

Setting gpad_debug_level to 0 by default disables every debug print in setup() and GPAD_HAL_setup(), but the new mechanisms that change this value (interpretBuffer() serial command and the LCD FIELD) only run after setup has completed. In practice, sending d1 after boot cannot expose startup diagnostics like MAC/Wi-Fi/UART logs, so boot-time debugging regresses compared with the previous default (DEBUG 1 in GPAD_API.ino).

Useful? React with 👍 / 👎.

11 changes: 11 additions & 0 deletions Firmware/GPAD_API/GPAD_API/gpad_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef GPAD_DEBUG_H
#define GPAD_DEBUG_H

// Runtime debug level — can be changed via LCD menu or serial command (d0-d3).
// 0 = off
// 1 = basic (setup info, key events)
// 2 = verbose (detailed message flow)
// 3 = trace (inside functions, SPI, per-loop)
extern int gpad_debug_level;

#endif