예제 #1
0
 private void Mouse_Disconnected(USBH_Mouse sender, USBH_MouseEventArgs args)
 {
     // Unhook event handlers and null our host mouse device.
     _Mouse.Disconnected -= new USBH_MouseEventHandler(Mouse_Disconnected);
     _Mouse.MouseDown    -= new USBH_MouseEventHandler(Mouse_Activity);
     _Mouse.MouseUp      -= new USBH_MouseEventHandler(Mouse_Activity);
     _Mouse.MouseMove    -= new USBH_MouseEventHandler(Mouse_Activity);
     _Mouse = null;
 }
예제 #2
0
 /// <summary>
 /// Raises the <see cref="MouseDisconnected"/> event.
 /// </summary>
 /// <param name="sender">The <see cref="USBHost"/> object that raised the event.</param>
 /// <param name="mouse">The <see cref="USBH_Mouse"/> object associated with the event.</param>
 protected virtual void OnMouseDisconnectedEvent(USBHost sender, USBH_Mouse mouse)
 {
     if (_OnMouseDisconnected == null)
     {
         _OnMouseDisconnected = new MouseDisconnectedEventHandler(OnMouseDisconnectedEvent);
     }
     if (Program.CheckAndInvoke(MouseDisconnected, _OnMouseDisconnected, sender, mouse))
     {
         MouseDisconnected(sender, mouse);
     }
 }
예제 #3
0
        private void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            try
            {
                switch (device.TYPE)
                {
                case USBH_DeviceType.MassStorage:
                    lock (this.storageDevices)
                    {
                        var ps = new PersistentStorage(device);
                        ps.MountFileSystem();
                        this.storageDevices.Add(device.ID, ps);
                    }

                    break;

                case USBH_DeviceType.Mouse:
                    lock (this.mice)
                    {
                        var mouse = new USBH_Mouse(device);
                        mouse.SetCursorBounds(int.MinValue, int.MaxValue, int.MinValue, int.MaxValue);
                        this.mice.Add(device.ID, mouse);
                        this.OnMouseConnectedEvent(this, mouse);
                    }

                    break;

                case USBH_DeviceType.Keyboard:
                    lock (this.keyboards)
                    {
                        var keyboard = new USBH_Keyboard(device);
                        this.keyboards.Add(device.ID, keyboard);
                        this.OnKeyboardConnectedEvent(this, keyboard);
                    }

                    break;

                case USBH_DeviceType.Webcamera:
                    ErrorPrint("Use GTM.GHIElectronics.Camera for USB WebCamera support.");
                    break;

                default:
                    ErrorPrint("USB device is not supported by the Gadgeteer driver. More devices are supported by the GHI USB Host driver. Remove the USB Host from the designer, and proceed without using Gadgeteer code.");
                    break;
                }
            }
            catch (Exception)
            {
                ErrorPrint("Unable to identify USB Host device.");
            }
        }
예제 #4
0
 static void DeviceDisconnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.Keyboard)
     {
         _keyboard.KeyDown -= _keyboard_KeyDown;
         _keyboard.KeyUp   -= _keyboard_KeyUp;
         _keyboard          = null;
     }
     else if (device.TYPE == USBH_DeviceType.Mouse)
     {
         _mouse.MouseMove   -= _mouse_MouseMove;
         _mouse              = null;
         Core.MouseAvailable = false;
     }
 }
예제 #5
0
        static void _mouse_MouseUp(USBH_Mouse sender, USBH_MouseEventArgs args)
        {
            switch (args.ChangedButton)
            {
            case USBH_MouseButton.Left:
                Core.RaiseButtonEvent((int)ButtonIDs.Click, false);
                break;

            case USBH_MouseButton.Middle:
                Core.RaiseButtonEvent((int)ButtonIDs.ClickMiddle, false);
                break;

            case USBH_MouseButton.Right:
                Core.RaiseButtonEvent((int)ButtonIDs.ClickRight, false);
                break;
            }
        }
예제 #6
0
        private void Mouse_Activity(USBH_Mouse sender, USBH_MouseEventArgs args)
        {
            // Translate from the host button presses (normal enum) to client button presses (flags enum).
            GHIElectronics.NETMF.USBClient.USBC_Mouse.Buttons buttonBit = GHIElectronics.NETMF.USBClient.USBC_Mouse.Buttons.BUTTON_NONE;
            if (args.ChangedButton == USBH_MouseButton.Left)
            {
                buttonBit = GHIElectronics.NETMF.USBClient.USBC_Mouse.Buttons.BUTTON_LEFT;
            }
            else if (args.ChangedButton == USBH_MouseButton.Right)
            {
                buttonBit = GHIElectronics.NETMF.USBClient.USBC_Mouse.Buttons.BUTTON_RIGHT;
            }
            else if (args.ChangedButton == USBH_MouseButton.Middle)
            {
                buttonBit = GHIElectronics.NETMF.USBClient.USBC_Mouse.Buttons.BUTTON_MIDDLE;
            }
            else if (args.ChangedButton == USBH_MouseButton.XButton1)
            {
                buttonBit = GHIElectronics.NETMF.USBClient.USBC_Mouse.Buttons.BUTTON_XBUTTON1;
            }
            else if (args.ChangedButton == USBH_MouseButton.XButton2)
            {
                buttonBit = GHIElectronics.NETMF.USBClient.USBC_Mouse.Buttons.BUTTON_XBUTTON2;
            }
            if (args.ButtonState == USBH_MouseButtonState.Pressed)
            {
                _MouseButtonState = _MouseButtonState | buttonBit;
            }
            else
            {
                _MouseButtonState = _MouseButtonState & ~buttonBit;
            }

            _Output.MouseData(args.DeltaPosition.X, args.DeltaPosition.Y, args.DeltaPosition.ScrollWheelValue, _MouseButtonState);

            // Handle inactivity and minimum time before start state.
            this.SetInactivityTimeout();

            if (_IsInactive)
            {
                // Transition to initial delay state by initialising the minimum variables.
                SetMinimumCounters();
                _IsInactive = false;
            }
        }
예제 #7
0
 static void DeviceConnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.Keyboard)
     {
         _keyboard          = new USBH_Keyboard(device);
         _keyboard.KeyDown += _keyboard_KeyDown;
         _keyboard.KeyUp   += _keyboard_KeyUp;
         Debug.Print("Keyboard attached");
     }
     else if (device.TYPE == USBH_DeviceType.Mouse)
     {
         _mouse = new USBH_Mouse(device);
         _mouse.SetCursorBounds(0, Core.ScreenWidth, 0, Core.ScreenHeight);
         _mouse.SetCursor(0, 0);
         _mouse.Scale(20);
         _mouse.MouseMove   += _mouse_MouseMove;
         _mouse.MouseDown   += _mouse_MouseDown;
         _mouse.MouseUp     += _mouse_MouseUp;
         Core.MouseAvailable = true;
         Debug.Print("Mouse attached");
     }
 }
예제 #8
0
 private void _mouse_MouseWheel(USBH_Mouse sender, USBH_MouseEventArgs args)
 {
     var mwp = args.DeltaPosition.ScrollWheelValue;
     if (mwp > 0) // mwp is the number of pixels moved since last scrollinterrupt
     {
         OnNavigationRequested(NavigationDirection.Backward);
     }
     else
     {
         OnNavigationRequested(NavigationDirection.Forward);
     }
 }
예제 #9
0
 private void _mouse_MouseDown(USBH_Mouse sender, USBH_MouseEventArgs args)
 {
     if (_sdCardDevice != null)
     {
         OnNavigationRequested(args.ChangedButton == USBH_MouseButton.Left ? NavigationDirection.Backward : NavigationDirection.Forward);
     }
 }
예제 #10
0
 private void usbHost_MouseConnected(GTM.GHIElectronics.UsbHost sender, USBH_Mouse mouse)
 {
     _mouse = mouse;
     _mouse.MouseDown += new USBH_MouseEventHandler(_mouse_MouseDown);
     _mouse.MouseWheel += new USBH_MouseEventHandler(_mouse_MouseWheel);
 }