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)
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/>.
25 #include <drivers/vtx_table.h>
29 #if defined(USE_CMS) && defined(USE_VTX_TRAMP)
31 #include "common/printf.h"
32 #include "common/utils.h"
35 #include "cms/cms_types.h"
37 #include "drivers/vtx_common.h"
39 #include "config/config.h"
41 #include "io/vtx_tramp.h"
44 char trampCmsStatusString
[31] = "- -- ---- ----";
48 static int16_t trampCmsTemp
;
49 static OSD_INT16_t trampCmsEntTemp
= { &trampCmsTemp
, -100, 300, 0 };
51 void trampCmsUpdateStatusString(void)
53 vtxDevice_t
*vtxDevice
= vtxCommonDevice();
55 if (vtxTableBandCount
== 0 || vtxTablePowerLevels
== 0) {
56 strncpy(trampCmsStatusString
, "PLEASE CONFIGURE VTXTABLE", sizeof(trampCmsStatusString
));
60 trampCmsStatusString
[0] = '*';
61 trampCmsStatusString
[1] = ' ';
64 if (!vtxCommonGetBandAndChannel(vtxDevice
, &band
, &chan
) || (band
== 0 && chan
== 0)) {
65 trampCmsStatusString
[2] = 'U';//user freq
66 trampCmsStatusString
[3] = 'F';
68 trampCmsStatusString
[2] = vtxCommonLookupBandLetter(vtxDevice
, band
);
69 trampCmsStatusString
[3] = vtxCommonLookupChannelName(vtxDevice
, chan
)[0];
71 trampCmsStatusString
[4] = ' ';
74 if (!vtxCommonGetFrequency(vtxDevice
, &freq
) || (freq
== 0)) {
75 tfp_sprintf(&trampCmsStatusString
[5], "----");
77 tfp_sprintf(&trampCmsStatusString
[5], "%4d", freq
);
80 uint16_t actualPower
= vtxTrampGetCurrentActualPower();
83 if (actualPower
> 0 && vtxCommonGetPowerIndex(vtxDevice
, &powerIndex
) && vtxCommonLookupPowerValue(vtxDevice
, powerIndex
, &powerValue
)) {
84 tfp_sprintf(&trampCmsStatusString
[9], " %c%3d", (actualPower
== powerValue
) ? ' ' : '*', actualPower
);
86 tfp_sprintf(&trampCmsStatusString
[9], " ----");
89 trampCmsTemp
= vtxTrampGetCurrentTemp();
92 uint8_t trampCmsPitMode
= 0;
93 uint8_t trampCmsBand
= 1;
94 uint8_t trampCmsChan
= 1;
95 uint16_t trampCmsFreqRef
;
97 static OSD_TAB_t trampCmsEntBand
;
98 static OSD_TAB_t trampCmsEntChan
;
100 static OSD_UINT16_t trampCmsEntFreqRef
= { &trampCmsFreqRef
, 5600, 5900, 0 };
102 static uint8_t trampCmsPower
= 1;
104 static OSD_TAB_t trampCmsEntPower
;
106 static void trampCmsUpdateFreqRef(void)
108 if (trampCmsBand
> 0 && trampCmsChan
> 0) {
109 trampCmsFreqRef
= vtxCommonLookupFrequency(vtxCommonDevice(), trampCmsBand
, trampCmsChan
);
113 static const void *trampCmsConfigBand(displayPort_t
*pDisp
, const void *self
)
118 if (trampCmsBand
== 0) {
122 trampCmsUpdateFreqRef();
128 static const void *trampCmsConfigChan(displayPort_t
*pDisp
, const void *self
)
133 if (trampCmsChan
== 0) {
137 trampCmsUpdateFreqRef();
143 static const void *trampCmsConfigPower(displayPort_t
*pDisp
, const void *self
)
148 if (trampCmsPower
== 0) {
156 #define TRAMP_PIT_STATUS_NA (0)
157 #define TRAMP_PIT_STATUS_OFF (1)
158 #define TRAMP_PIT_STATUS_ON (2)
160 static const char * const trampCmsPitModeNames
[] = {
164 static OSD_TAB_t trampCmsEntPitMode
= { &trampCmsPitMode
, 2, trampCmsPitModeNames
};
166 static const void *trampCmsSetPitMode(displayPort_t
*pDisp
, const void *self
)
171 if (trampCmsPitMode
== TRAMP_PIT_STATUS_NA
) {
173 trampCmsPitMode
= TRAMP_PIT_STATUS_OFF
;
175 vtxCommonSetPitMode(vtxCommonDevice(),
176 (trampCmsPitMode
== TRAMP_PIT_STATUS_OFF
) ? 0 : 1);
182 static const void *trampCmsCommence(displayPort_t
*pDisp
, const void *self
)
187 vtxDevice_t
*device
= vtxCommonDevice();
188 vtxCommonSetBandAndChannel(device
, trampCmsBand
, trampCmsChan
);
189 vtxCommonSetPowerByIndex(device
, trampCmsPower
);
191 // update'vtx_' settings
192 vtxSettingsConfigMutable()->band
= trampCmsBand
;
193 vtxSettingsConfigMutable()->channel
= trampCmsChan
;
194 vtxSettingsConfigMutable()->power
= trampCmsPower
;
195 vtxSettingsConfigMutable()->freq
= vtxCommonLookupFrequency(vtxCommonDevice(), trampCmsBand
, trampCmsChan
);
197 saveConfigAndNotify();
198 cmsMenuExit(pDisp
, self
);
200 return MENU_CHAIN_BACK
;
203 static bool trampCmsInitSettings(void)
205 vtxDevice_t
*device
= vtxCommonDevice();
212 vtxCommonGetBandAndChannel(device
, &trampCmsBand
, &trampCmsChan
);
214 trampCmsUpdateFreqRef();
215 if (vtxCommonGetStatus(device
, &vtxStatus
)) {
216 trampCmsPitMode
= (vtxStatus
& VTX_STATUS_PIT_MODE
) ? TRAMP_PIT_STATUS_ON
: TRAMP_PIT_STATUS_OFF
;
218 trampCmsPitMode
= TRAMP_PIT_STATUS_NA
;
221 if (!vtxCommonGetPowerIndex(vtxCommonDevice(), &trampCmsPower
)) {
225 trampCmsEntBand
.val
= &trampCmsBand
;
226 trampCmsEntBand
.max
= vtxTableBandCount
;
227 trampCmsEntBand
.names
= vtxTableBandNames
;
229 trampCmsEntChan
.val
= &trampCmsChan
;
230 trampCmsEntChan
.max
= vtxTableChannelCount
;
231 trampCmsEntChan
.names
= vtxTableChannelNames
;
233 trampCmsEntPower
.val
= &trampCmsPower
;
234 trampCmsEntPower
.max
= vtxTablePowerLevels
;
235 trampCmsEntPower
.names
= vtxTablePowerLabels
;
240 static const void *trampCmsOnEnter(displayPort_t
*pDisp
)
244 if (!trampCmsInitSettings()) {
245 return MENU_CHAIN_BACK
;
251 static const OSD_Entry trampCmsMenuCommenceEntries
[] = {
252 { "CONFIRM", OME_Label
, NULL
, NULL
},
253 { "YES", OME_OSD_Exit
, trampCmsCommence
, (void *)CMS_EXIT
},
254 { "NO", OME_Back
, NULL
, NULL
},
255 { NULL
, OME_END
, NULL
, NULL
}
258 static CMS_Menu trampCmsMenuCommence
= {
259 #ifdef CMS_MENU_DEBUG
260 .GUARD_text
= "XVTXTRC",
261 .GUARD_type
= OME_MENU
,
265 .onDisplayUpdate
= NULL
,
266 .entries
= trampCmsMenuCommenceEntries
,
269 static const OSD_Entry trampMenuEntries
[] =
271 { "- TRAMP -", OME_Label
, NULL
, NULL
},
273 { "", OME_Label
| DYNAMIC
, NULL
, trampCmsStatusString
},
274 { "PIT", OME_TAB
, trampCmsSetPitMode
, &trampCmsEntPitMode
},
275 { "BAND", OME_TAB
, trampCmsConfigBand
, &trampCmsEntBand
},
276 { "CHAN", OME_TAB
, trampCmsConfigChan
, &trampCmsEntChan
},
277 { "(FREQ)", OME_UINT16
| DYNAMIC
, NULL
, &trampCmsEntFreqRef
},
278 { "POWER", OME_TAB
, trampCmsConfigPower
, &trampCmsEntPower
},
279 { "T(C)", OME_INT16
| DYNAMIC
, NULL
, &trampCmsEntTemp
},
280 { "SAVE&EXIT", OME_Submenu
, cmsMenuChange
, &trampCmsMenuCommence
},
282 { "BACK", OME_Back
, NULL
, NULL
},
283 { NULL
, OME_END
, NULL
, NULL
}
286 CMS_Menu cmsx_menuVtxTramp
= {
287 #ifdef CMS_MENU_DEBUG
288 .GUARD_text
= "XVTXTR",
289 .GUARD_type
= OME_MENU
,
291 .onEnter
= trampCmsOnEnter
,
293 .onDisplayUpdate
= NULL
,
294 .entries
= trampMenuEntries
,