xinput - Any way to block while reading an XBox 360 controller other than HID API? -
i'm trying read xbox 360 controller without polling it. (to precise, i'm using logitech f310, windows 10 pc sees xbox 360 controller.) i've written rather nasty hid code uses overlapping i/o block in thread on 2 events, 1 indicates there report ready read hid device, other indicating ui thread has requested hid thread exit. works fine, hid driver behaves differently xinput does. in particular, consolidates 2 triggers single value, passing difference (on curious claim games expect hid values 0x80 when player's finger off control). xinput treats them 2 distinct values, big improvement. also, xinput reports hat switches 4 bits, means can ten states out of it: unpressed, n, ne, e, se, s, sw, w, nw, , all-down (that last might hard use successfully, @ least it's there if want it; i've been using exit polling loop).
the downside, me, of xinput there appears no way block on read request until controller changes 1 of values or buttons. hid device, readfile call block (more exactly, waitformultipleevents blocks until there data available). xinput seems anticipate polling. game naturally written poll controller updated game state (maybe once each new video frame displayed, example), makes sense. if want use controller other purpose (i'm working on theatrical application), might want purely asynchronous system hid api supplies. but, again, hid api combines 2 value triggers.
now, when read device xinput, not state of controls, packet number. msdn says packet number changes when state of control changes. way, if consecutive packet numbers same, don't have bother processing after first one, because know controller state hasn't changed. still polling which, me, vulgar.
what intrigues me, however, when put big delay in between polls (100ms) can see packet numbers go more 1 when value controls (the triggers or sticks) being moved. this, think, suggests device sending packets without waiting polled, , getting recent packet each time poll. if case, seems ought able block until packet sent, , react when happens, rather having poll @ all. can't find indication option. because can block hid api, don't want give without trying (including asking advice here).
short of writing own driver controller (which i'm not sure option without proprietary documentation), know how can use overlapping i/o (or other blocking method) read xbox 360 controller way xinput does, triggers separate values, , hat 4 buttons?
below code wrote reads controller , shows packet numbers can jump more 1 between reads:
#include <windows.h> #include <xinput.h> #include <stdio.h> #define max_controllers 4 int main() { dword userindex; xinput_state xs; xinput_vibration v; xinputenable(true); // 1 we? (userindex = 0; userindex < xuser_max_count; ++userindex) if (xinputgetstate(userindex, &xs) == error_success) break; if (userindex == xuser_max_count) { printf("couldn't find xbox 360 controller.\n"); getchar(); return -1; } printf("using controller #%1d.\n", userindex); while (true) { dword res = xinputgetstate(userindex, &xs); printf("%5d %6d: %3d %3d %3d %3d %3d %3d 0x%04x\n", res, xs.dwpacketnumber, xs.gamepad.blefttrigger & 0xff, xs.gamepad.brighttrigger & 0xff, xs.gamepad.sthumblx & 0xff, xs.gamepad.sthumbly & 0xff, xs.gamepad.sthumbrx & 0xff, xs.gamepad.sthumbry & 0xff, xs.gamepad.wbuttons); if (xs.gamepad.wbuttons == 0x000f) // mash down hat break; sleep(100); } getchar(); return 0; }
please note directinput isn't help, combines triggers 1 value.
thanks!
not sure there advantage this, write thread polls on regular interval , sets semaphore (or other signal) when state has changed. main thread block waiting signal polling thread. potentially there might not advantage system because on controllers values of thumbsticks change ever frame whether move them or not. (noise) of course ignore small changes , signal semaphore when large change occurred.
Comments
Post a Comment