diff --git a/Platformio/HAL/HardwareModules/wifiHandlerInterface.h b/Platformio/HAL/HardwareModules/wifiHandlerInterface.h index fd61c4d..1bd93d1 100644 --- a/Platformio/HAL/HardwareModules/wifiHandlerInterface.h +++ b/Platformio/HAL/HardwareModules/wifiHandlerInterface.h @@ -3,25 +3,25 @@ #include #include -struct WifiInfo { - WifiInfo(){}; - WifiInfo(std::string aSsid, int aRssi) : ssid(aSsid), rssi(aRssi) {} - - std::string ssid = ""; - int rssi = 0; -}; - -struct wifiStatus { - wifiStatus(bool aConnected, std::string aIp, std::string aSsid) - : isConnected(aConnected), IP(aIp), ssid(aSsid){}; - - bool isConnected; - std::string IP = ""; - std::string ssid = ""; -}; - class wifiHandlerInterface { public: + struct WifiInfo { + WifiInfo(){}; + WifiInfo(std::string aSsid, int aRssi) : ssid(aSsid), rssi(aRssi) {} + + std::string ssid = ""; + int rssi = 0; + }; + + struct wifiStatus { + wifiStatus(bool aConnected, std::string aIp, std::string aSsid) + : isConnected(aConnected), IP(aIp), ssid(aSsid){}; + + bool isConnected; + std::string IP = ""; + std::string ssid = ""; + }; + typedef std::vector ScanDoneDataTy; typedef Notification ScanNotificationTy; diff --git a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp index 9b9ddec..b25bf9d 100644 --- a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp +++ b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp @@ -107,7 +107,6 @@ void wifiHandler::update_credentials() { void wifiHandler::scan() { Serial.println("scan called"); - WiFi.disconnect(); WiFi.scanNetworks(true); } diff --git a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp index b7dd33a..44618a6 100644 --- a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp +++ b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp @@ -1,5 +1,7 @@ #include "wifiHandlerSim.hpp" +using WifiInfo = wifiHandlerInterface::WifiInfo; + wifiHandlerSim::wifiHandlerSim() {} void wifiHandlerSim::begin() {} diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp index 0295276..480631e 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp @@ -6,10 +6,12 @@ using namespace UI; using namespace UI::Page; +using WifiInfo = wifiHandlerInterface::WifiInfo; WifiSettings::WifiSettings(std::shared_ptr aWifi) : Base(ID::Pages::WifiSettings), mWifi(aWifi), mScanCompleteHandler(mWifi->ScanCompleteNotification()), + mScanStatusHandler(mWifi->WifiStatusNotification()), mScanningText(AddElement( std::make_unique("Scanning..."))), mWifiNetworks(AddElement(std::make_unique())), @@ -27,6 +29,8 @@ WifiSettings::WifiSettings(std::shared_ptr aWifi) [this, wifiInfo](auto aUserEnteredPassword) { // Attempt Connection when user finishes up with keyboard input mWifi->connect(wifiInfo.ssid, aUserEnteredPassword); + mScanningText->SetText("Attempting Connection to " + + wifiInfo.ssid); mPasswordGetter->AnimateOut(); }); keyboard->OnKeyboardAnimatedOut([this] { @@ -41,6 +45,14 @@ WifiSettings::WifiSettings(std::shared_ptr aWifi) } }; + mScanStatusHandler = [this](auto aWifiStatus) { + if (aWifiStatus.isConnected) { + mScanningText->SetText("Connected to " + aWifiStatus.ssid); + } else { + mScanningText->SetText("Failed To Connect To" + aWifiStatus.ssid); + } + }; + mWifi->scan(); } diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp index 3a1e2dc..f911ad5 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp @@ -20,6 +20,7 @@ public: private: std::shared_ptr mWifi; Handler mScanCompleteHandler; + Handler mScanStatusHandler; UI::Widget::Label *mScanningText; UI::Widget::List *mWifiNetworks; diff --git a/Platformio/OmoteUI/core/UIElement.hpp b/Platformio/OmoteUI/core/UIElement.hpp index f60555e..11b2837 100644 --- a/Platformio/OmoteUI/core/UIElement.hpp +++ b/Platformio/OmoteUI/core/UIElement.hpp @@ -91,11 +91,17 @@ public: void StartLvglEventHandler(); void StopLvglEventHandler(); -protected: - /// @brief get Lvgl object refernce to use in LVGL APIs + /// @brief Register a callback to run for Lvgl Events for objects that + /// are created from base classes. + void OnLvglEvent(std::function aLvglEventHandler) { + mLvglEventHandler = aLvglEventHandler; + } + + /// @brief get Lvgl object reference to use in LVGL APIs /// @return lvgl object a lv_obj_t *LvglSelf() { return mLvglSelf; } +protected: /// @brief Show Element virtual void Show(); /// @brief Hide Element @@ -116,12 +122,6 @@ protected: } }; - /// @brief Register a callback to run for Lvgl Events for objects that - /// are created from base classes. - void OnLvglEvent(std::function aLvglEventHandler) { - mLvglEventHandler = aLvglEventHandler; - } - /// @brief Set KeyEvent to the UI element to see if it wants to handle it virtual bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent); diff --git a/Platformio/OmoteUI/core/widget/Keyboard.cpp b/Platformio/OmoteUI/core/widget/Keyboard.cpp index 35e059a..268c37c 100644 --- a/Platformio/OmoteUI/core/widget/Keyboard.cpp +++ b/Platformio/OmoteUI/core/widget/Keyboard.cpp @@ -14,7 +14,7 @@ Keyboard::Keyboard(std::function aOnUserCompletedTextEntry) mOnUserCompleteTextEntry(aOnUserCompletedTextEntry) { lv_keyboard_set_textarea(mKeyboard->LvglSelf(), mTextArea->LvglSelf()); - mKeyboard->HandleLvglEvent([this](auto aEvent) { + mKeyboard->OnLvglEvent([this](auto aEvent) { if (aEvent->code == LV_EVENT_READY) { std::string userEnteredText = std::string(lv_textarea_get_text(mTextArea->LvglSelf()));