|
22 | 22 | #include "espnow_ctrl.h" |
23 | 23 | #if !defined(CONFIG_EXAMPLE_USE_COIN_CELL_BUTTON) || !CONFIG_EXAMPLE_USE_COIN_CELL_BUTTON_V1 |
24 | 24 | #include "iot_button.h" |
| 25 | +#include "button_gpio.h" |
| 26 | +#include "button_adc.h" |
25 | 27 | #endif |
26 | 28 | #ifdef CONFIG_EXAMPLE_USE_COIN_CELL_BUTTON |
27 | 29 | #include "switch_board.h" |
@@ -359,51 +361,59 @@ static void app_driver_init(void) |
359 | 361 | board_init(); |
360 | 362 |
|
361 | 363 | #if !CONFIG_EXAMPLE_USE_COIN_CELL_BUTTON_V1 |
| 364 | + /* Button 4.x API for ADC */ |
362 | 365 | button_config_t button_config = { |
363 | | - .type = BUTTON_TYPE_ADC, |
364 | | - .adc_button_config = { |
365 | | - .adc_channel = BOARD_CHAN_ADC, |
366 | | - .min = 2200, |
367 | | - .max = 3400, |
368 | | - .adc_handle = NULL, |
369 | | - }, |
| 366 | + .long_press_time = 2000, |
| 367 | + .short_press_time = 180, |
370 | 368 | }; |
371 | | - button_handle_t button_handle = iot_button_create(&button_config); |
372 | | - iot_button_register_cb(button_handle, BUTTON_PRESS_DOWN, app_switch_button_event_cb, NULL); |
373 | | - iot_button_register_cb(button_handle, BUTTON_SINGLE_CLICK, app_switch_button_event_cb, NULL); |
374 | | - iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_HOLD, app_switch_button_event_cb, NULL); |
375 | | - iot_button_register_cb(button_handle, BUTTON_PRESS_END, app_switch_button_event_cb, NULL); |
376 | | - |
377 | | - button_event_config_t btn_event_cfg = { |
378 | | - .event = BUTTON_LONG_PRESS_UP, |
379 | | - .event_data = { |
380 | | - .long_press.press_time = 2000, |
381 | | - } |
| 369 | + |
| 370 | + button_adc_config_t adc_config = { |
| 371 | + .adc_channel = BOARD_CHAN_ADC, |
| 372 | + .adc_handle = NULL, |
| 373 | + .unit_id = ADC_UNIT_1, |
| 374 | + .button_index = 0, |
| 375 | + .min = 2200, |
| 376 | + .max = 3400, |
| 377 | + }; |
| 378 | + |
| 379 | + button_handle_t button_handle = NULL; |
| 380 | + ESP_ERROR_CHECK(iot_button_new_adc_device(&button_config, &adc_config, &button_handle)); |
| 381 | + |
| 382 | + iot_button_register_cb(button_handle, BUTTON_PRESS_DOWN, NULL, app_switch_button_event_cb, NULL); |
| 383 | + iot_button_register_cb(button_handle, BUTTON_SINGLE_CLICK, NULL, app_switch_button_event_cb, NULL); |
| 384 | + iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_HOLD, NULL, app_switch_button_event_cb, NULL); |
| 385 | + iot_button_register_cb(button_handle, BUTTON_PRESS_END, NULL, app_switch_button_event_cb, NULL); |
| 386 | + |
| 387 | + button_event_args_t btn_event_args = { |
| 388 | + .long_press.press_time = 2000, |
382 | 389 | }; |
383 | | - iot_button_register_event_cb(button_handle, btn_event_cfg, app_switch_button_event_cb, NULL); |
| 390 | + iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_UP, &btn_event_args, app_switch_button_event_cb, NULL); |
384 | 391 |
|
385 | | - btn_event_cfg.event = BUTTON_LONG_PRESS_START; |
386 | | - btn_event_cfg.event_data.long_press.press_time = 4000; |
387 | | - iot_button_register_event_cb(button_handle, btn_event_cfg, app_switch_button_event_cb, NULL); |
| 392 | + btn_event_args.long_press.press_time = 4000; |
| 393 | + iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_START, &btn_event_args, app_switch_button_event_cb, NULL); |
388 | 394 | #endif |
389 | 395 |
|
390 | 396 | #else |
| 397 | + /* Button 4.x API */ |
391 | 398 | button_config_t button_config = { |
392 | | - .type = BUTTON_TYPE_GPIO, |
393 | | - .gpio_button_config = { |
394 | | - .gpio_num = CONTROL_KEY_GPIO, |
395 | | - .active_level = 0, |
| 399 | + .long_press_time = 2000, |
| 400 | + .short_press_time = 180, |
| 401 | + }; |
| 402 | + |
| 403 | + button_gpio_config_t gpio_config = { |
| 404 | + .gpio_num = CONTROL_KEY_GPIO, |
| 405 | + .active_level = 0, |
396 | 406 | #if CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE |
397 | 407 | .enable_power_save = true, |
398 | 408 | #endif |
399 | | - }, |
400 | 409 | }; |
401 | 410 |
|
402 | | - button_handle_t button_handle = iot_button_create(&button_config); |
| 411 | + button_handle_t button_handle = NULL; |
| 412 | + ESP_ERROR_CHECK(iot_button_new_gpio_device(&button_config, &gpio_config, &button_handle)); |
403 | 413 |
|
404 | | - iot_button_register_cb(button_handle, BUTTON_SINGLE_CLICK, app_switch_button_event_cb, NULL); |
405 | | - iot_button_register_cb(button_handle, BUTTON_DOUBLE_CLICK, app_switch_button_event_cb, NULL); |
406 | | - iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_START, app_switch_button_event_cb, NULL); |
| 414 | + iot_button_register_cb(button_handle, BUTTON_SINGLE_CLICK, NULL, app_switch_button_event_cb, NULL); |
| 415 | + iot_button_register_cb(button_handle, BUTTON_DOUBLE_CLICK, NULL, app_switch_button_event_cb, NULL); |
| 416 | + iot_button_register_cb(button_handle, BUTTON_LONG_PRESS_START, NULL, app_switch_button_event_cb, NULL); |
407 | 417 | #endif |
408 | 418 | } |
409 | 419 |
|
|
0 commit comments