Skip to content

Commit 80e07d3

Browse files
authored
feat(ticker): extend ticker by adding restart timer options (#12240)
* Add restart methods for timer with different units * Fix missing closing parenthesis in restart methods * change(Ticker): implement the methods in CPP and leave just the declarations in the header change(Ticker): implement the methods in CPP and leave just the declarations in the header * change(Ticker): Refactor restart methods for better clarity and usability. change(Ticker): Refactor restart methods for better clarity and usability. * change(Ticker): Add restart keywords to keywords.txt change(Ticker): Add restart keywords to keywords.txt
1 parent bc82942 commit 80e07d3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

libraries/Ticker/keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ attach_us KEYWORD2
1414
once KEYWORD2
1515
once_ms KEYWORD2
1616
once_us KEYWORD2
17+
restart KEYWORD2
18+
restart_ms KEYWORD2
19+
restart_us KEYWORD2
1720
detach KEYWORD2
1821
active KEYWORD2

libraries/Ticker/src/Ticker.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,21 @@ void Ticker::_static_callback(void *arg) {
7070
_this->_callback_function();
7171
}
7272
}
73+
74+
void Ticker::restart(float seconds) {
75+
if (active()) {
76+
esp_timer_restart(_timer, 1000000ULL * seconds);
77+
}
78+
}
79+
80+
void Ticker::restart_ms(uint64_t milliseconds) {
81+
if (active()) {
82+
esp_timer_restart(_timer, 1000ULL * milliseconds);
83+
}
84+
}
85+
86+
void Ticker::restart_us(uint64_t micros) {
87+
if (active()) {
88+
esp_timer_restart(_timer, micros);
89+
}
90+
}

libraries/Ticker/src/Ticker.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ class Ticker {
101101
_attach_us(micros, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void *>(arg));
102102
}
103103

104+
void restart(float seconds);
105+
void restart_ms(uint64_t milliseconds);
106+
void restart_us(uint64_t micros);
107+
104108
void detach();
105109
bool active() const;
106110

0 commit comments

Comments
 (0)