01-06-2013 03:04 PM
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.
Solved! Go to Solution.
01-07-2013 05:04 AM
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,
01-07-2013 06:41 AM
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.
01-07-2013 08:17 AM
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,
01-09-2013 03:55 AM
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,
01-09-2013 10:18 PM
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.
01-12-2013 12:35 PM
Thanks Rob,
I Just received my controller, and the vi's generated by the import wizard work perfectly.