/
LinearTransform.h
46 lines (39 loc) · 1.08 KB
/
LinearTransform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*! \file */
#ifndef _ARDUINOUNIVERSALINPUTS_LINEARVALUETRANSFORM_H
#define _ARDUINOUNIVERSALINPUTS_LINEARVALUETRANSFORM_H
#include "IValueTransform.h"
/*!
* \class LinearTransform
* \brief Value transformation for basic linear interpolation.
*/
class LinearTransform : public IValueTransform
{
public:
/*!
* \copydoc IValueTransform::IValueTransform
* \param toLow Lowest mapped output value
* \param toHigh Highest mapped output value
*/
LinearTransform(inputanalog_t fromLow, inputanalog_t fromHigh,
inputanalog_t toLow, inputanalog_t toHigh)
: IValueTransform(fromLow, fromHigh)
, m_toLow(toLow)
, m_toHigh(toHigh)
{
}
virtual ~LinearTransform() {}
/*!
* \copydoc IValueTransform::transform
*
* Performs basic linear interpolation.
*/
inputanalog_t transform(inputanalog_t raw) const
{
return (raw - m_fromLow) * (m_toHigh - m_toLow) / (m_fromHigh - m_fromLow) +
m_toLow;
}
private:
inputanalog_t m_toLow; //!< Lowest output value
inputanalog_t m_toHigh; //!< Highest output value
};
#endif