Skip to content

Commit cb91cb0

Browse files
committed
Add midpoint function to range class
1 parent 6407bf1 commit cb91cb0

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/CalibratedServo.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ typedef struct Range {
66
unsigned int min;
77
unsigned int max;
88

9-
unsigned int clamp(unsigned int v) const { return constrain(v, min, max); }
9+
inline unsigned int clamp(unsigned int v) const { return constrain(v, min, max); }
10+
inline unsigned int midpoint() const { return (max - min) / 2; }
1011
} Range;
1112

1213
// a calibrated servo defines its input (signal) and output (position) ranges

src/DashState.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Range oilServoLimit { 0, 180 };
3232

3333
// define limits for LED strip brightness
3434
const Range LEDStripBrightnessLimit { 5, 255 };
35-
const int dimBrightnessLevel = (LEDStripBrightnessLimit.max - LEDStripBrightnessLimit.min) / 2;
35+
const int dimBrightnessLevel = LEDStripBrightnessLimit.midpoint();
3636

3737
const unsigned int ARDUINO_BOOT_ANIMATION_MS = 2000; // amount of time that we can use to do a bootup sequence
3838
const unsigned int ARDUINO_SOFT_SHUTDOWN_MS = 3000; // amount of time that we can use to do a soft shutdown

0 commit comments

Comments
 (0)