button_obj.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "freertos/FreeRTOS.h"
  14. #include "freertos/task.h"
  15. #include "esp_system.h"
  16. #include "iot_button.h"
  17. CButton::CButton(gpio_num_t gpio_num, button_active_t active_level)
  18. {
  19. m_btn_handle = iot_button_create(gpio_num, active_level);
  20. }
  21. CButton::~CButton()
  22. {
  23. iot_button_delete(m_btn_handle);
  24. m_btn_handle = NULL;
  25. }
  26. esp_err_t CButton::set_evt_cb(button_cb_type_t type, button_cb cb, void* arg)
  27. {
  28. return iot_button_set_evt_cb(m_btn_handle, type, cb, arg);
  29. }
  30. esp_err_t CButton::set_serial_cb(button_cb cb, void* arg, TickType_t interval_tick, uint32_t start_after_sec)
  31. {
  32. return iot_button_set_serial_cb(m_btn_handle, start_after_sec, interval_tick, cb, arg);
  33. }
  34. esp_err_t CButton::add_custom_cb(uint32_t press_sec, button_cb cb, void* arg)
  35. {
  36. return iot_button_add_custom_cb(m_btn_handle, press_sec, cb, arg);
  37. }
  38. esp_err_t CButton::rm_cb(button_cb_type_t type)
  39. {
  40. return iot_button_rm_cb(m_btn_handle, type);
  41. }