annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

XInput/DirectInput and Xbox Controllers

Risolto!
Vai alla soluzione

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
Messaggio 1 di 7
6.652Visualizzazioni

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
Messaggio 2 di 7
6.632Visualizzazioni

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.

Scarica tutti
0 Kudos
Messaggio 3 di 7
6.626Visualizzazioni
Soluzione
Accettato da 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
Messaggio 4 di 7
6.615Visualizzazioni

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
Messaggio 5 di 7
6.584Visualizzazioni

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
Messaggio 6 di 7
6.574Visualizzazioni

Thanks Rob,

 

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

0 Kudos
Messaggio 7 di 7
6.551Visualizzazioni