From 7ef98a611c4e32dc89eba26581f7245797d0623a Mon Sep 17 00:00:00 2001 From: Mike Turvey Date: Tue, 2 Jan 2018 21:51:28 -0700 Subject: Add button input support for wireless --- src/survive_vive.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/survive_vive.c') diff --git a/src/survive_vive.c b/src/survive_vive.c index 146ea01..048aad4 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -939,6 +939,14 @@ void registerButtonEvent(SurviveObject *so, buttonEvent *event) entry->eventType = BUTTON_EVENT_BUTTON_UP; } entry->buttonId = a; + if (entry->buttonId == 0) + { + // this fixes 2 issues. First, is the a button id of 0 indicates no button pressed. + // second is that the trigger shows up as button 0 coming from the wireless controller, + // but we infer it from the position on the wired controller. On the wired, we treat it + // as buttonId 24 (look further down in this function) + entry->buttonId = 24; + } incrementAndPostButtonQueue(so->ctx); entry = &(so->ctx->buttonQueue.entry[so->ctx->buttonQueue.nextWriteIndex]); } @@ -1049,32 +1057,47 @@ static void handle_watchman( SurviveObject * w, uint8_t * readdata ) if( (type & 0xf0) == 0xf0 ) { + buttonEvent bEvent; + memset(&bEvent, 0, sizeof(bEvent)); + propset |= 4; //printf( "%02x %02x %02x %02x\n", qty, type, time1, time2 ); type &= ~0x10; if( type & 0x01 ) { + qty-=1; - w->buttonmask = POP1; + bEvent.pressedButtonsValid = 1; + bEvent.pressedButtons = POP1; - printf("buttonmask is %d\n", w->buttonmask); + //printf("buttonmask is %d\n", w->buttonmask); type &= ~0x01; } if( type & 0x04 ) { qty-=1; - w->axis1 = ( POP1 ) * 128; + bEvent.triggerHighResValid = 1; + bEvent.triggerHighRes = ( POP1 ) * 128; type &= ~0x04; } if( type & 0x02 ) { qty-=4; - w->axis2 = POP2; - w->axis3 = POP2; + bEvent.touchpadHorizontalValid = 1; + bEvent.touchpadVerticalValid = 1; + + bEvent.touchpadHorizontal = POP2; + bEvent.touchpadVertical = POP2; type &= ~0x02; } + if (bEvent.pressedButtonsValid || bEvent.triggerHighResValid || bEvent.touchpadHorizontalValid) + { + registerButtonEvent(w, &bEvent); + } + + //XXX TODO: Is this correct? It looks SO WACKY type &= 0x7f; if( type == 0x68 ) doimu = 1; -- cgit v1.2.3