Difference between revisions of "Unit Joystick"

From Ultibo.org
Jump to: navigation, search
Line 23: Line 23:
 
----
 
----
  
''To be documented''
+
 
 +
'''Joystick data'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PJoystickData = ^TJoystickData;</code>
 +
 
 +
<code>TJoystickData = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>AxisCount:LongInt;</code>
 +
| The number of Axes reported by this device
 +
|-
 +
| <code>Axes:array[0..JOYSTICK_MAX_AXIS - 1] of SmallInt;</code>
 +
| The currently reported value of each Axis
 +
|-
 +
| <code>HatCount:LongInt;</code>
 +
| The number of Hats reported by this device
 +
|-
 +
| <code>Hats:array[0..JOYSTICK_MAX_HAT - 1] of SmallInt;</code>
 +
| The currently reported value of each Hat
 +
|-
 +
| <code>ButtonCount:LongInt;</code>
 +
| The number of Buttons reported by this device
 +
|-
 +
| <code>Buttons:LongWord;</code>
 +
| The currently reported state of each Button
 +
|-
 +
| <code>Parameter:Pointer;</code>
 +
| The parameter for the event callback (If applicable)
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Joystick buffer'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PJoystickBuffer = ^TJoystickBuffer;</code>
 +
 
 +
<code>TJoystickBuffer = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Wait:TSemaphoreHandle;</code>
 +
| Buffer ready semaphore
 +
|-
 +
| <code>Start:LongWord;</code>
 +
| Index of first buffer ready
 +
|-
 +
| <code>Count:LongWord;</code>
 +
| Number of entries ready in buffer
 +
|-
 +
| <code>Buffer:array[0..(JOYSTICK_BUFFER_SIZE - 1)] of TJoystickData;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Joystick extent'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PJoystickExtent = ^TJoystickExtent;</code>
 +
 
 +
<code>TJoystickExtent = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Minimum:LongInt;</code>
 +
| The minimum value for this extent
 +
|-
 +
| <code>Maximum:LongInt;</code>
 +
| The maximum value for this extent
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Joystick axis'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PJoystickAxis = ^TJoystickAxis;</code>
 +
 
 +
<code>TJoystickAxis = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Name:LongWord;</code>
 +
| The associated name (identifier) for this Axis
 +
|-
 +
| <code>Logical:TJoystickExtent;</code>
 +
| The minimum and maximum logical values for this Axis
 +
|-
 +
| <code>Physical:TJoystickExtent;</code>
 +
| The minimum and maximum physical values for this Axis
 +
|-
 +
| <code>Multiplier:Double;</code>
 +
| The conversion multiplier for this Axis from logical to physical units
 +
|-
 +
| <code>Resolution:Double;</code>
 +
| The unit resolution for this Axis in counts per physical unit
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Joystick hat'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PJoystickHat = ^TJoystickHat;</code>
 +
 
 +
<code>TJoystickHat = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Name:LongWord;</code>
 +
| The associated name (identifier) for this Hat
 +
|-
 +
| <code>Logical:TJoystickExtent;</code>
 +
| The minimum and maximum logical values for this Hat
 +
|-
 +
| <code>Physical:TJoystickExtent;</code>
 +
| The minimum and maximum physical values for this Hat
 +
|-
 +
| <code>Multiplier:Double;</code>
 +
| The conversion multiplier for this Hat from logical to physical units
 +
|-
 +
| <code>Resolution:Double;</code>
 +
| The unit resolution for this Hat in counts per physical unit
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Joystick properties'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PJoystickProperties = ^TJoystickProperties;</code>
 +
 
 +
<code>TJoystickProperties = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>Flags:LongWord;</code>
 +
| Device flags (eg JOYSTICK_FLAG_LED)
 +
|-
 +
| <code>AxisCount:LongWord;</code>
 +
| The number of Axes reported by this device
 +
|-
 +
| <code>Axes:array[0..JOYSTICK_MAX_AXIS - 1] of TJoystickAxis;</code>
 +
| The current properties of each Axis
 +
|-
 +
| <code>HatCount:LongWord;</code>
 +
| The number of Hats reported by this device
 +
|-
 +
| <code>Hats:array[0..JOYSTICK_MAX_HAT - 1] of TJoystickHat;</code>
 +
| The current properties of each Hat
 +
|-
 +
| <code>ButtonCount:LongWord;</code>
 +
| The number of Buttons reported by this device
 +
|-
 +
| <code>Buttons:array[0..JOYSTICK_MAX_BUTTON - 1] of LongWord;</code>
 +
| The current name (identifier) of each Button
 +
|-
 +
|}
 +
</div></div>
 +
 
 +
'''Joystick event callback'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickEvent = function(Joystick:PJoystickDevice; Data:PJoystickData):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick enumeration callback'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickEnumerate = function(Joystick:PJoystickDevice; Data:Pointer):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick notification callback'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick device start'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceStart = function(Joystick:PJoystickDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''Joystick device stop'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceStop = function(Joystick:PJoystickDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick device peek'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDevicePeek = function(Joystick:PJoystickDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick device read'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceRead = function(Joystick:PJoystickDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''Joystick device write'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceWrite = function(Joystick:PJoystickDevice; Buffer:Pointer; Size,Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''Joystick device flush'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceFlush = function(Joystick:PJoystickDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''Joystick device update'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceUpdate = function(Joystick:PJoystickDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick device control'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceControl = function(Joystick:PJoystickDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick device get properties'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TJoystickDeviceGetProperties = function(Joystick:PJoystickDevice; Properties:PJoystickProperties):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Joystick device'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PJoystickDevice = ^TJoystickDevice;</code>
 +
 
 +
<code>TJoystickDevice = record</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
|colspan="2"|''Device Properties''
 +
|-
 +
| <code>Device:TDevice;</code>
 +
| The Device entry for this Joystick device
 +
|-
 +
|colspan="2"|''Joystick Properties''
 +
|-
 +
| <code>JoystickId:LongWord;</code>
 +
| Unique Id of this Joystick device in the Joystick device table
 +
|-
 +
| <code>JoystickState:LongWord;</code>
 +
| Joystick device state (eg JOYSTICK_STATE_ENABLED)
 +
|-
 +
| <code>DeviceStart:TJoystickDeviceStart;</code>
 +
| A Device specific DeviceStart method implementing the standard Joystick device interface (Mandatory)
 +
|-
 +
| <code>DeviceStop:TJoystickDeviceStop;</code>
 +
| A Device specific DeviceStop method implementing the standard Joystick device interface (Mandatory)
 +
|-
 +
| <code>DevicePeek:TJoystickDevicePeek;</code>
 +
| A Device specific DevicePeek method implementing a standard Joystick device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceRead:TJoystickDeviceRead;</code>
 +
| A Device specific DeviceRead method implementing a standard Joystick device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceWrite:TJoystickDeviceWrite;</code>
 +
| A Device specific DeviceWrite method implementing a standard Joystick device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceFlush:TJoystickDeviceFlush;</code>
 +
| A Device specific DeviceFlush method implementing a standard Joystick device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceUpdate:TJoystickDeviceUpdate;</code>
 +
| A Device specific DeviceUpdate method implementing a standard Joystick device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceControl:TJoystickDeviceControl;</code>
 +
| A Device specific DeviceControl method implementing a standard Joystick device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetProperties:TJoystickDeviceGetProperties;</code>
 +
| A Device specific DeviceGetProperties method implementing a standard Joystick device interface (Or nil if the default method is suitable)
 +
|-
 +
|colspan="2"|''Driver Properties''
 +
|-
 +
| <code>Lock:TMutexHandle;</code>
 +
| Device lock
 +
|-
 +
| <code>Event:TJoystickEvent;</code>
 +
| Event callback function (If assigned)
 +
|-
 +
| <code>Parameter:Pointer;</code>
 +
| Parameter for the event callback (or nil)
 +
|-
 +
| <code>Buffer:TJoystickBuffer;</code>
 +
| Joystick input buffer
 +
|-
 +
| <code>Properties:TJoystickProperties;</code>
 +
| Device properties
 +
|-
 +
|colspan="2"|''Statistics Properties''
 +
|-
 +
| <code>ReceiveCount:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>ReceiveErrors:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>BufferOverruns:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|''Internal Properties''
 +
|-
 +
| <code>Prev:PJoystickDevice;</code>
 +
| Previous entry in Joystick device table
 +
|-
 +
| <code>Next:PJoystickDevice;</code>
 +
| Next entry in Joystick device table
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===

Revision as of 05:38, 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


To be documented


Return to Unit Reference