1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 05:15:25 +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,8 +103,12 @@ static OSD_TAB_t trampCmsEntPower;
static void trampCmsUpdateFreqRef(void) static void trampCmsUpdateFreqRef(void)
{ {
if (trampCmsBand > 0 && trampCmsChan > 0) { if (trampDeviceConfigured) {
trampCmsFreqRef = vtxCommonLookupFrequency(vtxCommonDevice(), trampCmsBand, trampCmsChan); if (trampCmsBand > 0 && trampCmsChan > 0) {
trampCmsFreqRef = vtxCommonLookupFrequency(vtxCommonDevice(), trampCmsBand, trampCmsChan);
}
} else {
trampCmsFreqRef = 0;
} }
} }
@ -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) {
// Bounce back if (trampCmsBand == 0) {
trampCmsBand = 1; // Bounce back
else trampCmsBand = 1;
trampCmsUpdateFreqRef(); } else {
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) {
// Bounce back if (trampCmsChan == 0) {
trampCmsChan = 1; // Bounce back
else trampCmsChan = 1;
trampCmsUpdateFreqRef(); } else {
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) {
// Bounce back if (trampCmsPower == 0) {
trampCmsPower = 1; // Bounce back
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 (trampCmsPitMode == 0) { if (trampDeviceConfigured) {
// Bouce back if (trampCmsPitMode == 0) {
trampCmsPitMode = 1; // Bouce back
trampCmsPitMode = 1;
} else {
trampSetPitMode(trampCmsPitMode - 1);
}
} else { } else {
trampSetPitMode(trampCmsPitMode - 1); trampCmsPitMode = 0;
} }
return 0; return 0;
} }
@ -189,32 +219,52 @@ 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;
} }
vtxCommonGetBandAndChannel(device, &trampCmsBand, &trampCmsChan); vtxDevType_e vtxType = vtxCommonGetDeviceType(device);
trampDeviceConfigured = (vtxType == VTXDEV_TRAMP);
trampCmsUpdateFreqRef(); if (trampDeviceConfigured) {
trampCmsPitMode = trampPitMode + 1; vtxCommonGetBandAndChannel(device, &trampCmsBand, &trampCmsChan);
if (trampConfiguredPower > 0) { trampCmsUpdateFreqRef();
if (!vtxCommonGetPowerIndex(vtxCommonDevice(), &trampCmsPower)) { trampCmsPitMode = trampPitMode + 1;
trampCmsPower = 1;
if (trampConfiguredPower > 0) {
if (!vtxCommonGetPowerIndex(vtxCommonDevice(), &trampCmsPower)) {
trampCmsPower = 1;
}
} }
} 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.val = &trampCmsBand;
trampCmsEntBand.max = vtxTableBandCount;
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,
}; };