Skip to content

Instantly share code, notes, and snippets.

@ajsb85
Created May 22, 2015 05:03
Show Gist options
  • Select an option

  • Save ajsb85/36b675f60e21aeb1d38d to your computer and use it in GitHub Desktop.

Select an option

Save ajsb85/36b675f60e21aeb1d38d to your computer and use it in GitHub Desktop.
function usbhid(vendor_id, product_id) {
this.product_id = product_id;
this.vendor_id = vendor_id;
this.buffer_1 = new Object();
this.buffer_2 = new Object();
this.xpcom = Components.classes["@firechip.info/hidapi;1"].createInstance().QueryInterface(Components.interfaces.nsIHid);
this.manufacturer_string = function() {
alert(this.xpcom.manufacturer_string);
}
this.product_string = function() {
alert(this.xpcom.product_string);
}
this.getVendor_id = function() {
this.vendor_id = this.xpcom.vendor_id.toString(16);
while(vendor_id.length < 4) this.vendor_id = "0" + this.vendor_id;
this.vendor_id = "0x" + this.vendor_id.toUpperCase();
alert(this.vendor_id);
}
this.getProduct_id = function() {
this.product_id = this.xpcom.product_id.toString(16);
while(product_id.length < 4) product_id = "0" + product_id;
product_id = "0x" + product_id.toUpperCase();
alert(product_id);
}
this.hid_write = function(buffer_1, buffer_2) {
var res = this.xpcom.hid_write(buffer_1, buffer_2);
alert(res);
}
this.hid_read = function() {
var res = this.xpcom.hid_read(this.buffer_1,this.buffer_2);
alert(res);
alert(this.buffer_1.value);
alert(this.buffer_2.value);
}
}
usb = new usbhid("0x4d8", "0x3f");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment