I had an extra look at the examples and this is what I came up with:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.USBHost;
using PS3ControllerUSB;
namespace PS3_Controller
{
public class Program
{
static PS3Controller PS3;
public static void Main()
{
Debug.Print("Initialize...");
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
Thread.Sleep(Timeout.Infinite);
}
static void DeviceConnectedEvent(USBH_Device device)
{
Debug.Print("Joystick Connected");
PS3 = new PS3Controller(device);
// Read the analog hat switch
Debug.Print("LH " + PS3.GetAnalogHat(PS3Controller.AnalogHat.LeftHatX) + " " + PS3.GetAnalogHat(PS3Controller.AnalogHat.LeftHatY));
// Read digital switch
if (PS3.GetButton(PS3Controller.Button.CROSS))
Debug.Print("CROSS");
}
}
}
But it stills gives me an error in the source code. If your look in line 43:
USB_Descriptors.ConfigurationDescriptor cd = raw.GetConfigurationDescriptors(0);
It says “The type or namespace name ‘USB_Descriptors’ could not be found (are you missing a using directive or an assembly reference?” I have tried including “Microsoft.SPOT.Hardware.UsbClient;”, but it is still not working. Alternative I changed it to:
USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);
But then it gives me the following error when I try to compile:
“An unhandled exception of type ‘System.InvalidOperationException’ occurred in GHIElectronics.NETMF.USBHost.dll” in this regard to this line:
Your issue is that you haven’t identified the namespace correctly. Until you do that, your code is not expected to work.
Changing something that is documented (and therefore expected to work) is the wrong approach. Sort out a working example with a keyboard or mouse and you’ll see what references you need to add and what USING statements you need. Then go back and try these more advanced devices.
Learning the simple stuff before you try to jump in the deep end is important.
using System;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Runtime.CompilerServices;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Messaging;
using Microsoft.SPOT.Hardware.UsbClient;
using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.USBClient;
But it still gives he same error:
“The type or namespace name ‘USB_Descriptors’ could not be found (are you missing a using directive or an assembly reference?”
The reason why I tried changing it, was because ConfigurationDescriptor is not a valid command.
You should go back and use the tutorials; as Mike points out (and as I kind of mentioned) you need to not only add a USING statement but add the REFERENCE.
[quote]The reason why I tried changing it, was because ConfigurationDescriptor is not a valid command.
[/quote]
It is valid, it’s just unknown in your project. Adding the reference and then adding an appropriate USING will enable VS to resolve what you are talking about. That’s my point, someone else has this working therefore it must be working, and you have something else wrong…
If you look under USB Host you will see USBH_Descriptors but the code uses USB_Descriptors and then the class doesn’t have “Configuration Descriptor” but it has “Configuration”.
Basically
USB_Descriptors.ConfigurationDescriptor cd = raw.GetConfigurationDescriptors(0);
becomes
USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);
Have fun!
Now, can you please try it then update the wiki with details and updated code?
Yeah thats exactly what I did (see reply 20). I will play around with it, and then I will update the wiki. I am thinking of enabling the rumble function as well, but that might take a bit of work
I have now updated the wiki: [url]http://wiki.tinyclr.com/index.php?title=PS3_Controller[/url] . I updated the code to work with NETMF 4.1 and also enabled Rumble and fixed some other minor bugs.
I will keep updating it and maybe write some further details about the protocol used by the PS3 Controller I will upload a videoclip in the following week.
I have updated the library, so it now enables anglemeasurement using the accelerometers and status. Bluetooth is still to come - I am still waiting for my Bluetooth dongle to arrive - but I have implemented set and get Bluetooth address, which is needed for bluetooth connection.
See the wiki for more details.
I worked with the PS3 controller over bluetooth in the past; issue is if you actually have a PS3 it will beat out the cobra on response time and the controller will end up talking to the PS3 instead of the Cobra.