javascript - cant get any input data from hid device with chrome api -


i making small app take input data usb device chrome packaged app. idea when press button on usb device take incoming traffic, analyze , react depending on input. tried several devices , techniques online tutorials/codes , met many problems, after solving them started use sony playstation 3 pads. device connected via hid that's can accomplish. pressing buttons doesnt make input incoming , far have no idea reason of that. stackoverflow, google manuals , internet doesnt seem have answers on that. here code:

manifest.json:

{       "manifest_version": 2,    "name": "hid input analyzer",   "version": "1.0",    "app": {     "background": {       "scripts": [ "background.js" ],       "persistent": true     }   },    "permissions": ["hid", {       "usbdevices": [     { "vendorid": 1356 , "productid": 616 }       ]     }   ] } 

background.js

chrome.app.runtime.onlaunched.addlistener(function() {   chrome.app.window.create('mychromeapp.html', {     singleton: true,     id: "input analyzer"   }); }); 

mychromeapp.html

<!doctype html> <html>   <head>     <title>hid input analyzer</title>   </head>   <body>         <input type="text" id="mytext" />     <script src="mychromeapp.js"></script>   </body> </html> 

mychromeapp.js

var my_hid_vendor_id  = 0x09da; // 4660 in hexadecimal! var my_hid_product_id = 0x8090; var device_info = {"vendorid": my_hid_vendor_id, "productid": my_hid_product_id };  var connectionid = null;  function arraybuffertostring(array) {   return string.fromcharcode.apply(null, new uint8array(array)); }  var mydevicepoll = function() {   var size = 64;     var = 0; if (chrome.runtime.lasterror) {console.log(chrome.runtime.lasterror);}     chrome.hid.receive(connectionid, function(data) {         console.log("::" + connectionid);       if (data != null) {             // convert byte ascii follow format of our device             mytext.value = arraybuffertostring(data);             console.log('data: ' + mytext.value);       }     settimeout(mydevicepoll, 0);     }); }      function initializehid(pollhid) { // brackets empty purpose because permissions given in manifest.json     chrome.hid.getdevices({}, function(devices) {         if (!devices || !devices.length) {           console.log('device not found');           if (chrome.runtime.lasterror) {console.log(chrome.runtime.lasterror);}           return;         }         console.log('found device deviceid: ' + devices[0].deviceid);         myhiddevice = devices[0].deviceid;          // connect hid device         chrome.hid.connect(myhiddevice, function(connection) {             console.log('connected hid device connectionid: ' + connection.connectionid);           connectionid = connection.connectionid;              // poll usb hid interrupt pipe             pollhid();         });     }); }  initializehid(mydevicepoll);  console.log("trying connect hid usb ...");   var mytext = document.getelementbyid("mytext"); mytext.value = "ready"; 

console log looks this:

trying connect hid usb ...

found device deviceid: 23

connected hid device connectionid: 31

after analzying code (especially last file) guess chrome.hid.receive function doesnt data device dont know why. unfortunatelly manuals of google made poor , lack of examples makes hard code. hope can me solution - sitting since 3 days:(

kalreg.

your callback function in receive missing parameter. check out in chrome.hid page , notice necessary reportid parameter along data. worked me, after fixing that. problem, however, getting new data every new poll. happens if connect again, if connected. problem mac , ubuntu. in windows, mine works perfectly.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -