| 44 | } |
| 45 | |
| 46 | float Potentiometer::normalized() const { |
| 47 | // Handle invalid range |
| 48 | if (mMaxValue <= mMinValue) { |
| 49 | return 0.0f; |
| 50 | } |
| 51 | |
| 52 | // Clamp current value to calibrated range |
| 53 | u16 clamped_value; |
| 54 | if (mCurrentValue < mMinValue) { |
| 55 | clamped_value = mMinValue; |
| 56 | } else if (mCurrentValue > mMaxValue) { |
| 57 | clamped_value = mMaxValue; |
| 58 | } else { |
| 59 | clamped_value = mCurrentValue; |
| 60 | } |
| 61 | |
| 62 | // Map calibrated range to [0.0, 1.0] |
| 63 | u16 range = mMaxValue - mMinValue; |
| 64 | u16 offset = clamped_value - mMinValue; |
| 65 | return static_cast<float>(offset) / static_cast<float>(range); |
| 66 | } |
| 67 | |
| 68 | u16 Potentiometer::fractional16() const { |
| 69 | // Handle invalid range |
no outgoing calls
no test coverage detected