diff options
author | cnlohr <lohr85@gmail.com> | 2017-03-13 01:01:43 -0400 |
---|---|---|
committer | cnlohr <lohr85@gmail.com> | 2017-03-13 01:01:43 -0400 |
commit | 44dc07e5fff7421289397ecd1051bd56012faac6 (patch) | |
tree | fa860154ac3bcd66955395d7a053c03b98943399 | |
parent | 767c46b76383be63926c7ec2a74e2dd9508f60d8 (diff) | |
parent | ab32fd2966df3f6c385f281adaa4fc5af21aed57 (diff) | |
download | libsurvive-44dc07e5fff7421289397ecd1051bd56012faac6.tar.gz libsurvive-44dc07e5fff7421289397ecd1051bd56012faac6.tar.bz2 |
Merge branch 'mwturvey-TrackerSupport2'
-rwxr-xr-x[-rw-r--r--] | src/survive.c | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/survive_cal.c | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | src/survive_vive.c | 96 | ||||
-rwxr-xr-x[-rw-r--r--] | test.c | 3 |
4 files changed, 78 insertions, 33 deletions
diff --git a/src/survive.c b/src/survive.c index 6d49d55..6d49d55 100644..100755 --- a/src/survive.c +++ b/src/survive.c diff --git a/src/survive_cal.c b/src/survive_cal.c index f810098..1a3be2d 100644..100755 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -114,9 +114,15 @@ void survive_cal_install( struct SurviveContext * ctx ) cd->hmd = survive_get_so_by_name( ctx, "HMD" ); if( !cd->hmd ) { - SV_ERROR( "Error: cannot find any devices labeled HMD. Required for calibration" ); - free( cd ); - return; + cd->hmd = survive_get_so_by_name( ctx, "TR0" ); + + if( !cd->hmd ) + { + SV_ERROR( "Error: cannot find any devices labeled HMD. Required for calibration" ); + free( cd ); + return; + } + SV_INFO( "HMD not found, calibrating using Tracker" ); } diff --git a/src/survive_vive.c b/src/survive_vive.c index 17c9dd5..0cae6f0 100644..100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -27,6 +27,7 @@ const short vidpids[] = { 0x28de, 0x2000, 0, //Valve lighthouse 0x28de, 0x2101, 0, //Valve Watchman 0x28de, 0x2101, 1, //Valve Watchman + 0x28de, 0x2022, 0, //HTC Tracker }; //length MAX_USB_INTERFACES*2 const char * devnames[] = { @@ -34,6 +35,7 @@ const char * devnames[] = { "Lighthouse", "Watchman 1", "Watchman 2", + "Tracker 0", }; //length MAX_USB_INTERFACES @@ -41,15 +43,17 @@ const char * devnames[] = { #define USB_DEV_LIGHTHOUSE 1 #define USB_DEV_WATCHMAN1 2 #define USB_DEV_WATCHMAN2 3 -#define MAX_USB_DEVS 4 +#define USB_DEV_TRACKER0 4 +#define MAX_USB_DEVS 5 #define USB_IF_HMD 0 #define USB_IF_LIGHTHOUSE 1 #define USB_IF_WATCHMAN1 2 #define USB_IF_WATCHMAN2 3 -#define USB_IF_LIGHTCAP 4 -#define MAX_INTERFACES 5 +#define USB_IF_TRACKER0 4 +#define USB_IF_LIGHTCAP 5 +#define MAX_INTERFACES 6 typedef struct SurviveUSBInterface SurviveUSBInterface; typedef struct SurviveViveData SurviveViveData; @@ -86,7 +90,7 @@ void survive_data_cb( SurviveUSBInterface * si ); //USB Subsystem void survive_usb_close( SurviveContext * t ); -int survive_usb_init( SurviveViveData * sv, SurviveObject * hmd, SurviveObject *wm0, SurviveObject * wm1 ); +int survive_usb_init( SurviveViveData * sv, SurviveObject * hmd, SurviveObject *wm0, SurviveObject * wm1, SurviveObject * tr0 ); int survive_usb_poll( SurviveContext * ctx ); int survive_get_config( char ** config, SurviveViveData * ctx, int devno, int interface, int send_extra_magic ); int survive_vive_send_magic(struct SurviveContext * ctx, void * drv, int magic_code, void * data, int datalen ); @@ -199,7 +203,7 @@ static inline int hid_get_feature_report_timeout(libusb_device_handle* device, u } -int survive_usb_init( struct SurviveViveData * sv, struct SurviveObject * hmd, struct SurviveObject *wm0, struct SurviveObject * wm1 ) +int survive_usb_init( struct SurviveViveData * sv, struct SurviveObject * hmd, struct SurviveObject *wm0, struct SurviveObject * wm1, struct SurviveObject * tr0 ) { struct SurviveContext * ctx = sv->ctx; int r = libusb_init( &sv->usbctx ); @@ -248,15 +252,15 @@ int survive_usb_init( struct SurviveViveData * sv, struct SurviveObject * hmd, s if( d == 0 ) { - SV_ERROR( "Couldn't find device %s (%04x:%04x.%d)", devnames[i], vid, pid, which ); - return -99; + SV_INFO( "Did not find device %s (%04x:%04x.%d)", devnames[i], vid, pid, which ); + sv->udev[i] = 0; + continue; } struct libusb_config_descriptor *conf; ret = libusb_get_config_descriptor(d, 0, &conf); if( ret ) continue; - ret = libusb_open(d, &sv->udev[i]); if( !sv->udev[i] || ret ) @@ -292,13 +296,14 @@ int survive_usb_init( struct SurviveViveData * sv, struct SurviveObject * hmd, s } libusb_free_device_list( devs, 1 ); - if( AttachInterface( sv, hmd, USB_IF_HMD, sv->udev[USB_DEV_HMD], 0x81, survive_data_cb, "Mainboard" ) ) { return -6; } - if( AttachInterface( sv, hmd, USB_IF_LIGHTHOUSE, sv->udev[USB_DEV_LIGHTHOUSE], 0x81, survive_data_cb, "Lighthouse" ) ) { return -7; } - if( AttachInterface( sv, wm0, USB_IF_WATCHMAN1, sv->udev[USB_DEV_WATCHMAN1], 0x81, survive_data_cb, "Watchman 1" ) ) { return -8; } - if( AttachInterface( sv, wm1, USB_IF_WATCHMAN2, sv->udev[USB_DEV_WATCHMAN2], 0x81, survive_data_cb, "Watchman 2" ) ) { return -9; } - if( AttachInterface( sv, hmd, USB_IF_LIGHTCAP, sv->udev[USB_DEV_LIGHTHOUSE], 0x82, survive_data_cb, "Lightcap" ) ) { return -10; } + if( sv->udev[USB_DEV_HMD] && AttachInterface( sv, hmd, USB_IF_HMD, sv->udev[USB_DEV_HMD], 0x81, survive_data_cb, "Mainboard" ) ) { return -6; } + if( sv->udev[USB_DEV_LIGHTHOUSE] && AttachInterface( sv, hmd, USB_IF_LIGHTHOUSE, sv->udev[USB_DEV_LIGHTHOUSE], 0x81, survive_data_cb, "Lighthouse" ) ) { return -7; } + if( sv->udev[USB_DEV_WATCHMAN1] && AttachInterface( sv, wm0, USB_IF_WATCHMAN1, sv->udev[USB_DEV_WATCHMAN1], 0x81, survive_data_cb, "Watchman 1" ) ) { return -8; } + if( sv->udev[USB_DEV_WATCHMAN2] && AttachInterface( sv, wm1, USB_IF_WATCHMAN2, sv->udev[USB_DEV_WATCHMAN2], 0x81, survive_data_cb, "Watchman 2")) { return -9; } + if( sv->udev[USB_DEV_TRACKER0] && AttachInterface( sv, tr0, USB_IF_TRACKER0, sv->udev[USB_DEV_TRACKER0], 0x81, survive_data_cb, "Tracker 1")) { return -10; } + if( sv->udev[USB_DEV_LIGHTHOUSE] && AttachInterface( sv, hmd, USB_IF_LIGHTCAP, sv->udev[USB_DEV_LIGHTHOUSE], 0x82, survive_data_cb, "Lightcap")) { return -12; } - SV_INFO( "All devices attached." ); + SV_INFO( "All enumerated devices attached." ); survive_vive_send_magic(ctx, sv, 1, 0, 0 ); @@ -337,12 +342,18 @@ int survive_vive_send_magic(struct SurviveContext * ctx, void * drv, int magic_c 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; #endif - r = update_feature_report( sv->udev[USB_DEV_HMD], 0, vive_magic_power_on, sizeof( vive_magic_power_on ) ); - if( r != sizeof( vive_magic_power_on ) ) return 5; + if (sv->udev[USB_DEV_HMD]) + { + r = update_feature_report( sv->udev[USB_DEV_HMD], 0, vive_magic_power_on, sizeof( vive_magic_power_on ) ); + if( r != sizeof( vive_magic_power_on ) ) return 5; + } - static uint8_t vive_magic_enable_lighthouse[64] = { 0x04 }; //[64] wat? Why did that fix it? - r = update_feature_report( sv->udev[USB_DEV_LIGHTHOUSE], 0, vive_magic_enable_lighthouse, sizeof( vive_magic_enable_lighthouse ) ); - if( r != sizeof( vive_magic_enable_lighthouse ) ) return 5; + if (sv->udev[USB_DEV_LIGHTHOUSE]) + { + static uint8_t vive_magic_enable_lighthouse[64] = { 0x04 }; //[64] wat? Why did that fix it? + r = update_feature_report( sv->udev[USB_DEV_LIGHTHOUSE], 0, vive_magic_enable_lighthouse, sizeof( vive_magic_enable_lighthouse ) ); + if( r != sizeof( vive_magic_enable_lighthouse ) ) return 5; + } #if 0 for( i = 0; i < 256; i++ ) @@ -379,10 +390,12 @@ int survive_vive_send_magic(struct SurviveContext * ctx, void * drv, int magic_c // SV_INFO( "UCR: %d", r ); // if( r != sizeof( vive_magic_power_off1 ) ) return 5; - r = update_feature_report( sv->udev[USB_DEV_HMD], 0, vive_magic_power_off2, sizeof( vive_magic_power_off2 ) ); - SV_INFO( "UCR: %d", r ); - if( r != sizeof( vive_magic_power_off2 ) ) return 5; - + if (sv->udev[USB_DEV_HMD]) + { + r = update_feature_report( sv->udev[USB_DEV_HMD], 0, vive_magic_power_off2, sizeof( vive_magic_power_off2 ) ); + SV_INFO( "UCR: %d", r ); + if( r != sizeof( vive_magic_power_off2 ) ) return 5; + } } } @@ -852,6 +865,22 @@ void survive_data_cb( SurviveUSBInterface * si ) } break; } + case USB_IF_TRACKER0: + { + SurviveObject * w = obj; + if( id == 32 ) + { + // TODO: Looks like this will need to be handle_tracker, since + // it appears the interface is sufficiently different. + // More work needd to reverse engineer it. + handle_watchman( w, readdata); + } + else + { + SV_INFO( "Unknown tracker code %d\n", id ); + } + break; + } case USB_IF_LIGHTCAP: { //Done! @@ -1030,6 +1059,7 @@ int DriverRegHTCVive( SurviveContext * ctx ) SurviveObject * hmd = calloc( 1, sizeof( SurviveObject ) ); SurviveObject * wm0 = calloc( 1, sizeof( SurviveObject ) ); SurviveObject * wm1 = calloc( 1, sizeof( SurviveObject ) ); + SurviveObject * tr0 = calloc( 1, sizeof( SurviveObject ) ); SurviveViveData * sv = calloc( 1, sizeof( SurviveViveData ) ); sv->ctx = ctx; @@ -1043,18 +1073,22 @@ int DriverRegHTCVive( SurviveContext * ctx ) wm1->ctx = ctx; memcpy( wm1->codename, "WM1", 4 ); memcpy( wm1->drivername, "HTC", 4 ); + tr0->ctx = ctx; + memcpy( tr0->codename, "TR0", 4 ); + memcpy( tr0->drivername, "HTC", 4 ); //USB must happen last. - if( r = survive_usb_init( sv, hmd, wm0, wm1 ) ) + if( r = survive_usb_init( sv, hmd, wm0, wm1, tr0) ) { //TODO: Cleanup any libUSB stuff sitting around. goto fail_gracefully; } //Next, pull out the config stuff. - if( LoadConfig( sv, hmd, 1, 0, 0 ) ) goto fail_gracefully; - if( LoadConfig( sv, wm0, 2, 0, 1 ) ) { SV_INFO( "Watchman 0 config issue." ); } - if( LoadConfig( sv, wm1, 3, 0, 1 ) ) { SV_INFO( "Watchman 1 config issue." ); } + if( sv->udev[USB_DEV_HMD] && LoadConfig( sv, hmd, 1, 0, 0 )) { SV_INFO( "HMD config issue." ); } + if( sv->udev[USB_DEV_WATCHMAN1] && LoadConfig( sv, wm0, 2, 0, 1 )) { SV_INFO( "Watchman 0 config issue." ); } + if( sv->udev[USB_DEV_WATCHMAN2] && LoadConfig( sv, wm1, 3, 0, 1 )) { SV_INFO( "Watchman 1 config issue." ); } + if( sv->udev[USB_DEV_TRACKER0] && LoadConfig( sv, tr0, 4, 0, 1 )) { SV_INFO( "Tracker 0 config issue." ); } hmd->timebase_hz = wm0->timebase_hz = wm1->timebase_hz = 48000000; hmd->pulsedist_max_ticks = wm0->pulsedist_max_ticks = wm1->pulsedist_max_ticks = 500000; @@ -1091,10 +1125,11 @@ int DriverRegHTCVive( SurviveContext * ctx ) */ //Add the drivers. + if( sv->udev[USB_DEV_HMD] ) { survive_add_object( ctx, hmd ); } + if( sv->udev[USB_DEV_WATCHMAN1] ) { survive_add_object( ctx, wm0 ); } + if( sv->udev[USB_DEV_WATCHMAN2] ) { survive_add_object( ctx, wm1 ); } + if( sv->udev[USB_DEV_TRACKER0] ) { survive_add_object( ctx, tr0 ); } - survive_add_object( ctx, hmd ); - survive_add_object( ctx, wm0 ); - survive_add_object( ctx, wm1 ); survive_add_driver( ctx, sv, survive_vive_usb_poll, survive_vive_close, survive_vive_send_magic ); return 0; @@ -1102,6 +1137,7 @@ fail_gracefully: free( hmd ); free( wm0 ); free( wm1 ); + free( tr0 ); survive_vive_usb_close( sv ); free( sv ); return -1; @@ -17,6 +17,8 @@ static void dump_iface( struct SurviveObject * so, const char * prefix ) FILE * f; char fname[1024]; + if (!so) { return; } + sprintf( fname, "%s_points.csv", prefix ); f = fopen( fname, "w" ); for( i = 0; i < so->nr_locations; i++ ) @@ -53,6 +55,7 @@ int main() dump_iface( survive_get_so_by_name( ctx, "HMD" ), "HMD" ); dump_iface( survive_get_so_by_name( ctx, "WM0" ), "WM0" ); dump_iface( survive_get_so_by_name( ctx, "WM1" ), "WM1" ); + dump_iface( survive_get_so_by_name( ctx, "TR0" ), "TR0" ); while(survive_poll(ctx) == 0) { |