Stairs/src/main.debug.h

77 lines
1.8 KiB
C
Raw Normal View History

#ifdef SerialDebug
void wifiEvent(WiFiEvent_t event);
void initDebug()
{
// onEvent is already deprecated, but since I'm only using it
// for debug purposes we'll see how long it lasts...
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
WiFi.onEvent(wifiEvent);
_d("WiFi :: MAC address: ");
_dln(WiFi.macAddress());
#pragma GCC diagnostic pop
}
void wifiEvent(WiFiEvent_t event)
{
switch (event)
{
case WIFI_EVENT_STAMODE_CONNECTED:
_dln("WiFi:: station mode: connected"); break;
case WIFI_EVENT_STAMODE_DISCONNECTED:
_dln("WiFi:: station mode: disconnected"); break;
case WIFI_EVENT_STAMODE_AUTHMODE_CHANGE:
_dln("WiFi:: station mode: authmode change"); break;
case WIFI_EVENT_STAMODE_GOT_IP:
_dln("WiFi:: station mode: got IP");
_dln(WiFi.localIP());
break;
case WIFI_EVENT_STAMODE_DHCP_TIMEOUT:
_dln("WiFi:: station mode: DHCP timeout"); break;
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
_dln("WiFi:: soft AP mode: station connected"); break;
case WIFI_EVENT_SOFTAPMODE_STADISCONNECTED:
_dln("WiFi:: soft AP mode: station disconnected"); break;
}
}
uint32_t debugStatusTime = 0;
void updateDebugStatus()
{
if (currentTime - debugStatusTime < 5000) return;
debugStatusTime = currentTime;
_d("Status :: available heap: ");
_dln(ESP.getFreeHeap());
if (ntpClient != nullptr)
{
_d("Status :: time: ");
uint32_t time = ntpClient->getEpochTime();
_d(day(time)); _d("-"); _d(month(time)); _d("-"); _d(year(time)); _d(" ");
_d(hour(time)); _d(":"); _d(minute(time)); _d(":"); _dln(second(time));
_d("Status :: offset: ");
_dln(timezoneOffset);
}
}
#else
#define initDebug() do { } while (0)
#define updateDebugStatus() do { } while (0)
#endif