@@ -34,7 +34,17 @@ Ticker::~Ticker()
34
34
detach ();
35
35
}
36
36
37
+ void Ticker::_attach_s (float seconds, bool repeat, callback_with_arg_t callback, void * arg)
38
+ {
39
+ _attach_us (1000000ULL * seconds, repeat, callback, arg);
40
+ }
41
+
37
42
void Ticker::_attach_ms (uint32_t milliseconds, bool repeat, callback_with_arg_t callback, void * arg)
43
+ {
44
+ _attach_us (1000ULL * milliseconds, repeat, callback, arg);
45
+ }
46
+
47
+ void Ticker::_attach_us (uint32_t micros, bool repeat, callback_with_arg_t callback, void * arg)
38
48
{
39
49
esp_timer_create_args_t _timerConfig;
40
50
_timerConfig.arg = reinterpret_cast <void *>(arg);
@@ -47,10 +57,10 @@ void Ticker::_attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t
47
57
}
48
58
esp_timer_create (&_timerConfig, &_timer);
49
59
if (repeat) {
50
- esp_timer_start_periodic (_timer, milliseconds * 1000ULL );
60
+ esp_timer_start_periodic (_timer, micros );
51
61
}
52
62
else {
53
- esp_timer_start_once (_timer, milliseconds * 1000ULL );
63
+ esp_timer_start_once (_timer, micros );
54
64
}
55
65
}
56
66
@@ -59,6 +69,7 @@ void Ticker::detach() {
59
69
esp_timer_stop (_timer);
60
70
esp_timer_delete (_timer);
61
71
_timer = nullptr ;
72
+ _callback_function = nullptr ;
62
73
}
63
74
}
64
75
@@ -70,6 +81,6 @@ bool Ticker::active() const
70
81
void Ticker::_static_callback (void * arg)
71
82
{
72
83
Ticker* _this = reinterpret_cast <Ticker*>(arg);
73
- if (! _this) return ;
74
- if (_this-> _callback_function ) _this->_callback_function ();
84
+ if (_this && _this-> _callback_function )
85
+ _this->_callback_function ();
75
86
}
0 commit comments