Speeduino
Loading...
Searching...
No Matches
Functions | Variables
sensors.cpp File Reference
#include <SimplyAtomic.h>
#include "sensors.h"
#include "crankMaths.h"
#include "globals.h"
#include "maths.h"
#include "storage.h"
#include "comms.h"
#include "idle.h"
#include "corrections.h"
#include "pages.h"
#include "decoders.h"
#include "auxiliaries.h"
#include "utilities.h"
#include "unit_testing.h"
#include "sensors_map_structs.h"

Functions

TESTABLE_INLINE_STATIC int16_t fastMap10Bit (uint16_t value, int16_t rangeMin, int16_t rangeMax)
 A specialist function to map a value in the range [0, 1023] (I.e. 10-bit) to a different range.
 
static uint16_t readAnalogPin (uint8_t pin)
 
static uint16_t readAnalogSensor (uint8_t pin)
 
static uint16_t readMAPSensor (uint8_t pin)
 
void initialiseADC (void)
 
TESTABLE_INLINE_STATIC bool instanteneousMAPReading (void)
 
static bool cycleAverageMAPReadingAccumulate (map_cycle_average_t &cycle_average, const map_adc_readings_t &sensorReadings)
 
static void reset (const statuses &current, map_cycle_average_t &cycle_average, const map_adc_readings_t &sensorReadings)
 
static bool cycleAverageEndCycle (const statuses &current, map_cycle_average_t &cycle_average, map_adc_readings_t &sensorReadings)
 
static bool isCycleCurrent (const statuses &current, uint32_t cycleStartIndex)
 
static bool isCycleCurrent (const statuses &current, const map_cycle_average_t &cycle_avg)
 
TESTABLE_INLINE_STATIC bool canUseCycleAverage (const statuses &current, const config2 &page2)
 
TESTABLE_INLINE_STATIC bool cycleAverageMAPReading (const statuses &current, const config2 &page2, map_cycle_average_t &cycle_average, map_adc_readings_t &sensorReadings)
 
static bool cycleMinimumAccumulate (map_cycle_min_t &cycle_min, const map_adc_readings_t &sensorReadings)
 
static void reset (const statuses &current, map_cycle_min_t &cycle_min, const map_adc_readings_t &sensorReadings)
 
static bool cycleMinimumEndCycle (const statuses &current, map_cycle_min_t &cycle_min, map_adc_readings_t &sensorReadings)
 
static bool isCycleCurrent (const statuses &current, const map_cycle_min_t &cycle_min)
 
TESTABLE_INLINE_STATIC bool cycleMinimumMAPReading (const statuses &current, const config2 &page2, map_cycle_min_t &cycle_min, map_adc_readings_t &sensorReadings)
 
static bool eventAverageAccumulate (map_event_average_t &eventAverage, const map_adc_readings_t &sensorReadings)
 
static bool isIgnitionEventValid (const map_event_average_t &eventAverage)
 
static void reset (map_event_average_t &eventAverage, const map_adc_readings_t &sensorReadings)
 
static bool eventAverageEndEvent (map_event_average_t &eventAverage, map_adc_readings_t &sensorReadings)
 
static bool isIgnitionEventCurrent (const map_event_average_t &eventAverage)
 
TESTABLE_INLINE_STATIC bool canUseEventAverage (const statuses &current, const config2 &page2)
 
TESTABLE_INLINE_STATIC bool eventAverageMAPReading (const statuses &current, const config2 &page2, map_event_average_t &eventAverage, map_adc_readings_t &sensorReadings)
 
static bool processMapReadings (const statuses &current, const config2 &page2, map_algorithm_t &state)
 
static bool isValidMapSensorReading (uint16_t reading)
 
TESTABLE_INLINE_STATIC uint16_t validateFilterMapSensorReading (uint16_t reading, uint8_t alpha, uint16_t prior)
 
static uint16_t readFilteredMapADC (uint8_t pin, uint8_t alpha, uint16_t prior)
 
static map_adc_readings_t readMapSensors (const map_adc_readings_t &previousReadings, const config4 &page4, bool useEMAP)
 
static void resetMAPLast (map_last_read_t &lastRead, uint16_t oldMAPValue)
 
static uint16_t mapADCToMAP (uint16_t mapADC, int8_t mapMin, uint16_t mapMax)
 
static void setMAPValuesFromReadings (const map_adc_readings_t &readings, const config2 &page2, bool useEMAP, statuses &current)
 
static void initialiseMAP (void)
 
void readMAP (void)
 
int16_t getMAPDelta (void)
 Get the MAP change between the last 2 readings.
 
uint32_t getMAPDeltaTime (void)
 Get the time in µS between the last 2 MAP readings.
 
void readTPS (bool useFilter)
 
void readCLT (bool useFilter)
 
void readIAT (void)
 
static bool isValidBaro (uint8_t baro)
 
static void setBaroFromSensorReading (uint16_t sensorReading)
 
static void setBaroFromMAP (void)
 
void readBaro (void)
 
static void initialiseBaro (void)
 
void initialiseMAPBaro (void)
 Initialize the MAP calculation & Baro values.
 
void readO2 (void)
 
void readO2_2 (void)
 
void readBat (void)
 
uint32_t vssGetPulseGap (uint8_t historyIndex)
 Returns the VSS pulse gap for a given history point.
 
uint16_t getSpeed (void)
 
byte getGear (void)
 
byte getFuelPressure (void)
 
byte getOilPressure (void)
 
uint8_t getAnalogKnock (void)
 
void flexPulse (void)
 
void knockPulse (void)
 
void vssPulse (void)
 The ISR function for VSS pulses.
 
uint16_t readAuxanalog (uint8_t analogPin)
 
uint16_t readAuxdigital (uint8_t digitalPin)
 

Variables

bool auxIsEnabled
 
static volatile uint32_t vssTimes [VSS_SAMPLES] = {0}
 
static volatile uint8_t vssIndex = 0U
 
volatile uint8_t flexCounter = 0U
 
static volatile uint32_t flexStartTime = 0UL
 
volatile uint32_t flexPulseWidth = 0U
 
static constexpr uint16_t VALID_MAP_MAX =1022U
 
static constexpr uint16_t VALID_MAP_MIN =2U
 
static map_algorithm_t mapAlgorithmState
 

Detailed Description

Read sensors with appropriate timing / scheduling.

Function Documentation

◆ canUseCycleAverage()

TESTABLE_INLINE_STATIC bool canUseCycleAverage ( const statuses current,
const config2 page2 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canUseEventAverage()

TESTABLE_INLINE_STATIC bool canUseEventAverage ( const statuses current,
const config2 page2 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycleAverageEndCycle()

static bool cycleAverageEndCycle ( const statuses current,
map_cycle_average_t cycle_average,
map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycleAverageMAPReading()

TESTABLE_INLINE_STATIC bool cycleAverageMAPReading ( const statuses current,
const config2 page2,
map_cycle_average_t cycle_average,
map_adc_readings_t sensorReadings 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycleAverageMAPReadingAccumulate()

static bool cycleAverageMAPReadingAccumulate ( map_cycle_average_t cycle_average,
const map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycleMinimumAccumulate()

static bool cycleMinimumAccumulate ( map_cycle_min_t cycle_min,
const map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycleMinimumEndCycle()

static bool cycleMinimumEndCycle ( const statuses current,
map_cycle_min_t cycle_min,
map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cycleMinimumMAPReading()

TESTABLE_INLINE_STATIC bool cycleMinimumMAPReading ( const statuses current,
const config2 page2,
map_cycle_min_t cycle_min,
map_adc_readings_t sensorReadings 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventAverageAccumulate()

static bool eventAverageAccumulate ( map_event_average_t eventAverage,
const map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventAverageEndEvent()

static bool eventAverageEndEvent ( map_event_average_t eventAverage,
map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventAverageMAPReading()

TESTABLE_INLINE_STATIC bool eventAverageMAPReading ( const statuses current,
const config2 page2,
map_event_average_t eventAverage,
map_adc_readings_t sensorReadings 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastMap10Bit()

TESTABLE_INLINE_STATIC int16_t fastMap10Bit ( uint16_t  value,
int16_t  rangeMin,
int16_t  rangeMax 
)

A specialist function to map a value in the range [0, 1023] (I.e. 10-bit) to a different range.

Mostly used for analog input voltage level to real world value conversions.

analogRead returns a number in the range [0, 1023], representing the pin input voltage from min to max (typically 0V - 5V) We need to convert that value to the real world value the sensor is reading (pressure, temperature etc.) If:

  • rangeMin is the real world value when the sensor is reading 0V
  • rangeMax is the real world measurement when the sensor is reading 5V
  • There is a linear relationship between voltage output and the real world value.

then this function will return the real world measurement (kPa, °C etc)

Parameters
valueValue to map (should be in range [0, 1023])
rangeMinMinimum of the output range
rangeMaxMaximum of the output range
Returns
int16_t
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flexPulse()

void flexPulse ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAnalogKnock()

uint8_t getAnalogKnock ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFuelPressure()

byte getFuelPressure ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGear()

byte getGear ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMAPDelta()

int16_t getMAPDelta ( void  )

Get the MAP change between the last 2 readings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMAPDeltaTime()

uint32_t getMAPDeltaTime ( void  )

Get the time in µS between the last 2 MAP readings.

Here is the caller graph for this function:

◆ getOilPressure()

byte getOilPressure ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpeed()

uint16_t getSpeed ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseADC()

void initialiseADC ( void  )

Init all ADC conversions by setting resolutions, etc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseBaro()

static void initialiseBaro ( void  )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseMAP()

static void initialiseMAP ( void  )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseMAPBaro()

void initialiseMAPBaro ( void  )

Initialize the MAP calculation & Baro values.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ instanteneousMAPReading()

TESTABLE_INLINE_STATIC bool instanteneousMAPReading ( void  )
Here is the caller graph for this function:

◆ isCycleCurrent() [1/3]

static bool isCycleCurrent ( const statuses current,
const map_cycle_average_t cycle_avg 
)
inlinestatic
Here is the call graph for this function:

◆ isCycleCurrent() [2/3]

static bool isCycleCurrent ( const statuses current,
const map_cycle_min_t cycle_min 
)
inlinestatic
Here is the call graph for this function:

◆ isCycleCurrent() [3/3]

static bool isCycleCurrent ( const statuses current,
uint32_t  cycleStartIndex 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isIgnitionEventCurrent()

static bool isIgnitionEventCurrent ( const map_event_average_t eventAverage)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isIgnitionEventValid()

static bool isIgnitionEventValid ( const map_event_average_t eventAverage)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValidBaro()

static bool isValidBaro ( uint8_t  baro)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValidMapSensorReading()

static bool isValidMapSensorReading ( uint16_t  reading)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ knockPulse()

void knockPulse ( void  )
Here is the caller graph for this function:

◆ mapADCToMAP()

static uint16_t mapADCToMAP ( uint16_t  mapADC,
int8_t  mapMin,
uint16_t  mapMax 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processMapReadings()

static bool processMapReadings ( const statuses current,
const config2 page2,
map_algorithm_t state 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAnalogPin()

static uint16_t readAnalogPin ( uint8_t  pin)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAnalogSensor()

static uint16_t readAnalogSensor ( uint8_t  pin)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAuxanalog()

uint16_t readAuxanalog ( uint8_t  analogPin)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAuxdigital()

uint16_t readAuxdigital ( uint8_t  digitalPin)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readBaro()

void readBaro ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readBat()

void readBat ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readCLT()

void readCLT ( bool  useFilter)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFilteredMapADC()

static uint16_t readFilteredMapADC ( uint8_t  pin,
uint8_t  alpha,
uint16_t  prior 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readIAT()

void readIAT ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readMAP()

void readMAP ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readMAPSensor()

static uint16_t readMAPSensor ( uint8_t  pin)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readMapSensors()

static map_adc_readings_t readMapSensors ( const map_adc_readings_t previousReadings,
const config4 page4,
bool  useEMAP 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readO2()

void readO2 ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readO2_2()

void readO2_2 ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readTPS()

void readTPS ( bool  useFilter)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset() [1/3]

static void reset ( const statuses current,
map_cycle_average_t cycle_average,
const map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset() [2/3]

static void reset ( const statuses current,
map_cycle_min_t cycle_min,
const map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:

◆ reset() [3/3]

static void reset ( map_event_average_t eventAverage,
const map_adc_readings_t sensorReadings 
)
inlinestatic
Here is the call graph for this function:

◆ resetMAPLast()

static void resetMAPLast ( map_last_read_t lastRead,
uint16_t  oldMAPValue 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBaroFromMAP()

static void setBaroFromMAP ( void  )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBaroFromSensorReading()

static void setBaroFromSensorReading ( uint16_t  sensorReading)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMAPValuesFromReadings()

static void setMAPValuesFromReadings ( const map_adc_readings_t readings,
const config2 page2,
bool  useEMAP,
statuses current 
)
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateFilterMapSensorReading()

TESTABLE_INLINE_STATIC uint16_t validateFilterMapSensorReading ( uint16_t  reading,
uint8_t  alpha,
uint16_t  prior 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vssGetPulseGap()

uint32_t vssGetPulseGap ( uint8_t  historyIndex)

Returns the VSS pulse gap for a given history point.

Parameters
historyIndexThe gap number that is wanted. EG: historyIndex = 0 = Latest entry historyIndex = 1 = 2nd entry entry
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vssPulse()

void vssPulse ( void  )

The ISR function for VSS pulses.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ auxIsEnabled

bool auxIsEnabled

◆ flexCounter

volatile uint8_t flexCounter = 0U

◆ flexPulseWidth

volatile uint32_t flexPulseWidth = 0U

◆ flexStartTime

volatile uint32_t flexStartTime = 0UL
static

◆ mapAlgorithmState

map_algorithm_t mapAlgorithmState
static

◆ VALID_MAP_MAX

constexpr uint16_t VALID_MAP_MAX =1022U
staticconstexpr

◆ VALID_MAP_MIN

constexpr uint16_t VALID_MAP_MIN =2U
staticconstexpr

◆ vssIndex

volatile uint8_t vssIndex = 0U
static

◆ vssTimes

volatile uint32_t vssTimes[VSS_SAMPLES] = {0}
static