added initial wifi settings page

currently can  scan for networks and
show them but clicking does nothing.
This commit is contained in:
MatthewColvin 2023-10-15 00:24:07 -05:00
parent 38ec26dce7
commit 99787a69f2
9 changed files with 96 additions and 3 deletions

View file

@ -15,4 +15,6 @@ BasicUI::BasicUI(std::shared_ptr<HardwareAbstract> aHardware)
Screen::Manager::getInstance().pushScreen( Screen::Manager::getInstance().pushScreen(
std::make_unique<Screen::HomeScreen>(aHardware)); std::make_unique<Screen::HomeScreen>(aHardware));
mHardware->wifi()->begin();
} }

View file

@ -8,6 +8,7 @@
#include "ScreenManager.hpp" #include "ScreenManager.hpp"
#include "Slider.hpp" #include "Slider.hpp"
#include "SystemSettings.hpp" #include "SystemSettings.hpp"
#include "WifiSettings.hpp"
using namespace UI::Page; using namespace UI::Page;
using namespace UI::Color; using namespace UI::Color;
@ -19,7 +20,8 @@ SettingsPage::SettingsPage(std::shared_ptr<HardwareAbstract> aHardware)
mSettingsList->AddItem("Display", LV_SYMBOL_EYE_OPEN, mSettingsList->AddItem("Display", LV_SYMBOL_EYE_OPEN,
[this] { PushDisplaySettings(); }); [this] { PushDisplaySettings(); });
mSettingsList->AddItem("Wifi", LV_SYMBOL_WIFI, [] {}); mSettingsList->AddItem("Wifi", LV_SYMBOL_WIFI,
[this] { PushWifiSettings(); });
mSettingsList->AddItem("System", LV_SYMBOL_SETTINGS, mSettingsList->AddItem("System", LV_SYMBOL_SETTINGS,
[this] { PushSystemSettings(); }); [this] { PushSystemSettings(); });
} }
@ -33,3 +35,8 @@ void SettingsPage::PushSystemSettings() {
UI::Screen::Manager::getInstance().pushPopUp( UI::Screen::Manager::getInstance().pushPopUp(
std::make_unique<SystemSettings>(mHardware)); std::make_unique<SystemSettings>(mHardware));
} }
void SettingsPage::PushWifiSettings() {
UI::Screen::Manager::getInstance().pushPopUp(
std::make_unique<WifiSettings>(mHardware->wifi()));
}

View file

@ -16,6 +16,7 @@ public:
void PushDisplaySettings(); void PushDisplaySettings();
void PushSystemSettings(); void PushSystemSettings();
void PushWifiSettings();
protected: protected:
void OnShow() override{}; void OnShow() override{};

View file

@ -0,0 +1,41 @@
#include "WifiSettings.hpp"
#include "Label.hpp"
#include "List.hpp"
#include "LvglResourceManager.hpp"
//#include <Arduino.h>
using namespace UI;
using namespace UI::Page;
WifiSettings::WifiSettings(std::shared_ptr<wifiHandlerInterface> aWifi)
: Base(ID::Pages::WifiSettings), mWifi(aWifi),
mScanCompleteHandler(mWifi->ScanCompleteNotification()),
mScanningText(AddElement<Widget::Label>(
std::make_unique<Widget::Label>("Scanning..."))),
mWifiNetworks(
AddElement<Widget::List>(std::make_unique<Widget::List>())) {
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);
};

View file

@ -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<wifiHandlerInterface> aWifi);
std::string GetTitle() override { return "Wifi Settings"; };
void SetHeight(lv_coord_t aHeight) override;
private:
std::shared_ptr<wifiHandlerInterface> mWifi;
Handler<wifiHandlerInterface::ScanDoneDataTy> mScanCompleteHandler;
UI::Widget::Label *mScanningText;
UI::Widget::List *mWifiNetworks;
};
} // namespace UI::Page

View file

@ -26,6 +26,7 @@ public:
enum class Pages { enum class Pages {
Settings = static_cast<int>(Widgets::INVALID_WIDGET_ID) + 1, Settings = static_cast<int>(Widgets::INVALID_WIDGET_ID) + 1,
DisplaySettings, DisplaySettings,
WifiSettings,
SystemSettings, SystemSettings,
Demo, Demo,
INVALID_PAGE_ID INVALID_PAGE_ID

View file

@ -1,10 +1,17 @@
#include "Label.hpp" #include "Label.hpp"
#include "BackgroundScreen.hpp" #include "BackgroundScreen.hpp"
#include "Colors.hpp" #include "Colors.hpp"
#include "LvglResourceManager.hpp"
using namespace UI::Widget; using namespace UI::Widget;
Label::Label(std::string aText) 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()); lv_label_set_text(LvglSelf(), aText.c_str());
} }

View file

@ -7,6 +7,8 @@ namespace UI::Widget {
class Label : public Base { class Label : public Base {
public: public:
Label(std::string aText); Label(std::string aText);
void SetText(std::string aText);
}; };
} // namespace UI::Widget } // namespace UI::Widget

View file

@ -1,5 +1,6 @@
#include "List.hpp" #include "List.hpp"
#include "BackgroundScreen.hpp" #include "BackgroundScreen.hpp"
#include "LvglResourceManager.hpp"
using namespace UI; using namespace UI;
using namespace UI::Widget; using namespace UI::Widget;
@ -22,7 +23,11 @@ List::List()
void List::AddItem(std::string aTitle, const char *aSymbol, void List::AddItem(std::string aTitle, const char *aSymbol,
std::function<void()> onItemSelected) { std::function<void()> 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( mListItems.push_back(
std::make_unique<ListItem>(lvListItem, std::move(onItemSelected))); std::make_unique<ListItem>(lvListItem, std::move(onItemSelected)));
mListItems.back()->SetHeight(lv_pct(20)); mListItems.back()->SetHeight(lv_pct(20));