aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2016-12-15 22:35:51 -0500
committercnlohr <lohr85@gmail.com>2016-12-15 22:35:51 -0500
commit890a3addcc936229541626e6748fadd142f58a6e (patch)
tree654e761392f0387a59f903fa66eaaf935739065a /src
parentbe571a486992bf01ddf72b536b7c3bc47a87cc78 (diff)
downloadlibsurvive-890a3addcc936229541626e6748fadd142f58a6e.tar.gz
libsurvive-890a3addcc936229541626e6748fadd142f58a6e.tar.bz2
rework some of the way we display data and the way magic codes are sent.
Diffstat (limited to 'src')
-rw-r--r--src/survive_data.c17
-rw-r--r--src/survive_internal.h2
-rw-r--r--src/survive_process.c12
-rw-r--r--src/survive_usb.c52
4 files changed, 58 insertions, 25 deletions
diff --git a/src/survive_data.c b/src/survive_data.c
index 11677e0..c84ab09 100644
--- a/src/survive_data.c
+++ b/src/survive_data.c
@@ -41,11 +41,14 @@ static void handle_lightcap( struct SurviveObject * so, struct LightcapElement *
int32_t deltat = (uint32_t)le->timestamp - (uint32_t)ct->last_photo_time;
if( deltat > 2000 || deltat < -2000 ) //New pulse. (may be inverted)
{
- ct->last_photo_time = le->timestamp;
- ct->total_photo_time = 0;
- ct->total_photos = 0;
- ct->total_pulsecode_time = 0;
- survive_light_process( so, le->sensor_id, -1, 0, le->timestamp );
+ if( le->timestamp - ct->last_photo_time > 80000 )
+ {
+ ct->last_photo_time = le->timestamp;
+ ct->total_photo_time = 0;
+ ct->total_photos = 0;
+ ct->total_pulsecode_time = 0;
+ survive_light_process( so, le->sensor_id, -1, 0, le->timestamp, deltat );
+ }
}
else
{
@@ -54,7 +57,7 @@ static void handle_lightcap( struct SurviveObject * so, struct LightcapElement *
ct->total_photos++;
}
}
- else if( le->length < 900 && le->length > 50 && ct->total_photos )
+ else if( le->length < 1200 && le->length > 40 && ct->total_photos )
{
int32_t dl = (ct->total_photo_time/ct->total_photos);
int32_t tpco = (ct->total_pulsecode_time/ct->total_photos);
@@ -70,7 +73,7 @@ static void handle_lightcap( struct SurviveObject * so, struct LightcapElement *
if( offset_from < 380000 )
{
- survive_light_process( so, le->sensor_id, acode, offset_from, le->timestamp );
+ survive_light_process( so, le->sensor_id, acode, offset_from, le->timestamp, le->length );
}
}
else
diff --git a/src/survive_internal.h b/src/survive_internal.h
index d6168b2..40659e8 100644
--- a/src/survive_internal.h
+++ b/src/survive_internal.h
@@ -113,7 +113,7 @@ int survive_get_config( char ** config, struct SurviveContext * ctx, int devno,
void survive_data_cb( struct SurviveUSBInterface * si );
//Accept higher-level data.
-void survive_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode );
+void survive_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length );
void survive_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id );
diff --git a/src/survive_process.c b/src/survive_process.c
index 268fdfc..046971f 100644
--- a/src/survive_process.c
+++ b/src/survive_process.c
@@ -8,13 +8,13 @@ int bufferpts[32*2];
char buffermts[32*128];
int buffertimeto[32];
-void survive_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode )
+void survive_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length )
{
if( acode == -1 ) return;
if( acode == 0 || acode == 2 ) //data = 0
{
- printf( "L, X, %s, %d, %d, %d, %d\n", so->codename, timecode, sensor_id, acode, timeinsweep );
+ printf( "L X %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length );
bufferpts[sensor_id*2+0] = (timeinsweep-100000)/500;
buffertimeto[sensor_id] = 0;
//printf( "X: %d\n",bufferpts[sensor_id*2+0] );
@@ -22,7 +22,7 @@ void survive_light_process( struct SurviveObject * so, int sensor_id, int acode,
}
if( acode == 1 || acode == 3 ) //data = 1
{
- printf( "L, Y, %s, %d, %d, %d, %d\n", so->codename, timecode, sensor_id, acode, timeinsweep );
+ printf( "L Y %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length );
bufferpts[sensor_id*2+1] = (timeinsweep-100000)/500;
//printf( "Y: %d\n",bufferpts[sensor_id*2+1] );
buffertimeto[sensor_id] = 0;
@@ -33,7 +33,7 @@ void survive_light_process( struct SurviveObject * so, int sensor_id, int acode,
if( acode == 4 || acode == 6 ) //data = 0
{
- printf( "R, X, %s, %d, %d, %d, %d\n", so->codename, timecode, sensor_id, acode, timeinsweep );
+ printf( "R X %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length );
bufferpts[sensor_id*2+0] = (timeinsweep-100000)/500;
buffertimeto[sensor_id] = 0;
//printf( "X: %d\n",bufferpts[sensor_id*2+0] );
@@ -41,7 +41,7 @@ void survive_light_process( struct SurviveObject * so, int sensor_id, int acode,
}
if( acode == 5 || acode == 7 ) //data = 1
{
- printf( "R, Y, %s, %d, %d, %d, %d\n", so->codename, timecode, sensor_id, acode, timeinsweep );
+ printf( "R Y %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length );
bufferpts[sensor_id*2+1] = (timeinsweep-100000)/500;
//printf( "Y: %d\n",bufferpts[sensor_id*2+1] );
buffertimeto[sensor_id] = 0;
@@ -58,6 +58,6 @@ void survive_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32
//if( so->codename[0] == 'H' )
if( 1 )
{
- printf( "I, %s, %d, %d, %d, %d, %d, %d, %d, %d\n", so->codename, timecode, accelgyro[0], accelgyro[1], accelgyro[2], accelgyro[3], accelgyro[4], accelgyro[5], id );
+ printf( "I %s %d %d %d %d %d %d %d %d\n", so->codename, timecode, accelgyro[0], accelgyro[1], accelgyro[2], accelgyro[3], accelgyro[4], accelgyro[5], id );
}
}
diff --git a/src/survive_usb.c b/src/survive_usb.c
index 07e5cb4..4f341ec 100644
--- a/src/survive_usb.c
+++ b/src/survive_usb.c
@@ -233,12 +233,22 @@ int survive_usb_init( struct SurviveContext * ctx )
SV_INFO( "All devices attached." );
-#if 1
+
+ //libUSB initialized. Continue.
+ return 0;
+}
+
+int survive_usb_send_magic(struct SurviveContext * ctx, int turnon )
+{
+ int r;
+
+
+ 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,
@@ -246,15 +256,14 @@ int survive_usb_init( struct SurviveContext * ctx )
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,
};
-
- //From actual use. ((THIS SEEMS TO BREAK IT))
-/*
+#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
r = update_feature_report( ctx->udev[USB_DEV_HMD], 0, vive_magic_power_on, sizeof( vive_magic_power_on ) );
SV_INFO( "UCR: %d", r );
if( r != sizeof( vive_magic_power_on ) ) return 5;
@@ -274,17 +283,38 @@ int survive_usb_init( struct SurviveContext * ctx )
usleep( 1000 );
}
#endif
+ SV_INFO( "Powered unit on." );
}
-#endif
+ else
+ {
- SV_INFO( "Powered unit on." );
+ static uint8_t vive_magic_power_off1[] = {
+ 0x04, 0x78, 0x29, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+ 0x30, 0x05, 0x77, 0x00, 0x30, 0x05, 0x77, 0x00, 0x6c, 0x4d, 0x37, 0x65, 0x40,
+ 0xf9, 0x33, 0x00, 0x04, 0xf8, 0xa3, 0x04, 0x04, 0x00, 0x00, 0x00, 0x70, 0xb0,
+ 0x72, 0x00, 0xf4, 0xf7, 0xa3, 0x04, 0x7c, 0xf8, 0x33, 0x00, 0x0c, 0xf8, 0xa3,
+ 0x04, 0x0a, 0x6e, 0x29, 0x65, 0x24, 0xf9, 0x33, 0x00, 0x00, 0x00, 0x00,
+ };
+ static uint8_t vive_magic_power_off2[] = {
+ 0x04, 0x78, 0x29, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+ 0x30, 0x05, 0x77, 0x00, 0xe4, 0xf7, 0x33, 0x00, 0xe4, 0xf7, 0x33, 0x00, 0x60,
+ 0x6e, 0x72, 0x00, 0xb4, 0xf7, 0x33, 0x00, 0x04, 0x00, 0x00, 0x00, 0x70, 0xb0,
+ 0x72, 0x00, 0x90, 0xf7, 0x33, 0x00, 0x7c, 0xf8, 0x33, 0x00, 0xd0, 0xf7, 0x33,
+ 0x00, 0x3c, 0x68, 0x29, 0x65, 0x24, 0xf9, 0x33, 0x00, 0x00, 0x00, 0x00,
+ };
+// r = update_feature_report( ctx->udev[USB_DEV_HMD], 0, vive_magic_power_off1, sizeof( vive_magic_power_off1 ) );
+// SV_INFO( "UCR: %d", r );
+// if( r != sizeof( vive_magic_power_off1 ) ) return 5;
- //libUSB initialized. Continue.
- return 0;
-}
+ r = update_feature_report( ctx->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;
+ }
+
+}
void survive_usb_close( struct SurviveContext * t )
{