1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00

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 <karlp@tweak.net.au>

* Code cleanup Ticker.cpp
This commit is contained in:
Karl Palsson 2018-01-05 04:04:53 +00:00 committed by Develo
parent 9cfbbc7ad3
commit 89837fcea5
3 changed files with 12 additions and 6 deletions

View File

@ -22,20 +22,18 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
extern "C" {
#include "c_types.h" #include "c_types.h"
#include "eagle_soc.h" #include "eagle_soc.h"
#include "ets_sys.h" #include "ets_sys.h"
#include "osapi.h" #include "osapi.h"
}
const int ONCE = 0; static const int ONCE = 0;
const int REPEAT = 1; static const int REPEAT = 1;
#include "Ticker.h" #include "Ticker.h"
Ticker::Ticker() Ticker::Ticker()
: _timer(0) : _timer(nullptr)
{ {
} }
@ -66,5 +64,10 @@ void Ticker::detach()
os_timer_disarm(_timer); os_timer_disarm(_timer);
delete _timer; delete _timer;
_timer = 0; _timer = nullptr;
}
bool Ticker::active()
{
return (bool)_timer;
} }

View File

@ -23,6 +23,7 @@
#define TICKER_H #define TICKER_H
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
extern "C" { extern "C" {
@ -93,6 +94,7 @@ public:
} }
void detach(); void detach();
bool active();
protected: protected:
void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, uint32_t arg); void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, uint32_t arg);

View File

@ -15,6 +15,7 @@ attach_ms KEYWORD2
once KEYWORD2 once KEYWORD2
once_ms KEYWORD2 once_ms KEYWORD2
detach KEYWORD2 detach KEYWORD2
active KEYWORD2
####################################### #######################################
# Instances (KEYWORD2) # Instances (KEYWORD2)