Clean ups to remove some of the compiler warnings

This commit is contained in:
Josh Stewart 2014-06-06 11:29:43 +10:00
parent 2ff9c42797
commit ed592f9416
4 changed files with 19 additions and 16 deletions

View File

@ -52,17 +52,17 @@ void command()
receiveValue(offset, Serial.read());
break;
case 't': // receive new Calibration info. Command structure: "t", <can_id> <tble_idx> <data array>. This is an MS2/Extra command, NOT part of MS1 spec
case 't': // receive new Calibration info. Command structure: "t", <tble_idx> <data array>. This is an MS2/Extra command, NOT part of MS1 spec
byte tableID;
byte canID;
//byte canID;
//The first 2 bytes sent represent the canID and tableID
while (Serial.available() == 0) { }
canID = Serial.read(); //Not currently used for anything
tableID = Serial.read(); //Not currently used for anything
//while (Serial.available() == 0) { }
// tableID = Serial.read();
receiveCalibration(canID); //Receive new values and store in memory
receiveCalibration(tableID); //Receive new values and store in memory
writeCalibration(); //Store received values in EEPROM
break;
@ -316,8 +316,8 @@ void receiveCalibration(byte tableID)
//break;
}
//1024 value pairs are sent. We have to receive them all, but only pick out the ones we want to keep
//Currently we are only picking out 3 values
//1024 value pairs are sent. We have to receive them all, but only pick out the 3 we want to keep
//Currently we are only picking out 3 values, we could switch to 5 or 7, but 3 seems to be working OK
//Each of the tables has a threshold at which valid values start and end
int newValues[1024];
//The first and last valid values

View File

@ -38,7 +38,7 @@ Calculates the % change of the throttle over time (%/second) and performs a look
byte correctionAccel()
{
int rateOfChange = div(1000000, (currentLoopTime - previousLoopTime)).quot * (currentStatus.TPS - currentStatus.TPSlast); //This is the % per second that the TPS has moved
int rateOfChange = ldiv(1000000, (currentLoopTime - previousLoopTime)).quot * (currentStatus.TPS - currentStatus.TPSlast); //This is the % per second that the TPS has moved
//int rateOfChange = div( (1000000 * (currentStatus.TPS - currentStatus.TPSlast)), (currentLoopTime - previousLoopTime)).quot; //This is the % per second that the TPS has moved
currentStatus.tpsDOT = div(rateOfChange, 10).quot;

2
math.h
View File

@ -1,6 +1,6 @@
//Replace the standard arduino map() function to use the div function instead
long fastMap(long x, long in_min, long in_max, long out_min, long out_max)
long fastMap(int x, int in_min, int in_max, int out_min, int out_max)
{
return div( ((x - in_min) * (out_max - out_min)) , ((in_max - in_min) + out_min) ).quot;
}

View File

@ -44,7 +44,7 @@ struct config2 configPage2;
int req_fuel_uS, triggerToothAngle;
volatile int triggerActualTeeth;
int triggerFilterTime = 500; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
unsigned int triggerFilterTime = 500; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
volatile int toothCurrentCount = 0; //The current number of teeth (Onec sync has been achieved, this can never actually be 0
volatile unsigned long toothLastToothTime = 0; //The time (micros()) that the last tooth was registered
@ -72,7 +72,7 @@ byte coilLOW = LOW;
struct statuses currentStatus;
volatile int mainLoopCount;
unsigned long secCounter; //The next time to increment 'runSecs' counter.
byte crankDegreesPerCylinder; //The number of crank degrees between cylinders (180 in a 4 cylinder, usually 120 in a 6 cylinder etc)
int crankDegreesPerCylinder; //The number of crank degrees between cylinders (180 in a 4 cylinder, usually 120 in a 6 cylinder etc)
void setup()
{
@ -225,7 +225,7 @@ void loop()
noInterrupts();
unsigned long revolutionTime = (toothOneTime - toothOneMinusOneTime); //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that)
interrupts();
currentStatus.RPM = US_IN_MINUTE / revolutionTime; //Calc RPM based on last full revolution time (Can't use div() here as US_IN_MINUTE is larger than an unsigned int)
currentStatus.RPM = ldiv(US_IN_MINUTE, revolutionTime).quot; //Calc RPM based on last full revolution time (uses ldiv rather than div as US_IN_MINUTE is a long)
}
else
{
@ -324,10 +324,13 @@ void loop()
if (configPage1.nCylinders == 2) { injector2StartAngle = (355 + crankDegreesPerCylinder - ( div(currentStatus.PW, timePerDegree).quot )) % 360; }
if (configPage1.nCylinders == 4) { injector2StartAngle = (355 + crankDegreesPerCylinder - ( div(currentStatus.PW, timePerDegree).quot )) % 360; }
if (currentStatus.RPM > ((int)(configPage2.SoftRevLim * 100)) ) { currentStatus.advance -= configPage2.SoftLimRetard; } //Softcut RPM limit (If we're above softcut limit, delay timing by configured number of degrees)
if (currentStatus.RPM > ((unsigned int)(configPage2.SoftRevLim * 100)) ) { currentStatus.advance -= configPage2.SoftLimRetard; } //Softcut RPM limit (If we're above softcut limit, delay timing by configured number of degrees)
//Calculate start angle for each channel
//1
ignition1StartAngle = 360 - currentStatus.advance - (div((configPage2.dwellRun*100), timePerDegree).quot ); // 360 - desired advance angle - number of degrees the dwell will take
if (configPage1.nCylinders == 2) { (ignition1StartAngle = 360 + crankDegreesPerCylinder - currentStatus.advance - (div((configPage2.dwellRun*100), timePerDegree).quot )) % 360; }
if (configPage1.nCylinders == 4) { (ignition1StartAngle = 360 + crankDegreesPerCylinder - currentStatus.advance - (div((configPage2.dwellRun*100), timePerDegree).quot )) % 360; }
//2
if (configPage1.nCylinders == 2) { (ignition2StartAngle = crankDegreesPerCylinder + 360 - currentStatus.advance - (div((configPage2.dwellRun*100), timePerDegree).quot )) % 360; }
if (configPage1.nCylinders == 4) { (ignition2StartAngle = crankDegreesPerCylinder + 360 - currentStatus.advance - (div((configPage2.dwellRun*100), timePerDegree).quot )) % 360; }
//Finally calculate the time (uS) until we reach the firing angles and set the schedules
@ -353,7 +356,7 @@ void loop()
int dwell = (configPage2.dwellRun * 100); //Dwell is stored as ms * 10. ie Dwell of 4.3ms would be 43 in configPage2. This number therefore needs to be multiplied by 100 to get dwell in uS
if ( ignition1StartAngle > crankAngle)
{
if (currentStatus.RPM < ((int)(configPage2.HardRevLim) * 100) ) //Check for hard cut rev limit (If we're above the hardcut limit, we simply don't set a spark schedule)
if (currentStatus.RPM < ((unsigned int)(configPage2.HardRevLim) * 100) ) //Check for hard cut rev limit (If we're above the hardcut limit, we simply don't set a spark schedule)
{
setIgnitionSchedule1(beginCoil1Charge,
(ignition1StartAngle - crankAngle) * timePerDegree,
@ -364,7 +367,7 @@ void loop()
}
if ( ignition2StartAngle > crankAngle)
{
if (currentStatus.RPM < ((int)(configPage2.HardRevLim) * 100) ) //Check for hard cut rev limit (If we're above the hardcut limit, we simply don't set a spark schedule)
if (currentStatus.RPM < ((unsigned int)(configPage2.HardRevLim) * 100) ) //Check for hard cut rev limit (If we're above the hardcut limit, we simply don't set a spark schedule)
{
setIgnitionSchedule2(beginCoil2Charge,
(ignition2StartAngle - crankAngle) * timePerDegree,