mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 17:25:13 +03:00
Remove a receiver if the BIND failed / was stopped by user
This commit is contained in:
parent
17335d5909
commit
62d12290e6
3 changed files with 29 additions and 6 deletions
|
@ -244,6 +244,16 @@ enum MenuModelSetupItems {
|
|||
#endif
|
||||
|
||||
#if defined(PXX2)
|
||||
const char * STR_BIND = "Bind";
|
||||
const char * STR_SHARE = "Share";
|
||||
|
||||
void removePXX2ReceiverIfEmpty(uint8_t moduleIdx, uint8_t receiverIdx)
|
||||
{
|
||||
if (is_memclear(g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx], PXX2_LEN_RX_NAME)) {
|
||||
g_model.moduleData[moduleIdx].pxx2.receivers &= ~(1 << receiverIdx);
|
||||
}
|
||||
}
|
||||
|
||||
void onPXX2BindMenu(const char * result)
|
||||
{
|
||||
if (result != STR_EXIT) {
|
||||
|
@ -253,13 +263,12 @@ void onPXX2BindMenu(const char * result)
|
|||
else {
|
||||
// the user pressed [Exit]
|
||||
uint8_t moduleIdx = CURRENT_MODULE_EDITED(menuVerticalPosition - HEADER_LINE);
|
||||
uint8_t receiverIdx = CURRENT_RECEIVER_EDITED(menuVerticalPosition - HEADER_LINE);
|
||||
moduleSettings[moduleIdx].mode = MODULE_MODE_NORMAL;
|
||||
removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx);
|
||||
}
|
||||
}
|
||||
|
||||
const char * STR_BIND = "Bind";
|
||||
const char * STR_SHARE = "Share";
|
||||
|
||||
void onPXX2ReceiverMenu(const char * result)
|
||||
{
|
||||
uint8_t moduleIdx = CURRENT_MODULE_EDITED(menuVerticalPosition - HEADER_LINE);
|
||||
|
@ -287,6 +296,9 @@ void onPXX2ReceiverMenu(const char * result)
|
|||
memclear(g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx], PXX2_LEN_RX_NAME);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else {
|
||||
removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1209,7 +1221,7 @@ void menuModelSetup(event_t event)
|
|||
break;
|
||||
#endif
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
#if defined(PXX2)
|
||||
case ITEM_MODEL_REGISTRATION_ID:
|
||||
lcdDrawTextAlignedLeft(y, STR_REG_ID);
|
||||
if (isDefaultModelRegistrationID())
|
||||
|
@ -1289,6 +1301,7 @@ void menuModelSetup(event_t event)
|
|||
s_editMode = 0;
|
||||
killEvents(event);
|
||||
g_model.moduleData[moduleIdx].pxx2.receivers |= (1 << receiverIdx);
|
||||
memclear(g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx], PXX2_LEN_RX_NAME);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else {
|
||||
|
@ -1301,6 +1314,7 @@ void menuModelSetup(event_t event)
|
|||
if (attr && (moduleSettings[moduleIdx].mode == 0 || s_editMode == 0)) {
|
||||
if (moduleSettings[moduleIdx].mode) {
|
||||
moduleSettings[moduleIdx].mode = 0;
|
||||
removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx);
|
||||
killEvents(event); // we stopped BIND / SHARE, we don't want to re-open the menu
|
||||
event = 0;
|
||||
}
|
||||
|
|
|
@ -248,7 +248,16 @@
|
|||
|
||||
#include "myeeprom.h"
|
||||
|
||||
#define memclear(p, s) memset(p, 0, s)
|
||||
inline void memclear(void * p, size_t size)
|
||||
{
|
||||
memset(p, 0, size);
|
||||
}
|
||||
|
||||
inline bool is_memclear(void * p, size_t size)
|
||||
{
|
||||
uint8_t * buf = (uint8_t *)p;
|
||||
return buf[0] == 0 && !memcmp(buf, buf + 1, size - 1);
|
||||
}
|
||||
|
||||
void memswap(void * a, void * b, uint8_t size);
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ void Pxx2Pulses::setupHardwareInfoFrame(uint8_t module)
|
|||
if (reusableBuffer.hardwareAndSettings.modules[module].current <= reusableBuffer.hardwareAndSettings.modules[module].maximum) {
|
||||
addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_HW_INFO);
|
||||
Pxx2Transport::addByte(reusableBuffer.hardwareAndSettings.modules[module].current);
|
||||
reusableBuffer.hardwareAndSettings.modules[module].timeout = 50; /* 200ms */
|
||||
reusableBuffer.hardwareAndSettings.modules[module].timeout = 60; /* 300ms */
|
||||
reusableBuffer.hardwareAndSettings.modules[module].current++;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue