Skip to content

Commit b8ede59

Browse files
committed
Add deadzone option to pedal serial calibration
This allows the user to set independent 'start' and 'end' deadzones for their pedal serial calibration. The purpose is to prevent pedals from being slightly pressed in their resting position, and to prevent pedals from reaching their 100% "pressed" position at full extension. By default, this uses a 1% deadzone for the start of travel and a 2.5% deadzone for the end of travel. I'm trying to be conservative here, because the last thing I want is for a user to set a large deadzone and then be unable to compensate for it when using the pedals as an HID device. Still, I think a tiny bit of fuzzing is good and can compensate for noise at the input extremes.
1 parent 97b7a34 commit b8ede59

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/SimRacing.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,61 @@ void Pedals::serialCalibration(Stream& iface) {
447447
pedalData[i].read(); // read position
448448
pedalCal[i].max = pedalData[i].getPositionRaw(); // set max to the recorded position
449449
}
450+
451+
// deadzone options
452+
iface.println(separator);
453+
iface.println();
454+
455+
float DeadzoneMin = 0.01; // by default, 1% (trying to keep things responsive)
456+
float DeadzoneMax = 0.025; // by default, 2.5%
457+
458+
iface.println(F("These settings are optional. Send 'y' to customize. Send any other character to continue with the default values."));
459+
460+
iface.print(F(" * Pedal Travel Deadzone, Start: \t"));
461+
iface.print(DeadzoneMin);
462+
iface.println(F(" (Used to avoid the pedal always being slightly pressed)"));
463+
464+
iface.print(F(" * Pedal Travel Deadzone, End: \t"));
465+
iface.print(DeadzoneMax);
466+
iface.println(F(" (Used to guarantee that the pedal can be fully pressed)"));
467+
450468
iface.println();
451469

470+
waitClient(iface);
471+
472+
if (iface.read() == 'y') {
473+
iface.println(F("Set the pedal travel starting deadzone as a floating point percentage."));
474+
readFloat(DeadzoneMin, iface);
475+
iface.println();
476+
477+
iface.println(F("Set the pedal travel ending deadzone as a floating point percentage."));
478+
readFloat(DeadzoneMax, iface);
479+
iface.println();
480+
}
481+
482+
flushClient(iface);
483+
484+
// calculate deadzone offsets
485+
for (int i = 0; (i < getNumPedals()) && (i < MaxPedals); i++) {
486+
auto &cMin = pedalCal[i].min;
487+
auto &cMax = pedalCal[i].max;
488+
489+
const int range = abs(cMax - cMin);
490+
const int dzMin = DeadzoneMin * (float)range;
491+
const int dzMax = DeadzoneMax * (float)range;
492+
493+
// non-inverted
494+
if (cMax >= cMin) {
495+
cMax -= dzMax; // 'cut' into the range so it limits sooner
496+
cMin += dzMin;
497+
}
498+
// inverted
499+
else {
500+
cMax += dzMax;
501+
cMin -= dzMin;
502+
}
503+
}
504+
452505
// print finished calibration
453506
iface.println(F("Here is your calibration:"));
454507
iface.println(separator);

0 commit comments

Comments
 (0)