#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include "esp_event.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
ESP_EVENT_DECLARE_BASE(TIMER_EVENTS);
enum {
TIMER_EVENT_STARTED,
TIMER_EVENT_EXPIRY,
TIMER_EVENT_STOPPED
};
ESP_EVENT_DEFINE_BASE(TIMER_EVENTS);
void timer_started_handler(void *event_handler_arg, esp_event_base_t event_base,
int32_t event_id, void *event_data) {
static int count = 0;
count++;
printf("event_id: %ld , count : %d\n", event_id,count);
}
void app_main(void) {
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(
esp_event_handler_instance_register(TIMER_EVENTS, TIMER_EVENT_STARTED, timer_started_handler, NULL, NULL));
ESP_ERROR_CHECK(
esp_event_handler_instance_register(TIMER_EVENTS, TIMER_EVENT_STOPPED, timer_started_handler, NULL, NULL));
while (1) {
ESP_ERROR_CHECK(
esp_event_post(TIMER_EVENTS, TIMER_EVENT_STARTED, NULL, 0, portMAX_DELAY));
sleep(1);
ESP_ERROR_CHECK(
esp_event_post(TIMER_EVENTS, TIMER_EVENT_STOPPED, NULL, 0, portMAX_DELAY));
sleep(1);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)