-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement motion sensor support #416
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
be7185e
to
7437814
Compare
6d6cef5
to
cc49b8f
Compare
@mmmaisel
It would make this change easier to review and manage. What do you think? |
My plan was to take the finished code and split it again into different commits, so that there are no things to be reviewed that are changed again (like the mentioned 37407c4 which only refactors code from an earlier commit in this pull request) or reverted a few commits later. This should be very similar than your suggestion. The planned commit outline is:
|
813086c
to
aceb319
Compare
1b64a55
to
33a9b54
Compare
Could you also add some doxygen descriptions for some of the classes you have worked with? (the ones which you got familiar with and are too big to understand at first glance) Anyway. You don't have to do it if, you don't want to or don't have time. |
7c79206
to
83feffe
Compare
If a controller has sensors, add configuration buttons similar to a control stick to the main view. The layout is based on a isometric 3D view with the regular XY axes and a diagonal Z axis. Add a JoySensor button for every direction to the JoySensor object and connect them to the "flashing" events. Add dummy methods for required JoySensor interfaces. Make all the QT connections in JoyTabWidgets as for a JoyControlStick. But I'm not sure for what checkSensorDisplay and checkSensorEmptyDisplay are really used. The new buttons have no function yet. Even though it is possible to map buttons to the sensor directions, but no events will be generated yet.
Draw sensor position like an artifical horizon instrument. This should be very intuitive to understand for accelerometer and not much more difficult for gyroscope. Only draw the diagonal zones for the XY plane to avoid cluttering. Add the required interfaces to JoySensor. Use dummies for non-trivial interfaces. This widget will be used in the coming sensor edit dialog and calibration dialog.
They were implemented as dummies in previous commits.
Add missing setters for dead zone, max zone and diagonal range as well as change events for them. These are required for the coming sensor settings edit dialog. Add missing sensor delay property. Initialize sensor settings with default values from global constants during initialization.
Show this dialog based on JoyControlStickEditDialog when clicking on the central sensor button in the GUI. It allows editing sensor parameters with sliders and spin boxes. This is the first time in the patcheset where sensors can be watch in action in the GUI. Show raw and processed sensor values with correct units in indicators. Presets and sensor preview widget will be implemented in a later commit.
Add group boxes to the common MouseSettingsDialog to hide the parts that are not needed for sensors. This avoids duplicating the dialog for sensors.
Use the existing mouse settings dialog as base and hide the parts that are not needed for sensors. For example, an absolute mouse does not make any sense for gyroscopes because they are relative sensors. Thus, only show mouse sensitivity widgets.
Add presets for the existing mouse variants to gyroscope. Add presets for existing keyboard variants to accelerometer. Do not add all presets to both because a accelerometer mouse or a gyroscope keyboard does not make too much sense. Define the preset values in the caonstructor and not in the .ui file to realize dynamic entries based on the sensor type. With this commit, preset selection from the sensor edit dialog works. Factor out a UI thread helper similar to joycontrolstickcontextmenuhelper or joycontrolstickeditdialoghelper which will be used used for both types of UI.
ControlSticks have context menues which allow quick preset selection so implement them for sensors as well.
Gyroscope calibration is mandatory to get useful information from it. Apply calibration to all sets similar to control sticks. Calibration is applied when queueing pending events so that all following calculations receive corrected values. Define abstract calibration methods on JoySensor class and implement them for JoyGyroscopeSensor. Add some stubs for JoyAccelerometerSensor to make it compile. Calibration workflow as well as load/store of calibration values follow in another commit.
Add gyroscope as input device to the existing calibration dialog and implement a calibration workflow. Only implement offset calibration because calibrating gyroscope gain requires to apply a defined angular velocity to all axes, e.g. with an accurate turntable, which is not feasible for users.
InputDevice and SetJoystick need sensor name interfaces for setting sensor names for loading XML.
Read/write sensor properties similar to a JoyControlStick.
For smooth mouse movement, JoyButton needs information about the current desired movement speed. Do not normalize sensor distances by max zone because this would cause a change in sensitivity when adjusting max zone. Instead, limit the values at max zone.
Implement the required delay timer similar to JoyControlStick. The timer will be used in a following commit.
Add methods to calculate accelerometer and gyroscope directions for measurement values. These methods take the configured diagonal zone into account. The used algorithm is described in the code. The new methods will be used in a following commit.
Perform shock detection through envelope detection with a PT1 filter. The filter needs the sensor event rate to work correctly. If no data rate is available assume a default of 5 ms to avoid division by zero. Using some type of timer does not work because none of SDL ticks, QElapsedTimer and std::chrono::high_resolution_timer had enough resolution to be non-zero between two events. The algorithm used for shock detection is described in the code.
These events and connections are necessary for set change slots. Propagate events that affect all sets from SetJoystick to InputDevice. I'm not 100% sure how all of this works, so implement all events from JoyControlStick for JoySensor as well.
This allows copying sensor assignments from one set to another. Using multiple similar sets is the way to go to configure a "gyro off" button.
Process sensor joyEvents into desktopEvents. The emitted desktop events trigger flashes on the configuration buttons in the GUI and generate the configured key presses.
This saves a few CPU cycles.
This allows users to define a custom neutral controller orientation for the accelerometer. Implement the stubs in JoyAccelerometerSensor.
Add accelerometer as input device to the existing calibration dialog and implement a calibration workflow. The calibration simply gets the desired neutral orientation because offset and gain calibration would require a fixture which exactly aligns the controller to gravity on all axes which is not feasible for users.
Finally merged 🎉 I will prepare test release soon. |
Test release is published here: |
Begin step-by-step implementation of Playstation 4/5 and Switch Pro controllers motion sensor support in AntimicroX. For example, gyro can be mapped as mouse like a stick for precise aiming and the accelerometer can be used to lean in game by tilting the controller.
Closes #375