A joystick is an analog input device that can be used for mouse control and other functions. Currently, only NRF series chips are supported.
TODO:
toml configurationname: 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:
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.
Device reads values from each axis
Adds the bias value to each axis to make the value close to 0 when the joystick is released
About the transform matrix:
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, transform is designed as a divisor.
Each axis value is adjusted to the largest integer multiple of resolution that is less than its original value to reduce noise from ADC device readings.
First set bias to 0, resolution to 1, and transform to [[1, 0, 0], [0, 1, 0], [0, 0, 1]] (matrix dimension depends on the number of axes)
Find the optimal bias value:
JoystickProcessor::generate_report: record = [axis_x, axis_y, axis_z] in debug informationbias value that makes each axis closest to 0 when the joystick is releasedIf the mouse moves too fast, gradually increase the transform value until you find the right sensitivity
If the mouse jitters, gradually increase the resolution value until the jitter disappears
rust configurationBecause 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.