event_source.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* esp_event (event loop library) basic example
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #ifndef EVENT_SOURCE_H_
  8. #define EVENT_SOURCE_H_
  9. #include "esp_event.h"
  10. #include "esp_timer.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. // This example makes use of two event sources: a periodic timer, and a task.
  15. // Declarations for event source 1: periodic timer
  16. #define TIMER_EXPIRIES_COUNT 3 // number of times the periodic timer expires before being stopped
  17. #define TIMER_PERIOD 1000000 // period of the timer event source in microseconds
  18. extern esp_timer_handle_t g_timer; // the periodic timer object
  19. // Declare an event base
  20. ESP_EVENT_DECLARE_BASE(TIMER_EVENTS); // declaration of the timer events family
  21. enum { // declaration of the specific events under the timer event family
  22. TIMER_EVENT_STARTED, // raised when the timer is first started
  23. TIMER_EVENT_EXPIRY, // raised when a period of the timer has elapsed
  24. TIMER_EVENT_STOPPED // raised when the timer has been stopped
  25. };
  26. // Declarations for event source 2: task
  27. #define TASK_ITERATIONS_COUNT 5 // number of times the task iterates
  28. #define TASK_ITERATIONS_UNREGISTER 3 // count at which the task event handler is unregistered
  29. #define TASK_PERIOD 500 // period of the task loop in milliseconds
  30. ESP_EVENT_DECLARE_BASE(TASK_EVENTS); // declaration of the task events family
  31. enum {
  32. TASK_ITERATION_EVENT, // raised during an iteration of the loop within the task
  33. };
  34. #ifdef __cplusplus
  35. }
  36. #endif
  37. #endif // #ifndef EVENT_SOURCE_H_