Difference between revisions of "Unit Mouse"

From Ultibo.org
Jump to: navigation, search
 
(18 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
----
 
----
  
'''Ultibo Mouse interface unit'''
+
'''Ultibo Mouse Interface unit'''
  
This unit provides both the Mouse device interface and the generic USB HID mouse driver.
+
'''Mouse Devices'''
 +
 
 +
This unit provides the Mouse device interface and mouse API to be used by both drivers and applications.
 +
 +
The API includes functions to create, register, locate, read, write, control and configure each connected mouse device.
 +
 
 +
The API supports a global mouse buffer so multiple devices can feed data into a common buffer as well as a buffer per device to allow each device to be used for a specific purpose. For example an application with two separate displays may choose to have a mouse or pointing device to control each one individually.
  
 
=== Constants ===
 
=== Constants ===
Line 86: Line 92:
 
|-
 
|-
 
| <code>MOUSE_FLAG_DIRECT_READ = $00000002;</code>
 
| <code>MOUSE_FLAG_DIRECT_READ = $00000002;</code>
| If set device writes mouse data to its local buffer and which must be read using MouseDeviceRead
+
| If set device writes mouse data to its local buffer which must be read using MouseDeviceRead
 
|-
 
|-
 
| <code>MOUSE_FLAG_SWAP_BUTTONS = $00000004;</code>
 
| <code>MOUSE_FLAG_SWAP_BUTTONS = $00000004;</code>
Line 93: Line 99:
 
| <code>MOUSE_FLAG_PEEK_BUFFER = $00000008;</code>
 
| <code>MOUSE_FLAG_PEEK_BUFFER = $00000008;</code>
 
| Peek at the buffer to see if any data is available, don't remove it. (Used only in Flags parameter of MouseReadEx)
 
| Peek at the buffer to see if any data is available, don't remove it. (Used only in Flags parameter of MouseReadEx)
 +
|-
 +
| <code>MOUSE_FLAG_SWAP_XY = $00000010;</code>
 +
| If set swap the X and Y coordinates
 +
|-
 +
| <code>MOUSE_FLAG_INVERT_X = $00000020;</code>
 +
| If set invert the X coordinate
 +
|-
 +
| <code>MOUSE_FLAG_INVERT_Y = $00000040;</code>
 +
| If set invert the Y coordinate
 +
|-
 +
| <code>MOUSE_FLAG_SWAP_MAX_XY = $00000080;</code>
 +
| If set swap the maximum X and Y values
 
|-
 
|-
 
|colspan="2"|&nbsp;
 
|colspan="2"|&nbsp;
Line 98: Line 116:
 
|colspan="2"|''Flags supported by MOUSE_CONTROL_GET/SET/CLEAR_FLAG''
 
|colspan="2"|''Flags supported by MOUSE_CONTROL_GET/SET/CLEAR_FLAG''
 
|-
 
|-
| <code>MOUSE_FLAG_MASK = MOUSE_FLAG_NON_BLOCK or MOUSE_FLAG_DIRECT_READ or MOUSE_FLAG_SWAP_BUTTONS;</code>
+
|colspan="2"|<code>MOUSE_FLAG_MASK = MOUSE_FLAG_NON_BLOCK or MOUSE_FLAG_DIRECT_READ or MOUSE_FLAG_SWAP_BUTTONS or MOUSE_FLAG_SWAP_XY or MOUSE_FLAG_INVERT_X or MOUSE_FLAG_INVERT_Y or MOUSE_FLAG_SWAP_MAX_XY;</code>
| &nbsp;
+
 
|-
 
|-
 
|}
 
|}
Line 138: Line 155:
 
| <code>MOUSE_CONTROL_GET_MAX_BUTTONS = 10;</code>
 
| <code>MOUSE_CONTROL_GET_MAX_BUTTONS = 10;</code>
 
| Get Maximum Buttons mask (eg MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON etc)
 
| Get Maximum Buttons mask (eg MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON etc)
 +
|-
 +
| <code>MOUSE_CONTROL_GET_ROTATION = 11;</code>
 +
| Get Rotation value (0, 90, 180, 270) (Only where supported by the driver)
 +
|-
 +
| <code>MOUSE_CONTROL_SET_ROTATION = 12;</code>
 +
| Set Rotation value (0, 90, 180, 270) (Only where supported by the driver)
 
|-
 
|-
 
|}
 
|}
Line 203: Line 226:
 
</div></div>
 
</div></div>
 
<br />
 
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 +
<div style="font-size: 14px; padding-left: 12px;">'''Mouse rotation''' <code> MOUSE_ROTATION_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>MOUSE_ROTATION_0 = FRAMEBUFFER_ROTATION_0;</code>
 +
| No rotation
 +
|-
 +
| <code>MOUSE_ROTATION_90  = FRAMEBUFFER_ROTATION_90;</code>
 +
| 90 degree rotation
 +
|-
 +
| <code>MOUSE_ROTATION_180 = FRAMEBUFFER_ROTATION_180;</code>
 +
| 180 degree rotation
 +
|-
 +
| <code>MOUSE_ROTATION_270 = FRAMEBUFFER_ROTATION_270;</code>
 +
| 270 degree rotation
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div style="font-size: 14px; padding-left: 12px;">'''Mouse logging''' <code> MOUSE_LOG_* </code></div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Mouse logging''' <code> MOUSE_LOG_* </code></div>
Line 231: Line 274:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
| <code>USBMOUSE_DRIVER_NAME = 'USB Mouse Driver (HID boot protocol)';</code>
+
|colspan="2"|Note: The following constants are duplicated with the USBMouse unit for backwards compatibility
| Name of USB mouse driver
+
 
|-
 
|-
|colspan="2"|&nbsp;
+
|}
|-
+
</div></div>
| <code>USBMOUSE_MOUSE_DESCRIPTION = 'USB HID Mouse';</code>
+
<br />
| Description of USB mouse device
+
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
|-
+
<div style="font-size: 14px; padding-left: 12px;">'''USB HID types''' <code> USB_HID_* </code></div>
|colspan="2"|&nbsp;
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
 
|colspan="2"|''HID Interface Subclass types (See USB HID v1.11 specification)''
 
|colspan="2"|''HID Interface Subclass types (See USB HID v1.11 specification)''
Line 374: Line 417:
 
|-
 
|-
 
| <code>Buttons:Word;</code>
 
| <code>Buttons:Word;</code>
| style="width: 50%;"|&nbsp;
+
| The bitmap of current button values (eg MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON)
 
|-
 
|-
 
| <code>OffsetX:SmallInt;</code>
 
| <code>OffsetX:SmallInt;</code>
| &nbsp;
+
| The X offset of the mouse pointer (May be negative, read as absolute if Buttons includes MOUSE_ABSOLUTE_X)
 
|-
 
|-
 
| <code>OffsetY:SmallInt;</code>
 
| <code>OffsetY:SmallInt;</code>
| &nbsp;
+
| The Y offset of the mouse pointer (May be negative, read as absolute if Buttons includes MOUSE_ABSOLUTE_Y)
 
|-
 
|-
 
| <code>OffsetWheel:SmallInt;</code>
 
| <code>OffsetWheel:SmallInt;</code>
| &nbsp;
+
| The X offset of the mouse pointer (May be negative, read as absolute if Buttons includes MOUSE_ABSOLUTE_WHEEL)
 +
|-
 +
| <code>MaximumX:Word;</code>
 +
| The maximum X value of the mouse (Only applicable if Buttons includes MOUSE_ABSOLUTE_X, otherwise must be 0)
 +
|-
 +
| <code>MaximumY:Word;</code>
 +
| The maximum Y value of the mouse (Only applicable if Buttons includes MOUSE_ABSOLUTE_Y, otherwise must be 0)
 +
|-
 +
| <code>MaximumWheel:Word;</code>
 +
| The maximum Wheel value of the mouse (Only applicable if Buttons includes MOUSE_ABSOLUTE_WHEEL, otherwise must be 0)
 +
|-
 +
| <code>Reserved:Word;</code>
 +
| Reserved field (Round structure to 16 bytes)
 
|-
 
|-
 
|}
 
|}
Line 408: Line 463:
 
| <code>Buffer:array[0..(MOUSE_BUFFER_SIZE - 1)] of TMouseData; </code>
 
| <code>Buffer:array[0..(MOUSE_BUFFER_SIZE - 1)] of TMouseData; </code>
 
| &nbsp;
 
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
 +
'''Mouse properties'''
 +
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PMouseProperties = ^TMouseProperties;</code>
 +
 +
<code>TMouseProperties = 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 MOUSE_FLAG_SWAP_BUTTONS)
 +
|-
 +
| <code>Rotation:LongWord;</code>
 +
| Screen Rotation (eg MOUSE_ROTATION_180)
 +
|-
 +
| <code>MaxX:LongWord;</code>
 +
| Maximum (absolute) X value for the mouse device
 +
|-
 +
| <code>MaxY:LongWord;</code>
 +
| Maximum (absolute) Y value for the mouse device
 +
|-
 +
| <code>MaxWheel:LongWord;</code>
 +
| Maximum (absolute) wheel value for the mouse device
 +
|-
 +
| <code>MaxButtons:LongWord;</code>
 +
| Maximum buttons mask (eg MOUSE_LEFT_BUTTON or MOUSE_RIGHT_BUTTON etc)
 
|-
 
|-
 
|}
 
|}
Line 435: Line 520:
 
|-
 
|-
 
| <code>TMouseDeviceRead = function(Mouse:PMouseDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</code>
 
| <code>TMouseDeviceRead = function(Mouse:PMouseDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 +
'''Mouse device update'''
 +
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TMouseDeviceUpdate = function(Mouse:PMouseDevice):LongWord; stdcall;</code>
 
| style="width: 40%;"|
 
| style="width: 40%;"|
 
|-
 
|-
Line 443: Line 537:
 
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
|-
 
|-
| <code>TMouseDeviceControl = function(Mouse:PMouseDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;</code>
+
| <code>TMouseDeviceControl = function(Mouse:PMouseDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Mouse device get properties'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TMouseDeviceGetProperties = function(Mouse:PMouseDevice; Properties:PMouseProperties):LongWord; stdcall;</code>
 
| style="width: 40%;"|
 
| style="width: 40%;"|
 
|-
 
|-
Line 475: Line 578:
 
| <code>DeviceRead:TMouseDeviceRead;</code>
 
| <code>DeviceRead:TMouseDeviceRead;</code>
 
| A Device specific DeviceRead method implementing a standard Mouse device interface (Or nil if the default method is suitable)
 
| A Device specific DeviceRead method implementing a standard Mouse device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceUpdate:TMouseDeviceUpdate;</code>
 +
| A Device specific DeviceUpdate method implementing a standard Mouse device interface (Or nil if the default method is suitable)
 
|-
 
|-
 
| <code>DeviceControl:TMouseDeviceControl;</code>
 
| <code>DeviceControl:TMouseDeviceControl;</code>
 
| A Device specific DeviceControl method implementing a standard Mouse device interface (Or nil if the default method is suitable)
 
| A Device specific DeviceControl method implementing a standard Mouse device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetProperties:TMouseDeviceGetProperties;</code>
 +
| A Device specific DeviceGetProperties method implementing a standard Mouse device interface (Or nil if the default method is suitable)
 
|-
 
|-
 
|colspan="2"|''Driver Properties''
 
|colspan="2"|''Driver Properties''
Line 486: Line 595:
 
| <code>Buffer:TMouseBuffer;</code>
 
| <code>Buffer:TMouseBuffer;</code>
 
| Mouse input buffer
 
| Mouse input buffer
 +
|-
 +
| <code>Properties:TMouseProperties;</code>
 +
| Device properties
 
|-
 
|-
 
|colspan="2"|''Statistics Properties''
 
|colspan="2"|''Statistics Properties''
Line 507: Line 619:
 
|-
 
|-
 
|}
 
|}
</div></div>
+
</div></div>  
 +
 
 +
'''USB HID descriptor'''
  
'''USB mouse device types'''
 
 
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
<code>PUSBMouseDevice = ^TUSBMouseDevice;</code>
+
<code>PUSBHIDDescriptor = ^TUSBHIDDescriptor;</code>
  
<code>TUSBMouseDevice = record</code>
+
<code>TUSBHIDDescriptor = packed record</code>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
|colspan="2"|''Mouse Properties''
+
| <code>bLength:Byte;</code>
 +
| style="width: 50%;"|&nbsp;
 
|-
 
|-
| <code>Mouse:TMouseDevice;</code>
+
| <code>bDescriptorType:Byte;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
|colspan="2"|''USB Properties''
+
| <code>bcdHID:Word;</code>
 +
| &nbsp;
 
|-
 
|-
| <code>HIDInterface:PUSBInterface;</code>
+
| <code>bCountryCode:Byte;</code>
| USB HID Mouse Interface
+
| &nbsp;
 
|-
 
|-
| <code>ReportRequest:PUSBRequest;</code>
+
| <code>bNumDescriptors:Byte;</code>
| USB request for mouse report data
+
| &nbsp;
 
|-
 
|-
| <code>ReportEndpoint:PUSBEndpointDescriptor;</code>
+
| <code>bHIDDescriptorType:Byte;</code>
| USB Mouse Interrupt IN Endpoint
+
| &nbsp;
 
|-
 
|-
| <code>PendingCount:LongWord;</code>
+
| <code>wHIDDescriptorLength:Word;</code>
| Number of USB requests pending for this mouse
+
| &nbsp;
 
|-
 
|-
| <code>WaiterThread:TThreadId;</code>
+
|colspan="2"|''Note: Up to two optional bHIDDescriptorType/wHIDDescriptorLength pairs after the Report descriptor details''
| Thread waiting for pending requests to complete (for mouse detachment)
+
 
|-
 
|-
 
|}
 
|}
</div></div>
+
</div></div>  
 
<br />
 
<br />
  
Line 572: Line 685:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 MouseInit;</pre>
 
<pre style="border: 0; padding-bottom:0px;">procedure MouseInit;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize the mouse unit, device table and USB mouse driver</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize the mouse unit and device table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 598: Line 711:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 MouseRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read mouse data packets from the global mouse buffer</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read mouse data packets from the global mouse buffer</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
Line 610: Line 723:
 
|-
 
|-
 
! Count
 
! Count
| The number of mouse data packets copied to the buffer
+
| The number of mouse data packets copied to the bufferm
 
|-
 
|-
 
! Return
 
! Return
Line 700: Line 813:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 MouseDeviceControl(Mouse:PMouseDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseDeviceUpdate(Mouse:PMouseDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Request the specified mouse 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;"
 +
|-
 +
! Mouse
 +
| The mouse device to update
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
! Note
 +
| Items updated can include rotation, maximum X, Y and wheel 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 MouseDeviceControl(Mouse:PMouseDevice; 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 mouse device</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Perform a control request on the specified mouse device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
Line 716: Line 847:
 
! Argument2
 
! Argument2
 
| The second argument for the operation (Dependent on request code)
 
| 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 MouseDeviceGetProperties(Mouse:PMouseDevice; Properties:PMouseProperties):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the properties for the specified mouse device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Mouse
 +
| The mouse device to get properties from
 +
|-
 +
! Properties
 +
| Pointer to a TMouseProperties structure to fill in
 
|-
 
|-
 
! Return
 
! Return
Line 940: Line 1,089:
 
<br />
 
<br />
  
'''USB mouse functions'''
+
'''Mouse helper functions'''
  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 USBMouseDeviceRead(Mouse:PMouseDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseGetCount:LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of MouseDeviceRead API for USB Mouse</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current mouse count</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
 
! Note
 
! Note
| Not intended to be called directly by applications, use MouseDeviceRead instead.
+
| None documented
 
|-
 
|-
 
|}
 
|}
Line 955: Line 1,104:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 USBMouseDeviceControl(Mouse:PMouseDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseDeviceCheck(Mouse:PMouseDevice):PMouseDevice;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of MouseDeviceControl API for USB Mouse</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied Mouse is in the mouse table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
 
! Note
 
! Note
| Not intended to be called directly by applications, use MouseDeviceControl instead.
+
| None documented
 
|-
 
|-
 
|}
 
|}
Line 967: Line 1,116:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 USBMouseDriverBind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseDeviceTypeToString(MouseType:LongWord):String;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Bind the Mouse driver to a USB device if it is suitable</div>
+
<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;"
+
|-
+
! Device
+
| The USB device to attempt to bind to
+
|-
+
! Interrface
+
| The USB interface to attempt to bind to (or nil for whole device)
+
|-
+
! Return
+
| USB_STATUS_SUCCESS if completed, USB_STATUS_DEVICE_UNSUPPORTED if unsupported 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 USBMouseDriverUnbind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;</pre>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Unbind the Mouse driver from a USB device</div>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
|-
+
! Device
+
| The USB device to unbind from
+
|-
+
! Interrface
+
| The USB interface to unbind from (or nil for whole device)
+
|-
+
! Return
+
| USB_STATUS_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;">procedure USBMouseReportWorker(Request:PUSBRequest);</pre>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Called (by a Worker thread) to process a completed USB request from a USB mouse IN interrupt endpoint</div>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
|-
+
! Request
+
| The USB request which has completed
+
|-
+
|}
+
</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 USBMouseReportComplete(Request:PUSBRequest);</pre>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Called when a USB request from a USB mouse IN interrupt endpoint completes</div>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
|-
+
! Request
+
| The USB request which has completed
+
|-
+
! Note
+
| Request is passed to worker thread for processing to prevent blocking the USB completion
+
|-
+
|}
+
</div></div>
+
<br />
+
 
+
'''Mouse 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 MouseGetCount:LongWord; inline;</pre>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current mouse count</div>
+
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 1,045: Line 1,128:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 MouseDeviceCheck(Mouse:PMouseDevice):PMouseDevice;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseDeviceStateToString(MouseState:LongWord):String;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Check if the supplied Mouse is in the mouse table</div>
+
<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;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 1,057: Line 1,140:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 MouseDeviceTypeToString(MouseType:LongWord):String;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseDeviceRotationToString(Rotation:LongWord):String;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return a string describing the supplied mouse rotation value</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 1,069: Line 1,152:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 MouseDeviceStateToString(MouseState:LongWord):String;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseDeviceStateToNotification(State:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a Mouse state value into the notification code for device notifications</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 1,081: Line 1,164:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<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 MouseDeviceStateToNotification(State:LongWord):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function MouseDeviceResolveRotation(ARotation:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a Mouse state value into the notification code for device notifications</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Resolve a value of 0, 90, 180 or 270 to a mouse rotation constant (eg MOUSE_ROTATION_180)</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
 
! Note
 
! Note
| None documented
+
| Also accepts passing the mouse rotation constant values directly
 
|-
 
|-
 
|}
 
|}
Line 1,172: Line 1,255:
 
! Note
 
! Note
 
| None documented
 
| None documented
|-
 
|}
 
</div></div>
 
<br />
 
 
'''USB mouse 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 USBMouseDeviceSetProtocol(Mouse:PUSBMouseDevice; Protocol:Byte):LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the report protocol for a USB mouse device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
! Mouse
 
| The USB mouse device to set the report protocol for
 
|-
 
! Protocol
 
| The report protocol to set (eg USB_HID_PROTOCOL_BOOT)
 
|-
 
! Return
 
| USB_STATUS_SUCCESS if completed or another USB error code on failure
 
 
|-
 
|-
 
|}
 
|}

Latest revision as of 03:41, 15 December 2022

Return to Unit Reference


Description


Ultibo Mouse Interface unit

Mouse Devices

This unit provides the Mouse device interface and mouse API to be used by both drivers and applications.

The API includes functions to create, register, locate, read, write, control and configure each connected mouse device.

The API supports a global mouse buffer so multiple devices can feed data into a common buffer as well as a buffer per device to allow each device to be used for a specific purpose. For example an application with two separate displays may choose to have a mouse or pointing device to control each one individually.

Constants



[Expand]
Mouse specific constants MOUSE_*


[Expand]
Mouse device type MOUSE_TYPE_*


[Expand]
Mouse device state MOUSE_STATE_*


[Expand]
Mouse device flag MOUSE_FLAG_*


[Expand]
Mouse device control code MOUSE_CONTROL_*


[Expand]
Mouse buffer size MOUSE_BUFFER_*


[Expand]
Mouse sampling rate MOUSE_SAMPLE_*


[Expand]
Mouse data definition MOUSE_LEFT_*, MOUSE_RIGHT_*


[Expand]
Mouse rotation MOUSE_ROTATION_*


[Expand]
Mouse logging MOUSE_LOG_*


[Expand]
USB mouse specific constants USBMOUSE_*


[Expand]
USB HID types USB_HID_*


Type definitions



Mouse data

[Expand]

PMouseData = ^TMouseData;

TMouseData = record

Mouse buffer

[Expand]

PMouseBuffer = ^TMouseBuffer;

TMouseBuffer = record

Mouse properties

[Expand]

PMouseProperties = ^TMouseProperties;

TMouseProperties = record

Mouse enumeration callback

TMouseEnumerate = function(Mouse:PMouseDevice; Data:Pointer):LongWord;

Mouse notification callback

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

Mouse device read

TMouseDeviceRead = function(Mouse:PMouseDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;

Mouse device update

TMouseDeviceUpdate = function(Mouse:PMouseDevice):LongWord; stdcall;

Mouse device control

TMouseDeviceControl = function(Mouse:PMouseDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;

Mouse device get properties

TMouseDeviceGetProperties = function(Mouse:PMouseDevice; Properties:PMouseProperties):LongWord; stdcall;

Mouse device types

[Expand]

PMouseDevice = ^TMouseDevice;

TMouseDevice = record

USB HID descriptor

[Expand]

PUSBHIDDescriptor = ^TUSBHIDDescriptor;

TUSBHIDDescriptor = packed record


Public variables



Mouse logging

MOUSE_DEFAULT_LOG_LEVEL:LongWord = MOUSE_LOG_LEVEL_DEBUG; Minimum level for Mouse messages. Only messages with level greater than or equal to this will be printed.
MOUSE_LOG_ENABLED:Boolean;


Function declarations



Initialization functions

[Expand]
procedure MouseInit;
Description: Initialize the mouse unit and device table


Mouse functions

[Expand]
function MousePeek:LongWord;
Description: Peek at the global mouse buffer to see if any data packets are ready


[Expand]
function MouseRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord; inline;
Description: Read mouse data packets from the global mouse buffer


[Expand]
function MouseReadEx(Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Read mouse data packets from the global mouse buffer


[Expand]
function MouseWrite(Buffer:Pointer; Size,Count:LongWord):LongWord;
Description: Write mouse data packets to the global mouse buffer


[Expand]
function MouseFlush:LongWord;
Description: Flush the contents of the global mouse buffer


[Expand]
function MouseDeviceRead(Mouse:PMouseDevice; Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Read mouse data packets from the buffer of the specified mouse


[Expand]
function MouseDeviceUpdate(Mouse:PMouseDevice):LongWord;
Description: Request the specified mouse device to update the current configuration


[Expand]
function MouseDeviceControl(Mouse:PMouseDevice; Request:Integer; Argument1:PtrUInt; var Argument2:PtrUInt):LongWord;
Description: Perform a control request on the specified mouse device


[Expand]
function MouseDeviceGetProperties(Mouse:PMouseDevice; Properties:PMouseProperties):LongWord;
Description: Get the properties for the specified mouse device


[Expand]
function MouseDeviceSetState(Mouse:PMouseDevice; State:LongWord):LongWord;
Description: Set the state of the specified mouse and send a notification


[Expand]
function MouseDeviceCreate:PMouseDevice;
Description: Create a new Mouse device entry


[Expand]
function MouseDeviceCreateEx(Size:LongWord):PMouseDevice;
Description: Create a new Mouse device entry


[Expand]
function MouseDeviceDestroy(Mouse:PMouseDevice):LongWord;
Description: Destroy an existing Mouse device entry


[Expand]
function MouseDeviceRegister(Mouse:PMouseDevice):LongWord;
Description: Register a new Mouse device in the Mouse table


[Expand]
function MouseDeviceDeregister(Mouse:PMouseDevice):LongWord;
Description: Deregister a Mouse device from the Mouse table


[Expand]
function MouseDeviceFind(MouseId:LongWord):PMouseDevice;
Description: Find a mouse device by ID in the mouse table


[Expand]
function MouseDeviceFindByName(const Name:String):PMouseDevice; inline;
Description: Find a mouse device by name in the mouse table


[Expand]
function MouseDeviceFindByDescription(const Description:String):PMouseDevice; inline;
Description: Find a mouse device by description in the mouse table


[Expand]
function MouseDeviceEnumerate(Callback:TMouseEnumerate; Data:Pointer):LongWord;
Description: Enumerate all mouse devices in the mouse table


[Expand]
function MouseDeviceNotification(Mouse:PMouseDevice; Callback:TMouseNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for mouse device changes


RTL console functions

[Expand]
function SysConsoleHideMouse(AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleHideMouse function


[Expand]
function SysConsoleShowMouse(X,Y:LongWord; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleShowMouse function


[Expand]
function SysConsoleReadMouse(var X,Y,Buttons:LongWord; AUserData:Pointer):Boolean;
Description: Handler for Platform ConsoleReadMouse function


Mouse helper functions

[Expand]
function MouseGetCount:LongWord;
Description: Get the current mouse count


[Expand]
function MouseDeviceCheck(Mouse:PMouseDevice):PMouseDevice;
Description: Check if the supplied Mouse is in the mouse table


[Expand]
function MouseDeviceTypeToString(MouseType:LongWord):String;
Description: To be documented


[Expand]
function MouseDeviceStateToString(MouseState:LongWord):String;
Description: To be documented


[Expand]
function MouseDeviceRotationToString(Rotation:LongWord):String;
Description: Return a string describing the supplied mouse rotation value


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


[Expand]
function MouseDeviceResolveRotation(ARotation:LongWord):LongWord;
Description: Resolve a value of 0, 90, 180 or 270 to a mouse rotation constant (eg MOUSE_ROTATION_180)


[Expand]
function MouseInsertData(Mouse:PMouseDevice; Data:PMouseData; Signal:Boolean):LongWord;
Description: Insert a TMouseData entry into the mouse buffer (Direct or Global)


[Expand]
procedure MouseLog(Level:LongWord; Mouse:PMouseDevice; const AText:String);
Description: To be documented


[Expand]
procedure MouseLogInfo(Mouse:PMouseDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure MouseLogWarn(Mouse:PMouseDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure MouseLogError(Mouse:PMouseDevice; const AText:String); inline;
Description: To be documented


[Expand]
procedure MouseLogDebug(Mouse:PMouseDevice;const AText:String); inline;
Description: To be documented


Return to Unit Reference