USBHost Module with Mouse

I have a project using a Raptor. I’m working on getting a mouse to work properly for the project. I need a larger screen than a 7" (New Haven).

I added the code below and here’s what happens

When I connect the mouse and start the controller, the mouse isn’t recognized. The MouseConnected event doesn’t fire. If I unplug the mouse and re-plug it in, the event then fires.

The mouse ButtonChanged event fires but neither does the cursor_moved or wheel_moved events.

There isn’t any movement on the screen. When I interrogate the mouse position in ButtonChanged it’s always at 0,0. And how do I get a cursor to appear on the screen?

Any ideas anyone?

Thanks


        void ConfigureMouse()
        {
            Controller.MouseConnected += Controller_MouseConnected;
            Controller.Start();
            bool IsMouseConected = usbHost.IsMouseConnected;
        }

        private static void Controller_MouseConnected(object sender, Mouse mouse)
        {
            mouse.ButtonChanged += mouse_ButtonChanged;
            mouse.CursorMoved += mouse_CursorMoved;
            mouse.WheelMoved += mouse_WheelMoved;
            Debug.Print("Mouse connected.");
        }

        private static void mouse_ButtonChanged(Mouse sender, Mouse.ButtonChangedEventArgs e)
        {
            Debug.Print(e.State.ToString() + " " + e.Which);
        }

        private static void mouse_CursorMoved(Mouse sender, Mouse.CursorMovedEventArgs e)
        {
            Debug.Print(e.Delta.ToString() + " " + e.NewPosition.ToString());
        }

        private static void mouse_WheelMoved(Mouse sender, Mouse.WheelMovedEventArgs e)
        {
            Debug.Print(e.Delta.ToString() + " " + e.NewPosition.ToString());
        }

        void Controller_DeviceConnectFailed()
        {
            Debug.Print("Device disconnected...");
        }

[ol][/ol] [ol][/ol] [ol][/ol]

@ DanCio -

Do you meant the mouse cursor like mouse on PC?
Mouse class doesn’t draw it for you, it just provide position x,y when you moved the mouse. You have to draw it.

For the move event, try this:

static Mouse mymouse;
private static void Controller_MouseConnected(object sender, Mouse mouse)
{
       mymouse = mouse;
       mymouse .ButtonChanged += mouse_ButtonChanged;
        mymouse .CursorMoved += mouse_CursorMoved;
       mymouse .WheelMoved += mouse_WheelMoved;
}

The same behavior, the mouse isn’t initially recognized unless I unplug it and re-plug it in and the only code the events respond to is the button press.

@ DanCio -

We just ran simple code and all event work very well with all mouses we have.
Try a different mouse if trying my code below still doesn’t work
Tested on both socket 6,7 raptor, 4.3.8.0 - SDK 2016 Pre1

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Usb.Host;
using System.Threading;
namespace USBHID
{
    public class Program
    {
        public static void Main()
        {
            Controller.MouseConnected += Controller_MouseConnected;
            Controller.Start();
            Thread.Sleep(Timeout.Infinite);
        }
        static Mouse mymouse;
        static void Controller_MouseConnected(object sender, Mouse mouse)
        {
            Debug.Print("Mouse connected.");
            mymouse = mouse;
            mymouse.ButtonChanged += mymouse_ButtonChanged;
            mymouse.CursorMoved += mymouse_CursorMoved;
            mymouse.WheelMoved += mymouse_WheelMoved;
            mymouse.Disconnected += mouse_Disconnected;
        }

        static void mymouse_WheelMoved(Mouse sender, Mouse.WheelMovedEventArgs e)
        {
            Debug.Print("WheelMoved ->" + e.Delta.ToString() + " " + e.NewPosition.ToString());
        }
        static void mymouse_CursorMoved(Mouse sender, Mouse.CursorMovedEventArgs e)
        {
            Debug.Print("CursorMoved ->" + e.Delta.ToString() + " " + e.NewPosition.ToString());
        }
        static void mymouse_ButtonChanged(Mouse sender, Mouse.ButtonChangedEventArgs e)
        {
            Debug.Print("ButtonChanged ->" + e.State.ToString() + " " + e.Which);
        }
        static void mouse_Disconnected(BaseDevice sender, EventArgs e)
        {
            Debug.Print("Mouse disconnected.");
        }
    }
}

mouses?

1 Like

You have to excuse them thar folks in the US of A, they can’t even spell or pronounce ALUMINIUM for starters. They even had Scotty on the Enterprise using the US version :stuck_out_tongue:

@ Dave McLaughlin - I think he became interested because of the cat in his profile pic.