GY-63_MS5611/libraries/Interval/Interval.h

73 lines
1.8 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: Interval.h
// AUTHOR: Rob Tillaart
// DATE: 2020-07-21
2022-11-14 13:10:33 -05:00
// VERSION: 0.1.3
2021-01-29 06:31:58 -05:00
// PURPOSE: Arduino library for Interval datatype
// URL: https://github.com/RobTillaart/Interval
//
// HISTORY:
// see Interval.cpp file
2021-05-28 07:35:27 -04:00
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2022-11-14 13:10:33 -05:00
#define INTERVAL_LIB_VERSION (F("0.1.3"))
2021-05-28 07:35:27 -04:00
2021-01-29 06:31:58 -05:00
class Interval: public Printable
{
2021-05-28 07:35:27 -04:00
public:
2022-11-14 13:10:33 -05:00
// CONSTRUCTOR
2021-01-29 06:31:58 -05:00
Interval();
Interval(float lo, float hi);
Interval(float f); // default zero interval [f, f]
2022-11-14 13:10:33 -05:00
// PRINTABLE
2021-01-29 06:31:58 -05:00
size_t printTo(Print& p) const;
void setDecimals(uint8_t n) { _decimals = n; };
2022-11-14 13:10:33 -05:00
// BASE FUNCTIONS
2021-01-29 06:31:58 -05:00
float value() { return (_hi /2 + _lo /2); }; // assumption
float range() { return _hi -_lo; };
float high() { return _hi; };
float low() { return _lo; };
float relAccuracy();
void setRange(float r);
2022-11-14 13:10:33 -05:00
// MATH OPERATORS
2021-01-29 06:31:58 -05:00
Interval operator + (const Interval&);
Interval operator - (const Interval&);
Interval operator * (const Interval&);
Interval operator / (const Interval&);
Interval operator += (const Interval&);
Interval operator -= (const Interval&);
Interval operator *= (const Interval&);
Interval operator /= (const Interval&);
2022-11-14 13:10:33 -05:00
// COMPARISON OPERATORS - compares value()
2021-01-29 06:31:58 -05:00
bool operator == (const Interval&);
bool operator != (const Interval&);
// bool operator > (const Interval&);
// bool operator >= (const Interval&);
// bool operator < (const Interval&);
// bool operator <= (const Interval&);
2022-11-14 13:10:33 -05:00
// SET OPERATORS
2021-01-29 06:31:58 -05:00
// Interval operator & (const Interval&); // common part [1, 5] & [4, 8] => [4, 5]
// Interval operator | (const Interval&); // superset [1, 5] | [4, 8] => [1, 8]
// Interval operator ^ (const Interval&); //
// smaller
2021-05-28 07:35:27 -04:00
private:
2021-01-29 06:31:58 -05:00
float _lo;
float _hi;
uint8_t _decimals = 3;
};
// -- END OF FILE --
2022-11-14 13:10:33 -05:00