@@ -29,6 +29,7 @@ extern "C" {
29
29
#include " esp_timer.h"
30
30
}
31
31
#include < functional>
32
+ #include < Schedule.h>
32
33
33
34
class Ticker
34
35
{
@@ -51,6 +52,17 @@ class Ticker
51
52
_attach_ms (milliseconds, true , _static_callback, this );
52
53
}
53
54
55
+ void attach_us_scheduled (uint32_t micros, callback_function_t callback)
56
+ {
57
+ attach_us (micros, [callback]() { schedule_function (callback); });
58
+ }
59
+
60
+ void attach_us (uint32_t micros, callback_function_t callback)
61
+ {
62
+ _callback_function = std::move (callback);
63
+ _attach_us (micros, true , _static_callback, this );
64
+ }
65
+
54
66
template <typename TArg>
55
67
void attach (float seconds, void (*callback)(TArg), TArg arg)
56
68
{
@@ -68,6 +80,13 @@ class Ticker
68
80
_attach_ms (milliseconds, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
69
81
}
70
82
83
+ template <typename TArg>
84
+ void attach_us (uint32_t micros, void (*callback)(TArg), TArg arg)
85
+ {
86
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
87
+ _attach_us (micros, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
88
+ }
89
+
71
90
void once (float seconds, callback_function_t callback)
72
91
{
73
92
_callback_function = std::move (callback);
@@ -80,6 +99,17 @@ class Ticker
80
99
_attach_ms (milliseconds, false , _static_callback, this );
81
100
}
82
101
102
+ void once_us_scheduled (uint32_t micros, callback_function_t callback)
103
+ {
104
+ once_us (micros, [callback]() { schedule_function (callback); });
105
+ }
106
+
107
+ void once_us (uint32_t micros, callback_function_t callback)
108
+ {
109
+ _callback_function = std::move (callback);
110
+ _attach_us (micros, false , _static_callback, this );
111
+ }
112
+
83
113
template <typename TArg>
84
114
void once (float seconds, void (*callback)(TArg), TArg arg)
85
115
{
@@ -94,6 +124,13 @@ class Ticker
94
124
_attach_ms (milliseconds, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
95
125
}
96
126
127
+ template <typename TArg>
128
+ void once_us (uint32_t micros, void (*callback)(TArg), TArg arg)
129
+ {
130
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
131
+ _attach_us (micros, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
132
+ }
133
+
97
134
void detach ();
98
135
bool active () const ;
99
136
0 commit comments