Skip to content

Commit

Permalink
lib/Ticker: add bool active() (esp8266#2722)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
karlp authored and devyte committed Jan 5, 2018
1 parent 9cfbbc7 commit 89837fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions libraries/Ticker/Ticker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -66,5 +64,10 @@ void Ticker::detach()

os_timer_disarm(_timer);
delete _timer;
_timer = 0;
_timer = nullptr;
}

bool Ticker::active()
{
return (bool)_timer;
}
2 changes: 2 additions & 0 deletions libraries/Ticker/Ticker.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define TICKER_H

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

extern "C" {
Expand Down Expand Up @@ -93,6 +94,7 @@ class Ticker
}

void detach();
bool active();

protected:
void _attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t callback, uint32_t arg);
Expand Down
1 change: 1 addition & 0 deletions libraries/Ticker/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ attach_ms KEYWORD2
once KEYWORD2
once_ms KEYWORD2
detach KEYWORD2
active KEYWORD2

#######################################
# Instances (KEYWORD2)
Expand Down

0 comments on commit 89837fc

Please sign in to comment.