36const bool SendAnalogAxis =
false;
41const bool SendReverseRaw =
false;
43const int Pin_ShifterX = A0;
44const int Pin_ShifterY = A2;
45const int Pin_ShifterRev = 2;
50const int Gears[] = { 1, 2, 3, 4, 5, 6, -1 };
51const int NumGears =
sizeof(Gears) /
sizeof(Gears[0]);
53const int ADC_Max = 1023;
56 JOYSTICK_DEFAULT_REPORT_ID,
57 JOYSTICK_TYPE_JOYSTICK,
58 NumGears + SendReverseRaw,
60 SendAnalogAxis, SendAnalogAxis,
61 false,
false,
false,
false,
false,
false,
false,
false,
false);
71 Joystick.begin(
false);
72 Joystick.setXAxisRange(0, ADC_Max);
73 Joystick.setYAxisRange(ADC_Max, 0);
81 if (SendAnalogAxis ==
true || shifter.
gearChanged()) {
86void updateJoystick() {
88 for (
int i = 0; i < NumGears; i++) {
89 if (shifter.
getGear() == Gears[i]) {
90 Joystick.pressButton(i);
93 Joystick.releaseButton(i);
98 if (SendAnalogAxis ==
true) {
99 int x = shifter.
getPosition(SimRacing::X, 0, ADC_Max);
100 int y = shifter.
getPosition(SimRacing::Y, 0, ADC_Max);
101 Joystick.setXAxis(x);
102 Joystick.setYAxis(y);
106 if (SendReverseRaw ==
true) {
108 Joystick.setButton(NumGears, reverseState);
111 Joystick.sendState();
Header file for the Sim Racing Library.
bool getReverseButton() const
Checks the current state of the "reverse" button at the bottom of the shift column.
virtual bool update()
Polls the hardware to update the current gear state.
virtual void begin()
Initializes the hardware pins for reading the gear states.
long getPosition(Axis ax, long rMin=AnalogInput::Min, long rMax=AnalogInput::Max) const
Retrieves the buffered position for the analog axis, rescaled to a nominal range using the calibratio...
Interface with the Logitech Driving Force shifter.
int8_t getGear() const
Returns the currently selected gear.
bool gearChanged() const
Checks whether the current gear has changed since the last update.