From 121afb94493a7379ce39d76bffb61c898e6aebf0 Mon Sep 17 00:00:00 2001 From: Michael Turvey Date: Sun, 12 Mar 2017 12:28:10 -0700 Subject: More changes to gracefully support a tracker --- src/survive.c | 0 src/survive_cal.c | 12 +++++++++--- src/survive_vive.c | 50 ++++++++++++++++++++++++++++++++++++++------------ test.c | 3 +++ 4 files changed, 50 insertions(+), 15 deletions(-) mode change 100644 => 100755 src/survive.c mode change 100644 => 100755 src/survive_cal.c mode change 100644 => 100755 test.c diff --git a/src/survive.c b/src/survive.c old mode 100644 new mode 100755 diff --git a/src/survive_cal.c b/src/survive_cal.c old mode 100644 new mode 100755 index 06914eb..ad518b3 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -104,9 +104,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" ); } ootx_packet_clbk = ootx_packet_clbk_d; diff --git a/src/survive_vive.c b/src/survive_vive.c index 6e209d9..993125a 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -342,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++ ) @@ -384,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; + } } } @@ -857,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! @@ -1101,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; @@ -1112,6 +1137,7 @@ fail_gracefully: free( hmd ); free( wm0 ); free( wm1 ); + free( tr0 ); survive_vive_usb_close( sv ); free( sv ); return -1; diff --git a/test.c b/test.c old mode 100644 new mode 100755 index 9dc3631..a7da490 --- a/test.c +++ b/test.c @@ -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) { -- cgit v1.2.3