Arduino Universal Inputs
A collection of libraries for managing/processing input devices on Arduino.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator
LinearTransform.h
Go to the documentation of this file.
1 
3 #ifndef _ARDUINOUNIVERSALINPUTS_LINEARVALUETRANSFORM_H
4 #define _ARDUINOUNIVERSALINPUTS_LINEARVALUETRANSFORM_H
5 
6 #include "IValueTransform.h"
7 
13 {
14 public:
21  inputanalog_t toLow, inputanalog_t toHigh)
22  : IValueTransform(fromLow, fromHigh)
23  , m_toLow(toLow)
24  , m_toHigh(toHigh)
25  {
26  }
27 
28  virtual ~LinearTransform() {}
29 
36  {
37  return (raw - m_fromLow) * (m_toHigh - m_toLow) / (m_fromHigh - m_fromLow) +
38  m_toLow;
39  }
40 
41 private:
42  inputanalog_t m_toLow;
43  inputanalog_t m_toHigh;
44 };
45 
46 #endif
inputanalog_t transform(inputanalog_t raw) const
Perform the value transformation.
Definition: LinearTransform.h:35
Value transformation for basic linear interpolation.
Definition: LinearTransform.h:12
inputanalog_t m_fromLow
Lowest input value.
Definition: IValueTransform.h:36
int32_t inputanalog_t
Holds the value of an analog input value.
Definition: UniversalInputTypes.h:31
inputanalog_t m_fromHigh
Highest input value.
Definition: IValueTransform.h:37
LinearTransform(inputanalog_t fromLow, inputanalog_t fromHigh, inputanalog_t toLow, inputanalog_t toHigh)
Create a new value transformation.
Definition: LinearTransform.h:20
Interface for a value transformation.
Definition: IValueTransform.h:12