mirror of https://github.com/rusefi/speeduino.git
Further testing on the calibration receives from TS (Partially Broken)
This commit is contained in:
parent
838f0ee5c7
commit
fcd700b6f9
85
comms.ino
85
comms.ino
|
@ -300,46 +300,77 @@ void receiveCalibration(byte tableID)
|
|||
{
|
||||
byte* pnt_TargetTable; //Pointer that will be used to point to the required target table
|
||||
int default_val; //The default value that is used in the sent table for invalid ADC values
|
||||
|
||||
switch(tableID)
|
||||
int offset;
|
||||
|
||||
switch (tableID)
|
||||
{
|
||||
case 0:
|
||||
//coolant table
|
||||
pnt_TargetTable = (byte *)&cltCalibrationTable;
|
||||
break;
|
||||
case 1:
|
||||
//Inlet air temp table
|
||||
pnt_TargetTable = (byte *)&iatCalibrationTable;
|
||||
break;
|
||||
case 2:
|
||||
//O2 table
|
||||
pnt_TargetTable = (byte *)&o2CalibrationTable;
|
||||
break;
|
||||
|
||||
default:
|
||||
return; //Should never get here, but if we do, just fail back to main loop
|
||||
//pnt_TargetTable = (table2D *)&o2CalibrationTable;
|
||||
//break;
|
||||
case 0:
|
||||
//coolant table
|
||||
pnt_TargetTable = (byte *)&cltCalibrationTable;
|
||||
offset = CALIBRATION_TEMPERATURE_OFFSET;
|
||||
break;
|
||||
case 1:
|
||||
//Inlet air temp table
|
||||
pnt_TargetTable = (byte *)&iatCalibrationTable;
|
||||
offset = CALIBRATION_TEMPERATURE_OFFSET;
|
||||
break;
|
||||
case 2:
|
||||
//O2 table
|
||||
pnt_TargetTable = (byte *)&o2CalibrationTable;
|
||||
offset = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
return; //Should never get here, but if we do, just fail back to main loop
|
||||
//pnt_TargetTable = (table2D *)&o2CalibrationTable;
|
||||
//break;
|
||||
}
|
||||
|
||||
|
||||
//1024 value pairs are sent. We have to receive them all, but only use every second one (We only store 512 calibratino table entries to save on EEPROM space)
|
||||
//The values are sent as 2 byte ints, but we convert them to single bytes. Any values over 255 are capped at 255.
|
||||
int newValues[1024];
|
||||
int tempValue;
|
||||
bool every2nd = true;
|
||||
for(int x=0; x<1024; x++)
|
||||
//byte tempVal = 3;
|
||||
int x;
|
||||
int counter = 0;
|
||||
for (x = 0; x < 800; x++)
|
||||
{
|
||||
while (Serial.available() < 2) { }
|
||||
newValues[x] = int(word(Serial.read(), Serial.read())) / 10; //Read 2 bytes, convert to word (an unsigned int), convert to signed int
|
||||
//tempVal = Serial.available();
|
||||
int failcount = 0;
|
||||
//while ( (Serial.available() < 2) && (failcount < 20000) ) { failcount++; }
|
||||
|
||||
int hsb16 = -1;
|
||||
while( hsb16 == -1 ) { hsb16 = Serial.read(); }
|
||||
byte hsb = (byte)(hsb16);
|
||||
int lsb16 = -1;
|
||||
while( lsb16 == -1 ) { lsb16 = Serial.read(); }
|
||||
byte lsb = (byte)(lsb16);
|
||||
|
||||
//int hsb16 = Serial.read();
|
||||
//int lsb16 = Serial.read();
|
||||
|
||||
tempValue = div(int(word(hsb16, lsb16)), 10).quot; //Read 2 bytes, convert to word (an unsigned int), convert to signed int. These values come through * 10 from Tuner Studio
|
||||
tempValue = tempValue + offset;
|
||||
|
||||
if (every2nd) //Only use every 2nd value
|
||||
{
|
||||
if (newValues[x] > 255) { newValues[x] = 255; } // Cap the maximum value to prevent overflow when converting to byte
|
||||
if (newValues[x] < 0) { newValues[x] = 0; }
|
||||
pnt_TargetTable[(x/2)] = (byte)newValues[x];
|
||||
if (tempValue > 255) { 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[counter] = (byte)tempValue;
|
||||
if(counter > 400) { cltCalibrationTable[counter] = 201;}
|
||||
|
||||
every2nd = false;
|
||||
counter++;
|
||||
}
|
||||
else { every2nd = true; }
|
||||
|
||||
//pnt_TargetTable[x] = tempVal;
|
||||
x++;
|
||||
}
|
||||
|
||||
//pnt_TargetTable[511] = 123;
|
||||
//cltCalibrationTable[510] = 123;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -34,6 +34,7 @@ const byte page_size = 128;
|
|||
|
||||
//Table sizes
|
||||
#define CALIBRATION_TABLE_SIZE 512
|
||||
#define CALIBRATION_TEMPERATURE_OFFSET 40 // All temperature measurements are stored offset by 40 degrees. This is so we can use an unsigned byte (0-255) to represent temperature ranges from -40 to 215
|
||||
|
||||
//The status struct contains the current values for all 'live' variables
|
||||
//In current version this is 64 bytes
|
||||
|
@ -47,9 +48,9 @@ struct statuses {
|
|||
byte tpsDOT;
|
||||
byte VE;
|
||||
byte O2;
|
||||
byte coolant;
|
||||
int coolant;
|
||||
int cltADC;
|
||||
byte IAT;
|
||||
int IAT;
|
||||
int iatADC;
|
||||
int batADC;
|
||||
byte battery10; //The current BRV in volts (multiplied by 10. Eg 12.5V = 125)
|
||||
|
|
|
@ -567,7 +567,7 @@ help = helpEnrichments, "Enrichments Help"
|
|||
#matADCGauge = matADC, "MAT ADC", "", 0, 255, -1, -1, 256, 256, 0, 0
|
||||
#cltADCGauge = cltADC, "CLT ADC", "", 0, 255, -1, -1, 256, 256, 0, 0
|
||||
tpsADCGauge = tpsADC, "TPS ADC", "", 0, 255, -1, -1, 256, 256, 0, 0
|
||||
batADCGauge = batADC, "BAT ADC", "", 0, 255, -1, -1, 256, 256, 0, 0
|
||||
#batVoltGauge = batteryVoltage, "BAT V", "", 0, 255, -1, -1, 256, 256, 0, 0
|
||||
|
||||
#if NARROW_BAND_EGO
|
||||
egoGauge = egoVoltage, "Exhaust Gas Oxygen", "volts", 0, 1.0, 0.2, 0.3, 0.6, 0.8, 2, 2
|
||||
|
@ -755,13 +755,13 @@ help = helpEnrichments, "Enrichments Help"
|
|||
#cltADC = scalar, U08, 6, "ADC", 1.000, 0.000
|
||||
#if CELSIUS
|
||||
mat = scalar, U08, 5, "°C", 1.000, 0.000
|
||||
coolant = scalar, U08, 6, "°C", 1.000, 0.000
|
||||
coolantRaw = scalar, U08, 6, "°C", 1.000, 0.000
|
||||
#else
|
||||
mat = scalar, U08, 5, "°F", 1.000, 0.000
|
||||
coolant = scalar, U08, 6, "°F", 1.000, 0.000
|
||||
coolantRaw = scalar, U08, 6, "°F", 1.000, 0.000
|
||||
#endif
|
||||
tpsADC = scalar, U08, 7, "ADC", 1.000, 0.000
|
||||
batteryVoltage = scalar, U08, 8, "ADC", 0.100, 0.000
|
||||
batteryVoltage = scalar, U08, 8, "V", 0.100, 0.000
|
||||
egoADC = scalar, U08, 9, "ADC", 1.000, 0.000
|
||||
egoCorrection = scalar, U08, 10, "%", 1.000, 0.000
|
||||
airCorrection = scalar, U08, 11, "%", 1.000, 0.000
|
||||
|
@ -785,7 +785,7 @@ help = helpEnrichments, "Enrichments Help"
|
|||
|
||||
accDecEnrich = { accelEnrich + ((engine & 0b00100000) ? tdePct : 100) }
|
||||
#batteryVoltage = { batADC / 255.0 * 30.0 } ; Current MS power supply voltage.
|
||||
#coolant = { tempCvt(table(cltADC, "thermfactor.inc")-40) } ; Coolant sensor temperature in user units.
|
||||
coolant = { coolantRaw - 40 } ; Coolant sensor temperature in user units.
|
||||
#mat = { tempCvt(table(matADC, "matfactor.inc")-40) } ; Manifold temperature in user units.
|
||||
egoVoltage = { egoADC / 255.0 * 5.0 } ; EGO sensor voltage.
|
||||
rpm = { rpm100*100 } ; True RPM.
|
||||
|
|
|
@ -245,8 +245,8 @@ void loop()
|
|||
currentStatus.battery10 = map(analogRead(pinBat), 0, 1023, 0, 245); //Get the current raw Battery value. Permissible values are from 0v to 24.5v (245)
|
||||
//currentStatus.batADC = map(analogRead(pinBat), 0, 1023, 0, 255); //Get the current raw Battery value
|
||||
|
||||
currentStatus.coolant = cltCalibrationTable[currentStatus.cltADC];
|
||||
currentStatus.IAT = iatCalibrationTable[currentStatus.iatADC];
|
||||
currentStatus.coolant = cltCalibrationTable[currentStatus.cltADC] - CALIBRATION_TEMPERATURE_OFFSET; //Temperature calibration values are stored as positive bytes. We subtract 40 from them to allow for negative temperatures
|
||||
currentStatus.IAT = iatCalibrationTable[currentStatus.iatADC] - CALIBRATION_TEMPERATURE_OFFSET;
|
||||
}
|
||||
|
||||
//Always check for sync
|
||||
|
|
Loading…
Reference in New Issue