Speeduino
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
conversionFactor< TUser, TRaw > Struct Template Reference

Scale and translate signed/unsigned values to convert between "raw" & "user" values. More...

#include <units.h>

Public Member Functions

constexpr TUser toUser (TRaw raw) const
 Convert a value from raw page value to user value.
 
constexpr TRaw toRaw (TUser user) const
 Convert a value from a user value to raw page value.
 

Public Attributes

uint16_t scale
 Scale factor, must be >0.
 
int16_t translate
 Translation - can be negative.
 

Detailed Description

template<typename TUser, typename TRaw>
struct conversionFactor< TUser, TRaw >

Scale and translate signed/unsigned values to convert between "raw" & "user" values.

Terminology:

The scaling and translation values are used as follows

Typically these will be the same scale and translate values as specified in the TunerStudio configuration file (ini)

Rationale: It encapsulates all conversion factors and operations in one place

Background: For memory footprint reasons, many tune parameters are stored using a smaller type than the full numeric range requires. E.g.

See section 4.4.7, Scale and Translate, of the TunerStudio ECU definition manual.

Template Parameters
TUserThe type of a user value. E.g. int8_t
TRawThe type of a raw value. E.g. uint8_t

Member Function Documentation

◆ toRaw()

template<typename TUser , typename TRaw >
constexpr TRaw conversionFactor< TUser, TRaw >::toRaw ( TUser  user) const
inlineconstexpr

Convert a value from a user value to raw page value.

It's the callers responsibility to make sure the converted value fits into the destination type

Here is the call graph for this function:

◆ toUser()

template<typename TUser , typename TRaw >
constexpr TUser conversionFactor< TUser, TRaw >::toUser ( TRaw  raw) const
inlineconstexpr

Convert a value from raw page value to user value.

It's the callers responsibility to make sure the converted value fits into the destination type after translation & scaling

Here is the call graph for this function:

Member Data Documentation

◆ scale

Scale factor, must be >0.

◆ translate

Translation - can be negative.


The documentation for this struct was generated from the following file: