Skip to content

Commit

Permalink
minor wifi improvements (#70)
Browse files Browse the repository at this point in the history
* make the wifi handling a bit more intuitive
  • Loading branch information
consp authored Apr 11, 2024
1 parent e9a7c1f commit 8c29efe
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/wifi_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ WifiPanel::WifiPanel(std::mutex &l)
lv_textarea_set_one_line(password_input, true);

lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_event_cb(password_input, &WifiPanel::_handle_kb_input, LV_EVENT_ALL, this);
lv_obj_add_event_cb(password_input, &WifiPanel::_handle_kb_input, LV_EVENT_FOCUSED, this);
lv_obj_add_event_cb(password_input, &WifiPanel::_handle_kb_input, LV_EVENT_DEFOCUSED, this);
lv_obj_add_event_cb(password_input, &WifiPanel::_handle_kb_input, LV_EVENT_READY, this);

// allow clicks on non-clickables to hide the keyboard
lv_obj_add_event_cb(prompt_cont, &WifiPanel::_handle_kb_input, LV_EVENT_CLICKED, this);
lv_obj_add_event_cb(wifi_label, &WifiPanel::_handle_kb_input, LV_EVENT_CLICKED, this);
lv_obj_move_background(cont);
lv_obj_move_foreground(spinner);

Expand Down Expand Up @@ -150,6 +155,7 @@ void WifiPanel::handle_callback(lv_event_t *e) {
} else {
lv_label_set_text(wifi_label, fmt::format("Enter password for {}", selected_network).c_str());
lv_obj_clear_flag(password_input, LV_OBJ_FLAG_HIDDEN);
lv_event_send(password_input, LV_EVENT_FOCUSED, NULL);
}

lv_obj_clear_flag(prompt_cont, LV_OBJ_FLAG_HIDDEN);
Expand Down Expand Up @@ -250,14 +256,12 @@ void WifiPanel::handle_kb_input(lv_event_t *e)
if(code == LV_EVENT_FOCUSED) {
lv_keyboard_set_textarea(kb, password_input);
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
}

if(code == LV_EVENT_DEFOCUSED) {
} else if(code == LV_EVENT_DEFOCUSED) {
lv_keyboard_set_textarea(kb, NULL);
lv_label_set_text(wifi_label, "Please select your wifi network");
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
}

if (code == LV_EVENT_READY) {
lv_obj_add_flag(password_input, LV_OBJ_FLAG_HIDDEN);
} else if (code == LV_EVENT_READY) {
const char *password = lv_textarea_get_text(password_input);
if (password == NULL || password[0] == 0) {
return;
Expand All @@ -266,6 +270,15 @@ void WifiPanel::handle_kb_input(lv_event_t *e)
// add network, set password, save wpa
connect(password);
lv_textarea_set_text(password_input, "");
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
lv_label_set_text(wifi_label, fmt::format("Connecting to {} ...", selected_network).c_str());
lv_obj_clear_state(password_input, LV_STATE_FOCUSED);
lv_obj_add_flag(password_input, LV_OBJ_FLAG_HIDDEN);
} else if (code == LV_EVENT_CLICKED) {
lv_obj_t *target = lv_event_get_target(e);
if (target != kb && target != password_input) {
lv_event_send(password_input, LV_EVENT_DEFOCUSED, NULL);
}
}
}

Expand Down

0 comments on commit 8c29efe

Please sign in to comment.