@@ -1421,7 +1421,7 @@ LogitechShifterG25::LogitechShifterG25(
14211421{
14221422 // using the calibration values from my own G25 shifter
14231423 this ->setCalibration ({ 508 , 435 }, { 310 , 843 }, { 303 , 8 }, { 516 , 827 }, { 540 , 14 }, { 713 , 846 }, { 704 , 17 });
1424- this ->setCalibrationSequential (425 , 619 , 257 );
1424+ this ->setCalibrationSequential (425 , 257 , 619 );
14251425}
14261426
14271427void LogitechShifterG25::begin () {
@@ -1463,17 +1463,17 @@ bool LogitechShifterG25::updateState(bool connected) {
14631463
14641464 // if we're neutral, check for up/down shift
14651465 if (this ->sequentialState == 0 ) {
1466- if (y > = this ->seqCalibration .upTrigger ) this ->sequentialState = 1 ;
1467- else if (y < = this ->seqCalibration .downTrigger ) this ->sequentialState = -1 ;
1466+ if (y < = this ->seqCalibration .upTrigger ) this ->sequentialState = 1 ;
1467+ else if (y > = this ->seqCalibration .downTrigger ) this ->sequentialState = -1 ;
14681468 }
14691469
14701470 // if we're in up-shift mode, check for release
1471- else if ((this ->sequentialState == 1 ) && (y < this ->seqCalibration .upRelease )) {
1471+ else if ((this ->sequentialState == 1 ) && (y > this ->seqCalibration .upRelease )) {
14721472 this ->sequentialState = 0 ;
14731473 }
14741474
14751475 // if we're in down-shift mode, check for release
1476- else if ((this ->sequentialState == -1 ) && (y > this ->seqCalibration .downRelease )) {
1476+ else if ((this ->sequentialState == -1 ) && (y < this ->seqCalibration .downRelease )) {
14771477 this ->sequentialState = 0 ;
14781478 }
14791479
@@ -1526,16 +1526,35 @@ void LogitechShifterG25::setCalibrationSequential(int neutral, int up, int down,
15261526 releasePoint = engagePoint;
15271527 }
15281528
1529+ // if up/down calibration points are reversed, swap them
1530+ //
1531+ // in v2 of the library, pushing the shifter was 'shift up' and pulling the
1532+ // shifter was 'shift down'
1533+ //
1534+ // in v3 of the library this was fixed, so that pushing the shifter is
1535+ // 'shift down' and pulling the shifter is 'shift up', matching the
1536+ // markings on the shifter itself (or mine, at least). this also matches
1537+ // the behavior of a sequential shift lever in a real rally car
1538+ //
1539+ // by swapping the calibration points here, the function maintains
1540+ // compatibility with calibration lines written for both version of
1541+ // the library
1542+ if (up > down) {
1543+ int temp = up;
1544+ up = down; // dogs and cats living together, mass hysteria
1545+ down = temp;
1546+ }
1547+
15291548 // calculate ranges
1530- const int upRange = up - neutral ;
1531- const int downRange = neutral - down ;
1549+ const int upRange = neutral - up ;
1550+ const int downRange = down - neutral ;
15321551
15331552 // calculate calibration points
1534- this ->seqCalibration .upTrigger = neutral + (upRange * engagePoint);
1535- this ->seqCalibration .upRelease = neutral + (upRange * releasePoint);
1553+ this ->seqCalibration .upTrigger = neutral - (upRange * engagePoint);
1554+ this ->seqCalibration .upRelease = neutral - (upRange * releasePoint);
15361555
1537- this ->seqCalibration .downTrigger = neutral - (downRange * engagePoint);
1538- this ->seqCalibration .downRelease = neutral - (downRange * releasePoint);
1556+ this ->seqCalibration .downTrigger = neutral + (downRange * engagePoint);
1557+ this ->seqCalibration .downRelease = neutral + (downRange * releasePoint);
15391558}
15401559
15411560void LogitechShifterG25::serialCalibrationSequential (Stream& iface) {
@@ -1582,14 +1601,14 @@ void LogitechShifterG25::serialCalibrationSequential(Stream& iface) {
15821601
15831602 const uint8_t NumPoints = 3 ;
15841603 const char * directions[2 ][2 ] = {
1585- { " away from you" , " up" },
1586- { " towards you" , " down" },
1604+ { " towards you" , " up" },
1605+ { " away from you" , " down" },
15871606 };
15881607 int data[NumPoints];
15891608
15901609 int & neutral = data[0 ];
1591- int & yMax = data[1 ];
1592- int & yMin = data[2 ];
1610+ int & yMin = data[1 ];
1611+ int & yMax = data[2 ];
15931612
15941613 for (uint8_t i = 0 ; i < NumPoints; ++i) {
15951614 if (i == 0 ) {
@@ -1635,7 +1654,7 @@ void LogitechShifterG25::serialCalibrationSequential(Stream& iface) {
16351654 flushClient (iface);
16361655
16371656 // apply and print
1638- this ->setCalibrationSequential (neutral, yMax, yMin , engagementPoint, releasePoint);
1657+ this ->setCalibrationSequential (neutral, yMin, yMax , engagementPoint, releasePoint);
16391658
16401659 iface.println (F (" Here is your calibration:" ));
16411660 iface.println (separator);
@@ -1645,10 +1664,10 @@ void LogitechShifterG25::serialCalibrationSequential(Stream& iface) {
16451664
16461665 iface.print (neutral);
16471666 iface.print (" , " );
1648- iface.print (yMax);
1649- iface.print (" , " );
16501667 iface.print (yMin);
16511668 iface.print (" , " );
1669+ iface.print (yMax);
1670+ iface.print (" , " );
16521671
16531672 iface.print (engagementPoint);
16541673 iface.print (" , " );
0 commit comments