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