2015-05-28 16:49:44 -07:00
/*
Speeduino - Simple engine management for the Arduino Mega 2560 platform
Copyright ( C ) Josh Stewart
A full copy of the license may be found in the projects root directory
*/
2013-07-18 04:53:40 -07:00
# include <EEPROM.h>
2015-02-14 09:04:00 -08:00
# include "storage.h"
# include "globals.h"
2014-05-12 04:28:24 -07:00
//#include "table.h"
2013-07-16 05:29:17 -07:00
2015-02-14 09:04:00 -08:00
2013-08-25 21:11:47 -07:00
/*
Takes the current configuration ( config pages and maps )
2014-01-09 23:54:33 -08:00
and writes them to EEPROM as per the layout defined in storage . h
2013-08-25 21:11:47 -07:00
*/
2013-07-18 04:53:40 -07:00
void writeConfig ( )
{
/*
We only ever write to the EEPROM where the new value is different from the currently stored byte
This is due to the limited write life of the EEPROM ( Approximately 100 , 000 writes )
*/
2013-08-25 21:11:47 -07:00
int offset ;
//Create a pointer to the config page
byte * pnt_configPage ;
2013-07-18 04:53:40 -07:00
if ( EEPROM . read ( 0 ) ! = data_structure_version ) { EEPROM . write ( 0 , data_structure_version ) ; } //Write the data structure version
2013-08-25 21:11:47 -07:00
2015-06-05 00:28:31 -07:00
/*---------------------------------------------------
| Fuel table ( See storage . h for data layout ) - Page 1
| 16 x16 table itself + the 16 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2013-07-18 04:53:40 -07:00
if ( EEPROM . read ( EEPROM_CONFIG1_XSIZE ) ! = fuelTable . xSize ) { EEPROM . write ( EEPROM_CONFIG1_XSIZE , fuelTable . xSize ) ; } //Write the VE Tables RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG1_YSIZE ) ! = fuelTable . ySize ) { EEPROM . write ( EEPROM_CONFIG1_YSIZE , fuelTable . ySize ) ; } //Write the VE Tables MAP/TPS dimension size
2013-08-25 21:11:47 -07:00
for ( int x = EEPROM_CONFIG1_MAP ; x < EEPROM_CONFIG1_XBINS ; x + + )
2013-07-18 04:53:40 -07:00
{
2013-08-25 21:11:47 -07:00
offset = x - EEPROM_CONFIG1_MAP ;
2015-06-05 00:28:31 -07:00
if ( EEPROM . read ( x ) ! = fuelTable . values [ 15 - offset / 16 ] [ offset % 16 ] ) { EEPROM . write ( x , fuelTable . values [ 15 - offset / 16 ] [ offset % 16 ] ) ; } //Write the 16x16 map
2013-08-25 21:11:47 -07:00
}
2013-09-15 05:39:55 -07:00
2013-08-25 21:11:47 -07:00
//RPM bins
for ( int x = EEPROM_CONFIG1_XBINS ; x < EEPROM_CONFIG1_YBINS ; x + + )
{
offset = x - EEPROM_CONFIG1_XBINS ;
2013-09-14 04:29:21 -07:00
if ( EEPROM . read ( x ) ! = byte ( fuelTable . axisX [ offset ] / 100 ) ) { EEPROM . write ( x , byte ( fuelTable . axisX [ offset ] / 100 ) ) ; } //RPM bins are divided by 100 and converted to a byte
2013-08-25 21:11:47 -07:00
}
//TPS/MAP bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG1_YBINS ; x < EEPROM_CONFIG2_START ; x + + )
2013-08-25 21:11:47 -07:00
{
offset = x - EEPROM_CONFIG1_YBINS ;
if ( EEPROM . read ( x ) ! = fuelTable . axisY [ offset ] ) { EEPROM . write ( x , fuelTable . axisY [ offset ] ) ; }
}
2013-07-18 04:53:40 -07:00
//That concludes the writing of the VE table
2015-06-05 00:28:31 -07:00
//*********************************************************************************************************************************************************************************
2013-07-18 04:53:40 -07:00
2015-06-05 00:28:31 -07:00
/*---------------------------------------------------
| Config page 2 ( See storage . h for data layout )
| 64 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
pnt_configPage = ( byte * ) & configPage1 ; //Create a pointer to Page 2 in memory
for ( int x = EEPROM_CONFIG2_START ; x < EEPROM_CONFIG2_END ; x + + )
{
2015-06-09 06:32:00 -07:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG2_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG2_START ) ) ) ; }
2015-06-05 00:28:31 -07:00
}
2013-09-11 05:06:13 -07:00
//*********************************************************************************************************************************************************************************
2015-06-05 00:28:31 -07:00
/*---------------------------------------------------
| Ignition table ( See storage . h for data layout ) - Page 1
| 16 x16 table itself + the 16 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2013-07-18 04:53:40 -07:00
//Begin writing the Ignition table, basically the same thing as above
2015-06-05 00:28:31 -07:00
if ( EEPROM . read ( EEPROM_CONFIG3_XSIZE ) ! = ignitionTable . xSize ) { EEPROM . write ( EEPROM_CONFIG3_XSIZE , ignitionTable . xSize ) ; } //Write the ignition Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG3_YSIZE ) ! = ignitionTable . ySize ) { EEPROM . write ( EEPROM_CONFIG3_YSIZE , ignitionTable . ySize ) ; } //Write the ignition Table MAP/TPS dimension size
2013-07-18 04:53:40 -07:00
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG3_MAP ; x < EEPROM_CONFIG3_XBINS ; x + + )
2013-09-11 05:06:13 -07:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG3_MAP ;
if ( EEPROM . read ( x ) ! = ignitionTable . values [ 15 - offset / 16 ] [ offset % 16 ] ) { EEPROM . write ( x , ignitionTable . values [ 15 - offset / 16 ] [ offset % 16 ] ) ; } //Write the 16x16 map with translation
2013-09-11 05:06:13 -07:00
}
//RPM bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG3_XBINS ; x < EEPROM_CONFIG3_YBINS ; x + + )
2013-09-11 05:06:13 -07:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG3_XBINS ;
2013-09-14 04:29:21 -07:00
if ( EEPROM . read ( x ) ! = byte ( ignitionTable . axisX [ offset ] / 100 ) ) { EEPROM . write ( x , byte ( ignitionTable . axisX [ offset ] / 100 ) ) ; } //RPM bins are divided by 100 and converted to a byte
2013-09-11 05:06:13 -07:00
}
//TPS/MAP bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG3_YBINS ; x < EEPROM_CONFIG4_START ; x + + )
2013-09-11 05:06:13 -07:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG3_YBINS ;
2013-09-11 05:06:13 -07:00
if ( EEPROM . read ( x ) ! = ignitionTable . axisY [ offset ] ) { EEPROM . write ( x , ignitionTable . axisY [ offset ] ) ; }
}
2015-02-03 02:33:22 -08:00
//That concludes the writing of the IGN table
2015-06-05 00:28:31 -07:00
//*********************************************************************************************************************************************************************************
2015-02-03 02:33:22 -08:00
2015-06-05 00:28:31 -07:00
/*---------------------------------------------------
| Config page 2 ( See storage . h for data layout )
| 64 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
pnt_configPage = ( byte * ) & configPage2 ; //Create a pointer to Page 2 in memory
for ( int x = EEPROM_CONFIG4_START ; x < EEPROM_CONFIG4_END ; x + + )
{
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG4_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG4_START ) ) ) ; }
}
2015-02-03 02:33:22 -08:00
//*********************************************************************************************************************************************************************************
2015-06-05 00:28:31 -07:00
/*---------------------------------------------------
| AFR table ( See storage . h for data layout ) - Page 5
| 16 x16 table itself + the 16 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2015-02-03 02:33:22 -08:00
//Begin writing the Ignition table, basically the same thing as above
2015-06-05 00:28:31 -07:00
if ( EEPROM . read ( EEPROM_CONFIG5_XSIZE ) ! = afrTable . xSize ) { EEPROM . write ( EEPROM_CONFIG5_XSIZE , afrTable . xSize ) ; } //Write the ignition Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG5_YSIZE ) ! = afrTable . ySize ) { EEPROM . write ( EEPROM_CONFIG5_YSIZE , afrTable . ySize ) ; } //Write the ignition Table MAP/TPS dimension size
2015-02-03 02:33:22 -08:00
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG5_MAP ; x < EEPROM_CONFIG5_XBINS ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG5_MAP ;
if ( EEPROM . read ( x ) ! = afrTable . values [ 15 - offset / 16 ] [ offset % 16 ] ) { EEPROM . write ( x , afrTable . values [ 15 - offset / 16 ] [ offset % 16 ] ) ; } //Write the 16x16 map
2015-02-03 02:33:22 -08:00
}
//RPM bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG5_XBINS ; x < EEPROM_CONFIG5_YBINS ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG5_XBINS ;
2015-02-03 02:33:22 -08:00
if ( EEPROM . read ( x ) ! = byte ( afrTable . axisX [ offset ] / 100 ) ) { EEPROM . write ( x , byte ( afrTable . axisX [ offset ] / 100 ) ) ; } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG5_YBINS ; x < EEPROM_CONFIG6_START ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG5_YBINS ;
2015-02-03 02:33:22 -08:00
if ( EEPROM . read ( x ) ! = afrTable . axisY [ offset ] ) { EEPROM . write ( x , afrTable . axisY [ offset ] ) ; }
}
2015-06-05 00:28:31 -07:00
//That concludes the writing of the AFR table
//*********************************************************************************************************************************************************************************
/*---------------------------------------------------
| Config page 3 ( See storage . h for data layout )
| 64 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
pnt_configPage = ( byte * ) & configPage3 ; //Create a pointer to Page 3 in memory
for ( int x = EEPROM_CONFIG6_START ; x < EEPROM_CONFIG6_END ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG6_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG6_START ) ) ) ; }
2015-02-03 02:33:22 -08:00
}
2015-05-30 12:30:08 -07:00
//*********************************************************************************************************************************************************************************
2015-06-05 00:28:31 -07:00
/*---------------------------------------------------
| Config page 4 ( See storage . h for data layout )
| 64 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2015-05-30 12:30:08 -07:00
pnt_configPage = ( byte * ) & configPage4 ; //Create a pointer to Page 4 in memory
//The next 128 bytes can simply be pulled straight from the configTable
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG7_START ; x < EEPROM_CONFIG7_END ; x + + )
2015-05-30 12:30:08 -07:00
{
2015-06-05 00:28:31 -07:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG7_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG7_START ) ) ) ; }
2015-05-30 12:30:08 -07:00
}
2015-09-25 04:02:15 -07:00
/*---------------------------------------------------
| Boost and vvt tables ( See storage . h for data layout ) - Page 8
| 8 x8 table itself + the 8 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
//Begin writing the 2 tables, basically the same thing as above but we're doing these 2 together (2 tables per page instead of 1)
if ( EEPROM . read ( EEPROM_CONFIG8_XSIZE1 ) ! = boostTable . xSize ) { EEPROM . write ( EEPROM_CONFIG8_XSIZE1 , boostTable . xSize ) ; } //Write the boost Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_YSIZE1 ) ! = boostTable . ySize ) { EEPROM . write ( EEPROM_CONFIG8_YSIZE1 , boostTable . ySize ) ; } //Write the boost Table MAP/TPS dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_XSIZE2 ) ! = vvtTable . xSize ) { EEPROM . write ( EEPROM_CONFIG8_XSIZE2 , vvtTable . xSize ) ; } //Write the vvt Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_YSIZE2 ) ! = vvtTable . ySize ) { EEPROM . write ( EEPROM_CONFIG8_YSIZE2 , vvtTable . ySize ) ; } //Write the vvt Table MAP/TPS dimension size
int y = EEPROM_CONFIG8_MAP2 ; //We do the 2 maps together in the same loop
for ( int x = EEPROM_CONFIG8_MAP1 ; x < EEPROM_CONFIG8_XBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG8_MAP1 ;
if ( EEPROM . read ( x ) ! = boostTable . values [ 7 - offset / 8 ] [ offset % 8 ] ) { EEPROM . write ( x , boostTable . values [ 7 - offset / 8 ] [ offset % 8 ] ) ; } //Write the 8x8 map
offset = y - EEPROM_CONFIG8_MAP2 ;
if ( EEPROM . read ( y ) ! = vvtTable . values [ 7 - offset / 8 ] [ offset % 8 ] ) { EEPROM . write ( y , vvtTable . values [ 7 - offset / 8 ] [ offset % 8 ] ) ; } //Write the 8x8 map
y + + ;
}
//RPM bins
y = EEPROM_CONFIG8_XBINS2 ;
for ( int x = EEPROM_CONFIG8_XBINS1 ; x < EEPROM_CONFIG8_YBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG8_XBINS1 ;
if ( EEPROM . read ( x ) ! = byte ( boostTable . axisX [ offset ] / 100 ) ) { EEPROM . write ( x , byte ( boostTable . axisX [ offset ] / 100 ) ) ; } //RPM bins are divided by 100 and converted to a byte
offset = y - EEPROM_CONFIG8_XBINS2 ;
if ( EEPROM . read ( y ) ! = byte ( vvtTable . axisX [ offset ] / 100 ) ) { EEPROM . write ( y , byte ( vvtTable . axisX [ offset ] / 100 ) ) ; } //RPM bins are divided by 100 and converted to a byte
y + + ;
}
//TPS/MAP bins
y = EEPROM_CONFIG8_YBINS2 ;
2015-09-28 04:57:27 -07:00
for ( int x = EEPROM_CONFIG8_YBINS1 ; x < EEPROM_CONFIG8_XSIZE2 ; x + + )
2015-09-25 04:02:15 -07:00
{
offset = x - EEPROM_CONFIG8_YBINS1 ;
if ( EEPROM . read ( x ) ! = boostTable . axisY [ offset ] ) { EEPROM . write ( x , boostTable . axisY [ offset ] ) ; }
2015-09-28 04:57:27 -07:00
offset = y - EEPROM_CONFIG8_YBINS2 ;
2015-09-25 04:02:15 -07:00
if ( EEPROM . read ( y ) ! = vvtTable . axisY [ offset ] ) { EEPROM . write ( y , vvtTable . axisY [ offset ] ) ; }
2015-09-28 04:57:27 -07:00
y + + ;
2015-09-25 04:02:15 -07:00
}
2016-10-24 23:31:44 -07:00
/*---------------------------------------------------
| Fuel trim tables ( See storage . h for data layout ) - Page 9
| 6 x6 tables itself + the 6 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
//Begin writing the 2 tables, basically the same thing as above but we're doing these 2 together (2 tables per page instead of 1)
EEPROM . update ( EEPROM_CONFIG9_XSIZE1 , trim1Table . xSize ) ; //Write the boost Table RPM dimension size
EEPROM . update ( EEPROM_CONFIG9_YSIZE1 , trim1Table . ySize ) ; //Write the boost Table MAP/TPS dimension size
EEPROM . update ( EEPROM_CONFIG9_XSIZE2 , trim2Table . xSize ) ; //Write the boost Table RPM dimension size
EEPROM . update ( EEPROM_CONFIG9_YSIZE2 , trim2Table . ySize ) ; //Write the boost Table MAP/TPS dimension size
EEPROM . update ( EEPROM_CONFIG9_XSIZE3 , trim3Table . xSize ) ; //Write the boost Table RPM dimension size
EEPROM . update ( EEPROM_CONFIG9_YSIZE3 , trim3Table . ySize ) ; //Write the boost Table MAP/TPS dimension size
EEPROM . update ( EEPROM_CONFIG9_XSIZE4 , trim4Table . xSize ) ; //Write the boost Table RPM dimension size
EEPROM . update ( EEPROM_CONFIG9_YSIZE4 , trim4Table . ySize ) ; //Write the boost Table MAP/TPS dimension size
y = EEPROM_CONFIG9_MAP2 ; //We do the 4 maps together in the same loop
int z = EEPROM_CONFIG9_MAP3 ; //We do the 4 maps together in the same loop
int i = EEPROM_CONFIG9_MAP4 ; //We do the 4 maps together in the same loop
for ( int x = EEPROM_CONFIG9_MAP1 ; x < EEPROM_CONFIG9_XBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG9_MAP1 ;
EEPROM . update ( x , trim1Table . values [ 5 - offset / 6 ] [ offset % 6 ] ) ; //Write the 6x6 map
offset = y - EEPROM_CONFIG9_MAP2 ;
EEPROM . update ( y , trim2Table . values [ 5 - offset / 6 ] [ offset % 6 ] ) ; //Write the 6x6 map
offset = z - EEPROM_CONFIG9_MAP3 ;
EEPROM . update ( z , trim3Table . values [ 5 - offset / 6 ] [ offset % 6 ] ) ; //Write the 6x6 map
offset = i - EEPROM_CONFIG9_MAP4 ;
EEPROM . update ( i , trim4Table . values [ 5 - offset / 6 ] [ offset % 6 ] ) ; //Write the 6x6 map
y + + ;
z + + ;
i + + ;
}
//RPM bins
y = EEPROM_CONFIG9_XBINS2 ;
z = EEPROM_CONFIG9_XBINS3 ;
i = EEPROM_CONFIG9_XBINS4 ;
for ( int x = EEPROM_CONFIG9_XBINS1 ; x < EEPROM_CONFIG9_YBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG9_XBINS1 ;
EEPROM . update ( x , byte ( trim1Table . axisX [ offset ] / 100 ) ) ; //RPM bins are divided by 100 and converted to a byte
offset = y - EEPROM_CONFIG9_XBINS2 ;
EEPROM . update ( y , byte ( trim2Table . axisX [ offset ] / 100 ) ) ; //RPM bins are divided by 100 and converted to a byte
offset = z - EEPROM_CONFIG9_XBINS3 ;
EEPROM . update ( z , byte ( trim3Table . axisX [ offset ] / 100 ) ) ; //RPM bins are divided by 100 and converted to a byte
offset = i - EEPROM_CONFIG9_XBINS4 ;
EEPROM . update ( i , byte ( trim4Table . axisX [ offset ] / 100 ) ) ; //RPM bins are divided by 100 and converted to a byte
y + + ;
z + + ;
i + + ;
}
//TPS/MAP bins
y = EEPROM_CONFIG9_YBINS2 ;
z = EEPROM_CONFIG9_YBINS3 ;
i = EEPROM_CONFIG9_YBINS4 ;
for ( int x = EEPROM_CONFIG9_YBINS1 ; x < EEPROM_CONFIG9_XSIZE2 ; x + + )
{
offset = x - EEPROM_CONFIG9_YBINS1 ;
EEPROM . update ( x , trim1Table . axisY [ offset ] ) ;
offset = y - EEPROM_CONFIG9_YBINS2 ;
EEPROM . update ( y , trim2Table . axisY [ offset ] ) ;
offset = z - EEPROM_CONFIG9_YBINS3 ;
EEPROM . update ( z , trim3Table . axisY [ offset ] ) ;
offset = i - EEPROM_CONFIG9_YBINS4 ;
EEPROM . update ( i , trim4Table . axisY [ offset ] ) ;
y + + ;
z + + ;
i + + ;
}
2013-07-18 04:53:40 -07:00
}
2013-07-16 05:31:01 -07:00
void loadConfig ( )
{
2013-09-11 05:34:40 -07:00
int offset ;
//Create a pointer to the config page
2013-07-19 04:02:19 -07:00
byte * pnt_configPage ;
2015-06-05 00:28:31 -07:00
2013-09-11 05:34:40 -07:00
//Fuel table (See storage.h for data layout)
//fuelTable.xSize = EEPROM.read(EEPROM_CONFIG1_XSIZE); //Read the VE Tables RPM dimension size
//fuelTable.ySize = EEPROM.read(EEPROM_CONFIG1_YSIZE); //Read the VE Tables MAP/TPS dimension size
for ( int x = EEPROM_CONFIG1_MAP ; x < EEPROM_CONFIG1_XBINS ; x + + )
{
offset = x - EEPROM_CONFIG1_MAP ;
2015-06-05 00:28:31 -07:00
fuelTable . values [ 15 - offset / 16 ] [ offset % 16 ] = EEPROM . read ( x ) ; //Read the 8x8 map
2013-09-11 05:34:40 -07:00
}
//RPM bins
for ( int x = EEPROM_CONFIG1_XBINS ; x < EEPROM_CONFIG1_YBINS ; x + + )
{
offset = x - EEPROM_CONFIG1_XBINS ;
fuelTable . axisX [ offset ] = ( EEPROM . read ( x ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
}
//TPS/MAP bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG1_YBINS ; x < EEPROM_CONFIG2_START ; x + + )
2013-09-11 05:34:40 -07:00
{
offset = x - EEPROM_CONFIG1_YBINS ;
fuelTable . axisY [ offset ] = EEPROM . read ( x ) ;
}
2015-06-05 00:28:31 -07:00
pnt_configPage = ( byte * ) & configPage1 ; //Create a pointer to Page 1 in memory
for ( int x = EEPROM_CONFIG2_START ; x < EEPROM_CONFIG2_END ; x + + )
2013-07-19 04:02:19 -07:00
{
2015-06-05 00:28:31 -07:00
* ( pnt_configPage + byte ( x - EEPROM_CONFIG2_START ) ) = EEPROM . read ( x ) ;
2013-07-19 04:02:19 -07:00
}
2014-01-09 23:54:33 -08:00
//That concludes the reading of the VE table
2013-07-19 04:02:19 -07:00
2013-09-11 05:34:40 -07:00
//*********************************************************************************************************************************************************************************
//IGNITION CONFIG PAGE (2)
2015-06-05 00:28:31 -07:00
2013-09-11 05:34:40 -07:00
//Begin writing the Ignition table, basically the same thing as above
//ignitionTable.xSize = EEPROM.read(EEPROM_CONFIG2_XSIZE); //Read the ignition Table RPM dimension size (Currently not supproted)
//ignitionTable.ySize = EEPROM.read(EEPROM_CONFIG2_YSIZE); //Read the ignition Table MAP/TPS dimension size (Currently not supproted)
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG3_MAP ; x < EEPROM_CONFIG3_XBINS ; x + + )
2013-09-11 05:34:40 -07:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG3_MAP ;
ignitionTable . values [ 15 - offset / 16 ] [ offset % 16 ] = EEPROM . read ( x ) ; //Read the 8x8 map
2013-09-11 05:34:40 -07:00
}
//RPM bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG3_XBINS ; x < EEPROM_CONFIG3_YBINS ; x + + )
2013-09-11 05:34:40 -07:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG3_XBINS ;
2013-09-11 05:34:40 -07:00
ignitionTable . axisX [ offset ] = ( EEPROM . read ( x ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
}
//TPS/MAP bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG3_YBINS ; x < EEPROM_CONFIG4_START ; x + + )
2013-09-11 05:34:40 -07:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG3_YBINS ;
2013-09-11 05:34:40 -07:00
ignitionTable . axisY [ offset ] = EEPROM . read ( x ) ;
}
2015-06-05 00:28:31 -07:00
pnt_configPage = ( byte * ) & configPage2 ; //Create a pointer to Page 2 in memory
for ( int x = EEPROM_CONFIG4_START ; x < EEPROM_CONFIG4_END ; x + + )
2013-07-19 04:02:19 -07:00
{
2015-06-05 00:28:31 -07:00
* ( pnt_configPage + byte ( x - EEPROM_CONFIG4_START ) ) = EEPROM . read ( x ) ;
2013-07-19 04:02:19 -07:00
}
2015-02-03 02:33:22 -08:00
//*********************************************************************************************************************************************************************************
//AFR TARGET CONFIG PAGE (3)
2015-06-05 00:28:31 -07:00
2015-02-03 02:33:22 -08:00
//Begin writing the Ignition table, basically the same thing as above
//ignitionTable.xSize = EEPROM.read(EEPROM_CONFIG2_XSIZE); //Read the ignition Table RPM dimension size (Currently not supproted)
//ignitionTable.ySize = EEPROM.read(EEPROM_CONFIG2_YSIZE); //Read the ignition Table MAP/TPS dimension size (Currently not supproted)
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG5_MAP ; x < EEPROM_CONFIG5_XBINS ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG5_MAP ;
2015-06-09 06:32:00 -07:00
afrTable . values [ 15 - offset / 16 ] [ offset % 16 ] = EEPROM . read ( x ) ; //Read the 16x16 map
2015-02-03 02:33:22 -08:00
}
//RPM bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG5_XBINS ; x < EEPROM_CONFIG5_YBINS ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG5_XBINS ;
2015-02-03 02:33:22 -08:00
afrTable . axisX [ offset ] = ( EEPROM . read ( x ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
}
//TPS/MAP bins
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG5_YBINS ; x < EEPROM_CONFIG6_START ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG5_YBINS ;
2015-02-03 02:33:22 -08:00
afrTable . axisY [ offset ] = EEPROM . read ( x ) ;
}
2015-06-05 00:28:31 -07:00
pnt_configPage = ( byte * ) & configPage3 ; //Create a pointer to Page 2 in memory
for ( int x = EEPROM_CONFIG6_START ; x < EEPROM_CONFIG6_END ; x + + )
2015-02-03 02:33:22 -08:00
{
2015-06-05 00:28:31 -07:00
* ( pnt_configPage + byte ( x - EEPROM_CONFIG6_START ) ) = EEPROM . read ( x ) ;
2015-02-03 02:33:22 -08:00
}
2015-05-30 12:30:08 -07:00
//*********************************************************************************************************************************************************************************
//CONFIG PAGE (4) //############
pnt_configPage = ( byte * ) & configPage4 ; //Create a pointer to Page 3 in memory
//Begin writing the Ignition table, basically the same thing as above
//ignitionTable.xSize = EEPROM.read(EEPROM_CONFIG2_XSIZE); //Read the ignition Table RPM dimension size (Currently not supproted)
//ignitionTable.ySize = EEPROM.read(EEPROM_CONFIG2_YSIZE); //Read the ignition Table MAP/TPS dimension size (Currently not supproted)
2015-02-03 02:33:22 -08:00
2015-06-09 06:32:00 -07:00
//The next 64 bytes can simply be pulled straight from the configTable
2015-06-05 00:28:31 -07:00
for ( int x = EEPROM_CONFIG7_START ; x < EEPROM_CONFIG7_END ; x + + )
2015-05-30 12:30:08 -07:00
{
2015-06-05 00:28:31 -07:00
* ( pnt_configPage + byte ( x - EEPROM_CONFIG7_START ) ) = EEPROM . read ( x ) ;
2015-09-25 04:02:15 -07:00
}
//*********************************************************************************************************************************************************************************
// Boost and vvt tables load
int y = EEPROM_CONFIG8_MAP2 ;
for ( int x = EEPROM_CONFIG8_MAP1 ; x < EEPROM_CONFIG8_XBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG8_MAP1 ;
boostTable . values [ 7 - offset / 8 ] [ offset % 8 ] = EEPROM . read ( x ) ; //Read the 8x8 map
offset = y - EEPROM_CONFIG8_MAP2 ;
vvtTable . values [ 7 - offset / 8 ] [ offset % 8 ] = EEPROM . read ( y ) ; //Read the 8x8 map
y + + ;
}
2015-09-28 04:57:27 -07:00
2015-09-25 04:02:15 -07:00
//RPM bins
y = EEPROM_CONFIG8_XBINS2 ;
for ( int x = EEPROM_CONFIG8_XBINS1 ; x < EEPROM_CONFIG8_YBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG8_XBINS1 ;
boostTable . axisX [ offset ] = ( EEPROM . read ( x ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
offset = y - EEPROM_CONFIG8_XBINS2 ;
vvtTable . axisX [ offset ] = ( EEPROM . read ( y ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
y + + ;
}
2015-09-28 04:57:27 -07:00
2015-09-25 04:02:15 -07:00
//TPS/MAP bins
y = EEPROM_CONFIG8_YBINS2 ;
2015-09-28 04:57:27 -07:00
for ( int x = EEPROM_CONFIG8_YBINS1 ; x < EEPROM_CONFIG8_XSIZE2 ; x + + )
2015-09-25 04:02:15 -07:00
{
offset = x - EEPROM_CONFIG8_YBINS1 ;
boostTable . axisY [ offset ] = EEPROM . read ( x ) ;
offset = y - EEPROM_CONFIG8_YBINS2 ;
vvtTable . axisY [ offset ] = EEPROM . read ( y ) ;
y + + ;
}
2016-10-24 23:31:44 -07:00
//*********************************************************************************************************************************************************************************
// Fuel trim tables load
y = EEPROM_CONFIG9_MAP2 ;
int z = EEPROM_CONFIG9_MAP3 ;
int i = EEPROM_CONFIG9_MAP4 ;
for ( int x = EEPROM_CONFIG9_MAP1 ; x < EEPROM_CONFIG9_XBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG9_MAP1 ;
trim1Table . values [ 5 - offset / 6 ] [ offset % 6 ] = EEPROM . read ( x ) ; //Read the 6x6 map
offset = y - EEPROM_CONFIG9_MAP2 ;
trim2Table . values [ 5 - offset / 6 ] [ offset % 6 ] = EEPROM . read ( y ) ; //Read the 6x6 map
offset = z - EEPROM_CONFIG9_MAP3 ;
trim3Table . values [ 5 - offset / 6 ] [ offset % 6 ] = EEPROM . read ( z ) ; //Read the 6x6 map
offset = i - EEPROM_CONFIG9_MAP4 ;
trim4Table . values [ 5 - offset / 6 ] [ offset % 6 ] = EEPROM . read ( i ) ; //Read the 6x6 map
y + + ;
z + + ;
i + + ;
}
//RPM bins
y = EEPROM_CONFIG9_XBINS2 ;
z = EEPROM_CONFIG9_XBINS3 ;
i = EEPROM_CONFIG9_XBINS4 ;
for ( int x = EEPROM_CONFIG9_XBINS1 ; x < EEPROM_CONFIG9_YBINS1 ; x + + )
{
offset = x - EEPROM_CONFIG9_XBINS1 ;
trim1Table . axisX [ offset ] = ( EEPROM . read ( x ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
offset = y - EEPROM_CONFIG9_XBINS2 ;
trim2Table . axisX [ offset ] = ( EEPROM . read ( y ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
offset = z - EEPROM_CONFIG9_XBINS3 ;
trim3Table . axisX [ offset ] = ( EEPROM . read ( z ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
offset = i - EEPROM_CONFIG9_XBINS4 ;
trim4Table . axisX [ offset ] = ( EEPROM . read ( i ) * 100 ) ; //RPM bins are divided by 100 when stored. Multiply them back now
y + + ;
z + + ;
i + + ;
}
//TPS/MAP bins
y = EEPROM_CONFIG9_YBINS2 ;
z = EEPROM_CONFIG9_YBINS3 ;
i = EEPROM_CONFIG9_YBINS4 ;
for ( int x = EEPROM_CONFIG9_YBINS1 ; x < EEPROM_CONFIG9_XSIZE2 ; x + + )
{
offset = x - EEPROM_CONFIG9_YBINS1 ;
trim1Table . axisY [ offset ] = EEPROM . read ( x ) ;
offset = y - EEPROM_CONFIG9_YBINS2 ;
trim2Table . axisY [ offset ] = EEPROM . read ( y ) ;
offset = z - EEPROM_CONFIG9_YBINS3 ;
trim3Table . axisY [ offset ] = EEPROM . read ( z ) ;
offset = i - EEPROM_CONFIG9_YBINS4 ;
trim4Table . axisY [ offset ] = EEPROM . read ( i ) ;
y + + ;
z + + ;
i + + ;
}
2013-07-16 05:31:01 -07:00
}
2014-05-12 04:28:24 -07:00
/*
Reads the calibration information from EEPROM .
This is separate from the config load as the calibrations do not exist as pages within the ini file for Tuner Studio
*/
void loadCalibration ( )
{
2014-12-10 15:21:59 -08:00
for ( int x = 0 ; x < CALIBRATION_TABLE_SIZE ; x + + ) //Each calibration table is 512 bytes long
2014-05-12 04:28:24 -07:00
{
2014-12-10 15:21:59 -08:00
int y = EEPROM_CALIBRATION_CLT + x ;
cltCalibrationTable [ x ] = EEPROM . read ( y ) ;
2014-05-12 04:28:24 -07:00
2014-12-10 15:21:59 -08:00
y = EEPROM_CALIBRATION_IAT + x ;
iatCalibrationTable [ x ] = EEPROM . read ( y ) ;
2014-05-12 04:28:24 -07:00
2014-12-10 15:21:59 -08:00
y = EEPROM_CALIBRATION_O2 + x ;
o2CalibrationTable [ x ] = EEPROM . read ( y ) ;
2014-05-12 04:28:24 -07:00
}
}
2014-05-13 00:13:12 -07:00
2014-12-10 15:21:59 -08:00
/*
This takes the values in the 3 calibration tables ( Coolant , Inlet temp and O2 )
and saves them to the EEPROM .
*/
2014-05-13 00:13:12 -07:00
void writeCalibration ( )
{
2014-12-10 15:21:59 -08:00
for ( int x = 0 ; x < CALIBRATION_TABLE_SIZE ; x + + ) //Each calibration table is 512 bytes long
2014-05-13 00:13:12 -07:00
{
2014-12-10 15:21:59 -08:00
int y = EEPROM_CALIBRATION_CLT + x ;
2015-01-09 14:56:14 -08:00
if ( EEPROM . read ( y ) ! = cltCalibrationTable [ x ] ) { EEPROM . write ( y , cltCalibrationTable [ x ] ) ; }
2014-05-13 00:13:12 -07:00
2014-12-10 15:21:59 -08:00
y = EEPROM_CALIBRATION_IAT + x ;
2015-01-09 14:56:14 -08:00
if ( EEPROM . read ( y ) ! = iatCalibrationTable [ x ] ) { EEPROM . write ( y , iatCalibrationTable [ x ] ) ; }
2014-05-13 00:13:12 -07:00
2014-12-10 15:21:59 -08:00
y = EEPROM_CALIBRATION_O2 + x ;
2015-01-09 14:56:14 -08:00
if ( EEPROM . read ( y ) ! = o2CalibrationTable [ x ] ) { EEPROM . write ( y , o2CalibrationTable [ x ] ) ; }
2014-05-13 00:13:12 -07:00
}
}