Skip to content

Commit 7b5489e

Browse files
committed
Return Ticker to libraries only for modularity.
squash! Return Ticker to libraries only for modularity.
1 parent ce691dd commit 7b5489e

File tree

4 files changed

+31
-214
lines changed

4 files changed

+31
-214
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ set(CORE_SRCS
3232
cores/esp32/Schedule.cpp
3333
cores/esp32/Stream.cpp
3434
cores/esp32/StreamString.cpp
35-
cores/esp32/Ticker.cpp
3635
cores/esp32/wiring_pulse.c
3736
cores/esp32/wiring_shift.c
3837
cores/esp32/WMath.cpp

cores/esp32/Ticker.cpp

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

cores/esp32/Ticker.h

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

libraries/Ticker/src/Ticker.h

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,37 @@ class Ticker
4040
typedef void (*callback_with_arg_t)(void*);
4141
typedef std::function<void(void)> callback_function_t;
4242

43+
void attach_scheduled(float seconds, callback_function_t callback)
44+
{
45+
attach(seconds, [callback]() { schedule_function(callback); });
46+
}
47+
4348
void attach(float seconds, callback_function_t callback)
4449
{
4550
_callback_function = std::move(callback);
4651
_attach_s(seconds, true, _static_callback, this);
4752
}
4853

54+
void attach_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
55+
{
56+
attach_ms(milliseconds, [callback]() { schedule_function(callback); });
57+
}
58+
4959
void attach_ms(uint32_t milliseconds, callback_function_t callback)
5060
{
5161
_callback_function = std::move(callback);
5262
_attach_ms(milliseconds, true, _static_callback, this);
5363
}
5464

55-
void attach_us(uint32_t micros, callback_function_t callback)
65+
void attach_us_scheduled(uint32_t micros, callback_function_t callback)
5666
{
57-
_callback_function = std::move(callback);
58-
_attach_us(micros, true, _static_callback, this);
67+
attach_us(micros, [callback]() { schedule_function(callback); });
68+
}
5969

60-
void attach_ms(uint32_t milliseconds, callback_function_t callback)
70+
void attach_us(uint32_t micros, callback_function_t callback)
6171
{
6272
_callback_function = std::move(callback);
63-
_attach_ms(milliseconds, true, _static_callback, this);
73+
_attach_us(micros, true, _static_callback, this);
6474
}
6575

6676
template<typename TArg>
@@ -86,19 +96,34 @@ class Ticker
8696
static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)");
8797
_attach_us(micros, true, reinterpret_cast<callback_with_arg_t>(callback), (void*)arg);
8898
}
89-
99+
100+
void once_scheduled(float seconds, callback_function_t callback)
101+
{
102+
once(seconds, [callback]() { schedule_function(callback); });
103+
}
104+
90105
void once(float seconds, callback_function_t callback)
91106
{
92107
_callback_function = std::move(callback);
93108
_attach_s(seconds, false, _static_callback, this);
94109
}
95110

111+
void once_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
112+
{
113+
once_ms(milliseconds, [callback]() { schedule_function(callback); });
114+
}
115+
96116
void once_ms(uint32_t milliseconds, callback_function_t callback)
97117
{
98118
_callback_function = std::move(callback);
99119
_attach_ms(milliseconds, false, _static_callback, this);
100120
}
101121

122+
void once_us_scheduled(uint32_t micros, callback_function_t callback)
123+
{
124+
once_us(micros, [callback]() { schedule_function(callback); });
125+
}
126+
102127
void once_us(uint32_t micros, callback_function_t callback)
103128
{
104129
_callback_function = std::move(callback);

0 commit comments

Comments
 (0)