Add handling for the O2 calibrations (single bytes)
This commit is contained in:
parent
7b2b0212c2
commit
67a1c1399d
23
comms.ino
23
comms.ino
|
@ -62,7 +62,6 @@ void command()
|
||||||
|
|
||||||
receiveCalibration(tableID); //Receive new values and store in memory
|
receiveCalibration(tableID); //Receive new values and store in memory
|
||||||
writeCalibration(); //Store received values in EEPROM
|
writeCalibration(); //Store received values in EEPROM
|
||||||
analogWrite(13, 0 );
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -300,7 +299,7 @@ This function is used to store calibration data sent by Tuner Studio.
|
||||||
void receiveCalibration(byte tableID)
|
void receiveCalibration(byte tableID)
|
||||||
{
|
{
|
||||||
byte* pnt_TargetTable; //Pointer that will be used to point to the required target table
|
byte* pnt_TargetTable; //Pointer that will be used to point to the required target table
|
||||||
int OFFSET, DIVISION_FACTOR;
|
int OFFSET, DIVISION_FACTOR, BYTES_PER_VALUE;
|
||||||
|
|
||||||
switch (tableID)
|
switch (tableID)
|
||||||
{
|
{
|
||||||
|
@ -309,18 +308,22 @@ void receiveCalibration(byte tableID)
|
||||||
pnt_TargetTable = (byte *)&cltCalibrationTable;
|
pnt_TargetTable = (byte *)&cltCalibrationTable;
|
||||||
OFFSET = CALIBRATION_TEMPERATURE_OFFSET; //
|
OFFSET = CALIBRATION_TEMPERATURE_OFFSET; //
|
||||||
DIVISION_FACTOR = 10;
|
DIVISION_FACTOR = 10;
|
||||||
|
BYTES_PER_VALUE = 2;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
//Inlet air temp table
|
//Inlet air temp table
|
||||||
pnt_TargetTable = (byte *)&iatCalibrationTable;
|
pnt_TargetTable = (byte *)&iatCalibrationTable;
|
||||||
OFFSET = CALIBRATION_TEMPERATURE_OFFSET;
|
OFFSET = CALIBRATION_TEMPERATURE_OFFSET;
|
||||||
DIVISION_FACTOR = 10;
|
DIVISION_FACTOR = 10;
|
||||||
|
BYTES_PER_VALUE = 2;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//O2 table
|
//O2 table
|
||||||
pnt_TargetTable = (byte *)&o2CalibrationTable;
|
pnt_TargetTable = (byte *)&o2CalibrationTable;
|
||||||
OFFSET = 0;
|
OFFSET = 0;
|
||||||
DIVISION_FACTOR = 1;
|
DIVISION_FACTOR = 1;
|
||||||
|
o2CalibrationTable[10] = 123;
|
||||||
|
BYTES_PER_VALUE = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -340,30 +343,36 @@ void receiveCalibration(byte tableID)
|
||||||
|
|
||||||
digitalWrite(13, LOW);
|
digitalWrite(13, LOW);
|
||||||
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
|
||||||
|
if(BYTES_PER_VALUE == 1)
|
||||||
|
{
|
||||||
|
while ( Serial.available() < 1 ) {}
|
||||||
|
tempValue = Serial.read();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
while ( Serial.available() < 2 ) {}
|
while ( Serial.available() < 2 ) {}
|
||||||
tempBuffer[0] = Serial.read();
|
tempBuffer[0] = Serial.read();
|
||||||
tempBuffer[1] = Serial.read();
|
tempBuffer[1] = Serial.read();
|
||||||
|
|
||||||
tempValue = div(int(word(tempBuffer[0], tempBuffer[1])), DIVISION_FACTOR).quot; //Read 2 bytes, convert to word (an unsigned int), convert to signed int. These values come through * 10 from Tuner Studio
|
tempValue = div(int(word(tempBuffer[0], tempBuffer[1])), DIVISION_FACTOR).quot; //Read 2 bytes, convert to word (an unsigned int), convert to signed int. These values come through * 10 from Tuner Studio
|
||||||
//tempValue = div((tempBuffer[0] << 8 | tempBuffer[1]), 10).quot;
|
}
|
||||||
tempValue = tempValue + OFFSET;
|
tempValue = tempValue + OFFSET;
|
||||||
//tempValue = word(tempBuffer[0], tempBuffer[1]);
|
|
||||||
|
|
||||||
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) { tempValue = 255; } // Cap the maximum value to prevent overflow when converting to byte
|
||||||
if (tempValue < 0) { tempValue = 0; }
|
if (tempValue < 0) { tempValue = 0; }
|
||||||
|
|
||||||
pnt_TargetTable[(x / 2)] = (byte)tempValue;
|
pnt_TargetTable[(x / 2)] = (byte)tempValue;
|
||||||
//pnt_TargetTable[counter] = (byte)(counter);
|
|
||||||
int y = EEPROM_CALIBRATION_O2 + counter;
|
int y = EEPROM_CALIBRATION_O2 + counter;
|
||||||
//EEPROM.write(y, (byte)counter);
|
|
||||||
|
|
||||||
every2nd = false;
|
every2nd = false;
|
||||||
analogWrite(13, (counter % 50) );
|
analogWrite(13, (counter % 50) );
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
else { every2nd = true; }//digitalWrite(13, HIGH); }
|
else { every2nd = true; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue