|
1 | 1 | #include "ZigbeeAnalog.h"
|
2 | 2 | #if CONFIG_ZB_ENABLED
|
| 3 | +#include <cfloat> |
3 | 4 |
|
4 | 5 | ZigbeeAnalog::ZigbeeAnalog(uint8_t endpoint) : ZigbeeEP(endpoint) {
|
5 | 6 | _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID;
|
@@ -20,6 +21,8 @@ bool ZigbeeAnalog::addAnalogInput() {
|
20 | 21 | "Analog Input";
|
21 | 22 | uint32_t application_type = 0x00000000 | (ESP_ZB_ZCL_AI_GROUP_ID << 24);
|
22 | 23 | float resolution = 0.1; // Default resolution of 0.1
|
| 24 | +float min = -FLT_MAX; // Default min value for float |
| 25 | +float max = FLT_MAX; // Default max value for float |
23 | 26 |
|
24 | 27 | esp_err_t ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_DESCRIPTION_ID, (void *)default_description);
|
25 | 28 | if (ret != ESP_OK) {
|
@@ -39,11 +42,24 @@ bool ZigbeeAnalog::addAnalogInput() {
|
39 | 42 | return false;
|
40 | 43 | }
|
41 | 44 |
|
| 45 | +ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID, (void *)&min); |
| 46 | +if (ret != ESP_OK) { |
| 47 | +log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 48 | +return false; |
| 49 | +} |
| 50 | + |
| 51 | +ret = esp_zb_analog_input_cluster_add_attr(esp_zb_analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID, (void *)&max); |
| 52 | +if (ret != ESP_OK) { |
| 53 | +log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 54 | +return false; |
| 55 | +} |
| 56 | + |
42 | 57 | ret = esp_zb_cluster_list_add_analog_input_cluster(_cluster_list, esp_zb_analog_input_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
|
43 | 58 | if (ret != ESP_OK) {
|
44 | 59 | log_e("Failed to add Analog Input cluster: 0x%x: %s", ret, esp_err_to_name(ret));
|
45 | 60 | return false;
|
46 | 61 | }
|
| 62 | + |
47 | 63 | _analog_clusters |= ANALOG_INPUT;
|
48 | 64 | return true;
|
49 | 65 | }
|
@@ -76,6 +92,8 @@ bool ZigbeeAnalog::addAnalogOutput() {
|
76 | 92 | "Analog Output";
|
77 | 93 | uint32_t application_type = 0x00000000 | (ESP_ZB_ZCL_AO_GROUP_ID << 24);
|
78 | 94 | float resolution = 1; // Default resolution of 1
|
| 95 | +float min = -FLT_MAX; // Default min value for float |
| 96 | +float max = FLT_MAX; // Default max value for float |
79 | 97 |
|
80 | 98 | esp_err_t ret =
|
81 | 99 | esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_DESCRIPTION_ID, (void *)default_description);
|
@@ -96,6 +114,18 @@ bool ZigbeeAnalog::addAnalogOutput() {
|
96 | 114 | return false;
|
97 | 115 | }
|
98 | 116 |
|
| 117 | +ret = esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MIN_PRESENT_VALUE_ID, (void *)&min); |
| 118 | +if (ret != ESP_OK) { |
| 119 | +log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 120 | +return false; |
| 121 | +} |
| 122 | + |
| 123 | +ret = esp_zb_analog_output_cluster_add_attr(esp_zb_analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MAX_PRESENT_VALUE_ID, (void *)&max); |
| 124 | +if (ret != ESP_OK) { |
| 125 | +log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 126 | +return false; |
| 127 | +} |
| 128 | + |
99 | 129 | ret = esp_zb_cluster_list_add_analog_output_cluster(_cluster_list, esp_zb_analog_output_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
|
100 | 130 | if (ret != ESP_OK) {
|
101 | 131 | log_e("Failed to add Analog Output cluster: 0x%x: %s", ret, esp_err_to_name(ret));
|
@@ -376,4 +406,58 @@ bool ZigbeeAnalog::setAnalogOutputResolution(float resolution) {
|
376 | 406 | return true;
|
377 | 407 | }
|
378 | 408 |
|
| 409 | +bool ZigbeeAnalog::setAnalogOutputMinMax(float min, float max) { |
| 410 | +if (!(_analog_clusters & ANALOG_OUTPUT)) { |
| 411 | +log_e("Analog Output cluster not added"); |
| 412 | +return false; |
| 413 | +} |
| 414 | + |
| 415 | +esp_zb_attribute_list_t *analog_output_cluster = |
| 416 | +esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); |
| 417 | +if (analog_output_cluster == nullptr) { |
| 418 | +log_e("Failed to get analog output cluster"); |
| 419 | +return false; |
| 420 | +} |
| 421 | + |
| 422 | +esp_err_t ret = esp_zb_cluster_update_attr(analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MIN_PRESENT_VALUE_ID, (void *)&min); |
| 423 | +if (ret != ESP_OK) { |
| 424 | +log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 425 | +return false; |
| 426 | +} |
| 427 | + |
| 428 | +ret = esp_zb_cluster_update_attr(analog_output_cluster, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_MAX_PRESENT_VALUE_ID, (void *)&max); |
| 429 | +if (ret != ESP_OK) { |
| 430 | +log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 431 | +return false; |
| 432 | +} |
| 433 | +return true; |
| 434 | +} |
| 435 | + |
| 436 | +bool ZigbeeAnalog::setAnalogInputMinMax(float min, float max) { |
| 437 | +if (!(_analog_clusters & ANALOG_INPUT)) { |
| 438 | +log_e("Analog Input cluster not added"); |
| 439 | +return false; |
| 440 | +} |
| 441 | + |
| 442 | +esp_zb_attribute_list_t *analog_input_cluster = |
| 443 | +esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); |
| 444 | +if (analog_input_cluster == nullptr) { |
| 445 | +log_e("Failed to get analog input cluster"); |
| 446 | +return false; |
| 447 | +} |
| 448 | + |
| 449 | +esp_err_t ret = esp_zb_cluster_update_attr(analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID, (void *)&min); |
| 450 | +if (ret != ESP_OK) { |
| 451 | +log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 452 | +return false; |
| 453 | +} |
| 454 | + |
| 455 | +ret = esp_zb_cluster_update_attr(analog_input_cluster, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID, (void *)&max); |
| 456 | +if (ret != ESP_OK) { |
| 457 | +log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret)); |
| 458 | +return false; |
| 459 | +} |
| 460 | +return true; |
| 461 | +} |
| 462 | + |
379 | 463 | #endif // CONFIG_ZB_ENABLED
|
0 commit comments