JOY(4) | Kernel Interfaces Manual | JOY(4) |
The game control adapter allows up to two joysticks to be attached to the system. The adapter plus the driver convert the present resistive value to a relative joystick position. On receipt of an output signal, four timing circuits are started. By determining the time required for the circuit to time-out (a function of the resistance), the paddle position can be determined. The adapter could be used as a general purpose I/O card with four analog (resistive) inputs plus four digital input points.
Applications may call ioctl(2) on a game adapter driver file descriptor to set and get the offsets of the two potentiometers and the maximum time-out value for the circuit. The ioctl(2) commands are listed in <machine/joystick.h> and currently are:
All these commands take an integer parameter.
read(2) on the file descriptor returns a joystick structure:
struct joystick { int x; int y; int b1; int b2; };
The fields have the following functions:
The b1 and b2 fields in struct joystick are set to 1 if the corresponding button is down, 0 otherwise.
The x and y coordinates are supposed to be between 0 and 255 for a good joystick and a good adapter. Unfortunately, because of the hardware hack that is used to measure the position (by measuring the time needed to discharge an RC circuit made from the joystick's potentiometer and a capacitor on the adapter), calibration is needed to determine exactly what values are returned for a specific joystick/adapter combination. Incorrect hardware can yield negative or values greater than 255.
A typical calibration procedure uses the values returned at lower left, center and upper right positions of the joystick to compute the relative position.
This calibration is not part of the driver.
July 22, 2006 | NetBSD 6.1 |