Skip to content

Commit 05a241a

Browse files
committed
Return Ticker to libraries only for modularity.
1 parent 81820ca commit 05a241a

File tree

6 files changed

+56
-247
lines changed

6 files changed

+56
-247
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ set(CORE_SRCS
5959
cores/esp32/StreamString.cpp
6060
cores/esp32/Tone.cpp
6161
cores/esp32/HWCDC.cpp
62-
cores/esp32/Ticker.cpp
6362
cores/esp32/USB.cpp
6463
cores/esp32/USBCDC.cpp
6564
cores/esp32/USBMSC.cpp

cores/esp32/Ticker.cpp

Lines changed: 0 additions & 86 deletions
This file was deleted.

cores/esp32/Ticker.h

Lines changed: 0 additions & 151 deletions
This file was deleted.

libraries/Ticker/keywords.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ Ticker KEYWORD1
88
# Methods and Functions (KEYWORD2)
99
#######################################
1010

11+
attach_scheduled KEYWORD2
1112
attach KEYWORD2
13+
attach_ms_scheduled KEYWORD2
1214
attach_ms KEYWORD2
15+
once_scheduled KEYWORD2
1316
once KEYWORD2
17+
once_ms_scheduled KEYWORD2
18+
once_ms KEYWORD2
1419
detach KEYWORD2
20+
active KEYWORD2
21+

libraries/Ticker/src/Ticker.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ Ticker::~Ticker()
3434
detach();
3535
}
3636

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+
3742
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)
3848
{
3949
esp_timer_create_args_t _timerConfig;
4050
_timerConfig.arg = reinterpret_cast<void*>(arg);
@@ -47,10 +57,10 @@ void Ticker::_attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t
4757
}
4858
esp_timer_create(&_timerConfig, &_timer);
4959
if (repeat) {
50-
esp_timer_start_periodic(_timer, milliseconds * 1000ULL);
60+
esp_timer_start_periodic(_timer, micros);
5161
}
5262
else {
53-
esp_timer_start_once(_timer, milliseconds * 1000ULL);
63+
esp_timer_start_once(_timer, micros);
5464
}
5565
}
5666

@@ -59,6 +69,7 @@ void Ticker::detach() {
5969
esp_timer_stop(_timer);
6070
esp_timer_delete(_timer);
6171
_timer = nullptr;
72+
_callback_function = nullptr;
6273
}
6374
}
6475

@@ -70,7 +81,7 @@ bool Ticker::active() const {
7081
void Ticker::_static_callback(void* arg)
7182
{
7283
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();
7586
}
7687

0 commit comments

Comments
 (0)