Skip to content

Commit 89837fc

Browse files
karlpdevyte
authored andcommitted
lib/Ticker: add bool active() (#2722)
* lib/Ticker: add bool active() Makes it easier to self detach, and check if a timer is still operating. Signed-off-by: Karl Palsson <[email protected]> * Code cleanup Ticker.cpp
1 parent 9cfbbc7 commit 89837fc

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

libraries/Ticker/Ticker.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@
2222
#include <stddef.h>
2323
#include <stdint.h>
2424

25-
extern "C" {
2625
#include "c_types.h"
2726
#include "eagle_soc.h"
2827
#include "ets_sys.h"
2928
#include "osapi.h"
30-
}
3129

32-
const int ONCE = 0;
33-
const int REPEAT = 1;
30+
static const int ONCE = 0;
31+
static const int REPEAT = 1;
3432

3533
#include "Ticker.h"
3634

3735
Ticker::Ticker()
38-
: _timer(0)
36+
: _timer(nullptr)
3937
{
4038
}
4139

@@ -66,5 +64,10 @@ void Ticker::detach()
6664

6765
os_timer_disarm(_timer);
6866
delete _timer;
69-
_timer = 0;
67+
_timer = nullptr;
68+
}
69+
70+
bool Ticker::active()
71+
{
72+
return (bool)_timer;
7073
}

libraries/Ticker/Ticker.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define TICKER_H
2424

2525
#include <stdint.h>
26+
#include <stdbool.h>
2627
#include <stddef.h>
2728

2829
extern "C" {
@@ -93,6 +94,7 @@ class Ticker
9394
}
9495

9596
void detach();
97+
bool active();
9698

9799
protected:
98100
void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, uint32_t arg);

libraries/Ticker/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ attach_ms KEYWORD2
1515
once KEYWORD2
1616
once_ms KEYWORD2
1717
detach KEYWORD2
18+
active KEYWORD2
1819

1920
#######################################
2021
# Instances (KEYWORD2)

0 commit comments

Comments
 (0)