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:
parent
33eeb4cc64
commit
e4b3b3af85
5 changed files with 137 additions and 38 deletions
|
@ -1241,16 +1241,37 @@ void menuGeneralHardware(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);
|
||||
reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]);
|
||||
reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]);
|
||||
#if defined(PCBTARANIS)
|
||||
if(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<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.hiVals[i] = -15000;
|
||||
reusableBuffer.calib.midVals[i] = anaIn(i);
|
||||
#if defined(PCBTARANIS)
|
||||
if (i<NUM_XPOTS) {
|
||||
reusableBuffer.calib.xpotsPositionsCount[i] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1294,12 +1320,26 @@ void menuCommonCalib(uint8_t event)
|
|||
lcd_putsLeft(3*FH, STR_MENUWHENDONE);
|
||||
|
||||
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) {
|
||||
if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i])>50) {
|
||||
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; 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];
|
||||
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
|
||||
|
|
|
@ -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<<index));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (swtch >= SWSRC_FIRST_CSW && swtch <= SWSRC_LAST_CSW) {
|
||||
CustomSwData * cs = cswAddress(swtch-SWSRC_FIRST_CSW);
|
||||
return (cs->func != CS_OFF);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<NUM_STICKS+NUM_POTS+5; i++)
|
||||
sum += calibValues[i];
|
||||
return sum;
|
||||
|
@ -1301,8 +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];
|
||||
tmr10ms_t potsLastposStart[NUM_XPOTS];
|
||||
uint8_t potsPos[NUM_XPOTS];
|
||||
#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)) { \
|
||||
|
@ -1336,17 +1336,28 @@ void getSwitchesPosition()
|
|||
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<uint8_t>(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; i<NUM_XPOTS; i++) {
|
||||
if (g_eeGeneral.potsType & (1 << i)) {
|
||||
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[POT1+i];
|
||||
if (calib->count>0 && calib->count<6) {
|
||||
uint8_t pos = calib->count;
|
||||
int v = (int16_t)anaIn(POT1+i);
|
||||
for (int j=0; j<calib->count; 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<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
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue