I’m using the sd card and usb host. The usb host event won’t fire when the mouse is in the socket when the code starts. I have to remove and re-insert it to use the mouse.
I’ve tried variations in code but it simply won’t fire. It works without the sd card module.
There will be no access to the usb host.
I’d be really thankful for any solutions - right now I’m thinking to add a relay switch to the power of the usb but it’s a last resort.
hey there, it’s probably worth giving a code example of the minimum required to repro this so we know how to test for it. Probably also worth telling us a 4.1 or 4.2 project, and what mainboard you’re using.
This is my code - I’ve tried putting the mouse connected event else were but it makes no difference. I remember having a similar issue before with the camera connected event. Hopefully it’s not silly coding!
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.USBClient;
using GHIElectronics.NETMF.System;
using Gadgeteer.Modules.Seeed;
namespace ScreenMovement
{
public partial class Program
{
USBH_Mouse mouse;
float Scale = 0.5f; // set mouse scale and sensitivity
static int Xmin = 0; // set the boundaries according to the image size
static int Ymin = 0;
int Xmax;
int Ymax;
int x; // mouse x coordinate
int y; // mouse y coordinate
GT.StorageDevice sd;
int screenWidth;
int screenHeight;
Bitmap picture;
void ProgramStarted()
{
Debug.Print("Program Started");
screenWidth = (int)oledDisplay.Width;
screenHeight = (int)oledDisplay.Height;
sdCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
}
void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
{
Debug.Print("Card Mounted");
// red when not loaded
oledDisplay.SimpleGraphics.DisplayRectangle(GT.Color.Red, 0, GT.Color.Red, 0, 0, (uint)screenWidth, (uint)screenHeight);
sd = SDCard;
string fileName = "\\ProtoPictures\\picture.jpg"; // file name
picture = sd.LoadBitmap(fileName, Bitmap.BitmapImageType.Jpeg);
// green when loaded
oledDisplay.SimpleGraphics.DisplayRectangle(GT.Color.Green, 0, GT.Color.Green, 0, 0, (uint)screenWidth, (uint)screenHeight);
Debug.Print("Picture Loaded");
usbHost.MouseConnected += new UsbHost.MouseConnectedEventHandler(usbHost_MouseConnected);
}
void usbHost_MouseConnected(UsbHost sender, USBH_Mouse mouse)
{
Debug.Print("Mouse Connected");
mouse.Scale(Scale);
mouse.SetCursor(picture.Width / 2, picture.Height / 2); // center the mouse to begin with
this.mouse = mouse;
mouse.MouseMove += new USBH_MouseEventHandler(mouse_MouseMove);
showImage();
}
void showImage() // show image to start without the event
{
x = picture.Width / 2;
y = picture.Height / 2;
scrollImage(x, y);
}
void mouse_MouseMove(USBH_Mouse sender, USBH_MouseEventArgs args)
{
Xmax = picture.Width - screenWidth;
Ymax = picture.Height - screenHeight;
mouse.SetCursorBounds(Xmin, Xmax, Ymin, Ymax);
Debug.Print(mouse.Cursor.X.ToString() + " , " + mouse.Cursor.Y.ToString());
x = mouse.Cursor.X;
y = mouse.Cursor.Y;
scrollImage(x, y);
}
void scrollImage(int x, int y)
{
Bitmap croppedImage = new Bitmap(128, 128);
croppedImage.DrawImage(0, 0, picture, x, y, screenWidth, screenHeight);
oledDisplay.SimpleGraphics.DisplayImage(croppedImage, 0, 0);
croppedImage.Clear();
}
}
}