From 99787a69f2d95816862431daf3f6aed931c763ab Mon Sep 17 00:00:00 2001 From: MatthewColvin Date: Sun, 15 Oct 2023 00:24:07 -0500 Subject: [PATCH] added initial wifi settings page currently can scan for networks and show them but clicking does nothing. --- .../OmoteUI/UIs/BasicRefactored/BasicUI.cpp | 2 + .../UIs/BasicRefactored/page/SettingsPage.cpp | 9 +++- .../UIs/BasicRefactored/page/SettingsPage.hpp | 1 + .../UIs/BasicRefactored/page/WifiSettings.cpp | 41 +++++++++++++++++++ .../UIs/BasicRefactored/page/WifiSettings.hpp | 27 ++++++++++++ Platformio/OmoteUI/core/UIElementIds.hpp | 1 + Platformio/OmoteUI/core/widget/Label.cpp | 9 +++- Platformio/OmoteUI/core/widget/Label.hpp | 2 + Platformio/OmoteUI/core/widget/List.cpp | 7 +++- 9 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp create mode 100644 Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp index 28c91aa..755aefd 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp @@ -15,4 +15,6 @@ BasicUI::BasicUI(std::shared_ptr aHardware) Screen::Manager::getInstance().pushScreen( std::make_unique(aHardware)); + + mHardware->wifi()->begin(); } \ No newline at end of file diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp index 724b48a..f101ba9 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp @@ -8,6 +8,7 @@ #include "ScreenManager.hpp" #include "Slider.hpp" #include "SystemSettings.hpp" +#include "WifiSettings.hpp" using namespace UI::Page; using namespace UI::Color; @@ -19,7 +20,8 @@ SettingsPage::SettingsPage(std::shared_ptr aHardware) mSettingsList->AddItem("Display", LV_SYMBOL_EYE_OPEN, [this] { PushDisplaySettings(); }); - mSettingsList->AddItem("Wifi", LV_SYMBOL_WIFI, [] {}); + mSettingsList->AddItem("Wifi", LV_SYMBOL_WIFI, + [this] { PushWifiSettings(); }); mSettingsList->AddItem("System", LV_SYMBOL_SETTINGS, [this] { PushSystemSettings(); }); } @@ -33,3 +35,8 @@ void SettingsPage::PushSystemSettings() { UI::Screen::Manager::getInstance().pushPopUp( std::make_unique(mHardware)); } + +void SettingsPage::PushWifiSettings() { + UI::Screen::Manager::getInstance().pushPopUp( + std::make_unique(mHardware->wifi())); +} diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.hpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.hpp index 3bd23a8..1a017e5 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.hpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.hpp @@ -16,6 +16,7 @@ public: void PushDisplaySettings(); void PushSystemSettings(); + void PushWifiSettings(); protected: void OnShow() override{}; diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp new file mode 100644 index 0000000..6018bf0 --- /dev/null +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp @@ -0,0 +1,41 @@ +#include "WifiSettings.hpp" +#include "Label.hpp" +#include "List.hpp" +#include "LvglResourceManager.hpp" +//#include + +using namespace UI; +using namespace UI::Page; + +WifiSettings::WifiSettings(std::shared_ptr aWifi) + : Base(ID::Pages::WifiSettings), mWifi(aWifi), + mScanCompleteHandler(mWifi->ScanCompleteNotification()), + mScanningText(AddElement( + std::make_unique("Scanning..."))), + mWifiNetworks( + AddElement(std::make_unique())) { + + mScanCompleteHandler = [this](auto aWifiInfos) { + // Serial.println("populating UI"); + mScanningText->SetText("Networks Found"); + for (WifiInfo wifiInfo : aWifiInfos) { + mWifiNetworks->AddItem(wifiInfo.ssid, LV_SYMBOL_WIFI, [] {}); + } + }; + + mWifi->scan(); + + // mWifi->onScanDone([this](auto aWifiInfos) { + // + // }); +} + +void WifiSettings::SetHeight(lv_coord_t aHeight) { + Base::SetHeight(aHeight); + mScanningText->AlignTo(this, LV_ALIGN_TOP_MID); + mScanningText->SetHeight(15); + const auto padding = 10; + mWifiNetworks->AlignTo(mScanningText, LV_ALIGN_OUT_BOTTOM_MID, 0, padding); + mWifiNetworks->SetHeight(GetContentHeight() - mScanningText->GetBottom() - + padding); +}; diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp new file mode 100644 index 0000000..521c68e --- /dev/null +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp @@ -0,0 +1,27 @@ +#pragma once +#include "PageBase.hpp" +#include "wifiHandlerInterface.h" + +namespace UI::Widget { +class List; +class Label; +} // namespace UI::Widget + +namespace UI::Page { +class WifiSettings : public Base { +public: + WifiSettings(std::shared_ptr aWifi); + + std::string GetTitle() override { return "Wifi Settings"; }; + + void SetHeight(lv_coord_t aHeight) override; + +private: + std::shared_ptr mWifi; + Handler mScanCompleteHandler; + + UI::Widget::Label *mScanningText; + UI::Widget::List *mWifiNetworks; +}; + +} // namespace UI::Page \ No newline at end of file diff --git a/Platformio/OmoteUI/core/UIElementIds.hpp b/Platformio/OmoteUI/core/UIElementIds.hpp index b46a305..acf8bef 100644 --- a/Platformio/OmoteUI/core/UIElementIds.hpp +++ b/Platformio/OmoteUI/core/UIElementIds.hpp @@ -26,6 +26,7 @@ public: enum class Pages { Settings = static_cast(Widgets::INVALID_WIDGET_ID) + 1, DisplaySettings, + WifiSettings, SystemSettings, Demo, INVALID_PAGE_ID diff --git a/Platformio/OmoteUI/core/widget/Label.cpp b/Platformio/OmoteUI/core/widget/Label.cpp index 07345a4..ca61935 100644 --- a/Platformio/OmoteUI/core/widget/Label.cpp +++ b/Platformio/OmoteUI/core/widget/Label.cpp @@ -1,10 +1,17 @@ #include "Label.hpp" #include "BackgroundScreen.hpp" #include "Colors.hpp" +#include "LvglResourceManager.hpp" using namespace UI::Widget; Label::Label(std::string aText) - : Base(lv_label_create(UI::Screen::BackgroundScreen::getLvInstance()), ID::Widgets::Label) { + : Base(lv_label_create(UI::Screen::BackgroundScreen::getLvInstance()), + ID::Widgets::Label) { + SetText(aText); +} + +void Label::SetText(std::string aText) { + auto lock = LvglResourceManager::GetInstance().scopeLock(); lv_label_set_text(LvglSelf(), aText.c_str()); } \ No newline at end of file diff --git a/Platformio/OmoteUI/core/widget/Label.hpp b/Platformio/OmoteUI/core/widget/Label.hpp index 2698ba2..47c482d 100644 --- a/Platformio/OmoteUI/core/widget/Label.hpp +++ b/Platformio/OmoteUI/core/widget/Label.hpp @@ -7,6 +7,8 @@ namespace UI::Widget { class Label : public Base { public: Label(std::string aText); + + void SetText(std::string aText); }; } // namespace UI::Widget diff --git a/Platformio/OmoteUI/core/widget/List.cpp b/Platformio/OmoteUI/core/widget/List.cpp index 9087324..53f4ad2 100644 --- a/Platformio/OmoteUI/core/widget/List.cpp +++ b/Platformio/OmoteUI/core/widget/List.cpp @@ -1,5 +1,6 @@ #include "List.hpp" #include "BackgroundScreen.hpp" +#include "LvglResourceManager.hpp" using namespace UI; using namespace UI::Widget; @@ -22,7 +23,11 @@ List::List() void List::AddItem(std::string aTitle, const char *aSymbol, std::function onItemSelected) { - auto lvListItem = lv_list_add_btn(LvglSelf(), aSymbol, aTitle.c_str()); + lv_obj_t *lvListItem = nullptr; + { + auto lock = LvglResourceManager::GetInstance().scopeLock(); + lvListItem = lv_list_add_btn(LvglSelf(), aSymbol, aTitle.c_str()); + } mListItems.push_back( std::make_unique(lvListItem, std::move(onItemSelected))); mListItems.back()->SetHeight(lv_pct(20));