Reads from the Logitech G25 shifter and prints the data over serial.
const int Pin_ShifterX = A0;
const int Pin_ShifterY = A2;
const int Pin_ShifterLatch = 5;
const int Pin_ShifterClock = 6;
const int Pin_ShifterData = 7;
const int Pin_ShifterLED =
SimRacing::UnusedPin;
const int Pin_ShifterDetect = SimRacing::UnusedPin;
Pin_ShifterX, Pin_ShifterY,
Pin_ShifterLatch, Pin_ShifterClock, Pin_ShifterData,
Pin_ShifterLED, Pin_ShifterDetect
);
void printConditional(bool state, char pressed);
void printButton(ShifterButton button, char pressed);
void printShifter();
const unsigned long PrintSpeed = 1500;
unsigned long lastPrint = 0;
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Logitech G25 Starting...");
}
void loop() {
if (Serial.read() != -1) {
shifter.serialCalibrationSequential();
delay(2000);
}
bool dataChanged = shifter.
update();
if (dataChanged) {
Serial.print("! ");
printShifter();
}
if (millis() - lastPrint >= PrintSpeed) {
Serial.print(" ");
printShifter();
}
}
void printConditional(bool state, char pressed) {
if (state == true) {
Serial.print(pressed);
}
else {
Serial.print('_');
}
}
void printButton(ShifterButton button, char pressed) {
bool state = shifter.getButton(button);
printConditional(state, pressed);
}
void printShifter() {
if (shifter.inSequentialMode()) {
Serial.print("S:[");
printConditional(shifter.getShiftUp(), '+');
printConditional(shifter.getShiftDown(), '-');
Serial.print(']');
}
else {
Serial.print("H: [");
Serial.print("]");
}
Serial.print(" - XY: (");
Serial.print(", ");
Serial.print(") ");
printButton(ShifterButton::DPAD_LEFT, '<');
printButton(ShifterButton::DPAD_UP, '^');
printButton(ShifterButton::DPAD_DOWN, 'v');
printButton(ShifterButton::DPAD_RIGHT, '>');
Serial.print(' ');
printButton(ShifterButton::BUTTON_NORTH, 'N');
printButton(ShifterButton::BUTTON_SOUTH, 'S');
printButton(ShifterButton::BUTTON_EAST, 'E');
printButton(ShifterButton::BUTTON_WEST, 'W');
Serial.print(' ');
printButton(ShifterButton::BUTTON_1, '1');
printButton(ShifterButton::BUTTON_2, '2');
printButton(ShifterButton::BUTTON_3, '3');
printButton(ShifterButton::BUTTON_4, '4');
Serial.println();
lastPrint = millis();
}
Header file for the Sim Racing Library.
void serialCalibration(Stream &iface=Serial)
Runs an interactive calibration tool using the serial interface.
int getPositionRaw(Axis ax) const
Retrieves the buffered position for the analog axis.
virtual void begin()
Initializes the hardware pins for reading the gear states.
Interface with the Logitech G25 shifter.
Button
Enumeration of button values.
bool update()
Perform a poll of the hardware to refresh the class state.
static char getGearChar(int gear)
Returns a character that represents the given gear.