更新按键驱动

This commit is contained in:
LokLiang
2025-02-18 17:41:45 +08:00
parent f455349861
commit 141a9970d8
14 changed files with 649 additions and 466 deletions

View File

@@ -12,7 +12,7 @@
#include "esp_err.h"
/* 通用模块 */
#include "button/button_event.h"
#include "button/button.h"
/* 应用模块 */
@@ -30,7 +30,7 @@ nvs_handle g_nvs_hdl; // nvs 句柄
os_work_q_t g_work_q_hdl_low; // 低于 default_os_work_q_hdl 优先级的工作队列
static void _init_nvs(void);
static int _change_mode_event_button(const button_event_t *event);
static void _change_mode_event_button(button_hdl_t *handle, press_event_t event);
static void _vset_cb(sh_t *sh_hdl);
void work_app_main(void *arg)
@@ -39,9 +39,7 @@ void work_app_main(void *arg)
_init_nvs();
/* 初始化按键检测和控制 */
button_init(PIN_BIT(g_cfg_board->key_boot.pin), g_cfg_board->key_boot.en_lev);
button_event_add_callback(g_cfg_board->key_boot.pin, _change_mode_event_button);
btn_attach(&g_cfg_board->key_boot, _change_mode_event_button, EVENT_PRESS_UP | EVENT_PRESS_DOWN | EVENT_LONG_PRESS_HOLD);
/* 启动 shell */
SYS_LOG_INF("app start");
@@ -59,19 +57,17 @@ static void _init_nvs(void)
}
}
static int _change_mode_event_button(const button_event_t *event)
static void _change_mode_event_button(button_hdl_t *handle, press_event_t event)
{
static const char *const stat_tab[] = {
[BUTTON_UP] = "up",
[BUTTON_DOWN] = "down",
[BUTTON_HELD] = "held",
[PRESS_UP] = "up",
[PRESS_DOWN] = "down",
[LONG_PRESS_HOLD] = "held",
};
if (event->event < __ARRAY_SIZE(stat_tab))
if (event < __ARRAY_SIZE(stat_tab) && stat_tab[event])
{
SYS_LOG_DBG("button stat: %s", stat_tab[event->event]);
SYS_LOG_DBG("button stat: %s", stat_tab[event]);
}
return 0;
}
static void _vset_cb(sh_t *sh_hdl)