From 62cef8aec06638bd006eaef46700f491750fc108 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Wed, 15 Mar 2017 19:24:26 -0400 Subject: rename variables --- src/survive_data.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/survive_data.c b/src/survive_data.c index 6824b0f..ac397b9 100644 --- a/src/survive_data.c +++ b/src/survive_data.c @@ -25,10 +25,10 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) //The sync pulse finder is taking Charles's old disambiguator code and mixing it with a more linear //version of Julian Picht's disambiguator, available in 488c5e9. Removed afterwards into this //unified driver. - int ssn = so->sync_set_number; + int ssn = so->sync_set_number; //lighthouse number if( ssn < 0 ) ssn = 0; - int last_sync_time = so->last_time [ssn]; - int last_sync_length = so->last_length[ssn]; + int last_sync_time = so->last_sync_time [ssn]; + int last_sync_length = so->last_sync_length[ssn]; int32_t delta = le->timestamp - last_sync_time; //Handle time wrapping (be sure to be int32) if( delta < -so->pulsedist_max_ticks || delta > so->pulsedist_max_ticks ) @@ -36,6 +36,7 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) //Reset pulse, etc. so->sync_set_number = -1; delta = so->pulsedist_max_ticks; +// return; //if we don't know what lighthouse this is we don't care to do much else } @@ -52,8 +53,8 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) if( is_master_sync_pulse ) { ssn = so->sync_set_number = 0; - so->last_time[ssn] = le->timestamp; - so->last_length[ssn] = le->length; + so->last_sync_time[ssn] = le->timestamp; + so->last_sync_length[ssn] = le->length; } else if( so->sync_set_number == -1 ) { @@ -69,8 +70,8 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) } else { - so->last_time[ssn] = le->timestamp; - so->last_length[ssn] = le->length; + so->last_sync_time[ssn] = le->timestamp; + so->last_sync_length[ssn] = le->length; } } } @@ -79,10 +80,10 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) //Find the longest pulse. if( le->length > last_sync_length ) { - if( so->last_time[ssn] > le->timestamp ) + if( so->last_sync_time[ssn] > le->timestamp ) { - so->last_time[ssn] = le->timestamp; - so->last_length[ssn] = le->length; + so->last_sync_time[ssn] = le->timestamp; + so->last_sync_length[ssn] = le->length; } } } @@ -93,8 +94,8 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) //See if this is a valid actual pulse. else if( le->length < so->pulse_max_for_sweep && delta > so->pulse_in_clear_time && ssn >= 0 ) { - int32_t dl = so->last_time[0]; - int32_t tpco = so->last_length[0]; + int32_t dl = so->last_sync_time[0]; + int32_t tpco = so->last_sync_length[0]; #if NUM_LIGHTHOUSES != 2 @@ -109,8 +110,8 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) int32_t acode_array[2] = { - (so->last_length[0]+main_divisor+50)/(main_divisor*2), //+50 adds a small offset and seems to help always get it right. - (so->last_length[1]+main_divisor+50)/(main_divisor*2), //Check the +50 in the future to see how well this works on a variety of hardware. + (so->last_sync_length[0]+main_divisor+50)/(main_divisor*2), //+50 adds a small offset and seems to help always get it right. + (so->last_sync_length[1]+main_divisor+50)/(main_divisor*2), //Check the +50 in the future to see how well this works on a variety of hardware. }; //XXX: TODO: Capture error count here. @@ -125,13 +126,13 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) if( !so->did_handle_ootx ) { - int32_t delta1 = so->last_time[0] - so->recent_sync_time; - int32_t delta2 = so->last_time[1] - so->last_time[0]; + int32_t delta1 = so->last_sync_time[0] - so->recent_sync_time; + int32_t delta2 = so->last_sync_time[1] - so->last_sync_time[0]; - ctx->lightproc( so, -1, acode_array[0], delta1, so->last_time[0], so->last_length[0] ); - ctx->lightproc( so, -2, acode_array[1], delta2, so->last_time[1], so->last_length[1] ); + ctx->lightproc( so, -1, acode_array[0], delta1, so->last_sync_time[0], so->last_sync_length[0] ); + ctx->lightproc( so, -2, acode_array[1], delta2, so->last_sync_time[1], so->last_sync_length[1] ); - so->recent_sync_time = so->last_time[1]; + so->recent_sync_time = so->last_sync_time[1]; //Throw out everything if our sync pulses look like they're bad. @@ -163,8 +164,8 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) //SV_INFO( "Warning: got a slave marker but only got a master sync." ); //This happens too frequently. Consider further examination. } - dl = so->last_time[1]; - tpco = so->last_length[1]; + dl = so->last_sync_time[1]; + tpco = so->last_sync_length[1]; } int32_t offset_from = le->timestamp - dl + le->length/2; -- cgit v1.2.3 From eeb4bc3ce4c70be89cbe963075907eceebe77d18 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Wed, 15 Mar 2017 20:57:50 -0400 Subject: print lots of sync data --- src/survive_data.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/survive_data.c b/src/survive_data.c index e51de8e..60849e2 100644 --- a/src/survive_data.c +++ b/src/survive_data.c @@ -44,6 +44,8 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) { int is_new_pulse = delta > so->pulselength_min_sync /*1500*/ + last_sync_length; + printf("m sync %d %d %d %d\n", le->sensor_id, so->last_sync_time[ssn], le->timestamp, delta); + so->did_handle_ootx = 0; if( is_new_pulse ) -- cgit v1.2.3 From 2b93b2c57f8fea99ed9a5de520b274696e058faf Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 15 Mar 2017 21:32:09 -0400 Subject: fix puff for headset. --- src/survive.c | 4 ++-- src/survive_vive.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index 1b5bed1..3c16353 100755 --- a/src/survive.c +++ b/src/survive.c @@ -253,8 +253,8 @@ struct SurviveObject * survive_get_so_by_name( struct SurviveContext * ctx, cons int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ) { unsigned long ol = outlen; - unsigned long il = inlen; - int ret = puff( output, &ol, input, &il ); + unsigned long il = inlen-2; + int ret = puff( output, &ol, input+2, &il ); if( ret == 0 ) return ol; else diff --git a/src/survive_vive.c b/src/survive_vive.c index fc05647..12d8c16 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -711,7 +711,7 @@ int survive_get_config( char ** config, struct SurviveViveData * sv, int devno, int len = survive_simple_inflate( ctx, compressed_data, count, uncompressed_data, sizeof(uncompressed_data)-1 ); if( len <= 0 ) { - SV_INFO( "Error: data for config descriptor %d:%d is bad.", devno, iface ); + SV_INFO( "Error: data for config descriptor %d:%d is bad. (%d)", devno, iface, len ); return -5; } -- cgit v1.2.3 From a15a75ea846f434691fc30f0db79e5fa844c065c Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 15 Mar 2017 21:34:33 -0400 Subject: add note about extra 2 bytes. --- src/survive.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index 3c16353..a756f3e 100755 --- a/src/survive.c +++ b/src/survive.c @@ -252,6 +252,7 @@ struct SurviveObject * survive_get_so_by_name( struct SurviveContext * ctx, cons int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ) { + //Tricky: we actually get 2 bytes of data on the front. I don't know what it's for. 0x78 0x9c - puff doesn't deal with it well. unsigned long ol = outlen; unsigned long il = inlen-2; int ret = puff( output, &ol, input+2, &il ); -- cgit v1.2.3 From 2eaf385fdd769c232be5826353fcf0dba13b827e Mon Sep 17 00:00:00 2001 From: CNLohr Date: Thu, 16 Mar 2017 01:57:36 -0400 Subject: Make the vive able to deal with data in new-valve-mode or old-valve-mode. --- src/survive_vive.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/survive_vive.c b/src/survive_vive.c index 12d8c16..c3967cd 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -1082,24 +1082,28 @@ void survive_data_cb( SurviveUSBInterface * si ) case USB_IF_LIGHTCAP: { int i; - #ifdef HIDAPI - for( i = 0; i < 7; i++ ) + + if( si->buffer[0] == 0x25 ) //Once the valve drivers run, they somehow put the HMD into 7-byte-width messages. { - LightcapElement le; - le.sensor_id = POP1; - le.type = 0xfe; - le.length = POP2; - le.timestamp = POP4; - if( le.sensor_id == 0xff ) break; - handle_lightcap( obj, &le ); - } - #else - for( i = 0; i < 7; i++ ) + for( i = 0; i < 9; i++ ) + { + LightcapElement le; + le.sensor_id = POP1; + le.type = 0xfe; + le.length = POP2; + le.timestamp = POP4; + if( le.sensor_id == 0xff ) break; + handle_lightcap( obj, &le ); + } + } + else //Otherwise, we're in the old mode. { - handle_lightcap( obj, (LightcapElement*)&readdata[i*8] ); + for( i = 0; i < 7; i++ ) + { + handle_lightcap( obj, (LightcapElement*)&readdata[i*8] ); + } + break; } - break; - #endif } } } -- cgit v1.2.3 From 23139f5a92d89be80b066e4dc71f27952bd284ca Mon Sep 17 00:00:00 2001 From: CNLohr Date: Thu, 16 Mar 2017 03:58:45 -0400 Subject: Fix lighthouse capture mechanism to match new valve. --- src/survive_vive.c | 69 ++++++++++++++---------------------------------------- 1 file changed, 17 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/survive_vive.c b/src/survive_vive.c index c3967cd..99d69a3 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -480,36 +480,23 @@ int survive_vive_send_magic(struct SurviveContext * ctx, void * drv, int magic_c if( turnon ) { - //Magic from vl_magic.h, originally copywritten under LGPL. - // * Copyright (C) 2013 Fredrik Hultin - // * Copyright (C) 2013 Jakob Bornecrantz -#if 0 - static uint8_t vive_magic_power_on[] = { - 0x04, 0x78, 0x29, 0x38, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, - 0xa8, 0x0d, 0x76, 0x00, 0x40, 0xfc, 0x01, 0x05, 0xfa, 0xec, 0xd1, 0x6d, 0x00, - 0x00, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0x0d, 0x76, 0x00, 0x68, 0xfc, - 0x01, 0x05, 0x2c, 0xb0, 0x2e, 0x65, 0x7a, 0x0d, 0x76, 0x00, 0x68, 0x54, 0x72, - 0x00, 0x18, 0x54, 0x72, 0x00, 0x00, 0x6a, 0x72, 0x00, 0x00, 0x00, 0x00, - }; -#else //From actual steam. - static uint8_t vive_magic_power_on[64] = { 0x04, 0x78, 0x29, 0x38, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 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 if (sv->udev[USB_DEV_HMD]) { + static uint8_t vive_magic_power_on[64] = { 0x04, 0x78, 0x29, 0x38 }; 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_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 ) ); ///XXX TODO: Shouldn't this be LIGHTHOUSEB for hidapi? + static uint8_t vive_magic_enable_lighthouse[5] = { 0x04 }; + 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; + + static uint8_t vive_magic_enable_lighthouse2[5] = { 0x07, 0x02 }; //Switch to 0x25 mode (able to get more light updates) + r = update_feature_report( sv->udev[USB_DEV_LIGHTHOUSE], 0, vive_magic_enable_lighthouse2, sizeof( vive_magic_enable_lighthouse2 ) ); + if( r != sizeof( vive_magic_enable_lighthouse2 ) ) return 5; } #if 0 @@ -621,16 +608,7 @@ int survive_get_config( char ** config, struct SurviveViveData * sv, int devno, int k; - uint8_t cfgbuff_send[64] = { - 0xff, 0x83, 0x00, 0xb6, 0x5b, 0xb0, 0x78, 0x69, - 0x0f, 0xf8, 0x78, 0x69, 0x0f, 0xa0, 0xf3, 0x18, - 0x00, 0xe8, 0xf2, 0x18, 0x00, 0x27, 0x44, 0x5a, - 0x0f, 0xf8, 0x78, 0x69, 0x0f, 0xf0, 0x77, 0x69, - 0x0f, 0xf0, 0x77, 0x69, 0x0f, 0x50, 0xca, 0x45, - 0x77, 0xa0, 0xf3, 0x18, 0x00, 0xf8, 0x78, 0x69, - 0x0f, 0x00, 0x00, 0xa0, 0x0f, 0xa0, 0x9b, 0x0a, - 0x01, 0x00, 0x00, 0x35, 0x00, 0x34, 0x02, 0x00 - }; + uint8_t cfgbuff_send[64] = { 0xff, 0x83 }; #ifdef HIDAPI //XXX TODO WRITEME @@ -928,7 +906,6 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata ) //Use insertion sort, since we should most of the time, be in order. LightcapElement * le = &les[lese++]; le->sensor_id = led; - le->type = 0xfe; if( (uint32_t)(endtime - starttime) > 65535 ) { fault = 6; goto end; } //Length of pulse dumb. le->length = endtime - starttime; @@ -1082,28 +1059,16 @@ void survive_data_cb( SurviveUSBInterface * si ) case USB_IF_LIGHTCAP: { int i; - - if( si->buffer[0] == 0x25 ) //Once the valve drivers run, they somehow put the HMD into 7-byte-width messages. + for( i = 0; i < 9; i++ ) { - for( i = 0; i < 9; i++ ) - { - LightcapElement le; - le.sensor_id = POP1; - le.type = 0xfe; - le.length = POP2; - le.timestamp = POP4; - if( le.sensor_id == 0xff ) break; - handle_lightcap( obj, &le ); - } - } - else //Otherwise, we're in the old mode. - { - for( i = 0; i < 7; i++ ) - { - handle_lightcap( obj, (LightcapElement*)&readdata[i*8] ); - } - break; - } + LightcapElement le; + le.sensor_id = POP1; + le.length = POP2; + le.timestamp = POP4; + if( le.sensor_id == 0xff ) break; + handle_lightcap( obj, &le ); + } + break; } } } -- cgit v1.2.3 From 9378bfbd11e0e476a8e0477a74ac918b931a690f Mon Sep 17 00:00:00 2001 From: CNLohr Date: Thu, 16 Mar 2017 04:14:26 -0400 Subject: Fix: Initialize both lighthouse configs. --- src/survive.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index a756f3e..b2e4ae3 100755 --- a/src/survive.c +++ b/src/survive.c @@ -55,7 +55,8 @@ SurviveContext * survive_init( int headless ) ctx->lh_config = malloc( sizeof(config_group) * NUM_LIGHTHOUSES); init_config_group(ctx->global_config_values,10); - init_config_group(ctx->lh_config,10); + init_config_group(&ctx->lh_config[0],10); + init_config_group(&ctx->lh_config[1],10); config_read(ctx, "config.json"); -- cgit v1.2.3 From 7dc4d180e0ce95ad6e9eeb2606a4516b93e872f5 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Thu, 16 Mar 2017 00:23:40 -0400 Subject: Fix compile warning --- src/survive_vive.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/survive_vive.c b/src/survive_vive.c index 99d69a3..3930a2c 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -17,10 +17,9 @@ #include #include #include - +#include #ifdef HIDAPI -#include #if defined(WINDOWS) || defined(WIN32) #include #undef WCHAR_MAX -- cgit v1.2.3 From 6daf2506fcfbfcd26d63a8bddba319d67ecc33e5 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Thu, 16 Mar 2017 00:47:54 -0400 Subject: Fix crashes in Linux without hidapi, and fix buffer overflow bug. --- src/survive_cal.c | 2 +- src/survive_vive.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/survive_cal.c b/src/survive_cal.c index 0ea9337..985ab24 100755 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -267,7 +267,7 @@ void survive_cal_angle( struct SurviveObject * so, int sensor_id, int acode, uin } if( sensors_visible < MIN_SENSORS_VISIBLE_PER_LH_FOR_CAL ) { - printf( "Dev %d, LH %d not enough visible points found.\n", i, j ); + //printf( "Dev %d, LH %d not enough visible points found.\n", i, j ); cd->found_common = 0; return; } diff --git a/src/survive_vive.c b/src/survive_vive.c index 3930a2c..18b2742 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -59,9 +59,13 @@ const char * devnames[] = { #define USB_DEV_WATCHMAN1 2 #define USB_DEV_WATCHMAN2 3 #define USB_DEV_TRACKER0 4 + +#ifdef HIDAPI #define USB_DEV_LIGHTHOUSEB 5 #define MAX_USB_DEVS 6 - +#else +#define MAX_USB_DEVS 5 +#endif #define USB_IF_HMD 0 #define USB_IF_LIGHTHOUSE 1 @@ -402,6 +406,7 @@ int survive_usb_init( struct SurviveViveData * sv, struct SurviveObject * hmd, s if( d == 0 ) { + printf( "!!%p %d %04x %04x %d\n", devnames[i], i, vid, pid, which ); SV_INFO( "Did not find device %s (%04x:%04x.%d)", devnames[i], vid, pid, which ); sv->udev[i] = 0; continue; @@ -1199,7 +1204,7 @@ printf( "Loading config: %d\n", len ); return 1; } - char fname[20]; + char fname[64]; sprintf( fname, "calinfo/%s_points.csv", so->codename ); FILE * f = fopen( fname, "w" ); -- cgit v1.2.3