diff --git a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp index 1b0d18d..5cd318b 100644 --- a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp +++ b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp @@ -13,7 +13,7 @@ std::shared_ptr wifiHandler::getInstance() { return mInstance; }; -void wifiHandler::WiFiEvent(WiFiEvent_t event) { +void wifiHandler::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t aEventInfo) { int no_networks = 0; switch (event) { case ARDUINO_EVENT_WIFI_SCAN_DONE: { @@ -30,12 +30,14 @@ void wifiHandler::WiFiEvent(WiFiEvent_t event) { } break; } + case ARDUINO_EVENT_WIFI_STA_CONNECTED: + StoreCredentials(); + WiFi.setAutoConnect(true); + UpdateStatus(); + break; + case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: case ARDUINO_EVENT_WIFI_STA_GOT_IP: case ARDUINO_EVENT_WIFI_STA_GOT_IP6: - this->StoreCredentials(); - break; - case ARDUINO_EVENT_WIFI_STA_CONNECTED: - case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: case ARDUINO_EVENT_WIFI_STA_LOST_IP: case ARDUINO_EVENT_WIFI_STA_STOP: UpdateStatus(); @@ -43,16 +45,14 @@ void wifiHandler::WiFiEvent(WiFiEvent_t event) { default: break; } - if (WiFi.status() == WL_CONNECT_FAILED) { - WiFi.disconnect(); - } } void wifiHandler::UpdateStatus() { Serial.println("UpdateStatus"); mCurrentStatus.isConnected = WiFi.isConnected(); mCurrentStatus.IP = WiFi.localIP().toString().c_str(); - mCurrentStatus.ssid = WiFi.SSID().c_str(); + mCurrentStatus.ssid = + mCurrentStatus.isConnected ? WiFi.SSID().c_str() : mConnectionAttemptSSID; mStatusUpdate->notify(mCurrentStatus); } @@ -78,14 +78,16 @@ void wifiHandler::StoreCredentials() { void wifiHandler::scan() { Serial.println("scan called"); - + WiFi.setAutoReconnect(false); WiFi.scanNetworks(true); } void wifiHandler::begin() { WiFi.setHostname("OMOTE"); WiFi.mode(WIFI_STA); - WiFi.onEvent([](WiFiEvent_t event) { mInstance->WiFiEvent(event); }); + WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t aEventInfo) { + mInstance->WiFiEvent(event, aEventInfo); + }); Preferences preferences; preferences.begin("wifiSettings", false); @@ -95,7 +97,7 @@ void wifiHandler::begin() { // Attempt Connection with stored Credentials if (!ssid.isEmpty()) { - connect(mSSID, mPassword); + connect(ssid.c_str(), password.c_str()); } else { Serial.println("no SSID or password stored"); WiFi.disconnect(); @@ -105,9 +107,10 @@ void wifiHandler::begin() { } void wifiHandler::connect(std::string ssid, std::string password) { - Serial.printf("Attempting Wifi Connection To %s \n", mSSID.c_str()); + Serial.printf("Attempting Wifi Connection To %s \n", ssid.c_str()); mIsConnectionAttempt = true; mConnectionAttemptPassword = password; mConnectionAttemptSSID = ssid; - WiFi.begin(ssid.c_str(), password.c_str()); + auto status = WiFi.begin(mConnectionAttemptSSID.c_str(), + mConnectionAttemptPassword.c_str()); } diff --git a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp index bf3bfda..18c196e 100644 --- a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp +++ b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp @@ -30,7 +30,7 @@ private: * @brief Handler for incoming arduino wifi events * @param event - a Wifi event */ - void WiFiEvent(WiFiEvent_t event); + void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t aEventInfo); /** * @brief Update Internal status and send out a notification diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp index b262c7c..b262b3b 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp @@ -33,7 +33,9 @@ WifiSettings::WifiSettings(std::shared_ptr aWifi) mScanningText->SetText("Attempting Connection to " + wifiInfo.ssid); mPasswordGetter->AnimateOut(); - }); + StartHandlingStatusUpdates(); + }, + "Password:"); keyboard->OnKeyboardAnimatedOut([this] { // Once keyboard is done animating out remove it and null the ref to // it. @@ -46,21 +48,24 @@ WifiSettings::WifiSettings(std::shared_ptr aWifi) } }; + mWifi->scan(); +} + +void WifiSettings::StartHandlingStatusUpdates() { mScanStatusHandler = [this](auto aWifiStatus) { if (aWifiStatus.isConnected) { mScanningText->SetText("Connected to " + aWifiStatus.ssid); } else { - mScanningText->SetText("Failed To Connect To" + aWifiStatus.ssid); + mScanningText->SetText("Failed To Connect To " + aWifiStatus.ssid); } }; - - mWifi->scan(); } void WifiSettings::SetHeight(lv_coord_t aHeight) { Base::SetHeight(aHeight); mScanningText->AlignTo(this, LV_ALIGN_TOP_MID); mScanningText->SetHeight(20); + mScanningText->SetLongMode(LV_LABEL_LONG_SCROLL); const auto padding = 10; mWifiNetworks->AlignTo(mScanningText, LV_ALIGN_OUT_BOTTOM_MID, 0, padding); mWifiNetworks->SetHeight(GetContentHeight() - mScanningText->GetBottom() - diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp index f911ad5..9e04d67 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp @@ -17,6 +17,9 @@ public: void SetHeight(lv_coord_t aHeight) override; +protected: + void StartHandlingStatusUpdates(); + private: std::shared_ptr mWifi; Handler mScanCompleteHandler; diff --git a/Platformio/OmoteUI/core/widget/Keyboard.cpp b/Platformio/OmoteUI/core/widget/Keyboard.cpp index 268c37c..3059569 100644 --- a/Platformio/OmoteUI/core/widget/Keyboard.cpp +++ b/Platformio/OmoteUI/core/widget/Keyboard.cpp @@ -5,7 +5,8 @@ using namespace UI; using namespace UI::Widget; -Keyboard::Keyboard(std::function aOnUserCompletedTextEntry) +Keyboard::Keyboard(std::function aOnUserCompletedTextEntry, + std::string aPrompt) : Base(ID::Widgets::Keyboard), mKeyboard(AddElement(std::make_unique( lv_keyboard_create(LvglSelf()), ID::Widgets::INVALID_WIDGET_ID))), @@ -13,6 +14,9 @@ Keyboard::Keyboard(std::function aOnUserCompletedTextEntry) lv_textarea_create(LvglSelf()), ID::Widgets::INVALID_WIDGET_ID))), mOnUserCompleteTextEntry(aOnUserCompletedTextEntry) { lv_keyboard_set_textarea(mKeyboard->LvglSelf(), mTextArea->LvglSelf()); + if (!aPrompt.empty()) { + lv_textarea_set_placeholder_text(mTextArea->LvglSelf(), aPrompt.c_str()); + } mKeyboard->OnLvglEvent([this](auto aEvent) { if (aEvent->code == LV_EVENT_READY) { diff --git a/Platformio/OmoteUI/core/widget/Keyboard.hpp b/Platformio/OmoteUI/core/widget/Keyboard.hpp index 2296901..82f8e97 100644 --- a/Platformio/OmoteUI/core/widget/Keyboard.hpp +++ b/Platformio/OmoteUI/core/widget/Keyboard.hpp @@ -8,7 +8,8 @@ namespace UI::Widget { class Keyboard : public Base { public: - Keyboard(std::function aOnUserCompletedTextEntry); + Keyboard(std::function aOnUserCompletedTextEntry, + std::string aPrompt = ""); void OnAdded(UIElement *aNewParent) override; diff --git a/Platformio/OmoteUI/core/widget/Label.cpp b/Platformio/OmoteUI/core/widget/Label.cpp index 7c40554..867a6d8 100644 --- a/Platformio/OmoteUI/core/widget/Label.cpp +++ b/Platformio/OmoteUI/core/widget/Label.cpp @@ -14,7 +14,6 @@ Label::Label(std::string aText) void Label::SetText(std::string aText) { auto lock = LvglResourceManager::GetInstance().scopeLock(); lv_label_set_text(LvglSelf(), aText.c_str()); - SetLongMode(LV_LABEL_LONG_SCROLL); } void Label::SetLongMode(lv_label_long_mode_t aLongMode) {