Difference between revisions of "Unit Joystick"

From Ultibo.org
Jump to: navigation, search
Line 406: Line 406:
 
----
 
----
  
''To be documented''
 
  
 +
'''Initialization functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure JoystickInit;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize the Joystick unit and Joystick device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Called only during system startup
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''Joystick functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceStart(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Start the specified Joystick device ready for receiving events</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to start
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceStop(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Stop the specified Joystick device and terminate receiving events</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to stop
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDevicePeek(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Peek at the buffer of the specified joystick device to see if any data packets are ready</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to peek at
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if packets are ready, ERROR_NO_MORE_ITEMS if not or another error code on failure.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceRead(Joystick:PJoystickDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read joystick data packets from the buffer of the specified joystick device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to read from
 +
|-
 +
! Buffer
 +
| Pointer to a buffer to copy the joystick data packets to
 +
|-
 +
! Size
 +
| The size of the buffer in bytes (Must be at least TJoystickData or greater)
 +
|-
 +
! Flags
 +
| The flags for the behaviour of the read (eg JOYSTICK_FLAG_NON_BLOCK)
 +
|-
 +
! Count
 +
| The number of joystick data packets copied to the buffer
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceWrite(Joystick:PJoystickDevice; Buffer:Pointer; Size,Count:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write joystick data packets to the buffer of the specified joystick device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to write to
 +
|-
 +
! Buffer
 +
| Pointer to a buffer to copy the joystick data packets from
 +
|-
 +
! Size
 +
| The size of the buffer in bytes (Must be at least TJoystickData or greater)
 +
|-
 +
! Count
 +
| The number of joystick data packets to copy from the buffer
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceFlush(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Flush the contents of the buffer of the specified joystick device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to flush
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceUpdate(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Request the specified Joystick device to update the current configuration</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to update
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
! Note
 +
| Items updated can include rotation, maximum X and Y and flags (If supported)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceControl(Joystick:PJoystickDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Perform a control request on the specified Joystick device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to control
 +
|-
 +
! Request
 +
| The request code for the operation (eg JOYSTICK_CONTROL_GET_FLAG)
 +
|-
 +
! Argument1
 +
| The first argument for the operation (Dependent on request code)
 +
|-
 +
! Argument2
 +
| The second argument for the operation (Dependent on request code)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceGetProperties(Joystick:PJoystickDevice; Properties:PJoystickProperties):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the properties for the specified Joystick device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to get properties from
 +
|-
 +
! Properties
 +
| Pointer to a TJoystickProperties structure to fill in
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceSetState(Joystick:PJoystickDevice; State:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the state of the specified joystick and send a notification</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The joystick to set the state for
 +
|-
 +
! State
 +
| The new state to set and notify
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceCreate:PJoystickDevice;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create a new Joystick device entry</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Return
 +
| Pointer to new Joystick device entry or nil if Joystick device could not be created
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceCreateEx(Size:LongWord):PJoystickDevice;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create a new Joystick device entry</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Size
 +
| Size in bytes to allocate for new Joystick device (Including the Joystick device entry)
 +
|-
 +
! Return
 +
| Pointer to new Joystick device entry or nil if Joystick device could not be created
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceDestroy(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Destroy an existing Joystick device entry</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to destroy
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceRegister(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Register a new Joystick device in the Joystick device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to register
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceDeregister(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister a Joystick device from the Joystick device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to deregister
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceFind(JoystickId:LongWord):PJoystickDevice;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find a Joystick device by ID in the Joystick device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! JoystickId
 +
| The ID number of the Joystick device to find
 +
|-
 +
! Return
 +
| Pointer to Joystick device entry or nil if not found
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceFindByName(const Name:String):PJoystickDevice; inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find a Joystick device by name in the device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Name
 +
| The name of the Joystick device to find (eg Joystick0)
 +
|-
 +
! Return
 +
| Pointer to Joystick device entry or nil if not found
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceFindByDescription(const Description:String):PJoystickDevice; inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find a Joystick device by description in the device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Description
 +
| The description of the Joystick to find (eg USB Gamepad)
 +
|-
 +
! Return
 +
| Pointer to Joystick device entry or nil if not found
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceEnumerate(Callback:TJoystickEnumerate; Data:Pointer):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Enumerate all Joystick devices in the Joystick device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Callback
 +
| The callback function to call for each Joystick device in the table
 +
|-
 +
! Data
 +
| A private data pointer to pass to callback for each Joystick device in the table
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceNotification(Joystick:PJoystickDevice; Callback:TJoystickNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Register a notification for Joystick device changes</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to notify changes for (Optional, pass nil for all Joystick devices)
 +
|-
 +
! Callback
 +
| The function to call when a notification event occurs
 +
|-
 +
! Data
 +
| A private data pointer to pass to callback when a notification event occurs
 +
|-
 +
! Notification
 +
| The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
 +
|-
 +
! Flags
 +
| The flags to control the notification (eg NOTIFIER_FLAG_WORKER)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 +
'''Joystick helper functions'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickGetCount:LongWord; inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current Joystick device count</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Return
 +
| The number of Joystick devices
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceGetDefault:PJoystickDevice; inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default Joystick device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Return
 +
| Pointer to default Joystick device entry
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceSetDefault(Joystick:PJoystickDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the current default Joystick device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to set as default
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceCheck(Joystick:PJoystickDevice):PJoystickDevice;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied Joystick device is in the Joystick device table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to check
 +
|-
 +
! Return
 +
| Pointer to Joystick device entry or nil if not found
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceAxisToString(Name:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return a string describing a Joystick or Gamepad Axis (eg JOYSTICK_AXIS_X)</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceHatToString(Name:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return a string describing a Joystick or Gamepad Hat (eg JOYSTICK_HAT_POV)</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceButtonToString(Name:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return a string describing a Joystick or Gamepad Button (eg GAMEPAD_BUTTON_UP)</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceTypeToString(JoystickType:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return a string describing the Joystick device type (eg JOYSTICK_TYPE_JOYSTICK)</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceStateToString(JoystickState:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return a string describing the Joystick device state (eg JOYSTICK_STATE_ENABLED)</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceStateToNotification(State:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a Joystick state value into the notification code for device notifications</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceGetAxis(Joystick:PJoystickDevice; Index:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the name (identifier) of an Axis on the specified Joystick</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to get the name from
 +
|-
 +
! Index
 +
| The index of the Axis in the Joystick properties (First Axis is 0)
 +
|-
 +
! Return
 +
| The current name of the Axis (eg GAMEPAD_AXIS_LEFT_X)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceSetAxis(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the name (identifier) of an Axis on the specified Joystick</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to set the name for
 +
|-
 +
! Index
 +
| The index of the Axis in the Joystick properties (First Axis is 0)
 +
|-
 +
! Name
 +
| The name (identifier) to set for the Axis (eg JOYSTICK_AXIS_X)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceGetHat(Joystick:PJoystickDevice; Index:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the name (identifier) of a Hat on the specified Joystick</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to get the name from
 +
|-
 +
! Index
 +
| The index of the Hat in the Joystick properties (First Hat is 0)
 +
|-
 +
! Return
 +
| The current name of the Hat (eg GAMEPAD_HAT_POV)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceSetHat(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the name (identifier) of a Hat on the specified Joystick</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to set the name for
 +
|-
 +
! Index
 +
| The index of the Hat in the Joystick properties (First Hat is 0)
 +
|-
 +
! Name
 +
| The name (identifier) to set for the Axis (eg JOYSTICK_HAT_POV)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceGetButton(Joystick:PJoystickDevice; Index:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the name (identifier) of a Button on the specified Joystick</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to get the name from
 +
|-
 +
! Index
 +
| The index of the Button in the Joystick properties (First Button is 0)
 +
|-
 +
! Return
 +
| The current name of the Button (eg GAMEPAD_BUTTON_B)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceSetButton(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the name (identifier) of a Button on the specified Joystick</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to set the name for
 +
|-
 +
! Index
 +
| The index of the Button in the Joystick properties (First Button is 0)
 +
|-
 +
! Name
 +
| The name (identifier) to set for the Axis (eg GAMEPAD_BUTTON_LT)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickDeviceSetCallback(Joystick:PJoystickDevice; Event:TJoystickEvent; Parameter:Pointer):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the event callback function for the specified Joystick</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The Joystick device to set the event callback for
 +
|-
 +
! Event
 +
| The event callback function to be called when Joystick data is received
 +
|-
 +
! Parameter
 +
| A pointer to private data to be passed to the callback with each event
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function JoystickInsertData(Joystick:PJoystickDevice; Data:PJoystickData; Signal:Boolean):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Insert a TJoystickData entry into the joystick device buffer</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Joystick
 +
| The joystick device to insert data for
 +
|-
 +
! Data
 +
| The TJoystickData entry to insert
 +
|-
 +
! Signal
 +
| If True then signal that new data is available in the buffer
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
! Note
 +
| Caller must hold the joystick device lock
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure JoystickLog(Level:LongWord; Joystick:PJoystickDevice; const AText:String);</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure JoystickLogInfo(Joystick:PJoystickDevice; const AText:String);</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure JoystickLogWarn(Joystick:PJoystickDevice; const AText:String);</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure JoystickLogError(Joystick:PJoystickDevice; const AText:String);</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure JoystickLogDebug(Joystick:PJoystickDevice; const AText:String);</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
Return to [[Unit_Reference|Unit Reference]]
 
Return to [[Unit_Reference|Unit Reference]]

Revision as of 23:47, 17 November 2022

Return to Unit Reference


Description


Ultibo Joystick and Gamepad Interface unit

Gamepads are almost universally used to control game consoles and other gaming platforms as they provide an easy way to interact with many different types of movement in gaming scenarios.

They range from simple devices with a 4 way rocker switch (often known as the D-pad) and a small number of push buttons to elaborate units with multi-axis controls and buttons that cover a whole range of uses.

Joysticks are used for more than just gaming, many modern industrial machines use a joystick as the primary control interface. Even common machines like ride on lawn mowers and earth moving equipment often feature a joystick type of control mechanism.

Devices such as flight simulator yokes will often also appear as a joystick to the system as the available ranges of movement and the reported axes are the same.

Constants


To be documented

Type definitions



Joystick data

PJoystickData = ^TJoystickData;

TJoystickData = record

AxisCount:LongInt; The number of Axes reported by this device
Axes:array[0..JOYSTICK_MAX_AXIS - 1] of SmallInt; The currently reported value of each Axis
HatCount:LongInt; The number of Hats reported by this device
Hats:array[0..JOYSTICK_MAX_HAT - 1] of SmallInt; The currently reported value of each Hat
ButtonCount:LongInt; The number of Buttons reported by this device
Buttons:LongWord; The currently reported state of each Button
Parameter:Pointer; The parameter for the event callback (If applicable)

Joystick buffer

PJoystickBuffer = ^TJoystickBuffer;

TJoystickBuffer = record

Wait:TSemaphoreHandle; Buffer ready semaphore
Start:LongWord; Index of first buffer ready
Count:LongWord; Number of entries ready in buffer
Buffer:array[0..(JOYSTICK_BUFFER_SIZE - 1)] of TJoystickData;  

Joystick extent

PJoystickExtent = ^TJoystickExtent;

TJoystickExtent = record

Minimum:LongInt; The minimum value for this extent
Maximum:LongInt; The maximum value for this extent

Joystick axis

PJoystickAxis = ^TJoystickAxis;

TJoystickAxis = record

Name:LongWord; The associated name (identifier) for this Axis
Logical:TJoystickExtent; The minimum and maximum logical values for this Axis
Physical:TJoystickExtent; The minimum and maximum physical values for this Axis
Multiplier:Double; The conversion multiplier for this Axis from logical to physical units
Resolution:Double; The unit resolution for this Axis in counts per physical unit

Joystick hat

PJoystickHat = ^TJoystickHat;

TJoystickHat = record

Name:LongWord; The associated name (identifier) for this Hat
Logical:TJoystickExtent; The minimum and maximum logical values for this Hat
Physical:TJoystickExtent; The minimum and maximum physical values for this Hat
Multiplier:Double; The conversion multiplier for this Hat from logical to physical units
Resolution:Double; The unit resolution for this Hat in counts per physical unit

Joystick properties

PJoystickProperties = ^TJoystickProperties;

TJoystickProperties = record

Flags:LongWord; Device flags (eg JOYSTICK_FLAG_LED)
AxisCount:LongWord; The number of Axes reported by this device
Axes:array[0..JOYSTICK_MAX_AXIS - 1] of TJoystickAxis; The current properties of each Axis
HatCount:LongWord; The number of Hats reported by this device
Hats:array[0..JOYSTICK_MAX_HAT - 1] of TJoystickHat; The current properties of each Hat
ButtonCount:LongWord; The number of Buttons reported by this device
Buttons:array[0..JOYSTICK_MAX_BUTTON - 1] of LongWord; The current name (identifier) of each Button

Joystick event callback

TJoystickEvent = function(Joystick:PJoystickDevice; Data:PJoystickData):LongWord;

Joystick enumeration callback

TJoystickEnumerate = function(Joystick:PJoystickDevice; Data:Pointer):LongWord;

Joystick notification callback

TJoystickNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;

Joystick device start

TJoystickDeviceStart = function(Joystick:PJoystickDevice):LongWord;

Joystick device stop

TJoystickDeviceStop = function(Joystick:PJoystickDevice):LongWord;

Joystick device peek

TJoystickDevicePeek = function(Joystick:PJoystickDevice):LongWord;

Joystick device read

TJoystickDeviceRead = function(Joystick:PJoystickDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;

Joystick device write

TJoystickDeviceWrite = function(Joystick:PJoystickDevice; Buffer:Pointer; Size,Count:LongWord):LongWord;

Joystick device flush

TJoystickDeviceFlush = function(Joystick:PJoystickDevice):LongWord;

Joystick device update

TJoystickDeviceUpdate = function(Joystick:PJoystickDevice):LongWord;

Joystick device control

TJoystickDeviceControl = function(Joystick:PJoystickDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;

Joystick device get properties

TJoystickDeviceGetProperties = function(Joystick:PJoystickDevice; Properties:PJoystickProperties):LongWord;

Joystick device

PJoystickDevice = ^TJoystickDevice;

TJoystickDevice = record

Device Properties
Device:TDevice; The Device entry for this Joystick device
Joystick Properties
JoystickId:LongWord; Unique Id of this Joystick device in the Joystick device table
JoystickState:LongWord; Joystick device state (eg JOYSTICK_STATE_ENABLED)
DeviceStart:TJoystickDeviceStart; A Device specific DeviceStart method implementing the standard Joystick device interface (Mandatory)
DeviceStop:TJoystickDeviceStop; A Device specific DeviceStop method implementing the standard Joystick device interface (Mandatory)
DevicePeek:TJoystickDevicePeek; A Device specific DevicePeek method implementing a standard Joystick device interface (Or nil if the default method is suitable)
DeviceRead:TJoystickDeviceRead; A Device specific DeviceRead method implementing a standard Joystick device interface (Or nil if the default method is suitable)
DeviceWrite:TJoystickDeviceWrite; A Device specific DeviceWrite method implementing a standard Joystick device interface (Or nil if the default method is suitable)
DeviceFlush:TJoystickDeviceFlush; A Device specific DeviceFlush method implementing a standard Joystick device interface (Or nil if the default method is suitable)
DeviceUpdate:TJoystickDeviceUpdate; A Device specific DeviceUpdate method implementing a standard Joystick device interface (Or nil if the default method is suitable)
DeviceControl:TJoystickDeviceControl; A Device specific DeviceControl method implementing a standard Joystick device interface (Or nil if the default method is suitable)
DeviceGetProperties:TJoystickDeviceGetProperties; A Device specific DeviceGetProperties method implementing a standard Joystick device interface (Or nil if the default method is suitable)
Driver Properties
Lock:TMutexHandle; Device lock
Event:TJoystickEvent; Event callback function (If assigned)
Parameter:Pointer; Parameter for the event callback (or nil)
Buffer:TJoystickBuffer; Joystick input buffer
Properties:TJoystickProperties; Device properties
Statistics Properties
ReceiveCount:LongWord;  
ReceiveErrors:LongWord;  
BufferOverruns:LongWord;  
Internal Properties
Prev:PJoystickDevice; Previous entry in Joystick device table
Next:PJoystickDevice; Next entry in Joystick device table


Public variables



Joystick logging

JOYSTICK_DEFAULT_LOG_LEVEL:LongWord = JOYSTICK_LOG_LEVEL_DEBUG; Minimum level for Joystick messages. Only messages with level greater than or equal to this will be printed.
JOYSTICK_LOG_ENABLED:Boolean;


Function declarations



Initialization functions

procedure JoystickInit;
Description: Initialize the Joystick unit and Joystick device table
Note Called only during system startup


Joystick functions

function JoystickDeviceStart(Joystick:PJoystickDevice):LongWord;
Description: Start the specified Joystick device ready for receiving events
Joystick The Joystick device to start
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceStop(Joystick:PJoystickDevice):LongWord;
Description: Stop the specified Joystick device and terminate receiving events
Joystick The Joystick device to stop
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDevicePeek(Joystick:PJoystickDevice):LongWord;
Description: Peek at the buffer of the specified joystick device to see if any data packets are ready
Joystick The Joystick device to peek at
Return ERROR_SUCCESS if packets are ready, ERROR_NO_MORE_ITEMS if not or another error code on failure.


function JoystickDeviceRead(Joystick:PJoystickDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Read joystick data packets from the buffer of the specified joystick device
Joystick The Joystick device to read from
Buffer Pointer to a buffer to copy the joystick data packets to
Size The size of the buffer in bytes (Must be at least TJoystickData or greater)
Flags The flags for the behaviour of the read (eg JOYSTICK_FLAG_NON_BLOCK)
Count The number of joystick data packets copied to the buffer
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceWrite(Joystick:PJoystickDevice; Buffer:Pointer; Size,Count:LongWord):LongWord;
Description: Write joystick data packets to the buffer of the specified joystick device
Joystick The Joystick device to write to
Buffer Pointer to a buffer to copy the joystick data packets from
Size The size of the buffer in bytes (Must be at least TJoystickData or greater)
Count The number of joystick data packets to copy from the buffer
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceFlush(Joystick:PJoystickDevice):LongWord;
Description: Flush the contents of the buffer of the specified joystick device
Joystick The Joystick device to flush
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceUpdate(Joystick:PJoystickDevice):LongWord;
Description: Request the specified Joystick device to update the current configuration
Joystick The Joystick device to update
Return ERROR_SUCCESS if completed or another error code on failure
Note Items updated can include rotation, maximum X and Y and flags (If supported)


function JoystickDeviceControl(Joystick:PJoystickDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;
Description: Perform a control request on the specified Joystick device
Joystick The Joystick device to control
Request The request code for the operation (eg JOYSTICK_CONTROL_GET_FLAG)
Argument1 The first argument for the operation (Dependent on request code)
Argument2 The second argument for the operation (Dependent on request code)
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceGetProperties(Joystick:PJoystickDevice; Properties:PJoystickProperties):LongWord;
Description: Get the properties for the specified Joystick device
Joystick The Joystick device to get properties from
Properties Pointer to a TJoystickProperties structure to fill in
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceSetState(Joystick:PJoystickDevice; State:LongWord):LongWord;
Description: Set the state of the specified joystick and send a notification
Joystick The joystick to set the state for
State The new state to set and notify
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceCreate:PJoystickDevice;
Description: Create a new Joystick device entry
Return Pointer to new Joystick device entry or nil if Joystick device could not be created


function JoystickDeviceCreateEx(Size:LongWord):PJoystickDevice;
Description: Create a new Joystick device entry
Size Size in bytes to allocate for new Joystick device (Including the Joystick device entry)
Return Pointer to new Joystick device entry or nil if Joystick device could not be created


function JoystickDeviceDestroy(Joystick:PJoystickDevice):LongWord;
Description: Destroy an existing Joystick device entry
Joystick The Joystick device to destroy
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceRegister(Joystick:PJoystickDevice):LongWord;
Description: Register a new Joystick device in the Joystick device table
Joystick The Joystick device to register
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceDeregister(Joystick:PJoystickDevice):LongWord;
Description: Deregister a Joystick device from the Joystick device table
Joystick The Joystick device to deregister
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceFind(JoystickId:LongWord):PJoystickDevice;
Description: Find a Joystick device by ID in the Joystick device table
JoystickId The ID number of the Joystick device to find
Return Pointer to Joystick device entry or nil if not found


function JoystickDeviceFindByName(const Name:String):PJoystickDevice; inline;
Description: Find a Joystick device by name in the device table
Name The name of the Joystick device to find (eg Joystick0)
Return Pointer to Joystick device entry or nil if not found


function JoystickDeviceFindByDescription(const Description:String):PJoystickDevice; inline;
Description: Find a Joystick device by description in the device table
Description The description of the Joystick to find (eg USB Gamepad)
Return Pointer to Joystick device entry or nil if not found


function JoystickDeviceEnumerate(Callback:TJoystickEnumerate; Data:Pointer):LongWord;
Description: Enumerate all Joystick devices in the Joystick device table
Callback The callback function to call for each Joystick device in the table
Data A private data pointer to pass to callback for each Joystick device in the table
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceNotification(Joystick:PJoystickDevice; Callback:TJoystickNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for Joystick device changes
Joystick The Joystick device to notify changes for (Optional, pass nil for all Joystick devices)
Callback The function to call when a notification event occurs
Data A private data pointer to pass to callback when a notification event occurs
Notification The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
Flags The flags to control the notification (eg NOTIFIER_FLAG_WORKER)
Return ERROR_SUCCESS if completed or another error code on failure


Joystick helper functions

function JoystickGetCount:LongWord; inline;
Description: Get the current Joystick device count
Return The number of Joystick devices


function JoystickDeviceGetDefault:PJoystickDevice; inline;
Description: Get the current default Joystick device
Return Pointer to default Joystick device entry


function JoystickDeviceSetDefault(Joystick:PJoystickDevice):LongWord;
Description: Set the current default Joystick device
Joystick The Joystick device to set as default
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceCheck(Joystick:PJoystickDevice):PJoystickDevice;
Description: Check if the supplied Joystick device is in the Joystick device table
Joystick The Joystick device to check
Return Pointer to Joystick device entry or nil if not found


function JoystickDeviceAxisToString(Name:LongWord):String;
Description: Return a string describing a Joystick or Gamepad Axis (eg JOYSTICK_AXIS_X)
Note None documented


function JoystickDeviceHatToString(Name:LongWord):String;
Description: Return a string describing a Joystick or Gamepad Hat (eg JOYSTICK_HAT_POV)
Note None documented


function JoystickDeviceButtonToString(Name:LongWord):String;
Description: Return a string describing a Joystick or Gamepad Button (eg GAMEPAD_BUTTON_UP)
Note None documented


function JoystickDeviceTypeToString(JoystickType:LongWord):String;
Description: Return a string describing the Joystick device type (eg JOYSTICK_TYPE_JOYSTICK)
Note None documented


function JoystickDeviceStateToString(JoystickState:LongWord):String;
Description: Return a string describing the Joystick device state (eg JOYSTICK_STATE_ENABLED)
Note None documented


function JoystickDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Joystick state value into the notification code for device notifications
Note None documented


function JoystickDeviceGetAxis(Joystick:PJoystickDevice; Index:LongWord):LongWord;
Description: Get the name (identifier) of an Axis on the specified Joystick
Joystick The Joystick device to get the name from
Index The index of the Axis in the Joystick properties (First Axis is 0)
Return The current name of the Axis (eg GAMEPAD_AXIS_LEFT_X)


function JoystickDeviceSetAxis(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;
Description: Set the name (identifier) of an Axis on the specified Joystick
Joystick The Joystick device to set the name for
Index The index of the Axis in the Joystick properties (First Axis is 0)
Name The name (identifier) to set for the Axis (eg JOYSTICK_AXIS_X)
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceGetHat(Joystick:PJoystickDevice; Index:LongWord):LongWord;
Description: Get the name (identifier) of a Hat on the specified Joystick
Joystick The Joystick device to get the name from
Index The index of the Hat in the Joystick properties (First Hat is 0)
Return The current name of the Hat (eg GAMEPAD_HAT_POV)


function JoystickDeviceSetHat(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;
Description: Set the name (identifier) of a Hat on the specified Joystick
Joystick The Joystick device to set the name for
Index The index of the Hat in the Joystick properties (First Hat is 0)
Name The name (identifier) to set for the Axis (eg JOYSTICK_HAT_POV)
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceGetButton(Joystick:PJoystickDevice; Index:LongWord):LongWord;
Description: Get the name (identifier) of a Button on the specified Joystick
Joystick The Joystick device to get the name from
Index The index of the Button in the Joystick properties (First Button is 0)
Return The current name of the Button (eg GAMEPAD_BUTTON_B)


function JoystickDeviceSetButton(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;
Description: Set the name (identifier) of a Button on the specified Joystick
Joystick The Joystick device to set the name for
Index The index of the Button in the Joystick properties (First Button is 0)
Name The name (identifier) to set for the Axis (eg GAMEPAD_BUTTON_LT)
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickDeviceSetCallback(Joystick:PJoystickDevice; Event:TJoystickEvent; Parameter:Pointer):LongWord;
Description: Set the event callback function for the specified Joystick
Joystick The Joystick device to set the event callback for
Event The event callback function to be called when Joystick data is received
Parameter A pointer to private data to be passed to the callback with each event
Return ERROR_SUCCESS if completed or another error code on failure


function JoystickInsertData(Joystick:PJoystickDevice; Data:PJoystickData; Signal:Boolean):LongWord;
Description: Insert a TJoystickData entry into the joystick device buffer
Joystick The joystick device to insert data for
Data The TJoystickData entry to insert
Signal If True then signal that new data is available in the buffer
Return ERROR_SUCCESS if completed or another error code on failure
Note Caller must hold the joystick device lock


procedure JoystickLog(Level:LongWord; Joystick:PJoystickDevice; const AText:String);
Description: To be documented
Note None documented


procedure JoystickLogInfo(Joystick:PJoystickDevice; const AText:String);
Description: To be documented
Note None documented


procedure JoystickLogWarn(Joystick:PJoystickDevice; const AText:String);
Description: To be documented
Note None documented


procedure JoystickLogError(Joystick:PJoystickDevice; const AText:String);
Description: To be documented
Note None documented


procedure JoystickLogDebug(Joystick:PJoystickDevice; const AText:String);
Description: To be documented
Note None documented


Return to Unit Reference