Skip to content

Commit 8a5dfd0

Browse files
committed
fix(): Simplify examples + fix zigbee partition table
1 parent bddb847 commit 8a5dfd0

File tree

3 files changed

+38
-54
lines changed

3 files changed

+38
-54
lines changed

Diff for: libraries/ESP32/examples/Zigbee/Zigbee_Light_Bulb/Zigbee_Light_Bulb.ino

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#endif
3030

3131
#include "esp_zigbee_core.h"
32-
#include "nvs_flash.h"
3332
#include "freertos/FreeRTOS.h"
3433
#include "freertos/task.h"
3534
#include "ha/esp_zigbee_ha_standard.h"
@@ -178,13 +177,12 @@ void setup() {
178177
.radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(),
179178
.host_config = ESP_ZB_DEFAULT_HOST_CONFIG(),
180179
};
181-
ESP_ERROR_CHECK(nvs_flash_init());
182180
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
183181

184182
// Init RMT and leave light OFF
185183
neopixelWrite(LED_PIN,0,0,0);
186184

187-
//Start Zigbee task
185+
// Start Zigbee task
188186
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
189187
}
190188

Diff for: libraries/ESP32/examples/Zigbee/Zigbee_Light_Switch/Zigbee_Light_Switch.ino

+36-50
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#endif
3131

3232
#include "esp_zigbee_core.h"
33-
#include "nvs_flash.h"
3433
#include "freertos/FreeRTOS.h"
3534
#include "freertos/task.h"
3635
#include "ha/esp_zigbee_ha_standard.h"
@@ -237,48 +236,6 @@ static void switch_gpios_intr_enabled(bool enabled)
237236
}
238237
}
239238

240-
// Tasks for checking the button event and debounce the switch state
241-
static void switch_button_detected(void *arg)
242-
{
243-
uint8_t pin = 0;
244-
switch_func_pair_t button_func_pair;
245-
static switch_state_t switch_state = SWITCH_IDLE;
246-
bool evt_flag = false;
247-
248-
for (;;) {
249-
/* check if there is any queue received, if yes read out the button_func_pair */
250-
if (xQueueReceive(gpio_evt_queue, &button_func_pair, portMAX_DELAY)) {
251-
pin = button_func_pair.pin;
252-
switch_gpios_intr_enabled(false);
253-
evt_flag = true;
254-
}
255-
while (evt_flag) {
256-
bool value = digitalRead(pin);
257-
switch (switch_state) {
258-
case SWITCH_IDLE:
259-
switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_IDLE;
260-
break;
261-
case SWITCH_PRESS_DETECTED:
262-
switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_RELEASE_DETECTED;
263-
break;
264-
case SWITCH_RELEASE_DETECTED:
265-
switch_state = SWITCH_IDLE;
266-
/* callback to button_handler */
267-
(*esp_zb_buttons_handler)(&button_func_pair);
268-
break;
269-
default:
270-
break;
271-
}
272-
if (switch_state == SWITCH_IDLE) {
273-
switch_gpios_intr_enabled(true);
274-
evt_flag = false;
275-
break;
276-
}
277-
vTaskDelay(10 / portTICK_PERIOD_MS);
278-
}
279-
}
280-
}
281-
282239
/********************* Arduino functions **************************/
283240
void setup() {
284241
// Init Zigbee
@@ -287,10 +244,8 @@ void setup() {
287244
.host_config = ESP_ZB_DEFAULT_HOST_CONFIG(),
288245
};
289246

290-
ESP_ERROR_CHECK(nvs_flash_init());
291247
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
292248

293-
//switch_driver_init(button_func_pair, PAIR_SIZE(button_func_pair), esp_zb_buttons_handler);
294249
// Init button switch
295250
for (int i = 0; i < PAIR_SIZE(button_func_pair); i++) {
296251
pinMode(button_func_pair[i].pin, INPUT_PULLUP);
@@ -305,12 +260,43 @@ void setup() {
305260

306261
// Start Zigbee task
307262
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
308-
309-
// Start GPIO task
310-
xTaskCreate(switch_button_detected, "button_detected", 2048, NULL, 10, NULL);
311-
312263
}
313264

314265
void loop() {
315-
//empty, zigbee running in separate task
266+
// Handle button switch in loop()
267+
uint8_t pin = 0;
268+
switch_func_pair_t button_func_pair;
269+
static switch_state_t switch_state = SWITCH_IDLE;
270+
bool evt_flag = false;
271+
272+
/* check if there is any queue received, if yes read out the button_func_pair */
273+
if (xQueueReceive(gpio_evt_queue, &button_func_pair, portMAX_DELAY)) {
274+
pin = button_func_pair.pin;
275+
switch_gpios_intr_enabled(false);
276+
evt_flag = true;
277+
}
278+
while (evt_flag) {
279+
bool value = digitalRead(pin);
280+
switch (switch_state) {
281+
case SWITCH_IDLE:
282+
switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_IDLE;
283+
break;
284+
case SWITCH_PRESS_DETECTED:
285+
switch_state = (value == LOW) ? SWITCH_PRESS_DETECTED : SWITCH_RELEASE_DETECTED;
286+
break;
287+
case SWITCH_RELEASE_DETECTED:
288+
switch_state = SWITCH_IDLE;
289+
/* callback to button_handler */
290+
(*esp_zb_buttons_handler)(&button_func_pair);
291+
break;
292+
default:
293+
break;
294+
}
295+
if (switch_state == SWITCH_IDLE) {
296+
switch_gpios_intr_enabled(true);
297+
evt_flag = false;
298+
break;
299+
}
300+
vTaskDelay(10 / portTICK_PERIOD_MS);
301+
}
316302
}

Diff for: tools/partitions/zigbee_zczr.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ nvs, data, nvs, 0x9000, 0x5000,
33
otadata, data, ota, 0xe000, 0x2000,
44
app0, app, ota_0, 0x10000, 0x140000,
55
app1, app, ota_1, 0x150000,0x140000,
6-
spiffs, data, spiffs, 0x28F000,0x15A000,
6+
spiffs, data, spiffs, 0x290000,0x15A000,
77
zb_storage, data, fat, 0x3EA000,0x4000,
88
zb_fct, data, fat, 0x3EE000,0x1000,
99
rcp_fw, data, spiffs, 0x3EF000,0x1000,

0 commit comments

Comments
 (0)