Menu

TDI_HowTo

Joël Matteotti

ATTENTION ! THIS PAGE IS NOT COMPLETE !!

DO NOT FOLLOW THE INSTRUCTIONS OF THIS PAGE AT THIS TIME !!

TuxDriverInterface HowTo

On this page I will explain with examples how to use TuxDriverInterface.

** Step 1: **

First download the most recent version of TuxDriverInterface, you can found it at: https://sourceforge.net/projects/tuxdroidapi/files/TDI/ the filename is like TDI_MM_DD_YYYY.zip example: TDI_08_14_2011.zip

** Step 2: **

In VisualStudio create a new C# project (Console or whatever you whant of project type), and add TuxDriverInterface.cs to your project

** Step 3: ** (initialize driver part #1)

Where you want use TuxDriverInterface don't forget to add:

using TuxDriverInterface;

In your main class declare a new TuxDriverInterface class instance:

private static TuxDriverInterface driver = null;

Now in your main function (it's Main() for console application, Form_Load for Windows Forms), instantiate the driver:

driver = new TuxDriverInterface();

** Step 4: ** (initialize driver part #2)

OK now whe have new instance of our driver, but it's not all, we optionally need to initialize some events, like the push of a button.

driver.OnHeadButtonPressed += new TuxDriverInterface.HeadButtonPressedEventHandler(driver_OnHeadButtonPressed);
driver.OnLeftButtonPressed += new TuxDriverInterface.LeftButtonPressedEventHandler(driver_OnLeftButtonPressed);
driver.OnRightButtonPressed += new TuxDriverInterface.RightButtonPressedEventHandler(driver_OnRightButtonPressed);
driver.OnRemoteButtonPressed += new TuxDriverInterface.RemoteButtonPressedEventHandler(driver_OnRemoteButtonPressed);

With this code i add 4 events, one for each tux's buttons

Optionally i can add 2 events for the dongle:

driver.OnDongleConnected += new TuxDriverInterface.OnDongleConnectedHandler(driver_OnDongleConnected);
driver.OnDongleDisconnected += new TuxDriverInterface.OnDongleDisconnectedHandler(driver_OnDongleDisconnected);

Now I must add the corresponding functions

        //this function is called when someone press the right wing
        private void driver_OnRightButtonPressed()
        {
            Console.WriteLine("RIGHT WING BUTTON PRESSED"); //and we notify that
        }

        //same for the left wing
        private void driver_OnLeftButtonPressed()
        {
             Console.WriteLine("LEFT WING BUTTON PRESSED"); //notification
        }

        //same for the head button
        private void driver_OnHeadButtonPressed()
        {
            Console.WriteLine("HEAD BUTON PRESSED"); //notification
        }

Ok now our code looks like this (or slightly different for a Windows Forms project):

using System;

namespace TDIDemo
{
     using TuxDriverInterface;

     public class Program
     {
         private static TuxDriverInterface driver = null;

         static void Main()
         {
            driver = new TuxDriverInterface();
            driver.OnHeadButtonPressed += new TuxDriverInterface.HeadButtonPressedEventHandler(driver_OnHeadButtonPressed);
            driver.OnLeftButtonPressed += new TuxDriverInterface.LeftButtonPressedEventHandler(driver_OnLeftButtonPressed);
            driver.OnRightButtonPressed += new TuxDriverInterface.RightButtonPressedEventHandler(driver_OnRightButtonPressed);
            driver.OnRemoteButtonPressed += new TuxDriverInterface.RemoteButtonPressedEventHandler(driver_OnRemoteButtonPressed);

            driver.OnDongleConnected += new TuxDriverInterface.OnDongleConnectedHandler(driver_OnDongleConnected);
            driver.OnDongleDisconnected += new TuxDriverInterface.OnDongleDisconnectedHandler(driver_OnDongleDisconnected);

         }

        //this function is called when someone press the right wing
        private void driver_OnRightButtonPressed()
        {
            Console.WriteLine("RIGHT WING BUTTON PRESSED"); //and we notify that
        }

        //same for the left wing
        private void driver_OnLeftButtonPressed()
        {
             Console.WriteLine("LEFT WING BUTTON PRESSED"); //notification
        }

        //same for the head button
        private void driver_OnHeadButtonPressed()
        {
            Console.WriteLine("HEAD BUTON PRESSED"); //notification
        }

     }
}

Now we need to start the driver, todo that after the line adding the OnDongleDisconnect event, simply add:

driver.Start();

And voilà !

We have now a program who handle the button's pressure and notify what button is pressed.


MongoDB Logo MongoDB