2025-03-08 14:45:49 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include "FluxButton.h"
|
|
|
|
|
|
#include "driver/gpio.h"
|
|
|
|
|
|
#include "ui.h"
|
|
|
|
|
|
|
|
|
|
|
|
static const char *BUTTON_TAG = "button_test";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*<2A><><EFBFBD>尴<EFBFBD><E5B0B4><EFBFBD>¼<EFBFBD><C2BC>б<EFBFBD>*/
|
|
|
|
|
|
const char *button_event_table[] = {
|
|
|
|
|
|
"BUTTON_PRESS_DOWN",
|
|
|
|
|
|
"BUTTON_PRESS_UP",
|
|
|
|
|
|
"BUTTON_PRESS_REPEAT",
|
|
|
|
|
|
"BUTTON_PRESS_REPEAT_DONE",
|
|
|
|
|
|
"BUTTON_SINGLE_CLICK",
|
|
|
|
|
|
"BUTTON_DOUBLE_CLICK",
|
|
|
|
|
|
"BUTTON_MULTIPLE_CLICK",
|
|
|
|
|
|
"BUTTON_LONG_PRESS_START",
|
|
|
|
|
|
"BUTTON_LONG_PRESS_HOLD",
|
|
|
|
|
|
"BUTTON_LONG_PRESS_UP",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void button_event_cb(void *arg, void *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
ESP_LOGI(BUTTON_TAG, "Button event %d", (int)data);
|
|
|
|
|
|
|
|
|
|
|
|
#if CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE
|
|
|
|
|
|
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
|
|
|
|
|
if (cause != ESP_SLEEP_WAKEUP_UNDEFINED) {
|
|
|
|
|
|
ESP_LOGI(BUTTON_TAG, "Wake up from light sleep, reason %d", cause);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>밴<EFBFBD><EBB0B4><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
|
switch ((int)data)
|
|
|
|
|
|
{
|
|
|
|
|
|
case BUTTON_CMD_POWER_ON:
|
|
|
|
|
|
/*<2A><>Ӧ<EFBFBD><D3A6>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>*/
|
2025-03-10 10:42:45 +08:00
|
|
|
|
POWER_ON;
|
2025-03-08 14:45:49 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case BUTTON_CMD_POWER_OFF:
|
2025-03-10 10:42:45 +08:00
|
|
|
|
POWER_OFF;
|
2025-03-08 14:45:49 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case BUTTON_CMD_CENTER_KEY:
|
|
|
|
|
|
/*<2A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><D4B0><EFBFBD>*/
|
2025-03-12 17:32:58 +08:00
|
|
|
|
lv_event_send(ui_pageHome_buttonStartTest, LV_EVENT_CLICKED, NULL);
|
2025-03-08 14:45:49 +08:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case BUTTON_CMD_LEFT_KEY:
|
2025-03-12 17:32:58 +08:00
|
|
|
|
lv_event_send(ui_pageHome_buttonMinus, LV_EVENT_CLICKED, NULL);
|
2025-03-08 14:45:49 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case BUTTON_CMD_RIGHT_KEY:
|
2025-03-12 17:32:58 +08:00
|
|
|
|
lv_event_send(ui_pageHome_buttonAdd, LV_EVENT_CLICKED, NULL);
|
2025-03-08 14:45:49 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void button_init_func(uint32_t button_num)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint8_t activeLevel = BUTTON_ACTIVE_LEVEL;
|
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<DEB8><C4BC><EFBFBD>״̬Ϊ<CCAC>ߵ<EFBFBD>ƽ*/
|
|
|
|
|
|
if (button_num == BUTTON_PowerIn_IO_NUM)
|
|
|
|
|
|
{
|
|
|
|
|
|
activeLevel = BUTTON_POWERIN_ACTIVE_LEVEL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button_config_t btn_cfg = {
|
|
|
|
|
|
.type = BUTTON_TYPE_GPIO,
|
|
|
|
|
|
.gpio_button_config = {
|
|
|
|
|
|
.gpio_num = button_num,
|
|
|
|
|
|
.active_level = activeLevel,
|
|
|
|
|
|
#if CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE
|
|
|
|
|
|
.enable_power_save = true,
|
|
|
|
|
|
#endif
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
button_handle_t btn = iot_button_create(&btn_cfg);
|
|
|
|
|
|
assert(btn);
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t err = ESP_OK;
|
|
|
|
|
|
/*Ϊ<><CEAA>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
|
if (button_num == BUTTON_PowerIn_IO_NUM)
|
|
|
|
|
|
{
|
|
|
|
|
|
/*˫<><CBAB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>йػ<D0B9>*/
|
|
|
|
|
|
err |= iot_button_register_cb(btn, BUTTON_DOUBLE_CLICK, button_event_cb, (void *)BUTTON_CMD_POWER_OFF);
|
|
|
|
|
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>*/
|
|
|
|
|
|
err |= iot_button_register_cb(btn, BUTTON_LONG_PRESS_HOLD, button_event_cb, (void *)BUTTON_CMD_POWER_ON);
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
/*Ϊ<>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ע<><D7A2><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
|
switch (button_num)
|
|
|
|
|
|
{
|
|
|
|
|
|
case BUTTON_Center_IO_NUM:
|
|
|
|
|
|
err |= iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, button_event_cb, (void *)BUTTON_CMD_CENTER_KEY);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case BUTTON_Left_IO_NUM:
|
|
|
|
|
|
err |= iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, button_event_cb, (void *)BUTTON_CMD_LEFT_KEY);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case BUTTON_Right_IO_NUM:
|
|
|
|
|
|
err |= iot_button_register_cb(btn, BUTTON_SINGLE_CLICK, button_event_cb, (void *)BUTTON_CMD_RIGHT_KEY);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ESP_ERROR_CHECK(err);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*<2A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
|
void button_init(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
button_init_func(BUTTON_Center_IO_NUM);
|
|
|
|
|
|
button_init_func(BUTTON_Left_IO_NUM);
|
|
|
|
|
|
button_init_func(BUTTON_Right_IO_NUM);
|
|
|
|
|
|
|
|
|
|
|
|
button_init_func(BUTTON_PowerIn_IO_NUM);
|
|
|
|
|
|
|
|
|
|
|
|
/*<2A>ڴ˴<DAB4><CBB4><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>IO<49><4F><EFBFBD><EFBFBD>*/
|
|
|
|
|
|
gpio_reset_pin(BUTTON_PowerOut_IO_NUM);
|
|
|
|
|
|
gpio_set_direction(BUTTON_PowerOut_IO_NUM, GPIO_MODE_OUTPUT);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE
|
|
|
|
|
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
|
|
|
|
|
|
void power_save_init(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
esp_pm_config_t pm_config = {
|
|
|
|
|
|
.max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ,
|
|
|
|
|
|
.min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,
|
|
|
|
|
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
|
|
|
|
|
.light_sleep_enable = true
|
|
|
|
|
|
#endif
|
|
|
|
|
|
};
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
|
|
|
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
|
|
void power_save_init(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
|
|
|
esp_pm_config_esp32_t pm_config = {
|
|
|
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
|
|
|
|
|
esp_pm_config_esp32s2_t pm_config = {
|
|
|
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
|
|
|
|
|
esp_pm_config_esp32c3_t pm_config = {
|
|
|
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
|
|
esp_pm_config_esp32s3_t pm_config = {
|
|
|
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C2
|
|
|
|
|
|
esp_pm_config_esp32c2_t pm_config = {
|
|
|
|
|
|
#endif
|
|
|
|
|
|
.max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ,
|
|
|
|
|
|
.min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,
|
|
|
|
|
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
|
|
|
|
|
.light_sleep_enable = true
|
|
|
|
|
|
#endif
|
|
|
|
|
|
};
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|