Switch 2D tables to pointers
This commit is contained in:
parent
e65ed37fea
commit
372f6da64e
|
@ -54,7 +54,7 @@ byte correctionWUE()
|
|||
//Possibly reduce the frequency this runs at (Costs about 50 loops per second)
|
||||
if (currentStatus.coolant > (WUETable.axisX[9] - CALIBRATION_TEMPERATURE_OFFSET)) { BIT_CLEAR(currentStatus.engine, BIT_ENGINE_WARMUP); return 100; } //This prevents us doing the 2D lookup if we're already up to temp
|
||||
BIT_SET(currentStatus.engine, BIT_ENGINE_WARMUP);
|
||||
return table2D_getValue(WUETable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET);
|
||||
return table2D_getValue(&WUETable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -121,7 +121,7 @@ byte correctionAccel()
|
|||
{
|
||||
BIT_SET(currentStatus.engine, BIT_ENGINE_ACC); //Mark accleration enrichment as active.
|
||||
currentStatus.TAEEndTime = micros() + ((unsigned long)configPage1.taeTime * 10000); //Set the time in the future where the enrichment will be turned off. taeTime is stored as mS / 10, so multiply it by 100 to get it in uS
|
||||
return 100 + table2D_getValue(taeTable, currentStatus.tpsDOT);
|
||||
return 100 + table2D_getValue(&taeTable, currentStatus.tpsDOT);
|
||||
}
|
||||
|
||||
//If we reach here then TAE is neither on, nor does it need to be turned on.
|
||||
|
@ -154,7 +154,7 @@ Uses a 2D enrichment table (WUETable) where the X axis is engine temp and the Y
|
|||
byte correctionsBatVoltage()
|
||||
{
|
||||
if (currentStatus.battery10 > (injectorVCorrectionTable.axisX[5])) { return injectorVCorrectionTable.values[injectorVCorrectionTable.xSize-1]; } //This prevents us doing the 2D lookup if the voltage is above maximum
|
||||
return table2D_getValue(injectorVCorrectionTable, currentStatus.battery10);
|
||||
return table2D_getValue(&injectorVCorrectionTable, currentStatus.battery10);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -36,10 +36,11 @@ void triggerPri_missingTooth()
|
|||
{
|
||||
// http://www.msextra.com/forums/viewtopic.php?f=94&t=22976
|
||||
// http://www.megamanual.com/ms2/wheel.htm
|
||||
noInterrupts();
|
||||
|
||||
curTime = micros();
|
||||
curGap = curTime - toothLastToothTime;
|
||||
if ( curGap < triggerFilterTime ) { return; } //Debounce check. Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS)
|
||||
if ( curGap < triggerFilterTime ) { interrupts(); return; } //Debounce check. Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS)
|
||||
toothCurrentCount++; //Increment the tooth counter
|
||||
|
||||
//High speed tooth logging history
|
||||
|
@ -66,7 +67,7 @@ void triggerPri_missingTooth()
|
|||
|
||||
toothLastMinusOneToothTime = toothLastToothTime;
|
||||
toothLastToothTime = curTime;
|
||||
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void triggerSec_missingTooth(){ return; } //This function currently is not used
|
||||
|
|
|
@ -485,7 +485,7 @@ void loop()
|
|||
if ( BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) ) { currentStatus.dwell = (configPage2.dwellCrank * 100); }
|
||||
else { currentStatus.dwell = (configPage2.dwellRun * 100); }
|
||||
//Pull battery voltage based dwell correction and apply if needed
|
||||
currentStatus.dwellCorrection = table2D_getValue(dwellVCorrectionTable, currentStatus.battery10);
|
||||
currentStatus.dwellCorrection = table2D_getValue(&dwellVCorrectionTable, currentStatus.battery10);
|
||||
if (currentStatus.dwellCorrection != 100) { currentStatus.dwell = divs100(currentStatus.dwell) * currentStatus.dwellCorrection; }
|
||||
int dwellAngle = (div(currentStatus.dwell, timePerDegree).quot ); //Convert the dwell time to dwell angle based on the current engine speed
|
||||
|
||||
|
|
5
table.h
5
table.h
|
@ -18,6 +18,9 @@ struct table2D {
|
|||
|
||||
int *values16;
|
||||
int *axisX16;
|
||||
|
||||
//Store the last X and Y coordinates in the table. This is used to make the next check faster
|
||||
byte lastXMax, lastXMin;
|
||||
};
|
||||
|
||||
void table2D_setSize(struct table2D targetTable, byte newSize);
|
||||
|
@ -50,6 +53,6 @@ Eg: 2x2 table
|
|||
|
||||
*/
|
||||
int get3DTableValue(struct table3D *fromTable, int, int);
|
||||
int table2D_getValue(struct table2D, int);
|
||||
int table2D_getValue(struct table2D *fromTable, int);
|
||||
|
||||
#endif // TABLE_H
|
||||
|
|
50
table.ino
50
table.ino
|
@ -35,21 +35,21 @@ ie: Given a value on the X axis, it returns a Y value that coresponds to the poi
|
|||
This function must take into account whether a table contains 8-bit or 16-bit values.
|
||||
Unfortunately this means many of the lines are duplicated depending on this
|
||||
*/
|
||||
int table2D_getValue(struct table2D fromTable, int X)
|
||||
int table2D_getValue(struct table2D *fromTable, int X)
|
||||
{
|
||||
|
||||
int xMinValue, xMaxValue;
|
||||
if (fromTable.valueSize == SIZE_BYTE)
|
||||
if (fromTable->valueSize == SIZE_BYTE)
|
||||
{
|
||||
//Byte version
|
||||
xMinValue = fromTable.axisX[0];
|
||||
xMaxValue = fromTable.axisX[fromTable.xSize-1];
|
||||
xMinValue = fromTable->axisX[0];
|
||||
xMaxValue = fromTable->axisX[fromTable->xSize-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
//int version
|
||||
xMinValue = fromTable.axisX16[0];
|
||||
xMaxValue = fromTable.axisX16[fromTable.xSize-1];
|
||||
xMinValue = fromTable->axisX16[0];
|
||||
xMaxValue = fromTable->axisX16[fromTable->xSize-1];
|
||||
}
|
||||
int xMin = 0;
|
||||
int xMax = 0;
|
||||
|
@ -58,21 +58,21 @@ int table2D_getValue(struct table2D fromTable, int X)
|
|||
if(X > xMaxValue) { X = xMaxValue; }
|
||||
if(X < xMinValue) { X = xMinValue; }
|
||||
|
||||
for (int x = fromTable.xSize-1; x >= 0; x--)
|
||||
for (int x = fromTable->xSize-1; x >= 0; x--)
|
||||
{
|
||||
if (fromTable.valueSize == SIZE_BYTE)
|
||||
if (fromTable->valueSize == SIZE_BYTE)
|
||||
{
|
||||
//Byte version
|
||||
//Checks the case where the X value is exactly what was requested
|
||||
if ( (X == fromTable.axisX[x]) || (x == 0) )
|
||||
if ( (X == fromTable->axisX[x]) || (x == 0) )
|
||||
{
|
||||
return fromTable.values[x]; //Simply return the coresponding value
|
||||
return fromTable->values[x]; //Simply return the coresponding value
|
||||
}
|
||||
//Normal case
|
||||
if ( (X <= fromTable.axisX[x]) && (X > fromTable.axisX[x-1]) )
|
||||
if ( (X <= fromTable->axisX[x]) && (X > fromTable->axisX[x-1]) )
|
||||
{
|
||||
xMaxValue = fromTable.axisX[x];
|
||||
xMinValue = fromTable.axisX[x-1];
|
||||
xMaxValue = fromTable->axisX[x];
|
||||
xMinValue = fromTable->axisX[x-1];
|
||||
xMax = x;
|
||||
xMin = x-1;
|
||||
break;
|
||||
|
@ -81,15 +81,15 @@ int table2D_getValue(struct table2D fromTable, int X)
|
|||
else
|
||||
{
|
||||
//int version
|
||||
if ( (X == fromTable.axisX16[x]) || (x == 0) )
|
||||
if ( (X == fromTable->axisX16[x]) || (x == 0) )
|
||||
{
|
||||
return fromTable.values16[x]; //Simply return the coresponding value
|
||||
return fromTable->values16[x]; //Simply return the coresponding value
|
||||
}
|
||||
//Normal case
|
||||
if ( (X <= fromTable.axisX16[x]) && (X > fromTable.axisX16[x-1]) )
|
||||
if ( (X <= fromTable->axisX16[x]) && (X > fromTable->axisX16[x-1]) )
|
||||
{
|
||||
xMaxValue = fromTable.axisX16[x];
|
||||
xMinValue = fromTable.axisX16[x-1];
|
||||
xMaxValue = fromTable->axisX16[x];
|
||||
xMinValue = fromTable->axisX16[x-1];
|
||||
xMax = x;
|
||||
xMin = x-1;
|
||||
break;
|
||||
|
@ -107,23 +107,23 @@ int table2D_getValue(struct table2D fromTable, int X)
|
|||
|
||||
//Non-Float version
|
||||
int yVal;
|
||||
if (fromTable.valueSize == SIZE_BYTE)
|
||||
if (fromTable->valueSize == SIZE_BYTE)
|
||||
{
|
||||
//Byte version
|
||||
yVal = ((long)(m << 6) / n) * (abs(fromTable.values[xMax] - fromTable.values[xMin]));
|
||||
yVal = ((long)(m << 6) / n) * (abs(fromTable->values[xMax] - fromTable->values[xMin]));
|
||||
yVal = (yVal >> 6);
|
||||
|
||||
if (fromTable.values[xMax] > fromTable.values[xMin]) { yVal = fromTable.values[xMin] + yVal; }
|
||||
else { yVal = fromTable.values[xMin] - yVal; }
|
||||
if (fromTable->values[xMax] > fromTable->values[xMin]) { yVal = fromTable->values[xMin] + yVal; }
|
||||
else { yVal = fromTable->values[xMin] - yVal; }
|
||||
}
|
||||
else
|
||||
{
|
||||
//int version
|
||||
yVal = ((long)(m << 6) / n) * (abs(fromTable.values16[xMax] - fromTable.values16[xMin]));
|
||||
yVal = ((long)(m << 6) / n) * (abs(fromTable->values16[xMax] - fromTable->values16[xMin]));
|
||||
yVal = (yVal >> 6);
|
||||
|
||||
if (fromTable.values[xMax] > fromTable.values16[xMin]) { yVal = fromTable.values16[xMin] + yVal; }
|
||||
else { yVal = fromTable.values16[xMin] - yVal; }
|
||||
if (fromTable->values[xMax] > fromTable->values16[xMin]) { yVal = fromTable->values16[xMin] + yVal; }
|
||||
else { yVal = fromTable->values16[xMin] - yVal; }
|
||||
}
|
||||
|
||||
return yVal;
|
||||
|
|
Loading…
Reference in New Issue