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

58 lines
1.3 KiB
C
Raw Normal View History

2020-11-27 05:16:22 -05:00
#pragma once
2014-11-02 11:24:21 -05:00
//
// FILE: FastMap.h
// AUTHOR: Rob Tillaart
2022-11-05 05:57:25 -04:00
// VERSION: 0.4.0
// PURPOSE: class with fast map function - library for Arduino
2020-11-27 05:16:22 -05:00
// URL: https://github.com/RobTillaart/FastMap
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2014-11-02 11:24:21 -05:00
2022-11-05 05:57:25 -04:00
#define FASTMAP_LIB_VERSION (F("0.4.0"))
2014-11-02 11:24:21 -05:00
class FastMap
{
public:
2022-11-05 05:57:25 -04:00
FastMap();
2014-11-02 11:24:21 -05:00
2022-11-05 05:57:25 -04:00
bool init(float in_min, float in_max, float out_min, float out_max);
2022-11-05 05:57:25 -04:00
float inline map (const float value) { return _base + value * _factor; }
float inline back (const float value) { return _backbase + value * _backfactor; }
2022-11-05 05:57:25 -04:00
float constrainedMap(const float value);
float lowerConstrainedMap(const float value);
float upperConstrainedMap(const float value);
2014-11-02 11:24:21 -05:00
private:
2022-11-05 05:57:25 -04:00
float _in_min, _in_max, _out_min, _out_max;
float _factor, _base;
float _backfactor, _backbase;
2014-11-02 11:24:21 -05:00
};
2017-07-27 09:26:36 -04:00
2020-11-27 05:16:22 -05:00
class FastMapDouble
{
public:
2022-11-05 05:57:25 -04:00
FastMapDouble();
bool init(double in_min, double in_max, double out_min, double out_max);
2020-11-27 05:16:22 -05:00
2022-11-05 05:57:25 -04:00
double inline map (const double value) { return _base + value * _factor; }
double inline back (const double value) { return _backbase + value * _backfactor; }
2020-11-27 05:16:22 -05:00
2022-11-05 05:57:25 -04:00
double constrainedMap(const double value);
double lowerConstrainedMap(const double value);
double upperConstrainedMap(const double value);
2020-11-27 05:16:22 -05:00
private:
2022-11-05 05:57:25 -04:00
double _in_min, _in_max, _out_min, _out_max;
double _factor, _base;
double _backfactor, _backbase;
2020-11-27 05:16:22 -05:00
};
// -- END OF FILE --