@@ -29,6 +29,7 @@ extern "C" {
2929#include " esp_timer.h"
3030}
3131#include < functional>
32+ #include < Schedule.h>
3233
3334class Ticker
3435{
@@ -51,6 +52,17 @@ class Ticker
5152 _attach_ms (milliseconds, true , _static_callback, this );
5253 }
5354
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+
5466 template <typename TArg>
5567 void attach (float seconds, void (*callback)(TArg), TArg arg)
5668 {
@@ -68,6 +80,13 @@ class Ticker
6880 _attach_ms (milliseconds, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
6981 }
7082
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+
7190 void once (float seconds, callback_function_t callback)
7291 {
7392 _callback_function = std::move (callback);
@@ -80,6 +99,17 @@ class Ticker
8099 _attach_ms (milliseconds, false , _static_callback, this );
81100 }
82101
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+
83113 template <typename TArg>
84114 void once (float seconds, void (*callback)(TArg), TArg arg)
85115 {
@@ -94,6 +124,13 @@ class Ticker
94124 _attach_ms (milliseconds, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
95125 }
96126
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+
97134 void detach ();
98135 bool active () const ;
99136
0 commit comments