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