1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Ticker library

This commit is contained in:
Ivan Grokhotkov
2014-12-19 01:43:40 +03:00
parent 4cf6737823
commit b22a803d53
6 changed files with 223 additions and 0 deletions

View File

@ -0,0 +1,48 @@
#include <stddef.h>
#include <stdint.h>
extern "C" {
#include "c_types.h"
#include "eagle_soc.h"
#include "ets_sys.h"
#include "osapi.h"
}
#include "Ticker.h"
Ticker::Ticker()
: _timer(0)
{
}
Ticker::~Ticker()
{
detach();
}
void Ticker::_attach_ms(callback_with_arg_t callback, uint32_t milliseconds, void* arg)
{
const int REPEAT = 1;
if (_timer)
{
os_timer_disarm(_timer);
}
else
{
_timer = new ETSTimer;
}
os_timer_setfn(_timer, reinterpret_cast<ETSTimerFunc*>(callback), arg);
os_timer_arm(_timer, milliseconds, REPEAT);
}
void Ticker::detach()
{
if (!_timer)
return;
os_timer_disarm(_timer);
delete _timer;
_timer = 0;
}