Skip to content

Commit 37560e8

Browse files
ci(pre-commit): Apply automatic fixes
1 parent 29c4216 commit 37560e8

File tree

3 files changed

+101
-111
lines changed

3 files changed

+101
-111
lines changed

Diff for: libraries/Zigbee/examples/Zigbee_Analog_Input_Output/Zigbee_Analog_Input_Output.ino

+92-93
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @brief This example demonstrates Zigbee analog input / output device.
1717
*
1818
* The example demonstrates how to use Zigbee library to create a end device analog device.
19-
*
19+
*
2020
* Proper Zigbee mode must be selected in Tools->Zigbee mode
2121
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
2222
*
@@ -26,95 +26,94 @@
2626
* Modified by Pat Clay
2727
*/
2828

29-
#ifndef ZIGBEE_MODE_ED
30-
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
31-
#endif
32-
33-
#include "Zigbee.h"
34-
35-
/* Zigbee analog device configuration */
36-
#define ANALOG_DEVICE_ENDPOINT_NUMBER 1
37-
38-
uint8_t analogPin = A0;
39-
uint8_t button = BOOT_PIN;
40-
41-
ZigbeeAnalog zbAnalogDevice = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER);
42-
43-
void onAnalogOutputChange(float analog_output) {
44-
Serial.printf("Received analog output change: %.1f\r\n", analog_output);
45-
}
46-
47-
void setup() {
48-
Serial.begin(115200);
49-
Serial.println("Starting...");
50-
51-
// Init button switch
52-
pinMode(button, INPUT_PULLUP);
53-
54-
// Set analog resolution to 10 bits
55-
analogReadResolution(10);
56-
57-
// Optional: set Zigbee device name and model
58-
zbAnalogDevice.setManufacturerAndModel("Espressif", "ZigbeeAnalogDevice");
59-
60-
// Add analog sensor cluster to Zigbee Analog accoding your needs
61-
zbAnalogDevice.addAnalogInput();
62-
zbAnalogDevice.addAnalogOutput();
63-
64-
// If analog output cluster is added, set callback function for analog output change
65-
zbAnalogDevice.onAnalogOutputChange(onAnalogOutputChange);
66-
67-
// Add endpoints to Zigbee Core
68-
Zigbee.addEndpoint(&zbAnalogDevice);
69-
70-
Serial.println("Starting Zigbee...");
71-
// When all EPs are registered, start Zigbee in End Device mode
72-
if (!Zigbee.begin()) {
73-
Serial.println("Zigbee failed to start!");
74-
Serial.println("Rebooting...");
75-
ESP.restart();
76-
} else {
77-
Serial.println("Zigbee started successfully!");
78-
}
79-
Serial.println("Connecting to network");
80-
while (!Zigbee.connected()) {
81-
Serial.print(".");
82-
delay(100);
83-
}
84-
Serial.println("Connected");
85-
86-
// Optional: Add reporting for analog input
87-
zbAnalogDevice.setAnalogInputReporting(0, 30, 10); // report every 30 seconds if value changes by 10
88-
}
89-
90-
void loop() {
91-
static uint32_t timeCounter = 0;
92-
93-
// Read ADC value and update the analog value every 2s
94-
if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s
95-
float analog = (float)analogRead(analogPin);
96-
Serial.printf("Updating analog input to %.1f\r\n", analog);
97-
zbAnalogDevice.setAnalogInput(analog);
98-
99-
// Analog input supports reporting
100-
zbAnalogDevice.reportAnalogInput();
101-
}
102-
103-
// Checking button for factory reset and reporting
104-
if (digitalRead(button) == LOW) { // Push button pressed
105-
// Key debounce handling
106-
delay(100);
107-
int startTime = millis();
108-
while (digitalRead(button) == LOW) {
109-
delay(50);
110-
if ((millis() - startTime) > 3000) {
111-
// If key pressed for more than 3secs, factory reset Zigbee and reboot
112-
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
113-
delay(1000);
114-
Zigbee.factoryReset();
115-
}
116-
}
117-
}
118-
delay(100);
119-
}
120-
29+
#ifndef ZIGBEE_MODE_ED
30+
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
31+
#endif
32+
33+
#include "Zigbee.h"
34+
35+
/* Zigbee analog device configuration */
36+
#define ANALOG_DEVICE_ENDPOINT_NUMBER 1
37+
38+
uint8_t analogPin = A0;
39+
uint8_t button = BOOT_PIN;
40+
41+
ZigbeeAnalog zbAnalogDevice = ZigbeeAnalog(ANALOG_DEVICE_ENDPOINT_NUMBER);
42+
43+
void onAnalogOutputChange(float analog_output) {
44+
Serial.printf("Received analog output change: %.1f\r\n", analog_output);
45+
}
46+
47+
void setup() {
48+
Serial.begin(115200);
49+
Serial.println("Starting...");
50+
51+
// Init button switch
52+
pinMode(button, INPUT_PULLUP);
53+
54+
// Set analog resolution to 10 bits
55+
analogReadResolution(10);
56+
57+
// Optional: set Zigbee device name and model
58+
zbAnalogDevice.setManufacturerAndModel("Espressif", "ZigbeeAnalogDevice");
59+
60+
// Add analog sensor cluster to Zigbee Analog accoding your needs
61+
zbAnalogDevice.addAnalogInput();
62+
zbAnalogDevice.addAnalogOutput();
63+
64+
// If analog output cluster is added, set callback function for analog output change
65+
zbAnalogDevice.onAnalogOutputChange(onAnalogOutputChange);
66+
67+
// Add endpoints to Zigbee Core
68+
Zigbee.addEndpoint(&zbAnalogDevice);
69+
70+
Serial.println("Starting Zigbee...");
71+
// When all EPs are registered, start Zigbee in End Device mode
72+
if (!Zigbee.begin()) {
73+
Serial.println("Zigbee failed to start!");
74+
Serial.println("Rebooting...");
75+
ESP.restart();
76+
} else {
77+
Serial.println("Zigbee started successfully!");
78+
}
79+
Serial.println("Connecting to network");
80+
while (!Zigbee.connected()) {
81+
Serial.print(".");
82+
delay(100);
83+
}
84+
Serial.println("Connected");
85+
86+
// Optional: Add reporting for analog input
87+
zbAnalogDevice.setAnalogInputReporting(0, 30, 10); // report every 30 seconds if value changes by 10
88+
}
89+
90+
void loop() {
91+
static uint32_t timeCounter = 0;
92+
93+
// Read ADC value and update the analog value every 2s
94+
if (!(timeCounter++ % 20)) { // delaying for 100ms x 20 = 2s
95+
float analog = (float)analogRead(analogPin);
96+
Serial.printf("Updating analog input to %.1f\r\n", analog);
97+
zbAnalogDevice.setAnalogInput(analog);
98+
99+
// Analog input supports reporting
100+
zbAnalogDevice.reportAnalogInput();
101+
}
102+
103+
// Checking button for factory reset and reporting
104+
if (digitalRead(button) == LOW) { // Push button pressed
105+
// Key debounce handling
106+
delay(100);
107+
int startTime = millis();
108+
while (digitalRead(button) == LOW) {
109+
delay(50);
110+
if ((millis() - startTime) > 3000) {
111+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
112+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
113+
delay(1000);
114+
Zigbee.factoryReset();
115+
}
116+
}
117+
}
118+
delay(100);
119+
}

Diff for: libraries/Zigbee/src/ep/ZigbeeAnalog.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,17 @@ ZigbeeAnalog::ZigbeeAnalog(uint8_t endpoint) : ZigbeeEP(endpoint) {
2121
}
2222

2323
void ZigbeeAnalog::addAnalogValue() {
24-
esp_zb_cluster_list_add_analog_value_cluster(
25-
_cluster_list, esp_zb_analog_value_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
26-
);
24+
esp_zb_cluster_list_add_analog_value_cluster(_cluster_list, esp_zb_analog_value_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
2725
_analog_clusters |= ANALOG_VALUE;
2826
}
2927

3028
void ZigbeeAnalog::addAnalogInput() {
31-
esp_zb_cluster_list_add_analog_input_cluster(
32-
_cluster_list, esp_zb_analog_input_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
33-
);
29+
esp_zb_cluster_list_add_analog_input_cluster(_cluster_list, esp_zb_analog_input_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
3430
_analog_clusters |= ANALOG_INPUT;
3531
}
3632

3733
void ZigbeeAnalog::addAnalogOutput() {
38-
esp_zb_cluster_list_add_analog_output_cluster(
39-
_cluster_list, esp_zb_analog_output_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
40-
);
34+
esp_zb_cluster_list_add_analog_output_cluster(_cluster_list, esp_zb_analog_output_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
4135
_analog_clusters |= ANALOG_OUTPUT;
4236
}
4337

@@ -64,31 +58,29 @@ void ZigbeeAnalog::analogOutputChanged(float analog_output) {
6458
}
6559

6660
void ZigbeeAnalog::setAnalogValue(float analog) {
67-
if(!(_analog_clusters & ANALOG_VALUE)) {
61+
if (!(_analog_clusters & ANALOG_VALUE)) {
6862
log_e("Analog Value cluster not added");
6963
return;
7064
}
7165
// float zb_analog = analog;
7266
log_d("Setting analog value to %.1f", analog);
7367
esp_zb_lock_acquire(portMAX_DELAY);
7468
esp_zb_zcl_set_attribute_val(
75-
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_VALUE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ANALOG_VALUE_PRESENT_VALUE_ID,
76-
&analog, false
69+
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_VALUE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ANALOG_VALUE_PRESENT_VALUE_ID, &analog, false
7770
);
7871
esp_zb_lock_release();
7972
}
8073

8174
void ZigbeeAnalog::setAnalogInput(float analog) {
82-
if(!(_analog_clusters & ANALOG_INPUT)) {
75+
if (!(_analog_clusters & ANALOG_INPUT)) {
8376
log_e("Analog Input cluster not added");
8477
return;
8578
}
8679
// float zb_analog = analog;
8780
log_d("Setting analog input to %.1f", analog);
8881
esp_zb_lock_acquire(portMAX_DELAY);
8982
esp_zb_zcl_set_attribute_val(
90-
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID,
91-
&analog, false
83+
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID, &analog, false
9284
);
9385
esp_zb_lock_release();
9486
}
@@ -123,11 +115,10 @@ void ZigbeeAnalog::setAnalogInputReporting(uint16_t min_interval, uint16_t max_i
123115
reporting_info.u.send_info.delta.s32 = delta;
124116
reporting_info.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID;
125117
reporting_info.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC;
126-
118+
127119
esp_zb_lock_acquire(portMAX_DELAY);
128120
esp_zb_zcl_update_reporting_info(&reporting_info);
129121
esp_zb_lock_release();
130122
}
131123

132-
133124
#endif //SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED

Diff for: libraries/Zigbee/src/ep/ZigbeeAnalog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ZigbeeAnalog : public ZigbeeEP {
6666

6767
private:
6868
void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override;
69-
69+
7070
void (*_on_analog_output_change)(float);
7171
void analogOutputChanged(float analog_output);
7272

0 commit comments

Comments
 (0)