1 /* Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models
2  *
3  * SPDX-FileCopyrightText: 2018 Vikrant More
4  * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef _STATE_BINDING_H_
10 #define _STATE_BINDING_H_
11 
12 #include "mesh_access.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 typedef enum {
19     GENERIC_ONOFF_STATE,
20     GENERIC_LEVEL_STATE,
21     GENERIC_ONPOWERUP_STATE,
22     GENERIC_POWER_ACTUAL_STATE,
23     LIGHT_LIGHTNESS_ACTUAL_STATE,
24     LIGHT_LIGHTNESS_LINEAR_STATE,
25     LIGHT_CTL_LIGHTNESS_STATE,
26     LIGHT_CTL_TEMP_DELTA_UV_STATE,
27     LIGHT_HSL_STATE,
28     LIGHT_HSL_LIGHTNESS_STATE,
29     LIGHT_HSL_HUE_STATE,
30     LIGHT_HSL_SATURATION_STATE,
31     LIGHT_XYL_LIGHTNESS_STATE,
32     LIGHT_LC_LIGHT_ONOFF_STATE,
33     BIND_STATE_MAX,
34 } bt_mesh_server_state_type_t;
35 
36 typedef union {
37     struct {
38         uint8_t onoff;
39     } gen_onoff;
40     struct {
41         int16_t level;
42     } gen_level;
43     struct {
44         uint8_t onpowerup;
45     } gen_onpowerup;
46     struct {
47         uint16_t power;
48     } gen_power_actual;
49     struct {
50         uint16_t lightness;
51     } light_lightness_actual;
52     struct {
53         uint16_t lightness;
54     } light_lightness_linear;
55     struct {
56         uint16_t lightness;
57     } light_ctl_lightness;
58     struct {
59         uint16_t temperature;
60         int16_t  delta_uv;
61     } light_ctl_temp_delta_uv;
62     struct {
63         uint16_t lightness;
64         uint16_t hue;
65         uint16_t saturation;
66     } light_hsl;
67     struct {
68         uint16_t lightness;
69     } light_hsl_lightness;
70     struct {
71         uint16_t hue;
72     } light_hsl_hue;
73     struct {
74         uint16_t saturation;
75     } light_hsl_saturation;
76     struct {
77         uint16_t lightness;
78     } light_xyl_lightness;
79     struct {
80         uint8_t onoff;
81     } light_lc_light_onoff;
82 } bt_mesh_server_state_value_t;
83 
84 uint16_t bt_mesh_convert_lightness_actual_to_linear(uint16_t actual);
85 
86 uint16_t bt_mesh_convert_lightness_linear_to_actual(uint16_t linear);
87 
88 int16_t bt_mesh_convert_temperature_to_gen_level(uint16_t temp, uint16_t min, uint16_t max);
89 
90 uint16_t bt_mesh_covert_gen_level_to_temperature(int16_t level, uint16_t min, uint16_t max);
91 
92 int16_t bt_mesh_convert_hue_to_level(uint16_t hue);
93 
94 uint16_t bt_mesh_convert_level_to_hue(int16_t level);
95 
96 int16_t bt_mesh_convert_saturation_to_level(uint16_t saturation);
97 
98 uint16_t bt_mesh_convert_level_to_saturation(int16_t level);
99 
100 int bt_mesh_update_binding_state(struct bt_mesh_model *model,
101                                  bt_mesh_server_state_type_t type,
102                                  bt_mesh_server_state_value_t *value);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* _STATE_BINDING_H_ */
109