A library that maps one range onto another range.

Dependents:   CANtran2

Map.cpp

Committer:
drorbalbul
Date:
2019-12-27
Revision:
2:ac294c579449
Parent:
1:dad975e2e150

File content as of revision 2:ac294c579449:

#include "Map.hpp"

Map::Map(float inMin, float inMax, float outMin, float outMax)
{
  _inMin = inMin;
  _inMax = inMax;
  _outMin = outMin;
  _outMax = outMax;
}

float Map::Calculate(float inVal)
{
  float rval = (inVal - _inMin)*(_outMax - _outMin)/(_inMax - _inMin) + _outMin ;
  if (rval < _outMin) {
      rval = _outMin;
      }
  if  (rval > _outMax) {
      rval = _outMax;
      }
  return rval;
}