From e62231fb06258c83ce823d8688959414915beb3f Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 3 Feb 2015 21:33:22 +1100 Subject: [PATCH] All the code infrastructure for the AFR target table --- comms.h | 1 + comms.ino | 52 +++++++++++++++++++++++++++++++++++++++++ globals.h | 60 ++++++++++++++++++++++++++++++++++++++--------- speeduino.ino | 2 ++ storage.h | 24 +++++++++++++------ storage.ino | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 184 insertions(+), 20 deletions(-) diff --git a/comms.h b/comms.h index ac38d2c6..b685f1c8 100644 --- a/comms.h +++ b/comms.h @@ -1,5 +1,6 @@ #define vePage 1 #define ignPage 2 +#define afrPage 3 byte currentPage; diff --git a/comms.ino b/comms.ino index 09393c24..a2593442 100644 --- a/comms.ino +++ b/comms.ino @@ -237,6 +237,41 @@ void receiveValue(byte offset, byte newValue) return; } break; + case afrPage: //Air/Fuel ratio target settings page (Page 3) + pnt_configPage = (byte *)&configPage3; + if (offset < 64) //New value is part of the afr map + { + afrTable.values[7-offset/8][offset%8] = newValue; + return; + } + 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 + afrTable.axisX[(offset-64)] = int(newValue) * int(100); //The RPM values sent by megasquirt are divided by 100, need to multiply it back by 100 to make it correct + } + else + { + + //Y Axis + offset = 7-(offset-72); //Need to do a translation to flip the order + afrTable.axisY[offset] = int(newValue); + + } + return; + } + else //New value is one of the remaining config items + { + //For some reason, TunerStudio is sending offsets greater than the maximum page size. I'm not sure if it's their bug or mine, but the fix is to only update the config page if the offset is less than the maximum size + if( offset < page_size) + { + *(pnt_configPage + byte(offset - 80)) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages + } + return; + } + break; default: break; @@ -292,6 +327,23 @@ void sendPage() Serial.flush(); break; + case afrPage: + //Need to perform a translation of the values[MAP/TPS][RPM] into the MS expected format + for(byte x=0;x<64;x++) { response[x] = afrTable.values[7-x/8][x%8]; } + for(byte x=64;x<72;x++) { response[x] = byte(afrTable.axisX[(x-64)] / 100); } + for(byte y=72;y<80;y++) { response[y] = byte(afrTable.axisY[7-(y-72)]); } + + //All other bytes can simply be copied from the config table + pnt_configPage = (byte *)&configPage3; //Create a pointer to Page 2 in memory + offset = 80; //Offset is based on the amount already copied above (table + bins) + for(byte x=offset; x