Skip to content

Commit 828a501

Browse files
authored
UI additions (#107)
* display connector menu option * allow custom actions in pixelpilot.yaml * add missing function * hide instead of disable
1 parent 336678b commit 828a501

File tree

11 files changed

+124
-2
lines changed

11 files changed

+124
-2
lines changed

gsmenu.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,9 @@ case "$@" in
726726
"values gs system rx_mode")
727727
echo -n -e "wfb\napfpv"
728728
;;
729+
"values gs system connector")
730+
echo -n -e "HDMI"
731+
;;
729732
"values gs system resolution")
730733
drm_info -j /dev/dri/card0 2>/dev/null | jq -r '."/dev/dri/card0".connectors[1].modes[] | select(.name | contains("i") | not) | .name + "@" + (.vrefresh|tostring)' | sort | uniq | sed -z '$ s/\n$//'
731734
;;
@@ -739,6 +742,9 @@ case "$@" in
739742
"get gs system gs_rendering")
740743
[ "$(grep ^render /config/setup.txt | cut -d ' ' -f 3)" = "ground" ] && echo 1 || echo 0
741744
;;
745+
"get gs system connector")
746+
echo HDMI
747+
;;
742748
"get gs system resolution")
743749
drm_info -j /dev/dri/card0 2>/dev/null | jq -r '."/dev/dri/card0".crtcs[0].mode| .name + "@" + (.vrefresh|tostring)'
744750
;;
@@ -816,6 +822,9 @@ case "$@" in
816822
msposd_rockchip --osd --ahi 0 --matrix 11 -v -r 5 --master 0.0.0.0:14551 &
817823
fi
818824
;;
825+
"set gs system connector"*)
826+
: # noop
827+
;;
819828
"set gs system resolution"*)
820829
sed -i "s/^screen_mode =.*/screen_mode = $5/" /config/setup.txt
821830
;;

pixelpilot.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ gsmenu:
3030
# right: 32
3131
# up: 16
3232
# down: 18
33-
33+
# Define custom actions here
34+
# action is the command the button will trigger
35+
# actions:
36+
# air:
37+
# - label: Custom Action 1
38+
# action: sleep 5
39+
# - label: Custom Action 1
40+
# action: sleep 5
41+
# ground:
42+
# - label: Custom Action 1
43+
# action: sleep 5
3444
# enables collection of `os_mon.*` OSD facts
3545
os_sensors:
3646
cpu: true # Monitor CPU load percentage

src/gsmenu/air_actions.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
#include "helper.h"
77
#include "executor.h"
88
#include "styles.h"
9+
#include "helper.h"
10+
#include "air_actions.h"
911

1012
extern lv_group_t * default_group;
1113
lv_obj_t * air_reboot;
14+
lv_obj_t * air_custom_action;
1215

1316
void create_air_actions_menu(lv_obj_t * parent) {
1417

@@ -27,5 +30,10 @@ void create_air_actions_menu(lv_obj_t * parent) {
2730
air_reboot = create_button(section, "Reboot");
2831
lv_obj_add_event_cb(lv_obj_get_child_by_type(air_reboot,0,&lv_button_class),generic_button_callback,LV_EVENT_CLICKED,menu_page_data);
2932

33+
for (size_t i = 0; i < airactions_count; i++) {
34+
air_custom_action = create_button(section, airactions[i].label);
35+
lv_obj_add_event_cb(lv_obj_get_child_by_type(air_custom_action,0,&lv_button_class),custom_actions_cb,LV_EVENT_CLICKED,&airactions[i]);
36+
}
37+
3038
lv_group_set_default(default_group);
3139
}

src/gsmenu/air_actions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#pragma once
2+
#include <stddef.h>
3+
#include "../menu.h"
4+
extern MenuAction airactions[MAX_ACTIONS];
5+
extern size_t airactions_count;
26

37
void create_air_actions_menu(lv_obj_t * parent);

src/gsmenu/gs_actions.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "helper.h"
88
#include "executor.h"
99
#include "styles.h"
10+
#include <stddef.h>
11+
#include "../menu.h"
12+
#include "gs_actions.h"
1013

1114
#ifdef USE_SIMULATOR
1215
void sig_handler(int exit_code)
@@ -20,6 +23,7 @@ extern lv_group_t * default_group;
2023
lv_obj_t * restart_pp;
2124
lv_obj_t * exit_pp;
2225
lv_obj_t * gs_reboot;
26+
lv_obj_t * gs_custom_action;
2327
int restart_value = 1;
2428
int exit_value = 2;
2529

@@ -51,5 +55,11 @@ void create_gs_actions_menu(lv_obj_t * parent) {
5155
gs_reboot = create_button(section, "Reboot");
5256
lv_obj_add_event_cb(lv_obj_get_child_by_type(gs_reboot,0,&lv_button_class),generic_button_callback,LV_EVENT_CLICKED,menu_page_data);
5357

58+
59+
for (size_t i = 0; i < gsactions_count; i++) {
60+
gs_custom_action = create_button(section, gsactions[i].label);
61+
lv_obj_add_event_cb(lv_obj_get_child_by_type(gs_custom_action,0,&lv_button_class),custom_actions_cb,LV_EVENT_CLICKED,&gsactions[i]);
62+
}
63+
5464
lv_group_set_default(default_group);
5565
}

src/gsmenu/gs_actions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#pragma once
2+
#include <stddef.h>
3+
#include "../menu.h"
4+
5+
extern MenuAction gsactions[MAX_ACTIONS];
6+
extern size_t gsactions_count;
27

38
void create_gs_actions_menu(lv_obj_t * parent);

src/gsmenu/gs_system.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum RXMode RXMODE = WFB;
1313

1414
lv_obj_t * rx_mode;
1515
lv_obj_t * gs_rendering;
16+
lv_obj_t * connector;
1617
lv_obj_t * resolution;
1718
lv_obj_t * rec_enabled;
1819
lv_obj_t * rec_fps;
@@ -36,6 +37,7 @@ void gs_system_page_load_callback(lv_obj_t * page)
3637
reload_switch_value(page,gs_rendering);
3738
reload_dropdown_value(page,rx_mode);
3839
RXMODE = lv_dropdown_get_selected(lv_obj_get_child_by_type(rx_mode,0,&lv_dropdown_class));
40+
reload_dropdown_value(page,connector);
3941
reload_dropdown_value(page,resolution);
4042
reload_dropdown_value(page,rec_fps);
4143
reload_slider_value(page, video_scale);
@@ -138,6 +140,7 @@ void create_gs_system_menu(lv_obj_t * parent) {
138140
RXMODE = lv_dropdown_get_selected(lv_obj_get_child_by_type(rx_mode,0,&lv_dropdown_class));
139141

140142
gs_rendering = create_switch(cont,LV_SYMBOL_SETTINGS,"GS Rendering","gs_rendering", menu_page_data,false);
143+
connector = create_dropdown(cont,LV_SYMBOL_SETTINGS, "Connector","","connector",menu_page_data,false);
141144
resolution = create_dropdown(cont,LV_SYMBOL_SETTINGS, "Resolution","","resolution",menu_page_data,false);
142145
video_scale = create_slider(cont, LV_SYMBOL_SETTINGS, "Video scale factor", "video_scale", menu_page_data, false, 2);
143146

src/gsmenu/helper.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ui.h"
1010
#include "executor.h"
1111
#include "../WiFiRSSIMonitor.h"
12+
#include "../menu.h"
1213

1314
extern enum RXMode RXMODE;
1415

@@ -862,6 +863,8 @@ void get_dropdown_value(lv_obj_t * parent) {
862863
thread_data_t * param_user_data = (thread_data_t*) lv_obj_get_user_data(obj);
863864
lv_dropdown_set_options(obj,get_values(param_user_data));
864865
update_dropdown_width(obj);
866+
if (lv_dropdown_get_option_cnt(obj) == 1)
867+
lv_obj_add_flag(lv_obj_get_parent(obj), LV_OBJ_FLAG_HIDDEN);
865868
}
866869

867870
bool file_exists(const char *path) {
@@ -1007,4 +1010,10 @@ void delete_menu_page_entry_by_obj(menu_page_data_t *menu_page_data, lv_obj_t* o
10071010
free(menu_page_data->page_entries);
10081011
menu_page_data->page_entries = NULL;
10091012
}
1013+
}
1014+
1015+
void custom_actions_cb(lv_event_t * event)
1016+
{
1017+
MenuAction *action = lv_event_get_user_data(event);
1018+
run_command_and_block(event, action->action, NULL);
10101019
}

src/gsmenu/helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ void gsmenu_toggle_rxmode();
5656

5757
void add_entry_to_menu_page(menu_page_data_t *menu_page_data, const char* text, lv_obj_t* obj, ReloadFunc reload_func);
5858
void delete_menu_page_entry_by_obj(menu_page_data_t *menu_page_data, lv_obj_t* obj);
59+
void custom_actions_cb(lv_event_t * event);

src/main.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ extern "C" {
5757
#include <iostream>
5858
#include "WiFiRSSIMonitor.hpp"
5959
#include "gsmenu/gs_system.h"
60+
#include "gsmenu/air_actions.h"
61+
#include "gsmenu/gs_actions.h"
62+
#include "menu.h"
63+
6064

6165
#define READ_BUF_SIZE (1024*1024) // SZ_1M https://github.com/rockchip-linux/mpp/blob/ed377c99a733e2cdbcc457a6aa3f0fcd438a9dff/osal/inc/mpp_common.h#L179
6266
#define MAX_FRAMES 24 // min 16 and 20+ recommended (mpp/readme.txt)
@@ -104,7 +108,10 @@ const char* unix_socket = NULL;
104108
char* dvr_template = NULL;
105109
Dvr *dvr = NULL;
106110
OsSensors os_sensors; // TODO: pass as argument to `main_loop`
107-
111+
MenuAction airactions[MAX_ACTIONS];
112+
size_t airactions_count;
113+
MenuAction gsactions[MAX_ACTIONS];
114+
size_t gsactions_count;
108115

109116
// Add global variables for plane id overrides
110117
uint32_t video_plane_id_override = 0;
@@ -924,6 +931,52 @@ int main(int argc, char **argv)
924931
if (config["gsmenu"]["enabled"]) {
925932
gsmenu_enabled = config["gsmenu"]["enabled"].as<bool>();
926933
}
934+
if (gsmenu_enabled && config["gsmenu"]["actions"]) {
935+
if (config["gsmenu"]["actions"]["air"]) {
936+
const YAML::Node& actionsNode = config["gsmenu"]["actions"]["air"];
937+
airactions_count = 0;
938+
939+
for (YAML::const_iterator it = actionsNode.begin();
940+
it != actionsNode.end() && airactions_count < MAX_ACTIONS;
941+
++it) {
942+
943+
std::string label = (*it)["label"].as<std::string>();
944+
std::string cmd = (*it)["action"].as<std::string>();
945+
946+
// Access the global array at the current index
947+
strncpy(airactions[airactions_count].label, label.c_str(), MAX_LABEL_LEN - 1);
948+
airactions[airactions_count].label[MAX_LABEL_LEN - 1] = '\0';
949+
950+
strncpy(airactions[airactions_count].action, cmd.c_str(), MAX_ACTION_LEN - 1);
951+
airactions[airactions_count].action[MAX_ACTION_LEN - 1] = '\0';
952+
953+
airactions_count++;
954+
}
955+
spdlog::debug("Parsed {} GS Actions", airactions_count);
956+
}
957+
if (config["gsmenu"]["actions"]["ground"]) {
958+
const YAML::Node& actionsNode = config["gsmenu"]["actions"]["ground"];
959+
gsactions_count = 0;
960+
961+
for (YAML::const_iterator it = actionsNode.begin();
962+
it != actionsNode.end() && gsactions_count < MAX_ACTIONS;
963+
++it) {
964+
965+
std::string label = (*it)["label"].as<std::string>();
966+
std::string cmd = (*it)["action"].as<std::string>();
967+
968+
// Access the global array at the current index
969+
strncpy(gsactions[gsactions_count].label, label.c_str(), MAX_LABEL_LEN - 1);
970+
gsactions[gsactions_count].label[MAX_LABEL_LEN - 1] = '\0';
971+
972+
strncpy(gsactions[gsactions_count].action, cmd.c_str(), MAX_ACTION_LEN - 1);
973+
gsactions[gsactions_count].action[MAX_ACTION_LEN - 1] = '\0';
974+
975+
gsactions_count++;
976+
}
977+
spdlog::debug("Parsed {} GS Actions", gsactions_count);
978+
}
979+
}
927980
}
928981

929982
if (config["os_sensors"] && config["os_sensors"].IsMap()) {

0 commit comments

Comments
 (0)