From ac2ce487fa5de38a15537aa1dcded22c814099a0 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 19 Jul 2019 13:22:09 +0200 Subject: [PATCH] R9M Lite BIND / TX OPTIONS / RX OPTIONS reviewed --- radio/src/gui/128x64/model_setup.cpp | 29 ++++++-- .../common/stdlcd/model_module_options.cpp | 31 +++++--- .../common/stdlcd/model_receiver_options.cpp | 72 +++++++++++-------- .../gui/common/stdlcd/model_setup_pxx2.cpp | 8 ++- radio/src/opentx.h | 7 +- radio/src/pulses/pulses.h | 2 +- radio/src/pulses/pxx2.h | 2 + 7 files changed, 97 insertions(+), 54 deletions(-) diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index 6d6d084b8..fe30a21cf 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -1206,12 +1206,31 @@ void menuModelSetup(event_t event) drawReceiverName(MODEL_SETUP_2ND_COLUMN, y, moduleIdx, receiverIdx, attr); - if (s_editMode && isModuleR9MAccess(moduleIdx) && moduleState[moduleIdx].mode == MODULE_MODE_NORMAL && moduleInformation.information.modelID) { - moduleInformation.information.modelID = 0; - moduleState[moduleIdx].startBind(&reusableBuffer.moduleSetup.bindInformation); + if (s_editMode && isModuleR9MAccess(moduleIdx) && moduleState[moduleIdx].mode == MODULE_MODE_NORMAL && reusableBuffer.moduleSetup.bindInformation.step < 0) { + lcdDrawNumber(lcdNextPos, y, reusableBuffer.moduleSetup.bindInformation.step); + if (reusableBuffer.moduleSetup.bindInformation.step == BIND_MODULE_TX_INFORMATION_REQUEST && moduleInformation.information.modelID) { + // For R9M ACCESS the module information has been requested to know if we are in EU mode. We just receive it here and continue + if (moduleInformation.information.variant == PXX2_VARIANT_EU) { + // In EU mode we will need the power of the module to know if telemetry can be proposed + reusableBuffer.moduleSetup.bindInformation.step = BIND_MODULE_TX_SETTINGS_REQUEST; +#if defined(SIMU) + reusableBuffer.moduleSetup.pxx2.moduleSettings.txPower = 14; +#else + moduleState[moduleIdx].readModuleSettings(&reusableBuffer.moduleSetup.pxx2.moduleSettings); +#endif + } + else { + reusableBuffer.moduleSetup.bindInformation.step = 0; + moduleState[moduleIdx].startBind(&reusableBuffer.moduleSetup.bindInformation); + } + } + else if (reusableBuffer.moduleSetup.bindInformation.step == BIND_MODULE_TX_SETTINGS_REQUEST && reusableBuffer.moduleSetup.pxx2.moduleSettings.txPower > 0) { + // We just receive the module settings (for TX power) + reusableBuffer.moduleSetup.bindInformation.step = 0; + moduleState[moduleIdx].startBind(&reusableBuffer.moduleSetup.bindInformation); + } } - - if (attr && (moduleState[moduleIdx].mode == 0 || s_editMode == 0)) { + else if (attr && (moduleState[moduleIdx].mode == MODULE_MODE_NORMAL || s_editMode == 0)) { if (moduleState[moduleIdx].mode) { moduleState[moduleIdx].mode = 0; removePXX2ReceiverIfEmpty(moduleIdx, receiverIdx); diff --git a/radio/src/gui/common/stdlcd/model_module_options.cpp b/radio/src/gui/common/stdlcd/model_module_options.cpp index eb7e629ab..3a60cefe5 100644 --- a/radio/src/gui/common/stdlcd/model_module_options.cpp +++ b/radio/src/gui/common/stdlcd/model_module_options.cpp @@ -26,9 +26,10 @@ extern uint8_t g_moduleIdx; enum { - MODULE_SETTINGS_OK, - MODULE_SETTINGS_DIRTY, - MODULE_SETTINGS_WRITING, + MODULE_SETTINGS_OK = 0, + MODULE_SETTINGS_DIRTY = 1, + MODULE_SETTINGS_REBIND = 2, + MODULE_SETTINGS_WRITING = 4, }; void onTxOptionsUpdateConfirm(const char * result) @@ -45,6 +46,7 @@ void onTxOptionsUpdateConfirm(const char * result) enum { ITEM_MODULE_SETTINGS_EXTERNAL_ANTENNA, ITEM_MODULE_SETTINGS_POWER, + ITEM_MODULE_SETTINGS_TELEMETRY, ITEM_MODULE_SETTINGS_COUNT }; @@ -57,8 +59,8 @@ bool isPowerAvailable(int value) if (modelId == PXX2_MODULE_R9M_LITE) { if (variant == PXX2_VARIANT_EU) - return (value == 14 /* 25 mW */ || - value == 20 /* 100 mW */); + return (value == 14 /* 25 mW with telemetry */ || + value == 20 /* 100 mW without telemetry */); else return value == 20; /* 100 mW */ } @@ -94,13 +96,14 @@ void menuModelModuleOptions(event_t event) SUBMENU_NOTITLE(ITEM_MODULE_SETTINGS_COUNT, { !optionsAvailable ? (uint8_t)0 : IF_MODULE_OPTIONS(MODULE_OPTION_EXTERNAL_ANTENNA, 0), IF_MODULE_OPTIONS(MODULE_OPTION_POWER, 0), + IF_MODULE_OPTIONS(MODULE_OPTION_POWER, reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].information.variant == PXX2_VARIANT_EU && reusableBuffer.hardwareAndSettings.moduleSettings.txPower > 14 ? READONLY_ROW : HIDDEN_ROW) }); if (reusableBuffer.hardwareAndSettings.moduleSettings.state == PXX2_HARDWARE_INFO && moduleState[g_moduleIdx].mode == MODULE_MODE_NORMAL) { - if (modelId) - moduleState[g_moduleIdx].readModuleSettings(&reusableBuffer.hardwareAndSettings.moduleSettings); - else + if (!modelId) moduleState[g_moduleIdx].readModuleInformation(&reusableBuffer.hardwareAndSettings.modules[g_moduleIdx], PXX2_HW_INFO_TX_ID, PXX2_HW_INFO_TX_ID); + else + moduleState[g_moduleIdx].readModuleSettings(&reusableBuffer.hardwareAndSettings.moduleSettings); } if (menuEvent) { @@ -166,11 +169,19 @@ void menuModelModuleOptions(event_t event) lcdDrawText(lcdNextPos, y, ")"); if (attr) { reusableBuffer.hardwareAndSettings.moduleSettings.txPower = checkIncDec(event, reusableBuffer.hardwareAndSettings.moduleSettings.txPower, 0, 30, 0, &isPowerAvailable); - if (checkIncDec_Ret) { - reusableBuffer.hardwareAndSettings.moduleSettings.dirty = MODULE_SETTINGS_DIRTY; + if (checkIncDec_Ret) + reusableBuffer.hardwareAndSettings.moduleSettings.dirty = MODULE_SETTINGS_DIRTY | MODULE_SETTINGS_REBIND; + if (s_editMode == 0 && (reusableBuffer.hardwareAndSettings.moduleSettings.dirty & MODULE_SETTINGS_REBIND)) { + reusableBuffer.hardwareAndSettings.moduleSettings.dirty &= ~MODULE_SETTINGS_REBIND; + POPUP_WARNING(STR_REBIND); } } break; + + case ITEM_MODULE_SETTINGS_TELEMETRY: + // only displayed in EU mode when TX power > 25mW + lcdDrawText(RECEIVER_OPTIONS_2ND_COLUMN, y, "Telem OFF", attr | SMLSIZE); + break; } } } diff --git a/radio/src/gui/common/stdlcd/model_receiver_options.cpp b/radio/src/gui/common/stdlcd/model_receiver_options.cpp index 001d7045a..50f9446df 100644 --- a/radio/src/gui/common/stdlcd/model_receiver_options.cpp +++ b/radio/src/gui/common/stdlcd/model_receiver_options.cpp @@ -24,11 +24,17 @@ extern uint8_t g_moduleIdx; +enum { + RECEIVER_SETTINGS_OK = 0, + RECEIVER_SETTINGS_DIRTY = 1, + RECEIVER_SETTINGS_WRITING = 2, +}; + void onRxOptionsUpdateConfirm(const char * result) { if (result == STR_OK) { reusableBuffer.hardwareAndSettings.receiverSettings.state = PXX2_SETTINGS_WRITE; - reusableBuffer.hardwareAndSettings.receiverSettings.dirty = 2; + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_WRITING; reusableBuffer.hardwareAndSettings.receiverSettings.timeout = 0; moduleState[g_moduleIdx].mode = MODULE_MODE_RECEIVER_SETTINGS; } @@ -38,8 +44,8 @@ void onRxOptionsUpdateConfirm(const char * result) } enum { - ITEM_RECEIVER_SETTINGS_TELEMETRY, ITEM_RECEIVER_SETTINGS_PWM_RATE, + ITEM_RECEIVER_SETTINGS_TELEMETRY, ITEM_RECEIVER_SETTINGS_SPORT_FPORT, ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED1, ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED2, @@ -62,7 +68,21 @@ void menuModelReceiverOptions(event_t event) reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount = 8; #endif } - else if (menuEvent) { + + uint8_t receiverId = reusableBuffer.hardwareAndSettings.receiverSettings.receiverId; + uint8_t receiverModelId = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.modelID; + uint8_t receiverVariant = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.variant; + + SUBMENU_NOTITLE(ITEM_RECEIVER_SETTINGS_PINMAP_FIRST + outputsCount, { + 0, // PWM rate + isModuleR9MAccess(g_moduleIdx) && receiverVariant == PXX2_VARIANT_EU && reusableBuffer.hardwareAndSettings.moduleSettings.txPower > 14 /*25mW*/ ? READONLY_ROW : (uint8_t)0, // Telemetry + IF_RECEIVER_CAPABILITY(RECEIVER_CAPABILITY_FPORT, 0), + uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW), + uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW), + 0 // channels ... + }); + + if (menuEvent) { killEvents(KEY_EXIT); moduleState[g_moduleIdx].mode = MODULE_MODE_NORMAL; if (reusableBuffer.hardwareAndSettings.receiverSettings.dirty) { @@ -74,37 +94,27 @@ void menuModelReceiverOptions(event_t event) } } - uint8_t receiverId = reusableBuffer.hardwareAndSettings.receiverSettings.receiverId; - uint8_t modelId = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.modelID; - - SUBMENU_NOTITLE(ITEM_RECEIVER_SETTINGS_PINMAP_FIRST + outputsCount, { - 0, // Telemetry - 0, // PWM rate - IF_RECEIVER_CAPABILITY(RECEIVER_CAPABILITY_FPORT, 0), - uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW), - uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW), - 0 // channels ... - }); - if (reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_HARDWARE_INFO && moduleState[g_moduleIdx].mode == MODULE_MODE_NORMAL) { - if (modelId) - moduleState[g_moduleIdx].readReceiverSettings(&reusableBuffer.hardwareAndSettings.receiverSettings); - else + if (!receiverModelId) moduleState[g_moduleIdx].readModuleInformation(&reusableBuffer.hardwareAndSettings.modules[g_moduleIdx], receiverId, receiverId); + else if (isModuleR9MAccess(g_moduleIdx) && receiverVariant == PXX2_VARIANT_EU && !reusableBuffer.hardwareAndSettings.moduleSettings.txPower) + moduleState[g_moduleIdx].readModuleSettings(&reusableBuffer.hardwareAndSettings.moduleSettings); + else + moduleState[g_moduleIdx].readReceiverSettings(&reusableBuffer.hardwareAndSettings.receiverSettings); } if (event == EVT_KEY_LONG(KEY_ENTER) && reusableBuffer.hardwareAndSettings.receiverSettings.dirty) { killEvents(event); - reusableBuffer.hardwareAndSettings.receiverSettings.dirty = 0; + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_OK; moduleState[g_moduleIdx].writeReceiverSettings(&reusableBuffer.hardwareAndSettings.receiverSettings); } - if (reusableBuffer.hardwareAndSettings.receiverSettings.dirty == 2 && reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_SETTINGS_OK) { + if (reusableBuffer.hardwareAndSettings.receiverSettings.dirty == RECEIVER_SETTINGS_WRITING && reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_SETTINGS_OK) { popMenu(); return; } - if (modelId != 0 && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) { + if (receiverModelId && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) { menuVerticalPosition = 0; while (menuVerticalPosition < ITEM_RECEIVER_SETTINGS_PINMAP_FIRST && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) { ++menuVerticalPosition; @@ -128,24 +138,24 @@ void menuModelReceiverOptions(event_t event) LcdFlags attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0); switch (i) { - case ITEM_RECEIVER_SETTINGS_TELEMETRY: - reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled, RECEIVER_OPTIONS_2ND_COLUMN, y, STR_TELEMETRY_DISABLED, attr, event); - if (attr && checkIncDec_Ret) { - reusableBuffer.hardwareAndSettings.receiverSettings.dirty = true; - } - break; - case ITEM_RECEIVER_SETTINGS_PWM_RATE: reusableBuffer.hardwareAndSettings.receiverSettings.pwmRate = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.pwmRate, RECEIVER_OPTIONS_2ND_COLUMN, y, isModuleR9MAccess(g_moduleIdx) ? "6.67ms PWM": "9ms PWM", attr, event); if (attr && checkIncDec_Ret) { - reusableBuffer.hardwareAndSettings.receiverSettings.dirty = true; + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; + } + break; + + case ITEM_RECEIVER_SETTINGS_TELEMETRY: + reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled, RECEIVER_OPTIONS_2ND_COLUMN, y, STR_TELEMETRY_DISABLED, attr, event); + if (attr && checkIncDec_Ret) { + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; } break; case ITEM_RECEIVER_SETTINGS_SPORT_FPORT: reusableBuffer.hardwareAndSettings.receiverSettings.fport = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.fport, RECEIVER_OPTIONS_2ND_COLUMN, y, "F.Port", attr, event); if (attr && checkIncDec_Ret) { - reusableBuffer.hardwareAndSettings.receiverSettings.dirty = true; + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; } break; @@ -173,7 +183,7 @@ void menuModelReceiverOptions(event_t event) if (attr) { mapping = checkIncDec(event, mapping, 0, sentModuleChannels(g_moduleIdx) - 1); if (checkIncDec_Ret) { - reusableBuffer.hardwareAndSettings.receiverSettings.dirty = true; + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; } } diff --git a/radio/src/gui/common/stdlcd/model_setup_pxx2.cpp b/radio/src/gui/common/stdlcd/model_setup_pxx2.cpp index e97dc793e..42d43ecdb 100644 --- a/radio/src/gui/common/stdlcd/model_setup_pxx2.cpp +++ b/radio/src/gui/common/stdlcd/model_setup_pxx2.cpp @@ -82,9 +82,10 @@ void onPXX2BindMenu(const char * result) reusableBuffer.moduleSetup.bindInformation.selectedReceiverIndex = (result - reusableBuffer.moduleSetup.bindInformation.candidateReceiversNames[0]) / sizeof(reusableBuffer.moduleSetup.bindInformation.candidateReceiversNames[0]); if (isModuleR9MAccess(moduleIdx) && reusableBuffer.moduleSetup.pxx2.moduleInformation.information.variant == PXX2_VARIANT_EU) { reusableBuffer.moduleSetup.bindInformation.step = BIND_RX_NAME_SELECTED; - POPUP_MENU_ADD_ITEM(STR_16CH_WITH_TELEMETRY); - POPUP_MENU_ADD_ITEM(STR_16CH_WITHOUT_TELEMETRY); - POPUP_MENU_START(onPXX2R9MBindModeMenu); + if (reusableBuffer.moduleSetup.pxx2.moduleSettings.txPower <= 14) + onPXX2R9MBindModeMenu(STR_16CH_WITH_TELEMETRY); + else + onPXX2R9MBindModeMenu(STR_16CH_WITHOUT_TELEMETRY); } else if (isModuleR9MAccess(moduleIdx) && reusableBuffer.moduleSetup.pxx2.moduleInformation.information.variant == PXX2_VARIANT_FLEX) { reusableBuffer.moduleSetup.bindInformation.step = BIND_RX_NAME_SELECTED; @@ -140,6 +141,7 @@ void onPXX2ReceiverMenu(const char * result) memclear(&reusableBuffer.moduleSetup.bindInformation, sizeof(BindInformation)); reusableBuffer.moduleSetup.bindInformation.rxUid = receiverIdx; if (isModuleR9MAccess(moduleIdx)) { + reusableBuffer.moduleSetup.bindInformation.step = BIND_MODULE_TX_INFORMATION_REQUEST; #if defined(SIMU) reusableBuffer.moduleSetup.pxx2.moduleInformation.information.modelID = 1; reusableBuffer.moduleSetup.pxx2.moduleInformation.information.variant = 2; diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 1e012f1e4..c3f83f617 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1129,6 +1129,7 @@ union ReusableBuffer }; uint8_t resetReceiverFlags; ModuleInformation moduleInformation; + ModuleSettings moduleSettings; } pxx2; #if defined(BLUETOOTH) struct { @@ -1168,10 +1169,8 @@ union ReusableBuffer struct { ModuleInformation modules[NUM_MODULES]; uint32_t updateTime; - union { - ModuleSettings moduleSettings; - ReceiverSettings receiverSettings; - }; + ModuleSettings moduleSettings; + ReceiverSettings receiverSettings; // when dealing with receiver settings, we also need module settings } hardwareAndSettings; struct { diff --git a/radio/src/pulses/pulses.h b/radio/src/pulses/pulses.h index 1402af060..c2ee66d53 100644 --- a/radio/src/pulses/pulses.h +++ b/radio/src/pulses/pulses.h @@ -133,7 +133,7 @@ class ReceiverSettings { class BindInformation { public: - uint8_t step; + int8_t step; uint32_t timeout; char candidateReceiversNames[PXX2_MAX_RECEIVERS_PER_MODULE][PXX2_LEN_RX_NAME + 1]; uint8_t candidateReceiversCount; diff --git a/radio/src/pulses/pxx2.h b/radio/src/pulses/pxx2.h index 394a30b13..b7c9d8eba 100644 --- a/radio/src/pulses/pxx2.h +++ b/radio/src/pulses/pxx2.h @@ -143,6 +143,8 @@ enum PXX2RegisterSteps { }; enum PXX2BindSteps { + BIND_MODULE_TX_INFORMATION_REQUEST = -2, + BIND_MODULE_TX_SETTINGS_REQUEST = -1, BIND_INIT, BIND_RX_NAME_SELECTED, BIND_INFO_REQUEST,