2019-12-18 22:31:02 -08:00
# include "globals.h"
2022-01-04 21:41:12 -08:00
# include "logger.h"
2019-12-18 22:31:02 -08:00
# include "errors.h"
2023-03-29 20:29:38 -07:00
# include "decoders.h"
2023-05-16 18:25:50 -07:00
# include "init.h"
2023-10-05 21:07:12 -07:00
# include "maths.h"
# include "utilities.h"
2023-10-06 00:10:20 -07:00
# include BOARD_H
2019-12-18 22:31:02 -08:00
2021-10-12 17:53:46 -07:00
/**
* Returns a numbered byte - field ( partial field in case of multi - byte fields ) from " current status " structure in the format expected by TunerStudio
2021-10-03 06:09:53 -07:00
* Notes on fields :
* - Numbered field will be fields from @ ref currentStatus , but not at all in the internal order of strct ( e . g . field RPM value , number 14 will be
* 2 nd field in struct )
* - The fields stored in multi - byte types will be accessed lowbyte and highbyte separately ( e . g . PW1 will be broken into numbered byte - fields 75 , 76 )
2021-10-12 17:53:46 -07:00
* - Values have the value offsets and shifts expected by TunerStudio . They will not all be a ' human readable value '
* @ param byteNum - byte - Field number . This is not the entry number ( As some entries have multiple byets ) , but the byte number that is needed
2021-10-03 06:09:53 -07:00
* @ return Field value in 1 byte size struct fields or 1 byte partial value ( chunk ) on multibyte fields .
*/
2021-10-12 17:53:46 -07:00
byte getTSLogEntry ( uint16_t byteNum )
2019-12-18 22:31:02 -08:00
{
2021-10-03 06:09:53 -07:00
byte statusValue = 0 ;
2019-12-18 22:31:02 -08:00
2021-10-03 06:09:53 -07:00
switch ( byteNum )
{
case 0 : statusValue = currentStatus . secl ; break ; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
case 1 : statusValue = currentStatus . status1 ; break ; //status1 Bitfield
case 2 : statusValue = currentStatus . engine ; break ; //Engine Status Bitfield
case 3 : statusValue = currentStatus . syncLossCounter ; break ;
case 4 : statusValue = lowByte ( currentStatus . MAP ) ; break ; //2 bytes for MAP
case 5 : statusValue = highByte ( currentStatus . MAP ) ; break ;
2023-10-05 21:07:12 -07:00
case 6 : statusValue = lowByte ( currentStatus . IAT + CALIBRATION_TEMPERATURE_OFFSET ) ; break ; //mat
case 7 : statusValue = lowByte ( currentStatus . coolant + CALIBRATION_TEMPERATURE_OFFSET ) ; break ; //Coolant ADC
2021-10-03 06:09:53 -07:00
case 8 : statusValue = currentStatus . batCorrection ; break ; //Battery voltage correction (%)
case 9 : statusValue = currentStatus . battery10 ; break ; //battery voltage
case 10 : statusValue = currentStatus . O2 ; break ; //O2
case 11 : statusValue = currentStatus . egoCorrection ; break ; //Exhaust gas correction (%)
case 12 : statusValue = currentStatus . iatCorrection ; break ; //Air temperature Correction (%)
case 13 : statusValue = currentStatus . wueCorrection ; break ; //Warmup enrichment (%)
case 14 : statusValue = lowByte ( currentStatus . RPM ) ; break ; //rpm HB
case 15 : statusValue = highByte ( currentStatus . RPM ) ; break ; //rpm LB
2023-10-05 21:07:12 -07:00
case 16 : statusValue = lowByte ( currentStatus . AEamount > > 1U ) ; break ; //TPS acceleration enrichment (%) divided by 2 (Can exceed 255)
2021-10-03 06:09:53 -07:00
case 17 : statusValue = lowByte ( currentStatus . corrections ) ; break ; //Total GammaE (%)
case 18 : statusValue = highByte ( currentStatus . corrections ) ; break ; //Total GammaE (%)
case 19 : statusValue = currentStatus . VE1 ; break ; //VE 1 (%)
case 20 : statusValue = currentStatus . VE2 ; break ; //VE 2 (%)
case 21 : statusValue = currentStatus . afrTarget ; break ;
2022-12-13 16:17:47 -08:00
case 22 : statusValue = lowByte ( currentStatus . tpsDOT ) ; break ; //TPS DOT
case 23 : statusValue = highByte ( currentStatus . tpsDOT ) ; break ; //TPS DOT
case 24 : statusValue = currentStatus . advance ; break ;
case 25 : statusValue = currentStatus . TPS ; break ; // TPS (0% to 100%)
2021-10-03 06:09:53 -07:00
2022-12-13 16:17:47 -08:00
case 26 :
2023-10-05 21:07:12 -07:00
if ( currentStatus . loopsPerSecond > 60000U ) { currentStatus . loopsPerSecond = 60000U ; }
2021-10-03 06:09:53 -07:00
statusValue = lowByte ( currentStatus . loopsPerSecond ) ;
break ;
2022-12-13 16:17:47 -08:00
case 27 :
2023-10-05 21:07:12 -07:00
if ( currentStatus . loopsPerSecond > 60000U ) { currentStatus . loopsPerSecond = 60000U ; }
2021-10-03 06:09:53 -07:00
statusValue = highByte ( currentStatus . loopsPerSecond ) ;
break ;
2022-12-13 16:17:47 -08:00
case 28 :
2021-10-03 06:09:53 -07:00
currentStatus . freeRAM = freeRam ( ) ;
statusValue = lowByte ( currentStatus . freeRAM ) ; //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF);
break ;
2022-12-13 16:17:47 -08:00
case 29 :
2021-10-03 06:09:53 -07:00
currentStatus . freeRAM = freeRam ( ) ;
statusValue = highByte ( currentStatus . freeRAM ) ;
break ;
2019-12-18 22:31:02 -08:00
2023-10-05 21:07:12 -07:00
case 30 : statusValue = lowByte ( currentStatus . boostTarget > > 1U ) ; break ; //Divide boost target by 2 to fit in a byte
case 31 : statusValue = lowByte ( div100 ( currentStatus . boostDuty ) ) ; break ;
2024-07-10 23:14:09 -07:00
case 32 : statusValue = currentStatus . status2 ; break ; //Spark related bitfield
2019-12-18 22:31:02 -08:00
//rpmDOT must be sent as a signed integer
2022-12-13 16:17:47 -08:00
case 33 : statusValue = lowByte ( currentStatus . rpmDOT ) ; break ;
case 34 : statusValue = highByte ( currentStatus . rpmDOT ) ; break ;
2019-12-18 22:31:02 -08:00
2022-12-13 16:17:47 -08:00
case 35 : statusValue = currentStatus . ethanolPct ; break ; //Flex sensor value (or 0 if not used)
case 36 : statusValue = currentStatus . flexCorrection ; break ; //Flex fuel correction (% above or below 100)
case 37 : statusValue = currentStatus . flexIgnCorrection ; break ; //Ignition correction (Increased degrees of advance) for flex fuel
2019-12-18 22:31:02 -08:00
2022-12-13 16:17:47 -08:00
case 38 : statusValue = currentStatus . idleLoad ; break ;
case 39 : statusValue = currentStatus . testOutputs ; break ;
2019-12-18 22:31:02 -08:00
2022-12-13 16:17:47 -08:00
case 40 : statusValue = currentStatus . O2_2 ; break ; //O2
case 41 : statusValue = currentStatus . baro ; break ; //Barometer value
2019-12-18 22:31:02 -08:00
2022-12-13 16:17:47 -08:00
case 42 : statusValue = lowByte ( currentStatus . canin [ 0 ] ) ; break ;
case 43 : statusValue = highByte ( currentStatus . canin [ 0 ] ) ; break ;
case 44 : statusValue = lowByte ( currentStatus . canin [ 1 ] ) ; break ;
case 45 : statusValue = highByte ( currentStatus . canin [ 1 ] ) ; break ;
case 46 : statusValue = lowByte ( currentStatus . canin [ 2 ] ) ; break ;
case 47 : statusValue = highByte ( currentStatus . canin [ 2 ] ) ; break ;
case 48 : statusValue = lowByte ( currentStatus . canin [ 3 ] ) ; break ;
case 49 : statusValue = highByte ( currentStatus . canin [ 3 ] ) ; break ;
case 50 : statusValue = lowByte ( currentStatus . canin [ 4 ] ) ; break ;
case 51 : statusValue = highByte ( currentStatus . canin [ 4 ] ) ; break ;
case 52 : statusValue = lowByte ( currentStatus . canin [ 5 ] ) ; break ;
case 53 : statusValue = highByte ( currentStatus . canin [ 5 ] ) ; break ;
case 54 : statusValue = lowByte ( currentStatus . canin [ 6 ] ) ; break ;
case 55 : statusValue = highByte ( currentStatus . canin [ 6 ] ) ; break ;
case 56 : statusValue = lowByte ( currentStatus . canin [ 7 ] ) ; break ;
case 57 : statusValue = highByte ( currentStatus . canin [ 7 ] ) ; break ;
case 58 : statusValue = lowByte ( currentStatus . canin [ 8 ] ) ; break ;
case 59 : statusValue = highByte ( currentStatus . canin [ 8 ] ) ; break ;
case 60 : statusValue = lowByte ( currentStatus . canin [ 9 ] ) ; break ;
case 61 : statusValue = highByte ( currentStatus . canin [ 9 ] ) ; break ;
case 62 : statusValue = lowByte ( currentStatus . canin [ 10 ] ) ; break ;
case 63 : statusValue = highByte ( currentStatus . canin [ 10 ] ) ; break ;
case 64 : statusValue = lowByte ( currentStatus . canin [ 11 ] ) ; break ;
case 65 : statusValue = highByte ( currentStatus . canin [ 11 ] ) ; break ;
case 66 : statusValue = lowByte ( currentStatus . canin [ 12 ] ) ; break ;
case 67 : statusValue = highByte ( currentStatus . canin [ 12 ] ) ; break ;
case 68 : statusValue = lowByte ( currentStatus . canin [ 13 ] ) ; break ;
case 69 : statusValue = highByte ( currentStatus . canin [ 13 ] ) ; break ;
case 70 : statusValue = lowByte ( currentStatus . canin [ 14 ] ) ; break ;
case 71 : statusValue = highByte ( currentStatus . canin [ 14 ] ) ; break ;
case 72 : statusValue = lowByte ( currentStatus . canin [ 15 ] ) ; break ;
case 73 : statusValue = highByte ( currentStatus . canin [ 15 ] ) ; break ;
2019-12-18 22:31:02 -08:00
2022-12-13 16:17:47 -08:00
case 74 : statusValue = currentStatus . tpsADC ; break ;
case 75 : statusValue = getNextError ( ) ; break ;
2019-12-18 22:31:02 -08:00
2022-12-13 16:17:47 -08:00
case 76 : statusValue = lowByte ( currentStatus . PW1 ) ; break ; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
case 77 : statusValue = highByte ( currentStatus . PW1 ) ; break ; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
case 78 : statusValue = lowByte ( currentStatus . PW2 ) ; break ; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
case 79 : statusValue = highByte ( currentStatus . PW2 ) ; break ; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
case 80 : statusValue = lowByte ( currentStatus . PW3 ) ; break ; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
case 81 : statusValue = highByte ( currentStatus . PW3 ) ; break ; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
case 82 : statusValue = lowByte ( currentStatus . PW4 ) ; break ; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
case 83 : statusValue = highByte ( currentStatus . PW4 ) ; break ; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
2019-12-18 22:31:02 -08:00
2022-12-13 16:17:47 -08:00
case 84 : statusValue = currentStatus . status3 ; break ;
case 85 : statusValue = currentStatus . engineProtectStatus ; break ;
case 86 : statusValue = lowByte ( currentStatus . fuelLoad ) ; break ;
case 87 : statusValue = highByte ( currentStatus . fuelLoad ) ; break ;
case 88 : statusValue = lowByte ( currentStatus . ignLoad ) ; break ;
case 89 : statusValue = highByte ( currentStatus . ignLoad ) ; break ;
case 90 : statusValue = lowByte ( currentStatus . dwell ) ; break ;
case 91 : statusValue = highByte ( currentStatus . dwell ) ; break ;
case 92 : statusValue = currentStatus . CLIdleTarget ; break ;
case 93 : statusValue = lowByte ( currentStatus . mapDOT ) ; break ;
case 94 : statusValue = highByte ( currentStatus . mapDOT ) ; break ;
case 95 : statusValue = lowByte ( currentStatus . vvt1Angle ) ; break ; //2 bytes for vvt1Angle
case 96 : statusValue = highByte ( currentStatus . vvt1Angle ) ; break ;
case 97 : statusValue = currentStatus . vvt1TargetAngle ; break ;
2023-10-05 21:07:12 -07:00
case 98 : statusValue = lowByte ( currentStatus . vvt1Duty ) ; break ;
2022-12-13 16:17:47 -08:00
case 99 : statusValue = lowByte ( currentStatus . flexBoostCorrection ) ; break ;
case 100 : statusValue = highByte ( currentStatus . flexBoostCorrection ) ; break ;
case 101 : statusValue = currentStatus . baroCorrection ; break ;
case 102 : statusValue = currentStatus . VE ; break ; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them
case 103 : statusValue = currentStatus . ASEValue ; break ; //Current ASE (%)
case 104 : statusValue = lowByte ( currentStatus . vss ) ; break ;
case 105 : statusValue = highByte ( currentStatus . vss ) ; break ;
case 106 : statusValue = currentStatus . gear ; break ;
case 107 : statusValue = currentStatus . fuelPressure ; break ;
case 108 : statusValue = currentStatus . oilPressure ; break ;
case 109 : statusValue = currentStatus . wmiPW ; break ;
case 110 : statusValue = currentStatus . status4 ; break ;
case 111 : statusValue = lowByte ( currentStatus . vvt2Angle ) ; break ; //2 bytes for vvt2Angle
case 112 : statusValue = highByte ( currentStatus . vvt2Angle ) ; break ;
case 113 : statusValue = currentStatus . vvt2TargetAngle ; break ;
2023-10-05 21:07:12 -07:00
case 114 : statusValue = lowByte ( currentStatus . vvt2Duty ) ; break ;
2022-12-13 16:17:47 -08:00
case 115 : statusValue = currentStatus . outputsStatus ; break ;
2023-10-05 21:07:12 -07:00
case 116 : statusValue = lowByte ( currentStatus . fuelTemp + CALIBRATION_TEMPERATURE_OFFSET ) ; break ; //Fuel temperature from flex sensor
2022-12-13 16:17:47 -08:00
case 117 : statusValue = currentStatus . fuelTempCorrection ; break ; //Fuel temperature Correction (%)
case 118 : statusValue = currentStatus . advance1 ; break ; //advance 1 (%)
case 119 : statusValue = currentStatus . advance2 ; break ; //advance 2 (%)
case 120 : statusValue = currentStatus . TS_SD_Status ; break ; //SD card status
case 121 : statusValue = lowByte ( currentStatus . EMAP ) ; break ; //2 bytes for EMAP
case 122 : statusValue = highByte ( currentStatus . EMAP ) ; break ;
case 123 : statusValue = currentStatus . fanDuty ; break ;
case 124 : statusValue = currentStatus . airConStatus ; break ;
2023-05-21 20:37:40 -07:00
case 125 : statusValue = lowByte ( currentStatus . actualDwell ) ; break ;
case 126 : statusValue = highByte ( currentStatus . actualDwell ) ; break ;
2024-07-10 23:14:09 -07:00
case 127 : statusValue = currentStatus . status5 ; break ;
case 128 : statusValue = currentStatus . knockCount ; break ;
case 129 : statusValue = currentStatus . knockRetard ; break ;
2023-10-05 21:07:12 -07:00
default : statusValue = 0 ; // MISRA check
2021-10-03 06:09:53 -07:00
}
2019-12-18 22:31:02 -08:00
2021-10-03 06:09:53 -07:00
return statusValue ;
2021-10-12 17:53:46 -07:00
}
/**
2021-10-20 14:03:29 -07:00
* Similar to the @ ref getTSLogEntry function , however this returns a full , unadjusted ( ie human readable ) log entry value .
2021-10-12 17:53:46 -07:00
* See logger . h for the field names and order
* @ param logIndex - The log index required . Note that this is NOT the byte number , but the index in the log
* @ return Raw , unadjusted value of the log entry . No offset or multiply is applied like it is with the TS log
*/
int16_t getReadableLogEntry ( uint16_t logIndex )
{
int16_t statusValue = 0 ;
switch ( logIndex )
{
case 0 : statusValue = currentStatus . secl ; break ; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
case 1 : statusValue = currentStatus . status1 ; break ; //status1 Bitfield
case 2 : statusValue = currentStatus . engine ; break ; //Engine Status Bitfield
case 3 : statusValue = currentStatus . syncLossCounter ; break ;
case 4 : statusValue = currentStatus . MAP ; break ; //2 bytes for MAP
case 5 : statusValue = currentStatus . IAT ; break ; //mat
case 6 : statusValue = currentStatus . coolant ; break ; //Coolant ADC
case 7 : statusValue = currentStatus . batCorrection ; break ; //Battery voltage correction (%)
case 8 : statusValue = currentStatus . battery10 ; break ; //battery voltage
case 9 : statusValue = currentStatus . O2 ; break ; //O2
2021-10-12 23:54:55 -07:00
case 10 : statusValue = currentStatus . egoCorrection ; break ; //Exhaust gas correction (%)
case 11 : statusValue = currentStatus . iatCorrection ; break ; //Air temperature Correction (%)
case 12 : statusValue = currentStatus . wueCorrection ; break ; //Warmup enrichment (%)
case 13 : statusValue = currentStatus . RPM ; break ; //rpm HB
2022-08-09 19:12:42 -07:00
case 14 : statusValue = currentStatus . AEamount ; break ; //TPS acceleration enrichment (%)
2021-10-12 23:54:55 -07:00
case 15 : statusValue = currentStatus . corrections ; break ; //Total GammaE (%)
case 16 : statusValue = currentStatus . VE1 ; break ; //VE 1 (%)
case 17 : statusValue = currentStatus . VE2 ; break ; //VE 2 (%)
case 18 : statusValue = currentStatus . afrTarget ; break ;
case 19 : statusValue = currentStatus . tpsDOT ; break ; //TPS DOT
case 20 : statusValue = currentStatus . advance ; break ;
case 21 : statusValue = currentStatus . TPS ; break ; // TPS (0% to 100%)
2021-10-12 17:53:46 -07:00
2021-10-12 23:54:55 -07:00
case 22 :
2023-10-05 21:07:12 -07:00
if ( currentStatus . loopsPerSecond > 60000U ) { currentStatus . loopsPerSecond = 60000U ; }
2021-10-12 23:54:55 -07:00
statusValue = currentStatus . loopsPerSecond ;
2021-10-12 17:53:46 -07:00
break ;
2021-10-12 23:54:55 -07:00
case 23 :
2021-10-12 17:53:46 -07:00
currentStatus . freeRAM = freeRam ( ) ;
2021-10-12 23:54:55 -07:00
statusValue = currentStatus . freeRAM ;
2021-10-12 17:53:46 -07:00
break ;
2021-10-12 23:54:55 -07:00
case 24 : statusValue = currentStatus . boostTarget ; break ;
case 25 : statusValue = currentStatus . boostDuty ; break ;
2024-07-10 23:14:09 -07:00
case 26 : statusValue = currentStatus . status2 ; break ; //Spark related bitfield
2021-10-12 23:54:55 -07:00
case 27 : statusValue = currentStatus . rpmDOT ; break ;
case 28 : statusValue = currentStatus . ethanolPct ; break ; //Flex sensor value (or 0 if not used)
case 29 : statusValue = currentStatus . flexCorrection ; break ; //Flex fuel correction (% above or below 100)
case 30 : statusValue = currentStatus . flexIgnCorrection ; break ; //Ignition correction (Increased degrees of advance) for flex fuel
case 31 : statusValue = currentStatus . idleLoad ; break ;
case 32 : statusValue = currentStatus . testOutputs ; break ;
case 33 : statusValue = currentStatus . O2_2 ; break ; //O2
case 34 : statusValue = currentStatus . baro ; break ; //Barometer value
2021-10-12 17:53:46 -07:00
2021-10-12 23:54:55 -07:00
case 35 : statusValue = currentStatus . canin [ 0 ] ; break ;
case 36 : statusValue = currentStatus . canin [ 1 ] ; break ;
case 37 : statusValue = currentStatus . canin [ 2 ] ; break ;
case 38 : statusValue = currentStatus . canin [ 3 ] ; break ;
case 39 : statusValue = currentStatus . canin [ 4 ] ; break ;
case 40 : statusValue = currentStatus . canin [ 5 ] ; break ;
case 41 : statusValue = currentStatus . canin [ 6 ] ; break ;
case 42 : statusValue = currentStatus . canin [ 7 ] ; break ;
case 43 : statusValue = currentStatus . canin [ 8 ] ; break ;
case 44 : statusValue = currentStatus . canin [ 9 ] ; break ;
case 45 : statusValue = currentStatus . canin [ 10 ] ; break ;
case 46 : statusValue = currentStatus . canin [ 11 ] ; break ;
case 47 : statusValue = currentStatus . canin [ 12 ] ; break ;
case 48 : statusValue = currentStatus . canin [ 13 ] ; break ;
case 49 : statusValue = currentStatus . canin [ 14 ] ; break ;
case 50 : statusValue = currentStatus . canin [ 15 ] ; break ;
case 51 : statusValue = currentStatus . tpsADC ; break ;
case 52 : statusValue = getNextError ( ) ; break ;
2021-10-12 17:53:46 -07:00
2021-10-12 23:54:55 -07:00
case 53 : statusValue = currentStatus . PW1 ; break ; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
case 54 : statusValue = currentStatus . PW2 ; break ; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
case 55 : statusValue = currentStatus . PW3 ; break ; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
case 56 : statusValue = currentStatus . PW4 ; break ; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
case 57 : statusValue = currentStatus . status3 ; break ;
case 58 : statusValue = currentStatus . engineProtectStatus ; break ;
2021-10-12 17:53:46 -07:00
2021-10-12 23:54:55 -07:00
case 59 : break ; //UNUSED!!
2021-10-12 17:53:46 -07:00
2021-10-12 23:54:55 -07:00
case 60 : statusValue = currentStatus . fuelLoad ; break ;
case 61 : statusValue = currentStatus . ignLoad ; break ;
2024-03-20 17:45:10 -07:00
case 62 : statusValue = ( int16_t ) currentStatus . dwell ; break ;
2021-10-12 23:54:55 -07:00
case 63 : statusValue = currentStatus . CLIdleTarget ; break ;
case 64 : statusValue = currentStatus . mapDOT ; break ;
case 65 : statusValue = currentStatus . vvt1Angle ; break ;
case 66 : statusValue = currentStatus . vvt1TargetAngle ; break ;
case 67 : statusValue = currentStatus . vvt1Duty ; break ;
case 68 : statusValue = currentStatus . flexBoostCorrection ; break ;
case 69 : statusValue = currentStatus . baroCorrection ; break ;
case 70 : statusValue = currentStatus . VE ; break ; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them
case 71 : statusValue = currentStatus . ASEValue ; break ; //Current ASE (%)
case 72 : statusValue = currentStatus . vss ; break ;
case 73 : statusValue = currentStatus . gear ; break ;
case 74 : statusValue = currentStatus . fuelPressure ; break ;
case 75 : statusValue = currentStatus . oilPressure ; break ;
case 76 : statusValue = currentStatus . wmiPW ; break ;
case 77 : statusValue = currentStatus . status4 ; break ;
case 78 : statusValue = currentStatus . vvt2Angle ; break ; //2 bytes for vvt2Angle
case 79 : statusValue = currentStatus . vvt2TargetAngle ; break ;
case 80 : statusValue = currentStatus . vvt2Duty ; break ;
case 81 : statusValue = currentStatus . outputsStatus ; break ;
case 82 : statusValue = currentStatus . fuelTemp ; break ; //Fuel temperature from flex sensor
case 83 : statusValue = currentStatus . fuelTempCorrection ; break ; //Fuel temperature Correction (%)
case 84 : statusValue = currentStatus . advance1 ; break ; //advance 1 (%)
case 85 : statusValue = currentStatus . advance2 ; break ; //advance 2 (%)
case 86 : statusValue = currentStatus . TS_SD_Status ; break ; //SD card status
case 87 : statusValue = currentStatus . EMAP ; break ;
2021-11-23 17:18:41 -08:00
case 88 : statusValue = currentStatus . fanDuty ; break ;
Air Conditioning Control - Feature Implementation (#665)
* 19.09.2021
* Final testing of AC Control, some idle features fixed
AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard.
Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work.
* Fixed mistakenly incremented page sizes
* Initial changes as per HWright9
-Renamed engineRunSeconds to acAfterEngineStartDelay
-Formatted large if statements better
-Fixed acStartDelay overflow bug
-Improved readability of logic
* Final fixes as per HWright9's feedback
-Add high/low RPM lockout delay, similar to the high TPM lockout delay
-General tidy-up
* Added stand-alone fan, moved config data in EEPROM
-Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic.
-Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13.
-Minor bug fix - rename Aux in 1-16 to Aux in 0-15
* Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5
* A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge.
Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings.
* Changed updates.ino to just set A/C to disabled
* Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba
* Fix remaining mistakes from previous master merge
* Remove test statements left in by mistake
* define unusedBits
* Remove test statements left in by mistake
* Increase timing granularity to 0.1s
* idleUpRPMAdder
* Remove another line put in by mistake by auto merge
* idleUpRPMFixes
* Update speeduino.ino
* Tweak A/C idle up descriptions
* Tweak A/C TS descriptors again
* Fixed alignment bug that turned page 15 config values into gobbledegook.
This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27).
* Fix bit count - should be 6 to match ini file
* Increase minimum RPM lockout granularity
* Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability
* Add static inline function prototypes to auxiliaries.h as per the style guide.
* Fixed page 15 merge errors
* Style changes to suit new pinIsUsed() checks in setPinMappings()
* Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged
* Fix comment
* Fix bug with stand-alone fan initialisation
Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit.
* Correction to Fahrenheit temperature scaling
* Move A/C updates to correct next release
Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com>
Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
case 89 : statusValue = currentStatus . airConStatus ; break ;
2023-05-21 20:37:40 -07:00
case 90 : statusValue = currentStatus . actualDwell ; break ;
2024-07-10 23:14:09 -07:00
case 91 : statusValue = currentStatus . status5 ; break ;
case 92 : statusValue = currentStatus . knockCount ; break ;
case 93 : statusValue = currentStatus . knockRetard ; break ;
2023-10-05 21:07:12 -07:00
default : statusValue = 0 ; // MISRA check
2021-10-12 17:53:46 -07:00
}
return statusValue ;
}
2022-08-09 19:12:42 -07:00
/**
* An expansion to the @ ref getReadableLogEntry function for systems that have an FPU . It will provide a floating point value for any parameter that this is appropriate for , otherwise will return the result of @ ref getReadableLogEntry .
* See logger . h for the field names and order
* @ param logIndex - The log index required . Note that this is NOT the byte number , but the index in the log
* @ return float value of the requested log entry .
*/
2023-10-05 21:07:12 -07:00
# if defined(FPU_MAX_SIZE) && FPU_MAX_SIZE >= 32 //cppcheck-suppress misra-c2012-20.9
2022-08-09 19:12:42 -07:00
float getReadableFloatLogEntry ( uint16_t logIndex )
{
float statusValue = 0.0 ;
switch ( logIndex )
{
case 8 : statusValue = currentStatus . battery10 / 10.0 ; break ; //battery voltage
case 9 : statusValue = currentStatus . O2 / 10.0 ; break ;
case 18 : statusValue = currentStatus . afrTarget / 10.0 ; break ;
case 21 : statusValue = currentStatus . TPS / 2.0 ; break ; // TPS (0% to 100% = 0 to 200)
case 33 : statusValue = currentStatus . O2_2 / 10.0 ; break ; //O2
case 53 : statusValue = currentStatus . PW1 / 1000.0 ; break ; //Pulsewidth 1 Have to convert from uS to mS.
case 54 : statusValue = currentStatus . PW2 / 1000.0 ; break ; //Pulsewidth 2 Have to convert from uS to mS.
case 55 : statusValue = currentStatus . PW3 / 1000.0 ; break ; //Pulsewidth 3 Have to convert from uS to mS.
case 56 : statusValue = currentStatus . PW4 / 1000.0 ; break ; //Pulsewidth 4 Have to convert from uS to mS.
default : statusValue = getReadableLogEntry ( logIndex ) ; break ; //If logIndex value is NOT a float based one, use the regular function
}
return statusValue ;
}
# endif
2023-10-09 21:49:36 -07:00
uint8_t getLegacySecondarySerialLogEntry ( uint16_t byteNum )
{
uint8_t statusValue = 0 ;
2024-07-10 23:14:09 -07:00
currentStatus . status2 ^ = ( - currentStatus . hasSync ^ currentStatus . status2 ) & ( 1U < < BIT_STATUS2_SYNC ) ; //Set the sync bit of the Spark variable to match the hasSync variable
2023-10-09 21:49:36 -07:00
switch ( byteNum )
{
case 0 : statusValue = currentStatus . secl ; break ; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
case 1 : statusValue = currentStatus . status1 ; break ; //status1 Bitfield, inj1Status(0), inj2Status(1), inj3Status(2), inj4Status(3), DFCOOn(4), boostCutFuel(5), toothLog1Ready(6), toothLog2Ready(7)
case 2 : statusValue = currentStatus . engine ; break ; //Engine Status Bitfield, running(0), crank(1), ase(2), warmup(3), tpsaccaen(4), tpsacden(5), mapaccaen(6), mapaccden(7)
case 3 : statusValue = ( byte ) div100 ( currentStatus . dwell ) ; break ; //Dwell in ms * 10
case 4 : statusValue = lowByte ( currentStatus . MAP ) ; break ; //2 bytes for MAP
case 5 : statusValue = highByte ( currentStatus . MAP ) ; break ;
case 6 : statusValue = ( byte ) ( currentStatus . IAT + CALIBRATION_TEMPERATURE_OFFSET ) ; break ; //mat
case 7 : statusValue = ( byte ) ( currentStatus . coolant + CALIBRATION_TEMPERATURE_OFFSET ) ; break ; //Coolant ADC
case 8 : statusValue = currentStatus . batCorrection ; break ; //Battery voltage correction (%)
case 9 : statusValue = currentStatus . battery10 ; break ; //battery voltage
case 10 : statusValue = currentStatus . O2 ; break ; //O2
case 11 : statusValue = currentStatus . egoCorrection ; break ; //Exhaust gas correction (%)
case 12 : statusValue = currentStatus . iatCorrection ; break ; //Air temperature Correction (%)
case 13 : statusValue = currentStatus . wueCorrection ; break ; //Warmup enrichment (%)
case 14 : statusValue = lowByte ( currentStatus . RPM ) ; break ; //rpm HB
case 15 : statusValue = highByte ( currentStatus . RPM ) ; break ; //rpm LB
case 16 : statusValue = currentStatus . AEamount ; break ; //acceleration enrichment (%)
case 17 : statusValue = currentStatus . corrections ; break ; //Total GammaE (%)
case 18 : statusValue = currentStatus . VE ; break ; //Current VE 1 (%)
case 19 : statusValue = currentStatus . afrTarget ; break ;
case 20 : statusValue = lowByte ( currentStatus . PW1 ) ; break ; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
case 21 : statusValue = highByte ( currentStatus . PW1 ) ; break ; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
case 22 : statusValue = ( uint8_t ) ( currentStatus . tpsDOT / 10 ) ; break ; //TPS DOT
case 23 : statusValue = currentStatus . advance ; break ;
case 24 : statusValue = currentStatus . TPS ; break ; // TPS (0% to 100%)
case 25 : statusValue = lowByte ( currentStatus . loopsPerSecond ) ; break ;
case 26 : statusValue = highByte ( currentStatus . loopsPerSecond ) ; break ;
case 27 : currentStatus . freeRAM = freeRam ( ) ; statusValue = lowByte ( currentStatus . freeRAM ) ; break ; //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF); break;
case 28 : currentStatus . freeRAM = freeRam ( ) ; statusValue = highByte ( currentStatus . freeRAM ) ; break ;
case 29 : statusValue = ( byte ) ( currentStatus . boostTarget > > 1 ) ; break ; //Divide boost target by 2 to fit in a byte
case 30 : statusValue = ( byte ) ( currentStatus . boostDuty / 100 ) ; break ;
2024-07-10 23:14:09 -07:00
case 31 : statusValue = currentStatus . status2 ; break ; //Spark related bitfield, launchHard(0), launchSoft(1), hardLimitOn(2), softLimitOn(3), boostCutSpark(4), error(5), idleControlOn(6), sync(7)
2023-10-09 21:49:36 -07:00
case 32 : statusValue = lowByte ( currentStatus . rpmDOT ) ; break ;
case 33 : statusValue = highByte ( currentStatus . rpmDOT ) ; break ;
case 34 : statusValue = currentStatus . ethanolPct ; break ; //Flex sensor value (or 0 if not used)
case 35 : statusValue = currentStatus . flexCorrection ; break ; //Flex fuel correction (% above or below 100)
case 36 : statusValue = currentStatus . flexIgnCorrection ; break ; //Ignition correction (Increased degrees of advance) for flex fuel
case 37 : statusValue = currentStatus . idleLoad ; break ;
case 38 : statusValue = currentStatus . testOutputs ; break ; // testEnabled(0), testActive(1)
case 39 : statusValue = currentStatus . O2_2 ; break ; //O2
case 40 : statusValue = currentStatus . baro ; break ; //Barometer value
case 41 : statusValue = lowByte ( currentStatus . canin [ 0 ] ) ; break ;
case 42 : statusValue = highByte ( currentStatus . canin [ 0 ] ) ; break ;
case 43 : statusValue = lowByte ( currentStatus . canin [ 1 ] ) ; break ;
case 44 : statusValue = highByte ( currentStatus . canin [ 1 ] ) ; break ;
case 45 : statusValue = lowByte ( currentStatus . canin [ 2 ] ) ; break ;
case 46 : statusValue = highByte ( currentStatus . canin [ 2 ] ) ; break ;
case 47 : statusValue = lowByte ( currentStatus . canin [ 3 ] ) ; break ;
case 48 : statusValue = highByte ( currentStatus . canin [ 3 ] ) ; break ;
case 49 : statusValue = lowByte ( currentStatus . canin [ 4 ] ) ; break ;
case 50 : statusValue = highByte ( currentStatus . canin [ 4 ] ) ; break ;
case 51 : statusValue = lowByte ( currentStatus . canin [ 5 ] ) ; break ;
case 52 : statusValue = highByte ( currentStatus . canin [ 5 ] ) ; break ;
case 53 : statusValue = lowByte ( currentStatus . canin [ 6 ] ) ; break ;
case 54 : statusValue = highByte ( currentStatus . canin [ 6 ] ) ; break ;
case 55 : statusValue = lowByte ( currentStatus . canin [ 7 ] ) ; break ;
case 56 : statusValue = highByte ( currentStatus . canin [ 7 ] ) ; break ;
case 57 : statusValue = lowByte ( currentStatus . canin [ 8 ] ) ; break ;
case 58 : statusValue = highByte ( currentStatus . canin [ 8 ] ) ; break ;
case 59 : statusValue = lowByte ( currentStatus . canin [ 9 ] ) ; break ;
case 60 : statusValue = highByte ( currentStatus . canin [ 9 ] ) ; break ;
case 61 : statusValue = lowByte ( currentStatus . canin [ 10 ] ) ; break ;
case 62 : statusValue = highByte ( currentStatus . canin [ 10 ] ) ; break ;
case 63 : statusValue = lowByte ( currentStatus . canin [ 11 ] ) ; break ;
case 64 : statusValue = highByte ( currentStatus . canin [ 11 ] ) ; break ;
case 65 : statusValue = lowByte ( currentStatus . canin [ 12 ] ) ; break ;
case 66 : statusValue = highByte ( currentStatus . canin [ 12 ] ) ; break ;
case 67 : statusValue = lowByte ( currentStatus . canin [ 13 ] ) ; break ;
case 68 : statusValue = highByte ( currentStatus . canin [ 13 ] ) ; break ;
case 69 : statusValue = lowByte ( currentStatus . canin [ 14 ] ) ; break ;
case 70 : statusValue = highByte ( currentStatus . canin [ 14 ] ) ; break ;
case 71 : statusValue = lowByte ( currentStatus . canin [ 15 ] ) ; break ;
case 72 : statusValue = highByte ( currentStatus . canin [ 15 ] ) ; break ;
case 73 : statusValue = currentStatus . tpsADC ; break ;
case 74 : statusValue = getNextError ( ) ; break ; // errorNum (0:1), currentError(2:7)
case 75 : statusValue = currentStatus . launchCorrection ; break ;
case 76 : statusValue = lowByte ( currentStatus . PW2 ) ; break ; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
case 77 : statusValue = highByte ( currentStatus . PW2 ) ; break ; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
case 78 : statusValue = lowByte ( currentStatus . PW3 ) ; break ; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
case 79 : statusValue = highByte ( currentStatus . PW3 ) ; break ; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
case 80 : statusValue = lowByte ( currentStatus . PW4 ) ; break ; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
case 81 : statusValue = highByte ( currentStatus . PW4 ) ; break ; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
case 82 : statusValue = currentStatus . status3 ; break ; // resentLockOn(0), nitrousOn(1), fuel2Active(2), vssRefresh(3), halfSync(4), nSquirts(6:7)
case 83 : statusValue = currentStatus . engineProtectStatus ; break ; //RPM(0), MAP(1), OIL(2), AFR(3), Unused(4:7)
case 84 : statusValue = lowByte ( currentStatus . fuelLoad ) ; break ;
case 85 : statusValue = highByte ( currentStatus . fuelLoad ) ; break ;
case 86 : statusValue = lowByte ( currentStatus . ignLoad ) ; break ;
case 87 : statusValue = highByte ( currentStatus . ignLoad ) ; break ;
case 88 : statusValue = lowByte ( currentStatus . injAngle ) ; break ;
case 89 : statusValue = highByte ( currentStatus . injAngle ) ; break ;
case 90 : statusValue = currentStatus . idleLoad ; break ;
case 91 : statusValue = currentStatus . CLIdleTarget ; break ; //closed loop idle target
case 92 : statusValue = ( uint8_t ) ( currentStatus . mapDOT / 10 ) ; break ; //rate of change of the map
case 93 : statusValue = ( int8_t ) currentStatus . vvt1Angle ; break ;
case 94 : statusValue = currentStatus . vvt1TargetAngle ; break ;
case 95 : statusValue = currentStatus . vvt1Duty ; break ;
case 96 : statusValue = lowByte ( currentStatus . flexBoostCorrection ) ; break ;
case 97 : statusValue = highByte ( currentStatus . flexBoostCorrection ) ; break ;
case 98 : statusValue = currentStatus . baroCorrection ; break ;
case 99 : statusValue = currentStatus . ASEValue ; break ; //Current ASE (%)
case 100 : statusValue = lowByte ( currentStatus . vss ) ; break ; //speed reading from the speed sensor
case 101 : statusValue = highByte ( currentStatus . vss ) ; break ;
case 102 : statusValue = currentStatus . gear ; break ;
case 103 : statusValue = currentStatus . fuelPressure ; break ;
case 104 : statusValue = currentStatus . oilPressure ; break ;
case 105 : statusValue = currentStatus . wmiPW ; break ;
case 106 : statusValue = currentStatus . status4 ; break ; // wmiEmptyBit(0), vvt1Error(1), vvt2Error(2), fanStatus(3), UnusedBits(4:7)
case 107 : statusValue = ( int8_t ) currentStatus . vvt2Angle ; break ;
case 108 : statusValue = currentStatus . vvt2TargetAngle ; break ;
case 109 : statusValue = currentStatus . vvt2Duty ; break ;
case 110 : statusValue = currentStatus . outputsStatus ; break ;
case 111 : statusValue = ( byte ) ( currentStatus . fuelTemp + CALIBRATION_TEMPERATURE_OFFSET ) ; break ; //Fuel temperature from flex sensor
case 112 : statusValue = currentStatus . fuelTempCorrection ; break ; //Fuel temperature Correction (%)
case 113 : statusValue = currentStatus . VE1 ; break ; //VE 1 (%)
case 114 : statusValue = currentStatus . VE2 ; break ; //VE 2 (%)
case 115 : statusValue = currentStatus . advance1 ; break ; //advance 1
case 116 : statusValue = currentStatus . advance2 ; break ; //advance 2
case 117 : statusValue = currentStatus . nitrous_status ; break ;
case 118 : statusValue = currentStatus . TS_SD_Status ; break ; //SD card status
case 119 : statusValue = lowByte ( currentStatus . EMAP ) ; break ; //2 bytes for EMAP
case 120 : statusValue = highByte ( currentStatus . EMAP ) ; break ;
case 121 : statusValue = currentStatus . fanDuty ; break ;
case 122 : statusValue = currentStatus . airConStatus ; break ;
}
return statusValue ;
}
2021-10-12 17:53:46 -07:00
/**
* Searches the log 2 byte array to determine whether a given index is a regular single byte or a 2 byte field
* Uses a boundless binary search for improved performance , but requires the fsIntIndex to remain in order
2022-01-04 21:41:12 -08:00
*
2021-10-12 17:53:46 -07:00
* @ param key - Index in the log array to check
* @ return True if the index is a 2 byte log field . False if it is a single byte
*/
bool is2ByteEntry ( uint8_t key )
{
2023-10-05 21:07:12 -07:00
// This array indicates which index values from the log are 2 byte values
// This array MUST remain in ascending order
// !!!! WARNING: If any value above 255 is required in this array, changes MUST be made to is2ByteEntry() function !!!!
static constexpr byte PROGMEM fsIntIndex [ ] = { 4 , 14 , 17 , 22 , 26 , 28 , 33 , 42 , 44 , 46 , 48 , 50 , 52 , 54 , 56 , 58 , 60 , 62 , 64 , 66 , 68 , 70 , 72 , 76 , 78 , 80 , 82 , 86 , 88 , 90 , 93 , 95 , 99 , 104 , 111 , 121 , 125 } ;
2021-10-12 17:53:46 -07:00
2023-10-05 21:07:12 -07:00
unsigned int bot = 0U ;
unsigned int mid = _countof ( fsIntIndex ) ;
2021-10-12 17:53:46 -07:00
2023-10-05 21:07:12 -07:00
while ( mid > 1U )
{
if ( key > = pgm_read_byte ( & fsIntIndex [ bot + mid / 2U ] ) )
2021-10-12 17:53:46 -07:00
{
2023-10-05 21:07:12 -07:00
bot + = mid + + / 2U ;
2021-10-12 17:53:46 -07:00
}
2023-10-05 21:07:12 -07:00
mid / = 2U ;
2021-10-12 17:53:46 -07:00
}
2023-10-05 21:07:12 -07:00
return key = = pgm_read_byte ( & fsIntIndex [ bot ] ) ;
2023-02-20 17:55:54 -08:00
}
void startToothLogger ( void )
{
currentStatus . toothLogEnabled = true ;
2023-10-05 21:07:12 -07:00
currentStatus . compositeTriggerUsed = 0U ; //Safety first (Should never be required)
2023-02-20 17:55:54 -08:00
BIT_CLEAR ( currentStatus . status1 , BIT_STATUS1_TOOTHLOG1READY ) ;
2023-10-05 21:07:12 -07:00
toothHistoryIndex = 0U ;
2023-02-20 17:55:54 -08:00
//Disconnect the standard interrupt and add the logger version
detachInterrupt ( digitalPinToInterrupt ( pinTrigger ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger ) , loggerPrimaryISR , CHANGE ) ;
2023-05-16 18:25:50 -07:00
if ( VSS_USES_RPM2 ( ) ! = true )
{
detachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) , loggerSecondaryISR , CHANGE ) ;
}
2023-02-20 17:55:54 -08:00
}
void stopToothLogger ( void )
{
currentStatus . toothLogEnabled = false ;
//Disconnect the logger interrupts and attach the normal ones
detachInterrupt ( digitalPinToInterrupt ( pinTrigger ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger ) , triggerHandler , primaryTriggerEdge ) ;
2023-05-16 18:25:50 -07:00
if ( VSS_USES_RPM2 ( ) ! = true )
{
detachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) , triggerSecondaryHandler , secondaryTriggerEdge ) ;
}
2023-02-20 17:55:54 -08:00
}
void startCompositeLogger ( void )
{
2023-10-05 21:07:12 -07:00
currentStatus . compositeTriggerUsed = 2U ;
2023-02-20 17:55:54 -08:00
currentStatus . toothLogEnabled = false ; //Safety first (Should never be required)
BIT_CLEAR ( currentStatus . status1 , BIT_STATUS1_TOOTHLOG1READY ) ;
2023-10-05 21:07:12 -07:00
toothHistoryIndex = 0U ;
2023-02-20 17:55:54 -08:00
//Disconnect the standard interrupt and add the logger version
detachInterrupt ( digitalPinToInterrupt ( pinTrigger ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger ) , loggerPrimaryISR , CHANGE ) ;
2023-05-17 23:06:16 -07:00
if ( ( VSS_USES_RPM2 ( ) ! = true ) & & ( FLEX_USES_RPM2 ( ) ! = true ) )
2023-05-16 18:25:50 -07:00
{
detachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) , loggerSecondaryISR , CHANGE ) ;
}
2023-02-20 17:55:54 -08:00
}
void stopCompositeLogger ( void )
{
2023-10-05 21:07:12 -07:00
currentStatus . compositeTriggerUsed = 0U ;
2023-02-20 17:55:54 -08:00
//Disconnect the logger interrupts and attach the normal ones
detachInterrupt ( digitalPinToInterrupt ( pinTrigger ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger ) , triggerHandler , primaryTriggerEdge ) ;
2023-05-17 23:06:16 -07:00
if ( ( VSS_USES_RPM2 ( ) ! = true ) & & ( FLEX_USES_RPM2 ( ) ! = true ) )
2023-05-16 18:25:50 -07:00
{
detachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) , triggerSecondaryHandler , secondaryTriggerEdge ) ;
}
2023-02-20 17:55:54 -08:00
}
2023-05-14 21:15:46 -07:00
void startCompositeLoggerTertiary ( void )
{
2023-10-05 21:07:12 -07:00
currentStatus . compositeTriggerUsed = 3U ;
2023-05-14 21:15:46 -07:00
currentStatus . toothLogEnabled = false ; //Safety first (Should never be required)
BIT_CLEAR ( currentStatus . status1 , BIT_STATUS1_TOOTHLOG1READY ) ;
2023-10-05 21:07:12 -07:00
toothHistoryIndex = 0U ;
2023-05-14 21:15:46 -07:00
//Disconnect the standard interrupt and add the logger version
detachInterrupt ( digitalPinToInterrupt ( pinTrigger ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger ) , loggerPrimaryISR , CHANGE ) ;
detachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) , loggerTertiaryISR , CHANGE ) ;
}
void stopCompositeLoggerTertiary ( void )
{
currentStatus . compositeTriggerUsed = 0 ;
//Disconnect the logger interrupts and attach the normal ones
detachInterrupt ( digitalPinToInterrupt ( pinTrigger ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger ) , triggerHandler , primaryTriggerEdge ) ;
detachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) , triggerTertiaryHandler , tertiaryTriggerEdge ) ;
}
void startCompositeLoggerCams ( void )
{
currentStatus . compositeTriggerUsed = 4 ;
currentStatus . toothLogEnabled = false ; //Safety first (Should never be required)
BIT_CLEAR ( currentStatus . status1 , BIT_STATUS1_TOOTHLOG1READY ) ;
toothHistoryIndex = 0 ;
//Disconnect the standard interrupt and add the logger version
2023-05-17 23:06:16 -07:00
if ( ( VSS_USES_RPM2 ( ) ! = true ) & & ( FLEX_USES_RPM2 ( ) ! = true ) )
2023-05-16 18:25:50 -07:00
{
detachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) , loggerSecondaryISR , CHANGE ) ;
}
2023-05-14 21:15:46 -07:00
detachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) , loggerTertiaryISR , CHANGE ) ;
}
void stopCompositeLoggerCams ( void )
{
currentStatus . compositeTriggerUsed = false ;
//Disconnect the logger interrupts and attach the normal ones
2023-05-17 23:06:16 -07:00
if ( ( VSS_USES_RPM2 ( ) ! = true ) & & ( FLEX_USES_RPM2 ( ) ! = true ) )
2023-05-16 18:25:50 -07:00
{
detachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger2 ) , triggerSecondaryHandler , secondaryTriggerEdge ) ;
}
2023-05-14 21:15:46 -07:00
detachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) ) ;
attachInterrupt ( digitalPinToInterrupt ( pinTrigger3 ) , triggerTertiaryHandler , tertiaryTriggerEdge ) ;
}