diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/survive.c | 3 | ||||
-rw-r--r-- | src/survive_data.c | 34 | ||||
-rw-r--r-- | src/survive_internal.h | 16 | ||||
-rw-r--r-- | src/survive_usb.c | 69 |
4 files changed, 109 insertions, 13 deletions
diff --git a/src/survive.c b/src/survive.c index a6a8b9e..6fa6fb3 100644 --- a/src/survive.c +++ b/src/survive.c @@ -3,11 +3,12 @@ #include <stdio.h> #include <stdlib.h> -struct SurviveContext * survive_init( void(*ff)( struct SurviveContext * ctx, const char * fault ) ) +struct SurviveContext * survive_init( void(*ff)( struct SurviveContext * ctx, const char * fault ), void(*notefunction)( struct SurviveContext * ctx, const char * note ) ) { int r = 0; struct SurviveContext * ret = calloc( 1, sizeof( struct SurviveContext ) ); ret->faultfunction = ff; + ret->notefunction = notefunction; if( r = survive_usb_init( ret ) ) { return 0; diff --git a/src/survive_data.c b/src/survive_data.c index de92a90..c384b52 100644 --- a/src/survive_data.c +++ b/src/survive_data.c @@ -29,6 +29,26 @@ static void handle_lightdata( struct LightpulseStructure * p ) //printf( "%4d %4d (%6d %6d %6d %6d %6d) %10d %6d\n", p->id, p->type, p->unknown1, p->unknown2, p->unknown3, p->unknown4, p->unknown5, p->timestamp, p->unknown6 ); } + +struct LightcapElement +{ + uint8_t sensor_id; + uint8_t type; + uint16_t length; + uint32_t timestamp; +} __attribute__((packed)); + + +static void handle_lightcap( struct SurviveUSBInterface * si, struct LightcapElement * le ) +{ + if( le->type != 0xfe || le->length < 1 ) return; + printf( "%3d %3d %6d %8d\n", le->sensor_id, le->type, le->length, le->timestamp ); +} + + + + + /* struct vive_controller_analog_trigger_message { __u8 squeeze; @@ -103,10 +123,10 @@ static void handle_watchman( int whichwatch, uint8_t * readdata ) break; //...many more F's. default: //It's a light! - printf( "WM: %3d %3d %3d %3d %02x: ", whichwatch, time1, sensor_id, time2, type ); - for( i = 0; i < 26; i++ ) - printf( "%02x ", readdata[i] ); - printf("\n" ); + //printf( "WM: %3d %3d %3d %3d %02x: ", whichwatch, time1, sensor_id, time2, type ); + //for( i = 0; i < 26; i++ ) + //printf( "%02x ", readdata[i] ); + //printf("\n" ); break; @@ -191,12 +211,10 @@ void survive_data_cb( struct SurviveUSBInterface * si ) case USB_IF_LIGHTCAP: { int i; - for( i = 0; i < size; i++ ) + for( i = 0; i < 7; i++ ) { - printf( "%02x ", si->buffer[i] ); + handle_lightcap( si, &readdata[i*8] ); } - printf( "\n" ); - break; } } diff --git a/src/survive_internal.h b/src/survive_internal.h index 70249e3..394842b 100644 --- a/src/survive_internal.h +++ b/src/survive_internal.h @@ -6,7 +6,7 @@ #include <stdint.h> #include <libusb-1.0/libusb.h> -#define SV_INFO( x... ) printf( x ) +#define SV_INFO( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->notefunction( ctx, stbuff ); } #define SV_ERROR( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->faultfunction( ctx, stbuff ); } //XXX TODO This one needs to be rewritten. @@ -26,7 +26,8 @@ #define USB_IF_LIGHTCAP 4 #define MAX_INTERFACES 5 -#define INTBUFFSIZE 64 +#define INTBUFFSIZE 64 +#define SENSORS_PER_OBJECT 32 struct SurviveContext; struct SurviveUSBInterface; @@ -44,18 +45,27 @@ struct SurviveUSBInterface const char * hname; //human-readable names }; +struct SurvivePhoto +{ + uint32_t last; + uint32_t lastcode; + uint32_t lastlength; +}; + struct SurviveContext { //USB Subsystem struct libusb_context* usbctx; void(*faultfunction)( struct SurviveContext * ctx, const char * fault ); + void(*notefunction)( struct SurviveContext * ctx, const char * fault ); struct libusb_device_handle * udev[MAX_USB_DEVS]; struct SurviveUSBInterface uiface[MAX_INTERFACES]; + +// struct SurvivePhoto }; //USB Subsystem - void survive_usb_close( struct SurviveContext * t ); int survive_usb_init( struct SurviveContext * t ); int survive_usb_poll( struct SurviveContext * ctx ); diff --git a/src/survive_usb.c b/src/survive_usb.c index 0958070..92e61db 100644 --- a/src/survive_usb.c +++ b/src/survive_usb.c @@ -1,6 +1,7 @@ #include "survive_internal.h" #include <libusb-1.0/libusb.h> #include <stdio.h> +#include <unistd.h> //sleep if I ever use it. const short vidpids[] = { 0x0bb4, 0x2c87, 0, //The main HTC HMD device @@ -81,6 +82,17 @@ static void debug_cb( struct SurviveUSBInterface * si ) printf( "\n" ); }*/ + +static inline int update_feature_report(libusb_device_handle* dev, uint16_t interface, uint8_t * data, int datalen ) { +// int xfer; +// int r = libusb_interrupt_transfer(dev, 0x01, data, datalen, &xfer, 1000); +// printf( "XFER: %d / R: %d\n", xfer, r ); +// return xfer; + return libusb_control_transfer(dev, LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT, + 0x09, 0x300 | data[0], interface, data, datalen, 1000 ); +} + + int survive_usb_init( struct SurviveContext * ctx ) { int r = libusb_init( &ctx->usbctx ); @@ -149,6 +161,19 @@ int survive_usb_init( struct SurviveContext * ctx ) for (int j = 0; j < conf->bNumInterfaces; j++ ) { +#if 0 + if (libusb_kernel_driver_active(ctx->udev[i], j) == 1) { + ret = libusb_detach_kernel_driver(ctx->udev[i], j); + if (ret != LIBUSB_SUCCESS) { + SV_ERROR("Failed to unclaim interface %d for device %s " + "from the kernel.", j, devnames[i] ); + libusb_free_config_descriptor(conf); + libusb_close(ctx->udev[i]); + continue; + } + } +#endif + if( libusb_claim_interface(ctx->udev[i], j) ) { SV_ERROR( "Could not claim interface %d of %s", j, devnames[i] ); @@ -166,7 +191,49 @@ int survive_usb_init( struct SurviveContext * ctx ) if( AttachInterface( ctx, USB_IF_WATCHMAN2, ctx->udev[USB_DEV_WATCHMAN2], 0x81, survive_data_cb, "Watchman 2" ) ) { return -9; } if( AttachInterface( ctx, USB_IF_LIGHTCAP, ctx->udev[USB_DEV_LIGHTHOUSE], 0x82, survive_data_cb, "Lightcap" ) ) { return -10; } - SV_INFO( "All devices attached.\n" ); + SV_INFO( "All devices attached." ); + +#if 1 + { + //Magic from vl_magic.h, originally copywritten under LGPL. + // * Copyright (C) 2013 Fredrik Hultin + // * Copyright (C) 2013 Jakob Bornecrantz + + 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, + }; + + 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; + + static uint8_t vive_magic_enable_lighthouse[64] = { 0x04 }; //[64] wat? Why did that fix it? + SV_INFO( "UCR: %d", r ); + r = update_feature_report( ctx->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++ ) + { + static uint8_t vive_controller_haptic_pulse[64] = { 0xff, 0x8f, 0xff, 0, 0, 0, 0, 0, 0, 0 }; + r = update_feature_report( ctx->udev[USB_DEV_WATCHMAN1], 0, vive_controller_haptic_pulse, sizeof( vive_controller_haptic_pulse ) ); + SV_INFO( "UCR: %d", r ); + if( r != sizeof( vive_controller_haptic_pulse ) ) return 5; + usleep( 1000 ); + } +#endif + + //hret = hid_send_feature_report(drv->hmd_device, vive_magic_enable_lighthouse, sizeof(vive_magic_enable_lighthouse)); + //vl_debug("enable lighthouse magic: %d\n", hret); + } +#endif + + SV_INFO( "Powered unit on." ); + //libUSB initialized. Continue. |