Skip to content

Commit df38459

Browse files
committed
Add function to control G25/G27 power LED
1 parent 7c81e77 commit df38459

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ getButton KEYWORD2
149149
getButtonChanged KEYWORD2
150150
getDpadAngle KEYWORD2
151151
buttonsChanged KEYWORD2
152+
setPowerLED KEYWORD2
153+
getPowerLED KEYWORD2
152154

153155
#######################################
154156
# LogitechShifterG25 Methods and Functions (KEYWORD2)

src/SimRacing.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ LogitechShifterG27::LogitechShifterG27(
11571157
pinLed(sanitizePin(pinLed))
11581158
{
11591159
this->pinModesSet = false;
1160+
this->setPowerLED(1); // power LED on by default
11601161
this->buttonStates = this->previousButtons = 0x0000; // zero all button data
11611162

11621163
// using the calibration values from my own G27 shifter
@@ -1197,10 +1198,10 @@ void LogitechShifterG27::setPinModes(bool enabled) {
11971198
digitalWrite(this->pinClock, LOW);
11981199
pinMode(this->pinClock, OUTPUT);
11991200

1200-
// if we have an LED pin, set it to output and turn
1201-
// the LED on (active low)
1201+
// if we have an LED pin, set it to output and write the
1202+
// commanded state (inverted, as the LED is active-low)
12021203
if (this->pinLed != UnusedPin) {
1203-
digitalWrite(this->pinLed, LOW);
1204+
digitalWrite(this->pinLed, !(this->ledState));
12041205
pinMode(this->pinLed, OUTPUT);
12051206
}
12061207
}
@@ -1229,6 +1230,10 @@ void LogitechShifterG27::setPinModes(bool enabled) {
12291230
this->pinModesSet = enabled;
12301231
}
12311232

1233+
void LogitechShifterG27::setPowerLED(bool state) {
1234+
this->ledState = state;
1235+
}
1236+
12321237
uint16_t LogitechShifterG27::readShiftRegisters() {
12331238
// if the pin outputs are not set, quit (none pressed)
12341239
if (!this->pinModesSet) return 0x0000;
@@ -1293,6 +1298,10 @@ bool LogitechShifterG27::updateState(bool connected) {
12931298
this->setPinModes(1);
12941299
}
12951300

1301+
if (this->pinLed != UnusedPin) {
1302+
digitalWrite(this->pinLed, !(this->ledState)); // active low
1303+
}
1304+
12961305
const uint16_t data = this->readShiftRegisters();
12971306
this->cacheButtons(data);
12981307
changed |= this->buttonsChanged();

src/SimRacing.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,29 @@ namespace SimRacing {
10241024
*/
10251025
bool buttonsChanged() const;
10261026

1027+
/**
1028+
* Sets the state of the shifter's power LED
1029+
*
1030+
* If the shifter is currently connected, this function will turn the
1031+
* power LED on and off. If the shifter is not connected, this will
1032+
* buffer the commanded state and set the LED when the shifter is next
1033+
* connected.
1034+
*
1035+
* @note The update() function must be called in order to push the
1036+
* commanded state to the shifter.
1037+
*
1038+
* @param state the state to set: 1 = on, 0 = off
1039+
*/
1040+
void setPowerLED(bool state);
1041+
1042+
/**
1043+
* Gets the commanded state of the shifter's power LED
1044+
*
1045+
* @returns 'true' if the power LED is commanded to be on, 'false'
1046+
* if it's commanded to be off.
1047+
*/
1048+
bool getPowerLED() const { return this->ledState; }
1049+
10271050
protected:
10281051
/** @copydoc Peripheral::updateState(bool) */
10291052
virtual bool updateState(bool connected);
@@ -1079,6 +1102,7 @@ namespace SimRacing {
10791102

10801103
// I/O state
10811104
bool pinModesSet; ///< Flag for whether the output pins are enabled / driven
1105+
bool ledState; ///< Commanded state of the power LED output, DE-9 pin 5
10821106

10831107
// Button states
10841108
uint16_t buttonStates; ///< the state of the buttons, as a packed word (where 0 = unpressed and 1 = pressed)

0 commit comments

Comments
 (0)