diff --git a/.gitmodules b/.gitmodules index 44beed1..b7da252 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,3 +37,6 @@ [submodule "components/fmt"] path = components/fmt url = git@github.com:0xFEEDC0DE64/fmt.git +[submodule "components/espwifistack"] + path = components/espwifistack + url = git@github.com:0xFEEDC0DE64/espwifistack.git diff --git a/components/espwifistack b/components/espwifistack new file mode 160000 index 0000000..0497b7a --- /dev/null +++ b/components/espwifistack @@ -0,0 +1 @@ +Subproject commit 0497b7a1345f87ed2f54fd6ddf89dca0755276cc diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 830e653..f1201c0 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -154,6 +154,7 @@ set(headers feedbackparser.h globals.h htmlutils.h + macros_bobbycar.h modeinterface.h ota.h serialhandler.h @@ -167,6 +168,7 @@ set(headers unifiedmodelmode.h utils.h wifitexthelpers.h + wifi_bobbycar.h ) set(sources @@ -179,7 +181,7 @@ set(dependencies # AsyncTCP bobbycar-protocol cpputils cxx-ring-buffer date # ESPAsyncWebServer - espchrono espcpputils expected fmt TFT_eSPI + espchrono espcpputils espwifistack expected fmt TFT_eSPI ) idf_component_register( diff --git a/main/actions/wifisoftapaction.h b/main/actions/wifisoftapaction.h index 63a809d..007cb51 100644 --- a/main/actions/wifisoftapaction.h +++ b/main/actions/wifisoftapaction.h @@ -1,8 +1,10 @@ #pragma once +// local includes #include "actioninterface.h" #include "globals.h" #include "utils.h" +#include "macros_bobbycar.h" namespace { class WifiSoftApAction : public virtual ActionInterface diff --git a/main/displays/statusdisplay.h b/main/displays/statusdisplay.h index 887ae5d..4b20577 100644 --- a/main/displays/statusdisplay.h +++ b/main/displays/statusdisplay.h @@ -163,7 +163,7 @@ void StatusDisplay::redraw() m_labelLimit1.redraw(std::to_string(controllers.front.command.left.iDcMax) + "A"); m_labelPerformance.redraw(std::to_string(performance.last)); m_labelMode.redraw(currentMode->displayName()); - m_labelName.redraw(&deviceName[0]); + m_labelName.redraw(deviceName); const auto profile = settingsPersister.currentlyOpenProfileIndex(); m_labelProfile.redraw(profile ? std::to_string(*profile) : "-"); } diff --git a/main/globals.h b/main/globals.h index c09d708..74fa05b 100644 --- a/main/globals.h +++ b/main/globals.h @@ -14,6 +14,7 @@ #endif #include +// 3rdparty lib includes #include #include @@ -23,6 +24,7 @@ #include "modeinterface.h" #include "settings.h" #include "settingspersister.h" +#include "macros_bobbycar.h" namespace { std::optional raw_gas, raw_brems; @@ -34,7 +36,7 @@ float gametrakX, gametrakY, gametrakDist; #endif float avgSpeed, avgSpeedKmh, sumCurrent; -char deviceName[32]; +char deviceName[32] = STRING(DEVICE_PREFIX) "_ERR"; Settings settings; SettingsPersister settingsPersister; diff --git a/main/macros_bobbycar.h b/main/macros_bobbycar.h new file mode 100644 index 0000000..13fdd05 --- /dev/null +++ b/main/macros_bobbycar.h @@ -0,0 +1,5 @@ +#pragma once + +// macros are a shit piece of software +#define STRING2(s) #s +#define STRING(s) STRING2(s) diff --git a/main/main.cpp b/main/main.cpp index 69bbc7e..8aed033 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -3,6 +3,7 @@ // esp-idf includes #include +#include // Arduino includes #include @@ -10,10 +11,12 @@ // 3rdparty lib includes #include using namespace std::chrono_literals; +#include // local includes #include "bobbycar-common.h" #include "bobbycar-serial.h" +#include "macros_bobbycar.h" #include "globals.h" #include "modes/defaultmode.h" #include "modes/tempomatmode.h" @@ -176,13 +179,12 @@ extern "C" void app_main() printMemoryStats("swapFronBack()"); #endif - //bootLabel.redraw("deviceName"); - //{ - // uint8_t macAddress[6]; - // WiFi.macAddress(&macAddress[0]); - // std::sprintf(deviceName, STRING(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", macAddress[3], macAddress[4], macAddress[5]); - //} - //printMemoryStats("deviceName"); + bootLabel.redraw("deviceName"); + if (const auto result = wifi_stack::get_default_mac_addr()) + std::sprintf(deviceName, STRING(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", result->at(3), result->at(4), result->at(5)); + else + ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data()); + printMemoryStats("deviceName"); //bootLabel.redraw("setHostname"); //if (!WiFi.setHostname(deviceName)) diff --git a/main/utils.h b/main/utils.h index ba627b4..309e89f 100644 --- a/main/utils.h +++ b/main/utils.h @@ -28,10 +28,6 @@ #include "can.h" #endif -// macros are a shit piece of software -#define STRING2(s) #s -#define STRING(s) STRING2(s) - namespace { bool currentlyReverseBeeping; bool reverseBeepToggle; diff --git a/main/wifi_bobbycar.h b/main/wifi_bobbycar.h new file mode 100644 index 0000000..d373912 --- /dev/null +++ b/main/wifi_bobbycar.h @@ -0,0 +1,8 @@ +#pragma once + +// 3rdparty lib includes +#include + +namespace { + +} // namespace diff --git a/main/wifiaccessors.h b/main/wifiaccessors.h index 10ee782..eec93c1 100644 --- a/main/wifiaccessors.h +++ b/main/wifiaccessors.h @@ -1,7 +1,9 @@ #pragma once +// esp-idf includes #include +// local includes #include "accessorinterface.h" namespace {