Joysticks
A joystick is an analog input device that can be used for mouse control and other functions. Currently, only NRF series chips are supported.
- You need to use a debug probe to find your parameters now.
- Only Nrf is supported now.
TODO:
- a more intuitive way to configure the joystick
- more functions besides mouse
toml configuration
Parameters:
name: Unique name for the joystick. If you have multiple joysticks, they need different namespin_x: Pin for X-axispin_y: Pin for Y-axispin_z: Pin for Z-axistransform: Transformation matrix for the joystickbias: Bias value for each axisresolution: Resolution for each axis
_ indicates that the axis does not exist. _ is only allowed for:
- Both y and z axes
- Only z axis
For example: pin_x = "_" pin_y = "P0_29" pin_z = "P0_30" is not allowed
The transform might be not very intuitive, please read the document below for more information.
How it works
-
Device reads values from each axis
-
Adds the
biasvalue to each axis to make the value close to 0 when the joystick is released -
About the
transformmatrix:- New x-axis value = (axis_x + bias[0]) / transform[0][0] + (axis_y + bias[1]) / transform[0][1] + (axis_z + bias[2]) / transform[0][2]
- New y-axis value = (axis_x + bias[0]) / transform[1][0] + (axis_y + bias[1]) / transform[1][1] + (axis_z + bias[2]) / transform[1][2]
- New z-axis value = (axis_x + bias[0]) / transform[2][0] + (axis_y + bias[1]) / transform[2][1] + (axis_z + bias[2]) / transform[2][2]
If
transform[new_axis][old_axis]is 0, that old axis value is ignored.Since the value range read by the ADC device is usually much larger than the mouse report range of -256~255,
transformis designed as a divisor. -
Each axis value is adjusted to the largest integer multiple of
resolutionthat is less than its original value to reduce noise from ADC device readings.
How to find configuration for your hardware quickly
-
First set
biasto 0,resolutionto 1, andtransformto[[1, 0, 0], [0, 1, 0], [0, 0, 1]](matrix dimension depends on the number of axes) -
Find the optimal
biasvalue:- Use a debug probe to find the output
JoystickProcessor::generate_report: record = [axis_x, axis_y, axis_z]in debug information - Observe these values to find the
biasvalue that makes each axis closest to 0 when the joystick is released
- Use a debug probe to find the output
-
If the mouse moves too fast, gradually increase the
transformvalue until you find the right sensitivity -
If the mouse jitters, gradually increase the
resolutionvalue until the jitter disappears
rust configuration
Because the joystick and battery use the same ADC peripheral, they actually use the same NrfAdc input_device.
If the light_sleep is not None, the NrfAdc will enter light sleep mode when no event is generated after 1200ms, and the polling interval will be reduced to the value assigned.