forked from xiaozhi/xiaozhi-esp32
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#ifndef BUTTON_H_
|
|
#define BUTTON_H_
|
|
|
|
#include <driver/gpio.h>
|
|
#include <iot_button.h>
|
|
#include <button_types.h>
|
|
#include <button_adc.h>
|
|
#include <button_gpio.h>
|
|
#include <functional>
|
|
|
|
class Button {
|
|
public:
|
|
Button(button_handle_t button_handle);
|
|
Button(gpio_num_t gpio_num, bool active_high = false, uint16_t long_press_time = 0, uint16_t short_press_time = 0);
|
|
~Button();
|
|
|
|
void OnPressDown(std::function<void()> callback);
|
|
void OnPressUp(std::function<void()> callback);
|
|
void OnLongPress(std::function<void()> callback);
|
|
void OnClick(std::function<void()> callback);
|
|
void OnDoubleClick(std::function<void()> callback);
|
|
void OnMultipleClick(std::function<void()> callback, uint8_t click_count = 3);
|
|
|
|
protected:
|
|
gpio_num_t gpio_num_;
|
|
button_handle_t button_handle_ = nullptr;
|
|
|
|
std::function<void()> on_press_down_;
|
|
std::function<void()> on_press_up_;
|
|
std::function<void()> on_long_press_;
|
|
std::function<void()> on_click_;
|
|
std::function<void()> on_double_click_;
|
|
std::function<void()> on_multiple_click_;
|
|
};
|
|
|
|
#if CONFIG_SOC_ADC_SUPPORTED
|
|
class AdcButton : public Button {
|
|
public:
|
|
AdcButton(const button_adc_config_t& adc_config);
|
|
};
|
|
#endif
|
|
|
|
#endif // BUTTON_H_
|