diff --git a/make/source.mk b/make/source.mk index 260d80ad6..7431e42eb 100644 --- a/make/source.mk +++ b/make/source.mk @@ -133,6 +133,7 @@ FC_SRC = \ cms/cms_menu_osd.c \ cms/cms_menu_vtx_rtc6705.c \ cms/cms_menu_vtx_smartaudio.c \ + cms/cms_menu_vtx_tramp.c \ common/colorconversion.c \ common/gps_conversion.c \ drivers/display_ug2864hsweg01.c \ diff --git a/src/main/cms/cms_menu_builtin.c b/src/main/cms/cms_menu_builtin.c index 97e917cbc..ba763da30 100644 --- a/src/main/cms/cms_menu_builtin.c +++ b/src/main/cms/cms_menu_builtin.c @@ -44,11 +44,12 @@ #include "cms/cms_menu_ledstrip.h" #include "cms/cms_menu_misc.h" -// User supplied menus +// VTX supplied menus #include "io/vtx_rtc6705_cms.h" -#include "io/vtx_tramp.h" #include "cms/cms_menu_vtx_smartaudio.h" +#include "cms/cms_menu_vtx_tramp.h" + // Info diff --git a/src/main/cms/cms_menu_vtx_tramp.c b/src/main/cms/cms_menu_vtx_tramp.c new file mode 100644 index 000000000..79b7fa1b6 --- /dev/null +++ b/src/main/cms/cms_menu_vtx_tramp.c @@ -0,0 +1,223 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#include +#include +#include + +#include "platform.h" + +#ifdef CMS +#include "common/printf.h" +#include "common/utils.h" + +#include "cms/cms.h" +#include "cms/cms_types.h" + +#include "io/vtx_string.h" +#include "io/vtx_tramp.h" + + +char trampCmsStatusString[31] = "- -- ---- ----"; +// m bc ffff tppp +// 01234567890123 + +void trampCmsUpdateStatusString(void) +{ + trampCmsStatusString[0] = '*'; + trampCmsStatusString[1] = ' '; + trampCmsStatusString[2] = vtx58BandLetter[trampBand]; + trampCmsStatusString[3] = vtx58ChannelNames[trampChannel][0]; + trampCmsStatusString[4] = ' '; + + if (trampCurFreq) + tfp_sprintf(&trampCmsStatusString[5], "%4d", trampCurFreq); + else + tfp_sprintf(&trampCmsStatusString[5], "----"); + + if (trampPower) { + tfp_sprintf(&trampCmsStatusString[9], " %c%3d", (trampPower == trampConfiguredPower) ? ' ' : '*', trampPower); + } + else + tfp_sprintf(&trampCmsStatusString[9], " ----"); +} + +uint8_t trampCmsPitMode = 0; +uint8_t trampCmsBand = 1; +uint8_t trampCmsChan = 1; +uint16_t trampCmsFreqRef; + +static OSD_TAB_t trampCmsEntBand = { &trampCmsBand, 5, vtx58BandNames }; + +static OSD_TAB_t trampCmsEntChan = { &trampCmsChan, 8, vtx58ChannelNames }; + +static OSD_UINT16_t trampCmsEntFreqRef = { &trampCmsFreqRef, 5600, 5900, 0 }; + +static uint8_t trampCmsPower = 1; + +static OSD_TAB_t trampCmsEntPower = { &trampCmsPower, 5, trampPowerNames }; + +static void trampCmsUpdateFreqRef(void) +{ + if (trampCmsBand > 0 && trampCmsChan > 0) + trampCmsFreqRef = vtx58frequencyTable[trampCmsBand - 1][trampCmsChan - 1]; +} + +static long trampCmsConfigBand(displayPort_t *pDisp, const void *self) +{ + UNUSED(pDisp); + UNUSED(self); + + if (trampCmsBand == 0) + // Bounce back + trampCmsBand = 1; + else + trampCmsUpdateFreqRef(); + + return 0; +} + +static long trampCmsConfigChan(displayPort_t *pDisp, const void *self) +{ + UNUSED(pDisp); + UNUSED(self); + + if (trampCmsChan == 0) + // Bounce back + trampCmsChan = 1; + else + trampCmsUpdateFreqRef(); + + return 0; +} + +static long trampCmsConfigPower(displayPort_t *pDisp, const void *self) +{ + UNUSED(pDisp); + UNUSED(self); + + if (trampCmsPower == 0) + // Bounce back + trampCmsPower = 1; + + return 0; +} + +static OSD_INT16_t trampCmsEntTemp = { &trampTemperature, -100, 300, 0 }; + +static const char * const trampCmsPitModeNames[] = { + "---", "OFF", "ON " +}; + +static OSD_TAB_t trampCmsEntPitMode = { &trampCmsPitMode, 2, trampCmsPitModeNames }; + +static long trampCmsSetPitMode(displayPort_t *pDisp, const void *self) +{ + UNUSED(pDisp); + UNUSED(self); + + if (trampCmsPitMode == 0) { + // Bouce back + trampCmsPitMode = 1; + } else { + trampSetPitMode(trampCmsPitMode - 1); + } + + return 0; +} + +static long trampCmsCommence(displayPort_t *pDisp, const void *self) +{ + UNUSED(pDisp); + UNUSED(self); + + trampSetBandAndChannel(trampCmsBand, trampCmsChan); + trampSetRFPower(trampPowerTable[trampCmsPower-1]); + + // If it fails, the user should retry later + trampCommitChanges(); + + + return MENU_CHAIN_BACK; +} + +static void trampCmsInitSettings() +{ + if (trampBand > 0) trampCmsBand = trampBand; + if (trampChannel > 0) trampCmsChan = trampChannel; + + trampCmsUpdateFreqRef(); + trampCmsPitMode = trampPitMode + 1; + + if (trampConfiguredPower > 0) { + for (uint8_t i = 0; i < sizeof(trampPowerTable); i++) { + if (trampConfiguredPower <= trampPowerTable[i]) { + trampCmsPower = i + 1; + break; + } + } + } +} + +static long trampCmsOnEnter() +{ + trampCmsInitSettings(); + return 0; +} + +static OSD_Entry trampCmsMenuCommenceEntries[] = { + { "CONFIRM", OME_Label, NULL, NULL, 0 }, + { "YES", OME_Funcall, trampCmsCommence, NULL, 0 }, + { "BACK", OME_Back, NULL, NULL, 0 }, + { NULL, OME_END, NULL, NULL, 0 } +}; + +static CMS_Menu trampCmsMenuCommence = { + .GUARD_text = "XVTXTRC", + .GUARD_type = OME_MENU, + .onEnter = NULL, + .onExit = NULL, + .onGlobalExit = NULL, + .entries = trampCmsMenuCommenceEntries, +}; + +static OSD_Entry trampMenuEntries[] = +{ + { "- TRAMP -", OME_Label, NULL, NULL, 0 }, + + { "", OME_Label, NULL, trampCmsStatusString, DYNAMIC }, + { "PIT", OME_TAB, trampCmsSetPitMode, &trampCmsEntPitMode, 0 }, + { "BAND", OME_TAB, trampCmsConfigBand, &trampCmsEntBand, 0 }, + { "CHAN", OME_TAB, trampCmsConfigChan, &trampCmsEntChan, 0 }, + { "(FREQ)", OME_UINT16, NULL, &trampCmsEntFreqRef, DYNAMIC }, + { "POWER", OME_TAB, trampCmsConfigPower, &trampCmsEntPower, 0 }, + { "T(C)", OME_INT16, NULL, &trampCmsEntTemp, DYNAMIC }, + { "SET", OME_Submenu, cmsMenuChange, &trampCmsMenuCommence, 0 }, + + { "BACK", OME_Back, NULL, NULL, 0 }, + { NULL, OME_END, NULL, NULL, 0 } +}; + +CMS_Menu cmsx_menuVtxTramp = { + .GUARD_text = "XVTXTR", + .GUARD_type = OME_MENU, + .onEnter = trampCmsOnEnter, + .onExit = NULL, + .onGlobalExit = NULL, + .entries = trampMenuEntries, +}; +#endif diff --git a/src/main/cms/cms_menu_vtx_tramp.h b/src/main/cms/cms_menu_vtx_tramp.h new file mode 100644 index 000000000..a5e0db6c1 --- /dev/null +++ b/src/main/cms/cms_menu_vtx_tramp.h @@ -0,0 +1,24 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#pragma once + +#include "cms/cms.h" +#include "cms/cms_types.h" +extern CMS_Menu cmsx_menuVtxTramp; + +void trampCmsUpdateStatusString(void); diff --git a/src/main/io/vtx_tramp.c b/src/main/io/vtx_tramp.c index c00375cf8..281eb003d 100644 --- a/src/main/io/vtx_tramp.c +++ b/src/main/io/vtx_tramp.c @@ -29,22 +29,23 @@ #include "build/debug.h" #include "common/utils.h" -#include "common/printf.h" + +#include "cms/cms_menu_vtx_tramp.h" + +#include "drivers/vtx_common.h" #include "io/serial.h" -#include "drivers/serial.h" -#include "drivers/vtx_common.h" -#include "io/vtx_tramp.h" #include "io/vtx_string.h" +#include "io/vtx_tramp.h" #define TRAMP_SERIAL_OPTIONS (SERIAL_BIDIR) #if defined(CMS) || defined(VTX_COMMON) -static const uint16_t trampPowerTable[] = { +const uint16_t trampPowerTable[VTX_TRAMP_POWER_COUNT] = { 25, 100, 200, 400, 600 }; -static const char * const trampPowerNames[] = { +const char * const trampPowerNames[VTX_TRAMP_POWER_COUNT+1] = { "---", "25 ", "100", "200", "400", "600" }; #endif @@ -98,10 +99,6 @@ uint8_t trampFreqRetries = 0; uint16_t trampConfPower = 0; uint8_t trampPowerRetries = 0; -#ifdef CMS -static void trampCmsUpdateStatusString(void); // Forward -#endif - static void trampWriteBuf(uint8_t *buf) { serialWriteBuf(trampSerialPort, buf, 16); @@ -430,200 +427,6 @@ void vtxTrampProcess(uint32_t currentTimeUs) #endif } -#ifdef CMS -#include "cms/cms.h" -#include "cms/cms_types.h" - - -char trampCmsStatusString[31] = "- -- ---- ----"; -// m bc ffff tppp -// 01234567890123 - -static void trampCmsUpdateStatusString(void) -{ - trampCmsStatusString[0] = '*'; - trampCmsStatusString[1] = ' '; - trampCmsStatusString[2] = vtx58BandLetter[trampBand]; - trampCmsStatusString[3] = vtx58ChannelNames[trampChannel][0]; - trampCmsStatusString[4] = ' '; - - if (trampCurFreq) - tfp_sprintf(&trampCmsStatusString[5], "%4d", trampCurFreq); - else - tfp_sprintf(&trampCmsStatusString[5], "----"); - - if (trampPower) { - tfp_sprintf(&trampCmsStatusString[9], " %c%3d", (trampPower == trampConfiguredPower) ? ' ' : '*', trampPower); - } - else - tfp_sprintf(&trampCmsStatusString[9], " ----"); -} - -uint8_t trampCmsPitMode = 0; -uint8_t trampCmsBand = 1; -uint8_t trampCmsChan = 1; -uint16_t trampCmsFreqRef; - -static OSD_TAB_t trampCmsEntBand = { &trampCmsBand, 5, vtx58BandNames }; - -static OSD_TAB_t trampCmsEntChan = { &trampCmsChan, 8, vtx58ChannelNames }; - -static OSD_UINT16_t trampCmsEntFreqRef = { &trampCmsFreqRef, 5600, 5900, 0 }; - -static uint8_t trampCmsPower = 1; - -static OSD_TAB_t trampCmsEntPower = { &trampCmsPower, 5, trampPowerNames }; - -static void trampCmsUpdateFreqRef(void) -{ - if (trampCmsBand > 0 && trampCmsChan > 0) - trampCmsFreqRef = vtx58frequencyTable[trampCmsBand - 1][trampCmsChan - 1]; -} - -static long trampCmsConfigBand(displayPort_t *pDisp, const void *self) -{ - UNUSED(pDisp); - UNUSED(self); - - if (trampCmsBand == 0) - // Bounce back - trampCmsBand = 1; - else - trampCmsUpdateFreqRef(); - - return 0; -} - -static long trampCmsConfigChan(displayPort_t *pDisp, const void *self) -{ - UNUSED(pDisp); - UNUSED(self); - - if (trampCmsChan == 0) - // Bounce back - trampCmsChan = 1; - else - trampCmsUpdateFreqRef(); - - return 0; -} - -static long trampCmsConfigPower(displayPort_t *pDisp, const void *self) -{ - UNUSED(pDisp); - UNUSED(self); - - if (trampCmsPower == 0) - // Bounce back - trampCmsPower = 1; - - return 0; -} - -static OSD_INT16_t trampCmsEntTemp = { &trampTemperature, -100, 300, 0 }; - -static const char * const trampCmsPitModeNames[] = { - "---", "OFF", "ON " -}; - -static OSD_TAB_t trampCmsEntPitMode = { &trampCmsPitMode, 2, trampCmsPitModeNames }; - -static long trampCmsSetPitMode(displayPort_t *pDisp, const void *self) -{ - UNUSED(pDisp); - UNUSED(self); - - if (trampCmsPitMode == 0) { - // Bouce back - trampCmsPitMode = 1; - } else { - trampSetPitMode(trampCmsPitMode - 1); - } - - return 0; -} - -static long trampCmsCommence(displayPort_t *pDisp, const void *self) -{ - UNUSED(pDisp); - UNUSED(self); - - trampSetBandAndChannel(trampCmsBand, trampCmsChan); - trampSetRFPower(trampPowerTable[trampCmsPower-1]); - - // If it fails, the user should retry later - trampCommitChanges(); - - - return MENU_CHAIN_BACK; -} - -static void trampCmsInitSettings() -{ - if (trampBand > 0) trampCmsBand = trampBand; - if (trampChannel > 0) trampCmsChan = trampChannel; - - trampCmsUpdateFreqRef(); - trampCmsPitMode = trampPitMode + 1; - - if (trampConfiguredPower > 0) { - for (uint8_t i = 0; i < sizeof(trampPowerTable); i++) { - if (trampConfiguredPower <= trampPowerTable[i]) { - trampCmsPower = i + 1; - break; - } - } - } -} - -static long trampCmsOnEnter() -{ - trampCmsInitSettings(); - return 0; -} - -static OSD_Entry trampCmsMenuCommenceEntries[] = { - { "CONFIRM", OME_Label, NULL, NULL, 0 }, - { "YES", OME_Funcall, trampCmsCommence, NULL, 0 }, - { "BACK", OME_Back, NULL, NULL, 0 }, - { NULL, OME_END, NULL, NULL, 0 } -}; - -static CMS_Menu trampCmsMenuCommence = { - .GUARD_text = "XVTXTRC", - .GUARD_type = OME_MENU, - .onEnter = NULL, - .onExit = NULL, - .onGlobalExit = NULL, - .entries = trampCmsMenuCommenceEntries, -}; - -static OSD_Entry trampMenuEntries[] = -{ - { "- TRAMP -", OME_Label, NULL, NULL, 0 }, - - { "", OME_Label, NULL, trampCmsStatusString, DYNAMIC }, - { "PIT", OME_TAB, trampCmsSetPitMode, &trampCmsEntPitMode, 0 }, - { "BAND", OME_TAB, trampCmsConfigBand, &trampCmsEntBand, 0 }, - { "CHAN", OME_TAB, trampCmsConfigChan, &trampCmsEntChan, 0 }, - { "(FREQ)", OME_UINT16, NULL, &trampCmsEntFreqRef, DYNAMIC }, - { "POWER", OME_TAB, trampCmsConfigPower, &trampCmsEntPower, 0 }, - { "T(C)", OME_INT16, NULL, &trampCmsEntTemp, DYNAMIC }, - { "SET", OME_Submenu, cmsMenuChange, &trampCmsMenuCommence, 0 }, - - { "BACK", OME_Back, NULL, NULL, 0 }, - { NULL, OME_END, NULL, NULL, 0 } -}; - -CMS_Menu cmsx_menuVtxTramp = { - .GUARD_text = "XVTXTR", - .GUARD_type = OME_MENU, - .onEnter = trampCmsOnEnter, - .onExit = NULL, - .onGlobalExit = NULL, - .entries = trampMenuEntries, -}; -#endif #ifdef VTX_COMMON diff --git a/src/main/io/vtx_tramp.h b/src/main/io/vtx_tramp.h index 6a93881db..094f2b0d7 100644 --- a/src/main/io/vtx_tramp.h +++ b/src/main/io/vtx_tramp.h @@ -1,13 +1,19 @@ #pragma once -#if defined(VTX_TRAMP) && defined(VTX_CONTROL) +#define VTX_TRAMP_POWER_COUNT 5 +extern const uint16_t trampPowerTable[VTX_TRAMP_POWER_COUNT]; +extern const char * const trampPowerNames[VTX_TRAMP_POWER_COUNT+1]; + +extern uint8_t trampBand; +extern uint8_t trampChannel; +extern uint16_t trampPower; // Actual transmitting power +extern uint8_t trampPitMode; +extern uint32_t trampCurFreq; +extern uint16_t trampConfiguredPower; // Configured transmitting power +extern int16_t trampTemperature; bool vtxTrampInit(); - -#ifdef CMS -#include "cms/cms.h" -#include "cms/cms_types.h" -extern CMS_Menu cmsx_menuVtxTramp; -#endif - -#endif +bool trampCommitChanges(); +void trampSetPitMode(uint8_t onoff); +void trampSetBandAndChannel(uint8_t band, uint8_t channel); +void trampSetRFPower(uint16_t level);