MCPcopy Create free account
hub / github.com/FastLED/FastLED / fractional16

Method fractional16

src/fl/sensors/potentiometer.cpp.hpp:68–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68u16 Potentiometer::fractional16() const {
69 // Handle invalid range
70 if (mMaxValue <= mMinValue) {
71 return 0;
72 }
73
74 // Clamp current value to calibrated range
75 u16 clamped_value;
76 if (mCurrentValue < mMinValue) {
77 clamped_value = mMinValue;
78 } else if (mCurrentValue > mMaxValue) {
79 clamped_value = mMaxValue;
80 } else {
81 clamped_value = mCurrentValue;
82 }
83
84 // Map calibrated range to [0, 65535]
85 // Use 32-bit intermediate to avoid overflow
86 u32 range = mMaxValue - mMinValue;
87 u32 offset = clamped_value - mMinValue;
88 u32 scaled = (offset * 65535U) / range;
89 return static_cast<u16>(scaled);
90}
91
92void Potentiometer::setHysteresisPercent(float percent) {
93 // Clamp percent to valid range

Callers 1

FL_TEST_FILEFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected