Fixes for driving mode changes (#866)

- Use a float divisor to reduce the high resolution counter to a gray
  code. This gives a more stable rate of change for the gray code when
  using a sensitivity other than 1.
- Slightly remap the axis space, so that the positive and negative
  ranges are the same. The new range is [64,-1] [1, 64]. We don't need
  zero, because of the analog dead zone.
- Reorder the Event enum as suggested for on PR860.
This commit is contained in:
eds-collabora 2022-01-21 07:38:30 +00:00 committed by GitHub
parent 97e55f8a63
commit 5b2a365d2a
2 changed files with 6 additions and 6 deletions

View File

@ -124,15 +124,15 @@ void Driving::updateControllerAxes()
int a_axis = myEvent.get(myAnalogEvent); int a_axis = myEvent.get(myAnalogEvent);
if( abs(a_axis) > Controller::analogDeadZone()) { if( abs(a_axis) > Controller::analogDeadZone()) {
/* a_axis is in -2^15 to +2^15-1; dividing by 2^9 gives us -2^6 to /* a_axis is in -2^15 to +2^15-1; adding 1 when non-negative and
+2^6-1, which gives us roughly the same range as digital dividing by 2^9 gives us -2^6 to +2^6, which gives us the same
inputs. range as digital inputs.
*/ */
myCounterHires += a_axis/512; myCounterHires += (a_axis/512) + (a_axis >= 0);
} }
// Only consider the lower-most bits (corresponding to pins 1 & 2) // Only consider the lower-most bits (corresponding to pins 1 & 2)
myGrayIndex = Int32((myCounterHires / 256) * SENSITIVITY) & 0b11; myGrayIndex = Int32((myCounterHires / 256.0) * SENSITIVITY) & 0b11;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -183,7 +183,7 @@ class Event
enum Group enum Group
{ {
Menu, Emulation, Menu, Emulation,
Misc, AudioVideo, States, Console, Joystick, Paddles, Keyboard, Driving, Misc, AudioVideo, States, Console, Joystick, Paddles, Driving, Keyboard,
Devices, Devices,
Debug, Combo, Debug, Combo,
LastGroup LastGroup