使需要定期唤醒的设备,按下按钮。
我正在尝试实现此功能,但是在组合此功能时遇到了一些问题。按钮将进入睡眠状态,但仅在按下按钮时唤醒。然后它进入睡眠状态并立即醒来几次,然后进入睡眠状态,直到我再次按下按钮。
这个问题有什么解决方案吗?
#include "driver/uart.h"
#include "gpio.h"
#include "osapi.h"
#include "user_interface.h"
LOCAL os_
timer_t taskTimer;
LOCAL os_timer_t sleepTimer;
void ICACHE_FLASH_ATTR fpm_wakup_cb_func(void)
{
uint8_t pin_state = GPIO_INPUT_GET(5);
os_printf("nnnin wakeup function %dn", system_get_time());
os_printf("pin %dn", pin_state);
wifi_fpm_close(); // disable force sleep function
// wifi_set_sleep_type(NONE_SLEEP_T);
// wifi_fpm_set_sleep_type(NONE_SLEEP_T);
app_init();
}
void ICACHE_FLASH_ATTR go_to_sleep(void)
{
os_printf("sleep for 20 sn");
wifi_set_opmode(NULL_MODE);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5);
// PIN_PULLUP_DIS(BUTTON_PIN_MUX);
gpio_output_set(0, GPIO_ID_PIN(5), 0, GPIO_ID_PIN(5));
wifi_enable_gpio_wakeup(5, GPIO_PIN_INTR_LOLEVEL);
wifi_fpm_open();
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func); // Set wakeup callback
// wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);
wifi_fpm_do_sleep(20 * 1000000); // Sleep for 300s, then publish again to test
// os_printf("sleep done...n");
}
无效 ICACHE_FLASH_ATTR turn_off()
{
os_printf("going to sleep %dn", system_get_time());
os_printf("disconnecting from wifin");
wifi_station_disconnect();
os_printf("disarming timersn");
os_timer_disarm(&taskTimer);
os_timer_disarm(&sleepTimer);
os_timer_setfn(&sleepTimer, (os_timer_func_t *)go_to_sleep, NULL);
os_timer_arm(&sleepTimer, 1000, 0);
}
无效ICACHE_FLASH_ATTR set_turn_off_after(uint8_t秒)
{
os_printf("turn off after %d secondsn", sec);
os_timer_disarm(&taskTimer);
os_timer_setfn(&taskTimer, (os_timer_func_t *)turn_off, NULL);
os_timer_arm(&taskTimer, sec * 1000, 0);
}
void ICACHE_FLASH_ATTR app_init(无效)
{
set_turn_off_after(10);
}
void ICACHE_FLASH_ATTR user_init(无效)
{
//tur on the led
gpio_init();
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
gpio_output_set((1 << 4), 0, (1 << 4), 0);
uart_init(BIT_RATE_115200, BIT_RATE_115200);
uint8_t i;
for (i = 0; i < 10; i++)
{
os_printf(".");
os_delay_us(10000);
}
system_init_done_cb(app_init);
}
0