Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
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
6 changes: 6 additions & 0 deletions pixelpilot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ os_sensors:
# cpu: auto
# power: auto
# temperature: auto

# Phone restream target IP (optional)
# If set, this IP is always added to the "Stream To" dropdown and pre-selected.
# Remove or comment out to use auto-discovery only.
# restream:
# manual_ip: 192.168.1.100
82 changes: 82 additions & 0 deletions src/gsmenu/gs_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include "ui.h"
#include "../input.h"
#include "../gstrtpreceiver.h"
#include "helper.h"
#include "styles.h"
#include "executor.h"
Expand All @@ -23,6 +24,30 @@ lv_obj_t * password;
lv_obj_t * wlan;
lv_obj_t * hotspot;
lv_obj_t * ipinfo;
lv_obj_t * restream;
lv_obj_t * ip_dropdown;

static uint16_t find_dropdown_option_index(const char * options, const char * value)
{
if (!value || value[0] == '\0') {
return 0;
}

uint16_t idx = 0;
const char * option = options;

while (option && *option) {
const char * nl = strchr(option, '\n');
size_t len = nl ? (size_t)(nl - option) : strlen(option);
if (strlen(value) == len && strncmp(option, value, len) == 0) {
return idx;
}
idx++;
option = nl ? nl + 1 : NULL;
}

return 0;
}

void wifi_page_load_callback(lv_obj_t * page)
{
Expand All @@ -31,6 +56,31 @@ void wifi_page_load_callback(lv_obj_t * page)
reload_textarea_value(page,ssid);
reload_textarea_value(page,password);
reload_label_value(page,ipinfo);

if (restream_get_enabled()) lv_obj_add_state(lv_obj_get_child_by_type(restream,0,&lv_switch_class), LV_STATE_CHECKED);
else lv_obj_clear_state(lv_obj_get_child_by_type(restream,0,&lv_switch_class), LV_STATE_CHECKED);
{
char clients[512];
restream_scan_clients(clients, sizeof(clients));
lv_dropdown_set_options(ip_dropdown, clients);
lv_dropdown_set_selected(ip_dropdown, find_dropdown_option_index(clients, restream_get_manual_ip()));
}
}

static void ip_dropdown_cb(lv_event_t * e) {
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
lv_obj_t * dd = lv_event_get_target(e);
char buf[64];
lv_dropdown_get_selected_str(dd, buf, sizeof(buf));
restream_set_manual_ip(buf);
}
}

static void restream_switch_callback(lv_event_t * e) {
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
lv_obj_t * target = lv_event_get_target(e);
restream_set_enabled(lv_obj_has_state(target, LV_STATE_CHECKED));
}
}

static void btn_event_cb(lv_event_t * e)
Expand Down Expand Up @@ -138,6 +188,38 @@ void create_wifi_menu(lv_obj_t * parent) {
lv_obj_add_event_cb(kb, kb_event_cb, LV_EVENT_ALL,kb);
lv_keyboard_set_textarea(kb, NULL);

create_text(parent, NULL, "Phone Restream", NULL, NULL, false, LV_MENU_ITEM_BUILDER_VARIANT_1);
section = lv_menu_section_create(parent);
lv_obj_add_style(section, &style_openipc_section, 0);

cont = lv_menu_cont_create(section);
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);

restream = create_switch(cont,LV_SYMBOL_VIDEO,"Phone Restream",NULL, NULL,false);
lv_obj_add_event_cb(lv_obj_get_child_by_type(restream,0,&lv_switch_class), restream_switch_callback, LV_EVENT_VALUE_CHANGED,NULL);

lv_obj_t * ip_dropdown_row = lv_menu_cont_create(cont);
lv_obj_t * dd_icon = lv_image_create(ip_dropdown_row);
lv_image_set_src(dd_icon, LV_SYMBOL_WIFI);
lv_obj_t * dd_label = lv_label_create(ip_dropdown_row);
lv_label_set_text(dd_label, "Stream To");
lv_obj_set_flex_grow(dd_label, 1);
ip_dropdown = lv_dropdown_create(ip_dropdown_row);
lv_dropdown_set_options(ip_dropdown, "Auto");
lv_dropdown_set_dir(ip_dropdown, LV_DIR_RIGHT);
lv_dropdown_set_symbol(ip_dropdown, LV_SYMBOL_RIGHT);
lv_obj_set_width(ip_dropdown, 200);
lv_obj_add_style(ip_dropdown, &style_openipc_outline, LV_PART_MAIN | LV_STATE_FOCUS_KEY);
lv_obj_add_style(ip_dropdown, &style_openipc_dark_background, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_t * dd_list = lv_dropdown_get_list(ip_dropdown);
lv_obj_add_style(dd_list, &style_openipc, LV_PART_SELECTED | LV_STATE_CHECKED);
lv_obj_add_style(dd_list, &style_openipc_dark_background, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_add_event_cb(ip_dropdown, dropdown_event_handler, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ip_dropdown, ip_dropdown_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_add_event_cb(ip_dropdown, generic_back_event_handler, LV_EVENT_KEY, NULL);
lv_obj_add_event_cb(ip_dropdown, on_focus, LV_EVENT_FOCUSED, NULL);
lv_group_add_obj(menu_page_data->indev_group, ip_dropdown);

create_text(parent, NULL, "Network", NULL, NULL, false, LV_MENU_ITEM_BUILDER_VARIANT_1);
section = lv_menu_section_create(parent);
lv_obj_add_style(section, &style_openipc_section, 0);
Expand Down
Loading
Loading