Skip to content

Commit

Permalink
added initial wifi settings page
Browse files Browse the repository at this point in the history
currently can  scan for networks and
show them but clicking does nothing.
  • Loading branch information
MatthewColvin committed Oct 15, 2023
1 parent 38ec26d commit 99787a6
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ BasicUI::BasicUI(std::shared_ptr<HardwareAbstract> aHardware)

Screen::Manager::getInstance().pushScreen(
std::make_unique<Screen::HomeScreen>(aHardware));

mHardware->wifi()->begin();
}
9 changes: 8 additions & 1 deletion Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ScreenManager.hpp"
#include "Slider.hpp"
#include "SystemSettings.hpp"
#include "WifiSettings.hpp"

using namespace UI::Page;
using namespace UI::Color;
Expand All @@ -19,7 +20,8 @@ SettingsPage::SettingsPage(std::shared_ptr<HardwareAbstract> 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(); });
}
Expand All @@ -33,3 +35,8 @@ void SettingsPage::PushSystemSettings() {
UI::Screen::Manager::getInstance().pushPopUp(
std::make_unique<SystemSettings>(mHardware));
}

void SettingsPage::PushWifiSettings() {
UI::Screen::Manager::getInstance().pushPopUp(
std::make_unique<WifiSettings>(mHardware->wifi()));
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SettingsPage : public Base {

void PushDisplaySettings();
void PushSystemSettings();
void PushWifiSettings();

protected:
void OnShow() override{};
Expand Down
41 changes: 41 additions & 0 deletions Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.cpp
Original file line number Diff line number Diff line change
@@ -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);
};
27 changes: 27 additions & 0 deletions Platformio/OmoteUI/UIs/BasicRefactored/page/WifiSettings.hpp
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Platformio/OmoteUI/core/UIElementIds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ID {
enum class Pages {
Settings = static_cast<int>(Widgets::INVALID_WIDGET_ID) + 1,
DisplaySettings,
WifiSettings,
SystemSettings,
Demo,
INVALID_PAGE_ID
Expand Down
9 changes: 8 additions & 1 deletion Platformio/OmoteUI/core/widget/Label.cpp
Original file line number Diff line number Diff line change
@@ -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());
}
2 changes: 2 additions & 0 deletions Platformio/OmoteUI/core/widget/Label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace UI::Widget {
class Label : public Base {
public:
Label(std::string aText);

void SetText(std::string aText);
};

} // namespace UI::Widget
7 changes: 6 additions & 1 deletion Platformio/OmoteUI/core/widget/List.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "List.hpp"
#include "BackgroundScreen.hpp"
#include "LvglResourceManager.hpp"
using namespace UI;
using namespace UI::Widget;

Expand All @@ -22,7 +23,11 @@ List::List()

void List::AddItem(std::string aTitle, const char *aSymbol,
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(
std::make_unique<ListItem>(lvListItem, std::move(onItemSelected)));
mListItems.back()->SetHeight(lv_pct(20));
Expand Down

0 comments on commit 99787a6

Please sign in to comment.