diff --git a/jni/util/vtx_manager.c b/jni/util/vtx_manager.c index 3223d89..87e58db 100644 --- a/jni/util/vtx_manager.c +++ b/jni/util/vtx_manager.c @@ -2,20 +2,19 @@ #include #include "json/osd_config.h" #include "util/debug.h" +//#include "../rec/rec_shim.h" #define VTX_MPS_CONFIG_KEY "vtx_msp" +#define CHANNEL_PUBLIC 8 static void *tp1801_gui_lib = NULL; static uint32_t (* setChannelPilotOriginal)(void *this,unsigned short param_1, bool param_2) = 0; static uint32_t (* userSettingsGetInstanceOriginal)() = 0; static uint32_t userSettingsInstance = 0; +static __gs_gui_config *gs_gui_config = 0; static int8_t currentChannel = -1; -void changeChannel(int8_t channel) { - if(!get_boolean_config_value(VTX_MPS_CONFIG_KEY)) { - return; - } - +void setupManager() { //Load SetPilotChannel original setChannelPilotOriginal = dlsym (RTLD_NEXT, "_ZN17GlassUserSettings15setPilotChannelEtb"); if (setChannelPilotOriginal == NULL) { @@ -38,6 +37,21 @@ void changeChannel(int8_t channel) { return; } + userSettingsInstance = userSettingsGetInstanceOriginal(); + if(userSettingsInstance == NULL) { + printf("dlsym: error loading user setting instance"); + return; + } + gs_gui_config = (__gs_gui_config *)*(uint32_t *)((int)userSettingsInstance + 0xe4); +} + +void changeChannel(int8_t channel) { + if(!get_boolean_config_value(VTX_MPS_CONFIG_KEY)) { + return; + } + + setupManager(); + if (channel <= 0 || channel > 8) { printf("VTX_MANAGER Error:, invalid channel index: %d\n", channel); return; @@ -48,9 +62,12 @@ void changeChannel(int8_t channel) { } currentChannel = channel; - // if 8, need to set to public DEBUG_PRINT("VTX_MANAGER: requesting to the goggles to set channel %d\n", channel); - - int8_t channelIdx = channel - 1; - setChannelPilotOriginal(userSettingsGetInstanceOriginal(), channelIdx, true); + + if(channel == CHANNEL_PUBLIC){ + gs_gui_config->gs_modem_set_public_chnl(gs_gui_config->gs_info); + } else { + int8_t channelIdx = channel - 1; + setChannelPilotOriginal(userSettingsGetInstanceOriginal(), channelIdx, true); + } } \ No newline at end of file