Skip to content

Commit 93a4a6d

Browse files
committed
Replace all NOT_A_PIN references
Using a value we control rather than the platform-specific define (which isn't really meant for this purpose anyways).
1 parent 4a7a2eb commit 93a4a6d

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/SimRacing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void DeviceConnection::setStablePeriod(unsigned long t) {
248248
}
249249

250250
bool DeviceConnection::readPin() const {
251-
if (Pin == NOT_A_PIN) return HIGH; // if no pin is set, we're always connected
251+
if (Pin == UnusedPin) return HIGH; // if no pin is set, we're always connected
252252
const bool state = digitalRead(Pin);
253253
return Inverted ? !state : state;
254254
}
@@ -261,15 +261,15 @@ bool DeviceConnection::readPin() const {
261261
AnalogInput::AnalogInput(PinNum p)
262262
: Pin(p), position(AnalogInput::Min), cal({AnalogInput::Min, AnalogInput::Max})
263263
{
264-
if (Pin != NOT_A_PIN) {
264+
if (Pin != UnusedPin) {
265265
pinMode(Pin, INPUT);
266266
}
267267
}
268268

269269
bool AnalogInput::read() {
270270
bool changed = false;
271271

272-
if (Pin != NOT_A_PIN) {
272+
if (Pin != UnusedPin) {
273273
const int previous = this->position;
274274
this->position = analogRead(Pin);
275275

@@ -662,7 +662,7 @@ AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum det
662662
/* In initializing the Shifter, the lowest gear is going to be '-1' if a pin
663663
* exists for reverse, otherwise it's going to be '0' (neutral).
664664
*/
665-
Shifter(pinRev != NOT_A_PIN ? -1 : 0, 6),
665+
Shifter(pinRev != UnusedPin ? -1 : 0, 6),
666666

667667
/* Two axes, X and Y */
668668
analogAxis{ AnalogInput(pinX), AnalogInput(pinY) },
@@ -777,7 +777,7 @@ int AnalogShifter::getPositionRaw(Axis ax) const {
777777
bool AnalogShifter::getReverseButton() const {
778778
// if the reverse pin is not set *or* if the device is not currently
779779
// connected, avoid reading the floating input and just return 'false'
780-
if (PinReverse == NOT_A_PIN || detector.getState() != DeviceConnection::Connected) {
780+
if (PinReverse == UnusedPin || detector.getState() != DeviceConnection::Connected) {
781781
return false;
782782
}
783783
return digitalRead(PinReverse);

src/SimRacing.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ namespace SimRacing {
3434
/**
3535
* Type alias for pin numbers, using Arduino numbering
3636
*/
37-
using PinNum = uint8_t;
37+
using PinNum = int16_t;
38+
39+
/**
40+
* Dummy pin number signaling that a pin is unused
41+
* and can be safely ignored
42+
*/
43+
const PinNum UnusedPin = -1;
3844

3945

4046
/**
@@ -69,7 +75,7 @@ namespace SimRacing {
6975
/**
7076
* Class constructor
7177
*
72-
* @param pin the pin number being read. Can be 'NOT_A_PIN' to disable.
78+
* @param pin the pin number being read. Can be 'UnusedPin' to disable.
7379
* @param invert whether the input is inverted, so 'LOW' is detected instead of 'HIGH'
7480
* @param detectTime the amount of time, in ms, the input must be stable for
7581
* before it's interpreted as 'detected'
@@ -114,7 +120,7 @@ namespace SimRacing {
114120
*/
115121
bool readPin() const;
116122

117-
const PinNum Pin; ///< The pin number being read from. Can be 'NOT_A_PIN' to disable
123+
const PinNum Pin; ///< The pin number being read from. Can be 'UnusedPin' to disable
118124
const bool Inverted; ///< Whether the input is inverted, so 'LOW' is detected instead of 'HIGH'
119125
unsigned long stablePeriod; ///< The amount of time the input must be stable for (ms)
120126

@@ -231,7 +237,7 @@ namespace SimRacing {
231237
void setCalibration(Calibration newCal);
232238

233239
private:
234-
const PinNum Pin = NOT_A_PIN; ///< the digital pin number for this input
240+
const PinNum Pin = UnusedPin; ///< the digital pin number for this input
235241
int position; ///< the axis' position in its range, buffered
236242
Calibration cal; ///< the calibration values for the axis
237243
};
@@ -391,7 +397,7 @@ namespace SimRacing {
391397
* @param brakePin the analog pin for the brake pedal potentiometer
392398
* @param detectPin the digital pin for device detection (high is detected)
393399
*/
394-
TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = NOT_A_PIN);
400+
TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = UnusedPin);
395401

396402
/**
397403
* Sets the calibration data (min/max) for the pedals
@@ -420,7 +426,7 @@ namespace SimRacing {
420426
* @param clutchPin the analog pin for the clutch pedal potentiometer
421427
* @param detectPin the digital pin for device detection (high is detected)
422428
*/
423-
ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = NOT_A_PIN);
429+
ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = UnusedPin);
424430

425431
/**
426432
* Sets the calibration data (min/max) for the pedals
@@ -548,7 +554,7 @@ namespace SimRacing {
548554
* @param pinRev the digital input pin for the 'reverse' button
549555
* @param detectPin the digital pin for device detection (high is detected)
550556
*/
551-
AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = NOT_A_PIN, PinNum detectPin = NOT_A_PIN);
557+
AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum detectPin = UnusedPin);
552558

553559
/**
554560
* Initializes the hardware pins for reading the gear states.
@@ -687,7 +693,7 @@ namespace SimRacing {
687693
* @param pinAx analog pin number for the handbrake axis
688694
* @param detectPin the digital pin for device detection (high is detected)
689695
*/
690-
Handbrake(PinNum pinAx, PinNum detectPin = NOT_A_PIN);
696+
Handbrake(PinNum pinAx, PinNum detectPin = UnusedPin);
691697

692698
/**
693699
* Initializes the pin for reading from the handbrake.
@@ -754,7 +760,7 @@ namespace SimRacing {
754760
class LogitechPedals : public ThreePedals {
755761
public:
756762
/** @copydoc ThreePedals::ThreePedals */
757-
LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = NOT_A_PIN);
763+
LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = UnusedPin);
758764
};
759765

760766
/**
@@ -769,7 +775,7 @@ namespace SimRacing {
769775
class LogitechDrivingForceGT_Pedals : public TwoPedals {
770776
public:
771777
/** @copydoc TwoPedals::TwoPedals */
772-
LogitechDrivingForceGT_Pedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = NOT_A_PIN);
778+
LogitechDrivingForceGT_Pedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = UnusedPin);
773779
};
774780

775781
/**
@@ -781,7 +787,7 @@ namespace SimRacing {
781787
class LogitechShifter : public AnalogShifter {
782788
public:
783789
/** @copydoc AnalogShifter::AnalogShifter */
784-
LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = NOT_A_PIN, PinNum detectPin = NOT_A_PIN);
790+
LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum detectPin = UnusedPin);
785791
};
786792

787793

0 commit comments

Comments
 (0)