Permalink
Browse files

Allow VTX to be enabled/disabled via AUX channel. Idea by Keiren

Black/Fraser Oneil/Calum Richings/Graeme Matthews/Liam Noble (Team
Scotland) & Dominic Clifton.
  • Loading branch information...
hydra committed Oct 9, 2016
1 parent 60b2064 commit 31fa9d128f2b0d3ff44e282214ec3ab8ec3e2d95
View
@@ -135,6 +135,7 @@ extern uint8_t motorControlEnable;
serialPort_t *loopbackPort;
#endif
bool isUsingVTXSwitch(void);
void mixerUsePWMIOConfiguration(pwmIOConfiguration_t *pwmIOConfiguration);
void rxInit(modeActivationCondition_t *modeActivationConditions);
@@ -626,6 +626,9 @@ void processRx(void)
}
#endif
#ifdef VTX
updateVTXState();
#endif
}
void filterRc(void){
View
@@ -78,6 +78,8 @@
#define DEFAULT_RX_FEATURE FEATURE_RX_PARALLEL_PWM
#endif
void initVTXState(void);
// Default settings
STATIC_UNIT_TESTED void resetConf(void)
@@ -180,6 +182,10 @@ static void activateConfig(void)
recalculateMagneticDeclination();
#endif
#ifdef VTX
initVTXState();
#endif
static imuRuntimeConfig_t imuRuntimeConfig;
imuRuntimeConfig.dcm_kp = imuConfig()->dcm_kp / 10000.0f;
imuRuntimeConfig.dcm_ki = imuConfig()->dcm_ki / 10000.0f;
@@ -164,6 +164,7 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT] = {
{ "BLACKBOX", BOXBLACKBOX, 26 },
{ "FAILSAFE", BOXFAILSAFE, 27 },
{ "AIR MODE", BOXAIRMODE, 28 },
{ "VTX", BOXVTX, 29 },
};
// mask of enabled IDs, calculated on start based on enabled features. boxId_e is used as bit index.
@@ -368,6 +369,10 @@ static void initActiveBoxIds(void)
ena |= 1 << BOXGTUNE;
#endif
#ifdef VTX
ena |= 1 << BOXVTX;
#endif
// check that all enabled IDs are in boxes array (check is skipped when using findBoxBy<id>() functions
for(boxId_e boxId = 0; boxId < CHECKBOX_ITEM_COUNT; boxId++)
if((ena & (1 << boxId))
@@ -403,7 +408,7 @@ uint32_t packFlightModeFlags(void)
#define BM(x) (1 << (x))
const uint32_t rcModeCopyMask = BM(BOXHEADADJ) | BM(BOXCAMSTAB) | BM(BOXCAMTRIG) | BM(BOXBEEPERON)
| BM(BOXLEDMAX) | BM(BOXLEDLOW) | BM(BOXLLIGHTS) | BM(BOXCALIB) | BM(BOXGOV) | BM(BOXOSD)
| BM(BOXTELEMETRY) | BM(BOXGTUNE) | BM(BOXBLACKBOX) | BM(BOXAIRMODE) ;
| BM(BOXTELEMETRY) | BM(BOXGTUNE) | BM(BOXBLACKBOX) | BM(BOXAIRMODE) | BM(BOXVTX);
for(unsigned i = 0; i < sizeof(rcModeCopyMask) * 8; i++) {
if((rcModeCopyMask & BM(i)) == 0)
continue;
@@ -415,6 +420,7 @@ uint32_t packFlightModeFlags(void)
if(ARMING_FLAG(ARMED))
boxEnabledMask |= 1 << BOXARM;
// map boxId_e enabled bits to MSP status indexes
// only active boxIds are sent in status over MSP, other bits are not counted
uint32_t mspBoxEnabledMask = 0;
@@ -47,6 +47,7 @@ typedef enum {
BOXBLACKBOX,
BOXFAILSAFE,
BOXAIRMODE,
BOXVTX,
CHECKBOX_ITEM_COUNT
} boxId_e;
View
@@ -24,6 +24,7 @@
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "fc/rc_controls.h"
#include "common/utils.h"
#include "drivers/system.h"
@@ -143,6 +144,11 @@ void handleVTXControlButton(void)
#endif
}
bool isUsingVTXSwitch(void)
{
return rcModeIsActivationConditionPresent(modeActivationProfile()->modeActivationConditions, BOXVTX);
}
void vtxSaveState(void)
{
vtxConfig()->channel = vtxState.channel;
@@ -158,8 +164,40 @@ void vtxInit(void)
vtxState.band = vtxConfig()->band;
vtxState.rfPower = vtxConfig()->rfPower;
if (vtxConfig()->enabledOnBoot) {
vtxEnable();
if (!isUsingVTXSwitch()) {
if (vtxConfig()->enabledOnBoot) {
vtxEnable();
}
}
}
static bool vtxModeActivationConditionPresent = false;
void initVTXState(void)
{
vtxModeActivationConditionPresent = isUsingVTXSwitch();
}
void updateVTXState(void)
{
static bool vtxEnabled = false;
if (!vtxModeActivationConditionPresent) {
return;
}
if (rcModeIsActive(BOXVTX)) {
if (!vtxEnabled) {
if (!vtxState.enabled) {
vtxEnable();
}
vtxEnabled = true;
}
} else {
if (vtxEnabled) {
if (vtxState.enabled) {
vtxDisable();
}
vtxEnabled = false;
}
}
}
View
@@ -34,6 +34,12 @@ typedef struct vtxState_s {
extern vtxState_t vtxState;
// VTX Control
void initVTXState(void);
bool isUsingVTXSwitch(void);
void updateVTXState(void);
// VTX API
// common methods

0 comments on commit 31fa9d1

Please sign in to comment.