Skip to content

Commit 5c4bac3

Browse files
committed
Create type alias for shifter gear numbers
1 parent 80d083e commit 5c4bac3

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/SimRacing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ LogitechDrivingForceGT_Pedals::LogitechDrivingForceGT_Pedals(PinNum gasPin, PinN
605605
// Shifter #
606606
//#########################################################
607607

608-
Shifter::Shifter(int8_t min, int8_t max)
608+
Shifter::Shifter(Gear min, Gear max)
609609
: MinGear(min), MaxGear(max)
610610
{}
611611

@@ -716,7 +716,7 @@ bool AnalogShifter::update() {
716716
// neutral and then immediately return
717717
case(DeviceConnection::Unplug):
718718
{
719-
const int8_t previousGear = this->getGear();
719+
const Gear previousGear = this->getGear();
720720

721721
analogAxis[Axis::X].setPosition(calibration.neutralX);
722722
analogAxis[Axis::Y].setPosition(calibration.neutralY);
@@ -736,13 +736,13 @@ bool AnalogShifter::update() {
736736
break;
737737
}
738738

739-
const int8_t previousGear = this->getGear();
739+
const Gear previousGear = this->getGear();
740740
const bool prevOdd = ((previousGear != -1) && (previousGear & 1)); // were we previously in an odd gear
741741
const bool prevEven = (!prevOdd && previousGear != 0); // were we previously in an even gear
742742

743743
const int x = analogAxis[Axis::X].getPosition();
744744
const int y = analogAxis[Axis::Y].getPosition();
745-
int8_t newGear = 0;
745+
Gear newGear = 0;
746746

747747
// If we're below the 'release' thresholds, we must still be in the previous gear
748748
if ((prevOdd && y > calibration.oddRelease) || (prevEven && y < calibration.evenRelease)) {

src/SimRacing.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,18 @@ namespace SimRacing {
470470
*/
471471
class Shifter : public Peripheral {
472472
public:
473+
/**
474+
* Type alias for gear numbers
475+
*/
476+
using Gear = int8_t;
477+
473478
/**
474479
* Class constructor
475480
*
476481
* @param min the lowest gear possible
477482
* @param max the highest gear possible
478483
*/
479-
Shifter(int8_t min, int8_t max);
484+
Shifter(Gear min, Gear max);
480485

481486
/**
482487
* Returns the currently selected gear.
@@ -486,7 +491,7 @@ namespace SimRacing {
486491
*
487492
* @return current gear index
488493
*/
489-
int8_t getGear() const { return currentGear; }
494+
Gear getGear() const { return currentGear; }
490495

491496
/**
492497
* Returns a character that represents the given gear.
@@ -537,21 +542,21 @@ namespace SimRacing {
537542
*
538543
* @return the lowest gear index
539544
*/
540-
int8_t getGearMin() { return MinGear; }
545+
Gear getGearMin() { return MinGear; }
541546

542547
/**
543548
* Retrieves the maximum possible gear index.
544549
*
545550
* @return the highest gear index
546551
*/
547-
int8_t getGearMax() { return MaxGear; }
552+
Gear getGearMax() { return MaxGear; }
548553

549554
protected:
550-
const int8_t MinGear; ///< the lowest selectable gear
551-
const int8_t MaxGear; ///< the highest selectable gear
555+
const Gear MinGear; ///< the lowest selectable gear
556+
const Gear MaxGear; ///< the highest selectable gear
552557

553-
int8_t currentGear; ///< index of the current gear
554-
bool changed; ///< whether the gear has changed since the previous update
558+
Gear currentGear; ///< index of the current gear
559+
bool changed; ///< whether the gear has changed since the previous update
555560
};
556561

557562

0 commit comments

Comments
 (0)