Konstruktor pro periodic autostart
This commit is contained in:
parent
acffaeef87
commit
15be6b4674
@ -12,7 +12,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://git.xpablo.cz/pablo2048/Interval.git"
|
"url": "http://git.xpablo.cz/pablo2048/Interval.git"
|
||||||
},
|
},
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=Interval
|
name=Interval
|
||||||
version=0.0.3
|
version=0.0.4
|
||||||
author=Pavel Brychta
|
author=Pavel Brychta
|
||||||
maintainer=Pavel Brychta
|
maintainer=Pavel Brychta
|
||||||
sentence=Make timing by using intervals instead of delay()
|
sentence=Make timing by using intervals instead of delay()
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
extern "C" {
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
}
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "interval.h"
|
#include "interval.h"
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
@ -22,26 +16,22 @@ uint32_t Interval::elapsed(void)
|
|||||||
bool Interval::expired(void)
|
bool Interval::expired(void)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (_done)
|
|
||||||
{
|
if (_done) {
|
||||||
if (1 == _mode)
|
if (1 == _mode) {
|
||||||
{ // oneshot mode
|
// oneshot mode
|
||||||
if ((millis() - _timefrom) >= _timeout)
|
if ((millis() - _timefrom) >= _timeout) {
|
||||||
{
|
|
||||||
_done = 0;
|
_done = 0;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
} else if (2 == _mode) {
|
||||||
else if (2 == _mode)
|
// periodic mode
|
||||||
{ // periodic mode
|
if ((millis() - _timefrom) >= _timeout) {
|
||||||
if ((millis() - _timefrom) >= _timeout)
|
|
||||||
{
|
|
||||||
result = true;
|
result = true;
|
||||||
_timefrom = millis();
|
_timefrom = millis();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
// compatibility mode
|
||||||
{ // compatibility mode
|
|
||||||
if ((millis() - _timefrom) >= _timeout)
|
if ((millis() - _timefrom) >= _timeout)
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
|
#ifndef _INTERVAL_H_
|
||||||
#ifndef interval_h
|
#define _INTERVAL_H_
|
||||||
#define interval_h
|
|
||||||
|
|
||||||
/* Interval
|
/* Interval
|
||||||
* Copyright (C) 2014, 2016, 2018 Pavel Brychta http://www.xpablo.cz
|
* Copyright (C) 2014, 2016, 2018, 2019 Pavel Brychta http://www.xpablo.cz
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the MIT License
|
* This program is free software: you can redistribute it and/or modify it under the terms of the MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
class Interval
|
class Interval
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
uint32_t _timefrom;
|
uint32_t _timefrom;
|
||||||
uint32_t _timeout;
|
uint32_t _timeout;
|
||||||
uint8_t _mode; // mode of actual operation (compatibility, oneshot, periodic)
|
uint8_t _mode; // mode of actual operation (compatibility, oneshot, periodic)
|
||||||
uint8_t _done;
|
uint8_t _done;
|
||||||
public:
|
public:
|
||||||
Interval(): _mode(0), _done(0xff) {}
|
Interval(): _mode(0), _done(0xff) {} // compatibility mode autostart
|
||||||
|
Interval(uint32_t tmout): _timeout(tmout), _mode(2), _done(0xff) {} // periodic mode autostart
|
||||||
bool expired(void);
|
bool expired(void);
|
||||||
void set(uint32_t tmout);
|
void set(uint32_t tmout);
|
||||||
void setOneshot(uint32_t tmout);
|
void setOneshot(uint32_t tmout);
|
||||||
|
Loading…
Reference in New Issue
Block a user