Created
May 1, 2020 21:37
-
-
Save Vzor-/5ea13e104f91ad80cb336099edd8c277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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