ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XInput/DirectInput and Xbox Controllers

Solved!
Go to solution

For my final year project I'm using LabVIEW to create simple tactile feedback in an Xbox 360 controller.

 

Attached is some C++ example code using XInput that converts the trigger values (0 - 255) to vibration motor speed (0 - 65535);

The code defines a structure:

 

struct CONTROLER_STATE
{
XINPUT_STATE lastState;
XINPUT_STATE state;
DWORD dwResult;
bool bLockVibration;
XINPUT_VIBRATION vibration;
};

CONTROLER_STATE g_Controllers[MAX_CONTROLLERS];

 

it then sets values for vibration.wLeftMotorSpeed and vibration.wRightMotorSpeed, and passes the values to XInputSetState:

 

XInputSetState( i, &g_Controllers[i].vibration );

 

Using the "Call Library Function" node, and selecting XInput1_3.dll, I have access to XInputSetState and other functions.

'i' is the index of the controller (0 -3), but although the motor speeds are UInt_16, they are buried within the struct, and I'm not sure which type I should use, or how I should assemble the data in the block diagram.

Does anyone have any suggestions?

 

Thanks in advance,

Greg.

0 Kudos
Message 1 of 7
(7,380 Views)

Dear Greg,

 

You can change the representation of a numeric control by right clicking on it and selecting Representation -> U16.  This should ensure that the data type you pass into the Call Library Function node is the same as that assigned in the .DLL

 

I hope this helps, and if you upload the .dll or the .vi you are working on then I can provide further assistance.

 

Kind Regards,

Robert Ward
Applications Engineer, NI
0 Kudos
Message 2 of 7
(7,360 Views)

Attached are the dll and the test vi

 

I would like to point out that I do have experience with LabVIEW (I have used it for my second and third year projects), and I do have a bit of experience with C/C++, but I have no experience of interfacing the two.

So, although I am able to create the values needed, and I understand (somewhat) how the C++ code works, I'm not sure if wiring them into the node in the way I have is suitable.

Download All
0 Kudos
Message 3 of 7
(7,354 Views)
Solution
Accepted by Lucid_Insanity

Dear Greg,


Thank you for the clarification; I assumed that with 5 posts that you were a beginner.

 

It is possible to pass struct data type as defined in a .DLL as clusters in LabVIEW.  I was able to find this community example ( https://decibel.ni.com/content/docs/DOC-9079 ), and you can examine some of the attachments in LabVIEWWrapper as a basis.


Kind Regards,

Robert Ward
Applications Engineer, NI
0 Kudos
Message 4 of 7
(7,343 Views)

Dear Greg,

 

Did you find that community example useful or do you still require assitance with this issue?  I believe it is a relatively straight forward issue by converting structs into clusters and vice versa (see https://decibel.ni.com/content/docs/DOC-9076 ) but; still one needs to be careful and treat it accordingly.

 

Regards,

Robert Ward
Applications Engineer, NI
0 Kudos
Message 5 of 7
(7,312 Views)

I have managed to use the impolrt wizard to create vi's for some of the functions, but it didn't work for others.

However, untill the controller I ordered turns up, I won't be able to test the vi's. In the mean time, I'll keep trying to figure out the other functions, and why the wizard didn't work with them.

0 Kudos
Message 6 of 7
(7,302 Views)

Thanks Rob,

 

I Just received my controller, and the vi's generated by the import wizard work perfectly.

0 Kudos
Message 7 of 7
(7,279 Views)