Skip to content

Commit bdc3428

Browse files
committed
Add gear range arguments to AnalogShifter
This allows for limiting the shifter range, say if you want to build a 5-speed analog shifter. More importantly it allows us to put the shifter in reverse without having to define a pin to read the reverse signal from.
1 parent a11f9ec commit bdc3428

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/SimRacing.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,12 @@ const float AnalogShifter::CalEngagementPoint = 0.70;
692692
const float AnalogShifter::CalReleasePoint = 0.50;
693693
const float AnalogShifter::CalEdgeOffset = 0.60;
694694

695-
AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum detectPin, bool detectActiveLow)
696-
:
697-
/* In initializing the Shifter, the lowest gear is going to be '-1' if a pin
698-
* exists for reverse, otherwise it's going to be '0' (neutral).
699-
*/
700-
Shifter(sanitizePin(pinRev) != UnusedPin ? -1 : 0, 6),
695+
AnalogShifter::AnalogShifter(
696+
Gear gearMin, Gear gearMax,
697+
PinNum pinX, PinNum pinY, PinNum pinRev,
698+
PinNum detectPin, bool detectActiveLow
699+
) :
700+
Shifter(gearMin, gearMax),
701701

702702
/* Two axes, X and Y */
703703
analogAxis{ AnalogInput(pinX), AnalogInput(pinY) },
@@ -1014,6 +1014,7 @@ void AnalogShifter::serialCalibration(Stream& iface) {
10141014

10151015
LogitechShifter::LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum detectPin)
10161016
: AnalogShifter(
1017+
-1, 6, // includes reverse and gears 1-6
10171018
pinX, pinY, pinRev,
10181019
detectPin, false // active high
10191020
)

src/SimRacing.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,23 @@ namespace SimRacing {
582582
/**
583583
* Class constructor
584584
*
585+
* @param gearMin the lowest gear possible
586+
* @param gearMax the highest gear possible
585587
* @param pinX the analog input pin for the X axis
586588
* @param pinY the analog input pin for the Y axis
587589
* @param pinRev the digital input pin for the 'reverse' button
588590
* @param pinDetect the digital pin for device detection
589-
* @param detectActiveLow whether the device is detected on a high signal (false,
590-
* default) or a low signal (true)
591+
* @param detectActiveLow whether the device is detected on a high signal
592+
* (false, default) or a low signal (true)
593+
*
594+
* @note With the way the class is designed, the lowest possible gear is
595+
* -1 (reverse), and the highest possible gear is 6. Setting the
596+
* arguments lower/higher than this will have no effect. Setting
597+
* the arguments within this range will limit to those gears,
598+
* and selecting gears out of range will result in neutral.
591599
*/
592600
AnalogShifter(
601+
Gear gearMin, Gear gearMax,
593602
PinNum pinX, PinNum pinY,
594603
PinNum pinRev = UnusedPin,
595604
PinNum pinDetect = UnusedPin, bool detectActiveLow = false

0 commit comments

Comments
 (0)