mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
+ version 0.1.06
+ replaced float with double to support ARM (DUE) too
This commit is contained in:
parent
740d030b1b
commit
b3c0f3e85f
@ -1,12 +1,13 @@
|
||||
//
|
||||
// FILE: FastMap.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.05
|
||||
// VERSION: 0.1.06
|
||||
// PURPOSE: class implementation of map function - library for Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=276194
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.05 stripped of bit mask experimental code
|
||||
// 0.1.06 2015-03-08 replaced double by double (support ARM)
|
||||
// 0.1.05 2014-11-02 stripped of bit mask experimental code
|
||||
// 0.1.04 add back() - the inverse map
|
||||
// tested with bit mask for constrain code (Perfomance was killed)
|
||||
// 0.1.03 proper name
|
||||
@ -21,7 +22,7 @@
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
void FastMap::init(float in_min, float in_max, float out_min, float out_max)
|
||||
void FastMap::init(double in_min, double in_max, double out_min, double out_max)
|
||||
{
|
||||
_in_min = in_min;
|
||||
_in_max = in_max;
|
||||
@ -35,20 +36,20 @@ void FastMap::init(float in_min, float in_max, float out_min, float out_max)
|
||||
_backbase = in_min - out_min * _backfactor;
|
||||
}
|
||||
|
||||
float FastMap::constrainedMap(float value)
|
||||
double FastMap::constrainedMap(double value)
|
||||
{
|
||||
if (value <= _in_min) return _out_min;
|
||||
if (value >= _in_max) return _out_max;
|
||||
return this->map(value);
|
||||
}
|
||||
|
||||
float FastMap::lowerConstrainedMap(float value)
|
||||
double FastMap::lowerConstrainedMap(double value)
|
||||
{
|
||||
if (value <= _in_min) return _out_min;
|
||||
return this->map(value);
|
||||
}
|
||||
|
||||
float FastMap::upperConstrainedMap(float value)
|
||||
double FastMap::upperConstrainedMap(double value)
|
||||
{
|
||||
if (value >= _in_max) return _out_max;
|
||||
return this->map(value);
|
||||
|
@ -1,8 +1,8 @@
|
||||
//
|
||||
// FILE: FastMap.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.05
|
||||
// PURPOSE: class implementation of map function - library for Arduino
|
||||
// VERSION: 0.1.06
|
||||
// PURPOSE: class with fast map function - library for Arduino
|
||||
// URL: http://forum.arduino.cc/index.php?topic=276194
|
||||
//
|
||||
// HISTORY:
|
||||
@ -18,24 +18,24 @@
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#define FASTMAP_LIB_VERSION (F("0.1.05"))
|
||||
#define FASTMAP_LIB_VERSION (F("0.1.06"))
|
||||
|
||||
class FastMap
|
||||
{
|
||||
public:
|
||||
void init(float in_min, float in_max, float out_min, float out_max);
|
||||
void init(double in_min, double in_max, double out_min, double out_max);
|
||||
|
||||
float inline map(float value) { return _base + value * _factor; }
|
||||
float inline back(float value) { return _backbase + value * _backfactor; }
|
||||
double inline map(double value) { return _base + value * _factor; }
|
||||
double inline back(double value) { return _backbase + value * _backfactor; }
|
||||
|
||||
float constrainedMap(float value);
|
||||
float lowerConstrainedMap(float value);
|
||||
float upperConstrainedMap(float value);
|
||||
double constrainedMap(double value);
|
||||
double lowerConstrainedMap(double value);
|
||||
double upperConstrainedMap(double value);
|
||||
|
||||
private:
|
||||
float _in_min, _in_max, _out_min, _out_max;
|
||||
float _factor, _base;
|
||||
float _backfactor, _backbase;
|
||||
double _in_min, _in_max, _out_min, _out_max;
|
||||
double _factor, _base;
|
||||
double _backfactor, _backbase;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user