10 extern bool ICACHE_RAM_ATTR
IsArmed();
14 static enum VtxSendState_e
16 VTXSS_UNKNOWN
, // Status of the remote side is unknown, so we should send immediately if connected
17 VTXSS_MODIFIED
, // Config is editied, should always be sent regardless of connect state
18 VTXSS_SENDING1
, VTXSS_SENDING2
, VTXSS_SENDING3
, VTXSS_SENDINGDONE
, // Send the config 3x
19 VTXSS_CONFIRMED
// Status of remote side is consistent with our config
24 VtxSendState
= VTXSS_MODIFIED
;
25 devicesTriggerEvent();
28 static void eepromWriteToMSPOut()
32 packet
.function
= MSP_EEPROM_WRITE
;
34 crsf
.AddMspMessage(&packet
);
37 static void VtxConfigToMSPOut()
39 DBGLN("Sending VtxConfig");
40 uint8_t vtxIdx
= (config
.GetVtxBand()-1) * 8 + config
.GetVtxChannel();
45 packet
.function
= MSP_SET_VTX_CONFIG
;
46 packet
.addByte(vtxIdx
);
48 if (config
.GetVtxPower()) {
49 packet
.addByte(config
.GetVtxPower());
50 packet
.addByte(config
.GetVtxPitmode());
53 crsf
.AddMspMessage(&packet
);
54 msp
.sendPacket(&packet
, &Serial
); // send to tx-backpack as MSP
59 if (VtxSendState
== VTXSS_MODIFIED
||
60 (VtxSendState
== VTXSS_UNKNOWN
&& connectionState
== connected
))
62 VtxSendState
= VTXSS_SENDING1
;
66 if (connectionState
== disconnected
)
67 VtxSendState
= VTXSS_UNKNOWN
;
69 return DURATION_NEVER
;
74 // 0 = off in the lua Band field
75 // Do not send while armed
76 if (config
.GetVtxBand() == 0 || IsArmed())
78 VtxSendState
= VTXSS_CONFIRMED
;
79 return DURATION_NEVER
;
84 VtxSendState
= (VtxSendState_e
)((int)VtxSendState
+ 1);
85 if (VtxSendState
< VTXSS_SENDINGDONE
)
86 return 500; // repeat send in 500ms
88 if (connectionState
== connected
)
90 // Connected while sending, assume the MSP got to the RX
91 VtxSendState
= VTXSS_CONFIRMED
;
92 eepromWriteToMSPOut();
96 VtxSendState
= VTXSS_UNKNOWN
;
97 // Never received a connection, clear the queue which now
98 // has multiple VTX config packets in it
102 return DURATION_NEVER
;
105 device_t VTX_device
= {