Wifi app improvements (#107)

This commit is contained in:
Ken Van Hoeylandt
2024-12-05 23:14:27 +01:00
committed by GitHub
parent 50ee77d572
commit 422bc01fdb
11 changed files with 104 additions and 60 deletions
+9 -10
View File
@@ -14,14 +14,16 @@ namespace tt::app::wificonnect {
#define TAG "wifi_connect"
std::shared_ptr<WifiConnect> _Nullable optWifiConnect();
void View::resetErrors() {
lv_obj_add_flag(password_error, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(ssid_error, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(connection_error, LV_OBJ_FLAG_HIDDEN);
}
static void onConnect(lv_event_t* event) {
auto* wifi = (WifiConnect*)lv_event_get_user_data(event);
static void onConnect(TT_UNUSED lv_event_t* event) {
auto wifi = optWifiConnect();
auto& view = wifi->getView();
wifi->getState().setConnectionError(false);
@@ -78,7 +80,7 @@ void View::setLoading(bool loading) {
}
}
void View::createBottomButtons(WifiConnect* wifi, lv_obj_t* parent) {
void View::createBottomButtons(lv_obj_t* parent) {
lv_obj_t* button_container = lv_obj_create(parent);
lv_obj_set_width(button_container, LV_PCT(100));
lv_obj_set_height(button_container, LV_SIZE_CONTENT);
@@ -103,11 +105,11 @@ void View::createBottomButtons(WifiConnect* wifi, lv_obj_t* parent) {
lv_obj_t* connect_label = lv_label_create(connect_button);
lv_label_set_text(connect_label, "Connect");
lv_obj_align(connect_button, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(connect_button, &onConnect, LV_EVENT_CLICKED, wifi);
lv_obj_add_event_cb(connect_button, &onConnect, LV_EVENT_CLICKED, nullptr);
}
// TODO: Standardize dialogs
void View::init(AppContext& app, WifiConnect* wifiConnect, lv_obj_t* parent) {
void View::init(AppContext& app, lv_obj_t* parent) {
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lvgl::toolbar_create(parent, app);
@@ -180,7 +182,7 @@ void View::init(AppContext& app, WifiConnect* wifiConnect, lv_obj_t* parent) {
lv_obj_add_flag(connection_error, LV_OBJ_FLAG_HIDDEN);
// Bottom buttons
createBottomButtons(wifiConnect, wrapper);
createBottomButtons(wrapper);
// Keyboard bindings
service::gui::keyboardAddTextArea(ssid_textarea);
@@ -201,10 +203,7 @@ void View::init(AppContext& app, WifiConnect* wifiConnect, lv_obj_t* parent) {
}
}
void View::update(
TT_UNUSED Bindings* bindings,
State* state
) {
void View::update() {
if (state->hasConnectionError()) {
setLoading(false);
resetErrors();
+13 -4
View File
@@ -12,6 +12,11 @@ class WifiConnect;
class View {
private:
Bindings* bindings;
State* state;
public:
lv_obj_t* ssid_textarea = nullptr;
@@ -19,16 +24,20 @@ public:
lv_obj_t* password_textarea = nullptr;
lv_obj_t* password_error = nullptr;
lv_obj_t* connect_button = nullptr;
lv_obj_t* cancel_button = nullptr;
lv_obj_t* remember_switch = nullptr;
lv_obj_t* connecting_spinner = nullptr;
lv_obj_t* connection_error = nullptr;
lv_group_t* group = nullptr;
void init(AppContext& app, WifiConnect* wifiConnect, lv_obj_t* parent);
void update(Bindings* bindings, State* state);
View(Bindings* bindings, State* state) :
bindings(bindings),
state(state)
{}
void createBottomButtons(WifiConnect* wifi, lv_obj_t* parent);
void init(AppContext& app, lv_obj_t* parent);
void update();
void createBottomButtons(lv_obj_t* parent);
void setLoading(bool loading);
void resetErrors();
};
@@ -79,7 +79,7 @@ void WifiConnect::requestViewUpdate() {
lock();
if (view_enabled) {
if (lvgl::lock(1000)) {
view.update(&bindings, &state);
view.update();
lvgl::unlock();
} else {
TT_LOG_E(TAG, "Failed to lock lvgl");
@@ -91,12 +91,12 @@ void WifiConnect::requestViewUpdate() {
void WifiConnect::onShow(AppContext& app, lv_obj_t* parent) {
lock();
view_enabled = true;
view.init(app, this, parent);
view.update(&bindings, &state);
view.init(app, parent);
view.update();
unlock();
}
void WifiConnect::onHide(AppContext& app) {
void WifiConnect::onHide(TT_UNUSED AppContext& app) {
// No need to lock view, as this is called from within Gui's LVGL context
lock();
view_enabled = false;
@@ -10,15 +10,15 @@
namespace tt::app::wificonnect {
class WifiConnect {
PubSubSubscription* wifiSubscription;
Mutex mutex;
State state;
View view;
bool view_enabled = false;
Bindings bindings = {
.onConnectSsid = nullptr,
.onConnectSsidContext = nullptr
};
View view = View(&bindings, &state);
PubSubSubscription* wifiSubscription;
bool view_enabled = false;
public: