mirror of https://github.com/rusefi/speeduino.git
Allow for dynamically sized 3d tables
This commit is contained in:
parent
d2516460d3
commit
f8fd0f9692
|
@ -201,7 +201,7 @@ void receiveValue(int offset, byte newValue)
|
||||||
if (offset < 272)
|
if (offset < 272)
|
||||||
{
|
{
|
||||||
//X Axis
|
//X Axis
|
||||||
fuelTable.axisX[(offset-256)] = ((int)(newValue) * 100); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct
|
fuelTable.axisX[(offset-256)] = ((int)(newValue) * 100); //The RPM values sent by tunerstudio are divided by 100, need to multiple it back by 100 to make it correct
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,6 +108,10 @@ void setup()
|
||||||
//Setup the dummy fuel and ignition tables
|
//Setup the dummy fuel and ignition tables
|
||||||
//dummyFuelTable(&fuelTable);
|
//dummyFuelTable(&fuelTable);
|
||||||
//dummyIgnitionTable(&ignitionTable);
|
//dummyIgnitionTable(&ignitionTable);
|
||||||
|
table3D_setSize(&fuelTable, 16);
|
||||||
|
table3D_setSize(&ignitionTable, 16);
|
||||||
|
table3D_setSize(&afrTable, 16);
|
||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
//Repoint the 2D table structs to the config pages that were just loaded
|
//Repoint the 2D table structs to the config pages that were just loaded
|
||||||
|
|
16
table.h
16
table.h
|
@ -26,19 +26,23 @@ struct table2D {
|
||||||
void table2D_setSize(struct table2D targetTable, byte newSize);
|
void table2D_setSize(struct table2D targetTable, byte newSize);
|
||||||
|
|
||||||
struct table3D {
|
struct table3D {
|
||||||
//All tables must be the same size for simplicity
|
|
||||||
const static byte xSize = 16;
|
|
||||||
const static byte ySize = 16;
|
|
||||||
|
|
||||||
byte values[ySize][xSize];
|
//All tables must be the same size for simplicity
|
||||||
int axisX[xSize];
|
|
||||||
int axisY[ySize];
|
byte xSize;
|
||||||
|
byte ySize;
|
||||||
|
|
||||||
|
byte **values;
|
||||||
|
int *axisX;
|
||||||
|
int *axisY;
|
||||||
|
|
||||||
//Store the last X and Y coordinates in the table. This is used to make the next check faster
|
//Store the last X and Y coordinates in the table. This is used to make the next check faster
|
||||||
byte lastXMax, lastXMin;
|
byte lastXMax, lastXMin;
|
||||||
byte lastYMax, lastYMin;
|
byte lastYMax, lastYMin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void table3D_setSize(struct table3D *targetTable, byte newSize);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
3D Tables have an origin (0,0) in the top left hand corner. Vertical axis is expressed first.
|
3D Tables have an origin (0,0) in the top left hand corner. Vertical axis is expressed first.
|
||||||
Eg: 2x2 table
|
Eg: 2x2 table
|
||||||
|
|
12
table.ino
12
table.ino
|
@ -28,6 +28,18 @@ void table2D_setSize(struct table2D* targetTable, byte newSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void table3D_setSize(struct table3D *targetTable, byte newSize)
|
||||||
|
{
|
||||||
|
targetTable->values = (byte **)malloc(newSize * sizeof(byte*));
|
||||||
|
for(byte i = 0; i < newSize; i++) { targetTable->values[i] = (byte *)malloc(newSize * sizeof(byte)); }
|
||||||
|
|
||||||
|
targetTable->axisX = (int *)malloc(newSize * sizeof(int));
|
||||||
|
targetTable->axisY = (int *)malloc(newSize * sizeof(int));
|
||||||
|
targetTable->xSize = newSize;
|
||||||
|
targetTable->ySize = newSize;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function simply pulls a 1D linear interpolated (ie averaged) value from a 2D table
|
This function simply pulls a 1D linear interpolated (ie averaged) value from a 2D table
|
||||||
ie: Given a value on the X axis, it returns a Y value that coresponds to the point on the curve between the nearest two defined X values
|
ie: Given a value on the X axis, it returns a Y value that coresponds to the point on the curve between the nearest two defined X values
|
||||||
|
|
Loading…
Reference in New Issue