Skip to content

Commit cab7657

Browse files
committed
Inlining via header has better baseline ROM footprint.
1 parent 00c5313 commit cab7657

File tree

2 files changed

+47
-68
lines changed

2 files changed

+47
-68
lines changed

libraries/Ticker/src/Ticker.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,55 +33,6 @@ Ticker::~Ticker()
3333
detach();
3434
}
3535

36-
void Ticker::attach(float seconds, callback_function_t callback)
37-
{
38-
_callback_function = std::move(callback);
39-
_attach_ms(1000UL * seconds, true, _static_callback, this);
40-
}
41-
42-
void Ticker::attach_ms(uint32_t milliseconds, callback_function_t callback)
43-
{
44-
_callback_function = std::move(callback);
45-
_attach_ms(milliseconds, true, _static_callback, this);
46-
}
47-
48-
void Ticker::attach_scheduled(float seconds, callback_function_t callback)
49-
{
50-
attach(seconds, [callback]() { schedule_function(callback); });
51-
}
52-
53-
void Ticker::attach_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
54-
{
55-
attach_ms(milliseconds, [callback]() { schedule_function(callback); });
56-
}
57-
58-
void Ticker::once(float seconds, callback_function_t callback)
59-
{
60-
_callback_function = std::move(callback);
61-
_attach_ms(1000UL * seconds, false, _static_callback, this);
62-
}
63-
64-
void Ticker::once_ms(uint32_t milliseconds, callback_function_t callback)
65-
{
66-
_callback_function = std::move(callback);
67-
_attach_ms(milliseconds, false, _static_callback, this);
68-
}
69-
70-
void Ticker::once_scheduled(float seconds, callback_function_t callback)
71-
{
72-
once(seconds, [callback]() { schedule_function(callback); });
73-
}
74-
75-
void Ticker::once_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
76-
{
77-
once_ms(milliseconds, [callback]() { schedule_function(callback); });
78-
}
79-
80-
void Ticker::_attach_s(float seconds, bool repeat, callback_with_arg_t callback, void* arg)
81-
{
82-
_attach_ms(1000UL * seconds, repeat, callback, arg);
83-
}
84-
8536
void Ticker::_attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, void* arg)
8637
{
8738
if (_timer)

libraries/Ticker/src/Ticker.h

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,25 @@ class Ticker
3535
typedef void (*callback_with_arg_t)(void*);
3636
typedef std::function<void(void)> callback_function_t;
3737

38-
void attach(float seconds, callback_function_t callback);
39-
void attach_ms(uint32_t milliseconds, callback_function_t callback);
40-
void attach_scheduled(float seconds, callback_function_t callback);
41-
void attach_ms_scheduled(uint32_t milliseconds, callback_function_t callback);
38+
void attach_ms(uint32_t milliseconds, callback_function_t callback)
39+
{
40+
_callback_function = std::move(callback);
41+
_attach_ms(milliseconds, true, _static_callback, this);
42+
}
4243

43-
template<typename TArg>
44-
void attach(float seconds, void (*callback)(TArg), TArg arg)
44+
void attach(float seconds, callback_function_t callback)
4545
{
46-
static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)");
47-
// C-cast serves two purposes:
48-
// static_cast for smaller integer types,
49-
// reinterpret_cast + const_cast for pointer types
50-
_attach_s(seconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void*>(arg));
46+
attach_ms(1000UL * seconds, callback);
47+
}
48+
49+
void attach_scheduled(float seconds, callback_function_t callback)
50+
{
51+
attach(seconds, [callback]() { schedule_function(callback); });
52+
}
53+
54+
void attach_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
55+
{
56+
attach_ms(milliseconds, [callback]() { schedule_function(callback); });
5157
}
5258

5359
template<typename TArg>
@@ -57,16 +63,32 @@ class Ticker
5763
_attach_ms(milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void*>(arg));
5864
}
5965

60-
void once(float seconds, callback_function_t callback);
61-
void once_ms(uint32_t milliseconds, callback_function_t callback);
62-
void once_scheduled(float seconds, callback_function_t callback);
63-
void once_ms_scheduled(uint32_t milliseconds, callback_function_t callback);
64-
6566
template<typename TArg>
66-
void once(float seconds, void (*callback)(TArg), TArg arg)
67+
void attach(float seconds, void (*callback)(TArg), TArg arg)
6768
{
6869
static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)");
69-
_attach_s(seconds, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void*>(arg));
70+
attach_ms(1000UL * seconds, callback, arg);
71+
}
72+
73+
void once_ms(uint32_t milliseconds, callback_function_t callback)
74+
{
75+
_callback_function = std::move(callback);
76+
_attach_ms(milliseconds, false, _static_callback, this);
77+
}
78+
79+
void once(float seconds, callback_function_t callback)
80+
{
81+
once_ms(1000UL * seconds, callback);
82+
}
83+
84+
void once_scheduled(float seconds, callback_function_t callback)
85+
{
86+
once(seconds, [callback]() { schedule_function(callback); });
87+
}
88+
89+
void once_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
90+
{
91+
once_ms(milliseconds, [callback]() { schedule_function(callback); });
7092
}
7193

7294
template<typename TArg>
@@ -76,12 +98,18 @@ class Ticker
7698
_attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void*>(arg));
7799
}
78100

101+
template<typename TArg>
102+
void once(float seconds, void (*callback)(TArg), TArg arg)
103+
{
104+
static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)");
105+
once_ms(1000UL * seconds, callback, arg);
106+
}
107+
79108
void detach();
80109
bool active() const;
81110

82111
protected:
83112
static void _static_callback(void* arg);
84-
void _attach_s(float seconds, bool repeat, callback_with_arg_t callback, void* arg);
85113
void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, void* arg);
86114

87115
ETSTimer* _timer;

0 commit comments

Comments
 (0)