Adding new hardware/device support with a Provider

Adding additional providers to TouchToolkit allows for applications to work on additional platforms. The following steps (generically) outline how to add a provider for numerous touch-enabled platforms:

Step 1:

In Visual Studio, create a new C# file, and enter platformnameProvider.cs

ap1.png

This file should be added to the TouchInputProviders folder in the TouchToolkit.Framework project, assuming you have the TouchToolkit.Framework project added and linked for your specific application.

ap2.png

When this is done, the provider is now ready to be written.

Step 2:

It is important to understand the events that are supplied with the SDK of the platform you wish to support (and write the provider for). The key events to understand are typically related to "Touch down", "Touch up" and "Touch move". For the purposes of this example, I will demonstrate writing the provider for the Microsoft Surface, which uses the events "ContactDown", "ContactLeave" and "ContactChanged".

Step 3:

The 1st step in coding your provider is to import all the necessary references, which will include the following:

ap3.png

This will allow you to use the necessary components of the linked TouchToolkit.Framework and TouchToolkit.GestureProcessor.

Step 4:

The next step, invovles adding the following lines of code:

ap4.png

These 3 lines bind the provider to the touchtoolkit and also bind the events for the platform (in this case the Microsoft Surface) to the provider.

Step 5:

Typically when gathering information regarding touch points in an application, the data is usually binded to a window, as events occur on a window. Consequently, it is important to create a private window variable (in your provider code) and also to pass the window (of your created application) to the provider's constructor.

The following 2 examples illustrate this:

(Microsoft Surface)

ap5.png

(SMART Table)

ap6.png

In your application, this window is usually bound to the GestureFramework with the provider you create, which will be shown later.

Step 6:

Next, it is important to setup some manner of storing active touch points and touch information, that is required for the Framework to manage multi-touch information.

Typically, the best manner is to use the dictionary implementation as shown below.

ap7.png

Step 7:

The next step, involves the linking of the events in the SDK to methods. These events are first linked to the private window provider.

ap8.png

With the linkage, the following methods link the touch functionality of the SDK to the methods contained with TouchToolKit.Framework.

ap9.png

All the information regarding touch points is passed into a function with its apppropriate TouchAction2 type.

Step 8:

The UpdateActiveTouchPoints method, allows for the continous stream of touch points provided by the hardware, to be updated in TouchToolKit.

Lines 107 - 119, illustrate capturing the position of the touch point, and creating a new touchinfo object containing the action, position and device id of the contact.
Lines 121 - 133, illustrate the addition or update of touchpoints. If a down contact is recieved, it means that a new touchpoint needs to be added whereas everything else (typically move, etc) should be updated.
Lines 136-145, highlight updating the local cache of active touchpoints and information.

ap10.png

Step 9:

The final and most important step, is to handle the framechanged event for the SDK of your choice. Occasionally, this event may not be offered, in which case, a possible solution is to set a timer for ~ 30 msecs and capture all touches in that time frame to determine which event to raise in the SDK.

For this particular Microsoft Surface example, the SDK provides the necessary information to forgo the timer implementation.

Lines 53-54, turn the cached active touch information and points into a list, which is necessary to call the SingleTouched, MultiTouched and FrameChanged methods within TouchToolKit.Framework.

Lines 57 - 76, illustrate how to raise the appropriate events for TouchToolKit.

Lines 79 - 85, update any cached touch information and points and remove any points that are of type Up, as there is no longer a touch to be associated with the information and point.

ap11.png

With these basic steps and Microsoft Surface, a groundwork is set to for you to create your own provider. Have fun!

Last edited Jun 24, 2010 at 6:54 PM by teddyseyed, version 3

Comments

No comments yet.