#include "button_func.h"


static const char *TAG = "BUTTON_FUNC";

// 按钮句柄
static button_handle_t g_button = NULL;

// 按钮回调函数
static void button_single_click_cb()
{
    ESP_LOGI(TAG, "Button clicked");
}

static void button_long_press_start_cb()
{
    ESP_LOGI(TAG, "Button long press started");
    ESP_LOGI(TAG, "Power off");
    power_sys_off();
}




void button_func_init()
{
    ESP_LOGI(TAG, "init_GPIO");

    button_config_t btn_cfg = {
        .long_press_time=2000,
        .short_press_time=50,
    };

    button_gpio_config_t gpio_cfg={
        .gpio_num=BUTTON_PIN,
        .active_level=BUTTON_ACTIVE_LEVEL,
        
    };

    esp_err_t ret = iot_button_new_gpio_device(&btn_cfg, &gpio_cfg, &g_button);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to create GPIO button: 0x%x", ret);
       
    }
  
    iot_button_register_cb(g_button,BUTTON_PRESS_DOWN,NULL,button_single_click_cb,NULL);
    iot_button_register_cb(g_button,BUTTON_LONG_PRESS_START,NULL,button_long_press_start_cb,NULL);


}