2014-11-02 11:24:21 -05:00
|
|
|
//
|
|
|
|
// FILE: FastMap.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2017-07-27 09:26:36 -04:00
|
|
|
// VERSION: 0.1.8
|
2015-03-08 17:17:20 -04:00
|
|
|
// PURPOSE: class with fast map function - library for Arduino
|
2014-11-02 11:24:21 -05:00
|
|
|
// URL: http://forum.arduino.cc/index.php?topic=276194
|
|
|
|
//
|
|
|
|
// HISTORY:
|
2014-11-02 16:20:21 -05:00
|
|
|
// see FastMap.cpp file
|
2014-11-02 11:24:21 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef FastMap_h
|
|
|
|
#define FastMap_h
|
|
|
|
|
|
|
|
#if ARDUINO < 100
|
|
|
|
#include <WProgram.h>
|
|
|
|
#else
|
|
|
|
#include <Arduino.h>
|
|
|
|
#endif
|
|
|
|
|
2017-07-27 09:26:36 -04:00
|
|
|
#define FASTMAP_LIB_VERSION (F("0.1.8"))
|
2014-11-02 11:24:21 -05:00
|
|
|
|
|
|
|
class FastMap
|
|
|
|
{
|
|
|
|
public:
|
2017-07-15 12:28:01 -04:00
|
|
|
FastMap();
|
2014-11-02 11:24:21 -05:00
|
|
|
|
2017-07-27 09:26:36 -04:00
|
|
|
void init(const float in_min, const float in_max, const float out_min, const float out_max);
|
2014-11-02 16:20:21 -05:00
|
|
|
|
2017-07-27 09:26:36 -04:00
|
|
|
float inline map (const float value) { return _base + value * _factor; }
|
|
|
|
float inline back (const float value) { return _backbase + value * _backfactor; }
|
2017-07-15 12:28:01 -04:00
|
|
|
|
2017-07-27 09:26:36 -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:
|
2017-07-27 09:26:36 -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
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2017-07-27 09:26:36 -04:00
|
|
|
|
|
|
|
// END OF FILE
|