Simple MATLAB
Cursor class to log/display 2D position of virtual cursor that implements acceleration, velocity, and position states. Polling the joystick using basic Windows c
API modified from the code available in Psychtoolbox.
- Smooth and configurable joystick-based cursor control.
- Logging of joystick input to a binary file.
- Visualization of cursor movement in 2D space.
- Automatic compilation of
WinJoystickMex
if not present.
Add this as a submodule to your existing project- but make sure to put it in a folder named +cursor
git submodule add git@github.com:Neuro-Mechatronics-Interfaces/matlab_package__cursor.git +cursor
git submodule update --init --recursive
After adding the submodule, your MATLAB workspace (project
, below) should look like this:
project/
├── +cursor/
| ├── createButtonListener.m % Utility function to generate listeners for indexed button events.
│ ├── @Cursor/
| | ├──Cursor.m % Cursor class definition
│ | ├── WinJoystickMex.c % Source file for the joystick MEX function
│ ├── @GameContainer/
| | ├──GameContainer.m % Container class definition
│ ├── @ButtonEventData/
| ├──ButtonEventData.m % EventData definition for when BUTTON1-BUTTON8 is pressed.
- Create a
Cursor
object: Initialize the class to handle the joystick-based cursor. - Enable Logging: Configure the logging to output a
.dat
file. - Start Sampling and View Cursor: Launch the cursor visualization and joystick sampling.
- Stop Sampling: Stop the sampling process gracefully.
- The
WinJoystickMex.c
file must be present in the@Cursor
folder. - MATLAB automatically compiles the
WinJoystickMex
file if not already compiled. - Ensure
WinJoystickMex.c
compiles successfully with the required libraries (-lwinmm
on Windows).
- MATLAB R2022b or later (tested).
- A compatible joystick connected to the system.
- Compiler installed and configured for MEX files on your system.
- Ensure the
WinJoystickMex.c
file is present in the@Cursor
folder. - Ensure MATLAB can access a compatible C compiler.
- This typically occurs if the joystick data is not correctly processed. Ensure the
Cursor
class implementation matches the required logic for handling joystick data.