2024-10-03 06:39:22 +08:00
|
|
|
#ifndef BUTTON_H_
|
|
|
|
|
#define BUTTON_H_
|
|
|
|
|
|
|
|
|
|
#include <driver/gpio.h>
|
|
|
|
|
#include <iot_button.h>
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
class Button {
|
|
|
|
|
public:
|
2025-03-07 21:53:29 +08:00
|
|
|
#if CONFIG_SOC_ADC_SUPPORTED
|
|
|
|
|
Button(const button_adc_config_t& cfg);
|
|
|
|
|
#endif
|
2024-12-03 09:43:41 +08:00
|
|
|
Button(gpio_num_t gpio_num, bool active_high = false);
|
2024-10-03 06:39:22 +08:00
|
|
|
~Button();
|
|
|
|
|
|
2024-11-23 16:14:24 +08:00
|
|
|
void OnPressDown(std::function<void()> callback);
|
|
|
|
|
void OnPressUp(std::function<void()> callback);
|
2024-10-03 06:39:22 +08:00
|
|
|
void OnLongPress(std::function<void()> callback);
|
|
|
|
|
void OnClick(std::function<void()> callback);
|
|
|
|
|
void OnDoubleClick(std::function<void()> callback);
|
|
|
|
|
private:
|
|
|
|
|
gpio_num_t gpio_num_;
|
2025-01-23 21:51:59 +08:00
|
|
|
button_handle_t button_handle_ = nullptr;
|
2024-10-03 06:39:22 +08:00
|
|
|
|
|
|
|
|
|
2024-11-23 16:14:24 +08:00
|
|
|
std::function<void()> on_press_down_;
|
|
|
|
|
std::function<void()> on_press_up_;
|
2024-10-03 06:39:22 +08:00
|
|
|
std::function<void()> on_long_press_;
|
|
|
|
|
std::function<void()> on_click_;
|
|
|
|
|
std::function<void()> on_double_click_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // BUTTON_H_
|