From d26171614d1e16b55270523090c7d68d55d86886 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Fri, 19 Jul 2013 21:02:19 +1000 Subject: [PATCH] Completed (untested) read/write EEPROM and comms paging --- comms.ino | 31 +++++++++++++++++++++++++++---- storage.h | 2 -- storage.ino | 20 ++++++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/comms.ino b/comms.ino index f907dc86..363f9cc0 100644 --- a/comms.ino +++ b/comms.ino @@ -115,14 +115,25 @@ void receiveValue(byte offset, byte newValue) switch (currentPage) { case vePage: - pnt_configPage = (byte *)&configPage1; + pnt_configPage = (byte *)&configPage1; //Setup a pointer to the relevant config page if (offset < 64) //New value is part of the fuel map { - + fuelTable.values[7-offset/8][offset%8] = newValue; } else if (offset < 80) //New value is one of the X or Y axis bins { - + //Check whether this is on the X (RPM) or Y (MAP/TPS) axis + if (offset < 72) + { + //X Axis + *(pnt_configPage + offset) = newValue * 100; //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct + } + else + { + //Y Axis + offset = 7-(offset-72); //Need to do a translation to flip the order (Due to us using (0,0) in the top left rather than bottom right + *(pnt_configPage + offset) = newValue; + } } else //New value is one of the remaining config items { @@ -134,10 +145,22 @@ void receiveValue(byte offset, byte newValue) pnt_configPage = (byte *)&configPage2; if (offset < 64) //New value is part of the ignition map { - + ignitionTable.values[7-offset/8][offset%8] = newValue; } else if (offset < 80) //New value is one of the X or Y axis bins { + //Check whether this is on the X (RPM) or Y (MAP/TPS) axis + if (offset < 72) + { + //X Axis + *(pnt_configPage + offset) = newValue * 100; + } + else + { + //Y Axis + offset = 7-(offset-72); //Need to do a translation to flip the order + *(pnt_configPage + offset) = newValue; + } } else //New value is one of the remaining config items diff --git a/storage.h b/storage.h index a05aa1ae..0de26543 100644 --- a/storage.h +++ b/storage.h @@ -1,10 +1,8 @@ #include void writeConfig(); -void writeTables(); void loadConfig(); -void loadTables(); /* Current layout of EEPROM data (Version 1) is as follows (All sizes are in bytes): diff --git a/storage.ino b/storage.ino index 7f0d22fb..f8778b32 100644 --- a/storage.ino +++ b/storage.ino @@ -32,11 +32,23 @@ void writeConfig() } } -void writeTables(); void loadConfig() { - + byte* pnt_configPage; + //The next 125 bytes can simply be pulled straight from the fuelTable + pnt_configPage = (byte *)&configPage1; //Create a pointer to Page 1 in memory + for(int x=EEPROM_CONFIG1_MAP; x