Skip to content

Add a USB mouse sample - #965

Open
PS2HomeDeveloper wants to merge 2 commits into
ps2dev:masterfrom
PS2HomeDeveloper:add-a-usb-mouse-sample
Open

PS2HomeDeveloper wants to merge 2 commits into
ps2dev:masterfrom
PS2HomeDeveloper:add-a-usb-mouse-sample

Conversation

@PS2HomeDeveloper

Copy link
Copy Markdown
Contributor

Summary

Adds a sample for the USB mouse library (libmouse and the ps2mouse IRX) in ee/rpc/mouse/samples. It is added to samples/Makefile_sample as rpc/mouse.

The sample draws a square and a mouse pointer, and uses them to try every part of the mouse API: the three buttons, their double clicks, the wheel, both read modes and all the settings of the driver.

What the sample does

Square (button 1, button 2 and the wheel, with the pointer on it):

  • Button 1: changes its color, and holding it drags it. A double click puts it back in the center.
  • Button 2: a click opens a menu of sizes (128 to 2, the current size is marked). Holding it goes through the sizes, and a double click gives it the original size (64).
  • Wheel: changes its size. In the menu, it moves the mark.

Anywhere else:

  • Button 2 puts the pointer back in the center of the screen.
  • Button 3 changes the read mode (absolute or difference), and a double click resets everything.
  • Acceleration, threshold, double click time and boundary are shown as text. The wheel changes the one under the pointer, or button 1 (raise) and button 2 (lower).

The pointer is only drawn while a mouse is plugged in, and it comes back to its last place when a mouse is plugged in again. The sample works on NTSC and PAL.

API used

PS2MouseInit, PS2MouseGetVersion, PS2MouseEnum, PS2MouseRead, PS2MouseSetReadMode and PS2MouseGetReadMode, PS2MouseSetPosition, PS2MouseReset, PS2MouseSetBoundary and PS2MouseGetBoundary, PS2MouseSetAccel and PS2MouseGetAccel, PS2MouseSetThres and PS2MouseGetThres, PS2MouseSetDblClickTime and PS2MouseGetDblClickTIme.

Files

Only mouse.c calls the driver (and settings.c, for the settings); the other files draw and use what the mouse did in one frame.

  • mouse.c: start, read loop, plug and unplug, reset.
  • gfx.c/gfx.h: screen, rectangles, pointer and text.
  • square.c/square.h: the square.
  • menu.c/menu.h: the menu of sizes.
  • settings.c/settings.h: the settings of the driver.
  • input.h: what the mouse did in one frame.
  • cursor.raw: the pointer image, 16x16 RGBA.

Notes

  • libdebug sets the display to show only the top half of the framebuffer, so the sample calls graph_initialize() to show all of it.
  • In difference mode the driver has no position, so PS2MouseSetPosition is only used in absolute mode.

Testing

Tested on a real PS2 with a USB mouse (plugging it in and out while the sample runs).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant