Skip to content

Commit 4a7a2eb

Browse files
committed
Change all pin types to use PinNum alias
1 parent 053c24c commit 4a7a2eb

2 files changed

Lines changed: 29 additions & 23 deletions

File tree

src/SimRacing.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static void readFloat(float& value, Stream& client) {
161161
// DeviceConnection #
162162
//#########################################################
163163

164-
DeviceConnection::DeviceConnection(uint8_t pin, bool invert, unsigned long detectTime)
164+
DeviceConnection::DeviceConnection(PinNum pin, bool invert, unsigned long detectTime)
165165
:
166166
Pin(pin), Inverted(invert), stablePeriod(detectTime), // constants(ish)
167167

@@ -258,7 +258,7 @@ bool DeviceConnection::readPin() const {
258258
//#########################################################
259259

260260

261-
AnalogInput::AnalogInput(uint8_t p)
261+
AnalogInput::AnalogInput(PinNum p)
262262
: Pin(p), position(AnalogInput::Min), cal({AnalogInput::Min, AnalogInput::Max})
263263
{
264264
if (Pin != NOT_A_PIN) {
@@ -333,7 +333,7 @@ void AnalogInput::setCalibration(AnalogInput::Calibration newCal) {
333333
// Pedals #
334334
//#########################################################
335335

336-
Pedals::Pedals(AnalogInput* dataPtr, uint8_t nPedals, uint8_t detectPin)
336+
Pedals::Pedals(AnalogInput* dataPtr, uint8_t nPedals, PinNum detectPin)
337337
:
338338
pedalData(dataPtr),
339339
NumPedals(nPedals),
@@ -538,7 +538,7 @@ void Pedals::serialCalibration(Stream& iface) {
538538
}
539539

540540

541-
TwoPedals::TwoPedals(uint8_t gasPin, uint8_t brakePin, uint8_t detectPin)
541+
TwoPedals::TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin)
542542
: Pedals(pedalData, NumPedals, detectPin),
543543
pedalData{ AnalogInput(gasPin), AnalogInput(brakePin) }
544544
{}
@@ -549,7 +549,7 @@ void TwoPedals::setCalibration(AnalogInput::Calibration gasCal, AnalogInput::Cal
549549
}
550550

551551

552-
ThreePedals::ThreePedals(uint8_t gasPin, uint8_t brakePin, uint8_t clutchPin, uint8_t detectPin)
552+
ThreePedals::ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin)
553553
: Pedals(pedalData, NumPedals, detectPin),
554554
pedalData{ AnalogInput(gasPin), AnalogInput(brakePin), AnalogInput(clutchPin) }
555555
{}
@@ -562,7 +562,7 @@ void ThreePedals::setCalibration(AnalogInput::Calibration gasCal, AnalogInput::C
562562

563563

564564

565-
LogitechPedals::LogitechPedals(uint8_t gasPin, uint8_t brakePin, uint8_t clutchPin, uint8_t detectPin)
565+
LogitechPedals::LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin)
566566
: ThreePedals(gasPin, brakePin, clutchPin, detectPin)
567567
{
568568
// taken from calibrating my own pedals. the springs are pretty stiff so while
@@ -571,7 +571,7 @@ LogitechPedals::LogitechPedals(uint8_t gasPin, uint8_t brakePin, uint8_t clutchP
571571
this->setCalibration({ 904, 48 }, { 944, 286 }, { 881, 59 });
572572
}
573573

574-
LogitechDrivingForceGT_Pedals::LogitechDrivingForceGT_Pedals(uint8_t gasPin, uint8_t brakePin, uint8_t detectPin)
574+
LogitechDrivingForceGT_Pedals::LogitechDrivingForceGT_Pedals(PinNum gasPin, PinNum brakePin, PinNum detectPin)
575575
: TwoPedals(gasPin, brakePin, detectPin)
576576
{
577577
this->setCalibration({ 646, 0 }, { 473, 1023 }); // taken from calibrating my own pedals
@@ -657,7 +657,7 @@ const float AnalogShifter::CalEngagementPoint = 0.70;
657657
const float AnalogShifter::CalReleasePoint = 0.50;
658658
const float AnalogShifter::CalEdgeOffset = 0.60;
659659

660-
AnalogShifter::AnalogShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev, uint8_t detectPin)
660+
AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum detectPin)
661661
:
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).
@@ -977,7 +977,7 @@ void AnalogShifter::serialCalibration(Stream& iface) {
977977
iface.println(F("\n\nCalibration complete! :)\n"));
978978
}
979979

980-
LogitechShifter::LogitechShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev, uint8_t detectPin)
980+
LogitechShifter::LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum detectPin)
981981
: AnalogShifter(pinX, pinY, pinRev, detectPin)
982982
{
983983
this->setCalibration({ 490, 440 }, { 253, 799 }, { 262, 86 }, { 460, 826 }, { 470, 76 }, { 664, 841 }, { 677, 77 });
@@ -987,7 +987,7 @@ LogitechShifter::LogitechShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev, uin
987987
// Handbrake #
988988
//#########################################################
989989

990-
Handbrake::Handbrake(uint8_t pinAx, uint8_t detectPin)
990+
Handbrake::Handbrake(PinNum pinAx, PinNum detectPin)
991991
:
992992
analogAxis(pinAx),
993993
detector(detectPin),

src/SimRacing.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
*/
3232

3333
namespace SimRacing {
34+
/**
35+
* Type alias for pin numbers, using Arduino numbering
36+
*/
37+
using PinNum = uint8_t;
38+
39+
3440
/**
3541
* Enumeration for analog axis names, mapped to integers
3642
*/
@@ -68,7 +74,7 @@ namespace SimRacing {
6874
* @param detectTime the amount of time, in ms, the input must be stable for
6975
* before it's interpreted as 'detected'
7076
*/
71-
DeviceConnection(uint8_t pin, bool invert = false, unsigned long detectTime = 250);
77+
DeviceConnection(PinNum pin, bool invert = false, unsigned long detectTime = 250);
7278

7379
/**
7480
* Checks if the pin detects a connection. This polls the input and checks
@@ -108,7 +114,7 @@ namespace SimRacing {
108114
*/
109115
bool readPin() const;
110116

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

@@ -131,7 +137,7 @@ namespace SimRacing {
131137
*
132138
* @param p the I/O pin for this input (Arduino numbering)
133139
*/
134-
AnalogInput(uint8_t p);
140+
AnalogInput(PinNum p);
135141

136142
/**
137143
* Updates the current value of the axis by polling the ADC
@@ -225,7 +231,7 @@ namespace SimRacing {
225231
void setCalibration(Calibration newCal);
226232

227233
private:
228-
const uint8_t Pin = NOT_A_PIN; ///< the digital pin number for this input
234+
const PinNum Pin = NOT_A_PIN; ///< the digital pin number for this input
229235
int position; ///< the axis' position in its range, buffered
230236
Calibration cal; ///< the calibration values for the axis
231237
};
@@ -285,7 +291,7 @@ namespace SimRacing {
285291
* @param nPedals the number of pedals stored in said data pointer
286292
* @param detectPin the digital pin for device detection (high is detected)
287293
*/
288-
Pedals(AnalogInput* dataPtr, uint8_t nPedals, uint8_t detectPin);
294+
Pedals(AnalogInput* dataPtr, uint8_t nPedals, PinNum detectPin);
289295

290296
/** @copydoc Peripheral::begin() */
291297
virtual void begin();
@@ -385,7 +391,7 @@ namespace SimRacing {
385391
* @param brakePin the analog pin for the brake pedal potentiometer
386392
* @param detectPin the digital pin for device detection (high is detected)
387393
*/
388-
TwoPedals(uint8_t gasPin, uint8_t brakePin, uint8_t detectPin = NOT_A_PIN);
394+
TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = NOT_A_PIN);
389395

390396
/**
391397
* Sets the calibration data (min/max) for the pedals
@@ -414,7 +420,7 @@ namespace SimRacing {
414420
* @param clutchPin the analog pin for the clutch pedal potentiometer
415421
* @param detectPin the digital pin for device detection (high is detected)
416422
*/
417-
ThreePedals(uint8_t gasPin, uint8_t brakePin, uint8_t clutchPin, uint8_t detectPin = NOT_A_PIN);
423+
ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = NOT_A_PIN);
418424

419425
/**
420426
* Sets the calibration data (min/max) for the pedals
@@ -542,7 +548,7 @@ namespace SimRacing {
542548
* @param pinRev the digital input pin for the 'reverse' button
543549
* @param detectPin the digital pin for device detection (high is detected)
544550
*/
545-
AnalogShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev = NOT_A_PIN, uint8_t detectPin = NOT_A_PIN);
551+
AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = NOT_A_PIN, PinNum detectPin = NOT_A_PIN);
546552

547553
/**
548554
* Initializes the hardware pins for reading the gear states.
@@ -663,7 +669,7 @@ namespace SimRacing {
663669
} calibration;
664670

665671
AnalogInput analogAxis[2]; ///< Axis data for X and Y
666-
const uint8_t PinReverse; ///< The pin for the reverse gear button
672+
const PinNum PinReverse; ///< The pin for the reverse gear button
667673
DeviceConnection detector; ///< detector instance for checking if the shifter is connected
668674
};
669675

@@ -681,7 +687,7 @@ namespace SimRacing {
681687
* @param pinAx analog pin number for the handbrake axis
682688
* @param detectPin the digital pin for device detection (high is detected)
683689
*/
684-
Handbrake(uint8_t pinAx, uint8_t detectPin = NOT_A_PIN);
690+
Handbrake(PinNum pinAx, PinNum detectPin = NOT_A_PIN);
685691

686692
/**
687693
* Initializes the pin for reading from the handbrake.
@@ -748,7 +754,7 @@ namespace SimRacing {
748754
class LogitechPedals : public ThreePedals {
749755
public:
750756
/** @copydoc ThreePedals::ThreePedals */
751-
LogitechPedals(uint8_t gasPin, uint8_t brakePin, uint8_t clutchPin, uint8_t detectPin = NOT_A_PIN);
757+
LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = NOT_A_PIN);
752758
};
753759

754760
/**
@@ -763,7 +769,7 @@ namespace SimRacing {
763769
class LogitechDrivingForceGT_Pedals : public TwoPedals {
764770
public:
765771
/** @copydoc TwoPedals::TwoPedals */
766-
LogitechDrivingForceGT_Pedals(uint8_t gasPin, uint8_t brakePin, uint8_t detectPin = NOT_A_PIN);
772+
LogitechDrivingForceGT_Pedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = NOT_A_PIN);
767773
};
768774

769775
/**
@@ -775,7 +781,7 @@ namespace SimRacing {
775781
class LogitechShifter : public AnalogShifter {
776782
public:
777783
/** @copydoc AnalogShifter::AnalogShifter */
778-
LogitechShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev = NOT_A_PIN, uint8_t detectPin = NOT_A_PIN);
784+
LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = NOT_A_PIN, PinNum detectPin = NOT_A_PIN);
779785
};
780786

781787

0 commit comments

Comments
 (0)