Hello everyone!
I am currently working on integrating the SpaceNavigator Joystick into my programm, running on QNX (realtime-OS) on a Beaglebone Black. My current goal is to simply read in the SpaceNavigators sensor values into my C program.
Unfortunately, I am not very experienced with USB driver programming. Is there by chance something like a Programmers' Guide or an example (c-) driver that I can use?
Anything helps!
Thanks,
Thomas
PS: I am especially interested in the structure of the Data, which is sent to the host from the Spacenavigator. How many bytes are sent? How are x/y/z/rx/ry/rz encoded and so on.
SpaceNavigator driver for QNX
Moderator: Moderators
Re: SpaceNavigator driver for QNX
I ultimately managed to get a working piece of code, derived from https://www.ram.ewi.utwente.nl/ECSSoftw ... ource.html. Unfortunately I can only read three values, representing X,Y and Z. Does anyone know what I have to change in my Code to be able to read out the rotations as well?
Here is my adapted code:
When I run this code i get nice values for X,Y and Z, rX, rY and rZ continuously stay on zero.
What am I doing wrong? As usual, any help is appreciated!
Here is my adapted code:
Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <sys/neutrino.h>
#include <sys/hiddi.h>
#include <sys/hidut.h>
#include <unistd.h>
#include <errno.h>
struct hidd_connection *d_connection;
int16_t x, y, z, rx, ry, rz; //SpaceNavigator orientation variables
void dump(struct hidd_connection *connection, struct hidd_report *handle, void *report_data, _Uint32t report_len, _Uint32t flags, void *user)
{
x = ((int16_t*) report_data)[0];
y = ((int16_t*) report_data)[1];
z = ((int16_t*) report_data)[2];
rx = ((int16_t*) report_data)[3];
ry = ((int16_t*) report_data)[4];
rz = ((int16_t*) report_data)[5];
}
//This function is called when the USB device is inserted:
void oninsertion(struct hidd_connection *connection,hidd_device_instance_t *device_instance) {
struct hidd_collection **hidd_collections, **hidd_mcollections;
struct hidd_report_instance *report_instance;
struct hidd_report *report;
_uint16 num_col, num_mcol;
_uint16 usage_page, usage;
_uint16 max_but;
int i;
// Get root level HID collections
hidd_get_collections( device_instance, NULL, &hidd_collections, &num_col);
// for each top level collection
for(i = 0; i < num_col; i++)
{
// Get usage for the collection
hidd_collection_usage( hidd_collections[i], &usage_page, &usage);
// Ignore collection if it doesn't describe joystick functionality
if( usage_page != HIDD_PAGE_DESKTOP || usage != HIDD_USAGE_JOYSTICK)
continue;
// *** The following is a bad hack. Fix it as recursive search for report ****
hidd_get_collections( NULL, hidd_collections[i], &hidd_mcollections, &num_mcol);
if ( num_col && hidd_get_report_instance( hidd_mcollections[0], 0 , HID_INPUT_REPORT,
&report_instance ) == 0 )
{
hidd_num_buttons( report_instance, &max_but );
if( hidd_report_attach( connection, device_instance, report_instance, 0,
(max_but * sizeof(_int32)) , &report ) == 0 )
{
break;
}
}
} // end for
}
int main(int argc, char *argv[]) {
/*... here I usually have some more code, nothing to do with my problem...*/
//set up device identifier (0x256f=3dconnexion, 0xc641=Space Navigator)
hidd_device_ident_t interest = {0x256f,0xc641,(_uint32)HIDD_CONNECT_WILDCARD};
//set up usb functions
hidd_funcs_t funcs = {_HIDDI_NFUNCS, &oninsertion, NULL, &dump, NULL};
hidd_connect_parm_t parm = {NULL,
HID_VERSION,
HIDD_VERSION,
0,
0,
&interest,
&funcs,
HIDD_CONNECT_WAIT};
if(hidd_connect(&parm, &d_connection)!=0)
{
printf("hidd_connect() error\n");
return EXIT_FAILURE;
}
while(1)
{
sleep(1);
printf("X:%i\t Y:%i\t Z:%i\t rX:%i\t rY:%i\t rZ:%i\n", x, y, z, rx, ry, rz);
}
return EXIT_SUCCESS;
}
What am I doing wrong? As usual, any help is appreciated!