Merge pull request #11299 from daleckystepan/vtx-start-bit
[betaflight.git] / src / main / cms / cms_menu_vtx_common.c
blob527c5aa8eaf9a436419527d0521dd4c4a75e677d
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <ctype.h>
25 #include "platform.h"
27 #if defined(USE_CMS) && defined(USE_VTX_CONTROL) && (defined(USE_VTX_TRAMP) || defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_RTC6705))
29 #include "common/printf.h"
31 #include "cms/cms.h"
32 #include "cms/cms_menu_vtx_rtc6705.h"
33 #include "cms/cms_menu_vtx_smartaudio.h"
34 #include "cms/cms_menu_vtx_tramp.h"
35 #include "cms/cms_types.h"
37 #include "drivers/vtx_common.h"
39 #include "cms_menu_vtx_common.h"
41 #define MAX_STATUS_LINE_LENGTH 21
43 static char statusLine1[MAX_STATUS_LINE_LENGTH] = "";
44 static char statusLine2[MAX_STATUS_LINE_LENGTH] = "";
46 static const void *setStatusMessage(displayPort_t *pDisp)
48 UNUSED(pDisp);
50 vtxDevice_t *device = vtxCommonDevice();
52 statusLine1[0] = 0;
53 statusLine2[0] = 0;
55 if (!device) {
56 tfp_sprintf(&statusLine1[0], "VTX NOT RESPONDING");
57 tfp_sprintf(&statusLine2[0], "OR NOT CONFIGURED");
58 } else {
59 vtxDevType_e vtxType = vtxCommonGetDeviceType(device);
60 if (vtxType == VTXDEV_UNSUPPORTED) {
61 tfp_sprintf(&statusLine1[0], "UNSUPPORTED VTX TYPE");
62 } else {
63 tfp_sprintf(&statusLine1[0], "UNKNOWN VTX TYPE");
66 return NULL;
69 static const OSD_Entry vtxErrorMenuEntries[] =
71 { "", OME_Label | DYNAMIC, NULL, statusLine1 },
72 { "", OME_Label | DYNAMIC, NULL, statusLine2 },
73 { "", OME_Label, NULL, NULL },
74 { "BACK", OME_Back, NULL, NULL },
75 { NULL, OME_END, NULL, NULL }
78 static CMS_Menu cmsx_menuVtxError = {
79 #ifdef CMS_MENU_DEBUG
80 .GUARD_text = "XVTXERROR",
81 .GUARD_type = OME_MENU,
82 #endif
83 .onEnter = setStatusMessage,
84 .onExit = NULL,
85 .onDisplayUpdate = NULL,
86 .entries = vtxErrorMenuEntries,
89 // Redirect to the proper menu based on the vtx device type
90 // If device isn't valid or not a supported type then don't
91 // redirect and instead display a local informational menu.
92 const void *cmsSelectVtx(displayPort_t *pDisplay, const void *ptr)
94 UNUSED(ptr);
96 vtxDevice_t *device = vtxCommonDevice();
98 if (device) {
99 vtxDevType_e vtxType = vtxCommonGetDeviceType(device);
101 switch (vtxType) {
103 #if defined(USE_VTX_RTC6705)
104 case VTXDEV_RTC6705:
105 cmsMenuChange(pDisplay, &cmsx_menuVtxRTC6705);
107 break;
108 #endif
109 #if defined(USE_VTX_SMARTAUDIO)
110 case VTXDEV_SMARTAUDIO:
111 cmsMenuChange(pDisplay, &cmsx_menuVtxSmartAudio);
113 break;
114 #endif
115 #if defined(USE_VTX_TRAMP)
116 case VTXDEV_TRAMP:
117 cmsMenuChange(pDisplay, &cmsx_menuVtxTramp);
119 break;
120 #endif
122 default:
123 cmsMenuChange(pDisplay, &cmsx_menuVtxError);
125 break;
127 } else {
128 cmsMenuChange(pDisplay, &cmsx_menuVtxError);
131 return NULL;
133 #endif