diff --git a/src/SimRacing.cpp b/src/SimRacing.cpp index 9ae8672..e3472c4 100644 --- a/src/SimRacing.cpp +++ b/src/SimRacing.cpp @@ -178,7 +178,7 @@ static void readFloat(float& value, Stream& client) { DeviceConnection::DeviceConnection(PinNum pin, bool invert, unsigned long detectTime) : - Pin(sanitizePin(pin)), Inverted(invert), stablePeriod(detectTime), // constants(ish) + pin(sanitizePin(pin)), inverted(invert), stablePeriod(detectTime), // constants(ish) /* Assume we're connected on first call */ @@ -192,7 +192,7 @@ DeviceConnection::DeviceConnection(PinNum pin, bool invert, unsigned long detect * the device to be read as connected as soon as the board turns on, without * having to wait an arbitrary amount. */ - pinState(!Inverted), + pinState(!inverted), /* Set the last pin change to right now minus the stable period so it's * 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 { if (pin != UnusedPin) { - pinMode(Pin, INPUT); // set pin as input, *no* pull-up + pinMode(pin, INPUT); // set pin as input, *no* pull-up } } @@ -265,9 +265,9 @@ void DeviceConnection::setStablePeriod(unsigned long t) { } bool DeviceConnection::readPin() const { - if (Pin == UnusedPin) return HIGH; // if no pin is set, we're always connected - const bool state = digitalRead(Pin); - return Inverted ? !state : state; + if (pin == UnusedPin) return HIGH; // if no pin is set, we're always connected + const bool state = digitalRead(pin); + return inverted ? !state : state; } //######################################################### @@ -275,20 +275,20 @@ bool DeviceConnection::readPin() const { //######################################################### -AnalogInput::AnalogInput(PinNum p) - : Pin(sanitizePin(p)), position(AnalogInput::Min), cal({AnalogInput::Min, AnalogInput::Max}) +AnalogInput::AnalogInput(PinNum pin) + : pin(sanitizePin(pin)), position(AnalogInput::Min), cal({AnalogInput::Min, AnalogInput::Max}) { - if (Pin != UnusedPin) { - pinMode(Pin, INPUT); + if (pin != UnusedPin) { + pinMode(pin, INPUT); } } bool AnalogInput::read() { bool changed = false; - if (Pin != UnusedPin) { + if (pin != UnusedPin) { const int previous = this->position; - this->position = analogRead(Pin); + this->position = analogRead(pin); // check if value is different for 'changed' flag if (previous != this->position) { @@ -684,13 +684,13 @@ AnalogShifter::AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev, PinNum det /* Two axes, X and Y */ analogAxis{ AnalogInput(pinX), AnalogInput(pinY) }, - PinReverse(sanitizePin(pinRev)), + pinReverse(sanitizePin(pinRev)), detector(detectPin, false) // not inverted {} void AnalogShifter::begin() { - if (this->PinReverse != UnusedPin) { - pinMode(PinReverse, INPUT); + if (this->pinReverse != UnusedPin) { + pinMode(pinReverse, INPUT); } update(); // set initial gear position } @@ -796,10 +796,10 @@ int AnalogShifter::getPositionRaw(Axis ax) const { bool AnalogShifter::getReverseButton() const { // if the reverse pin is not set *or* if the device is not currently // connected, avoid reading the floating input and just return 'false' - if (PinReverse == UnusedPin || detector.getState() != DeviceConnection::Connected) { + if (pinReverse == UnusedPin || detector.getState() != DeviceConnection::Connected) { return false; } - return digitalRead(PinReverse); + return digitalRead(pinReverse); } void AnalogShifter::setCalibration( diff --git a/src/SimRacing.h b/src/SimRacing.h index 55728a6..b1cea20 100644 --- a/src/SimRacing.h +++ b/src/SimRacing.h @@ -120,13 +120,13 @@ namespace SimRacing { */ bool readPin() const; - const PinNum Pin; ///< The pin number being read from. Can be 'UnusedPin' to disable - const bool Inverted; ///< Whether the input is inverted, so 'LOW' is detected instead of 'HIGH' + PinNum pin; ///< The pin number being read from. Can be 'UnusedPin' to disable + bool inverted; ///< Whether the input is inverted, so 'LOW' is detected instead of 'HIGH' unsigned long stablePeriod; ///< The amount of time the input must be stable for (ms) - ConnectionState state; ///< The current state of the connection - bool pinState; ///< Buffered state of the input pin, accounting for inversion - unsigned long lastChange; ///< Timestamp of the last pin change, in ms (using millis()) + ConnectionState state; ///< The current state of the connection + bool pinState; ///< Buffered state of the input pin, accounting for inversion + unsigned long lastChange; ///< Timestamp of the last pin change, in ms (using millis()) }; @@ -141,9 +141,9 @@ namespace SimRacing { /** * Class constructor * - * @param p the I/O pin for this input (Arduino numbering) + * @param pin the I/O pin for this input (Arduino numbering) */ - AnalogInput(PinNum p); + AnalogInput(PinNum pin); /** * Updates the current value of the axis by polling the ADC @@ -237,9 +237,9 @@ namespace SimRacing { void setCalibration(Calibration newCal); private: - const PinNum Pin = UnusedPin; ///< the digital pin number for this input - int position; ///< the axis' position in its range, buffered - Calibration cal; ///< the calibration values for the axis + PinNum pin; ///< the digital pin number for this input + int position; ///< the axis' position in its range, buffered + Calibration cal; ///< the calibration values for the axis }; @@ -393,11 +393,11 @@ namespace SimRacing { /** * Class constructor * - * @param gasPin the analog pin for the gas pedal potentiometer - * @param brakePin the analog pin for the brake pedal potentiometer - * @param detectPin the digital pin for device detection (high is detected) + * @param pinGas the analog pin for the gas pedal potentiometer + * @param pinBrake the analog pin for the brake pedal potentiometer + * @param pinDetect the digital pin for device detection (high is detected) */ - TwoPedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = UnusedPin); + TwoPedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect = UnusedPin); /** * Sets the calibration data (min/max) for the pedals @@ -421,12 +421,12 @@ namespace SimRacing { /** * Class constructor * - * @param gasPin the analog pin for the gas pedal potentiometer - * @param brakePin the analog pin for the brake pedal potentiometer - * @param clutchPin the analog pin for the clutch pedal potentiometer - * @param detectPin the digital pin for device detection (high is detected) + * @param pinGas the analog pin for the gas pedal potentiometer + * @param pinBrake the analog pin for the brake pedal potentiometer + * @param pinClutch the analog pin for the clutch pedal potentiometer + * @param pinDetect the digital pin for device detection (high is detected) */ - ThreePedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = UnusedPin); + ThreePedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect = UnusedPin); /** * Sets the calibration data (min/max) for the pedals @@ -552,9 +552,9 @@ namespace SimRacing { * @param pinX the analog input pin for the X axis * @param pinY the analog input pin for the Y axis * @param pinRev the digital input pin for the 'reverse' button - * @param detectPin the digital pin for device detection (high is detected) + * @param pinDetect the digital pin for device detection (high is detected) */ - AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum detectPin = UnusedPin); + AnalogShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum pinDetect = UnusedPin); /** * Initializes the hardware pins for reading the gear states. @@ -675,7 +675,7 @@ namespace SimRacing { } calibration; AnalogInput analogAxis[2]; ///< Axis data for X and Y - const PinNum PinReverse; ///< The pin for the reverse gear button + PinNum pinReverse; ///< The pin for the reverse gear button DeviceConnection detector; ///< detector instance for checking if the shifter is connected }; @@ -691,9 +691,9 @@ namespace SimRacing { * Class constructor * * @param pinAx analog pin number for the handbrake axis - * @param detectPin the digital pin for device detection (high is detected) + * @param pinDetect the digital pin for device detection (high is detected) */ - Handbrake(PinNum pinAx, PinNum detectPin = UnusedPin); + Handbrake(PinNum pinAx, PinNum pinDetect = UnusedPin); /** * Initializes the pin for reading from the handbrake. @@ -760,7 +760,7 @@ namespace SimRacing { class LogitechPedals : public ThreePedals { public: /** @copydoc ThreePedals::ThreePedals */ - LogitechPedals(PinNum gasPin, PinNum brakePin, PinNum clutchPin, PinNum detectPin = UnusedPin); + LogitechPedals(PinNum pinGas, PinNum pinBrake, PinNum pinClutch, PinNum pinDetect = UnusedPin); }; /** @@ -775,7 +775,7 @@ namespace SimRacing { class LogitechDrivingForceGT_Pedals : public TwoPedals { public: /** @copydoc TwoPedals::TwoPedals */ - LogitechDrivingForceGT_Pedals(PinNum gasPin, PinNum brakePin, PinNum detectPin = UnusedPin); + LogitechDrivingForceGT_Pedals(PinNum pinGas, PinNum pinBrake, PinNum pinDetect = UnusedPin); }; /** @@ -787,7 +787,7 @@ namespace SimRacing { class LogitechShifter : public AnalogShifter { public: /** @copydoc AnalogShifter::AnalogShifter */ - LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum detectPin = UnusedPin); + LogitechShifter(PinNum pinX, PinNum pinY, PinNum pinRev = UnusedPin, PinNum pinDetect = UnusedPin); };