dashboard: draw wifi signal bars
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
static const char *DASHBOARD_VERSION = "0.1.11-main-ui-pass";
|
static const char *DASHBOARD_VERSION = "0.1.12-wifi-bars";
|
||||||
|
|
||||||
// Update these if your Cargo ESP AP credentials are different.
|
// Update these if your Cargo ESP AP credentials are different.
|
||||||
static const char *CARGO_WIFI_SSID = "OverlandController";
|
static const char *CARGO_WIFI_SSID = "OverlandController";
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ static lv_obj_t *inside_temp_label = nullptr;
|
|||||||
static lv_obj_t *outside_temp_label = nullptr;
|
static lv_obj_t *outside_temp_label = nullptr;
|
||||||
static lv_obj_t *system_status_label = nullptr;
|
static lv_obj_t *system_status_label = nullptr;
|
||||||
static lv_obj_t *wifi_icon_label = nullptr;
|
static lv_obj_t *wifi_icon_label = nullptr;
|
||||||
|
static lv_obj_t *wifi_bars_obj[4] = {nullptr};
|
||||||
static lv_obj_t *cargo_status_dot = nullptr;
|
static lv_obj_t *cargo_status_dot = nullptr;
|
||||||
static lv_obj_t *relay_buttons[6] = {nullptr};
|
static lv_obj_t *relay_buttons[6] = {nullptr};
|
||||||
static lv_obj_t *relay_button_labels[6] = {nullptr};
|
static lv_obj_t *relay_button_labels[6] = {nullptr};
|
||||||
@@ -89,27 +90,27 @@ static String format_hours(float hours)
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String wifi_bars()
|
static int wifi_bar_count()
|
||||||
{
|
{
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
return "□□□□";
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rssi = WiFi.RSSI();
|
int rssi = WiFi.RSSI();
|
||||||
|
|
||||||
if (rssi > -60) {
|
if (rssi > -60) {
|
||||||
return "■■■■";
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rssi > -70) {
|
if (rssi > -70) {
|
||||||
return "■■■□";
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rssi > -80) {
|
if (rssi > -80) {
|
||||||
return "■■□□";
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "■□□□";
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_status_icons()
|
static void update_status_icons()
|
||||||
@@ -120,7 +121,19 @@ static void update_status_icons()
|
|||||||
|
|
||||||
lvgl_port_lock(-1);
|
lvgl_port_lock(-1);
|
||||||
|
|
||||||
lv_label_set_text(wifi_icon_label, wifi_bars().c_str());
|
int bars = wifi_bar_count();
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (wifi_bars_obj[i] == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_set_style_bg_color(
|
||||||
|
wifi_bars_obj[i],
|
||||||
|
i < bars ? lv_color_hex(0xDDE3EA) : lv_color_hex(0x3A4652),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
lv_obj_set_style_bg_color(
|
lv_obj_set_style_bg_color(
|
||||||
cargo_status_dot,
|
cargo_status_dot,
|
||||||
@@ -830,17 +843,24 @@ static void create_overland_overview_screen()
|
|||||||
}
|
}
|
||||||
|
|
||||||
wifi_icon_label = lv_label_create(system_card);
|
wifi_icon_label = lv_label_create(system_card);
|
||||||
lv_label_set_text(wifi_icon_label, "□□□□");
|
lv_label_set_text(wifi_icon_label, "");
|
||||||
lv_obj_set_style_text_color(wifi_icon_label, lv_color_hex(0xDDE3EA), 0);
|
lv_obj_add_flag(wifi_icon_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
lv_obj_set_style_text_font(wifi_icon_label, &lv_font_montserrat_30, 0);
|
|
||||||
lv_obj_align(wifi_icon_label, LV_ALIGN_LEFT_MID, 10, 0);
|
for (int i = 0; i < 4; i++) {
|
||||||
|
wifi_bars_obj[i] = lv_obj_create(system_card);
|
||||||
|
lv_obj_set_size(wifi_bars_obj[i], 12, 14 + (i * 8));
|
||||||
|
lv_obj_set_style_radius(wifi_bars_obj[i], 2, 0);
|
||||||
|
lv_obj_set_style_border_width(wifi_bars_obj[i], 0, 0);
|
||||||
|
lv_obj_set_style_bg_color(wifi_bars_obj[i], lv_color_hex(0x3A4652), 0);
|
||||||
|
lv_obj_align(wifi_bars_obj[i], LV_ALIGN_LEFT_MID, 12 + (i * 18), 12 - (i * 4));
|
||||||
|
}
|
||||||
|
|
||||||
cargo_status_dot = lv_obj_create(system_card);
|
cargo_status_dot = lv_obj_create(system_card);
|
||||||
lv_obj_set_size(cargo_status_dot, 22, 22);
|
lv_obj_set_size(cargo_status_dot, 22, 22);
|
||||||
lv_obj_set_style_radius(cargo_status_dot, LV_RADIUS_CIRCLE, 0);
|
lv_obj_set_style_radius(cargo_status_dot, LV_RADIUS_CIRCLE, 0);
|
||||||
lv_obj_set_style_bg_color(cargo_status_dot, lv_color_hex(0xF97066), 0);
|
lv_obj_set_style_bg_color(cargo_status_dot, lv_color_hex(0xF97066), 0);
|
||||||
lv_obj_set_style_border_width(cargo_status_dot, 0, 0);
|
lv_obj_set_style_border_width(cargo_status_dot, 0, 0);
|
||||||
lv_obj_align(cargo_status_dot, LV_ALIGN_LEFT_MID, 118, 0);
|
lv_obj_align(cargo_status_dot, LV_ALIGN_LEFT_MID, 100, 0);
|
||||||
|
|
||||||
system_status_label = lv_label_create(system_card);
|
system_status_label = lv_label_create(system_card);
|
||||||
lv_label_set_text(system_status_label, "");
|
lv_label_set_text(system_status_label, "");
|
||||||
|
|||||||
Reference in New Issue
Block a user