Skip to content

Commit 1da6619

Browse files
committed
Clean up pin arguments and definitions
Removing const from pin number members to allow copying, and changing argument names so that 'pin' is the prefix rather than the suffix in all cases. This should not affect any user code.
1 parent b56d61f commit 1da6619

2 files changed

Lines changed: 44 additions & 44 deletions

File tree

src/SimRacing.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void readFloat(float& value, Stream& client) {
178178

179179
DeviceConnection::DeviceConnection(PinNum pin, bool invert, unsigned long detectTime)
180180
:
181-
Pin(sanitizePin(pin)), Inverted(invert), stablePeriod(detectTime), // constants(ish)
181+
pin(sanitizePin(pin)), inverted(invert), stablePeriod(detectTime), // constants(ish)
182182

183183
/* Assume we're connected on first call
184184
*/
@@ -192,7 +192,7 @@ DeviceConnection::DeviceConnection(PinNum pin, bool invert, unsigned long detect
192192
* the device to be read as connected as soon as the board turns on, without
193193
* having to wait an arbitrary amount.
194194
*/
195-
pinState(!Inverted),
195+
pinState(!inverted),
196196

197197
/* Set the last pin change to right now minus the stable period so it's
198198
* read as being already stable. Again, this will make the class return
@@ -202,7 +202,7 @@ DeviceConnection::DeviceConnection(PinNum pin, bool invert, unsigned long detect
202202

203203
{
204204
if (pin != UnusedPin) {
205-
pinMode(Pin, INPUT); // set pin as input, *no* pull-up
205+
pinMode(pin, INPUT); // set pin as input, *no* pull-up
206206
}
207207
}
208208

@@ -265,30 +265,30 @@ void DeviceConnection::setStablePeriod(unsigned long t) {
265265
}
266266

267267
bool DeviceConnection::readPin() const {
268-
if (Pin == UnusedPin) return HIGH; // if no pin is set, we're always connected
269-
const bool state = digitalRead(Pin);
270-
return Inverted ? !state : state;
268+
if (pin == UnusedPin) return HIGH; // if no pin is set, we're always connected
269+
const bool state = digitalRead(pin);
270+
return inverted ? !state : state;
271271
}
272272

273273
//#########################################################
274274
// AnalogInput #
275275
//#########################################################
276276

277277

278-
AnalogInput::AnalogInput(PinNum p)
279-
: Pin(sanitizePin(p)), position(AnalogInput::Min), cal({AnalogInput::Min, AnalogInput::Max})
278+
AnalogInput::AnalogInput(PinNum pin)
279+
: pin(sanitizePin(pin)), position(AnalogInput::Min), cal({AnalogInput::Min, AnalogInput::Max})
280280
{
281-
if (Pin != UnusedPin) {
282-
pinMode(Pin, INPUT);
281+
if (pin != UnusedPin) {
282+
pinMode(pin, INPUT);
283283
}
284284
}
285285

286286
bool AnalogInput::read() {
287287
bool changed = false;
288288

289-
if (Pin != UnusedPin) {
289+
if (pin != UnusedPin) {
290290
const int previous = this->position;
291-
this->position = analogRead(Pin);
291+
this->position = analogRead(pin);
292292

293293
// check if value is different for 'changed' flag
294294
if (previous != this->position) {
@@ -684,13 +684,13 @@ AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum det
684684
/* Two axes, X and Y */
685685
analogAxis{ AnalogInput(pinX), AnalogInput(pinY) },
686686

687-
PinReverse(sanitizePin(pinRev)),
687+
pinReverse(sanitizePin(pinRev)),
688688
detector(detectPin, false) // not inverted
689689
{}
690690

691691
void AnalogShifter::begin() {
692-
if (this->PinReverse != UnusedPin) {
693-
pinMode(PinReverse, INPUT);
692+
if (this->pinReverse != UnusedPin) {
693+
pinMode(pinReverse, INPUT);
694694
}
695695
update(); // set initial gear position
696696
}
@@ -796,10 +796,10 @@ int AnalogShifter::getPositionRaw(Axis ax) const {
796796
bool AnalogShifter::getReverseButton() const {
797797
// if the reverse pin is not set *or* if the device is not currently
798798
// connected, avoid reading the floating input and just return 'false'
799-
if (PinReverse == UnusedPin || detector.getState() != DeviceConnection::Connected) {
799+
if (pinReverse == UnusedPin || detector.getState() != DeviceConnection::Connected) {
800800
return false;
801801
}
802-
return digitalRead(PinReverse);
802+
return digitalRead(pinReverse);
803803
}
804804

805805
void AnalogShifter::setCalibration(

src/SimRacing.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ namespace SimRacing {
120120
*/
121121
bool readPin() const;
122122

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

127-
ConnectionState state; ///< The current state of the connection
128-
bool pinState; ///< Buffered state of the input pin, accounting for inversion
129-
unsigned long lastChange; ///< Timestamp of the last pin change, in ms (using millis())
127+
ConnectionState state; ///< The current state of the connection
128+
bool pinState; ///< Buffered state of the input pin, accounting for inversion
129+
unsigned long lastChange; ///< Timestamp of the last pin change, in ms (using millis())
130130
};
131131

132132

@@ -141,9 +141,9 @@ namespace SimRacing {
141141
/**
142142
* Class constructor
143143
*
144-
* @param p the I/O pin for this input (Arduino numbering)
144+
* @param pin the I/O pin for this input (Arduino numbering)
145145
*/
146-
AnalogInput(PinNum p);
146+
AnalogInput(PinNum pin);
147147

148148
/**
149149
* Updates the current value of the axis by polling the ADC
@@ -237,9 +237,9 @@ namespace SimRacing {
237237
void setCalibration(Calibration newCal);
238238

239239
private:
240-
const PinNum Pin = UnusedPin; ///< the digital pin number for this input
241-
int position; ///< the axis' position in its range, buffered
242-
Calibration cal; ///< the calibration values for the axis
240+
PinNum pin; ///< the digital pin number for this input
241+
int position; ///< the axis' position in its range, buffered
242+
Calibration cal; ///< the calibration values for the axis
243243
};
244244

245245

@@ -393,11 +393,11 @@ namespace SimRacing {
393393
/**
394394
* Class constructor
395395
*
396-
* @param gasPin the analog pin for the gas pedal potentiometer
397-
* @param brakePin the analog pin for the brake pedal potentiometer
398-
* @param detectPin the digital pin for device detection (high is detected)
396+
* @param pinGas the analog pin for the gas pedal potentiometer
397+
* @param pinBrake the analog pin for the brake pedal potentiometer
398+
* @param pinDetect the digital pin for device detection (high is detected)
399399
*/
400-
TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = UnusedPin);
400+
TwoPedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect = UnusedPin);
401401

402402
/**
403403
* Sets the calibration data (min/max) for the pedals
@@ -421,12 +421,12 @@ namespace SimRacing {
421421
/**
422422
* Class constructor
423423
*
424-
* @param gasPin the analog pin for the gas pedal potentiometer
425-
* @param brakePin the analog pin for the brake pedal potentiometer
426-
* @param clutchPin the analog pin for the clutch pedal potentiometer
427-
* @param detectPin the digital pin for device detection (high is detected)
424+
* @param pinGas the analog pin for the gas pedal potentiometer
425+
* @param pinBrake the analog pin for the brake pedal potentiometer
426+
* @param pinClutch the analog pin for the clutch pedal potentiometer
427+
* @param pinDetect the digital pin for device detection (high is detected)
428428
*/
429-
ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = UnusedPin);
429+
ThreePedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect = UnusedPin);
430430

431431
/**
432432
* Sets the calibration data (min/max) for the pedals
@@ -552,9 +552,9 @@ namespace SimRacing {
552552
* @param pinX the analog input pin for the X axis
553553
* @param pinY the analog input pin for the Y axis
554554
* @param pinRev the digital input pin for the 'reverse' button
555-
* @param detectPin the digital pin for device detection (high is detected)
555+
* @param pinDetect the digital pin for device detection (high is detected)
556556
*/
557-
AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum detectPin = UnusedPin);
557+
AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum pinDetect = UnusedPin);
558558

559559
/**
560560
* Initializes the hardware pins for reading the gear states.
@@ -675,7 +675,7 @@ namespace SimRacing {
675675
} calibration;
676676

677677
AnalogInput analogAxis[2]; ///< Axis data for X and Y
678-
const PinNum PinReverse; ///< The pin for the reverse gear button
678+
PinNum pinReverse; ///< The pin for the reverse gear button
679679
DeviceConnection detector; ///< detector instance for checking if the shifter is connected
680680
};
681681

@@ -691,9 +691,9 @@ namespace SimRacing {
691691
* Class constructor
692692
*
693693
* @param pinAx analog pin number for the handbrake axis
694-
* @param detectPin the digital pin for device detection (high is detected)
694+
* @param pinDetect the digital pin for device detection (high is detected)
695695
*/
696-
Handbrake(PinNum pinAx, PinNum detectPin = UnusedPin);
696+
Handbrake(PinNum pinAx, PinNum pinDetect = UnusedPin);
697697

698698
/**
699699
* Initializes the pin for reading from the handbrake.
@@ -760,7 +760,7 @@ namespace SimRacing {
760760
class LogitechPedals : public ThreePedals {
761761
public:
762762
/** @copydoc ThreePedals::ThreePedals */
763-
LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = UnusedPin);
763+
LogitechPedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect = UnusedPin);
764764
};
765765

766766
/**
@@ -775,7 +775,7 @@ namespace SimRacing {
775775
class LogitechDrivingForceGT_Pedals : public TwoPedals {
776776
public:
777777
/** @copydoc TwoPedals::TwoPedals */
778-
LogitechDrivingForceGT_Pedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = UnusedPin);
778+
LogitechDrivingForceGT_Pedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect = UnusedPin);
779779
};
780780

781781
/**
@@ -787,7 +787,7 @@ namespace SimRacing {
787787
class LogitechShifter : public AnalogShifter {
788788
public:
789789
/** @copydoc AnalogShifter::AnalogShifter */
790-
LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum detectPin = UnusedPin);
790+
LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum pinDetect = UnusedPin);
791791
};
792792

793793

0 commit comments

Comments
 (0)