Skip to content

Commit bcf0e7b

Browse files
committed
Revert formatting changes
1 parent a8c2e42 commit bcf0e7b

File tree

2 files changed

+125
-126
lines changed

2 files changed

+125
-126
lines changed

libraries/Ticker/src/Ticker.cpp

+26-27
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,41 @@ Ticker::~Ticker()
3434

3535
void Ticker::_attach_us(uint64_t micros, bool repeat, callback_with_arg_t callback, void* arg)
3636
{
37-
esp_timer_create_args_t _timerConfig;
38-
_timerConfig.arg = reinterpret_cast<void*>(arg);
39-
_timerConfig.callback = callback;
40-
_timerConfig.dispatch_method = ESP_TIMER_TASK;
41-
_timerConfig.name = "Ticker";
42-
if (_timer) {
43-
esp_timer_stop(_timer);
44-
esp_timer_delete(_timer);
45-
}
46-
esp_timer_create(&_timerConfig, &_timer);
47-
if (repeat) {
48-
esp_timer_start_periodic(_timer, micros);
49-
}
50-
else {
51-
esp_timer_start_once(_timer, micros);
52-
}
37+
esp_timer_create_args_t _timerConfig;
38+
_timerConfig.arg = reinterpret_cast<void*>(arg);
39+
_timerConfig.callback = callback;
40+
_timerConfig.dispatch_method = ESP_TIMER_TASK;
41+
_timerConfig.name = "Ticker";
42+
if (_timer) {
43+
esp_timer_stop(_timer);
44+
esp_timer_delete(_timer);
45+
}
46+
esp_timer_create(&_timerConfig, &_timer);
47+
if (repeat) {
48+
esp_timer_start_periodic(_timer, micros);
49+
} else {
50+
esp_timer_start_once(_timer, micros);
51+
}
5352
}
5453

5554
void Ticker::detach() {
56-
if (_timer) {
57-
esp_timer_stop(_timer);
58-
esp_timer_delete(_timer);
59-
_timer = nullptr;
60-
_callback_function = nullptr;
61-
}
55+
if (_timer) {
56+
esp_timer_stop(_timer);
57+
esp_timer_delete(_timer);
58+
_timer = nullptr;
59+
_callback_function = nullptr;
60+
}
6261
}
6362

6463
bool Ticker::active() const {
65-
if (!_timer) return false;
66-
return esp_timer_is_active(_timer);
64+
if (!_timer) return false;
65+
return esp_timer_is_active(_timer);
6766
}
6867

6968
void Ticker::_static_callback(void* arg)
7069
{
71-
Ticker* _this = reinterpret_cast<Ticker*>(arg);
72-
if (_this && _this->_callback_function)
73-
_this->_callback_function();
70+
Ticker* _this = reinterpret_cast<Ticker*>(arg);
71+
if (_this && _this->_callback_function)
72+
_this->_callback_function();
7473
}
7574

libraries/Ticker/src/Ticker.h

+99-99
Original file line numberDiff line numberDiff line change
@@ -33,106 +33,106 @@ extern "C" {
3333
class Ticker
3434
{
3535
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_us(1000000ULL * 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_us(1000ULL * 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_us(1000000ULL * seconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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_us(1000ULL * milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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), reinterpret_cast<void*>(arg));
82-
}
83-
84-
void once(float seconds, callback_function_t callback)
85-
{
86-
_callback_function = std::move(callback);
87-
_attach_us(1000000ULL * 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_us(1000ULL * 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_us(1000000ULL * seconds, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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_us(1000ULL * milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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), reinterpret_cast<void*>(arg));
121-
}
122-
123-
void detach();
124-
bool active() const;
125-
126-
protected:
127-
static void _static_callback(void* arg);
128-
129-
callback_function_t _callback_function = nullptr;
130-
131-
esp_timer_handle_t _timer;
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_us(1000000ULL * 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_us(1000ULL * 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_us(1000000ULL * seconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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_us(1000ULL * milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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), reinterpret_cast<void*>(arg));
82+
}
83+
84+
void once(float seconds, callback_function_t callback)
85+
{
86+
_callback_function = std::move(callback);
87+
_attach_us(1000000ULL * 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_us(1000ULL * 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_us(1000000ULL * seconds, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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_us(1000ULL * milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<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), reinterpret_cast<void*>(arg));
121+
}
122+
123+
void detach();
124+
bool active() const;
125+
126+
protected:
127+
static void _static_callback(void* arg);
128+
129+
callback_function_t _callback_function = nullptr;
130+
131+
esp_timer_handle_t _timer;
132132

133133
private:
134-
void _attach_us(uint64_t micros, bool repeat, callback_with_arg_t callback, void* arg);
135-
};
134+
void _attach_us(uint64_t micros, bool repeat, callback_with_arg_t callback, void* arg);
135+
};
136136

137137

138-
#endif//TICKER_H
138+
#endif // TICKER_H

0 commit comments

Comments
 (0)