@@ -42,7 +42,7 @@ class Ticker
42
42
void attach (float seconds, callback_function_t callback)
43
43
{
44
44
_callback_function = std::move (callback);
45
- _attach_ms (seconds * 1000 , true , _static_callback, this );
45
+ _attach_s (seconds, true , _static_callback, this );
46
46
}
47
47
48
48
void attach_ms (uint32_t milliseconds, callback_function_t callback)
@@ -51,14 +51,20 @@ class Ticker
51
51
_attach_ms (milliseconds, true , _static_callback, this );
52
52
}
53
53
54
+ void attach_us (uint32_t micros, callback_function_t callback)
55
+ {
56
+ _callback_function = std::move (callback);
57
+ _attach_us (micros, true , _static_callback, this );
58
+ }
59
+
54
60
template <typename TArg>
55
61
void attach (float seconds, void (*callback)(TArg), TArg arg)
56
62
{
57
63
static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
58
64
// C-cast serves two purposes:
59
65
// static_cast for smaller integer types,
60
66
// reinterpret_cast + const_cast for pointer types
61
- _attach_ms (seconds * 1000 , true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
67
+ _attach_s (seconds, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
62
68
}
63
69
64
70
template <typename TArg>
@@ -68,10 +74,17 @@ class Ticker
68
74
_attach_ms (milliseconds, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
69
75
}
70
76
77
+ template <typename TArg>
78
+ void attach_us (uint32_t micros, void (*callback)(TArg), TArg arg)
79
+ {
80
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
81
+ _attach_us (micros, true , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
82
+ }
83
+
71
84
void once (float seconds, callback_function_t callback)
72
85
{
73
86
_callback_function = std::move (callback);
74
- _attach_ms (seconds * 1000 , false , _static_callback, this );
87
+ _attach_s (seconds, false , _static_callback, this );
75
88
}
76
89
77
90
void once_ms (uint32_t milliseconds, callback_function_t callback)
@@ -80,11 +93,17 @@ class Ticker
80
93
_attach_ms (milliseconds, false , _static_callback, this );
81
94
}
82
95
96
+ void once_us (uint32_t micros, callback_function_t callback)
97
+ {
98
+ _callback_function = std::move (callback);
99
+ _attach_us (micros, false , _static_callback, this );
100
+ }
101
+
83
102
template <typename TArg>
84
103
void once (float seconds, void (*callback)(TArg), TArg arg)
85
104
{
86
105
static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
87
- _attach_ms (seconds * 1000 , false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
106
+ _attach_s (seconds, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
88
107
}
89
108
90
109
template <typename TArg>
@@ -94,6 +113,13 @@ class Ticker
94
113
_attach_ms (milliseconds, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
95
114
}
96
115
116
+ template <typename TArg>
117
+ void once_us (uint32_t micros, void (*callback)(TArg), TArg arg)
118
+ {
119
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
120
+ _attach_us (micros, false , reinterpret_cast <callback_with_arg_t >(callback), (void *)arg);
121
+ }
122
+
97
123
void detach ();
98
124
bool active () const ;
99
125
@@ -103,8 +129,11 @@ class Ticker
103
129
104
130
callback_function_t _callback_function = nullptr ;
105
131
106
- protected:
107
132
esp_timer_handle_t _timer;
133
+
134
+ private:
135
+ void _attach_us (uint32_t micros, bool repeat, callback_with_arg_t callback, void * arg);
136
+ void _attach_s (float seconds, bool repeat, callback_with_arg_t callback, void * arg);
108
137
};
109
138
110
139
0 commit comments