From 1c8b865d89b6cc5fd80e27af6e6b6a69c25da263 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Tue, 31 Dec 2013 13:02:53 +0100 Subject: [PATCH 01/12] [Taranis] Support for the 6POS Pots --- radio/src/eeprom_conversions.cpp | 20 +++++++++-- radio/src/gtests.cpp | 4 +-- radio/src/gui/menu_model.cpp | 6 ++-- radio/src/gui/menus.cpp | 10 +++--- radio/src/lcd.cpp | 2 +- radio/src/myeeprom.h | 13 +++++-- radio/src/opentx.cpp | 61 +++++++++++++++++++++----------- radio/src/opentx.h | 6 ++-- radio/src/translations/cz.h.txt | 3 +- radio/src/translations/de.h.txt | 3 +- radio/src/translations/en.h | 3 +- radio/src/translations/es.h.txt | 3 +- radio/src/translations/fr.h.txt | 3 +- radio/src/translations/it.h.txt | 3 +- radio/src/translations/pl.h.txt | 3 +- radio/src/translations/pt.h.txt | 3 +- radio/src/translations/se.h.txt | 3 +- 17 files changed, 101 insertions(+), 48 deletions(-) diff --git a/radio/src/eeprom_conversions.cpp b/radio/src/eeprom_conversions.cpp index 6edb00974..9bff69abf 100644 --- a/radio/src/eeprom_conversions.cpp +++ b/radio/src/eeprom_conversions.cpp @@ -177,6 +177,21 @@ void ConvertGeneralSettings_215_to_216(EEGeneral &settings) settings.version = 216; } +#if defined(PCBTARANIS) +int ConvertSwitch_215_to_216(int swtch) +{ + if (swtch < SWSRC_ON) + return swtch; + else + return swtch + (2*6); // 2 * 6-pos pots added as switches +} +#else +inline int ConvertSwitch_215_to_216(int swtch) +{ + return swtch; +} +#endif + void ConvertModel_215_to_216(ModelData &model) { // Virtual inputs added instead of Expo/DR @@ -188,6 +203,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 TRACE("Model conversion from v215 to v216"); @@ -221,7 +237,7 @@ void ConvertModel_215_to_216(ModelData &model) g_model.mixData[i].phases = oldModel.mixData[i].phases; g_model.mixData[i].mltpx = oldModel.mixData[i].mltpx; g_model.mixData[i].weight = oldModel.mixData[i].weight; - g_model.mixData[i].swtch = oldModel.mixData[i].swtch; + g_model.mixData[i].swtch = ConvertSwitch_215_to_216(oldModel.mixData[i].swtch); if (oldModel.mixData[i].curveMode==0/*differential*/) { g_model.mixData[i].curve.type = CURVE_REF_DIFF; g_model.mixData[i].curve.value = oldModel.mixData[i].curveParam; @@ -281,7 +297,7 @@ void ConvertModel_215_to_216(ModelData &model) } g_model.expoData[i].srcRaw = MIXSRC_Rud+chn; g_model.expoData[i].chn = chn; - g_model.expoData[i].swtch = oldModel.expoData[i].swtch; + g_model.expoData[i].swtch = ConvertSwitch_215_to_216(oldModel.expoData[i].swtch); g_model.expoData[i].phases = oldModel.expoData[i].phases; g_model.expoData[i].weight = oldModel.expoData[i].weight; memcpy(&g_model.expoData[i].name, &oldModel.expoData[i].name, LEN_EXPOMIX_NAME); diff --git a/radio/src/gtests.cpp b/radio/src/gtests.cpp index 2b8d8f2e8..fe6cb1a0a 100644 --- a/radio/src/gtests.cpp +++ b/radio/src/gtests.cpp @@ -295,8 +295,8 @@ TEST(FrSkySPORT, checkCrc) TEST(getSwitch, undefCSW) { MODEL_RESET(); - EXPECT_EQ(getSwitch(MAX_PSWITCH), false); - EXPECT_EQ(getSwitch(-MAX_PSWITCH), true); // no good answer there! + EXPECT_EQ(getSwitch(NUM_PSWITCH), false); + EXPECT_EQ(getSwitch(-NUM_PSWITCH), true); // no good answer there! } #endif diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index d1f9889fb..c2f472a47 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -1055,7 +1055,7 @@ void menuModelSetup(uint8_t event) div_t qr = div(timer->start, 60); switch (m_posHorz) { case 0: - CHECK_INCDEC_MODELVAR(event, timer->mode, -2*(MAX_PSWITCH+NUM_CSW), TMR_VAROFS-1+2*(MAX_PSWITCH+NUM_CSW)); + CHECK_INCDEC_MODELVAR(event, timer->mode, -2*(NUM_PSWITCH+NUM_CSW), TMR_VAROFS-1+2*(NUM_PSWITCH+NUM_CSW)); break; case 1: CHECK_INCDEC_MODELVAR_ZERO(event, qr.quot, 59); @@ -1835,7 +1835,7 @@ void menuModelFlightModesAll(uint8_t event) } else { putsSwitches((5+LEN_FP_NAME)*FW+FW/2, y, p->swtch, attr); - if (active) CHECK_INCDEC_MODELSWITCH(event, p->swtch, -MAX_SWITCH, MAX_SWITCH); + if (active) CHECK_INCDEC_MODELSWITCH(event, p->swtch, -NUM_SWITCH, NUM_SWITCH); } break; @@ -4290,7 +4290,7 @@ void menuModelCustomSwitchOne(uint8_t event) case CSW_FIELD_ANDSW: lcd_putsLeft(y, STR_AND_SWITCH); putsSwitches(CSWONE_2ND_COLUMN, y, cs->andsw, attr); - if (attr) CHECK_INCDEC_MODELVAR(event, cs->andsw, -MAX_SWITCH, MAX_SWITCH); + if (attr) CHECK_INCDEC_MODELVAR(event, cs->andsw, -NUM_SWITCH, NUM_SWITCH); break; case CSW_FIELD_DURATION: lcd_putsLeft(y, STR_DURATION); diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 5580a998d..69af3f0fa 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -232,13 +232,13 @@ int16_t checkIncDec(uint8_t event, int16_t val, int16_t i_min, int16_t i_max, ui if (event == EVT_KEY_LONG(KEY_ENTER) && i_max > SWSRC_ON) { s_editMode = !s_editMode; if (newval > SWSRC_ON) - newval -= (MAX_SWITCH+1); + newval -= (NUM_SWITCH+1); else if (newval > 0) - newval += (MAX_SWITCH+1); + newval += (NUM_SWITCH+1); else if (newval < SWSRC_OFF) - newval += (MAX_SWITCH+1); + newval += (NUM_SWITCH+1); else if (newval < 0) - newval -= (MAX_SWITCH+1); + newval -= (NUM_SWITCH+1); } } #endif @@ -976,7 +976,7 @@ int8_t switchMenuItem(uint8_t x, uint8_t y, int8_t value, LcdFlags attr, uint8_t { lcd_putsColumnLeft(x, y, STR_SWITCH); putsSwitches(x, y, value, attr); - if (attr) CHECK_INCDEC_MODELSWITCH(event, value, -MAX_SWITCH, MAX_SWITCH); + if (attr) CHECK_INCDEC_MODELSWITCH(event, value, -NUM_SWITCH, NUM_SWITCH); return value; } diff --git a/radio/src/lcd.cpp b/radio/src/lcd.cpp index b8702878d..c02ffd5a0 100644 --- a/radio/src/lcd.cpp +++ b/radio/src/lcd.cpp @@ -1097,7 +1097,7 @@ void putsTmrMode(xcoord_t x, uint8_t y, int8_t mode, LcdFlags att) return; } - if (mode >= TMR_VAROFS+MAX_PSWITCH+NUM_CSW) { + if (mode >= TMR_VAROFS+NUM_PSWITCH+NUM_CSW) { mode++; } diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 3c49e6f59..5343ef424 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -639,7 +639,7 @@ PACK( union u_int8int16_t { #if defined(CPUARM) #define MAX_CSW_DURATION 120 /*60s*/ #define MAX_CSW_DELAY 120 /*60s*/ -#define MAX_CSW_ANDSW MAX_SWITCH +#define MAX_CSW_ANDSW NUM_SWITCH typedef int16_t csw_telemetry_value_t; PACK(typedef struct t_CustomSwData { // Custom Switches data int16_t v1; @@ -1140,6 +1140,8 @@ enum SwitchSources { #endif SWSRC_FIRST_CSW, + SWSRC_LAST_SWITCH = SWSRC_FIRST_CSW-1, + SWSRC_SW1 = SWSRC_FIRST_CSW, SWSRC_SW2, SWSRC_SW3, @@ -1154,10 +1156,17 @@ 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_FIRST_MOMENT_SWITCH, - SWSRC_LAST_MOMENT_SWITCH = SWSRC_FIRST_MOMENT_SWITCH+SWSRC_ON-1, + SWSRC_LAST_MOMENT_SWITCH = SWSRC_FIRST_MOMENT_SWITCH+SWSRC_LAST_CSW, #if !defined(PCBSTD) SWSRC_TRAINER_SHORT, diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index af664925e..d3c6f5e2d 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1301,6 +1301,8 @@ uint8_t cswStates[NUM_CSW]; #if defined(PCBTARANIS) tmr10ms_t switchesMidposStart[6] = { 0 }; uint32_t switchesPos = 0; +tmr10ms_t potsLastposStart[2]; +uint8_t potsPos[2]; #define DELAY_SWITCH_3POS 10/*100ms*/ #define CHECK_2POS(sw) newPos |= (switchState(sw ## 0) ? (1 << (sw ## 0 - SW_SA0)) : (1 << (sw ## 0 - SW_SA0 + 1))) #define CHECK_3POS(idx, sw) if (switchState(sw ## 0)) { \ @@ -1321,8 +1323,7 @@ uint32_t switchesPos = 0; } \ newPos |= (switchesPos & (0x7 << (sw ## 0 - SW_SA0))); \ } -#define SWITCH_POSITION(sw) (switchesPos & (1<<(sw))) -void get3POSSwitchesPosition() +void getSwitchesPosition() { uint32_t newPos = 0; CHECK_3POS(0, SW_SA); @@ -1334,9 +1335,26 @@ void get3POSSwitchesPosition() CHECK_3POS(5, SW_SG); CHECK_2POS(SW_SH); switchesPos = newPos; + + for (int i=0; i<2; i++) { + int val = RESX + (int16_t)anaIn(POT1+i) + (RESX / 5); + uint8_t pos = limit(0, val / (2*RESX/5), 5); + uint8_t previousPos = potsPos[i] >> 4; + if (pos != previousPos) { + potsLastposStart[i] = get_tmr10ms(); + potsPos[i] = (pos << 4) | (potsPos[i] & 0x0f); + } + else if ((tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { + potsLastposStart[i] = 0; + potsPos[i] = (pos << 4) | (pos); + } + } } +#define SWITCH_POSITION(sw) (switchesPos & (1<<(sw))) +#define POT_POSITION(sw) ((potsPos[(sw)/6] & 0x0f) == ((sw) % 6)) #else -#define get3POSSwitchesPosition() +#define getSwitchesPosition() +#define SWITCH_POSITION(idx) switchState((EnumKeys)(SW_BASE+(idx))) #endif int16_t csLastValue[NUM_CSW]; @@ -1353,15 +1371,16 @@ bool getSwitch(int8_t swtch) if (cs_idx == SWSRC_ON) { result = true; } - else if (cs_idx <= MAX_PSWITCH) { -#if defined(PCBTARANIS) - result = SWITCH_POSITION(cs_idx-SWSRC_SA0); -#else - result = switchState((EnumKeys)(SW_BASE+cs_idx-1)); -#endif + else if (cs_idx <= SWSRC_LAST_SWITCH) { + result = SWITCH_POSITION(cs_idx-SWSRC_FIRST_SWITCH); } +#if defined(PCBTARANIS) + else if (cs_idx >= SWSRC_P11 && cs_idx <= SWSRC_P26) { + result = POT_POSITION(cs_idx-SWSRC_P11); + } +#endif else { - cs_idx -= MAX_PSWITCH+1; + cs_idx -= SWSRC_FIRST_CSW; GETSWITCH_RECURSIVE_TYPE mask = ((GETSWITCH_RECURSIVE_TYPE)1 << cs_idx); if (s_last_switch_used & mask) { @@ -1550,7 +1569,7 @@ int8_t getMovedSwitch() } } #else - for (uint8_t i=MAX_PSWITCH; i>0; i--) { + for (uint8_t i=NUM_PSWITCH; i>0; i--) { bool prev; swstate_t mask = 0; if (i <= 3) { @@ -1562,7 +1581,7 @@ int8_t getMovedSwitch() } bool next = getSwitch(i); if (prev != next) { - if (i!=MAX_PSWITCH || next==true) + if (i!=NUM_PSWITCH || next==true) result = next ? i : -i; if (mask) switches_states ^= mask; @@ -2203,7 +2222,7 @@ void checkSwitches() } #else uint8_t x = 2; - for (uint8_t i=1; i2?(i+1):1+((states>>1)&0x3)), attr); if (i == 1 && attr) i++; @@ -3053,13 +3072,13 @@ void evalFunctions() #endif - if (swtch > MAX_SWITCH+1) { + if (swtch > NUM_SWITCH+1) { momentary = 1; - swtch -= MAX_SWITCH+1; + swtch -= NUM_SWITCH+1; } - if (swtch < -MAX_SWITCH-1) { + if (swtch < -NUM_SWITCH-1) { momentary = 1; - swtch += MAX_SWITCH+1; + swtch += NUM_SWITCH+1; } bool active = getSwitch(swtch); @@ -3684,7 +3703,7 @@ void doMixerCalculations() // therefore forget the exact calculation and use only 1 instead; good compromise lastTMR = tmr10ms; - get3POSSwitchesPosition(); + getSwitchesPosition(); getADC(); @@ -3871,9 +3890,9 @@ void doMixerCalculations() timerState->sum+=val; } - if (atm>=(TMR_VAROFS+MAX_SWITCH)){ // toggeled switch + if (atm>=(TMR_VAROFS+NUM_SWITCH)){ // toggeled switch if(!(timerState->toggled | timerState->sum | timerState->cnt | timerState->lastPos)) { timerState->lastPos = tm < 0; timerState->sum = 1; } // if initializing then init the lastPos - uint8_t swPos = getSwitch(tm>0 ? tm-(TMR_VAROFS+MAX_SWITCH-1) : tm+MAX_SWITCH); + uint8_t swPos = getSwitch(tm>0 ? tm-(TMR_VAROFS+NUM_SWITCH-1) : tm+NUM_SWITCH); if (swPos && !timerState->lastPos) timerState->toggled = !timerState->toggled; // if switch is flipped first time -> change counter state timerState->lastPos = swPos; } @@ -3910,7 +3929,7 @@ void doMixerCalculations() newTimerVal++; } else { - if (atm<(TMR_VAROFS+MAX_SWITCH)) + if (atm<(TMR_VAROFS+NUM_SWITCH)) timerState->toggled = tm>0 ? getSwitch(tm-(TMR_VAROFS-1)) : !getSwitch(-tm); // normal switch if (timerState->toggled) newTimerVal++; diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 1ce0294b7..b432a53c0 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -376,8 +376,8 @@ enum EnumKeys { #if defined(PCBTARANIS) #define NUM_SWITCHES 8 #define IS_3POS(sw) ((sw) != 5 && (sw) != 7) - #define MAX_PSWITCH (SW_SH2-SW_SA0+1) #define NUM_POTS 4 + #define NUM_POTSSW (2*6) #define NUM_SW_SRCRAW 8 #define SWSRC_THR SWSRC_SF2 #define SWSRC_GEA SWSRC_SG2 @@ -389,13 +389,13 @@ enum EnumKeys { #define NUM_SWITCHES 7 #define IS_3POS(sw) ((sw) == 0) #define IS_MOMENTARY(sw) (sw == SWSRC_TRN) - #define MAX_PSWITCH (SW_TRN-SW_ID0+1) // 9 physical switches #define NUM_POTS 3 #define NUM_SW_SRCRAW 1 #define SW_DSM2_BIND SW_TRN #endif -#define MAX_SWITCH (MAX_PSWITCH+NUM_CSW) +#define NUM_PSWITCH (SWSRC_LAST_SWITCH-SWSRC_FIRST_SWITCH+1) +#define NUM_SWITCH (NUM_PSWITCH+NUM_CSW+NUM_POTSSW) #if defined(PCBTARANIS) #define KEY_RIGHT KEY_PLUS diff --git a/radio/src/translations/cz.h.txt b/radio/src/translations/cz.h.txt index 145783ff3..379444d0e 100644 --- a/radio/src/translations/cz.h.txt +++ b/radio/src/translations/cz.h.txt @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "*1 " + #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 "*1 " #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW "*1 " #endif diff --git a/radio/src/translations/de.h.txt b/radio/src/translations/de.h.txt index 8023eaf06..88490ce12 100644 --- a/radio/src/translations/de.h.txt +++ b/radio/src/translations/de.h.txt @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "ONE" + #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 "ONE" #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW "ONE" #endif diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index 62876daf9..80f25935a 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "One" + #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 "One" #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW "One" #endif diff --git a/radio/src/translations/es.h.txt b/radio/src/translations/es.h.txt index 11f626168..b689918f6 100644 --- a/radio/src/translations/es.h.txt +++ b/radio/src/translations/es.h.txt @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "Uno" + #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 "Uno" #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "ACE""DIR""ELE""ALE""GEA""TRN" TR_CUSTOMSW "Uno" #endif diff --git a/radio/src/translations/fr.h.txt b/radio/src/translations/fr.h.txt index 652776e6e..470b08b91 100644 --- a/radio/src/translations/fr.h.txt +++ b/radio/src/translations/fr.h.txt @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "1*\0" + #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 "1*\0" #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW "1*\0" #endif diff --git a/radio/src/translations/it.h.txt b/radio/src/translations/it.h.txt index 3a2c62fca..20033e41c 100644 --- a/radio/src/translations/it.h.txt +++ b/radio/src/translations/it.h.txt @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "One" + #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 "1*\0" #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW "One" #endif diff --git a/radio/src/translations/pl.h.txt b/radio/src/translations/pl.h.txt index 5525754ed..9cb38c672 100644 --- a/radio/src/translations/pl.h.txt +++ b/radio/src/translations/pl.h.txt @@ -323,7 +323,8 @@ #endif #if defined(PCBTARANIS) - #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 " * " + #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 "GAZ""SK ""LOT""SW ""GEA""TRN" TR_CUSTOMSW " * " #endif diff --git a/radio/src/translations/pt.h.txt b/radio/src/translations/pt.h.txt index 691c840af..7361bb86f 100644 --- a/radio/src/translations/pt.h.txt +++ b/radio/src/translations/pt.h.txt @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "1*\0" + #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 "1*\0" #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW "1*\0" #endif diff --git a/radio/src/translations/se.h.txt b/radio/src/translations/se.h.txt index 68de29549..71e5ede3f 100644 --- a/radio/src/translations/se.h.txt +++ b/radio/src/translations/se.h.txt @@ -322,7 +322,8 @@ #endif #if defined(PCBTARANIS) - #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 "One" + #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 "One" #else #define TR_VSWITCHES TR_9X_3POS_SWITCHES "THR""RUD""ELE""AIL""GEA""TRN" TR_CUSTOMSW "One" #endif From 33eeb4cc64d9138825e209dd6f57717dc1ba7276 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 2 Jan 2014 12:38:18 +0100 Subject: [PATCH 02/12] [all] Compilation was broken except for Taranis :( --- radio/src/opentx.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index b432a53c0..501ea65a8 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -390,6 +390,7 @@ enum EnumKeys { #define IS_3POS(sw) ((sw) == 0) #define IS_MOMENTARY(sw) (sw == SWSRC_TRN) #define NUM_POTS 3 + #define NUM_POTSSW 0 #define NUM_SW_SRCRAW 1 #define SW_DSM2_BIND SW_TRN #endif @@ -398,14 +399,14 @@ enum EnumKeys { #define NUM_SWITCH (NUM_PSWITCH+NUM_CSW+NUM_POTSSW) #if defined(PCBTARANIS) -#define KEY_RIGHT KEY_PLUS -#define KEY_LEFT KEY_MINUS -#define KEY_UP KEY_PLUS -#define KEY_DOWN KEY_MINUS + #define KEY_RIGHT KEY_PLUS + #define KEY_LEFT KEY_MINUS + #define KEY_UP KEY_PLUS + #define KEY_DOWN KEY_MINUS #else -#define KEY_ENTER KEY_MENU -#define KEY_PLUS KEY_RIGHT -#define KEY_MINUS KEY_LEFT + #define KEY_ENTER KEY_MENU + #define KEY_PLUS KEY_RIGHT + #define KEY_MINUS KEY_LEFT #endif #include "myeeprom.h" From e4b3b3af850ea87509926d7f0cd4eb229315c68c Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 6 Jan 2014 11:52:05 +0100 Subject: [PATCH 03/12] [Taranis] Automatic detection of the 6pos switch within the calibration process --- radio/src/gui/menu_general.cpp | 61 +++++++++++++++++++++++++----- radio/src/gui/menus.cpp | 9 ++++- radio/src/myeeprom.h | 27 +++++++++++-- radio/src/opentx.cpp | 69 +++++++++++++++++++++++----------- radio/src/opentx.h | 9 ++++- 5 files changed, 137 insertions(+), 38 deletions(-) diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index e6b7956ca..78d56bc2c 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -1241,16 +1241,37 @@ void menuGeneralHardware(uint8_t event) void menuCommonCalib(uint8_t event) { - for (uint8_t i=0; i= NUM_STICKS && i < NUM_STICKS+NUM_POTS-2) { -#else - if (i >= NUM_STICKS) { -#endif + if (i >= POT1 && i <= POT_LAST) { reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2; +#if defined(PCBTARANIS) + uint8_t idx = i - POT1; + int count = reusableBuffer.calib.xpotsPositionsCount[idx]; + if (count <= 6) { + bool found = false; + for (int j=0; j reusableBuffer.calib.xpotsPositions[idx][j][0]-20 && vt < reusableBuffer.calib.xpotsPositions[idx][j][0]+20) { + reusableBuffer.calib.xpotsPositions[idx][j][0] = min(vt, reusableBuffer.calib.xpotsPositions[idx][j][0]); + reusableBuffer.calib.xpotsPositions[idx][j][1] = max(vt, reusableBuffer.calib.xpotsPositions[idx][j][1]); + if (reusableBuffer.calib.xpotsPositions[idx][j][1] - reusableBuffer.calib.xpotsPositions[idx][j][0] > 50) { + reusableBuffer.calib.xpotsPositionsCount[idx] = 255; + } + found = true; + break; + } + } + if (!found) { + if (count < 6) { + reusableBuffer.calib.xpotsPositions[idx][count][0] = vt; + reusableBuffer.calib.xpotsPositions[idx][count][1] = vt; + } + reusableBuffer.calib.xpotsPositionsCount[idx] += 1; + } + } +#endif } } @@ -1284,6 +1305,11 @@ void menuCommonCalib(uint8_t event) reusableBuffer.calib.loVals[i] = 15000; reusableBuffer.calib.hiVals[i] = -15000; reusableBuffer.calib.midVals[i] = anaIn(i); +#if defined(PCBTARANIS) + if (i50) { - g_eeGeneral.calibMid[i] = reusableBuffer.calib.midVals[i]; +#if defined(PCBTARANIS) + if (i>=POT1 && i<=POT_LAST && reusableBuffer.calib.xpotsPositionsCount[i-POT1] > 1) { + g_eeGeneral.potsType &= ~(1 << (i-POT1)); + if (reusableBuffer.calib.xpotsPositionsCount[i-POT1] <= 6) { + StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i]; + calib->count = reusableBuffer.calib.xpotsPositionsCount[i-POT1]-1; + for (int j=0; jcount-1; j++) { + calib->steps[i] = (reusableBuffer.calib.xpotsPositions[i-POT1][j+1][0] + reusableBuffer.calib.xpotsPositions[i-POT1][j][1]) / 2; + } + g_eeGeneral.potsType |= (1 << (i-POT1)); + } + } + else +#endif + if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i]) > 50) { + g_eeGeneral.calib[i].mid = reusableBuffer.calib.midVals[i]; int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i]; - g_eeGeneral.calibSpanNeg[i] = v - v/STICK_TOLERANCE; + g_eeGeneral.calib[i].spanNeg = v - v/STICK_TOLERANCE; v = reusableBuffer.calib.hiVals[i] - reusableBuffer.calib.midVals[i]; - g_eeGeneral.calibSpanPos[i] = v - v/STICK_TOLERANCE; + g_eeGeneral.calib[i].spanPos = v - v/STICK_TOLERANCE; } } break; @@ -1316,6 +1356,7 @@ void menuCommonCalib(uint8_t event) } doMainScreenGraphics(); + #if defined(PCBTARANIS) drawPotsBars(); #endif diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 69af3f0fa..9feed0435 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -1263,7 +1263,14 @@ bool isSwitchAvailable(int16_t swtch) swtch = -swtch; } - if (swtch>=SWSRC_FIRST_CSW && swtch<=SWSRC_LAST_CSW) { +#if defined(PCBTARANIS) + if (swtch >= SWSRC_P11 && swtch <= SWSRC_P26) { + int index = (swtch - SWSRC_P11) / 6; + return (g_eeGeneral.potsType & (1<= SWSRC_FIRST_CSW && swtch <= SWSRC_LAST_CSW) { CustomSwData * cs = cswAddress(swtch-SWSRC_FIRST_CSW); return (cs->func != CS_OFF); } diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 5343ef424..9a8dbb803 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -221,7 +221,7 @@ enum BeeperMode { }; #if defined(CPUARM) - #define EXTRA_GENERAL_FIELDS \ + #define EXTRA_GENERAL_FIELDS_ARM \ uint8_t backlightBright; \ int8_t currentCalib; \ int8_t temperatureWarn; \ @@ -240,6 +240,14 @@ enum BeeperMode { int8_t wavVolume; \ int8_t varioVolume; \ int8_t backgroundVolume; +#endif + +#if defined(PCBTARANIS) +#define EXTRA_GENERAL_FIELDS \ + EXTRA_GENERAL_FIELDS_ARM \ + uint8_t potsType; +#elif defined(CPUARM) + #define EXTRA_GENERAL_FIELDS EXTRA_GENERAL_FIELDS_ARM #elif defined(PXX) #define EXTRA_GENERAL_FIELDS uint8_t countryCode; #else @@ -303,13 +311,24 @@ enum BacklightMode { #define SPLASH_MODE uint8_t splashMode:1; uint8_t spare4:2 #endif +#if defined(PCBTARANIS) +PACK(typedef struct { + int8_t count; + int8_t steps[5]; +}) StepsCalibData; +#endif + +PACK(typedef struct { + int16_t mid; + int16_t spanNeg; + int16_t spanPos; +}) CalibData; + #define ALTERNATE_VIEW 0x10 PACK(typedef struct t_EEGeneral { uint8_t version; uint16_t variant; - int16_t calibMid[NUM_STICKS+NUM_POTS]; - int16_t calibSpanNeg[NUM_STICKS+NUM_POTS]; - int16_t calibSpanPos[NUM_STICKS+NUM_POTS]; + CalibData calib[NUM_STICKS+NUM_POTS]; uint16_t chkSum; int8_t currModel; uint8_t contrast; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index d3c6f5e2d..0e07afb1d 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -503,7 +503,7 @@ void generalDefault() uint16_t evalChkSum() { uint16_t sum = 0; - const int16_t *calibValues = &g_eeGeneral.calibMid[0]; + const int16_t *calibValues = (const int16_t *) &g_eeGeneral.calib[0]; for (int i=0; i(0, val / (2*RESX/5), 5); - uint8_t previousPos = potsPos[i] >> 4; - if (pos != previousPos) { - potsLastposStart[i] = get_tmr10ms(); - potsPos[i] = (pos << 4) | (potsPos[i] & 0x0f); - } - else if ((tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { - potsLastposStart[i] = 0; - potsPos[i] = (pos << 4) | (pos); + for (int i=0; icount>0 && calib->count<6) { + uint8_t pos = calib->count; + int v = (int16_t)anaIn(POT1+i); + for (int j=0; jcount; j++) { + if (v < calib->steps[j]) { + pos = j; + break; + } + } + uint8_t previousPos = potsPos[i] >> 4; + if (pos != previousPos) { + potsLastposStart[i] = get_tmr10ms(); + potsPos[i] = (pos << 4) | (potsPos[i] & 0x0f); + } + else if ((tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { + potsLastposStart[i] = 0; + potsPos[i] = (pos << 4) | (pos); + } + } } } } @@ -2156,8 +2167,9 @@ void checkTHR() int16_t lowLim = THRCHK_DEADBAND - 1024 ; #else getADC(); // if thr is down - do not display warning at all - int16_t lowLim = g_eeGeneral.calibMid[thrchn]; - lowLim = (g_model.throttleReversed ? - lowLim - g_eeGeneral.calibSpanPos[thrchn] : lowLim - g_eeGeneral.calibSpanNeg[thrchn]); + CalibData * calib = &g_eeGeneral.calib[thrchn]; + int16_t lowLim = calib->mid; + lowLim = (g_model.throttleReversed ? - lowLim - calib->spanPos : lowLim - calib->spanNeg); lowLim += THRCHK_DEADBAND; #endif int16_t v = thrAnaIn(thrchn); @@ -2495,7 +2507,23 @@ void getADC() } for (uint32_t x=0; x> 3; + uint16_t v = temp[x] >> 3; +#if defined(PCBTARANIS) + StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[x]; + if (x >= POT1 && x <= POT_LAST && (g_eeGeneral.potsType & (1<<(x-POT1))) && calib->count>0 && calib->count<6) { + for (int i=0; i<=calib->count; i++) { + if (i == calib->count) { + s_anaFilt[x] = RESX; + } + else if (v < calib->steps[i]) { + s_anaFilt[x] = -RESX + i*2*RESX/calib->count; + break; + } + } + } + else +#endif + s_anaFilt[x] = v; } } #else @@ -2743,10 +2771,9 @@ void evalInputs(uint8_t mode) #ifndef SIMU if (i < NUM_STICKS+NUM_POTS) { - v -= g_eeGeneral.calibMid[i]; - v = v * (int32_t)RESX / (max((int16_t)100,(v>0 ? - g_eeGeneral.calibSpanPos[i] : - g_eeGeneral.calibSpanNeg[i]))); + CalibData * calib = &g_eeGeneral.calib[i]; + v -= calib->mid; + v = v * (int32_t)RESX / (max((int16_t)100, (v>0 ? calib->spanPos : calib->spanNeg))); } #endif diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 501ea65a8..d12bf7edd 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -377,7 +377,7 @@ enum EnumKeys { #define NUM_SWITCHES 8 #define IS_3POS(sw) ((sw) != 5 && (sw) != 7) #define NUM_POTS 4 - #define NUM_POTSSW (2*6) + #define NUM_XPOTS 2 #define NUM_SW_SRCRAW 8 #define SWSRC_THR SWSRC_SF2 #define SWSRC_GEA SWSRC_SG2 @@ -390,12 +390,13 @@ enum EnumKeys { #define IS_3POS(sw) ((sw) == 0) #define IS_MOMENTARY(sw) (sw == SWSRC_TRN) #define NUM_POTS 3 - #define NUM_POTSSW 0 + #define NUM_XPOTS 0 #define NUM_SW_SRCRAW 1 #define SW_DSM2_BIND SW_TRN #endif #define NUM_PSWITCH (SWSRC_LAST_SWITCH-SWSRC_FIRST_SWITCH+1) +#define NUM_POTSSW (NUM_XPOTS*6) #define NUM_SWITCH (NUM_PSWITCH+NUM_CSW+NUM_POTSSW) #if defined(PCBTARANIS) @@ -1042,12 +1043,14 @@ enum Analogs { #if defined(PCBTARANIS) POT1, POT2, + POT_LAST = POT2, SLIDER1, SLIDER2, #else POT1, POT2, POT3, + POT_LAST = POT3, #endif TX_VOLTAGE, #if defined(PCBSKY9X) && !defined(REVA) @@ -1565,6 +1568,8 @@ union ReusableBuffer int16_t loVals[NUM_STICKS+NUM_POTS]; int16_t hiVals[NUM_STICKS+NUM_POTS]; uint8_t state; + uint8_t xpotsPositionsCount[NUM_XPOTS]; + int16_t xpotsPositions[NUM_XPOTS][6][2]; } calib; #if defined(SDCARD) From 1dff05dc0222fd80924420982c0185084988915a Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 8 Jan 2014 12:08:33 +0100 Subject: [PATCH 04/12] User scripts ignored --- radio/src/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/radio/src/.gitignore b/radio/src/.gitignore index 31c048a1d..0f2d1136d 100644 --- a/radio/src/.gitignore +++ b/radio/src/.gitignore @@ -6,3 +6,4 @@ /opentx.map /simu.d /snapshot_*.png +/*.sh From a292fabb02dfae6a4c3f474f7d2e8f4c885832be Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sun, 12 Jan 2014 12:57:14 +0100 Subject: [PATCH 05/12] [Taranis] 6Pos switch support is now ok. Calibration is automatic. More tests needed --- radio/src/gui/menu_general.cpp | 59 ++++++++++++++++++++++++---------- radio/src/gui/menus.cpp | 10 ++++-- radio/src/gui/view_main.cpp | 6 ++-- radio/src/myeeprom.h | 5 +-- radio/src/opentx.cpp | 53 +++++++++++++++++------------- radio/src/opentx.h | 7 ++++ 6 files changed, 94 insertions(+), 46 deletions(-) diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index 78d56bc2c..766d05d8b 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -1250,13 +1250,13 @@ void menuCommonCalib(uint8_t event) #if defined(PCBTARANIS) uint8_t idx = i - POT1; int count = reusableBuffer.calib.xpotsPositionsCount[idx]; - if (count <= 6) { + if (count <= POTS_POS_COUNT) { bool found = false; for (int j=0; j reusableBuffer.calib.xpotsPositions[idx][j][0]-20 && vt < reusableBuffer.calib.xpotsPositions[idx][j][0]+20) { + if (vt > reusableBuffer.calib.xpotsPositions[idx][j][0]-10 && vt < reusableBuffer.calib.xpotsPositions[idx][j][0]+10) { reusableBuffer.calib.xpotsPositions[idx][j][0] = min(vt, reusableBuffer.calib.xpotsPositions[idx][j][0]); reusableBuffer.calib.xpotsPositions[idx][j][1] = max(vt, reusableBuffer.calib.xpotsPositions[idx][j][1]); - if (reusableBuffer.calib.xpotsPositions[idx][j][1] - reusableBuffer.calib.xpotsPositions[idx][j][0] > 50) { + if (reusableBuffer.calib.xpotsPositions[idx][j][1] - reusableBuffer.calib.xpotsPositions[idx][j][0] > 20) { reusableBuffer.calib.xpotsPositionsCount[idx] = 255; } found = true; @@ -1301,6 +1301,10 @@ void menuCommonCalib(uint8_t event) lcd_putsAtt(0*FW, 2*FH, STR_SETMIDPOINT, s_noScroll ? INVERS : 0); lcd_putsLeft(3*FH, STR_MENUWHENDONE); +#if defined(PCBTARANIS) + g_eeGeneral.potsType = 0; +#endif + for (uint8_t i=0; i=POT1 && i<=POT_LAST && reusableBuffer.calib.xpotsPositionsCount[i-POT1] > 1) { - g_eeGeneral.potsType &= ~(1 << (i-POT1)); - if (reusableBuffer.calib.xpotsPositionsCount[i-POT1] <= 6) { - StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i]; - calib->count = reusableBuffer.calib.xpotsPositionsCount[i-POT1]-1; - for (int j=0; jcount-1; j++) { - calib->steps[i] = (reusableBuffer.calib.xpotsPositions[i-POT1][j+1][0] + reusableBuffer.calib.xpotsPositions[i-POT1][j][1]) / 2; - } - g_eeGeneral.potsType |= (1 << (i-POT1)); - } - } - else -#endif if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i]) > 50) { g_eeGeneral.calib[i].mid = reusableBuffer.calib.midVals[i]; int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i]; @@ -1345,6 +1335,28 @@ void menuCommonCalib(uint8_t event) break; case 3: +#if defined(PCBTARANIS) + for (uint8_t i=POT1; i<=POT_LAST; i++) { + int idx = i - POT1; + int count = reusableBuffer.calib.xpotsPositionsCount[idx]; + if (count > 1 && count <= POTS_POS_COUNT) { + for (int j=0; jcount = count - 1; + for (int j=0; jcount; j++) { + calib->steps[j] = (reusableBuffer.calib.xpotsPositions[idx][j+1][0] + reusableBuffer.calib.xpotsPositions[idx][j][1]) >> 5; + } + } + } +#endif g_eeGeneral.chkSum = evalChkSum(); eeDirty(EE_GENERAL); reusableBuffer.calib.state = 4; @@ -1359,6 +1371,19 @@ void menuCommonCalib(uint8_t event) #if defined(PCBTARANIS) drawPotsBars(); + for (int i=POT1; i<=POT_LAST; i++) { + uint8_t steps = 0; + if (reusableBuffer.calib.state == 2) { + steps = reusableBuffer.calib.xpotsPositionsCount[i-POT1]; + } + else if (IS_MULTIPOS_POT(i)) { + StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i]; + steps = calib->count + 1; + } + if (steps > 0 && steps <= POTS_POS_COUNT) { + lcd_outdezAtt(LCD_W/2-2+(i-POT1)*5, LCD_H-6, steps, TINSIZE); + } + } #endif } diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index 9feed0435..9277f05b3 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -1265,8 +1265,14 @@ bool isSwitchAvailable(int16_t swtch) #if defined(PCBTARANIS) if (swtch >= SWSRC_P11 && swtch <= SWSRC_P26) { - int index = (swtch - SWSRC_P11) / 6; - return (g_eeGeneral.potsType & (1<count >= ((swtch - SWSRC_P11) % POTS_POS_COUNT)); + } + else { + return false; + } } #endif diff --git a/radio/src/gui/view_main.cpp b/radio/src/gui/view_main.cpp index 51465631d..930119fbd 100644 --- a/radio/src/gui/view_main.cpp +++ b/radio/src/gui/view_main.cpp @@ -120,9 +120,9 @@ void drawPotsBars() { // Optimization by Mike Blandford - uint8_t x, y, len ; // declare temporary variables - for (x=LCD_W/2-5, y=NUM_STICKS; ycount>0 && calib->count<6) { - uint8_t pos = calib->count; - int v = (int16_t)anaIn(POT1+i); - for (int j=0; jcount; j++) { - if (v < calib->steps[j]) { - pos = j; - break; - } - } + if (calib->count>0 && calib->countcount); uint8_t previousPos = potsPos[i] >> 4; if (pos != previousPos) { potsLastposStart[i] = get_tmr10ms(); @@ -1360,9 +1354,10 @@ void getSwitchesPosition() } } } +#endif } #define SWITCH_POSITION(sw) (switchesPos & (1<<(sw))) -#define POT_POSITION(sw) ((potsPos[(sw)/6] & 0x0f) == ((sw) % 6)) +#define POT_POSITION(sw) ((potsPos[(sw)/POTS_POS_COUNT] & 0x0f) == ((sw) % POTS_POS_COUNT)) #else #define getSwitchesPosition() #define SWITCH_POSITION(idx) switchState((EnumKeys)(SW_BASE+(idx))) @@ -2502,6 +2497,15 @@ void getADC() for (uint32_t i=0; i<4; i++) { adcRead(); for (uint32_t x=0; x=POT1 && x<=POT2 && temp[x]!=Analog_values[x]) { + i = 0; + } + temp[x] = Analog_values[x]; + } + else +#endif temp[x] += Analog_values[x]; } } @@ -2509,14 +2513,14 @@ void getADC() for (uint32_t x=0; x> 3; #if defined(PCBTARANIS) + if (s_noScroll) v = temp[x] >> 1; StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[x]; - if (x >= POT1 && x <= POT_LAST && (g_eeGeneral.potsType & (1<<(x-POT1))) && calib->count>0 && calib->count<6) { - for (int i=0; i<=calib->count; i++) { - if (i == calib->count) { - s_anaFilt[x] = RESX; - } - else if (v < calib->steps[i]) { - s_anaFilt[x] = -RESX + i*2*RESX/calib->count; + if (IS_MULTIPOS_POT(x) && calib->count>0 && calib->count> 4); + s_anaFilt[x] = 2*RESX; + for (int i=0; icount; i++) { + if (vShifted < calib->steps[i]) { + s_anaFilt[x] = i*2*RESX/calib->count; break; } } @@ -2771,9 +2775,14 @@ void evalInputs(uint8_t mode) #ifndef SIMU if (i < NUM_STICKS+NUM_POTS) { - CalibData * calib = &g_eeGeneral.calib[i]; - v -= calib->mid; - v = v * (int32_t)RESX / (max((int16_t)100, (v>0 ? calib->spanPos : calib->spanNeg))); + if (IS_MULTIPOS_POT(i)) { + v -= RESX; + } + else { + CalibData * calib = &g_eeGeneral.calib[i]; + v -= calib->mid; + v = v * (int32_t)RESX / (max((int16_t)100, (v>0 ? calib->spanPos : calib->spanNeg))); + } } #endif @@ -3730,10 +3739,10 @@ void doMixerCalculations() // therefore forget the exact calculation and use only 1 instead; good compromise lastTMR = tmr10ms; - getSwitchesPosition(); - getADC(); + getSwitchesPosition(); + #if defined(PCBSKY9X) && !defined(REVA) && !defined(SIMU) Current_analogue = (Current_analogue*31 + s_anaFilt[8] ) >> 5 ; if (Current_analogue > Current_max) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index d12bf7edd..ead6c7fc2 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -412,6 +412,12 @@ enum EnumKeys { #include "myeeprom.h" +#if defined(PCBTARANIS) + #define IS_MULTIPOS_POT(x) ((x)>=POT1 && (x)<=POT_LAST && (g_eeGeneral.potsType & (1 << ((x)-POT1)))) +#else + #define IS_MULTIPOS_POT(x) (false) +#endif + #if ROTARY_ENCODERS > 0 #define IF_ROTARY_ENCODERS(x) x, #else @@ -1098,6 +1104,7 @@ template FORCEINLINE t min(t a, t b) { return a FORCEINLINE t max(t a, t b) { return a>b?a:b; } template FORCEINLINE t sgn(t a) { return a>0 ? 1 : (a < 0 ? -1 : 0); } template FORCEINLINE t limit(t mi, t x, t ma) { return min(max(mi,x),ma); } +template void swap(t & a, t & b) { t tmp = b; b = a; a = tmp; } #if defined(HELI) || defined(FRSKY_HUB) uint16_t isqrt32(uint32_t n); From b4c6d123c841d10acdc752fa688817821abb354a Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 15 Jan 2014 21:15:28 +0100 Subject: [PATCH 06/12] Better implementation for the automatic detection of a 6pos switch --- radio/src/gui/menu_general.cpp | 53 +++++++++++++++++++--------------- radio/src/opentx.cpp | 12 ++------ radio/src/opentx.h | 10 +++++-- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index 766d05d8b..242b7f0fa 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -1238,6 +1238,7 @@ void menuGeneralHardware(uint8_t event) } #endif +#define XPOT_DELTA 5 void menuCommonCalib(uint8_t event) { @@ -1249,26 +1250,30 @@ void menuCommonCalib(uint8_t event) reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2; #if defined(PCBTARANIS) uint8_t idx = i - POT1; - int count = reusableBuffer.calib.xpotsPositionsCount[idx]; + int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount; if (count <= POTS_POS_COUNT) { - bool found = false; - for (int j=0; j reusableBuffer.calib.xpotsPositions[idx][j][0]-10 && vt < reusableBuffer.calib.xpotsPositions[idx][j][0]+10) { - reusableBuffer.calib.xpotsPositions[idx][j][0] = min(vt, reusableBuffer.calib.xpotsPositions[idx][j][0]); - reusableBuffer.calib.xpotsPositions[idx][j][1] = max(vt, reusableBuffer.calib.xpotsPositions[idx][j][1]); - if (reusableBuffer.calib.xpotsPositions[idx][j][1] - reusableBuffer.calib.xpotsPositions[idx][j][0] > 20) { - reusableBuffer.calib.xpotsPositionsCount[idx] = 255; - } - found = true; - break; - } + if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 0 || vt < reusableBuffer.calib.xpotsCalib[idx].lastPosition - XPOT_DELTA || vt > reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) { + reusableBuffer.calib.xpotsCalib[idx].lastPosition = vt; + reusableBuffer.calib.xpotsCalib[idx].lastCount = 1; } - if (!found) { - if (count < 6) { - reusableBuffer.calib.xpotsPositions[idx][count][0] = vt; - reusableBuffer.calib.xpotsPositions[idx][count][1] = vt; + else { + if (reusableBuffer.calib.xpotsCalib[idx].lastCount < 255) reusableBuffer.calib.xpotsCalib[idx].lastCount++; + } + if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 8/*80ms*/) { + int16_t position = reusableBuffer.calib.xpotsCalib[idx].lastPosition; + bool found = false; + for (int j=0; j= reusableBuffer.calib.xpotsCalib[idx].steps[j]-XPOT_DELTA && position <= reusableBuffer.calib.xpotsCalib[idx].steps[j]+XPOT_DELTA) { + found = true; + break; + } + } + if (!found) { + if (count < POTS_POS_COUNT) { + reusableBuffer.calib.xpotsCalib[idx].steps[count] = position; + } + reusableBuffer.calib.xpotsCalib[idx].stepsCount += 1; } - reusableBuffer.calib.xpotsPositionsCount[idx] += 1; } } #endif @@ -1311,7 +1316,8 @@ void menuCommonCalib(uint8_t event) reusableBuffer.calib.midVals[i] = anaIn(i); #if defined(PCBTARANIS) if (i 1 && count <= POTS_POS_COUNT) { for (int j=0; jcount = count - 1; for (int j=0; jcount; j++) { - calib->steps[j] = (reusableBuffer.calib.xpotsPositions[idx][j+1][0] + reusableBuffer.calib.xpotsPositions[idx][j][1]) >> 5; + calib->steps[j] = (reusableBuffer.calib.xpotsCalib[idx].steps[j+1] + reusableBuffer.calib.xpotsCalib[idx].steps[j]) >> 5; } } } @@ -1374,7 +1379,7 @@ void menuCommonCalib(uint8_t event) for (int i=POT1; i<=POT_LAST; i++) { uint8_t steps = 0; if (reusableBuffer.calib.state == 2) { - steps = reusableBuffer.calib.xpotsPositionsCount[i-POT1]; + steps = reusableBuffer.calib.xpotsCalib[i-POT1].stepsCount; } else if (IS_MULTIPOS_POT(i)) { StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i]; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 2e7fb6d8f..6923ecdce 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2497,17 +2497,11 @@ void getADC() for (uint32_t i=0; i<4; i++) { adcRead(); for (uint32_t x=0; x=POT1 && x<=POT2 && temp[x]!=Analog_values[x]) { - i = 0; - } - temp[x] = Analog_values[x]; - } - else -#endif temp[x] += Analog_values[x]; } +#if defined(PCBTARANIS) + if (s_noScroll) break; +#endif } for (uint32_t x=0; x Date: Fri, 31 Jan 2014 11:58:03 +0100 Subject: [PATCH 07/12] Issue #588 - S1/S2 Type added in Hardware configuration page --- radio/src/gui/menu_general.cpp | 28 +++++++++++++++++++--------- radio/src/translations.cpp | 3 +++ radio/src/translations.h | 10 +++++++--- radio/src/translations/de.h.txt | 5 +++++ radio/src/translations/en.h | 5 +++++ radio/src/translations/es.h.txt | 7 ++++++- radio/src/translations/fr.h.txt | 7 ++++++- radio/src/translations/it.h.txt | 9 +++++++-- radio/src/translations/pt.h.txt | 5 +++++ radio/src/translations/se.h.txt | 5 +++++ 10 files changed, 68 insertions(+), 16 deletions(-) diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index ebf5b24b3..c5f97dae9 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -1168,6 +1168,8 @@ void menuGeneralDiagAna(uint8_t event) #if defined(PCBTARANIS) enum menuGeneralHwItems { + ITEM_SETUP_HW_POT1, + ITEM_SETUP_HW_POT2, ITEM_SETUP_HW_UART3_MODE, ITEM_SETUP_HW_MAX }; @@ -1181,9 +1183,22 @@ void menuGeneralHardware(uint8_t event) uint8_t sub = m_posVert - 1; for (uint8_t i=0; i0) ? BLINK|INVERS : INVERS) : 0); + uint8_t y = 1 + 1*FH + i*FH; + uint8_t attr = (sub == i ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0); switch(i) { + case ITEM_SETUP_HW_POT1: + case ITEM_SETUP_HW_POT2: + { + int idx = i - ITEM_SETUP_HW_POT1; + uint8_t mask = (1< reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) { reusableBuffer.calib.xpotsCalib[idx].lastPosition = vt; reusableBuffer.calib.xpotsCalib[idx].lastCount = 1; @@ -1333,10 +1348,6 @@ void menuCommonCalib(uint8_t event) lcd_putsAtt(0*FW, 2*FH, STR_SETMIDPOINT, s_noScroll ? INVERS : 0); lcd_putsLeft(3*FH, STR_MENUWHENDONE); -#if defined(PCBTARANIS) - g_eeGeneral.potsType = 0; -#endif - for (uint8_t i=0; i 1 && count <= POTS_POS_COUNT) { + if (IS_MULTIPOS_POT(i) && count > 1 && count <= POTS_POS_COUNT) { for (int j=0; jcount = count - 1; for (int j=0; jcount; j++) { diff --git a/radio/src/translations.cpp b/radio/src/translations.cpp index f031ba40b..de37b6ee2 100644 --- a/radio/src/translations.cpp +++ b/radio/src/translations.cpp @@ -57,6 +57,7 @@ const pm_char STR_OPEN9X[] PROGMEM = ISTR(TRNCHN) #if defined(PCBTARANIS) ISTR(UART3MODES) + ISTR(POTTYPES) #endif ISTR(VTRIMINC) ISTR(RETA123) @@ -496,6 +497,8 @@ const pm_char STR_VIEW_TEXT[] PROGMEM = "View text"; const pm_char STR_VIEW_CHANNELS[] PROGMEM = "View Channels"; const pm_char STR_VIEW_NOTES[] PROGMEM = "View Notes"; const pm_char STR_UART3MODE[] PROGMEM = TR_UART3MODE; + const pm_char STR_POT1TYPE[] PROGMEM = TR_POT1TYPE; + const pm_char STR_POT2TYPE[] PROGMEM = TR_POT2TYPE; #endif #if MENUS_LOCK == 1 diff --git a/radio/src/translations.h b/radio/src/translations.h index 0c7f7af19..794c6b342 100644 --- a/radio/src/translations.h +++ b/radio/src/translations.h @@ -100,10 +100,11 @@ extern const pm_char STR_OPEN9X[]; #endif #define OFS_TRNCHN (OFS_TRNMODE + sizeof(TR_TRNMODE)) #if defined(PCBTARANIS) -#define OFS_UART3MODES (OFS_TRNCHN + sizeof(TR_TRNCHN)) -#define OFS_VTRIMINC (OFS_UART3MODES + sizeof(TR_UART3MODES)) + #define OFS_UART3MODES (OFS_TRNCHN + sizeof(TR_TRNCHN)) + #define OFS_POTTYPES (OFS_UART3MODES + sizeof(TR_UART3MODES)) + #define OFS_VTRIMINC (OFS_POTTYPES + sizeof(TR_POTTYPES)) #else -#define OFS_VTRIMINC (OFS_TRNCHN + sizeof(TR_TRNCHN)) + #define OFS_VTRIMINC (OFS_TRNCHN + sizeof(TR_TRNCHN)) #endif #define OFS_RETA123 (OFS_VTRIMINC + sizeof(TR_VTRIMINC)) #define OFS_VPROTOS (OFS_RETA123 + sizeof(TR_RETA123)) @@ -196,6 +197,7 @@ extern const pm_char STR_OPEN9X[]; #define STR_TRNMODE (STR_OPEN9X + OFS_TRNMODE) #define STR_TRNCHN (STR_OPEN9X + OFS_TRNCHN) #define STR_UART3MODES (STR_OPEN9X + OFS_UART3MODES) +#define STR_POTTYPES (STR_OPEN9X + OFS_POTTYPES) #define STR_VTRIMINC (STR_OPEN9X + OFS_VTRIMINC) #define STR_RETA123 (STR_OPEN9X + OFS_RETA123) #define STR_VPROTOS (STR_OPEN9X + OFS_VPROTOS) @@ -683,6 +685,8 @@ extern const pm_char STR_VIEW_TEXT[]; extern const pm_char STR_VIEW_CHANNELS[]; extern const pm_char STR_VIEW_NOTES[]; extern const pm_char STR_UART3MODE[]; + extern const pm_char STR_POT1TYPE[]; + extern const pm_char STR_POT2TYPE[]; #endif #if MENUS_LOCK == 1 diff --git a/radio/src/translations/de.h.txt b/radio/src/translations/de.h.txt index 4c719b79a..45355f3f4 100644 --- a/radio/src/translations/de.h.txt +++ b/radio/src/translations/de.h.txt @@ -71,6 +71,9 @@ #define LEN_UART3MODES "\017" #define TR_UART3MODES "OFF\0 ""SPORT Mirror\0 ""Virtual SP2UART" +#define LEN_POTTYPES "\017" +#define TR_POTTYPES "Pot\0 ""Multipos Switch" + #define LEN_DATETIME "\005" #define TR_DATETIME "DATE:""ZEIT:" @@ -680,6 +683,8 @@ #define TR_PERSISTENT_MAH INDENT "Store mAh" #define TR_FAS_OFFSET TR(INDENT "FAS Ofs", INDENT "FAS Offset") #define TR_UART3MODE "Serial port" +#define TR_POT1TYPE "S1 Type" +#define TR_POT2TYPE "S2 Type" #if defined(MAVLINK) #define TR_MAVLINK_RC_RSSI_SCALE_LABEL "Max RSSI" diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index 4f0397900..1c9054538 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -71,6 +71,9 @@ #define LEN_UART3MODES "\017" #define TR_UART3MODES "OFF\0 ""SPORT Mirror\0 ""Virtual SP2UART" +#define LEN_POTTYPES "\017" +#define TR_POTTYPES "Pot\0 ""Multipos Switch" + #define LEN_DATETIME "\005" #define TR_DATETIME "DATE:""TIME:" @@ -680,6 +683,8 @@ #define TR_PERSISTENT_MAH INDENT "Store mAh" #define TR_FAS_OFFSET TR(INDENT "FAS Ofs", INDENT "FAS Offset") #define TR_UART3MODE "Serial port" +#define TR_POT1TYPE "S1 Type" +#define TR_POT2TYPE "S2 Type" #if defined(MAVLINK) #define TR_MAVLINK_RC_RSSI_SCALE_LABEL "Max RSSI" diff --git a/radio/src/translations/es.h.txt b/radio/src/translations/es.h.txt index f1f81d0f5..65108e25f 100644 --- a/radio/src/translations/es.h.txt +++ b/radio/src/translations/es.h.txt @@ -1,4 +1,4 @@ -/* +/* * Authors (alphabetical order) * - Bertrand Songis * - Bernet Andre @@ -71,6 +71,9 @@ #define LEN_UART3MODES "\017" #define TR_UART3MODES "OFF\0 ""SPORT Mirror\0 ""Virtual SP2UART" +#define LEN_POTTYPES "\017" +#define TR_POTTYPES "Pot\0 ""Multipos Switch" + #define LEN_DATETIME "\005" #define TR_DATETIME "DATA:""HORA:" @@ -680,6 +683,8 @@ #define TR_PERSISTENT_MAH INDENT "Valor mAh" #define TR_FAS_OFFSET TR(INDENT "FAS Ofs", INDENT "FAS Offset") #define TR_UART3MODE "Serial port" +#define TR_POT1TYPE "S1 Type" +#define TR_POT2TYPE "S2 Type" #if defined(MAVLINK) #define TR_MAVLINK_RC_RSSI_SCALE_LABEL "Max RSSI" diff --git a/radio/src/translations/fr.h.txt b/radio/src/translations/fr.h.txt index 540aa08bd..09c7f0854 100644 --- a/radio/src/translations/fr.h.txt +++ b/radio/src/translations/fr.h.txt @@ -1,4 +1,4 @@ -/* +/* * Authors (alphabetical order) * - Bertrand Songis * - Bernet Andre @@ -71,6 +71,9 @@ #define LEN_UART3MODES "\017" #define TR_UART3MODES "OFF\0 ""SPORT Mirror\0 ""Virtual SP2UART" +#define LEN_POTTYPES "\017" +#define TR_POTTYPES "Pot\0 ""Multipos Switch" + #define LEN_DATETIME "\005" #define TR_DATETIME "DATE:""HEURE" @@ -680,6 +683,8 @@ #define TR_PERSISTENT_MAH TR(INDENT "Enr. mAh",INDENT "Enregistrer mAh") #define TR_FAS_OFFSET TR(INDENT "Corr FAS", INDENT "Correction FAS") #define TR_UART3MODE "Port série" +#define TR_POT1TYPE "S1 Type" +#define TR_POT2TYPE "S2 Type" #if defined(MAVLINK) #define TR_MAVLINK_RC_RSSI_SCALE_LABEL "RSSI Max" diff --git a/radio/src/translations/it.h.txt b/radio/src/translations/it.h.txt index 3f18eecf5..4326c226f 100644 --- a/radio/src/translations/it.h.txt +++ b/radio/src/translations/it.h.txt @@ -71,14 +71,17 @@ #define LEN_UART3MODES "\017" #define TR_UART3MODES "OFF\0 ""SPORT Mirror\0 ""Virtual SP2UART" +#define LEN_POTTYPES "\017" +#define TR_POTTYPES "Pot\0 ""Multipos Switch" + #define LEN_DATETIME "\005" #define TR_DATETIME "DATA:""ORA :" #define LEN_VLCD "\006" #define TR_VLCD "NormalOptrex" -#define LEN_COUNTRYCODES TR("\002", "\007") -#define TR_COUNTRYCODES TR("US""JP""EU", "America""Japan\0 ""Europe\0") +#define LEN_COUNTRYCODES TR("\002", "\007") +#define TR_COUNTRYCODES TR("US""JP""EU", "America""Japan\0 ""Europe\0") #define LEN_VTRIMINC "\006" #define TR_VTRIMINC "Exp ""ExFine""Fine ""Medio ""Ampio " @@ -680,6 +683,8 @@ #define TR_PERSISTENT_MAH INDENT "Store mAh" #define TR_FAS_OFFSET TR(INDENT "FAS Ofs", INDENT "FAS Offset") #define TR_UART3MODE "Serial port" +#define TR_POT1TYPE "S1 Type" +#define TR_POT2TYPE "S2 Type" #if defined(MAVLINK) #define TR_MAVLINK_RC_RSSI_SCALE_LABEL "Max RSSI" diff --git a/radio/src/translations/pt.h.txt b/radio/src/translations/pt.h.txt index a17f9af2f..33e9d16fe 100644 --- a/radio/src/translations/pt.h.txt +++ b/radio/src/translations/pt.h.txt @@ -71,6 +71,9 @@ #define LEN_UART3MODES "\017" #define TR_UART3MODES "OFF\0 ""SPORT Mirror\0 ""Virtual SP2UART" +#define LEN_POTTYPES "\017" +#define TR_POTTYPES "Pot\0 ""Multipos Switch" + #define LEN_DATETIME "\005" #define TR_DATETIME "DATA:""HORA:" @@ -680,6 +683,8 @@ #define TR_PERSISTENT_MAH INDENT "Store mAh" #define TR_FAS_OFFSET TR(INDENT "FAS Ofs", INDENT "FAS Offset") #define TR_UART3MODE "Serial port" +#define TR_POT1TYPE "S1 Type" +#define TR_POT2TYPE "S2 Type" #if defined(MAVLINK) #define TR_MAVLINK_RC_RSSI_SCALE_LABEL "Max RSSI" diff --git a/radio/src/translations/se.h.txt b/radio/src/translations/se.h.txt index 60bc0c6b2..ad1277001 100644 --- a/radio/src/translations/se.h.txt +++ b/radio/src/translations/se.h.txt @@ -71,6 +71,9 @@ #define LEN_UART3MODES "\017" #define TR_UART3MODES "Av\0 ""SPORT-spegel\0 ""VirtuellSP2UART" +#define LEN_POTTYPES "\017" +#define TR_POTTYPES "Pot\0 ""Multipos Switch" + #define LEN_DATETIME "\005" #define TR_DATETIME "DAG: ""TID: " @@ -680,6 +683,8 @@ #define TR_PERSISTENT_MAH INDENT "Store mAh" #define TR_FAS_OFFSET TR(INDENT "FAS Ofs", INDENT "FAS Offset") #define TR_UART3MODE "Serieport" +#define TR_POT1TYPE "S1 Type" +#define TR_POT2TYPE "S2 Type" #if defined(MAVLINK) #define TR_MAVLINK_RC_RSSI_SCALE_LABEL "Max RSSI" From 1cef62df483f7200417f511ff7de86d8b1914b91 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 31 Jan 2014 12:32:09 +0100 Subject: [PATCH 08/12] Compilation error --- radio/src/opentx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index fa4152aba..981d360bd 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1582,8 +1582,8 @@ union ReusableBuffer uint8_t lastCount; int16_t lastPosition; } xpotsCalib[NUM_XPOTS]; - } calib; #endif + } calib; #if defined(SDCARD) struct From 8ef1456fe90e558f1f1ca1b9234773b8dd5470c0 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 31 Jan 2014 17:19:21 +0100 Subject: [PATCH 09/12] EEPROM support in Companion for the 6pos pots on Taranis --- companion/src/eeprominterface.cpp | 48 +++++++++++-------- companion/src/eeprominterface.h | 8 +++- .../src/firmwares/opentx/opentxeeprom.cpp | 40 ++++++++++++---- .../src/firmwares/opentx/opentxinterface.cpp | 4 ++ companion/src/helpers.cpp | 11 +++++ radio/src/myeeprom.h | 4 +- 6 files changed, 82 insertions(+), 33 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index cf7686bea..9b5126780 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -67,7 +67,7 @@ RawSourceRange RawSource::getRange(bool singleprec) case TELEMETRY_SOURCE_A1: case TELEMETRY_SOURCE_A2: if (model) { - FrSkyChannelData channel = model->frsky.channels[index-TELEMETRY_SOURCE_A1]; // TODO const & + const FrSkyChannelData & channel = model->frsky.channels[index-TELEMETRY_SOURCE_A1]; float ratio = channel.getRatio(); if (channel.type==0 || channel.type==1 || channel.type==2) result.decimals = 2; @@ -239,26 +239,34 @@ QString SwitchDn(const char sw) QString RawSwitch::toString() { - static const QString switches9X[] = { QObject::tr("THR"), QObject::tr("RUD"), QObject::tr("ELE"), - QObject::tr("ID0"), QObject::tr("ID1"), QObject::tr("ID2"), - QObject::tr("AIL"), QObject::tr("GEA"), QObject::tr("TRN") - }; + static const QString switches9X[] = { + QString("THR"), QString("RUD"), QString("ELE"), + QString("ID0"), QString("ID1"), QString("ID2"), + QString("AIL"), QString("GEA"), QString("TRN") + }; - static const QString switchesX9D[] = { SwitchUp('A'), QString::fromUtf8("SA-"), SwitchDn('A'), - SwitchUp('B'), QString::fromUtf8("SB-"), SwitchDn('B'), - SwitchUp('C'), QString::fromUtf8("SC-"), SwitchDn('C'), - SwitchUp('D'), QString::fromUtf8("SD-"), SwitchDn('D'), - SwitchUp('E'), QString::fromUtf8("SE-"), SwitchDn('E'), - SwitchUp('F'), SwitchDn('F'), - SwitchUp('G'), QString::fromUtf8("SG-"), SwitchDn('G'), - SwitchUp('H'), SwitchDn('H'), - }; + static const QString switchesX9D[] = { + SwitchUp('A'), QString::fromUtf8("SA-"), SwitchDn('A'), + SwitchUp('B'), QString::fromUtf8("SB-"), SwitchDn('B'), + SwitchUp('C'), QString::fromUtf8("SC-"), SwitchDn('C'), + SwitchUp('D'), QString::fromUtf8("SD-"), SwitchDn('D'), + SwitchUp('E'), QString::fromUtf8("SE-"), SwitchDn('E'), + SwitchUp('F'), SwitchDn('F'), + SwitchUp('G'), QString::fromUtf8("SG-"), SwitchDn('G'), + SwitchUp('H'), SwitchDn('H'), + }; - static const QString virtualSwitches[] = { QObject::tr("LS1"), QObject::tr("LS2"), QObject::tr("LS3"), QObject::tr("LS4"), QObject::tr("LS5"), QObject::tr("LS6"), QObject::tr("LS7"), QObject::tr("LS8"), QObject::tr("LS9"), QObject::tr("LSA"), - QObject::tr("LSB"), QObject::tr("LSC"), QObject::tr("LSD"), QObject::tr("LSE"), QObject::tr("LSF"), QObject::tr("LSG"), QObject::tr("LSH"), QObject::tr("LSI"), QObject::tr("LSJ"), QObject::tr("LSK"), - QObject::tr("LSL"), QObject::tr("LSM"), QObject::tr("LSN"), QObject::tr("LSO"), QObject::tr("LSP"), QObject::tr("LSQ"), QObject::tr("LSR"), QObject::tr("LSS"), QObject::tr("LST"), QObject::tr("LSU"), - QObject::tr("LSV"), QObject::tr("LSW") - }; + static const QString virtualSwitches[] = { + QObject::tr("LS1"), QObject::tr("LS2"), QObject::tr("LS3"), QObject::tr("LS4"), QObject::tr("LS5"), QObject::tr("LS6"), QObject::tr("LS7"), QObject::tr("LS8"), QObject::tr("LS9"), QObject::tr("LSA"), + QObject::tr("LSB"), QObject::tr("LSC"), QObject::tr("LSD"), QObject::tr("LSE"), QObject::tr("LSF"), QObject::tr("LSG"), QObject::tr("LSH"), QObject::tr("LSI"), QObject::tr("LSJ"), QObject::tr("LSK"), + QObject::tr("LSL"), QObject::tr("LSM"), QObject::tr("LSN"), QObject::tr("LSO"), QObject::tr("LSP"), QObject::tr("LSQ"), QObject::tr("LSR"), QObject::tr("LSS"), QObject::tr("LST"), QObject::tr("LSU"), + QObject::tr("LSV"), QObject::tr("LSW") + }; + + static const QString multiposPots[] = { + QObject::tr("S11"), QObject::tr("S12"), QObject::tr("S13"), QObject::tr("S14"), QObject::tr("S15"), QObject::tr("S16"), + QObject::tr("S21"), QObject::tr("S22"), QObject::tr("S23"), QObject::tr("S24"), QObject::tr("S25"), QObject::tr("S26") + }; switch(type) { case SWITCH_TYPE_SWITCH: @@ -268,6 +276,8 @@ QString RawSwitch::toString() return index > 0 ? CHECK_IN_ARRAY(switches9X, index-1) : QString("!") + CHECK_IN_ARRAY(switches9X, -index-1); case SWITCH_TYPE_VIRTUAL: 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_ON: return QObject::tr("ON"); case SWITCH_TYPE_ONM: diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 915387e01..38b713c24 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -356,6 +356,7 @@ enum RawSwitchType { SWITCH_TYPE_NONE, SWITCH_TYPE_SWITCH, SWITCH_TYPE_VIRTUAL, + SWITCH_TYPE_MULTIPOS_POT, SWITCH_TYPE_MOMENT_SWITCH, SWITCH_TYPE_MOMENT_VIRTUAL, SWITCH_TYPE_ON, @@ -503,6 +504,7 @@ class GeneralSettings { unsigned int mavbaud; unsigned int switchUnlockStates; unsigned int hw_uartMode; + unsigned int potsType[8]; }; class CurveReference { @@ -737,7 +739,7 @@ class FrSkyChannelData { unsigned int multiplier; FrSkyAlarmData alarms[2]; - float getRatio() + float getRatio() const { if (type==0 || type==1 || type==2) return float(ratio << multiplier) / 10.0; @@ -1052,7 +1054,9 @@ enum Capability { EnhancedCurves, TelemetryInternalAlarms, HasFasOffset, - HasMahPersistent + HasMahPersistent, + MultiposPots, + MultiposPotsPositions }; enum UseContext { diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index a238d344d..0febeaf4e 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -56,21 +56,29 @@ class SwitchesConversionTable: public ConversionTable { addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, i), val++); } + if (IS_TARANIS(board) && version >= 216) { + for (int i=0; i<2; i++) { + for (int j=0; j<6; j++) { + addConversion(RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i*6+j), val++); + } + } + } + addConversion(RawSwitch(SWITCH_TYPE_OFF), -val); addConversion(RawSwitch(SWITCH_TYPE_ON), val++); for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) { int s = switchIndex(i, board, version); - addConversion(RawSwitch(SWITCH_TYPE_MOMENT_SWITCH, -s), -val); + // addConversion(RawSwitch(SWITCH_TYPE_MOMENT_SWITCH, -s), -val); addConversion(RawSwitch(SWITCH_TYPE_MOMENT_SWITCH, s), val++); } for (int i=1; i<=MAX_CUSTOM_SWITCHES(board, version); i++) { - addConversion(RawSwitch(SWITCH_TYPE_MOMENT_VIRTUAL, -i), -val); + // addConversion(RawSwitch(SWITCH_TYPE_MOMENT_VIRTUAL, -i), -val); addConversion(RawSwitch(SWITCH_TYPE_MOMENT_VIRTUAL, i), val++); } - addConversion(RawSwitch(SWITCH_TYPE_ONM, 1 ), -val); + // addConversion(RawSwitch(SWITCH_TYPE_ONM, 1 ), -val); addConversion(RawSwitch(SWITCH_TYPE_ONM, 0 ), val++); addConversion(RawSwitch(SWITCH_TYPE_TRN, 0), val++); addConversion(RawSwitch(SWITCH_TYPE_TRN, 1), val++); @@ -2011,12 +2019,21 @@ Open9xGeneralDataNew::Open9xGeneralDataNew(GeneralSettings & generalData, BoardE if (version >= 213 || (!IS_ARM(board) && version >= 212)) internalField.Append(new UnsignedField<16>(generalData.variant)); - for (int i=0; i(generalData.calibMid[i])); - for (int i=0; i(generalData.calibSpanNeg[i])); - for (int i=0; i(generalData.calibSpanPos[i])); + if (version >= 216) { + for (int i=0; i(generalData.calibMid[i])); + internalField.Append(new SignedField<16>(generalData.calibSpanNeg[i])); + internalField.Append(new SignedField<16>(generalData.calibSpanPos[i])); + } + } + else { + for (int i=0; i(generalData.calibMid[i])); + for (int i=0; i(generalData.calibSpanNeg[i])); + for (int i=0; i(generalData.calibSpanPos[i])); + } internalField.Append(new UnsignedField<16>(chkSum)); internalField.Append(new UnsignedField<8>(generalData.currModel)); @@ -2110,8 +2127,11 @@ Open9xGeneralDataNew::Open9xGeneralDataNew(GeneralSettings & generalData, BoardE internalField.Append(new SignedField<8>(generalData.varioVolume)); internalField.Append(new SignedField<8>(generalData.backgroundVolume)); } - if (version >= 216) { + if (IS_TARANIS(board) && version >= 216) { internalField.Append(new UnsignedField<8>(generalData.hw_uartMode)); + for (int i=0; i<8; i++) { + internalField.Append(new UnsignedField<1>(generalData.potsType[i])); + } } } } diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 178dcf5a1..b70ef9d8a 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -682,6 +682,10 @@ int Open9xInterface::getCapability(const Capability capability) return (IS_STOCK(board) ? false : true); case HasMahPersistent: return (IS_ARM(board) ? true : false); + case MultiposPots: + return IS_TARANIS(board) ? 2 : 0; + case MultiposPotsPositions: + return IS_TARANIS(board) ? 6 : 0; default: return 0; } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 1c69e2207..97ef84275 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -842,6 +842,8 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, return; } +#if 0 + // TODO check ... I removed negative toggle switches in the FW, no? if (attr & POPULATE_MSWITCHES) { if (attr & POPULATE_ONOFF) { item = RawSwitch(SWITCH_TYPE_ONM, 1); @@ -860,6 +862,7 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, if (item == value) b->setCurrentIndex(b->count()-1); } } +#endif if (attr & POPULATE_ONOFF) { item = RawSwitch(SWITCH_TYPE_OFF); @@ -905,6 +908,14 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, 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); + } + } + if (attr & POPULATE_ONOFF) { item = RawSwitch(SWITCH_TYPE_ON); b->addItem(item.toString(), item.toValue()); diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index d0b1147d1..0a0eaffcf 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -245,8 +245,8 @@ enum BeeperMode { #if defined(PCBTARANIS) #define EXTRA_GENERAL_FIELDS \ EXTRA_GENERAL_FIELDS_ARM \ - uint8_t potsType; \ - uint8_t hw_uartMode; + uint8_t hw_uartMode; \ + uint8_t potsType; #elif defined(CPUARM) #define EXTRA_GENERAL_FIELDS EXTRA_GENERAL_FIELDS_ARM #elif defined(PXX) From 2d884d413a7e16cb52ad6da204a2f86a45b11ea8 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 31 Jan 2014 17:32:56 +0100 Subject: [PATCH 10/12] [Taranis] Pots type added to the Companion UI --- companion/src/generaledit.cpp | 27 ++++++++++- companion/src/generaledit.h | 3 ++ companion/src/generaledit.ui | 87 ++++++++++++++++++++++++++++++++++- companion/src/helpers.cpp | 3 +- 4 files changed, 117 insertions(+), 3 deletions(-) diff --git a/companion/src/generaledit.cpp b/companion/src/generaledit.cpp index fdff37ae9..f197eb7b1 100644 --- a/companion/src/generaledit.cpp +++ b/companion/src/generaledit.cpp @@ -64,7 +64,8 @@ GeneralEdit::GeneralEdit(RadioData &radioData, QWidget *parent) : } this->layout()->removeItem(ui->TaranisReadOnlyUnlock); } - } else { + } + else { for (int i=0; pmsl[i]; i++) { pmsl[i]->hide(); } @@ -373,6 +374,18 @@ GeneralEdit::GeneralEdit(RadioData &radioData, QWidget *parent) : for (int i=0; tpmsld[i]; i++) { connect(tpmsld[i], SIGNAL(valueChanged(int)),this,SLOT(unlockSwitchEdited())); } + + if (GetEepromInterface()->getCapability(MultiposPots)) { + ui->pot1Type->setCurrentIndex(g_eeGeneral.potsType[0]); + ui->pot2Type->setCurrentIndex(g_eeGeneral.potsType[1]); + } + else { + ui->potsTypeSeparator->hide(); + ui->pot1Type->hide(); + ui->pot1TypeLabel->hide(); + ui->pot2Type->hide(); + ui->pot2TypeLabel->hide(); + } } GeneralEdit::~GeneralEdit() @@ -380,6 +393,18 @@ GeneralEdit::~GeneralEdit() delete ui; } +void GeneralEdit::on_pot1Type_currentIndexChanged(int index) +{ + g_eeGeneral.potsType[0] = index; + updateSettings(); +} + +void GeneralEdit::on_pot2Type_currentIndexChanged(int index) +{ + g_eeGeneral.potsType[1] = index; + updateSettings(); +} + void GeneralEdit::unlockSwitchEdited() { int i=0; diff --git a/companion/src/generaledit.h b/companion/src/generaledit.h index eb6895d13..ce160dc0b 100644 --- a/companion/src/generaledit.h +++ b/companion/src/generaledit.h @@ -119,6 +119,9 @@ private slots: void on_varioVolume_SL_valueChanged(); void on_wavVolume_SL_valueChanged(); + void on_pot1Type_currentIndexChanged(int index); + void on_pot2Type_currentIndexChanged(int index); + void on_stickmodeCB_currentIndexChanged(int index); void on_channelorderCB_currentIndexChanged(int index); void on_beeperCB_currentIndexChanged(int index); diff --git a/companion/src/generaledit.ui b/companion/src/generaledit.ui index 48a7445b5..29b17eb7d 100644 --- a/companion/src/generaledit.ui +++ b/companion/src/generaledit.ui @@ -110,7 +110,7 @@ These will be relevant for all models in the same EEPROM. - 0 + 3 @@ -3494,6 +3494,91 @@ p, li { white-space: pre-wrap; } + + + + + 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. + + + + Pot (normal) + + + + + Multipos Switch + + + + + + + + S1 Type + + + + + + + + + + + + + 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. + + + + Pot (normal) + + + + + Multipos Switch + + + + + + + + S2 Type + + + diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 97ef84275..2a5e4f2fc 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -1097,7 +1097,8 @@ void populateSourceCB(QComboBox *b, const RawSource & source, const ModelData & b->addItem(item.toString(), item.toValue()); if (item == source) b->setCurrentIndex(b->count()-1); } - } else if (flags & POPULATE_TELEMETRY) { + } + else if (flags & POPULATE_TELEMETRY) { for (int i=0; iaddItem(item.toString(), item.toValue()); From a3b785246762e19fc76a98e31ade5b3a8d265874 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Sat, 1 Feb 2014 09:52:27 +0100 Subject: [PATCH 11/12] Overflow in S2 type selection --- radio/src/gui/menu_general.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index c5f97dae9..1febca121 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -1191,7 +1191,7 @@ void menuGeneralHardware(uint8_t event) { int idx = i - ITEM_SETUP_HW_POT1; uint8_t mask = (1<> idx, 0, 1, attr, event); if (potType) g_eeGeneral.potsType |= mask; else From 7d5e37d5facbdd9a7cc8c707a8d7af27441e0677 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Sat, 1 Feb 2014 10:13:18 +0100 Subject: [PATCH 12/12] Reset pot type to Pot if max no of steps exceeded to avoid stray switch entry --- radio/src/gui/menu_general.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/radio/src/gui/menu_general.cpp b/radio/src/gui/menu_general.cpp index 1febca121..e422861fd 100644 --- a/radio/src/gui/menu_general.cpp +++ b/radio/src/gui/menu_general.cpp @@ -1314,6 +1314,9 @@ void menuCommonCalib(uint8_t event) if (count < POTS_POS_COUNT) { reusableBuffer.calib.xpotsCalib[idx].steps[count] = position; } + else { + g_eeGeneral.potsType &= !(1<