|
| 1 | +/* Class of Zigbee On/Off Light endpoint inherited from common EP class */ |
| 2 | + |
| 3 | +#pragma once |
| 4 | + |
| 5 | +#include "soc/soc_caps.h" |
| 6 | +#if SOC_IEEE802154_SUPPORTED |
| 7 | + |
| 8 | +#include "ZigbeeEP.h" |
| 9 | +#include "ha/esp_zigbee_ha_standard.h" |
| 10 | + |
| 11 | +/** |
| 12 | + * @brief Zigbee HA standard dimmable light device clusters. |
| 13 | + * Added here as not supported by ESP Zigbee library. |
| 14 | + * |
| 15 | + * |
| 16 | + */ |
| 17 | +typedef struct esp_zb_dimmable_light_cfg_s |
| 18 | +{ |
| 19 | + esp_zb_basic_cluster_cfg_t basic_cfg; /*!< Basic cluster configuration, @ref esp_zb_basic_cluster_cfg_s */ |
| 20 | + esp_zb_identify_cluster_cfg_t identify_cfg; /*!< Identify cluster configuration, @ref esp_zb_identify_cluster_cfg_s */ |
| 21 | + esp_zb_groups_cluster_cfg_t groups_cfg; /*!< Groups cluster configuration, @ref esp_zb_groups_cluster_cfg_s */ |
| 22 | + esp_zb_scenes_cluster_cfg_t scenes_cfg; /*!< Scenes cluster configuration, @ref esp_zb_scenes_cluster_cfg_s */ |
| 23 | + esp_zb_on_off_cluster_cfg_t on_off_cfg; /*!< On off cluster configuration, @ref esp_zb_on_off_cluster_cfg_s */ |
| 24 | + esp_zb_level_cluster_cfg_t level_cfg; /*!< Level cluster configuration, @ref esp_zb_level_cluster_cfg_s */ |
| 25 | +} esp_zb_dimmable_light_cfg_t; |
| 26 | + |
| 27 | +/** |
| 28 | + * @brief Zigbee HA standard dimmable light device default config value. |
| 29 | + * Added here as not supported by ESP Zigbee library. |
| 30 | + * |
| 31 | + */ |
| 32 | +#define ESP_ZB_DEFAULT_DIMMABLE_LIGHT_CONFIG() \ |
| 33 | + { \ |
| 34 | + .basic_cfg = \ |
| 35 | + { \ |
| 36 | + .zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, \ |
| 37 | + .power_source = ESP_ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE, \ |
| 38 | + }, \ |
| 39 | + .identify_cfg = \ |
| 40 | + { \ |
| 41 | + .identify_time = ESP_ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE, \ |
| 42 | + }, \ |
| 43 | + .groups_cfg = \ |
| 44 | + { \ |
| 45 | + .groups_name_support_id = ESP_ZB_ZCL_GROUPS_NAME_SUPPORT_DEFAULT_VALUE, \ |
| 46 | + }, \ |
| 47 | + .scenes_cfg = \ |
| 48 | + { \ |
| 49 | + .scenes_count = ESP_ZB_ZCL_SCENES_SCENE_COUNT_DEFAULT_VALUE, \ |
| 50 | + .current_scene = ESP_ZB_ZCL_SCENES_CURRENT_SCENE_DEFAULT_VALUE, \ |
| 51 | + .current_group = ESP_ZB_ZCL_SCENES_CURRENT_GROUP_DEFAULT_VALUE, \ |
| 52 | + .scene_valid = ESP_ZB_ZCL_SCENES_SCENE_VALID_DEFAULT_VALUE, \ |
| 53 | + .name_support = ESP_ZB_ZCL_SCENES_NAME_SUPPORT_DEFAULT_VALUE, \ |
| 54 | + }, \ |
| 55 | + .on_off_cfg = \ |
| 56 | + { \ |
| 57 | + .on_off = ESP_ZB_ZCL_ON_OFF_ON_OFF_DEFAULT_VALUE, \ |
| 58 | + }, \ |
| 59 | + .level_cfg = \ |
| 60 | + { \ |
| 61 | + .current_level = ESP_ZB_ZCL_LEVEL_CONTROL_CURRENT_LEVEL_DEFAULT_VALUE, \ |
| 62 | + }, \ |
| 63 | + } |
| 64 | + |
| 65 | +class ZigbeeDimmableLight : public ZigbeeEP |
| 66 | +{ |
| 67 | +public: |
| 68 | + ZigbeeDimmableLight(uint8_t endpoint); |
| 69 | + ~ZigbeeDimmableLight(); |
| 70 | + |
| 71 | + void onLightChange(void (*callback)(bool, uint8_t)) |
| 72 | + { |
| 73 | + _on_light_change = callback; |
| 74 | + } |
| 75 | + void restoreLight() |
| 76 | + { |
| 77 | + lightChanged(); |
| 78 | + } |
| 79 | + |
| 80 | +private: |
| 81 | + void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override; |
| 82 | + |
| 83 | + void lightChanged(); |
| 84 | + // callback function to be called on light change (State, Level) |
| 85 | + void (*_on_light_change)(bool, uint8_t); |
| 86 | + |
| 87 | + /** |
| 88 | + * @brief Create a standard HA dimmable light cluster list. |
| 89 | + * Added here as not supported by ESP Zigbee library. |
| 90 | + * |
| 91 | + * @note This contains basic, identify, groups, scenes, on-off, level, as server side. |
| 92 | + * @param[in] light_cfg Configuration parameters for this cluster lists defined by @ref esp_zb_dimmable_light_cfg_t |
| 93 | + * |
| 94 | + * @return Pointer to cluster list @ref esp_zb_cluster_list_s |
| 95 | + * |
| 96 | + */ |
| 97 | + esp_zb_cluster_list_t *esp_zb_dimmable_light_clusters_create(esp_zb_dimmable_light_cfg_t *light_cfg); |
| 98 | + |
| 99 | + bool _current_state; |
| 100 | + uint8_t _current_level; |
| 101 | +}; |
| 102 | + |
| 103 | +#endif // SOC_IEEE802154_SUPPORTED |
0 commit comments