nRF5 SDK for Mesh v5.0.0
light_lightness_utils.h
1 /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef LIGHT_LIGHTNESS_UTILS_H__
39 #define LIGHT_LIGHTNESS_UTILS_H__
40 
41 #include <stdint.h>
42 #include "utils.h"
43 #include "generic_level_common.h"
44 
60 static inline uint16_t light_lightness_utils_actual_to_linear(uint16_t ll_actual)
61 {
62  return CEIL_DIV((uint32_t)ll_actual * ll_actual, UINT16_MAX);
63 }
64 
74 static inline uint16_t light_lightness_utils_linear_to_actual(uint16_t ll_linear)
75 {
76  return uint_sqrt((uint32_t)ll_linear * UINT16_MAX);
77 }
78 
88 static inline int16_t light_lightness_utils_actual_to_generic_level(uint16_t ll_actual)
89 {
90  return ll_actual - GENERIC_LEVEL_MIN;
91 }
92 
102 static inline uint16_t light_lightness_utils_generic_level_to_actual(int16_t level)
103 {
104  return level + GENERIC_LEVEL_MIN;
105 }
106 
116 static inline uint8_t light_lightness_utils_actual_to_generic_onoff(uint16_t ll_actual)
117 {
118  return (ll_actual == 0 ? 0 : 1);
119 }
120 
132 static inline uint16_t light_lightness_utils_actual_to_range_restrict(uint16_t ll_actual,
133  uint16_t range_min,
134  uint16_t range_max)
135 {
136  return ll_actual != 0 ? MIN(MAX(ll_actual, range_min), range_max) : 0;
137 }
138 
140 #endif /* LIGHT_LIGHTNESS_UTILS_H__ */
static uint16_t light_lightness_utils_linear_to_actual(uint16_t ll_linear)
Convert the Light Lightness Linear state to the Light Lightness Actual state.
static uint16_t light_lightness_utils_actual_to_linear(uint16_t ll_actual)
Converts the Light Lightness Actual state to the Light Lightness Linear state.
static uint8_t light_lightness_utils_actual_to_generic_onoff(uint16_t ll_actual)
Convert the Light Lightness Actual state to the Generic OnOff state.
#define GENERIC_LEVEL_MIN
Generic Level state minimum value.
static uint16_t light_lightness_utils_actual_to_range_restrict(uint16_t ll_actual, uint16_t range_min, uint16_t range_max)
Convert the Light Lightness Actual state to the Generic OnOff state.
static uint16_t light_lightness_utils_generic_level_to_actual(int16_t level)
Convert the Generic Level state to the Light Lightness Actual state.
static int16_t light_lightness_utils_actual_to_generic_level(uint16_t ll_actual)
Convert the Light Lightness Actual state to the Generic Level state.

Documentation feedback | Developer Zone | Subscribe | Updated