Rework BIND to share code with OTA update
This commit is contained in:
@@ -122,6 +122,17 @@ struct ReceiverSettings {
|
||||
uint8_t outputsMapping[24];
|
||||
};
|
||||
|
||||
struct BindInformation {
|
||||
uint8_t step;
|
||||
uint32_t timeout;
|
||||
char candidateReceiversNames[PXX2_MAX_RECEIVERS_PER_MODULE][PXX2_LEN_RX_NAME + 1];
|
||||
uint8_t candidateReceiversCount;
|
||||
uint8_t selectedReceiverIndex;
|
||||
uint8_t rxUid;
|
||||
uint8_t lbtMode;
|
||||
uint8_t flexMode;
|
||||
};
|
||||
|
||||
PACK(struct ModuleState {
|
||||
uint8_t protocol:4;
|
||||
uint8_t mode:4;
|
||||
@@ -131,7 +142,18 @@ PACK(struct ModuleState {
|
||||
union {
|
||||
ModuleInformation * moduleInformation;
|
||||
ModuleSettings * moduleSettings;
|
||||
BindInformation * bindInformation;
|
||||
};
|
||||
void startBind(BindInformation * destination)
|
||||
{
|
||||
bindInformation = destination;
|
||||
mode = MODULE_MODE_BIND;
|
||||
#if defined(SIMU)
|
||||
bindInformation->candidateReceiversCount = 2;
|
||||
strcpy(bindInformation->candidateReceiversNames[0], "SimuRX1");
|
||||
strcpy(bindInformation->candidateReceiversNames[1], "SimuRX2");
|
||||
#endif
|
||||
}
|
||||
void readModuleInformation(ModuleInformation * destination, int8_t first, int8_t last)
|
||||
{
|
||||
moduleInformation = destination;
|
||||
|
||||
@@ -222,10 +222,12 @@ void Pxx2Pulses::setupReceiverSettingsFrame(uint8_t module)
|
||||
|
||||
void Pxx2Pulses::setupBindFrame(uint8_t module)
|
||||
{
|
||||
if (reusableBuffer.moduleSetup.pxx2.bindStep == BIND_WAIT) {
|
||||
if (get_tmr10ms() > reusableBuffer.moduleSetup.pxx2.bindWaitTimeout) {
|
||||
BindInformation * destination = moduleState[module].bindInformation;
|
||||
|
||||
if (destination->step == BIND_WAIT) {
|
||||
if (get_tmr10ms() > destination->timeout) {
|
||||
moduleState[module].mode = MODULE_MODE_NORMAL;
|
||||
reusableBuffer.moduleSetup.pxx2.bindStep = BIND_OK;
|
||||
destination->step = BIND_OK;
|
||||
POPUP_INFORMATION(STR_BIND_OK);
|
||||
}
|
||||
return;
|
||||
@@ -233,12 +235,12 @@ void Pxx2Pulses::setupBindFrame(uint8_t module)
|
||||
|
||||
addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_BIND);
|
||||
|
||||
if (reusableBuffer.moduleSetup.pxx2.bindStep == BIND_OPTIONS_SELECTED) {
|
||||
if (destination->step == BIND_OPTIONS_SELECTED) {
|
||||
Pxx2Transport::addByte(0x01);
|
||||
for (uint8_t i=0; i<PXX2_LEN_RX_NAME; i++) {
|
||||
Pxx2Transport::addByte(reusableBuffer.moduleSetup.pxx2.bindCandidateReceiversNames[reusableBuffer.moduleSetup.pxx2.bindSelectedReceiverIndex][i]);
|
||||
Pxx2Transport::addByte(destination->candidateReceiversNames[destination->selectedReceiverIndex][i]);
|
||||
}
|
||||
Pxx2Transport::addByte((reusableBuffer.moduleSetup.pxx2.bindLbtMode << 6) + (reusableBuffer.moduleSetup.pxx2.bindFlexMode << 4) + reusableBuffer.moduleSetup.pxx2.bindReceiverIndex); // RX_UID is the slot index (which is unique and never moved)
|
||||
Pxx2Transport::addByte((destination->lbtMode << 6) + (destination->flexMode << 4) + destination->rxUid); // RX_UID is the slot index (which is unique and never moved)
|
||||
Pxx2Transport::addByte(g_model.header.modelId[module]);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user