From fc27117299e98a9677832bbea83ff9703e97f615 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 15 Jan 2021 20:27:43 +0800 Subject: [PATCH] ble_mesh: stack: Enable updating lighting hsl state --- .../bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 6 ++++++ .../server/include/state_binding.h | 6 ++++++ .../mesh_models/server/state_binding.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index ea02c53b5d..ef823d6818 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -2131,6 +2131,11 @@ typedef union { uint16_t temperature; /*!< The value of the Light CTL Temperature state */ int16_t delta_uv; /*!< The value of the Light CTL Delta UV state */ } light_ctl_temp_delta_uv; /*!< The Light CTL Temperature & Delta UV states */ + struct { + uint16_t lightness; /*!< The value of the Light HSL Lightness state */ + uint16_t hue; /*!< The value of the Light HSL Hue state */ + uint16_t saturation; /*!< The value of the Light HSL Saturation state */ + } light_hsl; /*!< The Light HSL composite state */ struct { uint16_t lightness; /*!< The value of the Light HSL Lightness state */ } light_hsl_lightness; /*!< The Light HSL Lightness state */ @@ -2158,6 +2163,7 @@ typedef enum { ESP_BLE_MESH_LIGHT_LIGHTNESS_LINEAR_STATE, ESP_BLE_MESH_LIGHT_CTL_LIGHTNESS_STATE, ESP_BLE_MESH_LIGHT_CTL_TEMP_DELTA_UV_STATE, + ESP_BLE_MESH_LIGHT_HSL_STATE, ESP_BLE_MESH_LIGHT_HSL_LIGHTNESS_STATE, ESP_BLE_MESH_LIGHT_HSL_HUE_STATE, ESP_BLE_MESH_LIGHT_HSL_SATURATION_STATE, diff --git a/components/bt/esp_ble_mesh/mesh_models/server/include/state_binding.h b/components/bt/esp_ble_mesh/mesh_models/server/include/state_binding.h index d65609b005..9de67ea1d3 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/include/state_binding.h +++ b/components/bt/esp_ble_mesh/mesh_models/server/include/state_binding.h @@ -24,6 +24,7 @@ typedef enum { LIGHT_LIGHTNESS_LINEAR_STATE, LIGHT_CTL_LIGHTNESS_STATE, LIGHT_CTL_TEMP_DELTA_UV_STATE, + LIGHT_HSL_STATE, LIGHT_HSL_LIGHTNESS_STATE, LIGHT_HSL_HUE_STATE, LIGHT_HSL_SATURATION_STATE, @@ -58,6 +59,11 @@ typedef union { uint16_t temperature; int16_t delta_uv; } light_ctl_temp_delta_uv; + struct { + uint16_t lightness; + uint16_t hue; + uint16_t saturation; + } light_hsl; struct { uint16_t lightness; } light_hsl_lightness; diff --git a/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c b/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c index cfe27d0824..a407361bcf 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c @@ -252,6 +252,25 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, light_ctl_publish(model, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS); break; } + case LIGHT_HSL_STATE: { + if (model->id != BLE_MESH_MODEL_ID_LIGHT_HSL_SRV) { + BT_ERR("Invalid Light HSL Server, model id 0x%04x", model->id); + return -EINVAL; + } + + struct bt_mesh_light_hsl_srv *srv = model->user_data; + if (srv->state == NULL) { + BT_ERR("Invalid Light HSL Server state"); + return -EINVAL; + } + + bt_mesh_server_stop_transition(&srv->transition); + srv->state->lightness = value->light_hsl.lightness; + srv->state->hue = value->light_hsl.hue; + srv->state->saturation = value->light_hsl.saturation; + light_hsl_publish(model, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS); + break; + } case LIGHT_HSL_LIGHTNESS_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_HSL_SRV) { BT_ERR("Invalid Light HSL Server, model id 0x%04x", model->id);