[Taranis] Automatic detection of the 6pos switch within the calibration
process
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user