Speeduino
table.h
Go to the documentation of this file.
1/*
2This file is used for everything related to maps/tables including their definition, functions etc
3*/
4#ifndef TABLE_H
5#define TABLE_H
6
7#define TABLE_RPM_MULTIPLIER 100
8#define TABLE_LOAD_MULTIPLIER 2
9
10//The shift amount used for the 3D table calculations
11#define TABLE_SHIFT_FACTOR 8
12#define TABLE_SHIFT_POWER (1UL<<TABLE_SHIFT_FACTOR)
13
14//Define the total table memory sizes. Used for adding up the static heap size
15#define TABLE3D_SIZE_16 (16 * 16 + 32 + 32 + (16 * sizeof(byte*))) //2 bytes for each value on the axis + allocation for array pointers
16#define TABLE3D_SIZE_12 (12 * 12 + 24 + 24 + (12 * sizeof(byte*))) //2 bytes for each value on the axis + allocation for array pointers
17#define TABLE3D_SIZE_8 (8 * 8 + 16 + 16 + (8 * sizeof(byte*))) //2 bytes for each value on the axis + allocation for array pointers
18#define TABLE3D_SIZE_6 (6 * 6 + 12 + 12 + (6 * sizeof(byte*))) //2 bytes for each value on the axis + allocation for array pointers
19#define TABLE3D_SIZE_4 (4 * 4 + 8 + 8 + (4 * sizeof(byte*))) //2 bytes for each value on the axis + allocation for array pointers
20
21//Define the table sizes
22#define TABLE_FUEL1_SIZE 16;
23#define TABLE_FUEL2_SIZE 16;
24#define TABLE_IGN1_SIZE 16;
25#define TABLE_IGN2_SIZE 16;
26#define TABLE_AFR_SIZE 16;
27#define TABLE_STAGING_SIZE 8;
28#define TABLE_BOOST_SIZE 8;
29#define TABLE_VVT1_SIZE 8;
30#define TABLE_VVT2_SIZE 8;
31#define TABLE_WMI_SIZE 8;
32#define TABLE_TRIM1_SIZE 6;
33#define TABLE_TRIM2_SIZE 6;
34#define TABLE_TRIM3_SIZE 6;
35#define TABLE_TRIM4_SIZE 6;
36#define TABLE_TRIM5_SIZE 6;
37#define TABLE_TRIM6_SIZE 6;
38#define TABLE_TRIM7_SIZE 6;
39#define TABLE_TRIM8_SIZE 6;
40#define TABLE_DWELL_SIZE 4;
41
42/*
43*********** WARNING! ***********
44YOU MUST UPDATE THE TABLE COUNTS IN THE LINE BELOW WHENEVER A NEW TABLE IS ADDED!
45*/
46#define TABLE_HEAP_SIZE ((5 * TABLE3D_SIZE_16) + (5 * TABLE3D_SIZE_8) + (8 * TABLE3D_SIZE_6) + (1 * TABLE3D_SIZE_4) + 1)
47
48
49/*
50The 2D table can contain either 8-bit (byte) or 16-bit (int) values
51The valueSize variable should be set to either 8 or 16 to indicate this BEFORE the table is used
52*/
53struct table2D {
54 //Used 5414 RAM with original version
57 byte xSize;
58
59 void *values;
60 void *axisX;
61
62 //int16_t *values16;
63 //int16_t *axisX16;
64
65 //Store the last X and Y coordinates in the table. This is used to make the next check faster
66 int16_t lastXMax;
67 int16_t lastXMin;
68
69 //Store the last input and output for caching
70 int16_t lastInput;
71 int16_t lastOutput;
72 byte cacheTime; //Tracks when the last cache value was set so it can expire after x seconds. A timeout is required to pickup when a tuning value is changed, otherwise the old cached value will continue to be returned as the X value isn't changing.
73};
74
75//void table2D_setSize(struct table2D targetTable, byte newSize);
76void table2D_setSize(struct table2D*, byte);
77int16_t table2D_getAxisValue(struct table2D*, byte);
78int16_t table2D_getRawValue(struct table2D*, byte);
79
80struct table3D {
81
82 //All tables must be the same size for simplicity
83
84 byte xSize;
85 byte ySize;
86
87 byte **values;
88 int16_t *axisX;
89 int16_t *axisY;
90
91 //Store the last X and Y coordinates in the table. This is used to make the next check faster
94
95 //Store the last input and output values, again for caching purposes
97 byte lastOutput; //This will need changing if we ever have 16-bit table values
99};
100
101//void table3D_setSize(struct table3D *targetTable, byte);
102void table3D_setSize(struct table3D *targetTable, byte);
103
104/*
1053D Tables have an origin (0,0) in the top left hand corner. Vertical axis is expressed first.
106Eg: 2x2 table
107-----
108|2 7|
109|1 4|
110-----
111
112(0,1) = 7
113(0,0) = 2
114(1,0) = 1
115
116*/
117int get3DTableValue(struct table3D *fromTable, int, int);
118int table2D_getValue(struct table2D *fromTable, int);
119
120#endif // TABLE_H
Definition: table.h:53
int16_t lastXMax
Definition: table.h:66
byte xSize
Definition: table.h:57
void * axisX
Definition: table.h:60
int16_t lastXMin
Definition: table.h:67
byte cacheTime
Definition: table.h:72
byte valueSize
Definition: table.h:55
int16_t lastOutput
Definition: table.h:71
void * values
Definition: table.h:59
int16_t lastInput
Definition: table.h:70
byte axisSize
Definition: table.h:56
Definition: table.h:80
byte lastXMax
Definition: table.h:92
byte ySize
Definition: table.h:85
int16_t lastYInput
Definition: table.h:96
byte ** values
Definition: table.h:87
byte lastYMin
Definition: table.h:93
byte lastOutput
Definition: table.h:97
bool cacheIsValid
This tracks whether the tables cache should be used. Ordinarily this is true, but is set to false whe...
Definition: table.h:98
int16_t * axisY
Definition: table.h:89
int16_t * axisX
Definition: table.h:88
int16_t lastXInput
Definition: table.h:96
byte xSize
Definition: table.h:84
byte lastYMax
Definition: table.h:93
byte lastXMin
Definition: table.h:92
int table2D_getValue(struct table2D *fromTable, int)
Definition: table.ino:84
int16_t table2D_getAxisValue(struct table2D *, byte)
Returns an axis (bin) value from the 2D table. This works regardless of whether that axis is bytes or...
Definition: table.ino:185
void table3D_setSize(struct table3D *targetTable, byte)
Definition: table.ino:54
void table2D_setSize(struct table2D *, byte)
int16_t table2D_getRawValue(struct table2D *, byte)
Returns an value from the 2D table given an index value. No interpolation is performed.
Definition: table.ino:202
int get3DTableValue(struct table3D *fromTable, int, int)
Definition: table.ino:215