@@ -48,7 +48,7 @@ class Ticker
48
48
void attach (float seconds, callback_function_t callback)
49
49
{
50
50
_callback_function = std::move (callback);
51
- _attach_ms (seconds * 1000 , true , _static_callback, this );
51
+ _attach_s (seconds, true , _static_callback, this );
52
52
}
53
53
54
54
void attach_ms_scheduled (uint32_t milliseconds, callback_function_t callback)
@@ -62,14 +62,25 @@ class Ticker
62
62
_attach_ms (milliseconds, true , _static_callback, this );
63
63
}
64
64
65
+ void attach_us_scheduled (uint32_t micros, callback_function_t callback)
66
+ {
67
+ attach_us (micros, [callback]() { schedule_function (callback); });
68
+ }
69
+
70
+ void attach_us (uint32_t micros, callback_function_t callback)
71
+ {
72
+ _callback_function = std::move (callback);
73
+ _attach_us (micros, true , _static_callback, this );
74
+ }
75
+
65
76
template <typename TArg>
66
77
void attach (float seconds, void (*callback)(TArg), TArg arg)
67
78
{
68
79
static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
69
80
// C-cast serves two purposes:
70
81
// static_cast for smaller integer types,
71
82
// reinterpret_cast + const_cast for pointer types
72
- _attach_ms (seconds * 1000 , true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
83
+ _attach_s (seconds, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
73
84
}
74
85
75
86
template <typename TArg>
@@ -79,15 +90,22 @@ class Ticker
79
90
_attach_ms (milliseconds, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
80
91
}
81
92
93
+ template <typename TArg>
94
+ void attach_us (uint32_t micros, void (*callback)(TArg), TArg arg)
95
+ {
96
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
97
+ _attach_us (micros, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
98
+ }
99
+
82
100
void once_scheduled (float seconds, callback_function_t callback)
83
101
{
84
102
once (seconds, [callback]() { schedule_function (callback); });
85
103
}
86
-
104
+
87
105
void once (float seconds, callback_function_t callback)
88
106
{
89
107
_callback_function = std::move (callback);
90
- _attach_ms (seconds * 1000 , false , _static_callback, this );
108
+ _attach_s (seconds, false , _static_callback, this );
91
109
}
92
110
93
111
void once_ms_scheduled (uint32_t milliseconds, callback_function_t callback)
@@ -101,11 +119,22 @@ class Ticker
101
119
_attach_ms (milliseconds, false , _static_callback, this );
102
120
}
103
121
122
+ void once_us_scheduled (uint32_t micros, callback_function_t callback)
123
+ {
124
+ once_us (micros, [callback]() { schedule_function (callback); });
125
+ }
126
+
127
+ void once_us (uint32_t micros, callback_function_t callback)
128
+ {
129
+ _callback_function = std::move (callback);
130
+ _attach_us (micros, false , _static_callback, this );
131
+ }
132
+
104
133
template <typename TArg>
105
134
void once (float seconds, void (*callback)(TArg), TArg arg)
106
135
{
107
136
static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
108
- _attach_ms (seconds * 1000 , false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
137
+ _attach_s (seconds, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
109
138
}
110
139
111
140
template <typename TArg>
@@ -115,6 +144,13 @@ class Ticker
115
144
_attach_ms (milliseconds, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
116
145
}
117
146
147
+ template <typename TArg>
148
+ void once_us (uint32_t micros, void (*callback)(TArg), TArg arg)
149
+ {
150
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
151
+ _attach_us (micros, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
152
+ }
153
+
118
154
void detach ();
119
155
bool active () const ;
120
156
@@ -124,8 +160,11 @@ class Ticker
124
160
125
161
callback_function_t _callback_function = nullptr ;
126
162
127
- protected:
128
163
esp_timer_handle_t _timer;
164
+
165
+ private:
166
+ void _attach_us (uint32_t micros, bool repeat, callback_with_arg_t callback, void * arg);
167
+ void _attach_s (float seconds, bool repeat, callback_with_arg_t callback, void * arg);
129
168
};
130
169
131
170
0 commit comments