Hi,
I just wondered if anyone has had similar issues or if it’s a problem with my code?
When I have the SD card module included (as in the following code), the SDcard.mounted event will fire, but the mouse will only fire if I disconnect and reconnect the mouse.
When I don’t have the SD card module and the SD card event the mouse.connected event fires fine without re-inserting the mouse.
I’ve had a similar issue before so just wanted to clear this up. Also would there be a way to manually fire this event?
Thanks in advance for any help with this.
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 Gadgeteer.Modules.Seeed;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.USBClient;
using GHIElectronics.NETMF.System;
namespace ScreenMovement
{
public partial class Program
{
USBH_Mouse mouse;
// float Scale = 0; // 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");
oledDisplay.SimpleGraphics.DisplayRectangle(GT.Color.Red, 0, GT.Color.Red, 0, 0, (uint)screenWidth, (uint)screenHeight);
sd = SDCard;
string fileName = "picture_1.jpg"; // file name
picture = sd.LoadBitmap(fileName, Bitmap.BitmapImageType.Jpeg);
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.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() // bring image up 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)
{
// mouse.Scale(Scale);
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);
}
int 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();
return (0);
}
}
}