<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to TDI_HowTo</title><link>https://sourceforge.net/p/tuxdroidapi/wiki/TDI_HowTo/</link><description>Recent changes to TDI_HowTo</description><atom:link href="https://sourceforge.net/p/tuxdroidapi/wiki/TDI_HowTo/feed" rel="self"/><language>en</language><lastBuildDate>Sun, 14 Aug 2011 17:59:06 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/tuxdroidapi/wiki/TDI_HowTo/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage TDI_HowTo modified by Joe</title><link>https://sourceforge.net/p/tuxdroidapi/wiki/TDI_HowTo/</link><description>&lt;pre&gt;--- v1 
+++ v2 
@@ -1,3 +1,7 @@
+# ATTENTION ! THIS PAGE IS NOT COMPLETE !! #
+# DO NOT FOLLOW THE INSTRUCTIONS OF THIS PAGE AT THIS TIME !! #
+
+
 TuxDriverInterface HowTo
 ========================
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joe</dc:creator><pubDate>Sun, 14 Aug 2011 17:59:06 -0000</pubDate><guid>https://sourceforge.neteb2104f5e7d0a4e984f35332c49a0d813092e379</guid></item><item><title>WikiPage TDI_HowTo modified by Joe</title><link>https://sourceforge.net/p/tuxdroidapi/wiki/TDI_HowTo/</link><description>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.
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joe</dc:creator><pubDate>Sun, 14 Aug 2011 17:55:50 -0000</pubDate><guid>https://sourceforge.netc45f26ddcdfbc431cd6649098c713508dd5facc0</guid></item></channel></rss>