Ejemplo n.º 1
0
 private void DeviceFound(object sender, DeviceInfoEventArgs args)
 {
     Gtk.TreeIter iter = default(Gtk.TreeIter);
     Gtk.Application.Invoke(delegate {
         LogLine("Found a device, trying to connect...");
         string details = "unavailable";
         if (args.DeviceInfo is IBluetoothDeviceInfo)
         {
             details = ((IBluetoothDeviceInfo)(args.DeviceInfo)).Address.ToString();
         }
         iter = _ListStore.AppendValues("Device", details);
     });
     try
     {
         IDevice device = _Provider.Connect(args.DeviceInfo);
         Gtk.Application.Invoke(delegate { LogLine("Successfully connected to the device!");
                                           AddDevice(device, iter); });
     }
     catch (DeviceConnectException e)
     {
         Gtk.Application.Invoke(delegate {
             LogLine(e.Message);
             _ListStore.Remove(ref iter);
         });
     }
 }
Ejemplo n.º 2
0
        static void deviceProvider_DeviceFound(object sender, DeviceInfoEventArgs e)
        {
            IDeviceProvider deviceProvider = (IDeviceProvider)sender;

            Console.WriteLine("A device has been found.");
            IDeviceInfo foundDeviceInfo = e.DeviceInfo;

            IDevice device = deviceProvider.Connect(foundDeviceInfo);

            Console.WriteLine("Connected to the device.");

            device.Disconnected += device_Disconnected;

            if (device is IWiimote)
            {
                IWiimote wiimote = (IWiimote)device;
                Console.WriteLine("We have connected to a Wiimote device.");
                // Here we have access to all the operations that we can perform on a Wiimote.

                OnWiimoteConnected(wiimote);
            }

            // If we don't want to be connected to the device, we can disconnect like this:
            device.Disconnect();
        }
Ejemplo n.º 3
0
        static void deviceProvider_DeviceFound(object sender, DeviceInfoEventArgs e)
        {
            IDeviceProvider deviceProvider = (IDeviceProvider)sender;

            Console.WriteLine("A device has been found.");
            IDeviceInfo foundDeviceInfo = e.DeviceInfo;

            // Example 2. Connecting to a discovered device.
            // When you connect to a discovered device, it will result in a IDevice.
            // IDevice represents the device when connected.
            Console.WriteLine("Connecting to the device...");
            IDevice device = deviceProvider.Connect(foundDeviceInfo);

            Console.WriteLine("Connected to the device.");

            // You have connected to the device,
            // and can now use 'device' to interact with the connected device.
            // Note that 'device.DeviceInfo' is refering to 'foundDeviceInfo', which we used to connect to the device.
            // We can use the Disconnected event to stay informed if we can still use the device.
            device.Disconnected += device_Disconnected;

            // When the 'device' is an 'IDevice' you can only access properties that are common to
            // all Devices (Wiimote, BalanceBoard, etc...).
            // These devices have their own types in WiiDeviceLibrary: IWiimote and IBalanceBoard. Both of these types inherit from IDevice.
            // To use properties specific to the devices you will have to cast the 'device' to the proper interface.

            // First we check if the device is the desired type.
            if (device is IWiimote)
            {
                IWiimote wiimote = (IWiimote)device;
                Console.WriteLine("We have connected to a Wiimote device.");
                // Here we have access to all the operations that we can perform on a Wiimote.
                // That's it for connecting to Wii devices.
            }
            else if (device is IBalanceBoard)
            {
                IBalanceBoard balanceboard = (IBalanceBoard)device;
                Console.WriteLine("We have connected to a BalanceBoard device.");
                // Here we have access to all the operations that we can perform on a BalanceBoard.
            }

            // If we don't want to be connected to the device, we can disconnect like this:
            device.Disconnect();
        }
Ejemplo n.º 4
0
        void DeviceFound(object sender, DeviceInfoEventArgs args)
        {
            IDevice device = deviceProvider.Connect(args.DeviceInfo);

            Console.WriteLine("Found device: " + device.ToString());

            board = (IBalanceBoard)device;

            connected(sender, args);

            Console.WriteLine("Waiting 2 seconds for tare...");
            Thread.Sleep(2000);
            Console.WriteLine("Tare done.");

            tare[0] = board.TopLeftWeight;
            tare[1] = board.BottomLeftWeight;

            tare[2] = board.TopRightWeight;
            tare[3] = board.BottomRightWeight;

            board.Updated += Updated;
        }
Ejemplo n.º 5
0
        public IDevice Connect(UIDevice uiDevice)
        {
            IDevice device = _Provider.Connect(uiDevice.DeviceInfo);

            device.Disconnected += new EventHandler(device_Disconnected);
            if (device is IWiimote)
            {
                ((IWiimote)device).Leds       = WiimoteLeds.Led1;
                ((IWiimote)device).IsRumbling = true;
                System.Threading.Thread.Sleep(500);
                ((IWiimote)device).IsRumbling = false;
            }
            uiDevice.Device      = device;
            deviceLookup[device] = uiDevice;
            if (device is IWiimote)
            {
                Invoke(new Action <IWiimote>(delegate(IWiimote wiimote)
                {
                    WiimoteUserControl ucontrol = new WiimoteUserControl();
                    ucontrol.Wiimote            = wiimote;
                    uiDevice.Control            = ucontrol;
                    wiidevicePanel.Controls.Add(ucontrol);
                }), device);
            }
            else if (device is IBalanceBoard)
            {
                Invoke(new Action <IBalanceBoard>(delegate(IBalanceBoard balanceBoard)
                {
                    BalanceBoardUserControl ucontrol = new BalanceBoardUserControl();
                    ucontrol.BalanceBoard            = balanceBoard;
                    uiDevice.Control = ucontrol;
                    wiidevicePanel.Controls.Add(ucontrol);
                }), device);
            }

            return(device);
        }