From 5976f63e1043a9efe0869ee38340093771d9e1fa Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 14 Aug 2019 15:50:26 +0200 Subject: [PATCH] [X10 Express] Receiver options added --- radio/src/gui/480x272/CMakeLists.txt | 2 +- radio/src/gui/480x272/menus.h | 1 + .../src/gui/480x272/model_module_options.cpp | 2 +- .../gui/480x272/model_receiver_options.cpp | 211 ++++++++++++++++++ radio/src/gui/480x272/model_setup.cpp | 3 +- .../gui/480x272/model_telemetry_sensor.cpp | 2 +- 6 files changed, 217 insertions(+), 4 deletions(-) create mode 100644 radio/src/gui/480x272/model_receiver_options.cpp diff --git a/radio/src/gui/480x272/CMakeLists.txt b/radio/src/gui/480x272/CMakeLists.txt index 227bba2c7..de19e4b6a 100644 --- a/radio/src/gui/480x272/CMakeLists.txt +++ b/radio/src/gui/480x272/CMakeLists.txt @@ -9,7 +9,7 @@ set(GUI_SRC model_select.cpp model_setup.cpp model_module_options.cpp -# model_receiver_options.cpp + model_receiver_options.cpp model_failsafe.cpp model_logical_switches.cpp model_special_functions.cpp diff --git a/radio/src/gui/480x272/menus.h b/radio/src/gui/480x272/menus.h index b57f727a5..d141a1154 100644 --- a/radio/src/gui/480x272/menus.h +++ b/radio/src/gui/480x272/menus.h @@ -180,6 +180,7 @@ bool menuModelTelemetryFrsky(event_t event); bool menuModelSensor(event_t event); bool menuModelExpoOne(event_t event); bool menuModelModuleOptions(event_t event); +bool menuModelReceiverOptions(event_t event); extern const MenuHandlerFunc menuTabModel[MENU_MODEL_PAGES_COUNT]; diff --git a/radio/src/gui/480x272/model_module_options.cpp b/radio/src/gui/480x272/model_module_options.cpp index 686b154b0..4d21f6b3b 100644 --- a/radio/src/gui/480x272/model_module_options.cpp +++ b/radio/src/gui/480x272/model_module_options.cpp @@ -148,7 +148,7 @@ bool menuModelModuleOptions(event_t event) if (reusableBuffer.hardwareAndSettings.moduleSettings.state == PXX2_SETTINGS_OK) { if (optionsAvailable) { - for (uint8_t k=0; k(16, reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount); + + if (event == EVT_ENTRY) { + // reusableBuffer.hardwareSettings should have been cleared before calling this menu +#if defined(SIMU) + reusableBuffer.hardwareAndSettings.receiverSettings.state = PXX2_SETTINGS_OK; + reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount = 16; +#endif + } + + 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(STR_RECEIVER_OPTIONS, ICON_MODEL_SETUP, 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 (g_model.moduleData[g_moduleIdx].pxx2.receiverName[receiverId][0] != '\0') + lcdDrawSizedText(50, 3 + FH, g_model.moduleData[g_moduleIdx].pxx2.receiverName[receiverId], effectiveLen(g_model.moduleData[g_moduleIdx].pxx2.receiverName[receiverId], PXX2_LEN_RX_NAME), MENU_TITLE_COLOR); + else + lcdDrawText(50, 3 + FH, "---", MENU_TITLE_COLOR); + + if (menuEvent) { + killEvents(KEY_EXIT); + moduleState[g_moduleIdx].mode = MODULE_MODE_NORMAL; + if (reusableBuffer.hardwareAndSettings.receiverSettings.dirty) { + abortPopMenu(); + POPUP_CONFIRMATION(STR_UPDATE_RX_OPTIONS, onRxOptionsUpdateConfirm); + } + else { + return false; + } + } + + if (reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_HARDWARE_INFO && moduleState[g_moduleIdx].mode == MODULE_MODE_NORMAL) { + 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 = RECEIVER_SETTINGS_OK; + moduleState[g_moduleIdx].writeReceiverSettings(&reusableBuffer.hardwareAndSettings.receiverSettings); + } + + if (reusableBuffer.hardwareAndSettings.receiverSettings.dirty == RECEIVER_SETTINGS_WRITING && reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_SETTINGS_OK) { + popMenu(); + return false; + } + + if (receiverModelId && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) { + menuVerticalPosition = 0; + while (menuVerticalPosition < ITEM_RECEIVER_SETTINGS_PINMAP_FIRST && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) { + ++menuVerticalPosition; + } + } + + int8_t sub = menuVerticalPosition; + + if (reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_SETTINGS_OK) { + for (uint8_t k=0; k0 ? BLINK|INVERS : INVERS) : 0); + + switch (i) { + case ITEM_RECEIVER_SETTINGS_PWM_RATE: + lcdDrawText(MENUS_MARGIN_LEFT, y, isModuleR9MAccess(g_moduleIdx) ? "6.67ms PWM": "9ms PWM"); + reusableBuffer.hardwareAndSettings.receiverSettings.pwmRate = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.pwmRate, RECEIVER_OPTIONS_2ND_COLUMN, y, attr, event); + if (attr && checkIncDec_Ret) { + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; + } + break; + + case ITEM_RECEIVER_SETTINGS_TELEMETRY: + lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TELEMETRY_DISABLED); + reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled, RECEIVER_OPTIONS_2ND_COLUMN, y, attr, event); + if (attr && checkIncDec_Ret) { + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; + } + break; + + case ITEM_RECEIVER_SETTINGS_SPORT_FPORT: + lcdDrawText(MENUS_MARGIN_LEFT, y, "F.Port"); + reusableBuffer.hardwareAndSettings.receiverSettings.fport = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.fport, RECEIVER_OPTIONS_2ND_COLUMN, y, attr, event); + if (attr && checkIncDec_Ret) { + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; + } + break; + + case ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED1: + lcdDrawText(LCD_W/2, y+1, STR_MORE_OPTIONS_AVAILABLE, SMLSIZE|CENTERED); + break; + + case ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED2: + lcdDrawText(LCD_W/2, y+1, STR_OPENTX_UPGRADE_REQUIRED, SMLSIZE|CENTERED); + break; + + default: + // Pin + { + uint8_t pin = i - ITEM_RECEIVER_SETTINGS_PINMAP_FIRST; + if (pin < reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount) { + uint8_t & mapping = reusableBuffer.hardwareAndSettings.receiverSettings.outputsMapping[pin]; + uint8_t channel = g_model.moduleData[g_moduleIdx].channelsStart + mapping; + int32_t channelValue = channelOutputs[channel]; + lcdDrawText(MENUS_MARGIN_LEFT, y, STR_PIN); + lcdDrawNumber(lcdNextPos + 1, y, pin + 1); + putsChn(100, y, channel + 1, attr); + + // Channel + if (attr) { + mapping = checkIncDec(event, mapping, 0, sentModuleChannels(g_moduleIdx) - 1); + if (checkIncDec_Ret) { + reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY; + } + } + + // Bargraph + lcdDrawRect(RECEIVER_OPTIONS_2ND_COLUMN, y + 4, wbar + 1, 10); + const uint8_t lenChannel = limit(1, (abs(channelValue) * wbar / 2 + lim / 2) / lim, wbar / 2); + const coord_t xChannel = (channelValue > 0) ? RECEIVER_OPTIONS_2ND_COLUMN + wbar / 2 : RECEIVER_OPTIONS_2ND_COLUMN + wbar / 2 + 1 - lenChannel; + lcdDrawSolidFilledRect(xChannel, y + 5, lenChannel, 8, TEXT_INVERTED_BGCOLOR); + } + break; + } + } + } + } + else { + lcdDrawCenteredText(LCD_H/2, STR_WAITING_FOR_RX); + } + + return true; +} diff --git a/radio/src/gui/480x272/model_setup.cpp b/radio/src/gui/480x272/model_setup.cpp index 23788b0c0..3f8363beb 100644 --- a/radio/src/gui/480x272/model_setup.cpp +++ b/radio/src/gui/480x272/model_setup.cpp @@ -209,12 +209,13 @@ void onPXX2ReceiverMenu(const char * result) memclear(&reusableBuffer.hardwareAndSettings, sizeof(reusableBuffer.hardwareAndSettings)); reusableBuffer.hardwareAndSettings.receiverSettings.receiverId = receiverIdx; g_moduleIdx = moduleIdx; - // TODO pushMenu(menuModelReceiverOptions); + pushMenu(menuModelReceiverOptions); } else if (result == STR_BIND) { 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/gui/480x272/model_telemetry_sensor.cpp b/radio/src/gui/480x272/model_telemetry_sensor.cpp index 176d0d550..f4d285efb 100644 --- a/radio/src/gui/480x272/model_telemetry_sensor.cpp +++ b/radio/src/gui/480x272/model_telemetry_sensor.cpp @@ -61,7 +61,7 @@ bool menuModelSensor(event_t event) lcdDrawNumber(lcdNextPos, 3, s_currIdx+1, MENU_TITLE_COLOR|LEFT); drawSensorCustomValue(50, 3 + FH, s_currIdx, getValue(MIXSRC_FIRST_TELEM+3*s_currIdx), MENU_TITLE_COLOR|LEFT); - for (uint8_t i=0; i