mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Ticker library
This commit is contained in:
48
libraries/Ticker/Ticker.cpp
Normal file
48
libraries/Ticker/Ticker.cpp
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user