@@ -33,106 +33,106 @@ extern "C" {
33
33
class Ticker
34
34
{
35
35
public:
36
- Ticker ();
37
- ~Ticker ();
38
-
39
- typedef void (*callback_with_arg_t )(void *);
40
- typedef std::function<void (void )> callback_function_t ;
41
-
42
- void attach (float seconds, callback_function_t callback)
43
- {
44
- _callback_function = std::move (callback);
45
- _attach_us (1000000ULL * seconds, true , _static_callback, this );
46
- }
47
-
48
- void attach_ms (uint64_t milliseconds, callback_function_t callback)
49
- {
50
- _callback_function = std::move (callback);
51
- _attach_us (1000ULL * milliseconds, true , _static_callback, this );
52
- }
53
-
54
- void attach_us (uint64_t micros, callback_function_t callback)
55
- {
56
- _callback_function = std::move (callback);
57
- _attach_us (micros, true , _static_callback, this );
58
- }
59
-
60
- template <typename TArg>
61
- void attach (float seconds, void (*callback)(TArg), TArg arg)
62
- {
63
- static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
64
- // C-cast serves two purposes:
65
- // static_cast for smaller integer types,
66
- // reinterpret_cast + const_cast for pointer types
67
- _attach_us (1000000ULL * seconds, true , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
68
- }
69
-
70
- template <typename TArg>
71
- void attach_ms (uint64_t milliseconds, void (*callback)(TArg), TArg arg)
72
- {
73
- static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
74
- _attach_us (1000ULL * milliseconds, true , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
75
- }
76
-
77
- template <typename TArg>
78
- void attach_us (uint64_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), reinterpret_cast <void *>(arg));
82
- }
83
-
84
- void once (float seconds, callback_function_t callback)
85
- {
86
- _callback_function = std::move (callback);
87
- _attach_us (1000000ULL * seconds, false , _static_callback, this );
88
- }
89
-
90
- void once_ms (uint64_t milliseconds, callback_function_t callback)
91
- {
92
- _callback_function = std::move (callback);
93
- _attach_us (1000ULL * milliseconds, false , _static_callback, this );
94
- }
95
-
96
- void once_us (uint64_t micros, callback_function_t callback)
97
- {
98
- _callback_function = std::move (callback);
99
- _attach_us (micros, false , _static_callback, this );
100
- }
101
-
102
- template <typename TArg>
103
- void once (float seconds, void (*callback)(TArg), TArg arg)
104
- {
105
- static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
106
- _attach_us (1000000ULL * seconds, false , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
107
- }
108
-
109
- template <typename TArg>
110
- void once_ms (uint64_t milliseconds, void (*callback)(TArg), TArg arg)
111
- {
112
- static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
113
- _attach_us (1000ULL * milliseconds, false , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
114
- }
115
-
116
- template <typename TArg>
117
- void once_us (uint64_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), reinterpret_cast <void *>(arg));
121
- }
122
-
123
- void detach ();
124
- bool active () const ;
125
-
126
- protected:
127
- static void _static_callback (void * arg);
128
-
129
- callback_function_t _callback_function = nullptr ;
130
-
131
- esp_timer_handle_t _timer;
36
+ Ticker ();
37
+ ~Ticker ();
38
+
39
+ typedef void (*callback_with_arg_t )(void *);
40
+ typedef std::function<void (void )> callback_function_t ;
41
+
42
+ void attach (float seconds, callback_function_t callback)
43
+ {
44
+ _callback_function = std::move (callback);
45
+ _attach_us (1000000ULL * seconds, true , _static_callback, this );
46
+ }
47
+
48
+ void attach_ms (uint64_t milliseconds, callback_function_t callback)
49
+ {
50
+ _callback_function = std::move (callback);
51
+ _attach_us (1000ULL * milliseconds, true , _static_callback, this );
52
+ }
53
+
54
+ void attach_us (uint64_t micros, callback_function_t callback)
55
+ {
56
+ _callback_function = std::move (callback);
57
+ _attach_us (micros, true , _static_callback, this );
58
+ }
59
+
60
+ template <typename TArg>
61
+ void attach (float seconds, void (*callback)(TArg), TArg arg)
62
+ {
63
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
64
+ // C-cast serves two purposes:
65
+ // static_cast for smaller integer types,
66
+ // reinterpret_cast + const_cast for pointer types
67
+ _attach_us (1000000ULL * seconds, true , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
68
+ }
69
+
70
+ template <typename TArg>
71
+ void attach_ms (uint64_t milliseconds, void (*callback)(TArg), TArg arg)
72
+ {
73
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
74
+ _attach_us (1000ULL * milliseconds, true , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
75
+ }
76
+
77
+ template <typename TArg>
78
+ void attach_us (uint64_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), reinterpret_cast <void *>(arg));
82
+ }
83
+
84
+ void once (float seconds, callback_function_t callback)
85
+ {
86
+ _callback_function = std::move (callback);
87
+ _attach_us (1000000ULL * seconds, false , _static_callback, this );
88
+ }
89
+
90
+ void once_ms (uint64_t milliseconds, callback_function_t callback)
91
+ {
92
+ _callback_function = std::move (callback);
93
+ _attach_us (1000ULL * milliseconds, false , _static_callback, this );
94
+ }
95
+
96
+ void once_us (uint64_t micros, callback_function_t callback)
97
+ {
98
+ _callback_function = std::move (callback);
99
+ _attach_us (micros, false , _static_callback, this );
100
+ }
101
+
102
+ template <typename TArg>
103
+ void once (float seconds, void (*callback)(TArg), TArg arg)
104
+ {
105
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
106
+ _attach_us (1000000ULL * seconds, false , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
107
+ }
108
+
109
+ template <typename TArg>
110
+ void once_ms (uint64_t milliseconds, void (*callback)(TArg), TArg arg)
111
+ {
112
+ static_assert (sizeof (TArg) <= sizeof (void *), " attach() callback argument size must be <= sizeof(void*)" );
113
+ _attach_us (1000ULL * milliseconds, false , reinterpret_cast <callback_with_arg_t >(callback), reinterpret_cast <void *>(arg));
114
+ }
115
+
116
+ template <typename TArg>
117
+ void once_us (uint64_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), reinterpret_cast <void *>(arg));
121
+ }
122
+
123
+ void detach ();
124
+ bool active () const ;
125
+
126
+ protected:
127
+ static void _static_callback (void * arg);
128
+
129
+ callback_function_t _callback_function = nullptr ;
130
+
131
+ esp_timer_handle_t _timer;
132
132
133
133
private:
134
- void _attach_us (uint64_t micros, bool repeat, callback_with_arg_t callback, void * arg);
135
- };
134
+ void _attach_us (uint64_t micros, bool repeat, callback_with_arg_t callback, void * arg);
135
+ };
136
136
137
137
138
- #endif // TICKER_H
138
+ #endif // TICKER_H
0 commit comments