From a2bc8732ac13196e74b08739775bc098853f4356 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sat, 10 Jan 2015 09:56:14 +1100 Subject: [PATCH] Possible fix for TunerStudio calibrations --- comms.ino | 35 ++++++----------------------------- storage.ino | 8 +++----- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/comms.ino b/comms.ino index b4a8be0..8bb4b17 100644 --- a/comms.ino +++ b/comms.ino @@ -62,6 +62,7 @@ void command() receiveCalibration(tableID); //Receive new values and store in memory writeCalibration(); //Store received values in EEPROM + analogWrite(13, 0 ); break; @@ -333,35 +334,17 @@ void receiveCalibration(byte tableID) int tempValue; byte tempBuffer[2]; bool every2nd = true; - //byte tempVal = 3; int x; int counter = 0; - Serial.setTimeout(20); pinMode(13, OUTPUT); + digitalWrite(13, LOW); for (x = 0; x < 1024; x++) { - //tempVal = Serial.available(); - //int failcount = 0; while ( Serial.available() < 2 ) {} tempBuffer[0] = Serial.read(); tempBuffer[1] = Serial.read(); - /* - 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); - */ - //Serial.readBytes(tempBuffer, 2); - - //int hsb16 = Serial.read(); - //int lsb16 = 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((tempBuffer[0] << 8 | tempBuffer[1]), 10).quot; tempValue = tempValue + OFFSET; @@ -371,11 +354,10 @@ void receiveCalibration(byte tableID) { 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)(counter); + pnt_TargetTable[(x / 2)] = (byte)tempValue; + //pnt_TargetTable[counter] = (byte)(counter); int y = EEPROM_CALIBRATION_O2 + counter; - EEPROM.write(y, (byte)counter); - //if(counter > 400) { pnt_TargetTable[counter] = 201;} + //EEPROM.write(y, (byte)counter); every2nd = false; analogWrite(13, (counter % 50) ); @@ -383,13 +365,8 @@ void receiveCalibration(byte tableID) } else { every2nd = true; }//digitalWrite(13, HIGH); } - //pnt_TargetTable[x] = tempValue; - //x++; } - Serial.setTimeout(1000); - while(Serial.available() > 0) { Serial.read(); } - //pnt_TargetTable[511] = 123; - //cltCalibrationTable[510] = 123; + } /* diff --git a/storage.ino b/storage.ino index 821cfda..dba4f28 100644 --- a/storage.ino +++ b/storage.ino @@ -169,8 +169,6 @@ void loadCalibration() /* This takes the values in the 3 calibration tables (Coolant, Inlet temp and O2) and saves them to the EEPROM. - -TODO: Need to add checking prior to write in order to prolong EEPROM life */ void writeCalibration() { @@ -178,13 +176,13 @@ void writeCalibration() for(int x=0; x