Merge pull request #1 from noisymime/master

Update 20151013
This commit is contained in:
ConnerMcLaughlin 2015-10-13 13:50:58 -05:00
commit 84c0f542e1
4 changed files with 583 additions and 549 deletions

244
comms.ino
View File

@ -42,9 +42,15 @@ void command()
//This loop should never need to run as the byte should already be in the buffer, but is here just in case //This loop should never need to run as the byte should already be in the buffer, but is here just in case
while (Serial.available() == 0) { } while (Serial.available() == 0) { }
currentPage = Serial.read(); currentPage = Serial.read();
if(currentPage >= '0') {currentPage -= '0';} if (currentPage >= '0') {
if(currentPage == veMapPage || currentPage == ignMapPage || currentPage == afrMapPage) {isMap = true;} currentPage -= '0';
else{isMap = false;} }
if (currentPage == veMapPage || currentPage == ignMapPage || currentPage == afrMapPage) {
isMap = true;
}
else {
isMap = false;
}
break; break;
case 'R': // send 39 bytes of realtime values case 'R': // send 39 bytes of realtime values
@ -68,7 +74,7 @@ void command()
int offset; int offset;
while (Serial.available() == 0) { } while (Serial.available() == 0) { }
if(isMap) if (isMap)
{ {
byte offset1, offset2; byte offset1, offset2;
offset1 = Serial.read(); offset1 = Serial.read();
@ -106,28 +112,28 @@ void command()
digitalWrite(pinInjector2, LOW); digitalWrite(pinInjector2, LOW);
return; return;
Serial.println(F("Coolant")); Serial.println(F("Coolant"));
for(int x=0; x<CALIBRATION_TABLE_SIZE; x++) for (int x = 0; x < CALIBRATION_TABLE_SIZE; x++)
{ {
Serial.print(x); Serial.print(x);
Serial.print(", "); Serial.print(", ");
Serial.println(cltCalibrationTable[x]); Serial.println(cltCalibrationTable[x]);
} }
Serial.println(F("Inlet temp")); Serial.println(F("Inlet temp"));
for(int x=0; x<CALIBRATION_TABLE_SIZE; x++) for (int x = 0; x < CALIBRATION_TABLE_SIZE; x++)
{ {
Serial.print(x); Serial.print(x);
Serial.print(", "); Serial.print(", ");
Serial.println(iatCalibrationTable[x]); Serial.println(iatCalibrationTable[x]);
} }
Serial.println(F("O2")); Serial.println(F("O2"));
for(int x=0; x<CALIBRATION_TABLE_SIZE; x++) for (int x = 0; x < CALIBRATION_TABLE_SIZE; x++)
{ {
Serial.print(x); Serial.print(x);
Serial.print(", "); Serial.print(", ");
Serial.println(o2CalibrationTable[x]); Serial.println(o2CalibrationTable[x]);
} }
Serial.println(F("WUE")); Serial.println(F("WUE"));
for(int x=0; x<10; x++) for (int x = 0; x < 10; x++)
{ {
Serial.print(configPage2.wueBins[x]); Serial.print(configPage2.wueBins[x]);
Serial.print(", "); Serial.print(", ");
@ -194,7 +200,7 @@ void sendValues(int length)
response[0] = currentStatus.secl; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0) response[0] = currentStatus.secl; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
response[1] = currentStatus.squirt; //Squirt Bitfield response[1] = currentStatus.squirt; //Squirt Bitfield
response[2] = currentStatus.engine; //Engine Status Bitfield response[2] = currentStatus.engine; //Engine Status Bitfield
response[3] = 0x00; //baro response[3] = (byte)(divu100(currentStatus.dwell)); //Dwell in ms * 10
response[4] = currentStatus.MAP; //map response[4] = currentStatus.MAP; //map
response[5] = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); //mat response[5] = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); //mat
response[6] = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //Coolant ADC response[6] = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //Coolant ADC
@ -243,7 +249,7 @@ void receiveValue(int offset, byte newValue)
case veMapPage: case veMapPage:
if (offset < 256) //New value is part of the fuel map if (offset < 256) //New value is part of the fuel map
{ {
fuelTable.values[15-offset/16][offset%16] = newValue; fuelTable.values[15 - offset / 16][offset % 16] = newValue;
return; return;
} }
else else
@ -252,12 +258,12 @@ void receiveValue(int offset, byte newValue)
if (offset < 272) if (offset < 272)
{ {
//X Axis //X Axis
fuelTable.axisX[(offset-256)] = ((int)(newValue) * 100); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct fuelTable.axisX[(offset - 256)] = ((int)(newValue) * 100); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct
} }
else else
{ {
//Y Axis //Y Axis
offset = 15-(offset-272); //Need to do a translation to flip the order (Due to us using (0,0) in the top left rather than bottom right offset = 15 - (offset - 272); //Need to do a translation to flip the order (Due to us using (0,0) in the top left rather than bottom right
fuelTable.axisY[offset] = (int)(newValue); fuelTable.axisY[offset] = (int)(newValue);
} }
return; return;
@ -267,7 +273,7 @@ void receiveValue(int offset, byte newValue)
case veSetPage: case veSetPage:
pnt_configPage = &configPage1; //Setup a pointer to the relevant config page pnt_configPage = &configPage1; //Setup a pointer to the relevant config page
//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 //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) if ( offset < page_size)
{ {
*((byte *)pnt_configPage + (byte)offset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages *((byte *)pnt_configPage + (byte)offset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages
} }
@ -276,7 +282,7 @@ void receiveValue(int offset, byte newValue)
case ignMapPage: //Ignition settings page (Page 2) case ignMapPage: //Ignition settings page (Page 2)
if (offset < 256) //New value is part of the ignition map if (offset < 256) //New value is part of the ignition map
{ {
ignitionTable.values[15-offset/16][offset%16] = newValue; ignitionTable.values[15 - offset / 16][offset % 16] = newValue;
return; return;
} }
else else
@ -285,12 +291,12 @@ void receiveValue(int offset, byte newValue)
if (offset < 272) if (offset < 272)
{ {
//X Axis //X Axis
ignitionTable.axisX[(offset-256)] = (int)(newValue) * int(100); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct ignitionTable.axisX[(offset - 256)] = (int)(newValue) * int(100); //The RPM values sent by megasquirt are divided by 100, need to multiple it back by 100 to make it correct
} }
else else
{ {
//Y Axis //Y Axis
offset = 15-(offset-272); //Need to do a translation to flip the order offset = 15 - (offset - 272); //Need to do a translation to flip the order
ignitionTable.axisY[offset] = (int)(newValue); ignitionTable.axisY[offset] = (int)(newValue);
} }
return; return;
@ -299,7 +305,7 @@ void receiveValue(int offset, byte newValue)
case ignSetPage: case ignSetPage:
pnt_configPage = &configPage2; pnt_configPage = &configPage2;
//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 //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) if ( offset < page_size)
{ {
*((byte *)pnt_configPage + (byte)offset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages *((byte *)pnt_configPage + (byte)offset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages
} }
@ -308,7 +314,7 @@ void receiveValue(int offset, byte newValue)
case afrMapPage: //Air/Fuel ratio target settings page case afrMapPage: //Air/Fuel ratio target settings page
if (offset < 256) //New value is part of the afr map if (offset < 256) //New value is part of the afr map
{ {
afrTable.values[15-offset/16][offset%16] = newValue; afrTable.values[15 - offset / 16][offset % 16] = newValue;
return; return;
} }
else else
@ -317,12 +323,12 @@ void receiveValue(int offset, byte newValue)
if (offset < 272) if (offset < 272)
{ {
//X Axis //X Axis
afrTable.axisX[(offset-256)] = 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 afrTable.axisX[(offset - 256)] = 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 else
{ {
//Y Axis //Y Axis
offset = 15-(offset-272); //Need to do a translation to flip the order offset = 15 - (offset - 272); //Need to do a translation to flip the order
afrTable.axisY[offset] = int(newValue); afrTable.axisY[offset] = int(newValue);
} }
@ -332,7 +338,7 @@ void receiveValue(int offset, byte newValue)
case afrSetPage: case afrSetPage:
pnt_configPage = &configPage3; pnt_configPage = &configPage3;
//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 //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) if ( offset < page_size)
{ {
*((byte *)pnt_configPage + (byte)offset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages *((byte *)pnt_configPage + (byte)offset) = newValue; //Need to subtract 80 because the map and bins (Which make up 80 bytes) aren't part of the config pages
} }
@ -341,7 +347,7 @@ void receiveValue(int offset, byte newValue)
case iacPage: //Idle Air Control settings page (Page 4) case iacPage: //Idle Air Control settings page (Page 4)
pnt_configPage = &configPage4; pnt_configPage = &configPage4;
//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 //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) if ( offset < page_size)
{ {
*((byte *)pnt_configPage + (byte)offset) = newValue; *((byte *)pnt_configPage + (byte)offset) = newValue;
} }
@ -349,23 +355,23 @@ void receiveValue(int offset, byte newValue)
case boostvvtPage: //Boost and VVT maps (8x8) case boostvvtPage: //Boost and VVT maps (8x8)
if (offset < 64) //New value is part of the boost map if (offset < 64) //New value is part of the boost map
{ {
boostTable.values[7-offset/8][offset%8] = newValue; boostTable.values[7 - offset / 8][offset % 8] = newValue;
return; return;
} }
else if (offset < 72) //New value is on the X (RPM) axis of the boost table else if (offset < 72) //New value is on the X (RPM) axis of the boost table
{ {
boostTable.axisX[(offset-64)] = int(newValue) * int(100); //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct boostTable.axisX[(offset - 64)] = int(newValue) * int(100); //The RPM values sent by TunerStudio are divided by 100, need to multiply it back by 100 to make it correct
return; return;
} }
else if (offset < 80) //New value is on the Y (TPS) axis of the boost table else if (offset < 80) //New value is on the Y (TPS) axis of the boost table
{ {
boostTable.axisY[(7-(offset-72))] = int(newValue); boostTable.axisY[(7 - (offset - 72))] = int(newValue);
return; return;
} }
else if (offset < 144) //New value is part of the vvt map else if (offset < 144) //New value is part of the vvt map
{ {
offset = offset - 80; offset = offset - 80;
vvtTable.values[7-offset/8][offset%8] = newValue; vvtTable.values[7 - offset / 8][offset % 8] = newValue;
return; return;
} }
else if (offset < 152) //New value is on the X (RPM) axis of the vvt table else if (offset < 152) //New value is on the X (RPM) axis of the vvt table
@ -377,7 +383,7 @@ void receiveValue(int offset, byte newValue)
else //New value is on the Y (Load) axis of the vvt table else //New value is on the Y (Load) axis of the vvt table
{ {
offset = offset - 152; offset = offset - 152;
vvtTable.axisY[(7-offset)] = int(newValue); vvtTable.axisY[(7 - offset)] = int(newValue);
return; return;
} }
default: default:
@ -389,12 +395,13 @@ void receiveValue(int offset, byte newValue)
sendPage() packs the data within the current page (As set with the 'P' command) sendPage() packs the data within the current page (As set with the 'P' command)
into a buffer and sends it. into a buffer and sends it.
Note that some translation of the data is required to lay it out in the way Megasqurit / TunerStudio expect it Note that some translation of the data is required to lay it out in the way Megasqurit / TunerStudio expect it
useChar - If true, all values are send as chars, this is for the serial command line interface. TunerStudio expects data as raw values, so this must be set false in that case
*/ */
void sendPage(bool useChar) void sendPage(bool useChar)
{ {
void* pnt_configPage; void* pnt_configPage;
struct table3D currentTable; struct table3D currentTable;
byte currentTitleIndex=0; byte currentTitleIndex = 0;
switch (currentPage) switch (currentPage)
{ {
@ -408,20 +415,22 @@ void sendPage(bool useChar)
case veSetPage: case veSetPage:
{ {
// currentTitleIndex = 27; // currentTitleIndex = 27;
if(useChar) if (useChar)
{ {
//To Display Values from Config Page 1 //To Display Values from Config Page 1
Serial.println((const __FlashStringHelper *)&pageTitles[27]); Serial.println((const __FlashStringHelper *)&pageTitles[27]);
for(pnt_configPage=&configPage1;pnt_configPage<&configPage1.wueValues[0];pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage)); for (pnt_configPage = &configPage1; pnt_configPage < &configPage1.wueValues[0]; pnt_configPage = (byte *)pnt_configPage + 1) Serial.println(*((byte *)pnt_configPage));
for(byte x=10;x;x--) for (byte x = 10; x; x--)
{ {
Serial.print(configPage1.wueValues[10-x]); Serial.print(configPage1.wueValues[10 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
for(pnt_configPage=(byte *)&configPage1.wueValues[9]+1;pnt_configPage<&configPage1.inj1Ang;pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage)); for (pnt_configPage = (byte *)&configPage1.wueValues[9] + 1; pnt_configPage < &configPage1.inj1Ang; pnt_configPage = (byte *)pnt_configPage + 1) {
for(pnt_configPage=&configPage1.inj1Ang;pnt_configPage<(unsigned int *)&configPage1.inj4Ang+1;pnt_configPage=(unsigned int *)pnt_configPage+1) Serial.println(*((unsigned int *)pnt_configPage)); Serial.println(*((byte *)pnt_configPage));
for(pnt_configPage=(unsigned int *)&configPage1.inj4Ang+1;pnt_configPage<(byte *)&configPage1+page_size;pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage)); }
for (pnt_configPage = &configPage1.inj1Ang; pnt_configPage < (unsigned int *)&configPage1.inj4Ang + 1; pnt_configPage = (unsigned int *)pnt_configPage + 1) Serial.println(*((unsigned int *)pnt_configPage));
for (pnt_configPage = (unsigned int *)&configPage1.inj4Ang + 1; pnt_configPage < (byte *)&configPage1 + page_size; pnt_configPage = (byte *)pnt_configPage + 1) Serial.println(*((byte *)pnt_configPage));
return; return;
} }
else pnt_configPage = &configPage1; //Create a pointer to Page 1 in memory else pnt_configPage = &configPage1; //Create a pointer to Page 1 in memory
@ -438,38 +447,47 @@ void sendPage(bool useChar)
case ignSetPage: case ignSetPage:
{ {
//currentTitleIndex = 56; //currentTitleIndex = 56;
if(useChar) if (useChar)
{ {
//To Display Values from Config Page 2 //To Display Values from Config Page 2
Serial.println((const __FlashStringHelper *)&pageTitles[56]); Serial.println((const __FlashStringHelper *)&pageTitles[56]);
Serial.println(configPage2.triggerAngle); Serial.println(configPage2.triggerAngle);
for(pnt_configPage=(int *)&configPage2+1;pnt_configPage<&configPage2.taeBins[0];pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage));
for(byte y=2;y;y--) for (pnt_configPage = (int *)&configPage2 + 1; pnt_configPage < &configPage2.taeBins[0]; pnt_configPage = (byte *)pnt_configPage + 1) Serial.println(*((byte *)pnt_configPage));
for (byte y = 2; y; y--)
{ {
byte * currentVar; byte * currentVar;
if(y==2) currentVar=configPage2.taeBins; if (y == 2) {
else currentVar=configPage2.taeValues; currentVar = configPage2.taeBins;
for(byte x=4;x;x--) }
else {
currentVar = configPage2.taeValues;
}
for (byte x = 4; x; x--)
{ {
Serial.print(currentVar[4-x]); Serial.print(currentVar[4 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
} }
for(byte x=10;x;x--) for (byte x = 10; x ; x--)
{ {
Serial.print(configPage2.wueBins[10-x]); Serial.print(configPage2.wueBins[10 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
Serial.println(configPage2.dwellLimit); Serial.println(configPage2.dwellLimit);
for(byte x=6;x;x--) for (byte x = 6; x; x--)
{ {
Serial.print(configPage2.dwellCorrectionValues[6-x]); Serial.print(configPage2.dwellCorrectionValues[6 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
for(pnt_configPage=(byte *)&configPage2.dwellCorrectionValues[5]+1;pnt_configPage<(byte *)&configPage2+page_size;pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage)); for (pnt_configPage = (byte *)&configPage2.dwellCorrectionValues[5] + 1; pnt_configPage < (byte *)&configPage2 + page_size; pnt_configPage = (byte *)pnt_configPage + 1)
{
Serial.println(*((byte *)pnt_configPage));
}
return; return;
} }
else pnt_configPage = &configPage2; //Create a pointer to Page 2 in memory else pnt_configPage = &configPage2; //Create a pointer to Page 2 in memory
@ -486,36 +504,43 @@ void sendPage(bool useChar)
case afrSetPage: case afrSetPage:
{ {
//currentTitleIndex = 91; //currentTitleIndex = 91;
if(useChar) if (useChar)
{ {
//To Display Values from Config Page 3 //To Display Values from Config Page 3
Serial.println((const __FlashStringHelper *)&pageTitles[91]); Serial.println((const __FlashStringHelper *)&pageTitles[91]);
for(pnt_configPage=&configPage3;pnt_configPage<&configPage3.voltageCorrectionBins[0];pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage)); for (pnt_configPage = &configPage3; pnt_configPage < &configPage3.voltageCorrectionBins[0]; pnt_configPage = (byte *)pnt_configPage + 1)
for(byte y=2;y;y--) {
Serial.println(*((byte *)pnt_configPage));
}
for (byte y = 2; y; y--)
{ {
byte * currentVar; byte * currentVar;
if(y==2) currentVar=configPage3.voltageCorrectionBins; if (y == 2) { currentVar = configPage3.voltageCorrectionBins; }
else currentVar=configPage3.injVoltageCorrectionValues; else { currentVar = configPage3.injVoltageCorrectionValues; }
for(byte x=6;x;x--)
for (byte x = 6; x; x--)
{ {
Serial.print(currentVar[6-x]); Serial.print(currentVar[6 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
} }
for(byte y=2;y;y--) for (byte y = 2; y; y--)
{ {
byte* currentVar; byte* currentVar;
if(y==2) currentVar=configPage3.airDenBins; if (y == 2) currentVar = configPage3.airDenBins;
else currentVar=configPage3.airDenRates; else currentVar = configPage3.airDenRates;
for(byte x=9;x;x--) for (byte x = 9; x; x--)
{ {
Serial.print(currentVar[9-x]); Serial.print(currentVar[9 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
} }
for(pnt_configPage=(byte *)&configPage3.airDenRates[8]+1;pnt_configPage<(byte *)&configPage3+page_size;pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage)); for (pnt_configPage = (byte *)&configPage3.airDenRates[8] + 1; pnt_configPage < (byte *)&configPage3 + page_size; pnt_configPage = (byte *)pnt_configPage + 1)
{
Serial.println(*((byte *)pnt_configPage));
}
return; return;
} }
else pnt_configPage = &configPage3; //Create a pointer to Page 3 in memory else pnt_configPage = &configPage3; //Create a pointer to Page 3 in memory
@ -526,63 +551,64 @@ void sendPage(bool useChar)
{ {
//currentTitleIndex = 106; //currentTitleIndex = 106;
//To Display Values from Config Page 4 //To Display Values from Config Page 4
if(useChar) if (useChar)
{ {
Serial.println((const __FlashStringHelper *)&pageTitles[106]); Serial.println((const __FlashStringHelper *)&pageTitles[106]);
for(byte y=4;y;y--) for (byte y = 4; y; y--)
{ {
byte * currentVar; byte * currentVar;
switch(y) switch (y)
{ {
case 1: currentVar=configPage4.iacBins; break; case 1: currentVar = configPage4.iacBins; break;
case 2: currentVar=configPage4.iacOLPWMVal; break; case 2: currentVar = configPage4.iacOLPWMVal; break;
case 3: currentVar=configPage4.iacOLStepVal; break; case 3: currentVar = configPage4.iacOLStepVal; break;
case 4: currentVar=configPage4.iacCLValues; break; case 4: currentVar = configPage4.iacCLValues; break;
default: break; default: break;
} }
for(byte x=10;x;x--) for (byte x = 10; x; x--)
{ {
Serial.print(currentVar[10-x]); Serial.print(currentVar[10 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
} }
for(byte y=3;y;y--) for (byte y = 3; y; y--)
{ {
byte * currentVar; byte * currentVar;
switch(y) switch (y)
{ {
case 1: currentVar=configPage4.iacCrankBins; break; case 1: currentVar = configPage4.iacCrankBins; break;
case 2: currentVar=configPage4.iacCrankDuty; break; case 2: currentVar = configPage4.iacCrankDuty; break;
case 3: currentVar=configPage4.iacCrankSteps; break; case 3: currentVar = configPage4.iacCrankSteps; break;
default: break; default: break;
} }
for(byte x=4;x;x--) for (byte x = 4; x; x--)
{ {
Serial.print(currentVar[4-x]); Serial.print(currentVar[4 - x]);
Serial.print(' '); Serial.print(' ');
} }
Serial.println(); Serial.println();
} }
for(pnt_configPage=(byte *)&configPage4.iacCrankBins[3]+1;pnt_configPage<(byte *)&configPage4+page_size;pnt_configPage=(byte *)pnt_configPage+1) Serial.println(*((byte *)pnt_configPage)); for (pnt_configPage = (byte *)&configPage4.iacCrankBins[3] + 1; pnt_configPage < (byte *)&configPage4 + page_size; pnt_configPage = (byte *)pnt_configPage + 1) Serial.println(*((byte *)pnt_configPage));
return; return;
} }
else pnt_configPage = &configPage4; //Create a pointer to Page 4 in memory else pnt_configPage = &configPage4; //Create a pointer to Page 4 in memory
break; break;
} }
case boostvvtPage: case boostvvtPage:
{ {
//Need to perform a translation of the values[MAP/TPS][RPM] into the MS expected format //Need to perform a translation of the values[MAP/TPS][RPM] into the MS expected format
byte response[160]; //Bit hacky, but the size is: (8x8 + 8 + 8) + (8x8 + 8 + 8) = 160 byte response[160]; //Bit hacky, but the size is: (8x8 + 8 + 8) + (8x8 + 8 + 8) = 160
//Boost table //Boost table
for(int x=0;x<64;x++) { response[x] = boostTable.values[7-x/8][x%8]; } for (int x = 0; x < 64; x++) { response[x] = boostTable.values[7 - x / 8][x % 8]; }
for(int x=64;x<72;x++) { response[x] = byte(boostTable.axisX[(x-64)] / 100); } for (int x = 64; x < 72; x++) { response[x] = byte(boostTable.axisX[(x - 64)] / 100); }
for(int y=72;y<80;y++) { response[y] = byte(boostTable.axisY[7-(y-72)]); } for (int y = 72; y < 80; y++) { response[y] = byte(boostTable.axisY[7 - (y - 72)]); }
//VVT table //VVT table
for(int x=0;x<64;x++) { response[x+80] = vvtTable.values[7-x/8][x%8]; } for (int x = 0; x < 64; x++) { response[x + 80] = vvtTable.values[7 - x / 8][x % 8]; }
for(int x=64;x<72;x++) { response[x+80] = byte(vvtTable.axisX[(x-64)] / 100); } for (int x = 64; x < 72; x++) { response[x + 80] = byte(vvtTable.axisX[(x - 64)] / 100); }
for(int y=72;y<80;y++) { response[y+80] = byte(vvtTable.axisY[7-(y-72)]); } for (int y = 72; y < 80; y++) { response[y + 80] = byte(vvtTable.axisY[7 - (y - 72)]); }
Serial.write((byte *)&response, sizeof(response)); Serial.write((byte *)&response, sizeof(response));
return; return;
break; break;
@ -594,9 +620,9 @@ void sendPage(bool useChar)
break; break;
} }
} }
if(isMap) if (isMap)
{ {
if(useChar) if (useChar)
{ {
const char spaceChar = ' '; const char spaceChar = ' ';
/*while(pageTitles[currentTitleIndex]) /*while(pageTitles[currentTitleIndex])
@ -606,13 +632,13 @@ void sendPage(bool useChar)
}*/ }*/
Serial.println((const __FlashStringHelper *)&pageTitles[currentTitleIndex]); Serial.println((const __FlashStringHelper *)&pageTitles[currentTitleIndex]);
Serial.print(F("\n ")); Serial.print(F("\n "));
for(int x=0;x<currentTable.xSize;x++) for (int x = 0; x < currentTable.xSize; x++)
{ {
byte axisX = byte(currentTable.axisX[x]/100); byte axisX = byte(currentTable.axisX[x] / 100);
if(axisX < 100) if (axisX < 100)
{ {
Serial.write(spaceChar); Serial.write(spaceChar);
if(axisX <10) if (axisX < 10)
{ {
Serial.write(spaceChar); Serial.write(spaceChar);
} }
@ -621,17 +647,17 @@ void sendPage(bool useChar)
Serial.write(spaceChar); Serial.write(spaceChar);
} }
Serial.println(); Serial.println();
for(int y=0;y<currentTable.ySize;y++) for (int y = 0; y < currentTable.ySize; y++)
{ {
Serial.print(byte(currentTable.axisY[y])); Serial.print(byte(currentTable.axisY[y]));
Serial.write(spaceChar); Serial.write(spaceChar);
for(int x=0;x<currentTable.xSize;x++) for (int x = 0; x < currentTable.xSize; x++)
{ {
byte value = currentTable.values[y][x]; byte value = currentTable.values[y][x];
if(value < 100) if (value < 100)
{ {
Serial.write(spaceChar); Serial.write(spaceChar);
if(value <10) if (value < 10)
{ {
Serial.write(spaceChar); Serial.write(spaceChar);
} }
@ -648,9 +674,9 @@ void sendPage(bool useChar)
//MS format has origin (0,0) in the bottom left corner, we use the top left for efficiency reasons //MS format has origin (0,0) in the bottom left corner, we use the top left for efficiency reasons
byte response[map_page_size]; byte response[map_page_size];
for(int x=0;x<256;x++) { response[x] = currentTable.values[15-x/16][x%16]; } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged for (int x = 0; x < 256; x++) { response[x] = currentTable.values[15 - x / 16][x % 16]; } //This is slightly non-intuitive, but essentially just flips the table vertically (IE top line becomes the bottom line etc). Columns are unchanged
for(int x=256;x<272;x++) { response[x] = byte(currentTable.axisX[(x-256)] / 100); } //RPM Bins for VE table (Need to be dvidied by 100) for (int x = 256; x < 272; x++) { response[x] = byte(currentTable.axisX[(x - 256)] / 100); } //RPM Bins for VE table (Need to be dvidied by 100)
for(int y=272;y<288;y++) { response[y] = byte(currentTable.axisY[15-(y-272)]); } //MAP or TPS bins for VE table for (int y = 272; y < 288; y++) { response[y] = byte(currentTable.axisY[15 - (y - 272)]); } //MAP or TPS bins for VE table
Serial.write((byte *)&response, sizeof(response)); Serial.write((byte *)&response, sizeof(response));
} }
} }
@ -670,7 +696,7 @@ void sendPage(bool useChar)
{*/ {*/
//All other bytes can simply be copied from the config table //All other bytes can simply be copied from the config table
byte response[page_size]; byte response[page_size];
for(byte x=0; x<page_size; x++) for (byte x = 0; x < page_size; x++)
{ {
response[x] = *((byte *)pnt_configPage + x); //Each byte is simply the location in memory of the configPage + the offset + the variable number (x) response[x] = *((byte *)pnt_configPage + x); //Each byte is simply the location in memory of the configPage + the offset + the variable number (x)
} }
@ -731,7 +757,7 @@ void receiveCalibration(byte tableID)
for (x = 0; x < 1024; x++) for (x = 0; x < 1024; x++)
{ {
//UNlike what is listed in the protocol documentation, the O2 sensor values are sent as bytes rather than ints //UNlike what is listed in the protocol documentation, the O2 sensor values are sent as bytes rather than ints
if(BYTES_PER_VALUE == 1) if (BYTES_PER_VALUE == 1)
{ {
while ( Serial.available() < 1 ) {} while ( Serial.available() < 1 ) {}
tempValue = Serial.read(); tempValue = Serial.read();
@ -749,8 +775,12 @@ void receiveCalibration(byte tableID)
if (every2nd) //Only use every 2nd value if (every2nd) //Only use every 2nd value
{ {
if (tempValue > 255) { tempValue = 255; } // Cap the maximum value to prevent overflow when converting to byte if (tempValue > 255) {
if (tempValue < 0) { tempValue = 0; } tempValue = 255; // Cap the maximum value to prevent overflow when converting to byte
}
if (tempValue < 0) {
tempValue = 0;
}
pnt_TargetTable[(x / 2)] = (byte)tempValue; pnt_TargetTable[(x / 2)] = (byte)tempValue;
int y = EEPROM_CALIBRATION_O2 + counter; int y = EEPROM_CALIBRATION_O2 + counter;
@ -759,7 +789,9 @@ void receiveCalibration(byte tableID)
analogWrite(13, (counter % 50) ); analogWrite(13, (counter % 50) );
counter++; counter++;
} }
else { every2nd = true; } else {
every2nd = true;
}
} }
@ -774,7 +806,9 @@ void sendToothLog(bool useChar)
{ {
//We need 256 records to send to TunerStudio. If there aren't that many in the buffer (Buffer is 512 long) then we just return and wait for the next call //We need 256 records to send to TunerStudio. If there aren't that many in the buffer (Buffer is 512 long) then we just return and wait for the next call
if (toothHistoryIndex < 256) { return; } //Don't believe this is the best way to go. Just display whatever is in the buffer if (toothHistoryIndex < 256) {
return; //Don't believe this is the best way to go. Just display whatever is in the buffer
}
unsigned int tempToothHistory[512]; //Create a temporary array that will contain a copy of what is in the main toothHistory array unsigned int tempToothHistory[512]; //Create a temporary array that will contain a copy of what is in the main toothHistory array
//Copy the working history into the temporary buffer array. This is done so that, if the history loops whilst the values are being sent over serial, it doesn't affect the values //Copy the working history into the temporary buffer array. This is done so that, if the history loops whilst the values are being sent over serial, it doesn't affect the values
@ -784,20 +818,20 @@ void sendToothLog(bool useChar)
//Loop only needs to go to 256 (Even though the buffer is 512 long) as we only ever send 256 entries at a time //Loop only needs to go to 256 (Even though the buffer is 512 long) as we only ever send 256 entries at a time
if (useChar) if (useChar)
{ {
for(int x=0; x<256; x++) for (int x = 0; x < 256; x++)
{ {
Serial.println(tempToothHistory[x]); Serial.println(tempToothHistory[x]);
} }
} }
else else
{ {
for(int x=0; x<256; x++) for (int x = 0; x < 256; x++)
{ {
Serial.write(highByte(tempToothHistory[x])); Serial.write(highByte(tempToothHistory[x]));
Serial.write(lowByte(tempToothHistory[x])); Serial.write(lowByte(tempToothHistory[x]));
} }
} }
Serial.flush(); //Serial.flush();
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 KiB