1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 16:25:16 +03:00

[Taranis] Automatic detection of the 6pos switch within the calibration

process
This commit is contained in:
Bertrand Songis 2014-01-06 11:52:05 +01:00
parent 33eeb4cc64
commit e4b3b3af85
5 changed files with 137 additions and 38 deletions

View file

@ -1241,16 +1241,37 @@ void menuGeneralHardware(uint8_t event)
void menuCommonCalib(uint8_t event) void menuCommonCalib(uint8_t event)
{ {
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { //get low and high vals for sticks and trims for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { // get low and high vals for sticks and trims
int16_t vt = anaIn(i); int16_t vt = anaIn(i);
reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]); reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]);
reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]); reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]);
#if defined(PCBTARANIS) if (i >= POT1 && i <= POT_LAST) {
if(i >= NUM_STICKS && i < NUM_STICKS+NUM_POTS-2) {
#else
if (i >= NUM_STICKS) {
#endif
reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2; 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<count; j++) {
if (vt > 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.loVals[i] = 15000;
reusableBuffer.calib.hiVals[i] = -15000; reusableBuffer.calib.hiVals[i] = -15000;
reusableBuffer.calib.midVals[i] = anaIn(i); reusableBuffer.calib.midVals[i] = anaIn(i);
#if defined(PCBTARANIS)
if (i<NUM_XPOTS) {
reusableBuffer.calib.xpotsPositionsCount[i] = 0;
}
#endif
} }
break; break;
@ -1294,12 +1320,26 @@ void menuCommonCalib(uint8_t event)
lcd_putsLeft(3*FH, STR_MENUWHENDONE); lcd_putsLeft(3*FH, STR_MENUWHENDONE);
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) {
if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i])>50) { #if defined(PCBTARANIS)
g_eeGeneral.calibMid[i] = reusableBuffer.calib.midVals[i]; 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; j<calib->count-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]; 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]; 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; break;
@ -1316,6 +1356,7 @@ void menuCommonCalib(uint8_t event)
} }
doMainScreenGraphics(); doMainScreenGraphics();
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
drawPotsBars(); drawPotsBars();
#endif #endif

View file

@ -1263,7 +1263,14 @@ bool isSwitchAvailable(int16_t swtch)
swtch = -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<<index));
}
#endif
if (swtch >= SWSRC_FIRST_CSW && swtch <= SWSRC_LAST_CSW) {
CustomSwData * cs = cswAddress(swtch-SWSRC_FIRST_CSW); CustomSwData * cs = cswAddress(swtch-SWSRC_FIRST_CSW);
return (cs->func != CS_OFF); return (cs->func != CS_OFF);
} }

View file

@ -221,7 +221,7 @@ enum BeeperMode {
}; };
#if defined(CPUARM) #if defined(CPUARM)
#define EXTRA_GENERAL_FIELDS \ #define EXTRA_GENERAL_FIELDS_ARM \
uint8_t backlightBright; \ uint8_t backlightBright; \
int8_t currentCalib; \ int8_t currentCalib; \
int8_t temperatureWarn; \ int8_t temperatureWarn; \
@ -240,6 +240,14 @@ enum BeeperMode {
int8_t wavVolume; \ int8_t wavVolume; \
int8_t varioVolume; \ int8_t varioVolume; \
int8_t backgroundVolume; 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) #elif defined(PXX)
#define EXTRA_GENERAL_FIELDS uint8_t countryCode; #define EXTRA_GENERAL_FIELDS uint8_t countryCode;
#else #else
@ -303,13 +311,24 @@ enum BacklightMode {
#define SPLASH_MODE uint8_t splashMode:1; uint8_t spare4:2 #define SPLASH_MODE uint8_t splashMode:1; uint8_t spare4:2
#endif #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 #define ALTERNATE_VIEW 0x10
PACK(typedef struct t_EEGeneral { PACK(typedef struct t_EEGeneral {
uint8_t version; uint8_t version;
uint16_t variant; uint16_t variant;
int16_t calibMid[NUM_STICKS+NUM_POTS]; CalibData calib[NUM_STICKS+NUM_POTS];
int16_t calibSpanNeg[NUM_STICKS+NUM_POTS];
int16_t calibSpanPos[NUM_STICKS+NUM_POTS];
uint16_t chkSum; uint16_t chkSum;
int8_t currModel; int8_t currModel;
uint8_t contrast; uint8_t contrast;

View file

@ -503,7 +503,7 @@ void generalDefault()
uint16_t evalChkSum() uint16_t evalChkSum()
{ {
uint16_t sum = 0; 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<NUM_STICKS+NUM_POTS+5; i++) for (int i=0; i<NUM_STICKS+NUM_POTS+5; i++)
sum += calibValues[i]; sum += calibValues[i];
return sum; return sum;
@ -1301,8 +1301,8 @@ uint8_t cswStates[NUM_CSW];
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
tmr10ms_t switchesMidposStart[6] = { 0 }; tmr10ms_t switchesMidposStart[6] = { 0 };
uint32_t switchesPos = 0; uint32_t switchesPos = 0;
tmr10ms_t potsLastposStart[2]; tmr10ms_t potsLastposStart[NUM_XPOTS];
uint8_t potsPos[2]; uint8_t potsPos[NUM_XPOTS];
#define DELAY_SWITCH_3POS 10/*100ms*/ #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_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)) { \ #define CHECK_3POS(idx, sw) if (switchState(sw ## 0)) { \
@ -1336,17 +1336,28 @@ void getSwitchesPosition()
CHECK_2POS(SW_SH); CHECK_2POS(SW_SH);
switchesPos = newPos; switchesPos = newPos;
for (int i=0; i<2; i++) { for (int i=0; i<NUM_XPOTS; i++) {
int val = RESX + (int16_t)anaIn(POT1+i) + (RESX / 5); if (g_eeGeneral.potsType & (1 << i)) {
uint8_t pos = limit<uint8_t>(0, val / (2*RESX/5), 5); StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[POT1+i];
uint8_t previousPos = potsPos[i] >> 4; if (calib->count>0 && calib->count<6) {
if (pos != previousPos) { uint8_t pos = calib->count;
potsLastposStart[i] = get_tmr10ms(); int v = (int16_t)anaIn(POT1+i);
potsPos[i] = (pos << 4) | (potsPos[i] & 0x0f); for (int j=0; j<calib->count; j++) {
} if (v < calib->steps[j]) {
else if ((tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { pos = j;
potsLastposStart[i] = 0; break;
potsPos[i] = (pos << 4) | (pos); }
}
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 ; int16_t lowLim = THRCHK_DEADBAND - 1024 ;
#else #else
getADC(); // if thr is down - do not display warning at all getADC(); // if thr is down - do not display warning at all
int16_t lowLim = g_eeGeneral.calibMid[thrchn]; CalibData * calib = &g_eeGeneral.calib[thrchn];
lowLim = (g_model.throttleReversed ? - lowLim - g_eeGeneral.calibSpanPos[thrchn] : lowLim - g_eeGeneral.calibSpanNeg[thrchn]); int16_t lowLim = calib->mid;
lowLim = (g_model.throttleReversed ? - lowLim - calib->spanPos : lowLim - calib->spanNeg);
lowLim += THRCHK_DEADBAND; lowLim += THRCHK_DEADBAND;
#endif #endif
int16_t v = thrAnaIn(thrchn); int16_t v = thrAnaIn(thrchn);
@ -2495,7 +2507,23 @@ void getADC()
} }
for (uint32_t x=0; x<NUMBER_ANALOG; x++) { for (uint32_t x=0; x<NUMBER_ANALOG; x++) {
s_anaFilt[x] = temp[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 #else
@ -2743,10 +2771,9 @@ void evalInputs(uint8_t mode)
#ifndef SIMU #ifndef SIMU
if (i < NUM_STICKS+NUM_POTS) { if (i < NUM_STICKS+NUM_POTS) {
v -= g_eeGeneral.calibMid[i]; CalibData * calib = &g_eeGeneral.calib[i];
v = v * (int32_t)RESX / (max((int16_t)100,(v>0 ? v -= calib->mid;
g_eeGeneral.calibSpanPos[i] : v = v * (int32_t)RESX / (max((int16_t)100, (v>0 ? calib->spanPos : calib->spanNeg)));
g_eeGeneral.calibSpanNeg[i])));
} }
#endif #endif

View file

@ -377,7 +377,7 @@ enum EnumKeys {
#define NUM_SWITCHES 8 #define NUM_SWITCHES 8
#define IS_3POS(sw) ((sw) != 5 && (sw) != 7) #define IS_3POS(sw) ((sw) != 5 && (sw) != 7)
#define NUM_POTS 4 #define NUM_POTS 4
#define NUM_POTSSW (2*6) #define NUM_XPOTS 2
#define NUM_SW_SRCRAW 8 #define NUM_SW_SRCRAW 8
#define SWSRC_THR SWSRC_SF2 #define SWSRC_THR SWSRC_SF2
#define SWSRC_GEA SWSRC_SG2 #define SWSRC_GEA SWSRC_SG2
@ -390,12 +390,13 @@ enum EnumKeys {
#define IS_3POS(sw) ((sw) == 0) #define IS_3POS(sw) ((sw) == 0)
#define IS_MOMENTARY(sw) (sw == SWSRC_TRN) #define IS_MOMENTARY(sw) (sw == SWSRC_TRN)
#define NUM_POTS 3 #define NUM_POTS 3
#define NUM_POTSSW 0 #define NUM_XPOTS 0
#define NUM_SW_SRCRAW 1 #define NUM_SW_SRCRAW 1
#define SW_DSM2_BIND SW_TRN #define SW_DSM2_BIND SW_TRN
#endif #endif
#define NUM_PSWITCH (SWSRC_LAST_SWITCH-SWSRC_FIRST_SWITCH+1) #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) #define NUM_SWITCH (NUM_PSWITCH+NUM_CSW+NUM_POTSSW)
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
@ -1042,12 +1043,14 @@ enum Analogs {
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
POT1, POT1,
POT2, POT2,
POT_LAST = POT2,
SLIDER1, SLIDER1,
SLIDER2, SLIDER2,
#else #else
POT1, POT1,
POT2, POT2,
POT3, POT3,
POT_LAST = POT3,
#endif #endif
TX_VOLTAGE, TX_VOLTAGE,
#if defined(PCBSKY9X) && !defined(REVA) #if defined(PCBSKY9X) && !defined(REVA)
@ -1565,6 +1568,8 @@ union ReusableBuffer
int16_t loVals[NUM_STICKS+NUM_POTS]; int16_t loVals[NUM_STICKS+NUM_POTS];
int16_t hiVals[NUM_STICKS+NUM_POTS]; int16_t hiVals[NUM_STICKS+NUM_POTS];
uint8_t state; uint8_t state;
uint8_t xpotsPositionsCount[NUM_XPOTS];
int16_t xpotsPositions[NUM_XPOTS][6][2];
} calib; } calib;
#if defined(SDCARD) #if defined(SDCARD)