Skip to content

Commit 80d083e

Browse files
committed
Add activeLow option to peripherals
Although all current peripherals use active-high detection, that may not be the case in the future. Changing this now for future compatibility. The Logitech classes maintain their original arguments, as we know they are active-high. Because the added argument includes a default, this does not technically break the public API.
1 parent 03ad236 commit 80d083e

2 files changed

Lines changed: 96 additions & 37 deletions

File tree

src/SimRacing.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ void AnalogInput::setCalibration(AnalogInput::Calibration newCal) {
350350
// Pedals #
351351
//#########################################################
352352

353-
Pedals::Pedals(AnalogInput* dataPtr, uint8_t nPedals, PinNum detectPin)
353+
Pedals::Pedals(AnalogInput* dataPtr, uint8_t nPedals, PinNum detectPin, bool detectActiveLow)
354354
:
355355
pedalData(dataPtr),
356356
NumPedals(nPedals),
357-
detector(detectPin),
357+
detector(detectPin, detectActiveLow),
358358
changed(false)
359359
{}
360360

@@ -555,8 +555,8 @@ void Pedals::serialCalibration(Stream& iface) {
555555
}
556556

557557

558-
TwoPedals::TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin)
559-
: Pedals(pedalData, NumPedals, detectPin),
558+
TwoPedals::TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin, bool detectActiveLow)
559+
: Pedals(pedalData, NumPedals, detectPin, detectActiveLow),
560560
pedalData{ AnalogInput(gasPin), AnalogInput(brakePin) }
561561
{}
562562

@@ -566,8 +566,8 @@ void TwoPedals::setCalibration(AnalogInput::Calibration gasCal, AnalogInput::Cal
566566
}
567567

568568

569-
ThreePedals::ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin)
570-
: Pedals(pedalData, NumPedals, detectPin),
569+
ThreePedals::ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin, bool detectActiveLow)
570+
: Pedals(pedalData, NumPedals, detectPin, detectActiveLow),
571571
pedalData{ AnalogInput(gasPin), AnalogInput(brakePin), AnalogInput(clutchPin) }
572572
{}
573573

@@ -580,7 +580,10 @@ void ThreePedals::setCalibration(AnalogInput::Calibration gasCal, AnalogInput::C
580580

581581

582582
LogitechPedals::LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin)
583-
: ThreePedals(gasPin, brakePin, clutchPin, detectPin)
583+
: ThreePedals(
584+
gasPin, brakePin, clutchPin,
585+
detectPin, false // active high
586+
)
584587
{
585588
// taken from calibrating my own pedals. the springs are pretty stiff so while
586589
// this covers the whole travel range, users may want to back it down for casual
@@ -589,7 +592,10 @@ LogitechPedals::LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin,
589592
}
590593

591594
LogitechDrivingForceGT_Pedals::LogitechDrivingForceGT_Pedals(PinNum gasPin, PinNum brakePin, PinNum detectPin)
592-
: TwoPedals(gasPin, brakePin, detectPin)
595+
: TwoPedals(
596+
gasPin, brakePin,
597+
detectPin, false // active high
598+
)
593599
{
594600
this->setCalibration({ 646, 0 }, { 473, 1023 }); // taken from calibrating my own pedals
595601
}
@@ -674,7 +680,7 @@ const float AnalogShifter::CalEngagementPoint = 0.70;
674680
const float AnalogShifter::CalReleasePoint = 0.50;
675681
const float AnalogShifter::CalEdgeOffset = 0.60;
676682

677-
AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum detectPin)
683+
AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum detectPin, bool detectActiveLow)
678684
:
679685
/* In initializing the Shifter, the lowest gear is going to be '-1' if a pin
680686
* exists for reverse, otherwise it's going to be '0' (neutral).
@@ -685,7 +691,7 @@ AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum det
685691
analogAxis{ AnalogInput(pinX), AnalogInput(pinY) },
686692

687693
pinReverse(sanitizePin(pinRev)),
688-
detector(detectPin, false) // not inverted
694+
detector(detectPin, detectActiveLow)
689695
{}
690696

691697
void AnalogShifter::begin() {
@@ -997,7 +1003,10 @@ void AnalogShifter::serialCalibration(Stream& iface) {
9971003
}
9981004

9991005
LogitechShifter::LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum detectPin)
1000-
: AnalogShifter(pinX, pinY, pinRev, detectPin)
1006+
: AnalogShifter(
1007+
pinX, pinY, pinRev,
1008+
detectPin, false // active high
1009+
)
10011010
{
10021011
this->setCalibration({ 490, 440 }, { 253, 799 }, { 262, 86 }, { 460, 826 }, { 470, 76 }, { 664, 841 }, { 677, 77 });
10031012
}
@@ -1006,10 +1015,10 @@ LogitechShifter::LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum
10061015
// Handbrake #
10071016
//#########################################################
10081017

1009-
Handbrake::Handbrake(PinNum pinAx, PinNum detectPin)
1018+
Handbrake::Handbrake(PinNum pinAx, PinNum detectPin, boolean detectActiveLow)
10101019
:
10111020
analogAxis(pinAx),
1012-
detector(detectPin),
1021+
detector(detectPin, detectActiveLow),
10131022
changed(false)
10141023
{}
10151024

src/SimRacing.h

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,14 @@ namespace SimRacing {
294294
/**
295295
* Class constructor
296296
*
297-
* @param dataPtr pointer to the analog input data managed by the class, stored elsewhere
298-
* @param nPedals the number of pedals stored in said data pointer
299-
* @param detectPin the digital pin for device detection (high is detected)
297+
* @param dataPtr pointer to the analog input data managed by the class,
298+
* stored elsewhere
299+
* @param nPedals the number of pedals stored in said data pointer
300+
* @param detectPin the digital pin for device detection
301+
* @param detectActiveLow whether the device is detected on a high signal (false,
302+
* default) or a low signal (true)
300303
*/
301-
Pedals(AnalogInput* dataPtr, uint8_t nPedals, PinNum detectPin);
304+
Pedals(AnalogInput* dataPtr, uint8_t nPedals, PinNum detectPin, bool detectActiveLow = false);
302305

303306
/** @copydoc Peripheral::begin() */
304307
virtual void begin();
@@ -394,11 +397,16 @@ namespace SimRacing {
394397
/**
395398
* Class constructor
396399
*
397-
* @param pinGas the analog pin for the gas pedal potentiometer
398-
* @param pinBrake the analog pin for the brake pedal potentiometer
399-
* @param pinDetect the digital pin for device detection (high is detected)
400+
* @param pinGas the analog pin for the gas pedal potentiometer
401+
* @param pinBrake the analog pin for the brake pedal potentiometer
402+
* @param pinDetect the digital pin for device detection
403+
* @param detectActiveLow whether the device is detected on a high signal (false,
404+
* default) or a low signal (true)
400405
*/
401-
TwoPedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect = UnusedPin);
406+
TwoPedals(
407+
PinNum pinGas, PinNum pinBrake,
408+
PinNum pinDetect = UnusedPin, bool detectActiveLow = false
409+
);
402410

403411
/**
404412
* Sets the calibration data (min/max) for the pedals
@@ -422,12 +430,17 @@ namespace SimRacing {
422430
/**
423431
* Class constructor
424432
*
425-
* @param pinGas the analog pin for the gas pedal potentiometer
426-
* @param pinBrake the analog pin for the brake pedal potentiometer
427-
* @param pinClutch the analog pin for the clutch pedal potentiometer
428-
* @param pinDetect the digital pin for device detection (high is detected)
433+
* @param pinGas the analog pin for the gas pedal potentiometer
434+
* @param pinBrake the analog pin for the brake pedal potentiometer
435+
* @param pinClutch the analog pin for the clutch pedal potentiometer
436+
* @param pinDetect the digital pin for device detection
437+
* @param detectActiveLow whether the device is detected on a high signal (false,
438+
* default) or a low signal (true)
429439
*/
430-
ThreePedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect = UnusedPin);
440+
ThreePedals(
441+
PinNum pinGas, PinNum pinBrake, PinNum pinClutch,
442+
PinNum pinDetect = UnusedPin, bool detectActiveLow = false
443+
);
431444

432445
/**
433446
* Sets the calibration data (min/max) for the pedals
@@ -550,12 +563,18 @@ namespace SimRacing {
550563
/**
551564
* Class constructor
552565
*
553-
* @param pinX the analog input pin for the X axis
554-
* @param pinY the analog input pin for the Y axis
555-
* @param pinRev the digital input pin for the 'reverse' button
556-
* @param pinDetect the digital pin for device detection (high is detected)
566+
* @param pinX the analog input pin for the X axis
567+
* @param pinY the analog input pin for the Y axis
568+
* @param pinRev the digital input pin for the 'reverse' button
569+
* @param pinDetect the digital pin for device detection
570+
* @param detectActiveLow whether the device is detected on a high signal (false,
571+
* default) or a low signal (true)
557572
*/
558-
AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum pinDetect = UnusedPin);
573+
AnalogShifter(
574+
PinNum pinX, PinNum pinY,
575+
PinNum pinRev = UnusedPin,
576+
PinNum pinDetect = UnusedPin, bool detectActiveLow = false
577+
);
559578

560579
/**
561580
* Initializes the hardware pins for reading the gear states.
@@ -691,10 +710,15 @@ namespace SimRacing {
691710
/**
692711
* Class constructor
693712
*
694-
* @param pinAx analog pin number for the handbrake axis
695-
* @param pinDetect the digital pin for device detection (high is detected)
713+
* @param pinAx analog pin number for the handbrake axis
714+
* @param pinDetect the digital pin for device detection
715+
* @param detectActiveLow whether the device is detected on a high signal (false,
716+
* default) or a low signal (true)
696717
*/
697-
Handbrake(PinNum pinAx, PinNum pinDetect = UnusedPin);
718+
Handbrake(
719+
PinNum pinAx,
720+
PinNum pinDetect = UnusedPin, boolean detectActiveLow = false
721+
);
698722

699723
/**
700724
* Initializes the pin for reading from the handbrake.
@@ -760,7 +784,15 @@ namespace SimRacing {
760784
*/
761785
class LogitechPedals : public ThreePedals {
762786
public:
763-
/** @copydoc ThreePedals::ThreePedals */
787+
/**
788+
* Class constructor
789+
*
790+
* @param pinGas the analog pin for the gas pedal potentiometer, DE-9 pin 2
791+
* @param pinBrake the analog pin for the brake pedal potentiometer, DE-9 pin 3
792+
* @param pinClutch the analog pin for the clutch pedal potentiometer, DE-9 pin 4
793+
* @param pinDetect the digital pin for device detection, DE-9 pin 6. Requires a
794+
* pull-down resistor.
795+
*/
764796
LogitechPedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect = UnusedPin);
765797
};
766798

@@ -775,7 +807,14 @@ namespace SimRacing {
775807
*/
776808
class LogitechDrivingForceGT_Pedals : public TwoPedals {
777809
public:
778-
/** @copydoc TwoPedals::TwoPedals */
810+
/**
811+
* Class constructor
812+
*
813+
* @param pinGas the analog pin for the gas pedal potentiometer, DE-9 pin 2
814+
* @param pinBrake the analog pin for the brake pedal potentiometer, DE-9 pin 3
815+
* @param pinDetect the digital pin for device detection, DE-9 pin 4. Requires a
816+
* pull-down resistor.
817+
*/
779818
LogitechDrivingForceGT_Pedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect = UnusedPin);
780819
};
781820

@@ -787,7 +826,18 @@ namespace SimRacing {
787826
*/
788827
class LogitechShifter : public AnalogShifter {
789828
public:
790-
/** @copydoc AnalogShifter::AnalogShifter */
829+
/**
830+
* Class constructor
831+
*
832+
* @param pinX the analog input pin for the X axis, DE-9 pin 4
833+
* @param pinY the analog input pin for the Y axis, DE-9 pin 8
834+
* @param pinRev the digital input pin for the 'reverse' button, DE-9 pin 2
835+
* @param pinDetect the digital pin for device detection, DE-9 pin 7. Requires
836+
* a pull-down resistor.
837+
*
838+
* @note In order to get the 'reverse' signal from the shifter, the chip select
839+
* pin (DE-9 pin 3) needs to be pulled up to VCC.
840+
*/
791841
LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum pinDetect = UnusedPin);
792842
};
793843

0 commit comments

Comments
 (0)