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... | |
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
#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.
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().
|
inlinestatic |
Converts the scaled up temperature32 value back to neutral value.
[in] | temperature32 | Input temperature32 value. |
Definition at line 99 of file light_ctl_utils.h.
References SCALE_DOWN, and T32_SCALE_FACTOR.
|
inlinestatic |
Converts netural temperature value to internal, scaled up, temperature32 value.
[in] | temperature | Input temperature value. |
Definition at line 110 of file light_ctl_utils.h.
References SCALE_UP, and T32_SCALE_FACTOR.
|
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.
[in] | level | Input Generic Level state value. |
[in] | t32_min | Scaled up value of minimum CTL Temperature Range. |
[in] | t32_max | Scaled up value of maximum CTL Temperature Range. |
Definition at line 125 of file light_ctl_utils.h.
References SCALE_DOWN, and T32_SCALE_FACTOR.
|
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.
[in] | temperature32 | Input temperature32 value. |
[in] | t32_min | Scaled up value of minimum CTL Temperature Range. |
[in] | t32_max | Scaled up value of maximum CTL Temperature Range. |
Definition at line 141 of file light_ctl_utils.h.
References SCALE_UP, and T32_SCALE_FACTOR.
|
inlinestatic |
Restricts the given temperature32 value to given minimum and maximum (scaled up) range values.
[in] | temperature32 | Input temperature32 value. |
[in] | t32_min | Scaled up value of minimum CTL Temperature Range. |
[in] | t32_max | Scaled up value of maximum CTL Temperature Range. |
Definition at line 178 of file light_ctl_utils.h.