Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 22 additions & 5 deletions Firmware/GPAD_API/GPAD_API/GPAD_API.ino
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "DFPlayer.h"
#include "GPAD_menu.h"


AsyncWebServer server(80);
AsyncWebSocket ws("/ws");

Expand Down Expand Up @@ -285,10 +286,10 @@ unsigned long nextLEDchangee_ms = 5000; // time in ms.
void onWiFiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info) {
debugSerial.print("\nWifi Disconnected. Reason: ");
debugSerial.println(info.wifi_sta_disconnected.reason);

// OPTION A: Simple Reconnect
//WiFi.begin();
//WiFi.begin();

// OPTION B: Re-trigger WiFiManager Portal
// wm.startConfigPortal("AutoConnectAP");
}
Expand Down Expand Up @@ -1605,6 +1606,8 @@ void setupOTA()

void setup()
{


pinMode(LED_BUILTIN, OUTPUT); // set the LED pin mode
digitalWrite(LED_BUILTIN, HIGH);
// Serial setup
Expand All @@ -1614,6 +1617,9 @@ void setup()
{
; // wait for serial port to connect. Needed for native USB
}

printMemStats(&debugSerial);

serialSplash();
// We call this a second time to get the MAC on the screen
// clearLCD();
Expand Down Expand Up @@ -1754,7 +1760,7 @@ void setup()
debugSerial.println(F("initLiffleFS"));

server.begin(); // Start server web socket to render pages

debugSerial.println(F("iStart server web socket to render pages"));

ElegantOTA.begin(&server);
Expand All @@ -1781,6 +1787,9 @@ void setup()
debugSerial.println(F("Done With Setup!"));
turnOnAllLamps();
digitalWrite(LED_BUILTIN, LOW); // turn the LED off at end of setup

printMemStats(&debugSerial);

} // end of setup()

unsigned long last_ms = 0;
Expand All @@ -1790,15 +1799,23 @@ void toggle(int pin)
}

const unsigned long LOW_FREQ_DEBUG_MS = 20000;
unsigned long time_since_LOW_FREQ_ms = 0;
// unsigned long time_since_LOW_FREQ_ms = 0;

int cnt_actions = 0;

bool running_menu = false;
bool menu_just_exited = false;

unsigned long time_since_mem_stats = 0;
const unsigned long MEM_TIMER_LIMT_MS = 30*1000;
void loop()
{
unsigned long now = millis();
if (now > (MEM_TIMER_LIMT_MS + time_since_mem_stats)) {
printMemStats(&debugSerial);
time_since_mem_stats = millis();
}

#if defined HMWK || defined KRAKE

if (!client.loop())
Expand Down
15 changes: 15 additions & 0 deletions Firmware/GPAD_API/GPAD_API/gpad_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ void printAlarmState(Stream *serialport)
serialport->println(AlarmMessageBuffer);
}
}


void printMemStats(Stream *serialport) {
// 1. Get total free heap across all regions
uint32_t free_heap = esp_get_free_heap_size();
serialport->printf("Total free heap: %u bytes\n", free_heap);

// 2. Get free heap with specific capabilities (e.g., 8-bit accessible memory)
size_t free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
serialport->printf("Free 8-bit heap: %zu bytes\n", free_8bit);

// 3. Get the largest single contiguous block available (important for large allocations)
size_t max_block = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
serialport->printf("Largest free block: %zu bytes\n", max_block);
}
5 changes: 5 additions & 0 deletions Firmware/GPAD_API/GPAD_API/gpad_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

#ifndef GPAD_UTILITY
#define GPAD_UTILITY 1

#include "esp_system.h"
#include "esp_heap_caps.h"

#include <Stream.h>
#ifndef COMPANY_NAME
#define COMPANY_NAME ""
Expand Down Expand Up @@ -49,4 +53,5 @@
void printError(Stream *serialport);
void printInstructions(Stream *serialport);
void printAlarmState(Stream *serialport);
void printMemStats(Stream *serialport);
#endif
Loading