Konstruktor pro periodic autostart

This commit is contained in:
Pavel Brychta 2019-10-09 09:41:11 +02:00
parent acffaeef87
commit 15be6b4674
4 changed files with 58 additions and 68 deletions

View File

@ -12,7 +12,7 @@
"type": "git",
"url": "http://git.xpablo.cz/pablo2048/Interval.git"
},
"version": "0.0.3",
"version": "0.0.4",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=Interval
version=0.0.3
version=0.0.4
author=Pavel Brychta
maintainer=Pavel Brychta
sentence=Make timing by using intervals instead of delay()

View File

@ -1,9 +1,3 @@
extern "C" {
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
}
#include <Arduino.h>
#include "interval.h"
// Public Methods //////////////////////////////////////////////////////////////
@ -22,26 +16,22 @@ uint32_t Interval::elapsed(void)
bool Interval::expired(void)
{
bool result = false;
if (_done)
{
if (1 == _mode)
{ // oneshot mode
if ((millis() - _timefrom) >= _timeout)
{
if (_done) {
if (1 == _mode) {
// oneshot mode
if ((millis() - _timefrom) >= _timeout) {
_done = 0;
result = true;
}
}
else if (2 == _mode)
{ // periodic mode
if ((millis() - _timefrom) >= _timeout)
{
} else if (2 == _mode) {
// periodic mode
if ((millis() - _timefrom) >= _timeout) {
result = true;
_timefrom = millis();
}
}
else
{ // compatibility mode
} else {
// compatibility mode
if ((millis() - _timefrom) >= _timeout)
result = true;
}

View File

@ -1,24 +1,24 @@
#ifndef interval_h
#define interval_h
#ifndef _INTERVAL_H_
#define _INTERVAL_H_
/* 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
*/
#include <inttypes.h>
#include <Arduino.h>
class Interval
{
protected:
protected:
uint32_t _timefrom;
uint32_t _timeout;
uint8_t _mode; // mode of actual operation (compatibility, oneshot, periodic)
uint8_t _done;
public:
Interval(): _mode(0), _done(0xff) {}
public:
Interval(): _mode(0), _done(0xff) {} // compatibility mode autostart
Interval(uint32_t tmout): _timeout(tmout), _mode(2), _done(0xff) {} // periodic mode autostart
bool expired(void);
void set(uint32_t tmout);
void setOneshot(uint32_t tmout);