event_source.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_event_loop.h"
  11. #include "esp_timer.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. // This example makes use of two event sources: a periodic timer, and a task.
  16. // Declarations for event source 1: periodic timer
  17. #define TIMER_EXPIRIES_COUNT 3 // number of times the periodic timer expires before being stopped
  18. #define TIMER_PERIOD 1000000 // period of the timer event source in microseconds
  19. extern esp_timer_handle_t g_timer; // the periodic timer object
  20. // Declare an event base
  21. ESP_EVENT_DECLARE_BASE(TIMER_EVENTS); // declaration of the timer events family
  22. enum { // declaration of the specific events under the timer event family
  23. TIMER_EVENT_STARTED, // raised when the timer is first started
  24. TIMER_EVENT_EXPIRY, // raised when a period of the timer has elapsed
  25. TIMER_EVENT_STOPPED // raised when the timer has been stopped
  26. };
  27. // Declarations for event source 2: task
  28. #define TASK_ITERATIONS_COUNT 5 // number of times the task iterates
  29. #define TASK_ITERATIONS_UNREGISTER 3 // count at which the task event handler is unregistered
  30. #define TASK_PERIOD 500 // period of the task loop in milliseconds
  31. ESP_EVENT_DECLARE_BASE(TASK_EVENTS); // declaration of the task events family
  32. enum {
  33. TASK_ITERATION_EVENT, // raised during an iteration of the loop within the task
  34. };
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif // #ifndef EVENT_SOURCE_H_