c++ - Issues With Creating SDL2 Joystick Bindings With Node FFI -


i've been trying write object use joystick class sdl2 library nodejs using ffi module, keep running problems. appears work expected 50% of time, @ other times, program claims it's unable find connected joystick (using sdl_geterror()).

here's sample of code:

// constructor... function joystick(deviceid){         this.joystickpointer = ref.reftype('pointer');      this.sdl = ffi.library("sdl2.dll", {         "sdl_init": ["uint32", ["string"]],     "sdl_quit": ["void", []],     "sdl_joystickopen": ["pointer", ["int"]],     "sdl_numjoysticks": ["int", []],     "sdl_joystickname": ["string", [this.joystickpointer]],     "sdl_joysticknumbuttons": ["int", [this.joystickpointer]],     "sdl_joystickgetbutton": ["uint8", [this.joystickpointer, "int"]],     "sdl_joysticknumaxes": ["int", [this.joystickpointer]],     "sdl_joystickgetaxis": ["int16", [this.joystickpointer, "int"]],     "sdl_joystickgetattached": ["bool", [this.joystickpointer]],     "sdl_joystickclose": ["void", [this.joystickpointer]],     "sdl_joystickupdate": ["void", []],     "sdl_geterror": ["string", []]     });          // setup     this.deviceid = deviceid || 0;     this.sdl.sdl_init("sdl_init_joystick");     this.joystickobject = this.sdl.sdl_joystickopen(this.deviceid);          // poll joystick         this.devicecount = this.sdl.sdl_numjoysticks();     this.buttons = this.sdl.sdl_joysticknumbuttons(this.joystickobject);     this.name = this.sdl.sdl_joystickname(this.joystickobject);          // cleanup         this.sdl.sdl_joystickclose(this.joystickobject);         this.sdl.sdl_quit();          return false; }  var testjoystick = new joystick(0); console.log(testjoystick.name); 

when fails, sdl_geterror() gives me following error message:

"joystick hasn't been opened yet"  

any ideas?

i suspect there many issues in code above make work expected. in end, came different solution...

i found static, lower level input library - http://forums.tigsource.com/index.php?topic=10675.0 - wrote skeletal library on top of it, linked it, applied it...

it works great , much, lighter sdl...

will have put on git or bitbucket within next few days if have time.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -