added full ability to connect to wifi
This commit is contained in:
parent
cf646f21db
commit
ae7bc0da54
7 changed files with 41 additions and 27 deletions
|
@ -3,25 +3,25 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
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 {
|
class wifiHandlerInterface {
|
||||||
public:
|
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<WifiInfo> ScanDoneDataTy;
|
typedef std::vector<WifiInfo> ScanDoneDataTy;
|
||||||
typedef Notification<ScanDoneDataTy> ScanNotificationTy;
|
typedef Notification<ScanDoneDataTy> ScanNotificationTy;
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,6 @@ void wifiHandler::update_credentials() {
|
||||||
void wifiHandler::scan() {
|
void wifiHandler::scan() {
|
||||||
Serial.println("scan called");
|
Serial.println("scan called");
|
||||||
|
|
||||||
WiFi.disconnect();
|
|
||||||
WiFi.scanNetworks(true);
|
WiFi.scanNetworks(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "wifiHandlerSim.hpp"
|
#include "wifiHandlerSim.hpp"
|
||||||
|
|
||||||
|
using WifiInfo = wifiHandlerInterface::WifiInfo;
|
||||||
|
|
||||||
wifiHandlerSim::wifiHandlerSim() {}
|
wifiHandlerSim::wifiHandlerSim() {}
|
||||||
|
|
||||||
void wifiHandlerSim::begin() {}
|
void wifiHandlerSim::begin() {}
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
|
|
||||||
using namespace UI;
|
using namespace UI;
|
||||||
using namespace UI::Page;
|
using namespace UI::Page;
|
||||||
|
using WifiInfo = wifiHandlerInterface::WifiInfo;
|
||||||
|
|
||||||
WifiSettings::WifiSettings(std::shared_ptr<wifiHandlerInterface> aWifi)
|
WifiSettings::WifiSettings(std::shared_ptr<wifiHandlerInterface> aWifi)
|
||||||
: Base(ID::Pages::WifiSettings), mWifi(aWifi),
|
: Base(ID::Pages::WifiSettings), mWifi(aWifi),
|
||||||
mScanCompleteHandler(mWifi->ScanCompleteNotification()),
|
mScanCompleteHandler(mWifi->ScanCompleteNotification()),
|
||||||
|
mScanStatusHandler(mWifi->WifiStatusNotification()),
|
||||||
mScanningText(AddElement<Widget::Label>(
|
mScanningText(AddElement<Widget::Label>(
|
||||||
std::make_unique<Widget::Label>("Scanning..."))),
|
std::make_unique<Widget::Label>("Scanning..."))),
|
||||||
mWifiNetworks(AddElement<Widget::List>(std::make_unique<Widget::List>())),
|
mWifiNetworks(AddElement<Widget::List>(std::make_unique<Widget::List>())),
|
||||||
|
@ -27,6 +29,8 @@ WifiSettings::WifiSettings(std::shared_ptr<wifiHandlerInterface> aWifi)
|
||||||
[this, wifiInfo](auto aUserEnteredPassword) {
|
[this, wifiInfo](auto aUserEnteredPassword) {
|
||||||
// Attempt Connection when user finishes up with keyboard input
|
// Attempt Connection when user finishes up with keyboard input
|
||||||
mWifi->connect(wifiInfo.ssid, aUserEnteredPassword);
|
mWifi->connect(wifiInfo.ssid, aUserEnteredPassword);
|
||||||
|
mScanningText->SetText("Attempting Connection to " +
|
||||||
|
wifiInfo.ssid);
|
||||||
mPasswordGetter->AnimateOut();
|
mPasswordGetter->AnimateOut();
|
||||||
});
|
});
|
||||||
keyboard->OnKeyboardAnimatedOut([this] {
|
keyboard->OnKeyboardAnimatedOut([this] {
|
||||||
|
@ -41,6 +45,14 @@ WifiSettings::WifiSettings(std::shared_ptr<wifiHandlerInterface> 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();
|
mWifi->scan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<wifiHandlerInterface> mWifi;
|
std::shared_ptr<wifiHandlerInterface> mWifi;
|
||||||
Handler<wifiHandlerInterface::ScanDoneDataTy> mScanCompleteHandler;
|
Handler<wifiHandlerInterface::ScanDoneDataTy> mScanCompleteHandler;
|
||||||
|
Handler<wifiHandlerInterface::wifiStatus> mScanStatusHandler;
|
||||||
|
|
||||||
UI::Widget::Label *mScanningText;
|
UI::Widget::Label *mScanningText;
|
||||||
UI::Widget::List *mWifiNetworks;
|
UI::Widget::List *mWifiNetworks;
|
||||||
|
|
|
@ -91,11 +91,17 @@ public:
|
||||||
void StartLvglEventHandler();
|
void StartLvglEventHandler();
|
||||||
void StopLvglEventHandler();
|
void StopLvglEventHandler();
|
||||||
|
|
||||||
protected:
|
/// @brief Register a callback to run for Lvgl Events for objects that
|
||||||
/// @brief get Lvgl object refernce to use in LVGL APIs
|
/// are created from base classes.
|
||||||
|
void OnLvglEvent(std::function<void(lv_event_t *anEvent)> aLvglEventHandler) {
|
||||||
|
mLvglEventHandler = aLvglEventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief get Lvgl object reference to use in LVGL APIs
|
||||||
/// @return lvgl object a
|
/// @return lvgl object a
|
||||||
lv_obj_t *LvglSelf() { return mLvglSelf; }
|
lv_obj_t *LvglSelf() { return mLvglSelf; }
|
||||||
|
|
||||||
|
protected:
|
||||||
/// @brief Show Element
|
/// @brief Show Element
|
||||||
virtual void Show();
|
virtual void Show();
|
||||||
/// @brief Hide Element
|
/// @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<void(lv_event_t *anEvent)> aLvglEventHandler) {
|
|
||||||
mLvglEventHandler = aLvglEventHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @brief Set KeyEvent to the UI element to see if it wants to handle it
|
/// @brief Set KeyEvent to the UI element to see if it wants to handle it
|
||||||
virtual bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent);
|
virtual bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ Keyboard::Keyboard(std::function<void(std::string)> aOnUserCompletedTextEntry)
|
||||||
mOnUserCompleteTextEntry(aOnUserCompletedTextEntry) {
|
mOnUserCompleteTextEntry(aOnUserCompletedTextEntry) {
|
||||||
lv_keyboard_set_textarea(mKeyboard->LvglSelf(), mTextArea->LvglSelf());
|
lv_keyboard_set_textarea(mKeyboard->LvglSelf(), mTextArea->LvglSelf());
|
||||||
|
|
||||||
mKeyboard->HandleLvglEvent([this](auto aEvent) {
|
mKeyboard->OnLvglEvent([this](auto aEvent) {
|
||||||
if (aEvent->code == LV_EVENT_READY) {
|
if (aEvent->code == LV_EVENT_READY) {
|
||||||
std::string userEnteredText =
|
std::string userEnteredText =
|
||||||
std::string(lv_textarea_get_text(mTextArea->LvglSelf()));
|
std::string(lv_textarea_get_text(mTextArea->LvglSelf()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue