diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index cd6843d5a..be2c6d429 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -268,6 +268,10 @@ QString RawSwitch::toString() QObject::tr("S21"), QObject::tr("S22"), QObject::tr("S23"), QObject::tr("S24"), QObject::tr("S25"), QObject::tr("S26") }; + static const QString rotaryEncoders[] = { + QObject::tr("REa"), QObject::tr("REb") + }; + switch(type) { case SWITCH_TYPE_SWITCH: if (IS_TARANIS(GetEepromInterface()->getBoard())) @@ -278,6 +282,8 @@ QString RawSwitch::toString() return index > 0 ? CHECK_IN_ARRAY(virtualSwitches, index-1) : QString("!") + CHECK_IN_ARRAY(virtualSwitches, -index-1); case SWITCH_TYPE_MULTIPOS_POT: return CHECK_IN_ARRAY(multiposPots, index); + case SWITCH_TYPE_ROTARY_ENCODER: + return CHECK_IN_ARRAY(rotaryEncoders, index); case SWITCH_TYPE_ON: return QObject::tr("ON"); case SWITCH_TYPE_OFF: diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 9525b47d6..e072a83c8 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -318,6 +318,7 @@ enum RawSwitchType { SWITCH_TYPE_SWITCH, SWITCH_TYPE_VIRTUAL, SWITCH_TYPE_MULTIPOS_POT, + SWITCH_TYPE_ROTARY_ENCODER, SWITCH_TYPE_ON, SWITCH_TYPE_OFF }; diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index c02045546..1522e44fa 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -506,18 +506,22 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, } } - for (int i=1; i<=GetEepromInterface()->getCapability(CustomSwitches); i++) { - item = RawSwitch(SWITCH_TYPE_VIRTUAL, i); + for (int i=0; igetCapability(MultiposPots) * GetEepromInterface()->getCapability(MultiposPotsPositions); i++) { + item = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i); b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); } - if (IS_TARANIS(GetEepromInterface()->getBoard())) { - for (int i=0; igetCapability(MultiposPots) * GetEepromInterface()->getCapability(MultiposPotsPositions); i++) { - item = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i); - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); - } + for (int i=0; igetCapability(RotaryEncoders); i++) { + item = RawSwitch(SWITCH_TYPE_ROTARY_ENCODER, i); + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); + } + + for (int i=1; i<=GetEepromInterface()->getCapability(CustomSwitches); i++) { + item = RawSwitch(SWITCH_TYPE_VIRTUAL, i); + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); } if (attr & POPULATE_ONOFF) { diff --git a/radio/src/eeprom_conversions.cpp b/radio/src/eeprom_conversions.cpp index f06e02e09..4bf4d38d8 100644 --- a/radio/src/eeprom_conversions.cpp +++ b/radio/src/eeprom_conversions.cpp @@ -196,15 +196,18 @@ void ConvertGeneralSettings_215_to_216(EEGeneral &settings) #if defined(PCBTARANIS) int ConvertSwitch_215_to_216(int swtch) { - if (swtch < SWSRC_ON) + if (swtch <= SWSRC_LAST_SWITCH) return swtch; else - return swtch + (2*6); // 2 * 6-pos pots added as switches + return swtch + 4 + (2*6); // 4 trims and 2 * 6-pos added as switches } #else inline int ConvertSwitch_215_to_216(int swtch) { - return swtch; + if (swtch <= SWSRC_LAST_SWITCH) + return swtch; + else + return swtch + 4 + 1; // 4 trims and REa added } #endif @@ -219,7 +222,7 @@ void ConvertModel_215_to_216(ModelData &model) // Custom Switches: better precision for x when A comes from telemetry // Main View: altitude in top bar // Mixes: GVARS in weight moved from 512 to 4096 and -512 to -4096, because GVARS may be used in limits [-1250:1250] - // Switches: two 6-pos pots added + // Switches: two 6-pos pots added, REa added to Sky9x TRACE("Model conversion from v215 to v216"); diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index cfd6474d1..7f54eb54e 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -4483,7 +4483,7 @@ void menuModelCustomSwitches(uint8_t event) v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1; v2_min = SWSRC_OFF+1; v2_max = SWSRC_ON-1; INCDEC_SET_FLAG(INCDEC_SWITCH); - INCDEC_ENABLE_CHECK(NULL); + INCDEC_ENABLE_CHECK(isSwitchAvailableInCustomSwitches); } else if (cstate == CS_VCOMP) { putsMixerSource(CSW_2ND_COLUMN, y, cs->v1, attr1); diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 69916bc19..d45e91d61 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -1260,7 +1260,7 @@ bool isInputSourceAvailable(int16_t source) return false; } -bool isSwitchAvailable(int16_t swtch) +bool isSwitchAvailableInCustomSwitches(int16_t swtch) { if (swtch < 0) { if (swtch <= -SWSRC_ON) @@ -1286,6 +1286,15 @@ bool isSwitchAvailable(int16_t swtch) } #endif + return true; +} + +bool isSwitchAvailable(int16_t swtch) +{ + if (!isSwitchAvailableInCustomSwitches(swtch)) { + return false; + } + if (swtch >= SWSRC_FIRST_CSW && swtch <= SWSRC_LAST_CSW) { CustomSwData * cs = cswAddress(swtch-SWSRC_FIRST_CSW); return (cs->func != CS_OFF); @@ -1293,4 +1302,6 @@ bool isSwitchAvailable(int16_t swtch) return true; } + + #endif diff --git a/radio/src/gui/menus.h b/radio/src/gui/menus.h index 15080b7f2..3b4e44e59 100644 --- a/radio/src/gui/menus.h +++ b/radio/src/gui/menus.h @@ -191,6 +191,7 @@ int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max); #if defined(CPUARM) bool isSwitchAvailable(int16_t swtch); + bool isSwitchAvailableInCustomSwitches(int16_t swtch); #define AUTOSWITCH_ENTER_LONG() (attr && event==EVT_KEY_LONG(KEY_ENTER)) #define CHECK_INCDEC_MODELSWITCH(event, var, min, max) \ var = checkIncDec(event,var,min,max,EE_MODEL|INCDEC_SWITCH|NO_INCDEC_MARKS, isSwitchAvailable) diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index b95760e55..96dc9ffac 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -1165,6 +1165,7 @@ enum SwitchSources { SWSRC_SG2, SWSRC_SH0, SWSRC_SH2, + SWSRC_TRAINER = SWSRC_SH2, #else SWSRC_ID0 = SWSRC_FIRST_SWITCH, SWSRC_ID1, @@ -1180,11 +1181,39 @@ enum SwitchSources { SWSRC_AIL, SWSRC_GEA, SWSRC_TRN, + SWSRC_TRAINER = SWSRC_TRN, +#endif + + SWSRC_LAST_SWITCH = SWSRC_TRAINER, + +#if defined(PCBTARANIS) + SWSRC_P11, + SWSRC_P16 = SWSRC_P11+5, + SWSRC_P21, + SWSRC_P26 = SWSRC_P21+5, +#endif + +#if defined(CPUARM) + SWSRC_FIRST_TRIM, + SWSRC_TrimRudLeft = SWSRC_FIRST_TRIM, + SWSRC_TrimRudRight, + SWSRC_TrimEleDown, + SWSRC_TrimEleUp, + SWSRC_TrimThrDown, + SWSRC_TrimThrUp, + SWSRC_TrimAilLeft, + SWSRC_TrimAilRight, + SWSRC_LAST_TRIM = SWSRC_TrimAilRight, +#endif + +#if defined(PCBSKY9X) + SWSRC_REa, +#elif defined(PCBGRUVIN9X) || defined(PCBMEGA2560) + SWSRC_REa, + SWSRC_REb, #endif SWSRC_FIRST_CSW, - SWSRC_LAST_SWITCH = SWSRC_FIRST_CSW-1, - SWSRC_SW1 = SWSRC_FIRST_CSW, SWSRC_SW2, SWSRC_SW3, @@ -1199,18 +1228,9 @@ enum SwitchSources { SWSRC_SWC, SWSRC_LAST_CSW = SWSRC_SW1+NUM_CSW-1, -#if defined(PCBTARANIS) - SWSRC_P11, - SWSRC_P16 = SWSRC_P11+5, - SWSRC_P21, - SWSRC_P26 = SWSRC_P21+5, -#endif - SWSRC_ON, SWSRC_OFF = -SWSRC_ON, - SWSRC_TRAINER = SWSRC_SW1-1, - SWSRC_FIRST = SWSRC_OFF, SWSRC_LAST = SWSRC_ON }; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 7d5514e2d..f48586a20 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1386,9 +1386,24 @@ bool getSwitch(int8_t swtch) result = SWITCH_POSITION(cs_idx-SWSRC_FIRST_SWITCH); } #if defined(PCBTARANIS) - else if (cs_idx >= SWSRC_P11 && cs_idx <= SWSRC_P26) { + else if (cs_idx <= SWSRC_P26) { result = POT_POSITION(cs_idx-SWSRC_P11); } +#endif +#if defined(CPUARM) + else if (cs_idx <= SWSRC_LAST_TRIM) { + result = readTrims() & (1 << (cs_idx-SWSRC_FIRST_TRIM)); + } +#endif +#if ROTARY_ENCODERS > 0 + else if (cs_idx == SWSRC_REa) { + result = REA_DOWN(); + } +#endif +#if ROTARY_ENCODERS > 1 + else if (cs_idx == SWSRC_REb) { + result = REB_DOWN(); + } #endif else { cs_idx -= SWSRC_FIRST_CSW; @@ -3072,8 +3087,9 @@ void evalFunctions() } #if defined(GVARS) - for (uint8_t i=0; i> 3; - for (int i=1; i<7; i++) - { + for (int i=1; i<7; i++) { //INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6 - keys[enuk].input(in & (1< 0 - #define rotencDown() (!(PIOB->PIO_PDSR & 0x40)) + #define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40)) #else - #define rotencDown() 0 + #define REA_DOWN() (0) #endif // Debug driver diff --git a/radio/src/targets/sky9x/keys_driver.cpp b/radio/src/targets/sky9x/keys_driver.cpp index 604db4f8b..43e9ada11 100644 --- a/radio/src/targets/sky9x/keys_driver.cpp +++ b/radio/src/targets/sky9x/keys_driver.cpp @@ -115,7 +115,7 @@ uint32_t readTrims() uint8_t keyDown() { - return (~readKeys() & 0x7E) || rotencDown(); + return (~readKeys() & 0x7E) || REA_DOWN(); } void readKeysAndTrims() @@ -123,7 +123,7 @@ void readKeysAndTrims() register uint32_t i; #if ROTARY_ENCODERS > 0 - keys[BTN_REa].input(rotencDown(), BTN_REa); + keys[BTN_REa].input(REA_DOWN(), BTN_REa); #endif uint8_t enuk = KEY_MENU; diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index 070b76b03..0676113ea 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -338,21 +338,26 @@ #define TR_CUSTOMSW "CS1""CS2""CS3""CS4""CS5""CS6""CS7""CS8""CS9""CSA""CSB""CSC" #endif -#if defined(PCBTARANIS) - #define TR_6POS_POTS "P11""P12""P13""P14""P15""P16""P21""P22""P23""P24""P25""P26" - #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_CUSTOMSW TR_6POS_POTS -#else - #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW -#endif +#define TR_TRIMS_SWITCHES "tRl""tRr""tEd""tEu""tTd""tTu""tAl""tAr" #if defined(PCBSKY9X) - #define TR_ROTARY_ENCODERS_VSRCRAW "REnc" -#elif defined(PCBGRUVIN9X) && ROTARY_ENCODERS > 2 - #define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb ""REc ""REd " -#elif defined(PCBGRUVIN9X) && ROTARY_ENCODERS <= 2 - #define TR_ROTARY_ENCODERS_VSRCRAW "REa ""REb " + #define TR_ROTARY_ENCODERS "REa\0" + #define TR_ROTENC_SWITCHES "REa" +#elif defined(PCBGRUVIN9X) || defined(PCBMEGA2560) + #define TR_ROTARY_ENCODERS "REa\0""REb\0" + #define TR_ROTENC_SWITCHES "REa""REb" #else - #define TR_ROTARY_ENCODERS_VSRCRAW + #define TR_ROTARY_ENCODERS + #define TR_ROTENC_SWITCHES +#endif + +#if defined(PCBTARANIS) + #define TR_6POS_POTS "P11""P12""P13""P14""P15""P16""P21""P22""P23""P24""P25""P26" + #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_CUSTOMSW +#elif defined(CPUARM) + #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_TRIMS_SWITCHES TR_ROTENC_SWITCHES TR_CUSTOMSW +#else + #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_ROTENC_SWITCHES TR_CUSTOMSW #endif #if defined(HELI) @@ -361,7 +366,7 @@ #define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]" #endif -#define TR_VSRCRAW "---\0""Rud\0""Ele\0""Thr\0""Ail\0" TR_POTS_VSRCRAW TR_ROTARY_ENCODERS_VSRCRAW "MAX\0" TR_CYC_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" TR_SW_VSRCRAW +#define TR_VSRCRAW "---\0""Rud\0""Ele\0""Thr\0""Ail\0" TR_POTS_VSRCRAW TR_ROTARY_ENCODERS "MAX\0" TR_CYC_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" TR_SW_VSRCRAW #define LEN_VTMRMODES "\003" #define TR_VTMRMODES "OFF""ABS""THs""TH%""THt"