Add updater mechanism for translating data between firmware versions

This commit is contained in:
Josh Stewart 2017-05-16 15:05:39 +10:00
parent 1db7be4a33
commit f27f883a5c
4 changed files with 39 additions and 7 deletions

View File

@ -153,6 +153,7 @@ void setup()
table3D_setSize(&trim4Table, 6);
loadConfig();
doUpdates(); //Check if any data items need updating (Occurs ith firmware updates)
Serial.begin(115200);
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3

View File

@ -56,6 +56,8 @@ Current layout of EEPROM data (Version 3) is as follows (All sizes are in bytes)
-----------------------------------------------------
*/
#define EEPROM_DATA_VERSION 0
#define EEPROM_CONFIG1_XSIZE 1
#define EEPROM_CONFIG1_YSIZE 2
#define EEPROM_CONFIG1_MAP 3

View File

@ -24,9 +24,6 @@ void writeConfig()
//Create a pointer to the config page
byte* pnt_configPage;
if(EEPROM.read(0) != data_structure_version) { EEPROM.write(0,data_structure_version); } //Write the data structure version
/*---------------------------------------------------
| Fuel table (See storage.h for data layout) - Page 1
| 16x16 table itself + the 16 values along each of the axis

32
speeduino/updates.ino Normal file
View File

@ -0,0 +1,32 @@
/*
* This routine is used for doing any data conversions that are required during firmware changes
* This prevents users getting difference reports in TS when such a data change occurs.
* It also can be used for setting good values when there are viarables that move locations in the ini
* When a user skips multiple firmware versions at a time, this will roll through the updates 1 at a time
*/
void doUpdates()
{
#define CURRENT_DATA_VERSION 3
//May 2017 firmware introduced a -40 offset on the ignition table. Update that table to +40
if(EEPROM.read(EEPROM_DATA_VERSION) == 2)
{
for(int x=0; x<16; x++)
{
for(int y=0; y<16; y++)
{
ignitionTable.values[x][y] = ignitionTable.values[x][y] + 40;
}
}
writeConfig();
EEPROM.write(EEPROM_DATA_VERSION, 3);
}
//Final check is always for 255 and 0 (Brand new arduino)
if(EEPROM.read(EEPROM_DATA_VERSION) == 0 || EEPROM.read(EEPROM_DATA_VERSION) == 255)
{
EEPROM.write(EEPROM_DATA_VERSION, CURRENT_DATA_VERSION);
}
}