Skip to content

Commit 6c5ba50

Browse files
committed
Add inRange() functions to AnalogInput class
For checking whether a value is within the calibrated range.
1 parent febc212 commit 6c5ba50

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/SimRacing.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,26 @@ int AnalogInput::getPositionRaw() const {
285285
return this->position;
286286
}
287287

288+
bool AnalogInput::inRange() const {
289+
return inRange(this->getPositionRaw());
290+
}
291+
292+
bool AnalogInput::inRange(int p) const {
293+
bool output;
294+
295+
// In 'normal' orientation, we are within range if the position
296+
// is above the min and below the max.
297+
if (!isInverted()) {
298+
output = (p >= getMin() && p <= getMax());
299+
}
300+
// In 'inverted' orientation, we are within range if the position
301+
// is below the min and above the max.
302+
else {
303+
output = (p >= getMax() && p <= getMin());
304+
}
305+
return output;
306+
}
307+
288308
bool AnalogInput::isInverted() const {
289309
return (this->cal.min > this->cal.max); // inverted if min is greater than max
290310
}

src/SimRacing.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@ namespace SimRacing {
175175
*/
176176
int getMax() const { return this->cal.max; }
177177

178+
/**
179+
* Checks whether the current position is within the calibrated
180+
* range of the axis.
181+
*
182+
* @return 'true' if position is within range, 'false' otherwise
183+
*/
184+
bool inRange() const;
185+
186+
/**
187+
* Checks whether a given input value is within the calibrated
188+
* range of the axis.
189+
*
190+
* @param p position value to test
191+
* @return 'true' if test value is within range, 'false' otherwise
192+
*/
193+
bool inRange(int p) const;
194+
178195
/**
179196
* Check whether the axis is inverted or not.
180197
*

0 commit comments

Comments
 (0)