Unit Joystick

From Ultibo.org
Jump to: navigation, search

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



[Expand]
Joystick specific constants JOYSTICK_*


[Expand]
Joystick device types JOYSTICK_TYPE_*


[Expand]
Joystick device states JOYSTICK_STATE_*


[Expand]
Joystick device flags JOYSTICK_FLAG_*


[Expand]
Joystick device control codes JOYSTICK_CONTROL_*


[Expand]
Joystick buffer size JOYSTICK_BUFFER_*


[Expand]
Joystick axis, hat and button maximum JOYSTICK_MAX_*


[Expand]
Joystick default minimum and maximum JOYSTICK_DEFAULT_*


[Expand]
Joystick and Gamepad axis names JOYSTICK_AXIS_*


[Expand]
Joystick and Gamepad hat names JOYSTICK_HAT*


[Expand]
Joystick and Gamepad button names JOYSTICK_BUTTON_*


[Expand]
Joystick logging JOYSTICK_LOG_*


Type definitions



Joystick data

[Expand]

PJoystickData = ^TJoystickData;

TJoystickData = record

Joystick buffer

[Expand]

PJoystickBuffer = ^TJoystickBuffer;

TJoystickBuffer = record

Joystick extent

[Expand]

PJoystickExtent = ^TJoystickExtent;

TJoystickExtent = record

Joystick axis

[Expand]

PJoystickAxis = ^TJoystickAxis;

TJoystickAxis = record

Joystick hat

[Expand]

PJoystickHat = ^TJoystickHat;

TJoystickHat = record

Joystick properties

[Expand]

PJoystickProperties = ^TJoystickProperties;

TJoystickProperties = record

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

[Expand]

PJoystickDevice = ^TJoystickDevice;

TJoystickDevice = record


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

[Expand]
procedure JoystickInit;
Description: Initialize the Joystick unit and Joystick device table


Joystick functions

[Expand]
function JoystickDeviceStart(Joystick:PJoystickDevice):LongWord;
Description: Start the specified Joystick device ready for receiving events


[Expand]
function JoystickDeviceStop(Joystick:PJoystickDevice):LongWord;
Description: Stop the specified Joystick device and terminate receiving events


[Expand]
function JoystickDevicePeek(Joystick:PJoystickDevice):LongWord;
Description: Peek at the buffer of the specified joystick device to see if any data packets are ready


[Expand]
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


[Expand]
function JoystickDeviceWrite(Joystick:PJoystickDevice; Buffer:Pointer; Size,Count:LongWord):LongWord;
Description: Write joystick data packets to the buffer of the specified joystick device


[Expand]
function JoystickDeviceFlush(Joystick:PJoystickDevice):LongWord;
Description: Flush the contents of the buffer of the specified joystick device


[Expand]
function JoystickDeviceUpdate(Joystick:PJoystickDevice):LongWord;
Description: Request the specified Joystick device to update the current configuration


[Expand]
function JoystickDeviceControl(Joystick:PJoystickDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;
Description: Perform a control request on the specified Joystick device


[Expand]
function JoystickDeviceGetProperties(Joystick:PJoystickDevice; Properties:PJoystickProperties):LongWord;
Description: Get the properties for the specified Joystick device


[Expand]
function JoystickDeviceSetState(Joystick:PJoystickDevice; State:LongWord):LongWord;
Description: Set the state of the specified joystick and send a notification


[Expand]
function JoystickDeviceCreate:PJoystickDevice;
Description: Create a new Joystick device entry


[Expand]
function JoystickDeviceCreateEx(Size:LongWord):PJoystickDevice;
Description: Create a new Joystick device entry


[Expand]
function JoystickDeviceDestroy(Joystick:PJoystickDevice):LongWord;
Description: Destroy an existing Joystick device entry


[Expand]
function JoystickDeviceRegister(Joystick:PJoystickDevice):LongWord;
Description: Register a new Joystick device in the Joystick device table


[Expand]
function JoystickDeviceDeregister(Joystick:PJoystickDevice):LongWord;
Description: Deregister a Joystick device from the Joystick device table


[Expand]
function JoystickDeviceFind(JoystickId:LongWord):PJoystickDevice;
Description: Find a Joystick device by ID in the Joystick device table


[Expand]
function JoystickDeviceFindByName(const Name:String):PJoystickDevice; inline;
Description: Find a Joystick device by name in the device table


[Expand]
function JoystickDeviceFindByDescription(const Description:String):PJoystickDevice; inline;
Description: Find a Joystick device by description in the device table


[Expand]
function JoystickDeviceEnumerate(Callback:TJoystickEnumerate; Data:Pointer):LongWord;
Description: Enumerate all Joystick devices in the Joystick device table


[Expand]
function JoystickDeviceNotification(Joystick:PJoystickDevice; Callback:TJoystickNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for Joystick device changes


Joystick helper functions

[Expand]
function JoystickGetCount:LongWord;
Description: Get the current Joystick device count


[Expand]
function JoystickDeviceGetDefault:PJoystickDevice;
Description: Get the current default Joystick device


[Expand]
function JoystickDeviceSetDefault(Joystick:PJoystickDevice):LongWord;
Description: Set the current default Joystick device


[Expand]
function JoystickDeviceCheck(Joystick:PJoystickDevice):PJoystickDevice;
Description: Check if the supplied Joystick device is in the Joystick device table


[Expand]
function JoystickDeviceAxisToString(Name:LongWord):String;
Description: Return a string describing a Joystick or Gamepad Axis (eg JOYSTICK_AXIS_X)


[Expand]
function JoystickDeviceHatToString(Name:LongWord):String;
Description: Return a string describing a Joystick or Gamepad Hat (eg JOYSTICK_HAT_POV)


[Expand]
function JoystickDeviceButtonToString(Name:LongWord):String;
Description: Return a string describing a Joystick or Gamepad Button (eg GAMEPAD_BUTTON_UP)


[Expand]
function JoystickDeviceTypeToString(JoystickType:LongWord):String;
Description: Return a string describing the Joystick device type (eg JOYSTICK_TYPE_JOYSTICK)


[Expand]
function JoystickDeviceStateToString(JoystickState:LongWord):String;
Description: Return a string describing the Joystick device state (eg JOYSTICK_STATE_ENABLED)


[Expand]
function JoystickDeviceStateToNotification(State:LongWord):LongWord;
Description: Convert a Joystick state value into the notification code for device notifications


[Expand]
function JoystickDeviceGetAxis(Joystick:PJoystickDevice; Index:LongWord):LongWord;
Description: Get the name (identifier) of an Axis on the specified Joystick


[Expand]
function JoystickDeviceSetAxis(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;
Description: Set the name (identifier) of an Axis on the specified Joystick


[Expand]
function JoystickDeviceGetHat(Joystick:PJoystickDevice; Index:LongWord):LongWord;
Description: Get the name (identifier) of a Hat on the specified Joystick


[Expand]
function JoystickDeviceSetHat(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;
Description: Set the name (identifier) of a Hat on the specified Joystick


[Expand]
function JoystickDeviceGetButton(Joystick:PJoystickDevice; Index:LongWord):LongWord;
Description: Get the name (identifier) of a Button on the specified Joystick


[Expand]
function JoystickDeviceSetButton(Joystick:PJoystickDevice; Index,Name:LongWord):LongWord;
Description: Set the name (identifier) of a Button on the specified Joystick


[Expand]
function JoystickDeviceSetCallback(Joystick:PJoystickDevice; Event:TJoystickEvent; Parameter:Pointer):LongWord;
Description: Set the event callback function for the specified Joystick


[Expand]
function JoystickInsertData(Joystick:PJoystickDevice; Data:PJoystickData; Signal:Boolean):LongWord;
Description: Insert a TJoystickData entry into the joystick device buffer


[Expand]
procedure JoystickLog(Level:LongWord; Joystick:PJoystickDevice; const AText:String);
Description: To be documented


[Expand]
procedure JoystickLogInfo(Joystick:PJoystickDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure JoystickLogWarn(Joystick:PJoystickDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure JoystickLogError(Joystick:PJoystickDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure JoystickLogDebug(Joystick:PJoystickDevice; const AText:String); inline;
Description: To be documented


Return to Unit Reference