Skip to content

Instantly share code, notes, and snippets.

@Vzor-
Created May 1, 2020 21:37
Show Gist options
  • Save Vzor-/5ea13e104f91ad80cb336099edd8c277 to your computer and use it in GitHub Desktop.
Save Vzor-/5ea13e104f91ad80cb336099edd8c277 to your computer and use it in GitHub Desktop.
function sendHidData() {
printData = "abcdefghijklmnopqrstuvwhyz\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var deviceInfo = {
vendorId: $("#hidVendor").val(),
productId: $("#hidProduct").val(),
usagePage: $("#hidUsagePage").val(),
serial: $("#hidSerial").val(),
data: "",
endpoint: $("#hidReport").val()
};
createDataChain(qz.hid.sendData, deviceInfo, printData, 32).catch(displayError);
}
function createDataChain(targetFunction, deviceInfo, data, chunkLength) {
var chain = Promise.resolve();
for (var i = 0; i < data.length; i += chunkLength) {
//copy object
let newInfo = {
vendorId: deviceInfo.vendorId,
productId: deviceInfo.productId,
usagePage: deviceInfo.usagePage,
serial: deviceInfo.serial,
data: "",
endpoint: deviceInfo.endpoint
};
newInfo.data = data.substring(i, Math.min(i + chunkLength, data.length));
console.log(newInfo.data);
chain = chain.then(()=>targetFunction(newInfo));
}
return chain;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment