Updated wifi selection subpage handling

* Wifi selection subpage now only displays 3 found wifi networks at a time
* User can switch between selection pages to see all found wifi networks
This commit is contained in:
Thomas Bittner 2023-08-09 21:07:32 +02:00
parent 745e2dff51
commit 1ef4d8e8df
6 changed files with 159 additions and 58 deletions

View file

@ -83,6 +83,11 @@ void Display::setup()
digitalWrite(this->backlight_pin, HIGH);
this->tft = TFT_eSPI();
#if 1
ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION);
ledcAttachPin(this->backlight_pin, LCD_BACKLIGHT_LEDC_CHANNEL);
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0);
#else
// Configure the backlight PWM
// Manual setup because ledcSetup() briefly turns on the backlight
ledc_channel_config_t ledc_channel_left;
@ -102,6 +107,8 @@ void Display::setup()
ledc_channel_config(&ledc_channel_left);
ledc_timer_config(&ledc_timer);
#endif
// Slowly charge the VSW voltage to prevent a brownout
// Workaround for hardware rev 1!

View file

@ -52,17 +52,13 @@ class Display
*/
void flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p );
/**
* @brief Function to add list of networks to the wifi selection page.
* @brief API function to inform display that wifi scan is completed
*
* @param SSIDS Pointer to the list of SSIDs found. The strings are moved out and the pointer does not have to
* life after the function returns.
* @param RSSI Pointer to the list of the RSSI per SSID. The ordering of SSID and RSSI list should be equal. The
* value is moved out of the array in the function, therefore the array does not have to be valid after the
* function returns.
* @param size Size of the SSIDS and RSSI array.
* @param size number of wifi networks found
*/
void add_wifi_networks(String *SSIDS, int *RSSI, unsigned int size);
void wifi_scan_complete(unsigned int size);
/**
* @brief Clear the wifi networks listed in the wifi selection page. This function is called before new wifi
@ -255,6 +251,26 @@ class Display
*/
lv_obj_t* WifiLabel;
/**
* @brief Number of wifi subpage needed to display the found wifi networks
*
*/
unsigned int no_subpages;
/**
* @brief number of wifi networks found
*
*/
unsigned int no_wifi_networks;
/**
* @brief callback function to get next wifi subpage. This callback can be used to get the next or previous page
*
* @param e lvgl event object
*/
void next_wifi_selection_subpage(lv_event_t* e);
/**
* @brief Create a wifi selection sub page object
*
@ -287,6 +303,12 @@ class Display
*/
void create_wifi_settings(lv_obj_t* menu, lv_obj_t* parent);
/**
* @brief Function to update the wifi selection sub page
*
* @param page index of the page to display
*/
void update_wifi_selection_subpage(int page);
/************************************** Display settings menu ********************************************************/
/**

View file

@ -11,7 +11,7 @@ extern bool wakeupByIMUEnabled;
void bl_slider_event_cb(lv_event_t * e){
lv_obj_t * slider = lv_event_get_target(e);
unsigned int* backlight_brightness = (unsigned int*) lv_event_get_user_data(e);
*backlight_brightness = constrain(lv_slider_get_value(slider), 30, 255);
*backlight_brightness = map(constrain(lv_slider_get_value(slider), 30, 255), 30, 255, 255, 30);
}
// Wakeup by IMU Switch Event handler

View file

@ -17,7 +17,7 @@
/*********************************************************************************************************************
************************************************* Local functions ****************************************************
**********************************************************************************************************************/
#define WIFI_SUBPAGE_SIZE 3
extern wifiHandler wifihandler;
extern Display display;
static char* ssid;
@ -125,10 +125,14 @@ static void connect_btn_cb(lv_event_t* event)
void Display::clear_wifi_networks()
{
lv_obj_clean(this->wifi_setting_cont);
this->no_subpages = 0;
}
void Display::add_wifi_networks(String *SSIDs, int *RSSI, unsigned int size)
void Display::wifi_scan_complete(unsigned int size)
{
this->no_subpages = (size + WIFI_SUBPAGE_SIZE - 1)/WIFI_SUBPAGE_SIZE;
this->no_wifi_networks = size;
if (size == 0)
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
@ -137,49 +141,97 @@ void Display::add_wifi_networks(String *SSIDs, int *RSSI, unsigned int size)
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "no networks found");
}
for (int i = 0; i < size; i++)
else
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text_fmt(menuLabel, "%s", SSIDs[i]);
#if 0
menuLabel = lv_label_create(menuBox);
lv_label_set_text_fmt(menuLabel, "%d", RSSI[i]);
lv_obj_align(menuLabel, LV_ALIGN_TOP_RIGHT, 0, 0);
#else
lv_obj_t* wifi_image = lv_img_create(menuBox);
lv_obj_align(wifi_image, LV_ALIGN_TOP_RIGHT, 0, 0);
if (RSSI[i] > -50)
{
lv_img_set_src(wifi_image, &WiFi_High_Signal);
}
else if (RSSI[i] > -60)
{
lv_img_set_src(wifi_image, &WiFi_Mid_Signal);
}
else if (RSSI[i] > -70)
{
lv_img_set_src(wifi_image, &WiFi_Low_Signal);
}
else
{
lv_img_set_src(wifi_image, &WiFi_No_Signal);
}
lv_obj_set_style_img_recolor(wifi_image, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(wifi_image, LV_OPA_COVER, LV_PART_MAIN);
#endif
lv_menu_set_load_page_event(this->settingsMenu, menuBox, this->wifi_password_page);
lv_obj_add_event_cb(menuBox, wifi_selected_cb, LV_EVENT_CLICKED, this->wifi_password_label);
this->update_wifi_selection_subpage(0);
}
}
void Display::update_wifi_selection_subpage(int page)
{
if (page < this->no_subpages)
{
lv_obj_clean(this->wifi_setting_cont);
lv_obj_t* pageLabel = lv_label_create(this->wifi_setting_cont);
lv_label_set_text_fmt(pageLabel, "Page %d/%d", page + 1, this->no_subpages);
if (page > 0)
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "Previous");
lv_obj_align(menuLabel, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_add_event_cb(menuBox, [](lv_event_t* e) {display.next_wifi_selection_subpage(e);},LV_EVENT_CLICKED, (void*)(page - 1));
lv_obj_t* arrow = lv_label_create(menuBox);
lv_label_set_text(arrow, LV_SYMBOL_LEFT);
lv_obj_align(arrow, LV_ALIGN_TOP_LEFT, 0, 0);
}
for (int i = 0; i < WIFI_SUBPAGE_SIZE && (page*WIFI_SUBPAGE_SIZE + i) < this->no_wifi_networks; i++)
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_add_flag(menuBox, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, wifihandler.getFoundSSID(page*WIFI_SUBPAGE_SIZE + i).c_str());
lv_obj_t* wifi_image = lv_img_create(menuBox);
lv_obj_align(wifi_image, LV_ALIGN_TOP_RIGHT, 0, 0);
int RSSI = wifihandler.getFoundRSSI(page*WIFI_SUBPAGE_SIZE + i);
if (RSSI > -50)
{
lv_img_set_src(wifi_image, &WiFi_High_Signal);
}
else if (RSSI > -60)
{
lv_img_set_src(wifi_image, &WiFi_Mid_Signal);
}
else if (RSSI > -70)
{
lv_img_set_src(wifi_image, &WiFi_Low_Signal);
}
else
{
lv_img_set_src(wifi_image, &WiFi_No_Signal);
}
lv_obj_set_style_img_recolor(wifi_image, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(wifi_image, LV_OPA_COVER, LV_PART_MAIN);
lv_menu_set_load_page_event(this->settingsMenu, menuBox, this->wifi_password_page);
lv_obj_add_event_cb(menuBox, wifi_selected_cb, LV_EVENT_CLICKED, this->wifi_password_label);
}
if ((page + 1) < this->no_subpages)
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "Next");
lv_obj_add_event_cb(menuBox, [](lv_event_t* e) {display.next_wifi_selection_subpage(e);}, LV_EVENT_CLICKED, (void*)(page + 1));
lv_obj_t* arrow = lv_label_create(menuBox);
lv_label_set_text(arrow, LV_SYMBOL_RIGHT);
lv_obj_align(arrow, LV_ALIGN_TOP_RIGHT, 0, 0);
}
lv_obj_scroll_to_y(this->wifi_setting_cont, 0, LV_ANIM_OFF);
}
}
void Display::next_wifi_selection_subpage(lv_event_t* e)
{
int subpage = (int) lv_event_get_user_data(e);
this->update_wifi_selection_subpage(subpage);
}
void Display::update_wifi(bool connected)
{

View file

@ -42,14 +42,7 @@ void WiFiEvent(WiFiEvent_t event){
display.clear_wifi_networks();
Serial.print(no_networks);
Serial.print(" found\n");
String SSIDS[no_networks];
int RSSIS[no_networks];
for (int i = 0; i < no_networks; i++)
{
SSIDS[i] = WiFi.SSID(i);
RSSIS[i] = WiFi.RSSI(i);
}
display.add_wifi_networks(SSIDS, RSSIS, no_networks);
display.wifi_scan_complete( no_networks);
}
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
@ -67,6 +60,17 @@ void WiFiEvent(WiFiEvent_t event){
break;
}
}
String wifiHandler::getFoundSSID(unsigned int index)
{
return WiFi.SSID(index);
}
int wifiHandler::getFoundRSSI(unsigned int index)
{
return WiFi.RSSI(index);
}
wifiHandler::wifiHandler()
{
this->password[0] = '\0';

View file

@ -23,6 +23,22 @@ class wifiHandler {
*/
void disconnect();
/**
* @brief Get the SSID of the found wifi
*
* @param index index of the found wifi
* @return String SSID of the wifi
*/
String getFoundSSID(unsigned int index);
/**
* @brief Get the RSSI of the found wifi
*
* @param index index of the found wifi
* @return int RSSI value of the found wifi
*/
int getFoundRSSI(unsigned int index);
/**
* @brief Function to determine wether or not we are connected to a network
*