nRF5 SDK for Mesh v5.0.0
Macros | Functions
Utility functions for the Light CTL model

These utility functions are used to handle internal 32 bit representation (temperature32) of Light CTL Temperature state values. More...

Macros

#define T32_SCALE_FACTOR   (65535LL)
 Scaling factor used by this module to scale given temperature value so as not to loose precision. More...
 
#define SCALE_DOWN(_input, _scale_factor)   ((_input)/(_scale_factor))
 Macro for performing scaling down.
 
#define SCALE_UP(_input, _scale_factor)   ((_input)*(_scale_factor))
 Macro for performing scaling up.
 

Functions

static uint16_t light_ctl_utils_temperature32_to_temperature (uint32_t temperature32)
 Converts the scaled up temperature32 value back to neutral value. More...
 
static uint32_t light_ctl_utils_temperature_to_temperature32 (uint16_t temperature)
 Converts netural temperature value to internal, scaled up, temperature32 value. More...
 
static uint32_t light_ctl_utils_level_to_temperature32 (int16_t level, uint32_t t32_min, uint32_t t32_max)
 Converts Generic Level state to internal, scaled up, temperature32 value. More...
 
static int16_t light_ctl_utils_temperature32_to_level (uint32_t temperature32, uint32_t t32_min, uint32_t t32_max)
 Converts internal, scaled up, temperature32 value to Generic Level state. More...
 
static int32_t light_ctl_utils_level_delta_to_temperature_delta (int32_t generic_level_delta, uint16_t t_min, uint16_t t_max)
 Converts Generic Level Delta value to internal temperature value.
 
static uint32_t light_ctl_utils_temperature32_range_restrict (uint32_t temperature32, uint32_t t32_min, uint32_t t32_max)
 Restricts the given temperature32 value to given minimum and maximum (scaled up) range values. More...
 

Detailed Description

These utility functions are used to handle internal 32 bit representation (temperature32) of Light CTL Temperature state values.

Temperature32 is a temperature value that is multiplied by 65536 (T32_SCALE_FACTOR). This allows us to keep around a more precise values that will convert back to level without integer division round off errors.

Bluetooth Mesh Model Specification (MshMDLv1.0.1) section 6.1.3.1.1 Binding with the Generic Level state: the formulae are: temperature = t_min + (generic_level + 32768) * (t_max - t_min) / 65535 generic_level = (temperature - t_min) * 65535 / (t_max - t_min) - 32768 So to avoid dividing by 65535 to compute temperature, we multiply the 1st equation by 65535 and get a formula of: temperature32 = 65535 * t_min + (generic_level + 32768) * (t_max - t_min) and reverse that to get a generic_level of: generic_level = (temperature32 - t_min * 65535) / (t_max - t_min) - 32768 But, we also are storing t_max and t_min as temperature32 values as well (abbreviated as t32_max and t32_min), so the final form of the formulae is: temperature32 = t32_min + (generic_level + 32768) * (t32_max - t32_min)/65535 generic_level = (((temperature32 - t32_min) * 65535)/(t32_max - t32_min)) - 32768

For a delta, we don't add in t_min (that's an offset to get an absolute temperature value into the non-prohibited range), and we don't add in the 32768, since that is designed to convert a signed int into unsigned space - but we need to keep any negative delta value. So the formula is then: temperature_delta = generic_level_delta * (t_max - t_min) / 65535

Note
These utility functions assume that the input parameters are sanitized and within the valid limits.

Macro Definition Documentation

◆ T32_SCALE_FACTOR

#define T32_SCALE_FACTOR   (65535LL)

Scaling factor used by this module to scale given temperature value so as not to loose precision.

This factor must be 65535, for proper simplification of level<->temperature conversion equations that ensure min/max values convert correctly back and forth after scaling.

Warning
Do not change this value.

Definition at line 85 of file light_ctl_utils.h.

Referenced by light_ctl_utils_level_to_temperature32(), light_ctl_utils_temperature32_to_level(), light_ctl_utils_temperature32_to_temperature(), and light_ctl_utils_temperature_to_temperature32().

Function Documentation

◆ light_ctl_utils_temperature32_to_temperature()

static uint16_t light_ctl_utils_temperature32_to_temperature ( uint32_t  temperature32)
inlinestatic

Converts the scaled up temperature32 value back to neutral value.

Parameters
[in]temperature32Input temperature32 value.
Returns
The temperature value.

Definition at line 99 of file light_ctl_utils.h.

References SCALE_DOWN, and T32_SCALE_FACTOR.

◆ light_ctl_utils_temperature_to_temperature32()

static uint32_t light_ctl_utils_temperature_to_temperature32 ( uint16_t  temperature)
inlinestatic

Converts netural temperature value to internal, scaled up, temperature32 value.

Parameters
[in]temperatureInput temperature value.
Returns
The temperature32 value.

Definition at line 110 of file light_ctl_utils.h.

References SCALE_UP, and T32_SCALE_FACTOR.

◆ light_ctl_utils_level_to_temperature32()

static uint32_t light_ctl_utils_level_to_temperature32 ( int16_t  level,
uint32_t  t32_min,
uint32_t  t32_max 
)
inlinestatic

Converts Generic Level state to internal, scaled up, temperature32 value.

See Bluetooth Mesh Model Specification (MshMDLv1.0.1) section 6.1.3.1.1.

Parameters
[in]levelInput Generic Level state value.
[in]t32_minScaled up value of minimum CTL Temperature Range.
[in]t32_maxScaled up value of maximum CTL Temperature Range.
Returns
The temperature32 value.

Definition at line 125 of file light_ctl_utils.h.

References SCALE_DOWN, and T32_SCALE_FACTOR.

◆ light_ctl_utils_temperature32_to_level()

static int16_t light_ctl_utils_temperature32_to_level ( uint32_t  temperature32,
uint32_t  t32_min,
uint32_t  t32_max 
)
inlinestatic

Converts internal, scaled up, temperature32 value to Generic Level state.

See Bluetooth Mesh Model Specification (MshMDLv1.0.1) section 6.1.3.1.1.

Parameters
[in]temperature32Input temperature32 value.
[in]t32_minScaled up value of minimum CTL Temperature Range.
[in]t32_maxScaled up value of maximum CTL Temperature Range.
Returns
The Generic Level state value.

Definition at line 141 of file light_ctl_utils.h.

References SCALE_UP, and T32_SCALE_FACTOR.

◆ light_ctl_utils_temperature32_range_restrict()

static uint32_t light_ctl_utils_temperature32_range_restrict ( uint32_t  temperature32,
uint32_t  t32_min,
uint32_t  t32_max 
)
inlinestatic

Restricts the given temperature32 value to given minimum and maximum (scaled up) range values.

Parameters
[in]temperature32Input temperature32 value.
[in]t32_minScaled up value of minimum CTL Temperature Range.
[in]t32_maxScaled up value of maximum CTL Temperature Range.
Returns
The temperature32 value restricted to given range

Definition at line 178 of file light_ctl_utils.h.


Documentation feedback | Developer Zone | Subscribe | Updated