Skip to content

Commit

Permalink
Use callback for TX binding
Browse files Browse the repository at this point in the history
  • Loading branch information
CapnBry committed Feb 5, 2024
1 parent dd9f104 commit 84f81d7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib/CRSF/CRSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void (*CRSF::OnConnected)() = nullptr; // called when CRSF stream is regained
void (*CRSF::RecvParameterUpdate)(uint8_t type, uint8_t index, uint8_t arg) = nullptr; // called when recv parameter update req, ie from LUA
void (*CRSF::RecvModelUpdate)() = nullptr; // called when model id cahnges, ie command from Radio
void (*CRSF::RCdataCallback)() = nullptr; // called when there is new RC data
void (*CRSF::OnBindingCommand)() = nullptr; // called when the CRSF bind command comes via serial

/// UART Handling ///
uint8_t CRSF::SerialInPacketLen = 0; // length of the CRSF packet as measured
Expand Down Expand Up @@ -373,15 +374,14 @@ bool CRSF::processInternalCrsfPackage(uint8_t *package)
const crsf_frame_type_e packetType = (crsf_frame_type_e)header->type;

// Enter Binding Mode
if (connectionState == disconnected
&& packetType == CRSF_FRAMETYPE_COMMAND
if (packetType == CRSF_FRAMETYPE_COMMAND
&& header->frame_size >= 6 // official CRSF is 7 bytes with two CRCs
&& header->dest_addr == CRSF_ADDRESS_CRSF_TRANSMITTER
&& header->orig_addr == CRSF_ADDRESS_RADIO_TRANSMITTER
&& header->payload[0] == CRSF_COMMAND_SUBCMD_RX
&& header->payload[1] == CRSF_COMMAND_SUBCMD_RX_BIND)
{
EnterBindingModeSafely();
if (OnBindingCommand) OnBindingCommand();
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/CRSF/CRSF.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CRSF
static void (*RecvModelUpdate)();
static void (*RecvParameterUpdate)(uint8_t type, uint8_t index, uint8_t arg);
static void (*RCdataCallback)();
static void (*OnBindingCommand)();

// The model ID as received from the Transmitter
static uint8_t modelId;
Expand Down
1 change: 1 addition & 0 deletions src/src/tx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ void setup()
CRSF::OnDisconnected = &UARTdisconnected;
}
CRSF::RecvModelUpdate = &ModelUpdateReq;
CRSF::OnBindingCommand = &EnterBindingModeSafely;
DBGLN("ExpressLRS TX Module Booted...");

eeprom.Begin(); // Init the eeprom
Expand Down

0 comments on commit 84f81d7

Please sign in to comment.