GY-63_MS5611/libraries/FastMap/FastMap.cpp
rob tillaart 93a4857bc4 + version 0.1.05 (0.1.04 experimental only)
+ added back function to "reverse map"
+ fastMapDemo2 shows usage of 2 FastMaps
+ fastMapDemo3 shows usage of back function
+ FASTMAP_LIB_VERSION in PROGMEM
2014-11-02 22:20:21 +01:00

58 lines
1.3 KiB
C++

//
// FILE: FastMap.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.05
// 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.04 add back() - the inverse map
// tested with bit mask for constrain code (Perfomance was killed)
// 0.1.03 proper name
// 0.1.02 squized the code (first public version)
// 0.1.01 refactor
// 0.1.00 initial version
//
#include "FastMap.h"
/////////////////////////////////////////////////////
//
// PUBLIC
//
void FastMap::init(float in_min, float in_max, float out_min, float out_max)
{
_in_min = in_min;
_in_max = in_max;
_out_min = out_min;
_out_max = out_max;
_factor = (out_max - out_min)/(in_max - in_min);
_base = out_min - in_min * _factor;
_backfactor = 1/_factor;
_backbase = in_min - out_min * _backfactor;
}
float FastMap::constrainedMap(float value)
{
if (value <= _in_min) return _out_min;
if (value >= _in_max) return _out_max;
return this->map(value);
}
float FastMap::lowerConstrainedMap(float value)
{
if (value <= _in_min) return _out_min;
return this->map(value);
}
float FastMap::upperConstrainedMap(float value)
{
if (value >= _in_max) return _out_max;
return this->map(value);
}
//
// END OF FILE
//