Unit Touch

From Ultibo.org
Revision as of 06:12, 20 April 2018 by Ultibo (Talk | contribs)

Jump to: navigation, search

Return to Unit Reference


Description


Ultibo Touch interface unit

To be documented

Constants



Touch specific constants TOUCH_*
TOUCH_NAME_PREFIX = 'Touch'; Name prefix for Touch Devices


Touch device type TOUCH_TYPE_*
TOUCH_TYPE_NONE = 0;  
TOUCH_TYPE_RESISTIVE = 1;  
TOUCH_TYPE_CAPACITIVE = 2;  


Touch device state TOUCH_STATE_*
TOUCH_STATE_DISABLED = 0;  
TOUCH_STATE_ENABLED = 1;  


Touch device flag TOUCH_FLAG_*
TOUCH_FLAG_NONE = $00000000;  
TOUCH_FLAG_NON_BLOCK = $00000001; If set device reads are non blocking (Also supported in Flags parameter of TouchDeviceRead)
TOUCH_FLAG_PEEK_BUFFER = $00000002; Peek at the buffer to see if any data is available, don't remove it (Used only in Flags parameter of TouchDeviceRead)
TOUCH_FLAG_MOUSE_DATA = $00000004; If set the device will write a mouse data event for each touch event
TOUCH_FLAG_MULTI_POINT = $00000008; If set the device supports multi point touch
TOUCH_FLAG_PRESSURE = $00000010; If set the device supports pressure value on touch points
 
Flags supported by TOUCH_CONTROL_GET/SET/CLEAR_FLAG
TOUCH_FLAG_MASK = TOUCH_FLAG_NON_BLOCK or TOUCH_FLAG_MOUSE_DATA or TOUCH_FLAG_MULTI_POINT or TOUCH_FLAG_PRESSURE;


Touch device control code TOUCH_CONTROL_*
TOUCH_CONTROL_GET_FLAG = 1; Get Flag
TOUCH_CONTROL_SET_FLAG = 2; Set Flag
TOUCH_CONTROL_CLEAR_FLAG = 3; Clear Flag
TOUCH_CONTROL_FLUSH_BUFFER = 4; Flush Buffer


Touch buffer size TOUCH_BUFFER_*
TOUCH_BUFFER_SIZE = 1024;  


Touch data definitions TOUCH_FINGER*, TOUCH_ID_*
Values for TTouchData.Info
TOUCH_FINGER = $00000001; A finger is pressed at this touch point
Values for TTouchData.PointID
TOUCH_ID_UNKNOWN = Word(-1);  
Values for TTouchData.PositionX
TOUCH_X_UNKNOWN = -1;  
Values for TTouchData.PositionY
TOUCH_Y_UNKNOWN = -1;  
Values for TTouchData.PositionZ
TOUCH_Z_UNKNOWN = -1;  


Touch rotation TOUCH_ROTATION_*
TOUCH_ROTATION_0 = FRAMEBUFFER_ROTATION_0; No rotation
TOUCH_ROTATION_90 = FRAMEBUFFER_ROTATION_90; 90 degree rotation
TOUCH_ROTATION_180 = FRAMEBUFFER_ROTATION_180; 180 degree rotation
TOUCH_ROTATION_270 = FRAMEBUFFER_ROTATION_270; 270 degree rotation


Touch logging TOUCH_LOG_*
TOUCH_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG; Touch debugging messages
TOUCH_LOG_LEVEL_INFO = LOG_LEVEL_INFO; Touch informational messages, such as a device being attached or detached
TOUCH_LOG_LEVEL_WARN = LOG_LEVEL_WARN; Touch warning messages
TOUCH_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; Touch error messages
TOUCH_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No Touch messages


Type definitions



Touch data

PTouchData = ^TTouchData;

TTouchData = record

Info:LongWord;  
PointID:Word;  
PositionX:SmallInt;  
PositionY:SmallInt;  
PositionZ:SmallInt;  

Touch buffer

PTouchBuffer = ^TTouchBuffer;

TTouchBuffer = record

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

Touch properties

PTouchProperties = ^TTouchProperties;

TTouchProperties = record

Flags:LongWord; Device flags (eg TOUCH_FLAG_MULTI_POINT)
Width:LongWord; Screen Width
Height:LongWord; Screen Height
Rotation:LongWord; Screen Rotation (eg TOUCH_ROTATION_180)
MaxX:LongWord; Maximum (absolute) X value for the touch device
MaxY:LongWord; Maximum (absolute) Y value for the touch device
MaxZ:LongWord; Maximum (absolute) Z value for the touch device
MaxPoints:LongWord; Maximum number of touch points

Touch enumeration callback

TTouchEnumerate = function(Touch:PTouchDevice; Data:Pointer):LongWord;

Touch notification callback

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

Touch device start

TTouchDeviceStart = function(Touch:PTouchDevice):LongWord;

Touch device stop

TTouchDeviceStop = function(Touch:PTouchDevice):LongWord;

Touch device peek

TTouchDevicePeek = function(Touch:PTouchDevice):LongWord;

Touch device read

TTouchDeviceRead = function(Touch:PTouchDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;

Touch device write

TTouchDeviceWrite = function(Touch:PTouchDevice; Buffer:Pointer; Size,Count:LongWord):LongWord;

Touch device flush

TTouchDeviceFlush = function(Touch:PTouchDevice):LongWord;

Touch device control

TTouchDeviceControl = function(Touch:PTouchDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;

Touch device get properties

TTouchDeviceGetProperties = function(Touch:PTouchDevice; Properties:PTouchProperties):LongWord;

Touch device

PTouchDevice = ^TTouchDevice;

TTouchDevice = record

Device Properties
Device:TDevice; The Device entry for this Touch device
Touch Properties
TouchId:LongWord; Unique Id of this Touch device in the Touch device table
TouchState:LongWord; Touch dveice state (eg TOUCH_STATE_ENABLED)
DeviceStart:TTouchDeviceStart; A Device specific DeviceStart method implementing the standard Touch device interface (Mandatory)
DeviceStop:TTouchDeviceStop; A Device specific DeviceStop method implementing the standard Touch device interface (Mandatory)
DevicePeek:TTouchDevicePeek; A Device specific DevicePeek method implementing a standard Touch device interface (Or nil if the default method is suitable)
DeviceRead:TTouchDeviceRead; A Device specific DeviceRead method implementing a standard Touch device interface (Or nil if the default method is suitable)
DeviceWrite:TTouchDeviceWrite; A Device specific DeviceWrite method implementing a standard Touch device interface (Or nil if the default method is suitable)
DeviceFlush:TTouchDeviceFlush; A Device specific DeviceFlush method implementing a standard Touch device interface (Or nil if the default method is suitable)
DeviceControl:TTouchDeviceControl; A Device specific DeviceControl method implementing a standard Touch device interface (Or nil if the default method is suitable)
DeviceGetProperties:TTouchDeviceGetProperties; A Device specific DeviceGetProperties method implementing a standard Touch device interface (Or nil if the default method is suitable)
Driver Properties
Lock:TMutexHandle; Device lock
Buffer:TTouchBuffer; Touch input buffer
Properties:TTouchProperties; Device properties
Statistics Properties
ReceiveCount:LongWord;  
ReceiveErrors:LongWord;  
BufferOverruns:LongWord;  
Internal Properties
Prev:PTouchDevice; Previous entry in Touch device table
Next:PTouchDevice; Next entry in Touch device table


Public variables



Touch logging

TOUCH_DEFAULT_LOG_LEVEL:LongWord = TOUCH_LOG_LEVEL_DEBUG; Minimum level for Touch messages. Only messages with level greater than or equal to this will be printed.
TOUCH_LOG_ENABLED:Boolean;


Function declarations



Initialization functions

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


Touch functions

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


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


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


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


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


function TouchDeviceFlush(Touch:PTouchDevice):LongWord;
Description: Flush the contents of the buffer of the specified touch device
Touch The Touch device to flush
Return ERROR_SUCCESS if completed or another error code on failure


function TouchDeviceControl(Touch:PTouchDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;
Description: Perform a control request on the specified touch device
Touch The Touch device to control
Request The request code for the operation (eg TOUCH_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 TouchDeviceProperties(Touch:PTouchDevice; Properties:PTouchProperties):LongWord; inline;
Description: Get the properties for the specified Touch device
Touch The Touch device to get properties from
Properties Pointer to a TTouchProperties structure to fill in
Return ERROR_SUCCESS if completed or another error code on failure
Note Replaced by TouchDeviceGetProperties for consistency


function TouchDeviceGetProperties(Touch:PTouchDevice;Properties:PTouchProperties):LongWord;
Description: Get the properties for the specified Touch device
Touch The Touch device to get properties from
Properties Pointer to a TTouchProperties structure to fill in
Return ERROR_SUCCESS if completed or another error code on failure


function TouchDeviceCreate:PTouchDevice;
Description: Create a new Touch device entry
Return Pointer to new Touch device entry or nil if Touch device could not be created


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


function TouchDeviceDestroy(Touch:PTouchDevice):LongWord;
Description: Destroy an existing Touch device entry
Note None documented


function TouchDeviceRegister(Touch:PTouchDevice):LongWord;
Description: Register a new Touch device in the Touch device table
Note None documented


function TouchDeviceDeregister(Touch:PTouchDevice):LongWord;
Description: Deregister an Touch device from the Touch device table
Note None documented


function TouchDeviceFind(TouchId:LongWord):PTouchDevice;
Description: To be documented
Note None documented


function TouchDeviceFindByName(const Name:String):PTouchDevice; inline;
Description: To be documented
Note None documented


function TouchDeviceFindByDescription(const Description:String):PTouchDevice; inline;
Description: To be documented
Note None documented


function TouchDeviceEnumerate(Callback:TTouchEnumerate; Data:Pointer):LongWord;
Description: To be documented
Note None documented


function TouchDeviceNotification(Touch:PTouchDevice; Callback:TTouchNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: To be documented
Note None documented


Touch helper functions

function TouchGetCount:LongWord; inline;
Description: Get the current Touch device count
Note None documented


function TouchDeviceGetDefault:PTouchDevice; inline;
Description: Get the current default Touch device
Note None documented


function TouchDeviceSetDefault(Touch:PTouchDevice):LongWord;
Description: Set the current default Touch device
Note None documented


function TouchDeviceCheck(Touch:PTouchDevice):PTouchDevice;
Description: Check if the supplied Touch device is in the Touch device table
Note None documented


function TouchInsertData(Touch:PTouchDevice; Data:PTouchData; Signal:Boolean):LongWord;
Description: Insert a TTouchData entry into the touch device buffer
Touch The touch device to insert data for
Data The TTouchData 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 touch device lock


procedure TouchLog(Level:LongWord; Touch:PTouchDevice; const AText:String);
Description: To be documented
Note None documented


procedure TouchLogInfo(Touch:PTouchDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure TouchLogWarn(Touch:PTouchDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure TouchLogError(Touch:PTouchDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure TouchLogDebug(Touch:PTouchDevice; const AText:String); inline;
Description: To be documented
Note None documented


Return to Unit Reference