Air_58Printer/main/module/button.c

63 lines
3.1 KiB
C

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "iot_button.h"
#include "esp_sleep.h"
#include "esp_idf_version.h"
#include "esp_pm.h"
#include "module/include/Sys_Printer.h"
static const char *TAG = "button.c";
#define BOOT_BUTTON_NUM 0
#define BUTTON_ACTIVE_LEVEL 0
void button_init(void)
{
button_config_t btn_cfg = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = KEY_FEED_PIN,
.active_level = BUTTON_ACTIVE_LEVEL,
},
};
button_handle_t btn = iot_button_create(&btn_cfg);
assert(btn);
esp_err_t err = iot_button_register_cb(btn, BUTTON_PRESS_DOWN, Feed_Key_motion_cb, (void *)BUTTON_PRESS_DOWN);
err |= iot_button_register_cb(btn, BUTTON_PRESS_UP, Feed_Key_motion_cb, (void *)BUTTON_PRESS_UP);
err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT, Feed_Key_motion_cb, (void *)BUTTON_PRESS_REPEAT);
err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT_DONE, Feed_Key_motion_cb, (void *)BUTTON_PRESS_REPEAT_DONE);
err |= iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, Feed_Key_motion_cb, (void *)BUTTON_SINGLE_CLICK);
err |= iot_button_register_cb(btn, BUTTON_DOUBLE_CLICK, Feed_Key_motion_cb, (void *)BUTTON_DOUBLE_CLICK);
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_START, Feed_Key_motion_cb, (void *)BUTTON_LONG_PRESS_START);
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_HOLD, Feed_Key_motion_cb, (void *)BUTTON_LONG_PRESS_HOLD);
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_UP, Feed_Key_motion_cb, (void *)BUTTON_LONG_PRESS_UP);
err |= iot_button_register_cb(btn, BUTTON_PRESS_END, Feed_Key_motion_cb, (void *)BUTTON_PRESS_END);
button_config_t btn_sys_cfg = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config = {
.gpio_num = KEY_SYS_PIN,
.active_level = BUTTON_ACTIVE_LEVEL,
},
};
btn = iot_button_create(&btn_sys_cfg);
assert(btn);
err = iot_button_register_cb(btn, BUTTON_PRESS_DOWN, Sys_Key_motion_cb, (void *)BUTTON_PRESS_DOWN);
err |= iot_button_register_cb(btn, BUTTON_PRESS_UP, Sys_Key_motion_cb, (void *)BUTTON_PRESS_UP);
err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT, Sys_Key_motion_cb, (void *)BUTTON_PRESS_REPEAT);
err |= iot_button_register_cb(btn, BUTTON_PRESS_REPEAT_DONE, Sys_Key_motion_cb, (void *)BUTTON_PRESS_REPEAT_DONE);
err |= iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, Sys_Key_motion_cb, (void *)BUTTON_SINGLE_CLICK);
err |= iot_button_register_cb(btn, BUTTON_DOUBLE_CLICK, Sys_Key_motion_cb, (void *)BUTTON_DOUBLE_CLICK);
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_START, Sys_Key_motion_cb, (void *)BUTTON_LONG_PRESS_START);
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_HOLD, Sys_Key_motion_cb, (void *)BUTTON_LONG_PRESS_HOLD);
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_UP, Sys_Key_motion_cb, (void *)BUTTON_LONG_PRESS_UP);
err |= iot_button_register_cb(btn, BUTTON_PRESS_END, Sys_Key_motion_cb, (void *)BUTTON_PRESS_END);
ESP_ERROR_CHECK(err);
}