1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-18 22:05:17 +03:00

Disable CMS Tramp menu if other VTX device configured

Present a "disabled" menu with all 0 values that prevents changing settings if the VTX dvice is not configured as Tramp.
This commit is contained in:
Bruce Luckcuck 2019-10-30 19:40:33 -04:00
parent 8c75b557b1
commit 0904089c22

View file

@ -45,8 +45,16 @@ char trampCmsStatusString[31] = "- -- ---- ----";
// m bc ffff tppp // m bc ffff tppp
// 01234567890123 // 01234567890123
static bool trampDeviceConfigured = false;
void trampCmsUpdateStatusString(void) void trampCmsUpdateStatusString(void)
{ {
if (!trampDeviceConfigured) {
strncpy(trampCmsStatusString, "TRAMP NOT CONFIGURED", sizeof(trampCmsStatusString));
return;
}
vtxDevice_t *vtxDevice = vtxCommonDevice(); vtxDevice_t *vtxDevice = vtxCommonDevice();
if (vtxTableBandCount == 0 || vtxTablePowerLevels == 0) { if (vtxTableBandCount == 0 || vtxTablePowerLevels == 0) {
@ -95,9 +103,13 @@ static OSD_TAB_t trampCmsEntPower;
static void trampCmsUpdateFreqRef(void) static void trampCmsUpdateFreqRef(void)
{ {
if (trampDeviceConfigured) {
if (trampCmsBand > 0 && trampCmsChan > 0) { if (trampCmsBand > 0 && trampCmsChan > 0) {
trampCmsFreqRef = vtxCommonLookupFrequency(vtxCommonDevice(), trampCmsBand, trampCmsChan); trampCmsFreqRef = vtxCommonLookupFrequency(vtxCommonDevice(), trampCmsBand, trampCmsChan);
} }
} else {
trampCmsFreqRef = 0;
}
} }
static long trampCmsConfigBand(displayPort_t *pDisp, const void *self) static long trampCmsConfigBand(displayPort_t *pDisp, const void *self)
@ -105,11 +117,16 @@ static long trampCmsConfigBand(displayPort_t *pDisp, const void *self)
UNUSED(pDisp); UNUSED(pDisp);
UNUSED(self); UNUSED(self);
if (trampCmsBand == 0) if (trampDeviceConfigured) {
if (trampCmsBand == 0) {
// Bounce back // Bounce back
trampCmsBand = 1; trampCmsBand = 1;
else } else {
trampCmsUpdateFreqRef(); trampCmsUpdateFreqRef();
}
} else {
trampCmsBand = 0;
}
return 0; return 0;
} }
@ -119,11 +136,16 @@ static long trampCmsConfigChan(displayPort_t *pDisp, const void *self)
UNUSED(pDisp); UNUSED(pDisp);
UNUSED(self); UNUSED(self);
if (trampCmsChan == 0) if (trampDeviceConfigured) {
if (trampCmsChan == 0) {
// Bounce back // Bounce back
trampCmsChan = 1; trampCmsChan = 1;
else } else {
trampCmsUpdateFreqRef(); trampCmsUpdateFreqRef();
}
} else {
trampCmsChan = 0;
}
return 0; return 0;
} }
@ -133,9 +155,14 @@ static long trampCmsConfigPower(displayPort_t *pDisp, const void *self)
UNUSED(pDisp); UNUSED(pDisp);
UNUSED(self); UNUSED(self);
if (trampCmsPower == 0) if (trampDeviceConfigured) {
if (trampCmsPower == 0) {
// Bounce back // Bounce back
trampCmsPower = 1; trampCmsPower = 1;
}
} else {
trampCmsPower = 0;
}
return 0; return 0;
} }
@ -153,13 +180,16 @@ static long trampCmsSetPitMode(displayPort_t *pDisp, const void *self)
UNUSED(pDisp); UNUSED(pDisp);
UNUSED(self); UNUSED(self);
if (trampDeviceConfigured) {
if (trampCmsPitMode == 0) { if (trampCmsPitMode == 0) {
// Bouce back // Bouce back
trampCmsPitMode = 1; trampCmsPitMode = 1;
} else { } else {
trampSetPitMode(trampCmsPitMode - 1); trampSetPitMode(trampCmsPitMode - 1);
} }
} else {
trampCmsPitMode = 0;
}
return 0; return 0;
} }
@ -189,11 +219,16 @@ static long trampCmsCommence(displayPort_t *pDisp, const void *self)
static bool trampCmsInitSettings(void) static bool trampCmsInitSettings(void)
{ {
vtxDevice_t *device = vtxCommonDevice(); vtxDevice_t *device = vtxCommonDevice();
trampDeviceConfigured = false;
if (!device) { if (!device) {
return false; return false;
} }
vtxDevType_e vtxType = vtxCommonGetDeviceType(device);
trampDeviceConfigured = (vtxType == VTXDEV_TRAMP);
if (trampDeviceConfigured) {
vtxCommonGetBandAndChannel(device, &trampCmsBand, &trampCmsChan); vtxCommonGetBandAndChannel(device, &trampCmsBand, &trampCmsChan);
trampCmsUpdateFreqRef(); trampCmsUpdateFreqRef();
@ -204,17 +239,32 @@ static bool trampCmsInitSettings(void)
trampCmsPower = 1; trampCmsPower = 1;
} }
} }
trampCmsEntBand.val = &trampCmsBand;
trampCmsEntBand.max = vtxTableBandCount; trampCmsEntBand.max = vtxTableBandCount;
trampCmsEntChan.max = vtxTableChannelCount;
trampCmsEntPower.max = vtxTablePowerLevels;
} else {
trampCmsPitMode = 0;
trampCmsBand = 0;
trampCmsChan = 0;
trampCmsPower = 0;
trampCmsEntBand.max = 0;
trampCmsEntBand.names = 0;
trampCmsEntChan.max = 0;
trampCmsEntChan.names = 0;
trampCmsEntPower.max = 0;
trampCmsUpdateStatusString();
}
trampCmsEntBand.val = &trampCmsBand;
trampCmsEntBand.names = vtxTableBandNames; trampCmsEntBand.names = vtxTableBandNames;
trampCmsEntChan.val = &trampCmsChan; trampCmsEntChan.val = &trampCmsChan;
trampCmsEntChan.max = vtxTableChannelCount;
trampCmsEntChan.names = vtxTableChannelNames; trampCmsEntChan.names = vtxTableChannelNames;
trampCmsEntPower.val = &trampCmsPower; trampCmsEntPower.val = &trampCmsPower;
trampCmsEntPower.max = vtxTablePowerLevels;
trampCmsEntPower.names = vtxTablePowerLabels; trampCmsEntPower.names = vtxTablePowerLabels;
return true; return true;
@ -229,6 +279,14 @@ static long trampCmsOnEnter(void)
return 0; return 0;
} }
static long trampCmsCommenceOnEnter(void)
{
if (!trampDeviceConfigured) {
return MENU_CHAIN_BACK;
}
return 0;
}
static const OSD_Entry trampCmsMenuCommenceEntries[] = { static const OSD_Entry trampCmsMenuCommenceEntries[] = {
{ "CONFIRM", OME_Label, NULL, NULL, 0 }, { "CONFIRM", OME_Label, NULL, NULL, 0 },
{ "YES", OME_Funcall, trampCmsCommence, NULL, 0 }, { "YES", OME_Funcall, trampCmsCommence, NULL, 0 },
@ -241,7 +299,7 @@ static CMS_Menu trampCmsMenuCommence = {
.GUARD_text = "XVTXTRC", .GUARD_text = "XVTXTRC",
.GUARD_type = OME_MENU, .GUARD_type = OME_MENU,
#endif #endif
.onEnter = NULL, .onEnter = trampCmsCommenceOnEnter,
.onExit = NULL, .onExit = NULL,
.entries = trampCmsMenuCommenceEntries, .entries = trampCmsMenuCommenceEntries,
}; };