WiFi improvements (#102)
This commit is contained in:
committed by
GitHub
parent
505befef42
commit
c7314546fe
@@ -15,6 +15,20 @@ void State::setRadioState(service::wifi::WifiRadioState state) {
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
service::wifi::WifiRadioState State::getRadioState() const {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
auto result = radioState;
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool State::isScanning() const {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
bool result = scanning;
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
return result;
|
||||
}
|
||||
|
||||
const std::vector<service::wifi::WifiApRecord>& State::lockApRecords() const {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
return apRecords;
|
||||
@@ -30,4 +44,17 @@ void State::updateApRecords() {
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
void State::setConnectSsid(std::string ssid) {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
connectSsid = ssid;
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
}
|
||||
|
||||
std::string State::getConnectSsid() const {
|
||||
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
|
||||
auto result = connectSsid;
|
||||
tt_check(mutex.release() == TtStatusOk);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace tt::app::wifimanage {
|
||||
*/
|
||||
class State {
|
||||
|
||||
Mutex mutex;
|
||||
Mutex mutex = Mutex(MutexTypeRecursive);
|
||||
bool scanning;
|
||||
service::wifi::WifiRadioState radioState;
|
||||
std::vector<service::wifi::WifiApRecord> apRecords;
|
||||
@@ -20,18 +20,18 @@ public:
|
||||
State() {}
|
||||
|
||||
void setScanning(bool isScanning);
|
||||
bool isScanning() const { return scanning; }
|
||||
bool isScanning() const;
|
||||
|
||||
void setRadioState(service::wifi::WifiRadioState state);
|
||||
service::wifi::WifiRadioState getRadioState() const { return radioState; }
|
||||
service::wifi::WifiRadioState getRadioState() const;
|
||||
|
||||
void updateApRecords();
|
||||
|
||||
const std::vector<service::wifi::WifiApRecord>& lockApRecords() const;
|
||||
void unlockApRecords() const;
|
||||
|
||||
void setConnectSsid(std::string ssid) { connectSsid = ssid; }
|
||||
std::string getConnectSsid() const { return connectSsid; }
|
||||
void setConnectSsid(std::string ssid);
|
||||
std::string getConnectSsid() const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -25,6 +25,15 @@ static void on_enable_switch_changed(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void on_enable_on_boot_switch_changed(lv_event_t* event) {
|
||||
lv_event_code_t code = lv_event_get_code(event);
|
||||
auto* enable_switch = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||
bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED);
|
||||
service::wifi::settings::setEnableOnBoot(is_on);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_disconnect_pressed(lv_event_t* event) {
|
||||
auto* bindings = static_cast<Bindings*>(lv_event_get_user_data(event));
|
||||
bindings->onDisconnect();
|
||||
@@ -120,6 +129,15 @@ void View::updateWifiToggle(State* state) {
|
||||
}
|
||||
}
|
||||
|
||||
void View::updateEnableOnBootToggle() {
|
||||
lv_obj_clear_state(enable_on_boot_switch, LV_STATE_ANY);
|
||||
if (service::wifi::settings::shouldEnableOnBoot()) {
|
||||
lv_obj_add_state(enable_on_boot_switch, LV_STATE_CHECKED);
|
||||
} else {
|
||||
lv_obj_remove_state(enable_on_boot_switch, LV_STATE_CHECKED);
|
||||
}
|
||||
}
|
||||
|
||||
void View::updateConnectedAp(State* state, TT_UNUSED Bindings* bindings) {
|
||||
switch (state->getRadioState()) {
|
||||
case service::wifi::WIFI_RADIO_CONNECTION_PENDING:
|
||||
@@ -141,7 +159,10 @@ void View::init(const App& app, Bindings* bindings, lv_obj_t* parent) {
|
||||
root = parent;
|
||||
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
lv_obj_t* toolbar = lvgl::toolbar_create(parent, app);
|
||||
|
||||
enable_switch = lvgl::toolbar_add_switch_action(toolbar);
|
||||
lv_obj_add_event_cb(enable_switch, on_enable_switch_changed, LV_EVENT_ALL, bindings);
|
||||
|
||||
lv_obj_t* wrapper = lv_obj_create(parent);
|
||||
lv_obj_set_width(wrapper, LV_PCT(100));
|
||||
@@ -156,12 +177,12 @@ void View::init(const App& app, Bindings* bindings, lv_obj_t* parent) {
|
||||
lvgl::obj_set_style_bg_invisible(switch_container);
|
||||
|
||||
lv_obj_t* enable_label = lv_label_create(switch_container);
|
||||
lv_label_set_text(enable_label, "Wi-Fi");
|
||||
lv_label_set_text(enable_label, "Enable on boot");
|
||||
lv_obj_set_align(enable_label, LV_ALIGN_LEFT_MID);
|
||||
|
||||
enable_switch = lv_switch_create(switch_container);
|
||||
lv_obj_add_event_cb(enable_switch, on_enable_switch_changed, LV_EVENT_ALL, bindings);
|
||||
lv_obj_set_align(enable_switch, LV_ALIGN_RIGHT_MID);
|
||||
enable_on_boot_switch = lv_switch_create(switch_container);
|
||||
lv_obj_add_event_cb(enable_on_boot_switch, on_enable_on_boot_switch_changed, LV_EVENT_ALL, bindings);
|
||||
lv_obj_set_align(enable_on_boot_switch, LV_ALIGN_RIGHT_MID);
|
||||
|
||||
connected_ap_container = lv_obj_create(wrapper);
|
||||
lv_obj_set_size(connected_ap_container, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
@@ -207,6 +228,7 @@ void View::init(const App& app, Bindings* bindings, lv_obj_t* parent) {
|
||||
|
||||
void View::update(Bindings* bindings, State* state) {
|
||||
updateWifiToggle(state);
|
||||
updateEnableOnBootToggle();
|
||||
updateScanning(state);
|
||||
updateNetworkList(state, bindings);
|
||||
updateConnectedAp(state, bindings);
|
||||
|
||||
@@ -11,6 +11,7 @@ class View {
|
||||
private:
|
||||
lv_obj_t* root = nullptr;
|
||||
lv_obj_t* enable_switch = nullptr;
|
||||
lv_obj_t* enable_on_boot_switch = nullptr;
|
||||
lv_obj_t* scanning_spinner = nullptr;
|
||||
lv_obj_t* networks_label = nullptr;
|
||||
lv_obj_t* networks_list = nullptr;
|
||||
@@ -25,6 +26,7 @@ private:
|
||||
|
||||
void updateConnectedAp(State* state, TT_UNUSED Bindings* bindings);
|
||||
void updateWifiToggle(State* state);
|
||||
void updateEnableOnBootToggle();
|
||||
void updateScanning(State* state);
|
||||
void updateNetworkList(State* state, Bindings* bindings);
|
||||
void createNetworkButton(Bindings* bindings, const service::wifi::WifiApRecord& record);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "WifiManage.h"
|
||||
|
||||
#include "app/App.h"
|
||||
#include "app/wificonnect/WifiConnectBundle.h"
|
||||
#include "app/wificonnect/Parameters.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "service/loader/Loader.h"
|
||||
#include "service/wifi/WifiSettings.h"
|
||||
|
||||
Reference in New Issue
Block a user