From 06437b2954dd34a7aa1ab72608e775f3b7dce41e Mon Sep 17 00:00:00 2001 From: bsongis Date: Wed, 29 Oct 2014 07:08:02 +0100 Subject: [PATCH 1/2] Switches configuration + Switches/Pots/Sliders/Sticks custom names --- radio/src/eeprom_conversions.cpp | 207 +++++++++++++++++----- radio/src/gui/menu_general.cpp | 126 +++++++++++-- radio/src/gui/menu_model.cpp | 79 +++++++-- radio/src/gui/menus.cpp | 20 +++ radio/src/gui/menus.h | 2 + radio/src/keys.h | 12 ++ radio/src/lcd_common.cpp | 55 +++++- radio/src/mixer.cpp | 6 + radio/src/myeeprom.h | 82 +++++++-- radio/src/opentx.h | 5 +- radio/src/switches.cpp | 97 ++++++---- radio/src/targets/taranis/keys_driver.cpp | 102 +++++++++-- radio/src/tests/switches.cpp | 5 +- radio/src/translations/en.h.txt | 6 +- 14 files changed, 660 insertions(+), 144 deletions(-) diff --git a/radio/src/eeprom_conversions.cpp b/radio/src/eeprom_conversions.cpp index 0f7785599..71dd0b76b 100644 --- a/radio/src/eeprom_conversions.cpp +++ b/radio/src/eeprom_conversions.cpp @@ -36,6 +36,110 @@ #include "opentx.h" +enum Mix216Sources { + MIXSRC216_NONE, + +#if defined(PCBTARANIS) + MIXSRC216_FIRST_INPUT, + MIXSRC216_LAST_INPUT = MIXSRC216_FIRST_INPUT+MAX_INPUTS-1, + + MIXSRC216_FIRST_LUA, + MIXSRC216_LAST_LUA = MIXSRC216_FIRST_LUA+(MAX_SCRIPTS*MAX_SCRIPT_OUTPUTS)-1, +#endif + + MIXSRC216_Rud, + MIXSRC216_Ele, + MIXSRC216_Thr, + MIXSRC216_Ail, + + MIXSRC216_FIRST_POT, +#if defined(PCBTARANIS) + MIXSRC216_POT1 = MIXSRC216_FIRST_POT, + MIXSRC216_POT2, + MIXSRC216_POT3, + MIXSRC216_SLIDER1, + MIXSRC216_SLIDER2, + MIXSRC216_LAST_POT = MIXSRC216_SLIDER2, +#else + MIXSRC216_P1 = MIXSRC216_FIRST_POT, + MIXSRC216_P2, + MIXSRC216_P3, + MIXSRC216_LAST_POT = MIXSRC216_P3, +#endif + +#if defined(PCBSKY9X) + MIXSRC216_REa, + MIXSRC216_LAST_ROTARY_ENCODER = MIXSRC216_REa, +#endif + + MIXSRC216_MAX, + + MIXSRC216_CYC1, + MIXSRC216_CYC2, + MIXSRC216_CYC3, + + MIXSRC216_TrimRud, + MIXSRC216_TrimEle, + MIXSRC216_TrimThr, + MIXSRC216_TrimAil, + + MIXSRC216_FIRST_SWITCH, + +#if defined(PCBTARANIS) + MIXSRC216_SA = MIXSRC216_FIRST_SWITCH, + MIXSRC216_SB, + MIXSRC216_SC, + MIXSRC216_SD, + MIXSRC216_SE, + MIXSRC216_SF, + MIXSRC216_SG, + MIXSRC216_SH, +#else + MIXSRC216_3POS = MIXSRC216_FIRST_SWITCH, + MIXSRC216_THR, + MIXSRC216_RUD, + MIXSRC216_ELE, + MIXSRC216_AIL, + MIXSRC216_GEA, + MIXSRC216_TRN, +#endif + MIXSRC216_FIRST_LOGICAL_SWITCH, + MIXSRC216_SW1 = MIXSRC216_FIRST_LOGICAL_SWITCH, + MIXSRC216_SW9 = MIXSRC216_SW1 + 8, + MIXSRC216_SWA, + MIXSRC216_SWB, + MIXSRC216_SWC, + MIXSRC216_LAST_LOGICAL_SWITCH = MIXSRC216_FIRST_LOGICAL_SWITCH+NUM_LOGICAL_SWITCH-1, + + MIXSRC216_FIRST_TRAINER, + MIXSRC216_LAST_TRAINER = MIXSRC216_FIRST_TRAINER+NUM_TRAINER-1, + + MIXSRC216_FIRST_CH, + MIXSRC216_CH1 = MIXSRC216_FIRST_CH, + MIXSRC216_CH2, + MIXSRC216_CH3, + MIXSRC216_CH4, + MIXSRC216_CH5, + MIXSRC216_CH6, + MIXSRC216_CH7, + MIXSRC216_CH8, + MIXSRC216_CH9, + MIXSRC216_CH10, + MIXSRC216_CH11, + MIXSRC216_CH12, + MIXSRC216_CH13, + MIXSRC216_CH14, + MIXSRC216_CH15, + MIXSRC216_CH16, + MIXSRC216_LAST_CH = MIXSRC216_CH1+NUM_CHNOUT-1, + + MIXSRC216_GVAR1, + MIXSRC216_LAST_GVAR = MIXSRC216_GVAR1+MAX_GVARS-1, + + MIXSRC216_FIRST_TELEM, +}; + + enum Telemetry216Source { TELEM216_NONE, TELEM216_TX_VOLTAGE, @@ -441,7 +545,7 @@ PACK(typedef struct { int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5ms increments uint8_t thrTraceSrc; - swstate_t switchWarningStates; + swarnstate_t switchWarningState; char gvar_names[5][LEN_GVAR_NAME]; @@ -503,8 +607,8 @@ PACK(typedef struct { AVR_FIELD(int8_t ppmFrameLength) // 0=22.5ms (10ms-30ms) 0.5ms increments uint8_t thrTraceSrc; - swstate_t switchWarningStates; - uint8_t nSwToWarn; + swarnstate_t switchWarningState; + uint8_t switchWarningEnable; global_gvar_t gvars[MAX_GVARS]; @@ -657,17 +761,17 @@ int ConvertSource_215_to_216(int source, bool insertZero=false) if (source > 0) source += MAX_INPUTS + MAX_SCRIPTS*MAX_SCRIPT_OUTPUTS; // S3 added - if (source > MIXSRC_POT2) + if (source > MIXSRC216_POT2) source += 1; // PPM9-PPM16 added - if (source > MIXSRC_FIRST_TRAINER+7) + if (source > MIXSRC216_FIRST_TRAINER+7) source += 8; // 4 GVARS added - if (source > MIXSRC_GVAR1+4) + if (source > MIXSRC216_GVAR1+4) source += 4; // Telemetry conversions - if (source >= MIXSRC_FIRST_TELEM) - source = MIXSRC_FIRST_TELEM + ConvertTelemetrySource_215_to_216(source-MIXSRC_FIRST_TELEM+1) - 1; + if (source >= MIXSRC216_FIRST_TELEM) + source = MIXSRC216_FIRST_TELEM + ConvertTelemetrySource_215_to_216(source-MIXSRC216_FIRST_TELEM+1) - 1; return source; } @@ -695,14 +799,14 @@ int ConvertSource_215_to_216(int source, bool insertZero=false) if (insertZero) source += 1; // PPM9-PPM16 added - if (source > MIXSRC_FIRST_TRAINER+7) + if (source > MIXSRC216_FIRST_TRAINER+7) source += 8; // 4 GVARS added - if (source > MIXSRC_GVAR1+4) + if (source > MIXSRC216_GVAR1+4) source += 4; // Telemetry conversions - if (source >= MIXSRC_FIRST_TELEM) - source = MIXSRC_FIRST_TELEM + ConvertTelemetrySource_215_to_216(source-MIXSRC_FIRST_TELEM+1) - 1; + if (source >= MIXSRC216_FIRST_TELEM) + source = MIXSRC216_FIRST_TELEM + ConvertTelemetrySource_215_to_216(source-MIXSRC216_FIRST_TELEM+1) - 1; return source; } @@ -724,8 +828,31 @@ int ConvertSwitch_215_to_216(int swtch) } #endif +#if defined(PCBTARANIS) +int ConvertSwitch_216_to_217(int swtch) +{ + if (swtch < 0) + return -ConvertSwitch_216_to_217(-swtch); + + if (swtch >= SWSRC_SI0) + swtch += 12; + + return swtch; +} +#else +int ConvertSwitch_216_to_217(int swtch) +{ + return swtch; +} +#endif + int ConvertSource_216_to_217(int source) { +#if defined(PCBTARANIS) + // SI to SN switches added + if (source >= MIXSRC_SI) + source += 6; +#endif // Telemetry conversions if (source >= MIXSRC_FIRST_TELEM) source = 0; @@ -882,7 +1009,7 @@ void ConvertModel_215_to_216(ModelData &model) for (uint8_t j=chn+1; jsrcRaw = MIXSRC_Rud+chn; + expo->srcRaw = MIXSRC216_Rud+chn; expo->chn = chn; expo->mode = oldExpo->mode; expo->swtch = ConvertSwitch_215_to_216(oldExpo->swtch); @@ -925,7 +1052,7 @@ void ConvertModel_215_to_216(ModelData &model) ExpoData_v216 * expo = &newModel.expoData[idx]; memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData_v216)); memclear(expo, sizeof(ExpoData_v216)); - expo->srcRaw = MIXSRC_Rud + i; + expo->srcRaw = MIXSRC216_Rud + i; expo->chn = i; expo->weight = 100; expo->curve.type = CURVE_REF_EXPO; @@ -974,41 +1101,41 @@ void ConvertModel_215_to_216(ModelData &model) else if (cstate == LS_FAMILY_OFS || cstate == LS_FAMILY_COMP || cstate == LS_FAMILY_DIFF) { sw.v1 = ConvertSource_215_to_216(sw.v1); if (cstate == LS_FAMILY_OFS || cstate == LS_FAMILY_DIFF) { - if ((uint8_t)sw.v1 >= MIXSRC_FIRST_TELEM) { + if ((uint8_t)sw.v1 >= MIXSRC216_FIRST_TELEM) { switch ((uint8_t)sw.v1) { - case MIXSRC_FIRST_TELEM + TELEM216_TIMER1-1: - case MIXSRC_FIRST_TELEM + TELEM216_TIMER2-1: + case MIXSRC216_FIRST_TELEM + TELEM216_TIMER1-1: + case MIXSRC216_FIRST_TELEM + TELEM216_TIMER2-1: sw.v2 = (sw.v2+128) * 3; break; - case MIXSRC_FIRST_TELEM + TELEM216_ALT-1: - case MIXSRC_FIRST_TELEM + TELEM216_GPSALT-1: - case MIXSRC_FIRST_TELEM + TELEM216_MIN_ALT-1: - case MIXSRC_FIRST_TELEM + TELEM216_MAX_ALT-1: + case MIXSRC216_FIRST_TELEM + TELEM216_ALT-1: + case MIXSRC216_FIRST_TELEM + TELEM216_GPSALT-1: + case MIXSRC216_FIRST_TELEM + TELEM216_MIN_ALT-1: + case MIXSRC216_FIRST_TELEM + TELEM216_MAX_ALT-1: sw.v2 = (sw.v2+128) * 8 - 500; break; - case MIXSRC_FIRST_TELEM + TELEM216_RPM-1: - case MIXSRC_FIRST_TELEM + TELEM216_MAX_RPM-1: + case MIXSRC216_FIRST_TELEM + TELEM216_RPM-1: + case MIXSRC216_FIRST_TELEM + TELEM216_MAX_RPM-1: sw.v2 = (sw.v2+128) * 50; break; - case MIXSRC_FIRST_TELEM + TELEM216_T1-1: - case MIXSRC_FIRST_TELEM + TELEM216_T2-1: - case MIXSRC_FIRST_TELEM + TELEM216_MAX_T1-1: - case MIXSRC_FIRST_TELEM + TELEM216_MAX_T2-1: + case MIXSRC216_FIRST_TELEM + TELEM216_T1-1: + case MIXSRC216_FIRST_TELEM + TELEM216_T2-1: + case MIXSRC216_FIRST_TELEM + TELEM216_MAX_T1-1: + case MIXSRC216_FIRST_TELEM + TELEM216_MAX_T2-1: sw.v2 = (sw.v2+128) + 30; break; - case MIXSRC_FIRST_TELEM + TELEM216_CELL-1: - case MIXSRC_FIRST_TELEM + TELEM216_HDG-1: + case MIXSRC216_FIRST_TELEM + TELEM216_CELL-1: + case MIXSRC216_FIRST_TELEM + TELEM216_HDG-1: sw.v2 = (sw.v2+128) * 2; break; - case MIXSRC_FIRST_TELEM + TELEM216_DIST-1: - case MIXSRC_FIRST_TELEM + TELEM216_MAX_DIST-1: + case MIXSRC216_FIRST_TELEM + TELEM216_DIST-1: + case MIXSRC216_FIRST_TELEM + TELEM216_MAX_DIST-1: sw.v2 = (sw.v2+128) * 8; break; - case MIXSRC_FIRST_TELEM + TELEM216_CURRENT-1: - case MIXSRC_FIRST_TELEM + TELEM216_POWER-1: + case MIXSRC216_FIRST_TELEM + TELEM216_CURRENT-1: + case MIXSRC216_FIRST_TELEM + TELEM216_POWER-1: sw.v2 = (sw.v2+128) * 5; break; - case MIXSRC_FIRST_TELEM + TELEM216_CONSUMPTION-1: + case MIXSRC216_FIRST_TELEM + TELEM216_CONSUMPTION-1: sw.v2 = (sw.v2+128) * 20; break; default: @@ -1127,8 +1254,8 @@ void ConvertModel_215_to_216(ModelData &model) if (newModel.thrTraceSrc >= THROTTLE_SOURCE_S3) newModel.thrTraceSrc += 1; #endif - newModel.switchWarningStates = oldModel.switchWarningStates >> 1; - newModel.nSwToWarn = (oldModel.switchWarningStates & 0x01) ? 0xFF : 0; + newModel.switchWarningState = oldModel.switchWarningState >> 1; + newModel.switchWarningEnable = (oldModel.switchWarningState & 0x01) ? 0xFF : 0; for (uint8_t i=0; i<5; i++) { memcpy(newModel.gvars[i].name, oldModel.gvar_names[i], LEN_GVAR_NAME); } @@ -1223,7 +1350,7 @@ void ConvertModel_216_to_217(ModelData &model) newModel.mixData[i].carryTrim = oldModel.mixData[i].carryTrim; newModel.mixData[i].mixWarn = oldModel.mixData[i].mixWarn; newModel.mixData[i].weight = ConvertGVar_216_to_217(oldModel.mixData[i].weight); - newModel.mixData[i].swtch = oldModel.mixData[i].swtch; + newModel.mixData[i].swtch = ConvertSwitch_216_to_217(oldModel.mixData[i].swtch); #if defined(PCBTARANIS) newModel.mixData[i].curve = oldModel.mixData[i].curve; #else @@ -1265,7 +1392,7 @@ void ConvertModel_216_to_217(ModelData &model) newModel.expoData[i].curveParam = oldModel.expoData[i].curveParam; #endif newModel.expoData[i].chn = oldModel.expoData[i].chn; - newModel.expoData[i].swtch = oldModel.expoData[i].swtch; + newModel.expoData[i].swtch = ConvertSwitch_216_to_217(oldModel.expoData[i].swtch); newModel.expoData[i].flightModes = oldModel.expoData[i].flightModes; newModel.expoData[i].weight = oldModel.expoData[i].weight; newModel.expoData[i].mode = oldModel.expoData[i].mode; @@ -1302,8 +1429,8 @@ void ConvertModel_216_to_217(ModelData &model) memcpy(newModel.flightModeData, oldModel.flightModeData, sizeof(newModel.flightModeData)); newModel.thrTraceSrc = oldModel.thrTraceSrc; - newModel.switchWarningStates = oldModel.switchWarningStates; - newModel.nSwToWarn = oldModel.nSwToWarn; + newModel.switchWarningState = oldModel.switchWarningState; + newModel.switchWarningEnable = oldModel.switchWarningEnable; memcpy(newModel.gvars, oldModel.gvars, sizeof(newModel.gvars)); memcpy(&newModel.frsky.rssiAlarms, &oldModel.frsky.rssiAlarms, sizeof(newModel.frsky.rssiAlarms)); diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index 95f0694e1..7375b10d2 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -563,7 +563,7 @@ void menuGeneralSetup(uint8_t event) lcd_putc(lcdLastPos, y, 's'); } else { - lcd_putsiAtt(RADIO_SETUP_2ND_COLUMN, y, STR_MMMINV, 0, attr); + lcd_putsiAtt(RADIO_SETUP_2ND_COLUMN, y, STR_MMMINV, 0, attr); // TODO define } if (attr) g_eeGeneral.splashMode = -checkIncDecGen(event, -g_eeGeneral.splashMode, -3, 4); #else @@ -1362,50 +1362,148 @@ void menuGeneralDiagAna(uint8_t event) #if defined(PCBTARANIS) enum menuGeneralHwItems { + ITEM_SETUP_HW_LABEL_STICKS, + ITEM_SETUP_HW_STICK1, + ITEM_SETUP_HW_STICK2, + ITEM_SETUP_HW_STICK3, + ITEM_SETUP_HW_STICK4, + ITEM_SETUP_HW_LABEL_POTS, ITEM_SETUP_HW_POT1, ITEM_SETUP_HW_POT2, CASE_REVPLUS(ITEM_SETUP_HW_POT3) + ITEM_SETUP_HW_LS, + ITEM_SETUP_HW_RS, + ITEM_SETUP_HW_LABEL_SWITCHES, + ITEM_SETUP_HW_SA, + ITEM_SETUP_HW_SB, + ITEM_SETUP_HW_SC, + ITEM_SETUP_HW_SD, + ITEM_SETUP_HW_SE, + ITEM_SETUP_HW_SF, + ITEM_SETUP_HW_SG, + ITEM_SETUP_HW_SH, + ITEM_SETUP_HW_SI, + ITEM_SETUP_HW_SJ, + ITEM_SETUP_HW_SK, + ITEM_SETUP_HW_SL, + ITEM_SETUP_HW_SM, + ITEM_SETUP_HW_SN, ITEM_SETUP_HW_UART3_MODE, ITEM_SETUP_HW_MAX }; #define HW_SETTINGS_COLUMN 15*FW +#if defined(REVPLUS) + #define POTS_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, 0, 0 +#else + #define POTS_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, 0, 0 +#endif + +#define SWITCH_ROWS(x) uint8_t(IS_2x2POS(x) ? 0 : HIDDEN_ROW) + void menuGeneralHardware(uint8_t event) { - MENU(STR_HARDWARE, menuTabGeneral, e_Hardware, ITEM_SETUP_HW_MAX+1, {0}); + MENU(STR_HARDWARE, menuTabGeneral, e_Hardware, ITEM_SETUP_HW_MAX+1, {0, LABEL(Sticks), 0, 0, 0, 0, LABEL(Pots), POTS_ROWS, LABEL(Switches), NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, SWITCH_ROWS(0), SWITCH_ROWS(1), SWITCH_ROWS(2), SWITCH_ROWS(3), SWITCH_ROWS(4), SWITCH_ROWS(6), 0}); uint8_t sub = m_posVert - 1; - - for (uint8_t i=0; i0) ? BLINK|INVERS : INVERS) : 0); - switch(i) { + uint8_t k = i + s_pgOfs; + for (int j=0; j<=k; j++) { + if (mstate_tab[j+1] == HIDDEN_ROW) + k++; + } + uint8_t attr = (sub == k ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0); + switch (k) { + case ITEM_SETUP_HW_LABEL_STICKS: + lcd_putsLeft(y, "Sticks"); + break; + case ITEM_SETUP_HW_STICK1: + case ITEM_SETUP_HW_STICK2: + case ITEM_SETUP_HW_STICK3: + case ITEM_SETUP_HW_STICK4: + case ITEM_SETUP_HW_LS: + case ITEM_SETUP_HW_RS: + { + int idx = (k<=ITEM_SETUP_HW_STICK4 ? k-ITEM_SETUP_HW_STICK1 : k-ITEM_SETUP_HW_LS+7); + lcd_putsiAtt(INDENT_WIDTH, y, STR_VSRCRAW, idx+1, 0); + if (ZEXIST(g_eeGeneral.anaNames[idx]) || attr) + editName(HW_SETTINGS_COLUMN, y, g_eeGeneral.anaNames[idx], LEN_ANA_NAME, event, attr); + else + lcd_putsiAtt(HW_SETTINGS_COLUMN, y, STR_MMMINV, 0, 0); + break; + } + case ITEM_SETUP_HW_LABEL_POTS: + lcd_putsLeft(y, "Pots"); + break; case ITEM_SETUP_HW_POT1: case ITEM_SETUP_HW_POT2: #if defined(REVPLUS) case ITEM_SETUP_HW_POT3: #endif { - int idx = i - ITEM_SETUP_HW_POT1; + int idx = k - ITEM_SETUP_HW_POT1; uint8_t shift = (2*idx); uint8_t mask = (0x03 << shift); - putsMixerSource(sizeof(TR_TYPE)*FW, y, MIXSRC_FIRST_POT+idx); + lcd_putsiAtt(INDENT_WIDTH, y, STR_VSRCRAW, NUM_STICKS+idx+1, m_posHorz < 0 ? attr : 0); + if (ZEXIST(g_eeGeneral.anaNames[NUM_STICKS+idx]) || (attr && m_posHorz == 0)) + editName(HW_SETTINGS_COLUMN, y, g_eeGeneral.anaNames[NUM_STICKS+idx], LEN_ANA_NAME, event, attr && m_posHorz == 0); + else + lcd_putsiAtt(HW_SETTINGS_COLUMN, y, STR_MMMINV, 0, 0); + uint8_t potType = (g_eeGeneral.potsType & mask) >> shift; - if (potType == POT_TYPE_NONE && i < 2) + if (potType == POT_TYPE_NONE && k <= ITEM_SETUP_HW_POT2) potType = POT_TYPE_DETENT; - potType = selectMenuItem(HW_SETTINGS_COLUMN, y, STR_TYPE, STR_POTTYPES, potType, 0, POT_TYPE_MAX, attr, event); - if (potType == POT_TYPE_DETENT && i < 2) + potType = selectMenuItem(HW_SETTINGS_COLUMN+5*FW, y, "", STR_POTTYPES, potType, 0, POT_TYPE_MAX, m_posHorz == 1 ? attr : 0, event); + if (potType == POT_TYPE_DETENT && k <= ITEM_SETUP_HW_POT2) potType = POT_TYPE_NONE; g_eeGeneral.potsType &= ~mask; g_eeGeneral.potsType |= (potType << shift); break; } + case ITEM_SETUP_HW_LABEL_SWITCHES: + lcd_putsLeft(y, "Switches"); + break; + case ITEM_SETUP_HW_SA: + case ITEM_SETUP_HW_SB: + case ITEM_SETUP_HW_SC: + case ITEM_SETUP_HW_SD: + case ITEM_SETUP_HW_SE: + case ITEM_SETUP_HW_SF: + case ITEM_SETUP_HW_SG: + case ITEM_SETUP_HW_SH: + case ITEM_SETUP_HW_SI: + case ITEM_SETUP_HW_SJ: + case ITEM_SETUP_HW_SK: + case ITEM_SETUP_HW_SL: + case ITEM_SETUP_HW_SM: + case ITEM_SETUP_HW_SN: + { + int index = k-ITEM_SETUP_HW_SA; + char label[] = INDENT "S*"; + label[2] = 'A' + index; + uint32_t config = SWITCH_CONFIG(index); + lcd_putsAtt(0, y, label, m_posHorz < 0 ? attr : 0); + if (ZEXIST(g_eeGeneral.switchNames[index]) || (attr && m_posHorz == 0)) + editName(HW_SETTINGS_COLUMN, y, g_eeGeneral.switchNames[index], LEN_SWITCH_NAME, event, m_posHorz == 0 ? attr : 0); + else + lcd_putsiAtt(HW_SETTINGS_COLUMN, y, STR_MMMINV, 0, 0); + if (k <= ITEM_SETUP_HW_SH) { + config = selectMenuItem(HW_SETTINGS_COLUMN+5*FW, y, "", "\007DefaultToggle\0""2POS\0 3POS\0 2x2POS\0", config, 0, 4, m_posHorz == 1 ? attr : 0, event); + if (attr && checkIncDec_Ret) { + uint32_t mask = 0x0f << (4*index); + g_eeGeneral.switchConfig = (g_eeGeneral.switchConfig & ~mask) | (config << (4*index)); + } + } + break; + } case ITEM_SETUP_HW_UART3_MODE: - g_eeGeneral.uart3Mode = selectMenuItem(HW_SETTINGS_COLUMN, y, STR_UART3MODE, STR_UART3MODES, g_eeGeneral.uart3Mode, 0, UART_MODE_MAX, attr, event); + g_eeGeneral.uart3Mode = selectMenuItem(HW_SETTINGS_COLUMN, y, STR_UART3MODE, STR_UART3MODES, g_eeGeneral.uart3Mode, 0, UART_MODE_MAX, attr, event); if (attr && checkIncDec_Ret) { - uart3Init(g_eeGeneral.uart3Mode, MODEL_TELEMETRY_PROTOCOL()); - } + uart3Init(g_eeGeneral.uart3Mode, MODEL_TELEMETRY_PROTOCOL()); + } break; } } diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 791b6cac5..16767f450 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -850,7 +850,11 @@ void editName(coord_t x, coord_t y, char *name, uint8_t size, uint8_t event, uin if (c != v) { name[cur] = v; +#if defined(PCBTARANIS) + eeDirty(g_menuPos[0] == 0 ? EE_MODEL : EE_GENERAL); +#else eeDirty(EE_MODEL); +#endif } lcd_putcAtt(x+editNameCursorPos*FW, y, idx2char(v), ERASEBG|INVERS|FIXEDWIDTH); @@ -901,6 +905,7 @@ enum menuModelSetupItems { CASE_CPUARM(ITEM_MODEL_CHECKLIST_DISPLAY) ITEM_MODEL_THROTTLE_WARNING, ITEM_MODEL_SWITCHES_WARNING, + CASE_PCBTARANIS(ITEM_MODEL_SWITCHES_WARNING2) CASE_PCBTARANIS(ITEM_MODEL_POT_WARNING) ITEM_MODEL_BEEP_CENTER, CASE_CPUARM(ITEM_MODEL_USE_GLOBAL_FUNCTIONS) @@ -993,6 +998,7 @@ void onModelSetupBitmapMenu(const char *result) void menuModelSetup(uint8_t event) { #if defined(PCBTARANIS) + horzpos_t l_posHorz = m_posHorz; #define IF_INTERNAL_MODULE_ON(x) (g_model.moduleData[INTERNAL_MODULE].rfProtocol == RF_PROTO_OFF ? HIDDEN_ROW : (uint8_t)(x)) #define IF_EXTERNAL_MODULE_ON(x) (g_model.externalModule == MODULE_TYPE_NONE ? HIDDEN_ROW : (uint8_t)(x)) #define IF_TRAINER_ON(x) (g_model.trainerMode == TRAINER_MODE_SLAVE ? (uint8_t)(x) : HIDDEN_ROW) @@ -1007,7 +1013,7 @@ void menuModelSetup(uint8_t event) #define POT_WARN_ITEMS() ((g_model.nPotsToWarn >> 6) ? (uint8_t)NUM_POTS : (uint8_t)0) #define TIMER_ROWS 2, 0, CASE_PERSISTENT_TIMERS(0) 0, 0 bool CURSOR_ON_CELL = (m_posHorz >= 0); - MENU_TAB({ 0, 0, CASE_PCBTARANIS(0) TIMER_ROWS, TIMER_ROWS, TIMER_ROWS, 0, 1, 0, CASE_PCBTARANIS(LABEL(Throttle)) 0, 0, 0, CASE_CPUARM(LABEL(PreflightCheck)) CASE_CPUARM(0) 0, 7, POT_WARN_ITEMS(), NAVIGATION_LINE_BY_LINE|(NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS-1), 0, LABEL(InternalModule), 0, IF_INTERNAL_MODULE_ON(1), IF_INTERNAL_MODULE_ON(IS_D8_RX(0) ? (uint8_t)1 : (uint8_t)2), IF_INTERNAL_MODULE_ON(FAILSAFE_ROWS(INTERNAL_MODULE)), LABEL(ExternalModule), (IS_MODULE_XJT(EXTERNAL_MODULE) || IS_MODULE_DSM2(EXTERNAL_MODULE)) ? (uint8_t)1 : (uint8_t)0, EXTERNAL_MODULE_CHANNELS_ROWS(), (IS_MODULE_XJT(EXTERNAL_MODULE) && IS_D8_RX(EXTERNAL_MODULE)) ? (uint8_t)1 : (IS_MODULE_PPM(EXTERNAL_MODULE) || IS_MODULE_XJT(EXTERNAL_MODULE) || IS_MODULE_DSM2(EXTERNAL_MODULE)) ? (uint8_t)2 : HIDDEN_ROW, IF_EXTERNAL_MODULE_XJT(FAILSAFE_ROWS(EXTERNAL_MODULE)), LABEL(Trainer), 0, TRAINER_CHANNELS_ROWS(), IF_TRAINER_ON(2)}); + MENU_TAB({ 0, 0, CASE_PCBTARANIS(0) TIMER_ROWS, TIMER_ROWS, TIMER_ROWS, 0, 1, 0, CASE_PCBTARANIS(LABEL(Throttle)) 0, 0, 0, CASE_CPUARM(LABEL(PreflightCheck)) CASE_CPUARM(0) 0, uint8_t(NAVIGATION_LINE_BY_LINE|getSwitchWarningsAllowed()), ONE_2x2POS_DEFINED() ? TITLE_ROW : HIDDEN_ROW, POT_WARN_ITEMS(), NAVIGATION_LINE_BY_LINE|(NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS-1), 0, LABEL(InternalModule), 0, IF_INTERNAL_MODULE_ON(1), IF_INTERNAL_MODULE_ON(IS_D8_RX(0) ? (uint8_t)1 : (uint8_t)2), IF_INTERNAL_MODULE_ON(FAILSAFE_ROWS(INTERNAL_MODULE)), LABEL(ExternalModule), (IS_MODULE_XJT(EXTERNAL_MODULE) || IS_MODULE_DSM2(EXTERNAL_MODULE)) ? (uint8_t)1 : (uint8_t)0, EXTERNAL_MODULE_CHANNELS_ROWS(), (IS_MODULE_XJT(EXTERNAL_MODULE) && IS_D8_RX(EXTERNAL_MODULE)) ? (uint8_t)1 : (IS_MODULE_PPM(EXTERNAL_MODULE) || IS_MODULE_XJT(EXTERNAL_MODULE) || IS_MODULE_DSM2(EXTERNAL_MODULE)) ? (uint8_t)2 : HIDDEN_ROW, IF_EXTERNAL_MODULE_XJT(FAILSAFE_ROWS(EXTERNAL_MODULE)), LABEL(Trainer), 0, TRAINER_CHANNELS_ROWS(), IF_TRAINER_ON(2)}); #elif defined(CPUARM) #define IF_EXTERNAL_MODULE_XJT(x) (IS_MODULE_XJT(EXTERNAL_MODULE) ? (uint8_t)x : HIDDEN_ROW) #define IF_EXTERNAL_MODULE_ON(x) (g_model.externalModule == MODULE_TYPE_NONE ? HIDDEN_ROW : (uint8_t)(x)) @@ -1286,11 +1292,25 @@ void menuModelSetup(uint8_t event) case ITEM_MODEL_THROTTLE_WARNING: g_model.disableThrottleWarning = !onoffMenuItem(!g_model.disableThrottleWarning, MODEL_SETUP_2ND_COLUMN, y, STR_THROTTLEWARNING, attr, event); break; - + +#if defined(PCBTARANIS) + // TODO something more generic + case ITEM_MODEL_SWITCHES_WARNING2: + if (i==0) s_pgOfs++; + break; +#endif + case ITEM_MODEL_SWITCHES_WARNING: +#if defined(PCBTARANIS) + // TODO something more generic + if (i==LCD_LINES-2) { + s_pgOfs++; + break; + } +#endif { lcd_putsLeft(y, STR_SWITCHWARNING); - swstate_t states = g_model.switchWarningStates; + swarnstate_t states = g_model.switchWarningState; char c; if (attr) { s_editMode = 0; @@ -1299,11 +1319,11 @@ void menuModelSetup(uint8_t event) CASE_EVT_ROTARY_BREAK case EVT_KEY_BREAK(KEY_ENTER): #if defined(CPUM64) - g_model.nSwToWarn ^= (1 << m_posHorz); + g_model.switchWarningEnable ^= (1 << m_posHorz); eeDirty(EE_MODEL); -#else +#elif !defined(PCBTARANIS) if (m_posHorz < NUM_SWITCHES-1) { - g_model.nSwToWarn ^= (1 << m_posHorz); + g_model.switchWarningEnable ^= (1 << m_posHorz); eeDirty(EE_MODEL); } #endif @@ -1312,14 +1332,22 @@ void menuModelSetup(uint8_t event) case EVT_KEY_LONG(KEY_ENTER): #if defined(CPUM64) getMovedSwitch(); - g_model.switchWarningStates = switches_states; + g_model.switchWarningState = switches_states; AUDIO_WARNING1(); eeDirty(EE_MODEL); +#elif defined(PCBTARANIS) + if (m_posHorz < 0) { + s_noHi = NO_HI_LEN; + getMovedSwitch(); + g_model.switchWarningState = switches_states; + AUDIO_WARNING1(); + eeDirty(EE_MODEL); + } #else if (m_posHorz == NUM_SWITCHES-1) { s_noHi = NO_HI_LEN; getMovedSwitch(); - g_model.switchWarningStates = switches_states; + g_model.switchWarningState = switches_states; AUDIO_WARNING1(); eeDirty(EE_MODEL); } @@ -1332,15 +1360,28 @@ void menuModelSetup(uint8_t event) LcdFlags line = attr; - for (uint8_t i=0; i>= 2; + } + if (attr && m_posHorz < 0) { + lcd_filled_rect(MODEL_SETUP_2ND_COLUMN-1, y-1, 8*(2*FW+1), ONE_2x2POS_DEFINED() ? 2*FH+1 : FH+1); + } #else + for (uint8_t i=0; i=MIXSRC_SI && source<=MIXSRC_SN) { + if (!IS_2x2POS(source-MIXSRC_SI)) { + return false; + } + } +#endif + if (source>=MIXSRC_SW1 && source<=MIXSRC_LAST_LOGICAL_SWITCH) { LogicalSwitchData * cs = lswAddress(source-MIXSRC_SW1); return (cs->func != LS_FUNC_NONE); @@ -1487,6 +1495,18 @@ bool isSwitchAvailable(int swtch, SwitchContext context) swtch = -swtch; } +#if defined(PCBTARANIS) + if (swtch == SWSRC_SA1 || swtch == SWSRC_SB1 || swtch == SWSRC_SC1 || swtch == SWSRC_SD1 || swtch == SWSRC_SE1 || swtch == SWSRC_SG1) { + return IS_3POS((swtch-SWSRC_SA0)/3); + } + if (swtch >= SWSRC_SI0 && swtch <= SWSRC_SM2) { + return IS_2x2POS((swtch-SWSRC_SI0)/2); + } + if (swtch >= SWSRC_SN0 && swtch <= SWSRC_SN2) { + return IS_2x2POS(6); + } +#endif + #if defined(PCBTARANIS) if (swtch >= SWSRC_FIRST_MULTIPOS_SWITCH && swtch <= SWSRC_LAST_MULTIPOS_SWITCH) { int index = (swtch - SWSRC_FIRST_MULTIPOS_SWITCH) / XPOTS_MULTIPOS_COUNT; diff --git a/radio/src/gui/menus.h b/radio/src/gui/menus.h index e6d54ebd3..49fe6189a 100644 --- a/radio/src/gui/menus.h +++ b/radio/src/gui/menus.h @@ -367,6 +367,8 @@ int8_t switchMenuItem(coord_t x, coord_t y, int8_t value, LcdFlags attr, uint8_t #define displayGVar(x, y, v, min, max) lcd_outdez8(x, y, v) #endif +void editName(coord_t x, coord_t y, char *name, uint8_t size, uint8_t event, uint8_t active); + #define WARNING_TYPE_ASTERISK 0 #define WARNING_TYPE_CONFIRM 1 #define WARNING_TYPE_INPUT 2 diff --git a/radio/src/keys.h b/radio/src/keys.h index e468aa507..11a87a29e 100644 --- a/radio/src/keys.h +++ b/radio/src/keys.h @@ -95,6 +95,18 @@ enum EnumKeys { SW_SG2, SW_SH0, SW_SH2, + SW_SI0, + SW_SI2, + SW_SJ0, + SW_SJ2, + SW_SK0, + SW_SK2, + SW_SL0, + SW_SL2, + SW_SM0, + SW_SM2, + SW_SN0, + SW_SN2, #else SW_ID0=SW_BASE, SW_ID1, diff --git a/radio/src/lcd_common.cpp b/radio/src/lcd_common.cpp index a6133a6fd..d599175fc 100644 --- a/radio/src/lcd_common.cpp +++ b/radio/src/lcd_common.cpp @@ -730,6 +730,20 @@ void putsMixerSource(coord_t x, coord_t y, uint8_t idx, LcdFlags att) #endif #if defined(PCBTARANIS) + else if (idx < MIXSRC_LAST_POT) { + idx = idx-MIXSRC_Rud; + if (ZEXIST(g_eeGeneral.anaNames[idx])) + lcd_putsnAtt(x, y, g_eeGeneral.anaNames[idx], LEN_ANA_NAME, ZCHAR|att); + else + lcd_putsiAtt(x, y, STR_VSRCRAW, idx+1, att); + } + else if (idx >= MIXSRC_FIRST_SWITCH && idx < MIXSRC_FIRST_LOGICAL_SWITCH) { + idx = idx-MIXSRC_FIRST_SWITCH; + if (ZEXIST(g_eeGeneral.switchNames[idx])) + lcd_putsnAtt(x, y, g_eeGeneral.switchNames[idx], LEN_SWITCH_NAME, ZCHAR|att); + else + lcd_putsiAtt(x, y, STR_VSRCRAW, idx+MIXSRC_FIRST_SWITCH-MIXSRC_Rud+1, att); + } else if (idx < MIXSRC_SW1) lcd_putsiAtt(x, y, STR_VSRCRAW, idx-MIXSRC_Rud+1, att); #else @@ -794,6 +808,28 @@ void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att) } } +#if defined(PCBTARANIS) +div_t switchInfo(int switchPosition) +{ + if (switchPosition <= SWSRC_SE2) { + return div(switchPosition-SWSRC_SA0, 3); + } + else if (switchPosition <= SWSRC_SF2) { + div_t qr = { 5, switchPosition == SWSRC_SF2 ? 2 : 0 }; + return qr; + } + else if (switchPosition <= SWSRC_SG2) { + div_t qr = { 6, switchPosition-SWSRC_SG0 }; + return qr; + } + else { + div_t qr = div(2*7+switchPosition-SWSRC_SH0, 2); + qr.rem *= 2; + return qr; + } +} +#endif + void putsSwitches(coord_t x, coord_t y, int8_t idx, LcdFlags att) { if (idx == SWSRC_OFF) @@ -803,11 +839,22 @@ void putsSwitches(coord_t x, coord_t y, int8_t idx, LcdFlags att) idx = -idx; } #if defined(CPUARM) && defined(FLIGHT_MODES) - if (idx >= SWSRC_FIRST_FLIGHT_MODE) - putsStrIdx(x, y, STR_FP, idx-SWSRC_FIRST_FLIGHT_MODE, att); - else + if (idx >= SWSRC_FIRST_FLIGHT_MODE) { + return putsStrIdx(x, y, STR_FP, idx-SWSRC_FIRST_FLIGHT_MODE, att); + } #endif - lcd_putsiAtt(x, y, STR_VSWITCHES, idx, att); +#if defined(PCBTARANIS) + if (idx >= SWSRC_SA0 && idx <= SWSRC_SN2) { + div_t swinfo = switchInfo(idx); + if (ZEXIST(g_eeGeneral.switchNames[swinfo.quot])) { + lcd_putsnAtt(x, y, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME, ZCHAR|att); + char c = "\300-\301"[swinfo.rem]; + lcd_putcAtt(lcdNextPos, y, c, att); + return; + } + } +#endif + return lcd_putsiAtt(x, y, STR_VSWITCHES, idx, att); } #if defined(FLIGHT_MODES) diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index ebff34106..06bb62ac7 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -310,6 +310,12 @@ getvalue_t getValue(mixsrc_t i) else if (i==MIXSRC_SF) return (switchState(SW_SF0) ? -1024 : 1024); else if (i==MIXSRC_SG) return (switchState(SW_SG0) ? -1024 : (switchState(SW_SG1) ? 0 : 1024)); else if (i==MIXSRC_SH) return (switchState(SW_SH0) ? -1024 : 1024); + else if (i==MIXSRC_SI) return (switchState(SW_SI0) ? -1024 : 1024); + else if (i==MIXSRC_SJ) return (switchState(SW_SJ0) ? -1024 : 1024); + else if (i==MIXSRC_SK) return (switchState(SW_SK0) ? -1024 : 1024); + else if (i==MIXSRC_SL) return (switchState(SW_SL0) ? -1024 : 1024); + else if (i==MIXSRC_SM) return (switchState(SW_SM0) ? -1024 : 1024); + else if (i==MIXSRC_SN) return (switchState(SW_SN0) ? -1024 : 1024); #else else if (i==MIXSRC_3POS) return (getSwitch(SW_ID0-SW_BASE+1) ? -1024 : (getSwitch(SW_ID1-SW_BASE+1) ? 0 : 1024)); // don't use switchState directly to give getSwitch possibility to hack values if needed for switch warning diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 062f9cad7..2ed72a5b8 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -377,7 +377,8 @@ PACK(typedef struct { #define IS_TRAINER_EXTERNAL_MODULE() (g_model.trainerMode == TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE || g_model.trainerMode == TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE) #define MODELDATA_BITMAP char bitmap[LEN_BITMAP_NAME]; #define MODELDATA_EXTRA uint8_t externalModule; uint8_t trainerMode; ModuleData moduleData[NUM_MODULES+1]; char curveNames[MAX_CURVES][6]; ScriptData scriptsData[MAX_SCRIPTS]; char inputNames[MAX_INPUTS][LEN_INPUT_NAME]; uint8_t nPotsToWarn; int8_t potPosition[NUM_POTS]; - #define swstate_t uint16_t + #define swarnstate_t uint32_t + #define swarnenable_t uint16_t #elif defined(PCBSKY9X) enum ModuleIndex { EXTERNAL_MODULE, @@ -386,11 +387,13 @@ PACK(typedef struct { }; #define MODELDATA_BITMAP #define MODELDATA_EXTRA uint8_t externalModule; ModuleData moduleData[NUM_MODULES+1]; uint8_t nPotsToWarn; int8_t potPosition[NUM_POTS]; uint8_t rxBattAlarms[2]; - #define swstate_t uint8_t + #define swarnstate_t uint8_t + #define swarnenable_t uint8_t #else #define MODELDATA_BITMAP #define MODELDATA_EXTRA - #define swstate_t uint8_t + #define swarnstate_t uint8_t + #define swarnenable_t uint8_t #endif enum BacklightMode { @@ -609,6 +612,16 @@ PACK(typedef struct { #define CFN_GVAR_CST_MAX 125 #endif +enum SwitchConfig { + SWITCH_DEFAULT, + SWITCH_TOGGLE, + SWITCH_2POS, + SWITCH_3POS, + SWITCH_2x2POS +}; + +#define LEN_SWITCH_NAME 3 +#define LEN_ANA_NAME 3 #if defined(PCBSTD) #define N_PCBSTD_FIELD(x) @@ -668,16 +681,43 @@ PACK(typedef struct t_EEGeneral { EXTRA_GENERAL_FIELDS - ARM_FIELD(swstate_t switchUnlockStates) + ARM_FIELD(swarnstate_t switchUnlockStates) ARM_FIELD(CustomFunctionData customFn[NUM_CFN]) + ARM_FIELD(uint32_t switchConfig) + + ARM_FIELD(char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]) + + ARM_FIELD(char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]) + }) EEGeneral; #define SWITCHES_DELAY() uint8_t(15+g_eeGeneral.switchesDelay) #define SWITCHES_DELAY_NONE (-15) #define HAPTIC_STRENGTH() (3+g_eeGeneral.hapticStrength) +#if defined(PCBTARANIS) +#define SWITCH_CONFIG(x) ((g_eeGeneral.switchConfig >> (4*(x))) & 0x0f) +#define SWITCH_DEFAULT_CONFIG(x) ((x)==5 ? SWITCH_2POS : ((x)==7 ? SWITCH_TOGGLE : SWITCH_3POS)) +int switchConfig(int idx); +#define IS_3POS(x) (switchConfig(x) == SWITCH_3POS) +#define IS_2x2POS(x) (switchConfig(x) == SWITCH_2x2POS) +#define ONE_2x2POS_DEFINED() (g_eeGeneral.switchConfig & 0x44444444) +#define IS_TOGGLE(x) (switchConfig(x) == SWITCH_TOGGLE) +#define SWITCH_WARNING_ALLOWED(x) (x<8 ? !IS_TOGGLE(x) : IS_2x2POS(x-8)) +inline int getSwitchWarningsAllowed() +{ + int count = 0; + for (int i=0; i> (i*2); uint8_t next = (1024+getValue(MIXSRC_SA+i)) / 1024; if (prev != next) { @@ -560,7 +581,7 @@ int8_t getMovedSwitch() // 4..8 for all other switches if changed to true // -4..-8 for all other switches if changed to false // 9 for Trainer switch if changed to true; Change to false is ignored - swstate_t mask = 0x80; + swarnstate_t mask = 0x80; for (uint8_t i=NUM_PSWITCH; i>1; i--) { bool prev; prev = (switches_states & mask); @@ -586,11 +607,11 @@ int8_t getMovedSwitch() void checkSwitches() { #if defined(MODULE_ALWAYS_SEND_PULSES) - static swstate_t last_bad_switches = 0xff; + static swarnstate_t last_bad_switches = 0xff; #else - swstate_t last_bad_switches = 0xff; + swarnstate_t last_bad_switches = 0xff; #endif - swstate_t states = g_model.switchWarningStates; + swarnstate_t states = g_model.switchWarningState; #if defined(PCBTARANIS) uint8_t bad_pots = 0, last_bad_pots = 0xff; @@ -608,9 +629,9 @@ void checkSwitches() bool warn = false; #if defined(PCBTARANIS) - for (uint8_t i=0; i> (i*2)]; - lcd_putcAtt(60+i*(2*FW+FW/2), 4*FH+3, 'A'+i, attr); - lcd_putcAtt(60+i*(2*FW+FW/2)+FW, 4*FH+3, c, attr); + if (attr) { + char c = "\300-\301"[(states & mask) >> (i*2)]; + putsMixerSource(x, y, MIXSRC_FIRST_SWITCH+i, attr); + lcd_putcAtt(lcdNextPos, y, c, attr); + x = lcdNextPos + 3; + if (x >= LCD_W - 4*FW && y == 4*FH+3) { + y = 6*FH-2; + x = 60; + } + } } } if (potMode) { + if (y == 4*FH+3) { + y = 6*FH-2; + x = 60; + } for (uint8_t i=0; i 1) { - switch (i) { + lcd_putsiAtt(x, y, STR_VSRCRAW, NUM_STICKS+1+i, INVERS); + switch (i) { case 0: case 1: case 2: - lcd_putc(60+i*(5*FW)+2*FW+2, 6*FH-2, g_model.potPosition[i] > GET_LOWRES_POT_POSITION(i) ? 126 : 127); + lcd_putcAtt(lcdNextPos, y, g_model.potPosition[i] > GET_LOWRES_POT_POSITION(i) ? 126 : 127, INVERS); break; case 3: case 4: - lcd_putc(60+i*(5*FW)+2*FW+2, 6*FH-2, g_model.potPosition[i] > GET_LOWRES_POT_POSITION(i) ? '\300' : '\301'); + lcd_putcAtt(lcdNextPos, y, g_model.potPosition[i] > GET_LOWRES_POT_POSITION(i) ? '\300' : '\301', INVERS); break; } - flags = INVERS; + x = lcdNextPos + 3; } - lcd_putsiAtt(60+i*(5*FW), 6*FH-2, STR_VSRCRAW, NUM_STICKS+1+i, flags); + } } } @@ -706,7 +739,7 @@ void checkSwitches() attr = ((states & 0x03) != (switches_states & 0x03)) ? INVERS : 0; else attr = (states & (1 << (i+1))) == (switches_states & (1 << (i+1))) ? 0 : INVERS; - if (!(g_model.nSwToWarn & (1<0?(i+3):(states&0x3)+1), attr); x += 3*FW+FW/2; } diff --git a/radio/src/targets/taranis/keys_driver.cpp b/radio/src/targets/taranis/keys_driver.cpp index 0a2eda1be..608ec1583 100644 --- a/radio/src/targets/taranis/keys_driver.cpp +++ b/radio/src/targets/taranis/keys_driver.cpp @@ -131,7 +131,10 @@ bool switchState(EnumKeys enuk) switch ((uint8_t) enuk) { case SW_SA0: - xxx = (GPIO_PIN_SW_A_H & PIN_SW_A_H) && (~GPIO_PIN_SW_A_L & PIN_SW_A_L); + xxx = (GPIO_PIN_SW_A_H & PIN_SW_A_H); + if (IS_3POS(0)) { + xxx = xxx && (~GPIO_PIN_SW_A_L & PIN_SW_A_L); + } break; case SW_SA1: #if defined(REV3) @@ -141,21 +144,47 @@ bool switchState(EnumKeys enuk) #endif break; case SW_SA2: - xxx = (~GPIO_PIN_SW_A_H & PIN_SW_A_H) && (GPIO_PIN_SW_A_L & PIN_SW_A_L); + xxx = (~GPIO_PIN_SW_A_H & PIN_SW_A_H); + if (IS_3POS(0)) { + xxx = xxx && (GPIO_PIN_SW_A_L & PIN_SW_A_L); + } + break; + + case SW_SI0: + xxx = GPIO_PIN_SW_A_L & PIN_SW_A_L; + break; + case SW_SI2: + xxx = ~GPIO_PIN_SW_A_L & PIN_SW_A_L; break; case SW_SB0: - xxx = (GPIO_PIN_SW_B_H & PIN_SW_B_H) && (~GPIO_PIN_SW_B_L & PIN_SW_B_L); + xxx = (GPIO_PIN_SW_B_H & PIN_SW_B_H); + if (IS_3POS(1)) { + xxx = xxx && (~GPIO_PIN_SW_B_L & PIN_SW_B_L); + } break; case SW_SB1: xxx = (GPIO_PIN_SW_B_H & PIN_SW_B_H) && (GPIO_PIN_SW_B_L & PIN_SW_B_L); break; case SW_SB2: - xxx = (~GPIO_PIN_SW_B_H & PIN_SW_B_H) && (GPIO_PIN_SW_B_L & PIN_SW_B_L); + xxx = (~GPIO_PIN_SW_B_H & PIN_SW_B_H); + if (IS_3POS(1)) { + xxx = xxx && (GPIO_PIN_SW_B_L & PIN_SW_B_L); + } + break; + + case SW_SJ0: + xxx = GPIO_PIN_SW_B_L & PIN_SW_B_L; + break; + case SW_SJ2: + xxx = ~GPIO_PIN_SW_B_L & PIN_SW_B_L; break; case SW_SC0: - xxx = (GPIO_PIN_SW_C_H & PIN_SW_C_H) && (~GPIO_PIN_SW_C_L & PIN_SW_C_L); + xxx = (GPIO_PIN_SW_C_H & PIN_SW_C_H); + if (IS_3POS(2)) { + xxx = xxx && (~GPIO_PIN_SW_C_L & PIN_SW_C_L); + } break; case SW_SC1: #if defined(REV3) @@ -165,11 +194,24 @@ bool switchState(EnumKeys enuk) #endif break; case SW_SC2: - xxx = (~GPIO_PIN_SW_C_H & PIN_SW_C_H) && (GPIO_PIN_SW_C_L & PIN_SW_C_L); + xxx = (~GPIO_PIN_SW_C_H & PIN_SW_C_H); + if (IS_3POS(2)) { + xxx = xxx && (GPIO_PIN_SW_C_L & PIN_SW_C_L); + } + break; + + case SW_SK0: + xxx = GPIO_PIN_SW_C_L & PIN_SW_C_L; + break; + case SW_SK2: + xxx = ~GPIO_PIN_SW_C_L & PIN_SW_C_L; break; case SW_SD0: - xxx = (GPIO_PIN_SW_D_H & PIN_SW_D_H) && (~GPIO_PIN_SW_D_L & PIN_SW_D_L); + xxx = (GPIO_PIN_SW_D_H & PIN_SW_D_H); + if (IS_3POS(3)) { + xxx = xxx && (~GPIO_PIN_SW_D_L & PIN_SW_D_L); + } break; case SW_SD1: #if defined(REV3) @@ -179,17 +221,40 @@ bool switchState(EnumKeys enuk) #endif break; case SW_SD2: - xxx = (~GPIO_PIN_SW_D_H & PIN_SW_D_H) && (GPIO_PIN_SW_D_L & PIN_SW_D_L); + xxx = (~GPIO_PIN_SW_D_H & PIN_SW_D_H); + if (IS_3POS(3)) { + xxx = xxx && (GPIO_PIN_SW_D_L & PIN_SW_D_L); + } + break; + + case SW_SL0: + xxx = GPIO_PIN_SW_D_L & PIN_SW_D_L; + break; + case SW_SL2: + xxx = ~GPIO_PIN_SW_D_L & PIN_SW_D_L; break; case SW_SE0: - xxx = (~GPIO_PIN_SW_E_H & PIN_SW_E_H) && (GPIO_PIN_SW_E_L & PIN_SW_E_L); + xxx = (~GPIO_PIN_SW_E_H & PIN_SW_E_H); + if (IS_3POS(4)) { + xxx = xxx && (GPIO_PIN_SW_E_L & PIN_SW_E_L); + } break; case SW_SE1: xxx = (GPIO_PIN_SW_E_H & PIN_SW_E_H) && (GPIO_PIN_SW_E_L & PIN_SW_E_L); break; case SW_SE2: - xxx = (GPIO_PIN_SW_E_H & PIN_SW_E_H) && (~GPIO_PIN_SW_E_L & PIN_SW_E_L); + xxx = (GPIO_PIN_SW_E_H & PIN_SW_E_H); + if (IS_3POS(4)) { + xxx = xxx && (~GPIO_PIN_SW_E_L & PIN_SW_E_L); + } + break; + + case SW_SM0: + xxx = GPIO_PIN_SW_E_L & PIN_SW_E_L; + break; + case SW_SM2: + xxx = ~GPIO_PIN_SW_E_L & PIN_SW_E_L; break; case SW_SF0: @@ -200,7 +265,10 @@ bool switchState(EnumKeys enuk) break; case SW_SG0: - xxx = (GPIO_PIN_SW_G_H & PIN_SW_G_H) && (~GPIO_PIN_SW_G_L & PIN_SW_G_L); + xxx = (GPIO_PIN_SW_G_H & PIN_SW_G_H); + if (IS_3POS(6)) { + xxx = xxx && (~GPIO_PIN_SW_G_L & PIN_SW_G_L); + } break; case SW_SG1: #if defined(REV3) @@ -210,7 +278,17 @@ bool switchState(EnumKeys enuk) #endif break; case SW_SG2: - xxx = (~GPIO_PIN_SW_G_H & PIN_SW_G_H) && (GPIO_PIN_SW_G_L & PIN_SW_G_L); + xxx = (~GPIO_PIN_SW_G_H & PIN_SW_G_H); + if (IS_3POS(6)) { + xxx = xxx && (GPIO_PIN_SW_G_L & PIN_SW_G_L); + } + break; + + case SW_SN0: + xxx = GPIO_PIN_SW_G_L & PIN_SW_G_L; + break; + case SW_SN2: + xxx = ~GPIO_PIN_SW_G_L & PIN_SW_G_L; break; case SW_SH0: diff --git a/radio/src/tests/switches.cpp b/radio/src/tests/switches.cpp index f31cb1937..af976fe08 100644 --- a/radio/src/tests/switches.cpp +++ b/radio/src/tests/switches.cpp @@ -124,7 +124,7 @@ TEST(getSwitch, DISABLED_VfasWithDelay) (gdb) print Open9xX9D::g_model.logicalSw[0] $3 = {v1 = -39 '\331', v2 = 96, v3 = 0, func = 4 '\004', delay = 5 '\005', duration = 0 '\000', andsw = 0 '\000'} */ - g_model.logicalSw[0] = {-39, 96, 0, 4, 5, 0, 0}; + g_model.logicalSw[0] = {int8_t(MIXSRC_FIRST_TELEM+TELEM_VFAS-1), 96, 0, 4, 5, 0, 0}; frskyData.hub.vfas = 150; //unit is 100mV //telemetry streaming is FALSE, so L1 should be FALSE no matter what value Vfas has @@ -228,7 +228,8 @@ TEST(getSwitch, DISABLED_RssiWithDuration) (gdb) print Open9xX9D::g_model.logicalSw[0] $1 = {v1 = -55 '\311', v2 = 10, v3 = 0, func = 3 '\003', delay = 0 '\000', duration = 5 '\005', andsw = 0 '\000'} */ - g_model.logicalSw[0] = {-55, 10, 0, 3, 0, 5, 0}; + + g_model.logicalSw[0] = {int8_t(MIXSRC_FIRST_TELEM+TELEM_RSSI_RX-1), 10, 0, 3, 0, 5, 0}; EXPECT_EQ(TELEMETRY_STREAMING(), false); diff --git a/radio/src/translations/en.h.txt b/radio/src/translations/en.h.txt index 540aec04d..27a24f2a8 100644 --- a/radio/src/translations/en.h.txt +++ b/radio/src/translations/en.h.txt @@ -429,7 +429,7 @@ #if defined(PCBTARANIS) #define TR_POTS_VSRCRAW "S1\0 ""S2\0 ""S3\0 ""LS\0 ""RS\0 " - #define TR_SW_VSRCRAW "SA\0 ""SB\0 ""SC\0 ""SD\0 ""SE\0 ""SF\0 ""SG\0 ""SH\0 " + #define TR_SW_VSRCRAW "SA\0 ""SB\0 ""SC\0 ""SD\0 ""SE\0 ""SF\0 ""SG\0 ""SH\0 ""SI\0 ""SJ\0 ""SK\0 ""SL\0 ""SM\0 ""SN\0 " #elif defined(EXTRA_3POS) #define TR_POTS_VSRCRAW "P1\0 ""P2\0 " #define TR_SW_VSRCRAW "3P1\0""3P2\0" @@ -461,7 +461,7 @@ #if defined(PCBTARANIS) #define TR_6POS_POTS "S11""S12""S13""S14""S15""S16""S21""S22""S23""S24""S25""S26""S31""S32""S33""S34""S35""S36" - #define TR_VSWITCHES "---""SA\300""SA-""SA\301""SB\300""SB-""SB\301""SC\300""SC-""SC\301""SD\300""SD-""SD\301""SE\300""SE-""SE\301""SF\300""SF\301""SG\300""SG-""SG\301""SH\300""SH\301" TR_6POS_POTS TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" + #define TR_VSWITCHES "---""SA\300""SA-""SA\301""SB\300""SB-""SB\301""SC\300""SC-""SC\301""SD\300""SD-""SD\301""SE\300""SE-""SE\301""SF\300""SF\301""SG\300""SG-""SG\301""SH\300""SH\301""SI\300""SI\301""SJ\300""SJ\301""SK\300""SK\301""SL\300""SL\301""SM\300""SM\301""SN\300""SN\301" TR_6POS_POTS TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" #elif defined(CPUARM) #define TR_VSWITCHES "---" TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_LOGICALSW "ON\0""One" #else @@ -788,7 +788,7 @@ #define TR_SD_SPEED "Speed:" #define TR_SD_SECTORS "Sectors:" #define TR_SD_SIZE "Size:" -#define TR_TYPE "Type" +#define TR_TYPE INDENT "Type" #define TR_GLOBAL_VARS "Global Variables" #define TR_GLOBAL_V "GLOBAL V." #define TR_GLOBAL_VAR "Global Variable" From 50978c15c507746785f489e8533695d4dbe4935b Mon Sep 17 00:00:00 2001 From: bsongis Date: Sun, 16 Nov 2014 13:06:46 +0100 Subject: [PATCH 2/2] Companion switches / anas names configuration --- companion/src/burndialog.cpp | 4 +- companion/src/eeprominterface.cpp | 35 +- companion/src/eeprominterface.h | 77 +- companion/src/firmwares/er9x/er9xeeprom.cpp | 6 +- .../src/firmwares/ersky9x/ersky9xeeprom.cpp | 6 +- .../src/firmwares/gruvin9x/gruvin9xeeprom.cpp | 8 +- .../src/firmwares/opentx/opentxeeprom.cpp | 45 +- .../src/firmwares/opentx/opentxinterface.cpp | 4 +- companion/src/firmwares/th9x/th9xeeprom.cpp | 8 +- companion/src/generaledit/calibration.cpp | 103 ++ companion/src/generaledit/calibration.h | 3 +- companion/src/generaledit/calibration.ui | 1055 +++++++++++++---- companion/src/generaledit/generaledit.cpp | 4 +- companion/src/generaledit/generalsetup.cpp | 4 +- companion/src/helpers.cpp | 8 +- companion/src/modeledit/setup.cpp | 29 +- companion/src/shared/CMakeLists.txt | 1 + companion/src/shared/autocombobox.h | 8 +- companion/src/shared/autolineedit.h | 60 + companion/src/shared/genericpanel.h | 1 + radio/src/myeeprom.h | 34 +- 21 files changed, 1206 insertions(+), 297 deletions(-) create mode 100755 companion/src/shared/autolineedit.h diff --git a/companion/src/burndialog.cpp b/companion/src/burndialog.cpp index d0c166cfc..b868c2bbe 100644 --- a/companion/src/burndialog.cpp +++ b/companion/src/burndialog.cpp @@ -519,7 +519,7 @@ void burnDialog::on_BurnFlashButton_clicked() byte8u=(uint8_t)BeeperSet.mid(0,2).toUInt(&ok,16); if (ok) - radioData.generalSettings.beeperMode=(BeeperMode)byte8u; + radioData.generalSettings.beeperMode=(GeneralSettings::BeeperMode)byte8u; byte8=(int8_t)BeeperSet.mid(2,2).toInt(&ok,16); if (ok) @@ -527,7 +527,7 @@ void burnDialog::on_BurnFlashButton_clicked() byte8u=(uint8_t)HapticSet.mid(0,2).toUInt(&ok,16); if (ok) - radioData.generalSettings.hapticMode=(BeeperMode)byte8u; + radioData.generalSettings.hapticMode=(GeneralSettings::BeeperMode)byte8u; byte8u=(uint8_t)HapticSet.mid(2,2).toUInt(&ok,16); if (ok) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 3d88ba9ee..fd0cf0d1f 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -15,7 +15,7 @@ std::list EEPROMWarnings; const char * switches9X[] = { "3POS", "THR", "RUD", "ELE", "AIL", "GEA", "TRN" }; -const char * switchesX9D[] = { "SA", "SB", "SC", "SD", "SE", "SF", "SG", "SH" }; +const char * switchesX9D[] = { "SA", "SB", "SC", "SD", "SE", "SF", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN" }; const char leftArrow[] = {(char)0xE2, (char)0x86, (char)0x90, 0}; const char rightArrow[] = {(char)0xE2, (char)0x86, (char)0x92, 0}; const char upArrow[] = {(char)0xE2, (char)0x86, (char)0x91, 0}; @@ -531,6 +531,12 @@ QString RawSwitch::toString() SwitchUp('F'), SwitchDn('F'), SwitchUp('G'), QString::fromUtf8("SG-"), SwitchDn('G'), SwitchUp('H'), SwitchDn('H'), + SwitchUp('I'), SwitchDn('I'), + SwitchUp('J'), SwitchDn('J'), + SwitchUp('K'), SwitchDn('K'), + SwitchUp('L'), SwitchDn('L'), + SwitchUp('M'), SwitchDn('M'), + SwitchUp('N'), SwitchDn('N'), }; static const QString logicalSwitches[] = { @@ -976,6 +982,33 @@ void LimitData::clear() max = +1000; } +GeneralSettings::SwitchInfo GeneralSettings::switchInfoFromSwitchPositionTaranis(unsigned int index) +{ + if (index <= 3*5) + return SwitchInfo((index-1)/3, (index-1)%3); + else if (index <= 17) + return SwitchInfo(5, index==17 ? 2 : 0); + else if (index <= 20) + return SwitchInfo(6, index-18); + else + return SwitchInfo(7+(index-21)/2, 2*((index-21)%2)); +} + +bool GeneralSettings::switchPositionAllowedTaranis(int index) const +{ + if (index == 0) + return true; + SwitchInfo info = switchInfoFromSwitchPositionTaranis(abs(index)); + if (index < 0 && switchConfigTaranis(info.index) != SWITCH_3POS) + return false; + else if (info.index >= 8) + return switchConfigTaranis(info.index-8) == SWITCH_2x2POS; + else if (info.position == 1) + return switchConfigTaranis(info.index) == SWITCH_3POS; + else + return true; +} + GeneralSettings::GeneralSettings() { memset(this, 0, sizeof(GeneralSettings)); diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index ac3981217..766b51738 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -126,7 +126,14 @@ enum Switches { SWITCH_SG1, SWITCH_SG2, SWITCH_SH0, - SWITCH_SH1 + SWITCH_SH2, + SWITCH_SI0, + SWITCH_SI2, + SWITCH_SJ0, + SWITCH_SJ2, + SWITCH_SK0, + SWITCH_SK2, + }; enum TimerModes { @@ -1007,7 +1014,7 @@ class ModelData { unsigned int thrTraceSrc; unsigned int modelId; unsigned int switchWarningStates; - unsigned int nSwToWarn; + unsigned int switchWarningEnable; unsigned int nPotsToWarn; int potPosition[C9X_NUM_POTS]; bool displayChecklist; @@ -1070,15 +1077,24 @@ class TrainerData { void clear() { memset(this, 0, sizeof(TrainerData)); } }; -enum BeeperMode { - e_quiet = -2, - e_alarms_only = -1, - e_no_keys = 0, - e_all = 1 -}; - class GeneralSettings { public: + + enum BeeperMode { + BEEPER_QUIET = -2, + BEEPER_ALARMS_ONLY = -1, + BEEPER_NOKEYS = 0, + BEEPER_ALL = 1 + }; + + enum SwitchConfig { + SWITCH_DEFAULT, + SWITCH_TOGGLE, + SWITCH_2POS, + SWITCH_3POS, + SWITCH_2x2POS + }; + GeneralSettings(); int getDefaultStick(unsigned int channel) const; @@ -1166,6 +1182,49 @@ class GeneralSettings { unsigned int potsType[8]; unsigned int backlightColor; CustomFunctionData customFn[C9X_MAX_CUSTOM_FUNCTIONS]; + unsigned int switchConfig[8]; + char switchNames[32][3+1]; + char anaNames[32][3+1]; + + struct SwitchInfo { + SwitchInfo(unsigned int index, unsigned int position): + index(index), + position(position) + { + } + unsigned int index; + unsigned int position; + }; + + static SwitchInfo switchInfoFromSwitchPositionTaranis(unsigned int index); + bool switchPositionAllowedTaranis(int index) const; + + static unsigned int switchDefaultConfigTaranis(unsigned int index) + { + if (index == 5) + return SWITCH_2POS; + else if (index == 7) + return SWITCH_TOGGLE; + else + return SWITCH_3POS; + } + + unsigned int switchConfigTaranis(unsigned int index) const + { + unsigned int result = switchConfig[index]; + if (result == SWITCH_DEFAULT) + result = switchDefaultConfigTaranis(index); + return result; + } + + bool isSwitchWarningAllowedTaranis(unsigned int index) const + { + if (index < 8) + return switchConfigTaranis(index) != SWITCH_TOGGLE; + else + return switchConfig[index-8] == SWITCH_2x2POS; + } + }; class RadioData { diff --git a/companion/src/firmwares/er9x/er9xeeprom.cpp b/companion/src/firmwares/er9x/er9xeeprom.cpp index 1cb7d160b..18eadd7f5 100644 --- a/companion/src/firmwares/er9x/er9xeeprom.cpp +++ b/companion/src/firmwares/er9x/er9xeeprom.cpp @@ -85,13 +85,13 @@ Er9xGeneral::operator GeneralSettings () switch (beeperVal) { case 0: - result.beeperMode = e_quiet; + result.beeperMode = GeneralSettings::BEEPER_QUIET; break; case 1: - result.beeperMode = e_no_keys; + result.beeperMode = GeneralSettings::BEEPER_NOKEYS; break; default: - result.beeperMode = e_all; + result.beeperMode = GeneralSettings::BEEPER_ALL; result.beeperLength = beeperVal - 4; break; } diff --git a/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp b/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp index 7598e1fe4..7096a1ded 100644 --- a/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp +++ b/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp @@ -105,13 +105,13 @@ Ersky9xGeneral::operator GeneralSettings () switch (beeperVal) { case 0: - result.beeperMode = e_quiet; + result.beeperMode = GeneralSettings::BEEPER_QUIET; break; case 1: - result.beeperMode = e_no_keys; + result.beeperMode = GeneralSettings::BEEPER_NOKEYS; break; default: - result.beeperMode = e_all; + result.beeperMode = GeneralSettings::BEEPER_ALL; result.beeperLength = beeperVal - 4; break; } diff --git a/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp b/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp index 222b6237c..7beb76611 100644 --- a/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp +++ b/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp @@ -88,13 +88,13 @@ Gruvin9xGeneral_v103::operator GeneralSettings () switch (beeperVal) { case 0: - result.beeperMode = e_quiet; + result.beeperMode = GeneralSettings::BEEPER_QUIET; break; case 1: - result.beeperMode = e_no_keys; + result.beeperMode = GeneralSettings::BEEPER_NOKEYS; break; default: - result.beeperMode = e_all; + result.beeperMode = GeneralSettings::BEEPER_ALL; result.beeperLength = beeperVal - 4; break; } @@ -142,7 +142,7 @@ Gruvin9xGeneral_v104::operator GeneralSettings () result.view = view; result.disableThrottleWarning = disableThrottleWarning; result.switchWarning = switchWarning; - result.beeperMode = (BeeperMode)beeperVal; + result.beeperMode = (GeneralSettings::BeeperMode)beeperVal; result.disableMemoryWarning = disableMemoryWarning; result.disableAlarmWarning = disableAlarmWarning; result.stickMode = stickMode; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index d839b2dc6..aa046575f 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -12,8 +12,8 @@ #define HAS_LARGE_LCD(board) IS_TARANIS(board) #define MAX_VIEWS(board) (HAS_LARGE_LCD(board) ? 2 : 256) #define MAX_POTS(board) (IS_TARANIS(board) ? 5 : 3) -#define MAX_SWITCHES(board) (IS_TARANIS(board) ? 8 : 7) -#define MAX_SWITCHES_POSITION(board) (IS_TARANIS(board) ? 22 : 9) +#define MAX_SWITCHES(board, version) (version >= 217 ? (IS_TARANIS(board) ? 8+6 : 7) : (IS_TARANIS(board) ? 8 : 7)) +#define MAX_SWITCHES_POSITION(board, version) (IS_TARANIS(board) ? (version >= 217 ? 22+12 : 22) : 9) #define MAX_ROTARY_ENCODERS(board) (board==BOARD_GRUVIN9X ? 2 : (IS_SKY9X(board) ? 1 : 0)) #define MAX_FLIGHT_MODES(board, version) (IS_ARM(board) ? 9 : (IS_DBLRAM(board, version) ? 6 : 5)) #define MAX_TIMERS(board, version) ((IS_ARM(board) && version >= 217) ? 3 : 2) @@ -56,7 +56,7 @@ class SwitchesConversionTable: public ConversionTable { addConversion(RawSwitch(SWITCH_TYPE_NONE), val++); } - for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) { + for (int i=1; i<=MAX_SWITCHES_POSITION(board, version); i++) { int s = switchIndex(i, board, version); addConversion(RawSwitch(SWITCH_TYPE_SWITCH, s), val); if (IS_TARANIS(board) && s>=21/*SHup/SHdown*/) { @@ -110,7 +110,7 @@ class SwitchesConversionTable: public ConversionTable { if (version < 216) { // previous "moment" switches - for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) { + for (int i=1; i<=MAX_SWITCHES_POSITION(board, version); i++) { int s = switchIndex(i, board, version); addConversion(RawSwitch(SWITCH_TYPE_SWITCH, s), val++); } @@ -241,7 +241,7 @@ class SourcesConversionTable: public ConversionTable { if (!(flags & FLAG_NOSWITCHES)) { if (afterrelease21March2013) { - for (int i=1; i(modelData.modelId)); } - if (IS_TARANIS(board)) + if (IS_TARANIS(board) && version >= 217) + internalField.Append(new SwitchesWarningField<32>(modelData.switchWarningStates, board, version)); + else if (IS_TARANIS(board)) internalField.Append(new SwitchesWarningField<16>(modelData.switchWarningStates, board, version)); else internalField.Append(new SwitchesWarningField<8>(modelData.switchWarningStates, board, version)); - if (version >= 216) { - internalField.Append(new UnsignedField<8>(modelData.nSwToWarn)); - } + + if (IS_TARANIS(board) && version >= 217) + internalField.Append(new UnsignedField<16>(modelData.switchWarningEnable)); + else if (version >= 216) + internalField.Append(new UnsignedField<8>(modelData.switchWarningEnable)); if ((board == BOARD_STOCK || (board == BOARD_M128 && version >= 215)) && (variant & GVARS_VARIANT)) { for (int i=0; i(generalData.backlightColor)); } - if (version >= 216) { - internalField.Append(new SpareBitsField<16>()); + + if (IS_TARANIS(board)) { + if (version >= 217) + internalField.Append(new SpareBitsField<32>()); + else + internalField.Append(new SpareBitsField<16>()); } + if (version >= 217) { for (int i=0; i= 217) { + for (int i=0; i<8; i++) { + internalField.Append(new UnsignedField<4>(generalData.switchConfig[i])); + } + for (int i=0; i(generalData.switchNames[i])); + } + for (int i=0; i(generalData.anaNames[i])); + } + } } } diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index bfca15a82..f0bc7d557 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -571,9 +571,9 @@ int OpenTxFirmware::getCapability(const Capability capability) case Pots: return (IS_TARANIS(board) ? 5 : 3); case Switches: - return (IS_TARANIS(board) ? 8 : 7); + return (IS_TARANIS(board) ? 8+6 : 7); case SwitchesPositions: - return (IS_TARANIS(board) ? 22 : 9); + return (IS_TARANIS(board) ? 22+12 : 9); case CustomFunctions: if (IS_TARANIS(board)) return 64; diff --git a/companion/src/firmwares/th9x/th9xeeprom.cpp b/companion/src/firmwares/th9x/th9xeeprom.cpp index 76bc9851a..2a5e2d09e 100644 --- a/companion/src/firmwares/th9x/th9xeeprom.cpp +++ b/companion/src/firmwares/th9x/th9xeeprom.cpp @@ -71,16 +71,16 @@ Th9xGeneral::operator GeneralSettings () result.disableMemoryWarning = disableMemoryWarning; switch (beeperVal) { case 0: - result.beeperMode = e_quiet; + result.beeperMode = GeneralSettings::BEEPER_QUIET; break; case 1: - result.beeperMode = e_no_keys; + result.beeperMode = GeneralSettings::BEEPER_NOKEYS; break; case 2: - result.beeperMode = e_all; + result.beeperMode = GeneralSettings::BEEPER_ALL; break; case 3: - result.beeperMode = e_all; + result.beeperMode = GeneralSettings::BEEPER_ALL; result.beeperLength = 2; } result.stickMode = stickMode; diff --git a/companion/src/generaledit/calibration.cpp b/companion/src/generaledit/calibration.cpp index 1c8120cc7..ccbdf60ef 100644 --- a/companion/src/generaledit/calibration.cpp +++ b/companion/src/generaledit/calibration.cpp @@ -20,6 +20,93 @@ CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSe ui->pot2TypeLabel->hide(); ui->pot3Type->hide(); ui->pot3TypeLabel->hide(); + ui->pot4Label->hide(); + ui->pot5Label->hide(); + } + + if (IS_TARANIS(firmware->getBoard())) { + ui->rudName->setField(generalSettings.anaNames[0], 3, this); + ui->eleName->setField(generalSettings.anaNames[1], 3, this); + ui->thrName->setField(generalSettings.anaNames[2], 3, this); + ui->ailName->setField(generalSettings.anaNames[3], 3, this); + ui->pot1Name->setField(generalSettings.anaNames[4], 3, this); + ui->pot2Name->setField(generalSettings.anaNames[5], 3, this); + ui->pot3Name->setField(generalSettings.anaNames[6], 3, this); + ui->pot4Name->setField(generalSettings.anaNames[7], 3, this); + ui->pot5Name->setField(generalSettings.anaNames[8], 3, this); + ui->saName->setField(generalSettings.switchNames[0], 3, this); + ui->saType->setField(generalSettings.switchConfig[0], this); + ui->sbName->setField(generalSettings.switchNames[1], 3, this); + ui->sbType->setField(generalSettings.switchConfig[1], this); + ui->scName->setField(generalSettings.switchNames[2], 3, this); + ui->scType->setField(generalSettings.switchConfig[2], this); + ui->sdName->setField(generalSettings.switchNames[3], 3, this); + ui->sdType->setField(generalSettings.switchConfig[3], this); + ui->seName->setField(generalSettings.switchNames[4], 3, this); + ui->seType->setField(generalSettings.switchConfig[4], this); + ui->sfName->setField(generalSettings.switchNames[5], 3, this); + ui->sfType->setField(generalSettings.switchConfig[5], this); + ui->sgName->setField(generalSettings.switchNames[6], 3, this); + ui->sgType->setField(generalSettings.switchConfig[6], this); + ui->shName->setField(generalSettings.switchNames[7], 3, this); + ui->shType->setField(generalSettings.switchConfig[7], this); + ui->siName->setField(generalSettings.switchNames[8], 3, this); + ui->sjName->setField(generalSettings.switchNames[9], 3, this); + ui->skName->setField(generalSettings.switchNames[10], 3, this); + ui->slName->setField(generalSettings.switchNames[11], 3, this); + ui->smName->setField(generalSettings.switchNames[12], 3, this); + ui->snName->setField(generalSettings.switchNames[13], 3, this); + connect(ui->saType, SIGNAL(currentIndexChanged(int)), this, SLOT(update())); + connect(ui->sbType, SIGNAL(currentIndexChanged(int)), this, SLOT(update())); + connect(ui->scType, SIGNAL(currentIndexChanged(int)), this, SLOT(update())); + connect(ui->sdType, SIGNAL(currentIndexChanged(int)), this, SLOT(update())); + connect(ui->seType, SIGNAL(currentIndexChanged(int)), this, SLOT(update())); + connect(ui->sgType, SIGNAL(currentIndexChanged(int)), this, SLOT(update())); + } + else { + ui->rudLabel->hide(); + ui->rudName->hide(); + ui->eleLabel->hide(); + ui->eleName->hide(); + ui->thrLabel->hide(); + ui->thrName->hide(); + ui->ailLabel->hide(); + ui->ailName->hide(); + ui->pot1Name->hide(); + ui->pot2Name->hide(); + ui->pot3Name->hide(); + ui->pot4Name->hide(); + ui->pot5Name->hide(); + ui->saLabel->hide(); + ui->saName->hide(); + ui->saType->hide(); + ui->sbLabel->hide(); + ui->sbName->hide(); + ui->sbType->hide(); + ui->scLabel->hide(); + ui->scName->hide(); + ui->scType->hide(); + ui->sdLabel->hide(); + ui->sdName->hide(); + ui->sdType->hide(); + ui->seLabel->hide(); + ui->seName->hide(); + ui->seType->hide(); + ui->sfLabel->hide(); + ui->sfName->hide(); + ui->sfType->hide(); + ui->sgLabel->hide(); + ui->sgName->hide(); + ui->sgType->hide(); + ui->shLabel->hide(); + ui->shName->hide(); + ui->shType->hide(); + ui->siName->hide(); + ui->sjName->hide(); + ui->skName->hide(); + ui->slName->hide(); + ui->smName->hide(); + ui->snName->hide(); } int potsCount = GetCurrentFirmware()->getCapability(Pots); @@ -46,6 +133,22 @@ CalibrationPanel::~CalibrationPanel() delete ui; } +void CalibrationPanel::update() +{ + ui->siLabel->setVisible(generalSettings.switchConfig[0] == GeneralSettings::SWITCH_2x2POS); + ui->siName->setVisible(generalSettings.switchConfig[0] == GeneralSettings::SWITCH_2x2POS); + ui->sjLabel->setVisible(generalSettings.switchConfig[1] == GeneralSettings::SWITCH_2x2POS); + ui->sjName->setVisible(generalSettings.switchConfig[1] == GeneralSettings::SWITCH_2x2POS); + ui->skLabel->setVisible(generalSettings.switchConfig[2] == GeneralSettings::SWITCH_2x2POS); + ui->skName->setVisible(generalSettings.switchConfig[2] == GeneralSettings::SWITCH_2x2POS); + ui->slLabel->setVisible(generalSettings.switchConfig[3] == GeneralSettings::SWITCH_2x2POS); + ui->slName->setVisible(generalSettings.switchConfig[3] == GeneralSettings::SWITCH_2x2POS); + ui->smLabel->setVisible(generalSettings.switchConfig[4] == GeneralSettings::SWITCH_2x2POS); + ui->smName->setVisible(generalSettings.switchConfig[4] == GeneralSettings::SWITCH_2x2POS); + ui->snLabel->setVisible(generalSettings.switchConfig[6] == GeneralSettings::SWITCH_2x2POS); + ui->snName->setVisible(generalSettings.switchConfig[6] == GeneralSettings::SWITCH_2x2POS); +} + void CalibrationPanel::on_PPM_MultiplierDSB_editingFinished() { generalSettings.PPM_Multiplier = (int)(ui->PPM_MultiplierDSB->value()*10)-10; diff --git a/companion/src/generaledit/calibration.h b/companion/src/generaledit/calibration.h index 0135ce121..e89a058b9 100644 --- a/companion/src/generaledit/calibration.h +++ b/companion/src/generaledit/calibration.h @@ -14,6 +14,7 @@ class CalibrationPanel : public GeneralPanel public: CalibrationPanel(QWidget *parent, GeneralSettings & generalSettings, FirmwareInterface * firmware); virtual ~CalibrationPanel(); + virtual void update(); private slots: void on_battCalibDSB_editingFinished(); @@ -52,10 +53,10 @@ class CalibrationPanel : public GeneralPanel void on_ana7Pos_editingFinished(); void on_ana8Pos_editingFinished(); - void on_pot1Type_currentIndexChanged(int index); void on_pot2Type_currentIndexChanged(int index); void on_pot3Type_currentIndexChanged(int index); + void on_serialPortMode_currentIndexChanged(int index); private: diff --git a/companion/src/generaledit/calibration.ui b/companion/src/generaledit/calibration.ui index a5b0cdece..1de906f85 100644 --- a/companion/src/generaledit/calibration.ui +++ b/companion/src/generaledit/calibration.ui @@ -6,14 +6,340 @@ 0 0 - 780 - 450 + 802 + 1036 Form - + + + + + + + + + + + Beeper volume + +0 - Quiet. No beeps at all. +1 - No Keys. Normal beeps but menu keys do not beep. +2 - Normal. +3 - Loud. +4 - Extra loud. + + + + None + + + + + Pot with detent (normal) + + + + + Multipos Switch + + + + + Pot without detent + + + + + + + + 3 + + + + + + + RS + + + + + + + SB + + + + + + + Serial Port + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 3 + + + + + + + + + + + + + Beeper volume + +0 - Quiet. No beeps at all. +1 - No Keys. Normal beeps but menu keys do not beep. +2 - Normal. +3 - Loud. +4 - Extra loud. + + + + Default + + + + + 2POS Toggle + + + + + 2POS + + + + + 3POS + + + + + 2x2POS + + + + + + + + + 0 + 10 + + + + Qt::Horizontal + + + + + + + + + + + + + Beeper volume + +0 - Quiet. No beeps at all. +1 - No Keys. Normal beeps but menu keys do not beep. +2 - Normal. +3 - Loud. +4 - Extra loud. + + + + None + + + + + Pot with detent (normal) + + + + + Multipos Switch + + + + + Pot without detent + + + + + + + + + + + + + + Beeper volume + +0 - Quiet. No beeps at all. +1 - No Keys. Normal beeps but menu keys do not beep. +2 - Normal. +3 - Loud. +4 - Extra loud. + + + + Default + + + + + 2POS Toggle + + + + + 2POS + + + + + 3POS + + + + + 2x2POS + + + + + + + + + OFF + + + + + S-Port Mirror + + + + + Telemetry + + + + + SBUS Trainer + + + + + Debug + + + + + + + + + + + + + + Beeper volume + +0 - Quiet. No beeps at all. +1 - No Keys. Normal beeps but menu keys do not beep. +2 - Normal. +3 - Loud. +4 - Extra loud. + + + + None + + + + + Pot with detent (normal) + + + + + Multipos Switch + + + + + Pot without detent + + + + + + + + 3 + + + + + + + 3 + + + + + + + 3 + + + + + + + Rud + + + + + + + + + + -9999 + + + 9999 + + + @@ -75,20 +401,7 @@ - - - - 1 - - - 5.000000000000000 - - - 1.000000000000000 - - - - + PPM 1 @@ -168,16 +481,10 @@ - - - - - - - -9999 - - - 9999 + + + + PPM 2 @@ -315,27 +622,14 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - + Battery - + @@ -357,39 +651,14 @@ - + PPM Multiplier - - - - - 0 - 0 - - - - - 0 - 10 - - - - QFrame::Sunken - - - 1 - - - Qt::Horizontal - - - - + @@ -408,7 +677,7 @@ - + @@ -427,7 +696,7 @@ - + @@ -446,7 +715,7 @@ - + @@ -465,41 +734,21 @@ - - - - PPM 2 - - - - + PPM 3 - + PPM 4 - - - - - 0 - 10 - - - - Qt::Horizontal - - - - + -49 @@ -509,7 +758,7 @@ - + Current @@ -689,107 +938,113 @@ - - - - - - - - - - Beeper volume - -0 - Quiet. No beeps at all. -1 - No Keys. Normal beeps but menu keys do not beep. -2 - Normal. -3 - Loud. -4 - Extra loud. - - - - None - - - - - Pot with detent (normal) - - - - - Multipos Switch - - - - - Pot without detent - - - - - + - S1 Type + S1 - - - - + + + + S2 - - + + + + + + S3 - - Beeper volume - -0 - Quiet. No beeps at all. -1 - No Keys. Normal beeps but menu keys do not beep. -2 - Normal. -3 - Loud. -4 - Extra loud. + + + + + + 3 + + + + + + + SA - - - None - - - - - Pot with detent (normal) - - - - - Multipos Switch - - - - - Pot without detent - - - + - S2 Type + Ele + + + + + + + Ail - + - S3 Type + Thr + + + + + + + 3 + + + + + + + 3 - + + + 3 + + + + + + + SC + + + + + + + LS + + + + + + + 3 + + + + + + + 3 + + + + + @@ -797,77 +1052,439 @@ - Beeper volume - -0 - Quiet. No beeps at all. -1 - No Keys. Normal beeps but menu keys do not beep. -2 - Normal. -3 - Loud. -4 - Extra loud. + - None + Default - Pot with detent (normal) + 2POS Toggle - Multipos Switch + 2POS - Pot without detent + 3POS + + + + + 2x2POS - - - - - OFF - - - - - S-Port Mirror - - - - - Telemetry - - - - - SBUS Trainer - - - - - Debug - - + + + + 3 + - - + + - Serial Port + SD - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + Default + + + + + 2POS Toggle + + + + + 2POS + + + + + 3POS + + + + + 2x2POS + + + + + + + + 3 + + + + + + + SE + + + + + + + + + + + + + + + + + Default + + + + + 2POS Toggle + + + + + 2POS + + + + + 3POS + + + + + 2x2POS + + + + + + + + 3 + + + + + + + SF + + + + + + + + + + + + + + + + + Default + + + + + 2POS Toggle + + + + + 2POS + + + + + 3POS + + + + + 2x2POS + + + + + + + + 3 + + + + + + + SG + + + + + + + + + + + + + + + + + Default + + + + + 2POS Toggle + + + + + 2POS + + + + + 3POS + + + + + 2x2POS + + + + + + + + 3 + + + + + + + SH + + + + + + + + + + + + + + + + + Default + + + + + 2POS Toggle + + + + + 2POS + + + + + 3POS + + + + + 2x2POS + + + + + + + + 3 + + + + + + + SI + + + + + + + 3 + + + + + + + SJ + + + + + + + 3 + + + + + + + SK + + + + + + + 3 + + + + + + + SL + + + + + + + 3 + + + + + + + SM + + + + + + + 3 + + + + + + + SN + + + + + + + 3 + + + + + + + 1 + + + 5.000000000000000 + + + 1.000000000000000 + + + + + + + + 0 + 10 + + + + Qt::Horizontal + + + + + + + + 0 + 10 + + + + Qt::Horizontal + + + AutoLineEdit + QLineEdit +
autolineedit.h
+
+ + AutoComboBox + QComboBox +
autocombobox.h
+
+
diff --git a/companion/src/generaledit/generaledit.cpp b/companion/src/generaledit/generaledit.cpp index 9d4fb77d7..4c3ab0a87 100644 --- a/companion/src/generaledit/generaledit.cpp +++ b/companion/src/generaledit/generaledit.cpp @@ -142,13 +142,13 @@ void GeneralEdit::on_calretrieve_PB_clicked() generalSettings.backlightBright=byte8u; byte8=(int8_t)BeeperSet.mid(0,2).toUInt(&ok,16); if (ok) - generalSettings.beeperMode=(BeeperMode)byte8; + generalSettings.beeperMode = (GeneralSettings::BeeperMode)byte8; byte8=(int8_t)BeeperSet.mid(2,2).toInt(&ok,16); if (ok) generalSettings.beeperLength=byte8; byte8=(int8_t)HapticSet.mid(0,2).toUInt(&ok,16); if (ok) - generalSettings.hapticMode=(BeeperMode)byte8; + generalSettings.hapticMode=(GeneralSettings::BeeperMode)byte8; byte8=(int8_t)HapticSet.mid(2,2).toInt(&ok,16); if (ok) generalSettings.hapticStrength=byte8; diff --git a/companion/src/generaledit/generalsetup.cpp b/companion/src/generaledit/generalsetup.cpp index 9a839615e..d1f2fd370 100644 --- a/companion/src/generaledit/generalsetup.cpp +++ b/companion/src/generaledit/generalsetup.cpp @@ -553,7 +553,7 @@ void GeneralSetupPanel::on_alarmwarnChkB_stateChanged(int ) void GeneralSetupPanel::on_beeperCB_currentIndexChanged(int index) { - generalSettings.beeperMode = (BeeperMode)(index-2); + generalSettings.beeperMode = (GeneralSettings::BeeperMode)(index-2); emit modified(); } @@ -565,7 +565,7 @@ void GeneralSetupPanel::on_displayTypeCB_currentIndexChanged(int index) void GeneralSetupPanel::on_hapticmodeCB_currentIndexChanged(int index) { - generalSettings.hapticMode = (BeeperMode)(index-2); + generalSettings.hapticMode = (GeneralSettings::BeeperMode)(index-2); emit modified(); } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index f04d8eb3c..896ff2e98 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -412,11 +412,9 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin } for (int i=-GetCurrentFirmware()->getCapability(SwitchesPositions); i<0; i++) { + if (IS_TARANIS(GetCurrentFirmware()->getBoard()) && !generalSettings.switchPositionAllowedTaranis(i)) + continue; item = RawSwitch(SWITCH_TYPE_SWITCH, i); - if (IS_TARANIS(GetCurrentFirmware()->getBoard())) { - //hide up and down for !SH and !SF, because they are redundant (!SFup == SFdown) - if (item.toString().contains("H") || item.toString().contains("F")) continue; - } b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); } @@ -435,6 +433,8 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin } for (int i=1; i<=GetCurrentFirmware()->getCapability(SwitchesPositions); i++) { + if (IS_TARANIS(GetCurrentFirmware()->getBoard()) && !generalSettings.switchPositionAllowedTaranis(i)) + continue; item = RawSwitch(SWITCH_TYPE_SWITCH, i); b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 920041c31..4dbfe3fcb 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -453,15 +453,22 @@ SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & gen connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(onBeepCenterToggled(bool))); centerBeepCheckboxes << checkbox; if (!IS_TARANIS_PLUS(board) && i==6) { - checkbox->hide(); + checkbox->hide(); } } // Startup switches warnings - for (int i=0; igetCapability(Switches)-1; i++) { + for (int i=0; igetCapability(Switches); i++) { + if (!IS_TARANIS(firmware->getBoard()) && i==firmware->getCapability(Switches)-1) + continue; QLabel * label = new QLabel(this); QSlider * slider = new QSlider(this); QCheckBox * cb = new QCheckBox(this); + if (IS_TARANIS(firmware->getBoard()) && !generalSettings.isSwitchWarningAllowedTaranis(i)) { + label->hide(); + slider->hide(); + cb->hide(); + } slider->setProperty("index", i+1); slider->setOrientation(Qt::Vertical); slider->setMinimum(0); @@ -474,7 +481,7 @@ SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & gen slider->setMaximumSize(QSize(50, 50)); if (IS_TARANIS(board)) { label->setText(switchesX9D[i]); - slider->setMaximum(i==5 ? 1 : 2); + slider->setMaximum((i==5 || i>=7) ? 1 : 2); } else { label->setText(switches9X[i]); @@ -677,17 +684,21 @@ void SetupPanel::updateStartupSwitches() unsigned int switchStates = model->switchWarningStates; - for (int i=0; igetCapability(Switches)-1; i++) { + for (int i=0; igetCapability(Switches); i++) { QSlider * slider = startupSwitchesSliders[i]; QCheckBox * cb = startupSwitchesCheckboxes[i]; - bool enabled = !(model->nSwToWarn & (1 << i)); + bool enabled = !(model->switchWarningEnable & (1 << i)); slider->setEnabled(enabled); cb->setChecked(enabled); if (IS_TARANIS(GetEepromInterface()->getBoard())) { - slider->setValue(i==5 ? (switchStates & 0x3)/2 : switchStates & 0x3); + slider->setValue((i==5 || i>=7) ? (switchStates & 0x3)/2 : switchStates & 0x3); switchStates >>= 2; } else { + if (i == firmware->getCapability(Switches)-1) { + // Trainer switch, no switch warning + continue; + } slider->setValue(i==0 ? switchStates & 0x3 : switchStates & 0x1); switchStates >>= (i==0 ? 2 : 1); } @@ -704,7 +715,7 @@ void SetupPanel::startupSwitchEdited(int value) int index = sender()->property("index").toInt(); if (IS_TARANIS(GetEepromInterface()->getBoard())) { - if (index == 6) { + if (index == 6 || index >= 8) { shift = (index - 1) * 2; mask = 0x02 << shift; shift++; @@ -741,9 +752,9 @@ void SetupPanel::startupSwitchToggled(bool checked) int index = sender()->property("index").toInt()-1; if (checked) - model->nSwToWarn &= ~(1 << index); + model->switchWarningEnable &= ~(1 << index); else - model->nSwToWarn |= (1 << index); + model->switchWarningEnable |= (1 << index); updateStartupSwitches(); emit modified(); diff --git a/companion/src/shared/CMakeLists.txt b/companion/src/shared/CMakeLists.txt index 4fc2266f7..b5582ad6d 100644 --- a/companion/src/shared/CMakeLists.txt +++ b/companion/src/shared/CMakeLists.txt @@ -12,6 +12,7 @@ set(shared_HDRS autocombobox.h autodoublespinbox.h autohexspinbox.h + autolineedit.h genericpanel.h hexspinbox.h verticalscrollarea.h diff --git a/companion/src/shared/autocombobox.h b/companion/src/shared/autocombobox.h index ad370d83b..d106359af 100644 --- a/companion/src/shared/autocombobox.h +++ b/companion/src/shared/autocombobox.h @@ -2,7 +2,7 @@ #define AUTOCOMBOBOX_H_ #include -#include "modeledit/modeledit.h" +#include "genericpanel.h" class AutoComboBox: public QComboBox { @@ -35,7 +35,7 @@ class AutoComboBox: public QComboBox lock = false; } - void setField(unsigned int & field, ModelPanel * panel=NULL) + void setField(unsigned int & field, GenericPanel * panel=NULL) { this->field = (int *)&field; this->panel = panel; @@ -46,7 +46,7 @@ class AutoComboBox: public QComboBox } } - void setField(int & field, ModelPanel * panel=NULL) + void setField(int & field, GenericPanel * panel=NULL) { this->field = &field; this->panel = panel; @@ -70,7 +70,7 @@ class AutoComboBox: public QComboBox protected: int * field; - ModelPanel * panel; + GenericPanel * panel; bool lock; }; diff --git a/companion/src/shared/autolineedit.h b/companion/src/shared/autolineedit.h new file mode 100755 index 000000000..154dd55e6 --- /dev/null +++ b/companion/src/shared/autolineedit.h @@ -0,0 +1,60 @@ +#ifndef AUTOLINEEDIT_H_ +#define AUTOLINEEDIT_H_ + +#include +#include +#include "genericpanel.h" + +#define CHAR_FOR_NAMES_REGEX "[ A-Za-z0-9_.-,]*" + +class AutoLineEdit: public QLineEdit +{ + Q_OBJECT + + public: + explicit AutoLineEdit(QWidget *parent = 0): + QLineEdit(parent), + field(NULL), + panel(NULL), + lock(false) + { + QRegExp rx(CHAR_FOR_NAMES_REGEX); + setValidator(new QRegExpValidator(rx, this)); + connect(this, SIGNAL(editingFinished()), this, SLOT(onEdited())); + } + + void setField(char * field, int len, GenericPanel * panel=NULL) + { + this->field = field; + this->panel = panel; + setMaxLength(len); + updateValue(); + } + + void updateValue() + { + lock = true; + if (field) { + setText(field); + } + lock = false; + } + + protected slots: + void onEdited() + { + if (field && !lock) { + strcpy(field, text().toAscii()); + if (panel) { + emit panel->modified(); + } + } + } + + protected: + char * field; + GenericPanel * panel; + bool lock; +}; + +#endif /* AUTOLINEEDIT_H_ */ diff --git a/companion/src/shared/genericpanel.h b/companion/src/shared/genericpanel.h index eafb27c34..26983e634 100644 --- a/companion/src/shared/genericpanel.h +++ b/companion/src/shared/genericpanel.h @@ -17,6 +17,7 @@ class GenericPanel : public QWidget friend class AutoDoubleSpinBox; friend class AutoCheckBox; friend class AutoHexSpinBox; + friend class AutoLineEdit; public: GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware); diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 2ed72a5b8..ab929420a 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -90,6 +90,20 @@ #define AVR_FIELD(x) x; #endif +#if defined(PCBSTD) + #define N_PCBSTD_FIELD(x) +#else + #define N_PCBSTD_FIELD(x) x; +#endif + +#if defined(PCBTARANIS) + #define N_TARANIS_FIELD(x) + #define TARANIS_FIELD(x) x; +#else + #define N_TARANIS_FIELD(x) x; + #define TARANIS_FIELD(x) +#endif + #define NUM_STICKS 4 #if defined(PCBTARANIS) @@ -623,18 +637,6 @@ enum SwitchConfig { #define LEN_SWITCH_NAME 3 #define LEN_ANA_NAME 3 -#if defined(PCBSTD) - #define N_PCBSTD_FIELD(x) -#else - #define N_PCBSTD_FIELD(x) x; -#endif - -#if defined(PCBTARANIS) - #define N_TARANIS_FIELD(x) -#else - #define N_TARANIS_FIELD(x) x; -#endif - #define ALTERNATE_VIEW 0x10 PACK(typedef struct t_EEGeneral { uint8_t version; @@ -681,15 +683,15 @@ PACK(typedef struct t_EEGeneral { EXTRA_GENERAL_FIELDS - ARM_FIELD(swarnstate_t switchUnlockStates) + TARANIS_FIELD(swarnstate_t switchUnlockStates) ARM_FIELD(CustomFunctionData customFn[NUM_CFN]) - ARM_FIELD(uint32_t switchConfig) + TARANIS_FIELD(uint32_t switchConfig) - ARM_FIELD(char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]) + TARANIS_FIELD(char switchNames[NUM_SWITCHES][LEN_SWITCH_NAME]) - ARM_FIELD(char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]) + TARANIS_FIELD(char anaNames[NUM_STICKS+NUM_POTS][LEN_ANA_NAME]) }) EEGeneral;