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
*/
2015-02-14 09:04:00 -08:00
# include "storage.h"
# include "globals.h"
2017-01-17 22:37:55 -08:00
# include "table.h"
2017-09-18 21:05:43 -07:00
# include "comms.h"
2017-01-18 16:31:05 -08:00
# include <EEPROM.h>
2015-02-14 09:04:00 -08:00
2017-09-18 21:05:43 -07:00
void writeAllConfig ( )
{
writeConfig ( 1 ) ;
2017-09-19 21:06:55 -07:00
if ( eepromWritesPending = = false ) { writeConfig ( 2 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 3 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 4 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 5 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 6 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 7 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 8 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 9 ) ; }
if ( eepromWritesPending = = false ) { writeConfig ( 10 ) ; }
2017-09-18 21:05:43 -07: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
*/
2017-09-18 21:05:43 -07:00
void writeConfig ( byte tableNum )
2013-07-18 04:53:40 -07:00
{
/*
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 )
*/
2017-02-08 19:24:07 -08:00
2013-08-25 21:11:47 -07:00
int offset ;
2017-09-19 21:06:55 -07:00
int i , z , y ;
2017-09-18 21:05:43 -07:00
int writeCounter = 0 ;
2017-09-19 21:06:55 -07:00
byte newVal ; //Used for tempoerarily storing the new intended value
2013-08-25 21:11:47 -07:00
//Create a pointer to the config page
byte * pnt_configPage ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
switch ( tableNum )
2017-02-08 19:24:07 -08:00
{
2017-09-18 21:05:43 -07:00
case veMapPage :
/*---------------------------------------------------
| Fuel table ( See storage . h for data layout ) - Page 1
| 16 x16 table itself + the 16 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2017-09-19 21:06:55 -07:00
if ( EEPROM . read ( EEPROM_CONFIG1_XSIZE ) ! = fuelTable . xSize ) { EEPROM . write ( EEPROM_CONFIG1_XSIZE , fuelTable . xSize ) ; writeCounter + + ; } //Write the VE Tables RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG1_YSIZE ) ! = fuelTable . ySize ) { EEPROM . write ( EEPROM_CONFIG1_YSIZE , fuelTable . ySize ) ; writeCounter + + ; } //Write the VE Tables MAP/TPS dimension size
2017-09-18 21:05:43 -07:00
for ( int x = EEPROM_CONFIG1_MAP ; x < EEPROM_CONFIG1_XBINS ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG1_MAP ;
if ( EEPROM . read ( x ) ! = ( fuelTable . values [ 15 - ( offset / 16 ) ] [ offset % 16 ] ) ) { EEPROM . write ( x , fuelTable . values [ 15 - ( offset / 16 ) ] [ offset % 16 ] ) ; writeCounter + + ; } //Write the 16x16 map
}
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
//RPM bins
for ( int x = EEPROM_CONFIG1_XBINS ; x < EEPROM_CONFIG1_YBINS ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG1_XBINS ;
if ( EEPROM . read ( x ) ! = ( byte ( fuelTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ) { EEPROM . write ( x , byte ( fuelTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; writeCounter + + ; } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for ( int x = EEPROM_CONFIG1_YBINS ; x < EEPROM_CONFIG2_START ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG1_YBINS ;
EEPROM . update ( x , fuelTable . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ; //Table load is divided by 2 (Allows for MAP up to 511)
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
//That concludes the writing of the VE table
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
case veSetPage :
/*---------------------------------------------------
| Config page 2 ( See storage . h for data layout )
| 64 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage2 ; //Create a pointer to Page 2 in memory
2017-09-18 21:05:43 -07:00
for ( int x = EEPROM_CONFIG2_START ; x < EEPROM_CONFIG2_END ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG2_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG2_START ) ) ) ; writeCounter + + ; }
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2015-06-05 00:28:31 -07:00
2017-09-18 21:05:43 -07:00
case ignMapPage :
/*---------------------------------------------------
| Ignition table ( See storage . h for data layout ) - Page 1
| 16 x16 table itself + the 16 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
//Begin writing the Ignition table, basically the same thing as above
2017-09-19 21:06:55 -07:00
if ( EEPROM . read ( EEPROM_CONFIG3_XSIZE ) ! = ignitionTable . xSize ) { EEPROM . write ( EEPROM_CONFIG3_XSIZE , ignitionTable . xSize ) ; writeCounter + + ; } //Write the ignition Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG3_YSIZE ) ! = ignitionTable . ySize ) { EEPROM . write ( EEPROM_CONFIG3_YSIZE , ignitionTable . ySize ) ; writeCounter + + ; } //Write the ignition Table MAP/TPS dimension size
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
for ( int x = EEPROM_CONFIG3_MAP ; x < EEPROM_CONFIG3_XBINS ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG3_MAP ;
2017-09-19 21:06:55 -07:00
newVal = ignitionTable . values [ 15 - ( offset / 16 ) ] [ offset % 16 ] ;
if ( EEPROM . read ( x ) ! = newVal ) { EEPROM . write ( x , newVal ) ; writeCounter + + ; } //Write the 16x16 map with translation
2017-09-18 21:05:43 -07:00
}
//RPM bins
for ( int x = EEPROM_CONFIG3_XBINS ; x < EEPROM_CONFIG3_YBINS ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG3_XBINS ;
2017-09-19 21:06:55 -07:00
newVal = ignitionTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ;
if ( EEPROM . read ( x ) ! = newVal ) { EEPROM . write ( x , newVal ) ; writeCounter + + ; } //RPM bins are divided by 100 and converted to a byte
2017-09-18 21:05:43 -07:00
}
//TPS/MAP bins
for ( int x = EEPROM_CONFIG3_YBINS ; x < EEPROM_CONFIG4_START ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG3_YBINS ;
2017-09-19 21:06:55 -07:00
newVal = ignitionTable . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ;
if ( EEPROM . read ( x ) ! = newVal ) { EEPROM . write ( x , newVal ) ; writeCounter + + ; } //Table load is divided by 2 (Allows for MAP up to 511)
2017-09-18 21:05:43 -07:00
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
case ignSetPage :
/*---------------------------------------------------
| Config page 2 ( See storage . h for data layout )
| 64 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage4 ; //Create a pointer to Page 2 in memory
2017-09-18 21:05:43 -07:00
for ( int x = EEPROM_CONFIG4_START ; x < EEPROM_CONFIG4_END ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG4_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG4_START ) ) ) ; writeCounter + + ; }
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
case afrMapPage :
/*---------------------------------------------------
| AFR table ( See storage . h for data layout ) - Page 5
| 16 x16 table itself + the 16 values along each of the axis
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
//Begin writing the Ignition table, basically the same thing as above
2017-09-19 21:06:55 -07:00
if ( EEPROM . read ( EEPROM_CONFIG5_XSIZE ) ! = afrTable . xSize ) { EEPROM . write ( EEPROM_CONFIG5_XSIZE , afrTable . xSize ) ; writeCounter + + ; } //Write the ignition Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG5_YSIZE ) ! = afrTable . ySize ) { EEPROM . write ( EEPROM_CONFIG5_YSIZE , afrTable . ySize ) ; writeCounter + + ; } //Write the ignition Table MAP/TPS dimension size
2015-06-05 00:28:31 -07:00
2017-09-18 21:05:43 -07:00
for ( int x = EEPROM_CONFIG5_MAP ; x < EEPROM_CONFIG5_XBINS ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -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 ] ) ; writeCounter + + ; } //Write the 16x16 map
}
//RPM bins
for ( int x = EEPROM_CONFIG5_XBINS ; x < EEPROM_CONFIG5_YBINS ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG5_XBINS ;
if ( EEPROM . read ( x ) ! = byte ( afrTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) { EEPROM . write ( x , byte ( afrTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; writeCounter + + ; } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for ( int x = EEPROM_CONFIG5_YBINS ; x < EEPROM_CONFIG6_START ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
offset = x - EEPROM_CONFIG5_YBINS ;
EEPROM . update ( x , afrTable . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ; //Table load is divided by 2 (Allows for MAP up to 511)
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
case afrSetPage :
/*---------------------------------------------------
| Config page 3 ( See storage . h for data layout )
| 64 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage6 ; //Create a pointer to Page 3 in memory
2017-09-18 21:05:43 -07:00
for ( int x = EEPROM_CONFIG6_START ; x < EEPROM_CONFIG6_END ; x + + )
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2017-09-18 21:05:43 -07:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG6_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG6_START ) ) ) ; writeCounter + + ; }
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
case boostvvtPage :
/*---------------------------------------------------
| 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)
2018-01-23 17:05:50 -08:00
if ( EEPROM . read ( EEPROM_CONFIG7_XSIZE1 ) ! = boostTable . xSize ) { EEPROM . write ( EEPROM_CONFIG7_XSIZE1 , boostTable . xSize ) ; writeCounter + + ; } //Write the boost Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG7_YSIZE1 ) ! = boostTable . ySize ) { EEPROM . write ( EEPROM_CONFIG7_YSIZE1 , boostTable . ySize ) ; writeCounter + + ; } //Write the boost Table MAP/TPS dimension size
if ( EEPROM . read ( EEPROM_CONFIG7_XSIZE2 ) ! = vvtTable . xSize ) { EEPROM . write ( EEPROM_CONFIG7_XSIZE2 , vvtTable . xSize ) ; writeCounter + + ; } //Write the vvt Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG7_YSIZE2 ) ! = vvtTable . ySize ) { EEPROM . write ( EEPROM_CONFIG7_YSIZE2 , vvtTable . ySize ) ; writeCounter + + ; } //Write the vvt Table MAP/TPS dimension size
if ( EEPROM . read ( EEPROM_CONFIG7_XSIZE3 ) ! = stagingTable . xSize ) { EEPROM . write ( EEPROM_CONFIG7_XSIZE3 , stagingTable . xSize ) ; writeCounter + + ; } //Write the staging Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG7_YSIZE3 ) ! = stagingTable . ySize ) { EEPROM . write ( EEPROM_CONFIG7_YSIZE3 , stagingTable . ySize ) ; writeCounter + + ; } //Write the staging Table MAP/TPS dimension size
y = EEPROM_CONFIG7_MAP2 ; //We do the 3 maps together in the same loop
z = EEPROM_CONFIG7_MAP3 ;
for ( int x = EEPROM_CONFIG7_MAP1 ; x < EEPROM_CONFIG7_XBINS1 ; x + + )
2017-09-18 21:05:43 -07:00
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG7_MAP1 ;
2017-09-18 21:05:43 -07:00
if ( EEPROM . read ( x ) ! = ( boostTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] ) ) { EEPROM . write ( x , boostTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] ) ; writeCounter + + ; } //Write the 8x8 map
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG7_MAP2 ;
2017-09-18 21:05:43 -07:00
if ( EEPROM . read ( y ) ! = ( vvtTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] ) ) { EEPROM . write ( y , vvtTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] ) ; writeCounter + + ; } //Write the 8x8 map
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG7_MAP3 ;
2017-11-20 20:17:55 -08:00
if ( EEPROM . read ( z ) ! = ( stagingTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] ) ) { EEPROM . write ( z , stagingTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] ) ; writeCounter + + ; } //Write the 8x8 map
2017-09-18 21:05:43 -07:00
y + + ;
2017-11-20 20:17:55 -08:00
z + + ;
2017-09-18 21:05:43 -07:00
}
//RPM bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG7_XBINS2 ;
z = EEPROM_CONFIG7_XBINS3 ;
for ( int x = EEPROM_CONFIG7_XBINS1 ; x < EEPROM_CONFIG7_YBINS1 ; x + + )
2017-09-18 21:05:43 -07:00
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG7_XBINS1 ;
2017-09-18 21:05:43 -07:00
if ( EEPROM . read ( x ) ! = byte ( boostTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) { EEPROM . write ( x , byte ( boostTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; writeCounter + + ; } //RPM bins are divided by 100 and converted to a byte
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG7_XBINS2 ;
2017-09-18 21:05:43 -07:00
if ( EEPROM . read ( y ) ! = byte ( vvtTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) { EEPROM . write ( y , byte ( vvtTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; writeCounter + + ; } //RPM bins are divided by 100 and converted to a byte
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG7_XBINS3 ;
2017-11-20 20:17:55 -08:00
if ( EEPROM . read ( z ) ! = byte ( stagingTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) { EEPROM . write ( z , byte ( stagingTable . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; writeCounter + + ; } //RPM bins are divided by 100 and converted to a byte
2017-09-18 21:05:43 -07:00
y + + ;
2017-11-20 20:17:55 -08:00
z + + ;
2017-09-18 21:05:43 -07:00
}
//TPS/MAP bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG7_YBINS2 ;
z = EEPROM_CONFIG7_YBINS3 ;
for ( int x = EEPROM_CONFIG7_YBINS1 ; x < EEPROM_CONFIG7_XSIZE2 ; x + + )
2017-09-18 21:05:43 -07:00
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG7_YBINS1 ;
2017-09-19 21:06:55 -07:00
if ( EEPROM . read ( x ) ! = boostTable . axisY [ offset ] ) { EEPROM . write ( x , boostTable . axisY [ offset ] ) ; writeCounter + + ; } //TABLE_LOAD_MULTIPLIER is NOT used for boost as it is TPS based (0-100)
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG7_YBINS2 ;
2017-09-19 21:06:55 -07:00
if ( EEPROM . read ( y ) ! = vvtTable . axisY [ offset ] ) { EEPROM . write ( y , vvtTable . axisY [ offset ] ) ; writeCounter + + ; } //TABLE_LOAD_MULTIPLIER is NOT used for VVT as it is TPS based (0-100)
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG7_YBINS3 ;
2017-11-20 20:17:55 -08:00
if ( EEPROM . read ( z ) ! = byte ( stagingTable . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ) { EEPROM . write ( z , byte ( stagingTable . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ) ; writeCounter + + ; } //RPM bins are divided by 100 and converted to a byte
2017-09-18 21:05:43 -07:00
y + + ;
2017-11-20 20:17:55 -08:00
z + + ;
2017-09-18 21:05:43 -07:00
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
case seqFuelPage :
/*---------------------------------------------------
| 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)
2018-01-23 17:05:50 -08:00
if ( EEPROM . read ( EEPROM_CONFIG8_XSIZE1 ) ! = trim1Table . xSize ) { EEPROM . write ( EEPROM_CONFIG8_XSIZE1 , trim1Table . xSize ) ; writeCounter + + ; } //Write the boost Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_YSIZE1 ) ! = trim1Table . ySize ) { EEPROM . write ( EEPROM_CONFIG8_YSIZE1 , trim1Table . ySize ) ; writeCounter + + ; } //Write the boost Table MAP/TPS dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_XSIZE2 ) ! = trim2Table . xSize ) { EEPROM . write ( EEPROM_CONFIG8_XSIZE2 , trim2Table . xSize ) ; writeCounter + + ; } //Write the boost Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_YSIZE2 ) ! = trim2Table . ySize ) { EEPROM . write ( EEPROM_CONFIG8_YSIZE2 , trim2Table . ySize ) ; writeCounter + + ; } //Write the boost Table MAP/TPS dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_XSIZE3 ) ! = trim3Table . xSize ) { EEPROM . write ( EEPROM_CONFIG8_XSIZE3 , trim3Table . xSize ) ; writeCounter + + ; } //Write the boost Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_YSIZE3 ) ! = trim3Table . ySize ) { EEPROM . write ( EEPROM_CONFIG8_YSIZE3 , trim3Table . ySize ) ; writeCounter + + ; } //Write the boost Table MAP/TPS dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_XSIZE4 ) ! = trim4Table . xSize ) { EEPROM . write ( EEPROM_CONFIG8_XSIZE4 , trim4Table . xSize ) ; writeCounter + + ; } //Write the boost Table RPM dimension size
if ( EEPROM . read ( EEPROM_CONFIG8_YSIZE4 ) ! = trim4Table . ySize ) { EEPROM . write ( EEPROM_CONFIG8_YSIZE4 , trim4Table . ySize ) ; writeCounter + + ; } //Write the boost Table MAP/TPS dimension size
y = EEPROM_CONFIG8_MAP2 ; //We do the 4 maps together in the same loop
z = EEPROM_CONFIG8_MAP3 ; //We do the 4 maps together in the same loop
i = EEPROM_CONFIG8_MAP4 ; //We do the 4 maps together in the same loop
for ( int x = EEPROM_CONFIG8_MAP1 ; x < EEPROM_CONFIG8_XBINS1 ; x + + )
2017-09-18 21:05:43 -07:00
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG8_MAP1 ;
2017-09-19 21:06:55 -07:00
newVal = trim1Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] ;
if ( EEPROM . read ( x ) ! = newVal ) { EEPROM . update ( x , newVal ) ; writeCounter + + ; } //Write the 6x6 map
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG8_MAP2 ;
2017-09-19 21:06:55 -07:00
newVal = trim2Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] ;
if ( EEPROM . read ( y ) ! = newVal ) { EEPROM . update ( y , newVal ) ; writeCounter + + ; } //Write the 6x6 map
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG8_MAP3 ;
2017-09-19 21:06:55 -07:00
newVal = trim3Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] ;
if ( EEPROM . read ( z ) ! = newVal ) { EEPROM . update ( z , newVal ) ; writeCounter + + ; } //Write the 6x6 map
2018-01-23 17:05:50 -08:00
offset = i - EEPROM_CONFIG8_MAP4 ;
2017-09-19 21:06:55 -07:00
newVal = trim4Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] ;
if ( EEPROM . read ( i ) ! = newVal ) { EEPROM . update ( i , newVal ) ; writeCounter + + ; } //Write the 6x6 map
2017-09-18 21:05:43 -07:00
y + + ;
z + + ;
i + + ;
}
//RPM bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG8_XBINS2 ;
z = EEPROM_CONFIG8_XBINS3 ;
i = EEPROM_CONFIG8_XBINS4 ;
for ( int x = EEPROM_CONFIG8_XBINS1 ; x < EEPROM_CONFIG8_YBINS1 ; x + + )
2017-09-18 21:05:43 -07:00
{
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { eepromWritesPending = true ; break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG8_XBINS1 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( x , byte ( trim1Table . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; //RPM bins are divided by 100 and converted to a byte
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG8_XBINS2 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( y , byte ( trim2Table . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; //RPM bins are divided by 100 and converted to a byte
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG8_XBINS3 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( z , byte ( trim3Table . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; //RPM bins are divided by 100 and converted to a byte
2018-01-23 17:05:50 -08:00
offset = i - EEPROM_CONFIG8_XBINS4 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( i , byte ( trim4Table . axisX [ offset ] / TABLE_RPM_MULTIPLIER ) ) ; //RPM bins are divided by 100 and converted to a byte
y + + ;
z + + ;
i + + ;
}
//TPS/MAP bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG8_YBINS2 ;
z = EEPROM_CONFIG8_YBINS3 ;
i = EEPROM_CONFIG8_YBINS4 ;
for ( int x = EEPROM_CONFIG8_YBINS1 ; x < EEPROM_CONFIG8_XSIZE2 ; x + + )
2017-09-18 21:05:43 -07:00
{
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { eepromWritesPending = true ; break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG8_YBINS1 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( x , trim1Table . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ; //Table load is divided by 2 (Allows for MAP up to 511)
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG8_YBINS2 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( y , trim2Table . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ; //Table load is divided by 2 (Allows for MAP up to 511)
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG8_YBINS3 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( z , trim3Table . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ; //Table load is divided by 2 (Allows for MAP up to 511)
2018-01-23 17:05:50 -08:00
offset = i - EEPROM_CONFIG8_YBINS4 ;
2017-09-18 21:05:43 -07:00
EEPROM . update ( i , trim4Table . axisY [ offset ] / TABLE_LOAD_MULTIPLIER ) ; //Table load is divided by 2 (Allows for MAP up to 511)
y + + ;
z + + ;
i + + ;
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2016-10-24 23:31:44 -07:00
2017-09-18 21:05:43 -07:00
case canbusPage :
/*---------------------------------------------------
| Config page 10 ( See storage . h for data layout )
2018-07-03 16:36:37 -07:00
| 192 byte long config table
2017-09-18 21:05:43 -07:00
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage9 ; //Create a pointer to Page 10 in memory
for ( int x = EEPROM_CONFIG9_START ; x < EEPROM_CONFIG9_END ; x + + )
2017-09-18 21:05:43 -07:00
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG9_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG9_START ) ) ) ; writeCounter + + ; }
2017-09-18 21:05:43 -07:00
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
case warmupPage :
/*---------------------------------------------------
| Config page 11 ( See storage . h for data layout )
| 192 byte long config table
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage10 ; //Create a pointer to Page 11 in memory
2017-09-18 21:05:43 -07:00
//As there are no 3d tables in this page, all 192 bytes can simply be read in
2018-01-23 17:05:50 -08:00
for ( int x = EEPROM_CONFIG10_START ; x < EEPROM_CONFIG10_END ; x + + )
2017-09-18 21:05:43 -07:00
{
2017-09-19 21:06:55 -07:00
if ( ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) ) { break ; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
2018-01-23 17:05:50 -08:00
if ( EEPROM . read ( x ) ! = * ( pnt_configPage + byte ( x - EEPROM_CONFIG10_START ) ) ) { EEPROM . write ( x , * ( pnt_configPage + byte ( x - EEPROM_CONFIG10_START ) ) ) ; writeCounter + + ; }
2017-09-18 21:05:43 -07:00
}
2017-09-19 21:06:55 -07:00
if ( writeCounter > EEPROM_MAX_WRITE_BLOCK ) { eepromWritesPending = true ; }
else { eepromWritesPending = false ; }
2017-09-18 21:05:43 -07:00
break ;
2017-02-08 19:24:07 -08:00
2017-09-18 21:05:43 -07:00
default :
break ;
2017-08-02 18:51:07 -07:00
}
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 ;
2017-02-08 19:24:07 -08:00
2013-09-11 05:34:40 -07:00
//Fuel table (See storage.h for data layout)
2017-02-08 19:24:07 -08:00
for ( int x = EEPROM_CONFIG1_MAP ; x < EEPROM_CONFIG1_XBINS ; x + + )
{
2013-09-11 05:34:40 -07:00
offset = x - EEPROM_CONFIG1_MAP ;
2017-08-02 18:46:48 -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
2017-02-08 19:24:07 -08:00
for ( int x = EEPROM_CONFIG1_XBINS ; x < EEPROM_CONFIG1_YBINS ; x + + )
2013-09-11 05:34:40 -07:00
{
offset = x - EEPROM_CONFIG1_XBINS ;
2017-01-16 03:14:07 -08:00
fuelTable . axisX [ offset ] = ( EEPROM . read ( x ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2013-09-11 05:34:40 -07:00
}
//TPS/MAP bins
2017-02-08 19:24:07 -08: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 ;
2017-01-20 15:38:40 -08:00
fuelTable . axisY [ offset ] = EEPROM . read ( x ) * TABLE_LOAD_MULTIPLIER ;
2013-09-11 05:34:40 -07:00
}
2017-02-08 19:24:07 -08:00
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage2 ; //Create a pointer to Page 1 in memory
2017-02-08 19:24:07 -08:00
for ( int x = EEPROM_CONFIG2_START ; x < EEPROM_CONFIG2_END ; x + + )
{
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
2017-02-08 19:24:07 -08: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
2017-02-08 19:24:07 -08:00
for ( int x = EEPROM_CONFIG3_MAP ; x < EEPROM_CONFIG3_XBINS ; x + + )
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG3_MAP ;
2017-08-02 18:46:48 -07:00
ignitionTable . values [ 15 - ( offset / 16 ) ] [ offset % 16 ] = EEPROM . read ( x ) ; //Read the 8x8 map
2013-09-11 05:34:40 -07:00
}
//RPM bins
2017-02-08 19:24:07 -08: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 ;
2017-01-20 17:58:45 -08:00
ignitionTable . axisX [ offset ] = ( EEPROM . read ( x ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2013-09-11 05:34:40 -07:00
}
//TPS/MAP bins
2017-02-08 19:24:07 -08: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 ;
2017-01-16 03:14:07 -08:00
ignitionTable . axisY [ offset ] = EEPROM . read ( x ) * TABLE_LOAD_MULTIPLIER ; //Table load is divided by 2 (Allows for MAP up to 511)
2013-09-11 05:34:40 -07:00
}
2017-02-08 19:24:07 -08:00
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage4 ; //Create a pointer to Page 4 in memory
2017-02-08 19:24:07 -08:00
for ( int x = EEPROM_CONFIG4_START ; x < EEPROM_CONFIG4_END ; x + + )
{
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
}
2017-02-08 19:24:07 -08:00
2015-02-03 02:33:22 -08:00
//*********************************************************************************************************************************************************************************
//AFR TARGET CONFIG PAGE (3)
2017-02-08 19:24:07 -08:00
2015-02-03 02:33:22 -08:00
//Begin writing the Ignition table, basically the same thing as above
2017-02-08 19:24:07 -08:00
for ( int x = EEPROM_CONFIG5_MAP ; x < EEPROM_CONFIG5_XBINS ; x + + )
{
2015-06-05 00:28:31 -07:00
offset = x - EEPROM_CONFIG5_MAP ;
2017-08-02 18:46:48 -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
2017-02-08 19:24:07 -08: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 ;
2017-01-16 03:14:07 -08:00
afrTable . axisX [ offset ] = ( EEPROM . read ( x ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2015-02-03 02:33:22 -08:00
}
//TPS/MAP bins
2017-02-08 19:24:07 -08: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 ;
2017-01-16 03:14:07 -08:00
afrTable . axisY [ offset ] = EEPROM . read ( x ) * TABLE_LOAD_MULTIPLIER ; //Table load is divided by 2 (Allows for MAP up to 511)
2015-02-03 02:33:22 -08:00
}
2017-02-08 19:24:07 -08:00
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage6 ; //Create a pointer to Page 6 in memory
2017-02-08 19:24:07 -08:00
for ( int x = EEPROM_CONFIG6_START ; x < EEPROM_CONFIG6_END ; x + + )
{
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
}
2017-02-08 19:24:07 -08:00
2015-05-30 12:30:08 -07:00
//*********************************************************************************************************************************************************************************
2015-09-25 04:02:15 -07:00
// Boost and vvt tables load
2018-01-23 17:05:50 -08:00
int y = EEPROM_CONFIG7_MAP2 ;
int z = EEPROM_CONFIG7_MAP3 ;
for ( int x = EEPROM_CONFIG7_MAP1 ; x < EEPROM_CONFIG7_XBINS1 ; x + + )
2017-02-08 19:24:07 -08:00
{
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG7_MAP1 ;
2017-08-02 18:46:48 -07:00
boostTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] = EEPROM . read ( x ) ; //Read the 8x8 map
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG7_MAP2 ;
2017-08-02 18:46:48 -07:00
vvtTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] = EEPROM . read ( y ) ; //Read the 8x8 map
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG7_MAP3 ;
2017-11-20 20:17:55 -08:00
stagingTable . values [ 7 - ( offset / 8 ) ] [ offset % 8 ] = EEPROM . read ( z ) ; //Read the 8x8 map
2015-09-25 04:02:15 -07:00
y + + ;
2017-11-20 20:17:55 -08:00
z + + ;
2015-09-25 04:02:15 -07:00
}
2015-09-28 04:57:27 -07:00
2015-09-25 04:02:15 -07:00
//RPM bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG7_XBINS2 ;
z = EEPROM_CONFIG7_XBINS3 ;
for ( int x = EEPROM_CONFIG7_XBINS1 ; x < EEPROM_CONFIG7_YBINS1 ; x + + )
2015-09-25 04:02:15 -07:00
{
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG7_XBINS1 ;
2017-01-16 03:14:07 -08:00
boostTable . axisX [ offset ] = ( EEPROM . read ( x ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG7_XBINS2 ;
2017-01-16 03:14:07 -08:00
vvtTable . axisX [ offset ] = ( EEPROM . read ( y ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG7_XBINS3 ;
2017-11-20 20:17:55 -08:00
stagingTable . axisX [ offset ] = ( EEPROM . read ( z ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2015-09-25 04:02:15 -07:00
y + + ;
2017-11-20 20:17:55 -08:00
z + + ;
2015-09-25 04:02:15 -07:00
}
2017-02-08 19:24:07 -08:00
2015-09-25 04:02:15 -07:00
//TPS/MAP bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG7_YBINS2 ;
z = EEPROM_CONFIG7_YBINS3 ;
for ( int x = EEPROM_CONFIG7_YBINS1 ; x < EEPROM_CONFIG7_XSIZE2 ; x + + )
2015-09-25 04:02:15 -07:00
{
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG7_YBINS1 ;
2017-02-08 19:24:07 -08:00
boostTable . axisY [ offset ] = EEPROM . read ( x ) ; //TABLE_LOAD_MULTIPLIER is NOT used for boost as it is TPS based (0-100)
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG7_YBINS2 ;
2017-02-08 19:24:07 -08:00
vvtTable . axisY [ offset ] = EEPROM . read ( y ) ; //TABLE_LOAD_MULTIPLIER is NOT used for VVT as it is TPS based (0-100)
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG7_YBINS3 ;
2017-11-20 20:17:55 -08:00
stagingTable . axisY [ offset ] = EEPROM . read ( z ) * TABLE_LOAD_MULTIPLIER ;
2015-09-25 04:02:15 -07:00
y + + ;
2017-11-20 20:17:55 -08:00
z + + ;
2015-09-25 04:02:15 -07:00
}
2016-10-24 23:31:44 -07:00
//*********************************************************************************************************************************************************************************
// Fuel trim tables load
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG8_MAP2 ;
z = EEPROM_CONFIG8_MAP3 ;
int i = EEPROM_CONFIG8_MAP4 ;
for ( int x = EEPROM_CONFIG8_MAP1 ; x < EEPROM_CONFIG8_XBINS1 ; x + + )
2017-02-08 19:24:07 -08:00
{
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG8_MAP1 ;
2017-08-02 18:46:48 -07:00
trim1Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] = EEPROM . read ( x ) ; //Read the 6x6 map
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG8_MAP2 ;
2017-08-02 18:46:48 -07:00
trim2Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] = EEPROM . read ( y ) ; //Read the 6x6 map
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG8_MAP3 ;
2017-08-02 18:46:48 -07:00
trim3Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] = EEPROM . read ( z ) ; //Read the 6x6 map
2018-01-23 17:05:50 -08:00
offset = i - EEPROM_CONFIG8_MAP4 ;
2017-08-02 18:46:48 -07:00
trim4Table . values [ 5 - ( offset / 6 ) ] [ offset % 6 ] = EEPROM . read ( i ) ; //Read the 6x6 map
2016-10-24 23:31:44 -07:00
y + + ;
z + + ;
i + + ;
}
//RPM bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG8_XBINS2 ;
z = EEPROM_CONFIG8_XBINS3 ;
i = EEPROM_CONFIG8_XBINS4 ;
for ( int x = EEPROM_CONFIG8_XBINS1 ; x < EEPROM_CONFIG8_YBINS1 ; x + + )
2016-10-24 23:31:44 -07:00
{
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG8_XBINS1 ;
2017-01-16 03:14:07 -08:00
trim1Table . axisX [ offset ] = ( EEPROM . read ( x ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG8_XBINS2 ;
2017-01-16 03:14:07 -08:00
trim2Table . axisX [ offset ] = ( EEPROM . read ( y ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG8_XBINS3 ;
2017-01-16 03:14:07 -08:00
trim3Table . axisX [ offset ] = ( EEPROM . read ( z ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2018-01-23 17:05:50 -08:00
offset = i - EEPROM_CONFIG8_XBINS4 ;
2017-01-16 03:14:07 -08:00
trim4Table . axisX [ offset ] = ( EEPROM . read ( i ) * TABLE_RPM_MULTIPLIER ) ; //RPM bins are divided by 100 when stored. Multiply them back now
2016-10-24 23:31:44 -07:00
y + + ;
z + + ;
i + + ;
}
2017-02-08 19:24:07 -08:00
2016-10-24 23:31:44 -07:00
//TPS/MAP bins
2018-01-23 17:05:50 -08:00
y = EEPROM_CONFIG8_YBINS2 ;
z = EEPROM_CONFIG8_YBINS3 ;
i = EEPROM_CONFIG8_YBINS4 ;
for ( int x = EEPROM_CONFIG8_YBINS1 ; x < EEPROM_CONFIG8_XSIZE2 ; x + + )
2016-10-24 23:31:44 -07:00
{
2018-01-23 17:05:50 -08:00
offset = x - EEPROM_CONFIG8_YBINS1 ;
2017-01-16 03:14:07 -08:00
trim1Table . axisY [ offset ] = EEPROM . read ( x ) * TABLE_LOAD_MULTIPLIER ; //Table load is divided by 2 (Allows for MAP up to 511)
2018-01-23 17:05:50 -08:00
offset = y - EEPROM_CONFIG8_YBINS2 ;
2017-01-16 03:14:07 -08:00
trim2Table . axisY [ offset ] = EEPROM . read ( y ) * TABLE_LOAD_MULTIPLIER ; //Table load is divided by 2 (Allows for MAP up to 511)
2018-01-23 17:05:50 -08:00
offset = z - EEPROM_CONFIG8_YBINS3 ;
2017-01-16 03:14:07 -08:00
trim3Table . axisY [ offset ] = EEPROM . read ( z ) * TABLE_LOAD_MULTIPLIER ; //Table load is divided by 2 (Allows for MAP up to 511)
2018-01-23 17:05:50 -08:00
offset = i - EEPROM_CONFIG8_YBINS4 ;
2017-01-16 03:14:07 -08:00
trim4Table . axisY [ offset ] = EEPROM . read ( i ) * TABLE_LOAD_MULTIPLIER ; //Table load is divided by 2 (Allows for MAP up to 511)
2016-10-24 23:31:44 -07:00
y + + ;
z + + ;
i + + ;
}
2017-01-26 14:58:21 -08:00
//*********************************************************************************************************************************************************************************
//canbus control page load
2018-01-23 17:05:50 -08:00
pnt_configPage = ( byte * ) & configPage9 ; //Create a pointer to Page 10 in memory
for ( int x = EEPROM_CONFIG9_START ; x < EEPROM_CONFIG9_END ; x + + )
2017-02-08 19:24:07 -08:00
{
2018-01-23 17:05:50 -08:00
* ( pnt_configPage + byte ( x - EEPROM_CONFIG9_START ) ) = EEPROM . read ( x ) ;
2017-01-26 14:58:21 -08:00
}
2017-02-08 19:24:07 -08:00
2017-01-26 14:58:21 -08:00
//*********************************************************************************************************************************************************************************
2017-02-08 19:24:07 -08:00
2018-01-23 17:05:50 -08:00
//CONFIG PAGE (10)
pnt_configPage = ( byte * ) & configPage10 ; //Create a pointer to Page 11 in memory
2017-08-02 18:51:07 -07:00
//All 192 bytes can simply be pulled straight from the configTable
2018-01-23 17:05:50 -08:00
for ( int x = EEPROM_CONFIG10_START ; x < EEPROM_CONFIG10_END ; x + + )
2017-08-02 18:51:07 -07:00
{
2018-01-23 17:05:50 -08:00
* ( pnt_configPage + byte ( x - EEPROM_CONFIG10_START ) ) = EEPROM . read ( x ) ;
2017-08-02 18:51:07 -07:00
}
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 ( )
{
2017-02-08 19:24:07 -08:00
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 ) ;
2017-02-08 19:24:07 -08:00
2014-12-10 15:21:59 -08:00
y = EEPROM_CALIBRATION_IAT + x ;
iatCalibrationTable [ x ] = EEPROM . read ( y ) ;
2017-02-08 19:24:07 -08: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
}
2017-02-08 19:24:07 -08:00
2014-05-12 04:28:24 -07:00
}
2014-05-13 00:13:12 -07:00
2014-12-10 15:21:59 -08:00
/*
2017-02-08 19:24:07 -08:00
This takes the values in the 3 calibration tables ( Coolant , Inlet temp and O2 )
2014-12-10 15:21:59 -08:00
and saves them to the EEPROM .
*/
2014-05-13 00:13:12 -07:00
void writeCalibration ( )
{
2017-02-08 19:24:07 -08:00
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 ] ) ; }
2017-02-08 19:24:07 -08: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 ] ) ; }
2017-02-08 19:24:07 -08: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
}
2017-02-08 19:24:07 -08:00
2014-05-13 00:13:12 -07:00
}