Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
UI Statusbar now displays wifi status
  • Loading branch information
SumolX committed Jun 1, 2023
commit c0535045320f8e505f2b0b31bfd2ff1f8e22b963
49 changes: 41 additions & 8 deletions src/ui/page_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,39 @@ static void page_wifi_update_settings() {
}

/**
* Updates the all notes on every page.
* Acquire the actual address in use.
*/
void page_wifi_update_notes() {
static const char *page_wifi_get_real_address() {
const char *address = NULL;
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);

// Get DHCP Client assigned address
if (btn_group_get_sel(&page_wifi.page_1.mode.button) == WIFI_MODE_STA &&
btn_group_get_sel(&page_wifi.page_2.dhcp.button) == 0) {
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (fd >= 0) {
struct ifreq ifr;
strcpy(ifr.ifr_name, "wlan0");

// Try to derive the real ip address
if (0 == ioctl(fd, SIOCGIFADDR, &ifr)) {
address = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
} else {
address = "x.x.x.x";
}

close(fd);
}

return address;
}

/**
* Updates the all notes on every page.
*/
static void page_wifi_update_notes() {
const char *address = page_wifi_get_real_address();

if (btn_group_get_sel(&page_wifi.page_1.mode.button) == WIFI_MODE_STA &&
btn_group_get_sel(&page_wifi.page_2.dhcp.button) == 0 &&
address == NULL) {
address = "x.x.x.x";
}

static char buffer[1024];
snprintf(buffer,
sizeof(buffer),
Expand Down Expand Up @@ -892,3 +903,25 @@ page_pack_t pp_wifi = {
.on_click = page_wifi_on_click,
.on_right_button = page_wifi_on_right_button,
};

/**
* Provides the WiFi status string referenced by ui_statusbar.
*/
void page_wifi_get_statusbar_text(char *buffer, int size) {
if (g_setting.wifi.enable) {
switch (g_setting.wifi.mode) {
case WIFI_MODE_AP:
snprintf(buffer, size, "WiFi: %s", g_setting.wifi.ssid[WIFI_MODE_AP]);
break;
case WIFI_MODE_STA:
if (page_wifi_get_real_address()) {
snprintf(buffer, size, "WiFi: %s", g_setting.wifi.ssid[WIFI_MODE_STA]);
} else {
snprintf(buffer, size, "WiFi: Searching");
}
break;
}
} else {
snprintf(buffer, size, "WiFi: Off");
}
}
2 changes: 2 additions & 0 deletions src/ui/page_wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#include "ui/ui_main_menu.h"

extern page_pack_t pp_wifi;

extern void page_wifi_get_statusbar_text(char *buffer, int size);
125 changes: 65 additions & 60 deletions src/ui/ui_statusbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
#include "driver/gpio.h"
#include "ui/page_common.h"
#include "ui/page_playback.h"
#include "ui/page_wifi.h"
#include "ui/ui_style.h"

///////////////////////////////////////////////////////////////////////////////
// local
static lv_obj_t *label0;
static lv_obj_t *label1;
static lv_obj_t *label2;
static lv_obj_t *label3;
static lv_obj_t *label4;
enum STATUS {
STS_SDCARD,
STS_SOURCE,
STS_ELRS,
STS_WIFI,
STS_BATT,

STS_TOTAL
};

static lv_obj_t *label[STS_TOTAL];

static lv_obj_t *img_sdc;
LV_IMG_DECLARE(img_sdcard);
Expand Down Expand Up @@ -91,59 +98,59 @@ int statusbar_init(void) {
lv_obj_set_grid_cell(img_battery, LV_GRID_ALIGN_CENTER, 9, 1,
LV_GRID_ALIGN_CENTER, 0, 1);

label0 = lv_label_create(cont);
lv_label_set_long_mode(label0, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_label_set_text(label0, "SD Card ");
lv_obj_set_width(label0, 267); /*Set smaller width to make the lines wrap*/
lv_label_set_recolor(label0, true);
lv_obj_set_style_text_align(label0, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label0, lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label0, LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1);
label[STS_SDCARD] = lv_label_create(cont);
lv_label_set_long_mode(label[STS_SDCARD], LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_label_set_text(label[STS_SDCARD], "SD Card ");
lv_obj_set_width(label[STS_SDCARD], 267); /*Set smaller width to make the lines wrap*/
lv_label_set_recolor(label[STS_SDCARD], true);
lv_obj_set_style_text_align(label[STS_SDCARD], LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label[STS_SDCARD], lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label[STS_SDCARD], LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1);

label1 = lv_label_create(cont);
lv_label_set_long_mode(label1, LV_LABEL_LONG_DOT); /*Break the long lines*/
label[STS_SOURCE] = lv_label_create(cont);
lv_label_set_long_mode(label[STS_SOURCE], LV_LABEL_LONG_DOT); /*Break the long lines*/

sprintf(buf, "RF: HDZero %s", channel2str(g_setting.scan.channel & 0xF));

lv_label_set_text(label1, buf);
lv_obj_set_width(label1, 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label1, lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label1, LV_GRID_ALIGN_CENTER, 4, 1,
lv_label_set_text(label[STS_SOURCE], buf);
lv_obj_set_width(label[STS_SOURCE], 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label[STS_SOURCE], LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label[STS_SOURCE], lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label[STS_SOURCE], LV_GRID_ALIGN_CENTER, 4, 1,
LV_GRID_ALIGN_CENTER, 0, 1);

label2 = lv_label_create(cont);
lv_label_set_long_mode(label2, LV_LABEL_LONG_DOT); /*Break the long lines*/
lv_label_set_text(label2, "ELRS: Off");
lv_obj_set_width(label2, 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label2, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label2, lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label2, LV_GRID_ALIGN_CENTER, 6, 1,
label[STS_ELRS] = lv_label_create(cont);
lv_label_set_long_mode(label[STS_ELRS], LV_LABEL_LONG_DOT); /*Break the long lines*/
lv_label_set_text(label[STS_ELRS], "ELRS: Off");
lv_obj_set_width(label[STS_ELRS], 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label[STS_ELRS], LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label[STS_ELRS], lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label[STS_ELRS], LV_GRID_ALIGN_CENTER, 6, 1,
LV_GRID_ALIGN_CENTER, 0, 1);

label3 = lv_label_create(cont);
lv_label_set_long_mode(label3, LV_LABEL_LONG_DOT); /*Break the long lines*/
lv_label_set_text(label3, "Wifi: Off");
lv_obj_set_width(label3, 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label3, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label3, lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label3, LV_GRID_ALIGN_CENTER, 8, 1,
label[STS_WIFI] = lv_label_create(cont);
lv_label_set_long_mode(label[STS_WIFI], LV_LABEL_LONG_DOT); /*Break the long lines*/
lv_label_set_text(label[STS_WIFI], "WiFi: Off");
lv_obj_set_width(label[STS_WIFI], 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label[STS_WIFI], LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label[STS_WIFI], lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label[STS_WIFI], LV_GRID_ALIGN_CENTER, 8, 1,
LV_GRID_ALIGN_CENTER, 0, 1);

label4 = lv_label_create(cont);
lv_label_set_long_mode(label4, LV_LABEL_LONG_DOT); /*Break the long lines*/
lv_label_set_text(label4, " ");
lv_obj_set_width(label4, 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label4, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label4, lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label4, LV_GRID_ALIGN_CENTER, 10, 1,
label[STS_BATT] = lv_label_create(cont);
lv_label_set_long_mode(label[STS_BATT], LV_LABEL_LONG_DOT); /*Break the long lines*/
lv_label_set_text(label[STS_BATT], " ");
lv_obj_set_width(label[STS_BATT], 267); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label[STS_BATT], LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_text_color(label[STS_BATT], lv_color_make(255, 255, 255), 0);
lv_obj_set_grid_cell(label[STS_BATT], LV_GRID_ALIGN_CENTER, 10, 1,
LV_GRID_ALIGN_CENTER, 0, 1);

lv_obj_set_style_text_font(label0, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label1, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label2, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label3, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label4, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label[STS_BATT], &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label[STS_BATT], &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label[STS_BATT], &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label[STS_BATT], &lv_font_montserrat_26, 0);
lv_obj_set_style_text_font(label[STS_BATT], &lv_font_montserrat_26, 0);

return 0;
}
Expand All @@ -154,7 +161,7 @@ void statubar_update(void) {

// display battery voltage
battery_get_voltage_str(buf);
lv_label_set_text(label4, buf);
lv_label_set_text(label[STS_BATT], buf);

{
#define BEEP_INTERVAL 20
Expand All @@ -173,15 +180,15 @@ void statubar_update(void) {
beep();
beep_gap = 0;
}
lv_obj_set_style_text_color(label4, lv_color_make(255, 255, 255), 0);
lv_obj_set_style_text_color(label[STS_BATT], lv_color_make(255, 255, 255), 0);
}
break;

case SETTING_POWER_WARNING_TYPE_VISUAL:
if (low)
lv_obj_set_style_text_color(label4, lv_color_make(255, 0, 0), 0);
lv_obj_set_style_text_color(label[STS_BATT], lv_color_make(255, 0, 0), 0);
else
lv_obj_set_style_text_color(label4, lv_color_make(255, 255, 255), 0);
lv_obj_set_style_text_color(label[STS_BATT], lv_color_make(255, 255, 255), 0);
break;

case SETTING_POWER_WARNING_TYPE_BOTH:
Expand All @@ -190,9 +197,9 @@ void statubar_update(void) {
beep();
beep_gap = 0;
}
lv_obj_set_style_text_color(label4, lv_color_make(255, 0, 0), 0);
lv_obj_set_style_text_color(label[STS_BATT], lv_color_make(255, 0, 0), 0);
} else
lv_obj_set_style_text_color(label4, lv_color_make(255, 255, 255), 0);
lv_obj_set_style_text_color(label[STS_BATT], lv_color_make(255, 255, 255), 0);
break;
default:
break;
Expand All @@ -216,7 +223,7 @@ void statubar_update(void) {
else
sprintf(buf, "Expansion Module");

lv_label_set_text(label1, buf);
lv_label_set_text(label[STS_SOURCE], buf);
}
channel_last = g_setting.scan.channel;
source_last = g_source_info.source;
Expand All @@ -242,15 +249,13 @@ void statubar_update(void) {
lv_img_set_src(img_sdc, &img_noSdcard);
}

lv_label_set_text(label0, buf);
lv_label_set_text(label[STS_SDCARD], buf);

if (g_setting.elrs.enable)
lv_label_set_text(label2, "ELRS: On ");
lv_label_set_text(label[STS_ELRS], "ELRS: On ");
else
lv_label_set_text(label2, "ELRS: Off");
lv_label_set_text(label[STS_ELRS], "ELRS: Off");

if (g_setting.wifi.enable)
lv_label_set_text(label3, "WIFI: On ");
else
lv_label_set_text(label3, "WIFI: Off");
page_wifi_get_statusbar_text(buf, sizeof(buf));
lv_label_set_text(label[STS_WIFI], buf);
}