mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-25 20:02:37 +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:
parent
9cfbbc7ad3
commit
89837fcea5
@ -22,20 +22,18 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
#include "c_types.h"
|
||||
#include "eagle_soc.h"
|
||||
#include "ets_sys.h"
|
||||
#include "osapi.h"
|
||||
}
|
||||
|
||||
const int ONCE = 0;
|
||||
const int REPEAT = 1;
|
||||
static const int ONCE = 0;
|
||||
static const int REPEAT = 1;
|
||||
|
||||
#include "Ticker.h"
|
||||
|
||||
Ticker::Ticker()
|
||||
: _timer(0)
|
||||
: _timer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -66,5 +64,10 @@ void Ticker::detach()
|
||||
|
||||
os_timer_disarm(_timer);
|
||||
delete _timer;
|
||||
_timer = 0;
|
||||
_timer = nullptr;
|
||||
}
|
||||
|
||||
bool Ticker::active()
|
||||
{
|
||||
return (bool)_timer;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#define TICKER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
extern "C" {
|
||||
@ -93,6 +94,7 @@ public:
|
||||
}
|
||||
|
||||
void detach();
|
||||
bool active();
|
||||
|
||||
protected:
|
||||
void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, uint32_t arg);
|
||||
|
@ -15,6 +15,7 @@ attach_ms KEYWORD2
|
||||
once KEYWORD2
|
||||
once_ms KEYWORD2
|
||||
detach KEYWORD2
|
||||
active KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user