From f27f883a5c9f7dcfd33c5eab84fb527108cedfc7 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 16 May 2017 15:05:39 +1000 Subject: [PATCH] Add updater mechanism for translating data between firmware versions --- speeduino/speeduino.ino | 3 ++- speeduino/storage.h | 8 +++++--- speeduino/storage.ino | 3 --- speeduino/updates.ino | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 speeduino/updates.ino diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index cd59b9b6..e87454fc 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -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 @@ -1090,7 +1091,7 @@ void loop() currentStatus.PW1 = PW_AN(req_fuel_uS, currentStatus.VE, currentStatus.TPS, currentStatus.corrections, inj_opentime_uS); //Calculate pulsewidth using the Alpha-N algorithm (in uS) currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.TPS, currentStatus.RPM) - OFFSET_IGNITION; //As above, but for ignition advance } - + currentStatus.advance = correctionsIgn(currentStatus.advance); /* //Check for fixed ignition angles diff --git a/speeduino/storage.h b/speeduino/storage.h index da8d0d2e..b848a148 100644 --- a/speeduino/storage.h +++ b/speeduino/storage.h @@ -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 @@ -78,13 +80,13 @@ Current layout of EEPROM data (Version 3) is as follows (All sizes are in bytes) #define EEPROM_CONFIG6_START 999 #define EEPROM_CONFIG6_END 1063 #define EEPROM_CONFIG7_START 1063 -#define EEPROM_CONFIG7_END 1127 -#define EEPROM_CONFIG8_XSIZE1 1127 +#define EEPROM_CONFIG7_END 1127 +#define EEPROM_CONFIG8_XSIZE1 1127 #define EEPROM_CONFIG8_YSIZE1 1128 #define EEPROM_CONFIG8_MAP1 1129 #define EEPROM_CONFIG8_XBINS1 1193 #define EEPROM_CONFIG8_YBINS1 1201 -#define EEPROM_CONFIG8_XSIZE2 1209 +#define EEPROM_CONFIG8_XSIZE2 1209 #define EEPROM_CONFIG8_YSIZE2 1210 #define EEPROM_CONFIG8_MAP2 1211 #define EEPROM_CONFIG8_XBINS2 1275 diff --git a/speeduino/storage.ino b/speeduino/storage.ino index ac95ecf8..f7fa9421 100644 --- a/speeduino/storage.ino +++ b/speeduino/storage.ino @@ -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 diff --git a/speeduino/updates.ino b/speeduino/updates.ino new file mode 100644 index 00000000..cbcff403 --- /dev/null +++ b/speeduino/updates.ino @@ -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); + } +}