BSOD from the device…
Now if I knew what a BSOD was … :>)
By device do you mean the Spider or one of the attached modules? I should have mentioned that the app build is using your .Net Micro 4.2. Reciently I have ‘repaired’ all of the software (Including Visual Stduio Express) and reflashed 4.2 for the Spider.
I can post the code but not sure it would help, Kinda large and not finished. It is actually a modification of some PS3 code for a XBox controller (found in Codeshare).
I wanted to use a SONY XBox controller and it is different for some aspects of the PS3 code. Also, I only wanted to use part of the code for the PS3. Not sure how much code the ‘powers to be’ want placed into this form?. I’ll place it here and if it is an issue please just delete this post.
I have the following modules attached: USB Client DP, USBHost, Button and the T35. Also using the DLL for Glide 4.2. The code I was using for Glide has been removed because it was not in my code when I received the error.
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 GHI.Premium.USBHost;
using GHI.Premium.System;
using GHI.Premium.Hardware;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GTI = Gadgeteer.Interfaces;
//uses .Net Micro 4.2
namespace SonyControllerApp
{
public partial class Program
{
const int vendorId = 0x054c; //1356
const int productId = 0x0268; //616
static bool ifDebug = true;
static bool IsConnected;
static Sony360JoyController controller;
static Thread SonyThread;
static USBH_RawDevice SonyJoystick;
static USBH_RawDevice.Pipe SonyInputPipe;
static USBH_RawDevice.Pipe SonyOutputPipe;
static byte[] SonyJoystickData = null;
GT.Timer CheckTimer = new GT.Timer(200);
//For Test interrupt Button
//private GTI.InterruptInput interruptInput;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
// create the controller connector
controller = new Sony360JoyController();
// watch for the controller being connected
controller.ControllerConnected += ControllerConnected;
button.ButtonPressed +=new Button.ButtonEventHandler(button_ButtonPressed);
button.ButtonReleased +=new Button.ButtonEventHandler(button_ButtonReleased);
// Subscribe to USBH event.
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
// Unsubscribe to USBH event.
USBHostController.DeviceDisconnectedEvent += DeviceDisconnectedEvent;
/* Test interrupt Button used but not connected in Program.gadgeteer designer
GT.Socket socket = GT.Socket.GetSocket(11, true, null, null);
interruptInput = new GTI.InterruptInput(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On,
GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingEdge, null);
interruptInput.Interrupt += new GTI.InterruptInput.InterruptEventHandler(EventInterrupt);
*/
CheckTimer.Tick += new GT.Timer.TickEventHandler(CheckTimer_Tick);
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started. *** Ignore the message below: 'UsbHost ERROR : USB device not supported.'");
}
//
void EventInterrupt(GT.Interfaces.InterruptInput sender, bool value)
{
Debug.Print("interupt detected from " + sender);
}
//
static bool allow = false;
void CheckTimer_Tick(GT.Timer timer)
{
if (IsConnected && allow)
{
button.TurnLEDOn();
}
}
//
void ControllerConnected(object sender)
{
button.TurnLEDOff();
CheckTimer.Start();
}
//
void DeviceDisconnectedEvent(USBH_Device device)
{
// Sony USBH_DeviceType.Joystick device.TYPE Joystick = 5,
if (IsConnected && device.TYPE == USBH_DeviceType.Joystick && device.VENDOR_ID == vendorId && productId == productId)
{
IsConnected = false;
SonyThread.Join();
SonyInputPipe = null;
SonyJoystickData = null;
}
}
//
#region button events
private void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
sender.TurnLEDOn();
allow = !allow;
}
//
private void button_ButtonReleased(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
sender.TurnLEDOff();
}
#endregion button events
private void DeviceConnectedEvent(USBH_Device device)
{
if (SonyJoystickData != null)
{
//we already have our controller connected so we will ignore any new events
return;
}
if (device.TYPE == USBH_DeviceType.Joystick && device.VENDOR_ID == vendorId && device.PRODUCT_ID == productId)
{
if (ifDebug) { Debug.Print("A Sony XBox Controller Found"); }
if (ifDebug) { Debug.Print("Press button to start(led ON) / stop(led OFF) reading data"); }
SonyJoystick = new USBH_RawDevice(device);
// Get descriptors
USBH_Descriptors.Configuration cd = SonyJoystick.GetConfigurationDescriptors(0);
// communication endpoint
USBH_Descriptors.Endpoint SonyInputEndPoint = null;
USBH_Descriptors.Endpoint SonyOutputEndPoint = null;
for (int i = 0; i < cd.interfaces.Length; i++)
{
// SONY
if (cd.interfaces[i].bInterfaceSubclass == 0x0 && cd.interfaces[i].bInterfaceProtocol == 0x0)
{
if (cd.interfaces[i].endpoints.Length == 2)
{
int ep = 0;
//request the PS3 controller to send button presses etc back
//Host to device (0x00) | Class (0x20) | Interface (0x01), Set Report (0x09),
// Report Type (Feature 0x03) - Report ID (0xF4), Host to device (0x00) - Endpoint 0 (0x00), data, dataoffset, datalength
// set configuration Sony
SonyJoystick.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);
//XBoxJoystick.SendSetupTransfer(33, 9, 1012, 0, buf, 0, 4);
// XBoxJoystick.SendSetupTransfer(0x21, 0x09, 0x03F4, 0x0000, buf, 0x00, 0x04);
//XBoxJoystick.SendSetupTransfer(0x21, 0x09, 0x03F4, 0x0000, buf, 0x00, 0x04);
//SONY
SonyInputEndPoint = cd.interfaces[i].endpoints[ep]; // get endpoint
SonyInputPipe = SonyJoystick.OpenPipe(SonyInputEndPoint); // open pipe
SonyInputPipe.TransferTimeout = 0; // recommended for interrupt transfers
ep++;
SonyOutputEndPoint = cd.interfaces[i].endpoints[ep];
SonyOutputPipe = SonyJoystick.OpenPipe(SonyOutputEndPoint);
SonyOutputPipe.TransferTimeout = 0;
// we should read as fast as possible
SonyThread = new Thread(ReaderThread) { Priority = ThreadPriority.Highest };
// create the polling thread
SonyThread.Start();
}
}
}
IsConnected = true;
if (IsConnected)
{
ControllerConnected(this);
}
}
}
//
private void ReaderThread()
{
button.TurnLEDOn();
int count;
// Maximum data is wMaxPacketSize
SonyJoystickData = new byte[SonyInputPipe.PipeEndpoint.wMaxPacketSize];
// Read every bInterval
while (true)
{
Thread.Sleep(SonyInputPipe.PipeEndpoint.bInterval);
count = 0;
lock (SonyJoystickData)
{
try
{
count = SonyInputPipe.TransferData(SonyJoystickData, 0, SonyJoystickData.Length);
}
catch
{
USBH_ERROR e = USBHostController.GetLastError();
Debug.Print("ERROR" + e);
Array.Clear(SonyJoystickData, 0, SonyJoystickData.Length);
count = 0;
}
}
//
if (count > 3 && allow)
{
int i = 0;
Debug.Print("In ReaderThread");
/* Not using this except for a test
Debug.Print("=" +
ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " +
ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " +
ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " +
ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++]) + " " + ByteToHex(SonyJoystickData[i++])
);
*/
}
}
}
//
public static string ByteToHex(byte b)
{
const string hex = "0123456789ABCDEF";
int low = b & 0x0f;
int high = b >> 4;
string s = new string(new char[] { hex[high], hex[low] });
return s;
}
//
} //class
} //namespace
//In another file
namespace SonyControllerApp
{
public class Sony360JoyController
{
// Declare the delegate (if using non-generic pattern).
public delegate void SonyConnectedHandler(object sender);
// Declare the event.
public event SonyConnectedHandler ControllerConnected;
}
}