2021-01-29 12:31:58 +01:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: timing.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-26 14:28:31 +01:00
|
|
|
// VERSION: 0.2.4
|
2021-01-29 12:31:58 +01:00
|
|
|
// PURPOSE: Arduino library with wrapper classes for seconds millis micros
|
|
|
|
// URL: https://github.com/RobTillaart/timing
|
|
|
|
|
|
|
|
|
2022-11-26 14:28:31 +01:00
|
|
|
#define TIMING_LIB_VERSION (F("0.2.4"))
|
2021-05-28 13:47:03 +02:00
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
class microSeconds
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
microSeconds() { set(0); }
|
|
|
|
uint32_t now() { return micros() - _offset; }
|
2021-12-29 11:16:45 +01:00
|
|
|
void set(uint32_t value = 0UL) { _offset = micros() - value; }
|
2021-01-29 12:31:58 +01:00
|
|
|
uint32_t getOffset() { return _offset; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t _offset = 0UL;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class milliSeconds
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
milliSeconds() { set(0); };
|
|
|
|
uint32_t now() { return millis() - _offset; };
|
2021-12-29 11:16:45 +01:00
|
|
|
void set(uint32_t value = 0UL) { _offset = millis() - value; };
|
2021-01-29 12:31:58 +01:00
|
|
|
uint32_t getOffset() { return _offset; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t _offset = 0UL;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class seconds
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
seconds() { set(0); }
|
2022-11-26 14:28:31 +01:00
|
|
|
uint32_t now() { return millis() / 1000UL - _offset; }
|
|
|
|
void set(uint32_t value = 0UL) { _offset = millis() / 1000UL - value; }
|
2021-01-29 12:31:58 +01:00
|
|
|
uint32_t getOffset() { return _offset; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t _offset = 0UL;
|
|
|
|
};
|
|
|
|
|
2021-05-28 13:47:03 +02:00
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
// -- END OF FILE --
|
2021-12-29 11:16:45 +01:00
|
|
|
|