1 // Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /** @file 16 * @brief Bluetooth Mesh Lighting Client Model APIs. 17 */ 18 19 #ifndef _LIGHTING_CLIENT_H_ 20 #define _LIGHTING_CLIENT_H_ 21 22 #include "client_common.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Light client model common structure */ 29 typedef bt_mesh_client_user_data_t bt_mesh_light_client_t; 30 typedef bt_mesh_client_internal_data_t light_internal_data_t; 31 32 /* Lighting Client Model Callback */ 33 extern const struct bt_mesh_model_cb bt_mesh_lighting_client_cb; 34 35 /* Light Lightness Client Model Context */ 36 extern const struct bt_mesh_model_op bt_mesh_light_lightness_cli_op[]; 37 38 /** @def BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI 39 * 40 * Define a new light lightness client model. Note that this API 41 * needs to be repeated for each element which the application 42 * wants to have a light lightness client model on. 43 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 44 * @param cli_data Pointer to a unique struct bt_mesh_light_lightness_cli. 45 * 46 * @return New light lightness client model instance. 47 */ 48 #define BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI(cli_pub, cli_data) \ 49 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, \ 50 bt_mesh_light_lightness_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) 51 52 typedef bt_mesh_client_user_data_t bt_mesh_light_lightness_client_t; 53 54 struct bt_mesh_light_lightness_status { 55 bool op_en; /* Indicate whether optional parameters included */ 56 uint16_t present_lightness; /* Present value of light lightness actual state */ 57 uint16_t target_lightness; /* Target value of light lightness actual state (optional) */ 58 uint8_t remain_time; /* Time to complete state transition (C.1) */ 59 }; 60 61 struct bt_mesh_light_lightness_linear_status { 62 bool op_en; /* Indicate whether optional parameters included */ 63 uint16_t present_lightness; /* Present value of light lightness linear state */ 64 uint16_t target_lightness; /* Target value of light lightness linear state (optional) */ 65 uint8_t remain_time; /* Time to complete state transition (C.1) */ 66 }; 67 68 struct bt_mesh_light_lightness_last_status { 69 uint16_t lightness; /* The value of the Light Lightness Last state */ 70 }; 71 72 struct bt_mesh_light_lightness_default_status { 73 uint16_t lightness; /* The value of the Light Lightness default state */ 74 }; 75 76 struct bt_mesh_light_lightness_range_status { 77 uint8_t status_code; /* Status Code for the requesting message */ 78 uint16_t range_min; /* Value of range min field of light lightness range state */ 79 uint16_t range_max; /* Value of range max field of light lightness range state */ 80 }; 81 82 struct bt_mesh_light_lightness_set { 83 bool op_en; /* Indicate whether optional parameters included */ 84 uint16_t lightness; /* Target value of light lightness actual state */ 85 uint8_t tid; /* Transaction Identifier */ 86 uint8_t trans_time; /* Time to complete state transition (optional) */ 87 uint8_t delay; /* Indicate message execution delay (C.1) */ 88 }; 89 90 struct bt_mesh_light_lightness_linear_set { 91 bool op_en; /* Indicate whether optional parameters included */ 92 uint16_t lightness; /* Target value of light lightness linear state */ 93 uint8_t tid; /* Transaction Identifier */ 94 uint8_t trans_time; /* Time to complete state transition (optional) */ 95 uint8_t delay; /* Indicate message execution delay (C.1) */ 96 }; 97 98 struct bt_mesh_light_lightness_default_set { 99 uint16_t lightness; /* The value of the Light Lightness Default state */ 100 }; 101 102 struct bt_mesh_light_lightness_range_set { 103 uint16_t range_min; /* Value of range min field of light lightness range state */ 104 uint16_t range_max; /* Value of range max field of light lightness range state */ 105 }; 106 107 /* Light CTL Client Model Context */ 108 extern const struct bt_mesh_model_op bt_mesh_light_ctl_cli_op[]; 109 110 /** @def BLE_MESH_MODEL_LIGHT_CTL_CLI 111 * 112 * Define a new light CTL client model. Note that this API needs 113 * to be repeated for each element which the application wants to 114 * have a light CTL client model on. 115 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 116 * @param cli_data Pointer to a unique struct bt_mesh_light_ctl_cli. 117 * 118 * @return New light CTL client model instance. 119 */ 120 #define BLE_MESH_MODEL_LIGHT_CTL_CLI(cli_pub, cli_data) \ 121 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, \ 122 bt_mesh_light_ctl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) 123 124 typedef bt_mesh_client_user_data_t bt_mesh_light_ctl_client_t; 125 126 struct bt_mesh_light_ctl_status { 127 bool op_en; /* Indicate whether optional parameters included */ 128 uint16_t present_ctl_lightness; /* Present value of light ctl lightness state */ 129 uint16_t present_ctl_temperature; /* Present value of light ctl temperature state */ 130 uint16_t target_ctl_lightness; /* Target value of light ctl lightness state (optional) */ 131 uint16_t target_ctl_temperature; /* Target value of light ctl temperature state (C.1) */ 132 uint8_t remain_time; /* Time to complete state transition (C.1) */ 133 }; 134 135 struct bt_mesh_light_ctl_temperature_status { 136 bool op_en; /* Indicate whether optional parameters included */ 137 uint16_t present_ctl_temperature; /* Present value of light ctl temperature state */ 138 uint16_t present_ctl_delta_uv; /* Present value of light ctl delta UV state */ 139 uint16_t target_ctl_temperature; /* Target value of light ctl temperature state (optional) */ 140 uint16_t target_ctl_delta_uv; /* Target value of light ctl delta UV state (C.1) */ 141 uint8_t remain_time; /* Time to complete state transition (C.1) */ 142 }; 143 144 struct bt_mesh_light_ctl_temperature_range_status { 145 uint8_t status_code; /* Status code for the requesting message */ 146 uint16_t range_min; /* Value of temperature range min field of light ctl temperature range state */ 147 uint16_t range_max; /* Value of temperature range max field of light ctl temperature range state */ 148 }; 149 150 struct bt_mesh_light_ctl_default_status { 151 uint16_t lightness; /* Value of light lightness default state */ 152 uint16_t temperature; /* Value of light temperature default state */ 153 int16_t delta_uv; /* Value of light delta UV default state */ 154 }; 155 156 struct bt_mesh_light_ctl_set { 157 bool op_en; /* Indicate whether optional parameters included */ 158 uint16_t ctl_lightness; /* Target value of light ctl lightness state */ 159 uint16_t ctl_temperature; /* Target value of light ctl temperature state */ 160 int16_t ctl_delta_uv; /* Target value of light ctl delta UV state */ 161 uint8_t tid; /* Transaction Identifier */ 162 uint8_t trans_time; /* Time to complete state transition (optional) */ 163 uint8_t delay; /* Indicate message execution delay (C.1) */ 164 }; 165 166 struct bt_mesh_light_ctl_temperature_set { 167 bool op_en; /* Indicate whether optional parameters included */ 168 uint16_t ctl_temperature; /* Target value of light ctl temperature state */ 169 int16_t ctl_delta_uv; /* Target value of light ctl delta UV state */ 170 uint8_t tid; /* Transaction Identifier */ 171 uint8_t trans_time; /* Time to complete state transition (optional) */ 172 uint8_t delay; /* Indicate message execution delay (C.1) */ 173 }; 174 175 struct bt_mesh_light_ctl_temperature_range_set { 176 uint16_t range_min; /* Value of temperature range min field of light ctl temperature range state */ 177 uint16_t range_max; /* Value of temperature range max field of light ctl temperature range state */ 178 }; 179 180 struct bt_mesh_light_ctl_default_set { 181 uint16_t lightness; /* Value of light lightness default state */ 182 uint16_t temperature; /* Value of light temperature default state */ 183 int16_t delta_uv; /* Value of light delta UV default state */ 184 }; 185 186 /* Light HSL Client Model Context */ 187 extern const struct bt_mesh_model_op bt_mesh_light_hsl_cli_op[]; 188 189 /** @def BLE_MESH_MODEL_LIGHT_HSL_CLI 190 * 191 * Define a new light HSL client model. Note that this API needs 192 * to be repeated for each element which the application wants to 193 * have a light HSL client model on. 194 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 195 * @param cli_data Pointer to a unique struct bt_mesh_light_hsl_cli. 196 * 197 * @return New light HSL client model instance. 198 */ 199 #define BLE_MESH_MODEL_LIGHT_HSL_CLI(cli_pub, cli_data) \ 200 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, \ 201 bt_mesh_light_hsl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) 202 203 typedef bt_mesh_client_user_data_t bt_mesh_light_hsl_client_t; 204 205 struct bt_mesh_light_hsl_status { 206 bool op_en; /* Indicate whether optional parameters included */ 207 uint16_t hsl_lightness; /* Present value of light hsl lightness state */ 208 uint16_t hsl_hue; /* Present value of light hsl hue state */ 209 uint16_t hsl_saturation; /* Present value of light hsl saturation state */ 210 uint8_t remain_time; /* Time to complete state transition (optional) */ 211 }; 212 213 struct bt_mesh_light_hsl_target_status { 214 bool op_en; /* Indicate whether optional parameters included */ 215 uint16_t hsl_lightness_target; /* Target value of light hsl lightness state */ 216 uint16_t hsl_hue_target; /* Target value of light hsl hue state */ 217 uint16_t hsl_saturation_target; /* Target value of light hsl saturation state */ 218 uint8_t remain_time; /* Time to complete state transition (optional) */ 219 }; 220 221 struct bt_mesh_light_hsl_hue_status { 222 bool op_en; /* Indicate whether optional parameters included */ 223 uint16_t present_hue; /* Present value of light hsl hue state */ 224 uint16_t target_hue; /* Target value of light hsl hue state (optional) */ 225 uint8_t remain_time; /* Time to complete state transition (C.1) */ 226 }; 227 228 struct bt_mesh_light_hsl_saturation_status { 229 bool op_en; /* Indicate whether optional parameters included */ 230 uint16_t present_saturation; /* Present value of light hsl saturation state */ 231 uint16_t target_saturation; /* Target value of light hsl saturation state (optional) */ 232 uint8_t remain_time; /* Time to complete state transition (C.1) */ 233 }; 234 235 struct bt_mesh_light_hsl_default_status { 236 uint16_t lightness; /* Value of light lightness default state */ 237 uint16_t hue; /* Value of light hue default state */ 238 uint16_t saturation; /* Value of light saturation default state */ 239 }; 240 241 struct bt_mesh_light_hsl_range_status { 242 uint8_t status_code; /* Status code for the requesting message */ 243 uint16_t hue_range_min; /* Value of hue range min field of light hsl hue range state */ 244 uint16_t hue_range_max; /* Value of hue range max field of light hsl hue range state */ 245 uint16_t saturation_range_min; /* Value of saturation range min field of light hsl saturation range state */ 246 uint16_t saturation_range_max; /* Value of saturation range max field of light hsl saturation range state */ 247 }; 248 249 struct bt_mesh_light_hsl_set { 250 bool op_en; /* Indicate whether optional parameters included */ 251 uint16_t hsl_lightness; /* Target value of light hsl lightness state */ 252 uint16_t hsl_hue; /* Target value of light hsl hue state */ 253 uint16_t hsl_saturation; /* Target value of light hsl saturation state */ 254 uint8_t tid; /* Transaction Identifier */ 255 uint8_t trans_time; /* Time to complete state transition (optional) */ 256 uint8_t delay; /* Indicate message execution delay (C.1) */ 257 }; 258 259 struct bt_mesh_light_hsl_hue_set { 260 bool op_en; /* Indicate whether optional parameters included */ 261 uint16_t hue; /* Target value of light hsl hue state */ 262 uint8_t tid; /* Transaction Identifier */ 263 uint8_t trans_time; /* Time to complete state transition (optional) */ 264 uint8_t delay; /* Indicate message execution delay (C.1) */ 265 }; 266 267 struct bt_mesh_light_hsl_saturation_set { 268 bool op_en; /* Indicate whether optional parameters included */ 269 uint16_t saturation; /* Target value of light hsl hue state */ 270 uint8_t tid; /* Transaction Identifier */ 271 uint8_t trans_time; /* Time to complete state transition (optional) */ 272 uint8_t delay; /* Indicate message execution delay (C.1) */ 273 }; 274 275 struct bt_mesh_light_hsl_default_set { 276 uint16_t lightness; /* Value of light lightness default state */ 277 uint16_t hue; /* Value of light hue default state */ 278 uint16_t saturation; /* Value of light saturation default state */ 279 }; 280 281 struct bt_mesh_light_hsl_range_set { 282 uint16_t hue_range_min; /* Value of hue range min field of light hsl hue range state */ 283 uint16_t hue_range_max; /* Value of hue range max field of light hsl hue range state */ 284 uint16_t saturation_range_min; /* Value of saturation range min field of light hsl saturation range state */ 285 uint16_t saturation_range_max; /* Value of saturation range max field of light hsl saturation range state */ 286 }; 287 288 /* Light xyL Client Model Context */ 289 extern const struct bt_mesh_model_op bt_mesh_light_xyl_cli_op[]; 290 291 /** @def BLE_MESH_MODEL_LIGHT_XYL_CLI 292 * 293 * Define a new light xyL client model. Note that this API needs 294 * to be repeated for each element which the application wants 295 * to have a light xyL client model on. 296 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 297 * @param cli_data Pointer to a unique struct bt_mesh_light_xyl_cli. 298 * 299 * @return New light xyL client model instance. 300 */ 301 #define BLE_MESH_MODEL_LIGHT_XYL_CLI(cli_pub, cli_data) \ 302 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, \ 303 bt_mesh_light_xyl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) 304 305 typedef bt_mesh_client_user_data_t bt_mesh_light_xyl_client_t; 306 307 struct bt_mesh_light_xyl_status { 308 bool op_en; /* Indicate whether optional parameters included */ 309 uint16_t xyl_lightness; /* The present value of the Light xyL Lightness state */ 310 uint16_t xyl_x; /* The present value of the Light xyL x state */ 311 uint16_t xyl_y; /* The present value of the Light xyL y state */ 312 uint8_t remain_time; /* Time to complete state transition (optional) */ 313 }; 314 315 struct bt_mesh_light_xyl_target_status { 316 bool op_en; /* Indicate whether optional parameters included */ 317 uint16_t target_xyl_lightness; /* The target value of the Light xyL Lightness state */ 318 uint16_t target_xyl_x; /* The target value of the Light xyL x state */ 319 uint16_t target_xyl_y; /* The target value of the Light xyL y state */ 320 uint8_t remain_time; /* Time to complete state transition (optional) */ 321 }; 322 323 struct bt_mesh_light_xyl_default_status { 324 uint16_t lightness; /* The value of the Light Lightness Default state */ 325 uint16_t xyl_x; /* The value of the Light xyL x Default state */ 326 uint16_t xyl_y; /* The value of the Light xyL y Default state */ 327 }; 328 329 struct bt_mesh_light_xyl_range_status { 330 uint8_t status_code; /* Status Code for the requesting message */ 331 uint16_t xyl_x_range_min; /* The value of the xyL x Range Min field of the Light xyL x Range state */ 332 uint16_t xyl_x_range_max; /* The value of the xyL x Range Max field of the Light xyL x Range state */ 333 uint16_t xyl_y_range_min; /* The value of the xyL y Range Min field of the Light xyL y Range state */ 334 uint16_t xyl_y_range_max; /* The value of the xyL y Range Max field of the Light xyL y Range state */ 335 }; 336 337 struct bt_mesh_light_xyl_set { 338 bool op_en; /* Indicate whether optional parameters included */ 339 uint16_t xyl_lightness; /* The target value of the Light xyL Lightness state */ 340 uint16_t xyl_x; /* The target value of the Light xyL x state */ 341 uint16_t xyl_y; /* The target value of the Light xyL y state */ 342 uint8_t tid; /* Transaction Identifier */ 343 uint8_t trans_time; /* Time to complete state transition (optional) */ 344 uint8_t delay; /* Indicate message execution delay (C.1) */ 345 }; 346 347 struct bt_mesh_light_xyl_default_set { 348 uint16_t lightness; /* The value of the Light Lightness Default state */ 349 uint16_t xyl_x; /* The value of the Light xyL x Default state */ 350 uint16_t xyl_y; /* The value of the Light xyL y Default state */ 351 }; 352 353 struct bt_mesh_light_xyl_range_set { 354 uint16_t xyl_x_range_min; /* The value of the xyL x Range Min field of the Light xyL x Range state */ 355 uint16_t xyl_x_range_max; /* The value of the xyL x Range Max field of the Light xyL x Range state */ 356 uint16_t xyl_y_range_min; /* The value of the xyL y Range Min field of the Light xyL y Range state */ 357 uint16_t xyl_y_range_max; /* The value of the xyL y Range Max field of the Light xyL y Range state */ 358 }; 359 360 /* Light LC Client Model Context */ 361 extern const struct bt_mesh_model_op bt_mesh_light_lc_cli_op[]; 362 363 /** @def BLE_MESH_MODEL_LIGHT_LC_CLI 364 * 365 * Define a new light lc client model. Note that this API needs 366 * to be repeated for each element which the application wants 367 * to have a light lc client model on. 368 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 369 * @param cli_data Pointer to a unique struct bt_mesh_light_lc_cli. 370 * 371 * @return New light lc client model instance. 372 */ 373 #define BLE_MESH_MODEL_LIGHT_LC_CLI(cli_pub, cli_data) \ 374 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LC_CLI, \ 375 bt_mesh_light_lc_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) 376 377 typedef bt_mesh_client_user_data_t bt_mesh_light_lc_client_t; 378 379 struct bt_mesh_light_lc_mode_status { 380 uint8_t mode; /* The present value of the Light LC Mode state */ 381 }; 382 383 struct bt_mesh_light_lc_om_status { 384 uint8_t mode; /* The present value of the Light LC Occupancy Mode state */ 385 }; 386 387 struct bt_mesh_light_lc_light_onoff_status { 388 bool op_en; /* Indicate whether optional parameters included */ 389 uint8_t present_light_onoff; /* The present value of the Light LC Light OnOff state */ 390 uint8_t target_light_onoff; /* The target value of the Light LC Light OnOff state (Optional) */ 391 uint8_t remain_time; /* Time to complete state transition (C.1) */ 392 }; 393 394 struct bt_mesh_light_lc_property_status { 395 uint16_t light_lc_property_id; /* Property ID identifying a Light LC Property */ 396 struct net_buf_simple *light_lc_property_value; /* Raw value for the Light LC Property */ 397 }; 398 399 struct bt_mesh_light_lc_mode_set { 400 uint8_t mode; /* The target value of the Light LC Mode state */ 401 }; 402 403 struct bt_mesh_light_lc_om_set { 404 uint8_t mode; /* The target value of the Light LC Occupancy Mode state */ 405 }; 406 407 struct bt_mesh_light_lc_light_onoff_set { 408 bool op_en; /* Indicate whether optional parameters included */ 409 uint8_t light_onoff; /* The target value of the Light LC Light OnOff state */ 410 uint8_t tid; /* Transaction Identifier */ 411 uint8_t trans_time; /* Time to complete state transition (optional) */ 412 uint8_t delay; /* Indicate message execution delay (C.1) */ 413 }; 414 415 struct bt_mesh_light_lc_property_get { 416 uint16_t light_lc_property_id; /* Property ID identifying a Light LC Property */ 417 }; 418 419 struct bt_mesh_light_lc_property_set { 420 uint16_t light_lc_property_id; /* Property ID identifying a Light LC Property */ 421 struct net_buf_simple *light_lc_property_value; /* Raw value for the Light LC Property */ 422 }; 423 424 /** 425 * @brief This function is called to get light states. 426 * 427 * @param[in] common: Message common information structure 428 * @param[in] get: Pointer of light get message value 429 * 430 * @return Zero-success, other-fail 431 */ 432 int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get); 433 434 /** 435 * @brief This function is called to set light states. 436 * 437 * @param[in] common: Message common information structure 438 * @param[in] set: Pointer of light set message value 439 * 440 * @return Zero-success, other-fail 441 */ 442 int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set); 443 444 #ifdef __cplusplus 445 } 446 #endif 447 448 #endif /* _LIGHTING_CLIENT_H_ */ 449