Completed (untested) read/write EEPROM and comms paging

This commit is contained in:
Josh Stewart 2013-07-19 21:02:19 +10:00
parent 78e47fbbef
commit d26171614d
3 changed files with 43 additions and 10 deletions

View File

@ -115,14 +115,25 @@ void receiveValue(byte offset, byte newValue)
switch (currentPage) switch (currentPage)
{ {
case vePage: 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 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 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 else //New value is one of the remaining config items
{ {
@ -134,10 +145,22 @@ void receiveValue(byte offset, byte newValue)
pnt_configPage = (byte *)&configPage2; pnt_configPage = (byte *)&configPage2;
if (offset < 64) //New value is part of the ignition map 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 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 else //New value is one of the remaining config items

View File

@ -1,10 +1,8 @@
#include <EEPROM.h> #include <EEPROM.h>
void writeConfig(); void writeConfig();
void writeTables();
void loadConfig(); void loadConfig();
void loadTables();
/* /*
Current layout of EEPROM data (Version 1) is as follows (All sizes are in bytes): Current layout of EEPROM data (Version 1) is as follows (All sizes are in bytes):

View File

@ -32,11 +32,23 @@ void writeConfig()
} }
} }
void writeTables();
void loadConfig() 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<EEPROM_CONFIG2_XSIZE; x++)
{
*(pnt_configPage + x) = EEPROM.read(x);
}
//That concludes the writing of the VE table
//The next 125 bytes can simply be pulled straight from the ignitionTable
pnt_configPage = (byte *)&configPage2; //Create a pointer to Page 2 in memory
for(int x=EEPROM_CONFIG2_MAP; x<EEPROM_SIZE; x++)
{
*(pnt_configPage + x) = EEPROM.read(x);
}
} }
void loadTables();