The Control Panel applet Joystick calculates calibration values for your device. (If you need this applet for developing you joystick device driver, contact Microsoft Product Support Services and ask for the multimedia joystick control panel applet.) You can use the calibration values to convert the actual values returned by your hardware device to the logical values expected by the joystick interface. Your driver establishes the logical value range in its response to the JDD_GETDEVCAPS message.
The calibration settings consist of base and delta values for each coordinate. The base value represents the lowest logical value the driver returns; the delta value is the multiplier to use when converting the actual value returned by the device to a logical value appropriate for the established value range.
Immediately after MMSYSTEM loads the joystick driver, it reads the calibration values from the SYSTEM.INI file and sends them to your driver with the JDD_SETCALIBRATION message. MMSYSTEM sends the JDD_SETCALIBRATION message with two JOYCALIBRATE structures (pointers to them are passed in the lParam1 and lParam2 parameters). The first structure contains the new calibration settings that your device driver should adopt. Your device driver should fill the second structure with the previous calibration settings.
For a complete description of each JOYCALIBRATE field, see “Joystick Device Driver Data Structure Reference,” later in this chapter.
To calculate the base and delta calibration values, the Joystick applet sets the base value to 0 and the delta values to 1. It then polls the joystick driver while the user holds the joystick at each corner of the device coordinate space. This produces the actual value range returned by the device for each coordinate.
After retrieving the coordinate ranges specified by the joyGetDevCaps function, the applet uses the following formulas to calculate new base and delta values.
wDelta = (wTargetMax - wTargetMin) / (wActualMax - wActualMin)
wBase = wActualMin * wDelta - wTargetMin
In the following example, the joystick returned x coordinate values in the range 43 to 345, compared to a logical value range of 0 to 65535:
wDelta = (65535-0) / (345-43)
= 216
wBase = 43 * 216 - 0
= 9288