Speeduino
Loading...
Searching...
No Matches
Classes | Functions
units.h File Reference

Integer conversions using scale & translate. More...

#include <stdint.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  conversionFactor< TUser, TRaw >
 Scale and translate signed/unsigned values to convert between "raw" & "user" values. More...
 

Functions

static constexpr uint8_t temperatureAddOffset (int16_t temp)
 Convert from a user temperature (-40, 215) to storage (0, 255)
 
static constexpr int16_t temperatureRemoveOffset (uint8_t temp)
 Convert from a storage temperature (0, 255) to user (-40, 215)
 

Variables

Conversion factors
Note
Since these are all constexpr, they should be zero overhead in time & space (unless we take the address of one of them)
static constexpr conversionFactor< uint16_t, uint8_tRPM_COARSE = { .scale=100U, .translate=0U }
 RPM stored as RPM/100. E.g. 2700 -> 27 -> 2700.
 
static constexpr conversionFactor< uint16_t, uint8_tRPM_MEDIUM = { .scale=10U, .translate=0U }
 RPM stored as RPM/10. E.g. 2700 -> 270 -> 2700.
 
static constexpr conversionFactor< uint16_t, uint8_tRPM_FINE = { .scale=5U, .translate=0U }
 RPM stored as RPM/5. E.g. 1300->260->1300.
 
static constexpr conversionFactor< uint32_t, uint8_tTIME_TENTH_MILLIS = { .scale=10000U, .translate=0U }
 Time values stored in 1/10th milliseconds I.e ms/10.
 
static constexpr conversionFactor< uint16_t, uint8_tTIME_TWENTY_MILLIS = { .scale=5U, .translate=0U }
 Time values stored in 20 milliseconds.
 
static constexpr conversionFactor< uint16_t, uint8_tTIME_TEN_MILLIS = { .scale=100U, .translate=0U }
 Time values stored in 10 milliseconds.
 
static constexpr conversionFactor< uint16_t, uint8_tMAP = { .scale=2U, .translate=0U }
 MAP values: kpa.
 
static constexpr conversionFactor< int16_t, uint8_tMAP_DOT = { .scale=10U, .translate=0U }
 MAP rate of change: kpa/s

 
static constexpr conversionFactor< int16_t, uint8_tTPS_DOT = { .scale=10U, .translate=0U }
 TPS rate of change: %/s.
 
static constexpr conversionFactor< uint16_t, uint8_tCRANKING_ENRICHMENT = { .scale=5U, .translate=0U }
 Cranking enrichment values range from 0% to 1275%.
 
static constexpr conversionFactor< int8_t, uint8_tIGNITION_ADVANCE_LARGE = { .scale=1U, .translate=-40 }
 Ignition values from the main spark table are offset 40 degrees downwards to allow for negative spark timing.
 
static constexpr conversionFactor< int8_t, uint8_tIGNITION_ADVANCE_SMALL = { .scale=1U, .translate=-15 }
 Ignition advance adjustments can use a smaller offset.
 
static constexpr conversionFactor< int16_t, uint8_tTEMPERATURE = { .scale=1U, .translate=-40 }
 All temperature measurements are stored offset by 40 degrees, to represent temperature ranges from -40 to 215.
 

Detailed Description

Integer conversions using scale & translate.

Function Documentation

◆ temperatureAddOffset()

static constexpr uint8_t temperatureAddOffset ( int16_t  temp)
inlinestaticconstexpr

Convert from a user temperature (-40, 215) to storage (0, 255)

This is done often enough to warrant wrapping toRaw

Parameters
tempWorking temperature (-40, 215)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ temperatureRemoveOffset()

static constexpr int16_t temperatureRemoveOffset ( uint8_t  temp)
inlinestaticconstexpr

Convert from a storage temperature (0, 255) to user (-40, 215)

This is done often enough to warrant wrapping toUser

Parameters
tempStorage temperature (0, 255)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ CRANKING_ENRICHMENT

constexpr conversionFactor<uint16_t, uint8_t> CRANKING_ENRICHMENT = { .scale=5U, .translate=0U }
staticconstexpr

Cranking enrichment values range from 0% to 1275%.

◆ IGNITION_ADVANCE_LARGE

constexpr conversionFactor<int8_t, uint8_t> IGNITION_ADVANCE_LARGE = { .scale=1U, .translate=-40 }
staticconstexpr

Ignition values from the main spark table are offset 40 degrees downwards to allow for negative spark timing.

◆ IGNITION_ADVANCE_SMALL

constexpr conversionFactor<int8_t, uint8_t> IGNITION_ADVANCE_SMALL = { .scale=1U, .translate=-15 }
staticconstexpr

Ignition advance adjustments can use a smaller offset.

◆ MAP

constexpr conversionFactor<uint16_t, uint8_t> MAP = { .scale=2U, .translate=0U }
staticconstexpr

MAP values: kpa.

◆ MAP_DOT

constexpr conversionFactor<int16_t, uint8_t> MAP_DOT = { .scale=10U, .translate=0U }
staticconstexpr

MAP rate of change: kpa/s

◆ RPM_COARSE

constexpr conversionFactor<uint16_t, uint8_t> RPM_COARSE = { .scale=100U, .translate=0U }
staticconstexpr

RPM stored as RPM/100. E.g. 2700 -> 27 -> 2700.

◆ RPM_FINE

constexpr conversionFactor<uint16_t, uint8_t> RPM_FINE = { .scale=5U, .translate=0U }
staticconstexpr

RPM stored as RPM/5. E.g. 1300->260->1300.

This limits the maximum value to 1275 RPM, but gives more precision than RPM_MEDIUM

◆ RPM_MEDIUM

constexpr conversionFactor<uint16_t, uint8_t> RPM_MEDIUM = { .scale=10U, .translate=0U }
staticconstexpr

RPM stored as RPM/10. E.g. 2700 -> 270 -> 2700.

This limits the maximum value to 2550 RPM, but gives more precision than RPM_COARSE

◆ TEMPERATURE

constexpr conversionFactor<int16_t, uint8_t> TEMPERATURE = { .scale=1U, .translate=-40 }
staticconstexpr

All temperature measurements are stored offset by 40 degrees, to represent temperature ranges from -40 to 215.

◆ TIME_TEN_MILLIS

constexpr conversionFactor<uint16_t, uint8_t> TIME_TEN_MILLIS = { .scale=100U, .translate=0U }
staticconstexpr

Time values stored in 10 milliseconds.

We convert to/from µS

◆ TIME_TENTH_MILLIS

constexpr conversionFactor<uint32_t, uint8_t> TIME_TENTH_MILLIS = { .scale=10000U, .translate=0U }
staticconstexpr

Time values stored in 1/10th milliseconds I.e ms/10.

We convert to/from µS

◆ TIME_TWENTY_MILLIS

constexpr conversionFactor<uint16_t, uint8_t> TIME_TWENTY_MILLIS = { .scale=5U, .translate=0U }
staticconstexpr

Time values stored in 20 milliseconds.

We convert to/from secs/0.1

◆ TPS_DOT

constexpr conversionFactor<int16_t, uint8_t> TPS_DOT = { .scale=10U, .translate=0U }
staticconstexpr

TPS rate of change: %/s.