Emulates the shifter as a joystick over USB.
#include <Joystick.h>
const bool SendAnalogAxis = false;
const bool SendReverseRaw = false;
const int Pin_ShifterX = A0;
const int Pin_ShifterY = A2;
const int Pin_ShifterRev = 2;
const int Gears[] = { 1, 2, 3, 4, 5, 6, -1 };
const int NumGears = sizeof(Gears) / sizeof(Gears[0]);
const int ADC_Max = 1023;
Joystick_ Joystick(
JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK,
NumGears + SendReverseRaw,
0,
SendAnalogAxis, SendAnalogAxis,
false, false, false, false, false, false, false, false, false);
void updateJoystick();
void setup() {
Joystick.begin(false);
Joystick.setXAxisRange(0, ADC_Max);
Joystick.setYAxisRange(ADC_Max, 0);
updateJoystick();
}
void loop() {
updateJoystick();
}
}
void updateJoystick() {
for (int i = 0; i < NumGears; i++) {
if (shifter.
getGear() == Gears[i]) {
Joystick.pressButton(i);
}
else {
Joystick.releaseButton(i);
}
}
if (SendAnalogAxis == true) {
Joystick.setXAxis(x);
Joystick.setYAxis(y);
}
if (SendReverseRaw == true) {
Joystick.setButton(NumGears, reverseState);
}
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.