This commit is contained in:
aihe 2024-05-12 02:21:02 +08:00
parent bc6d96fd0f
commit d1098f2659

View File

@ -24,24 +24,31 @@
export function sendDataToDevice(options) {
let byteLength = options.value.byteLength;
//这里默认一次20个字发送
// 这里默认一次20个字发送
const speed = options.onceByleLength || 20;
console.log('byteLength====', byteLength)
if (byteLength > 0) {
console.log('speed====', speed)
console.log('value====', options.value)
uni.writeBLECharacteristicValue({
...options,
// writeType:"writeNoResponse",
value: options.value.slice(0, byteLength > speed ? speed : byteLength),
success: function (res) {
if (byteLength > speed) {
sendDataToDevice({
...options,
value: options.value.slice(speed, byteLength),
});
} else {
options.lasterSuccess && options.lasterSuccess();
}
// 【writeBLECharacteristicValue】安卓存在频繁调用失败的情况,下次调用前必须加上延迟
setTimeout(()=> {
if (byteLength > speed) {
sendDataToDevice({
...options,
value: options.value.slice(speed, byteLength),
});
} else {
options.lasterSuccess && options.lasterSuccess();
}
},10)
},
fail: function (res) {
console.log('writeBLECharacteristicValue:fail====', res)
options.onError && options.onError(res);
},
});
@ -116,7 +123,6 @@ function grayPixle(pix) {
}
*/
export function overwriteImageData(data) {
console.log("overwriteImageData data====", data)
let sendWidth = data.width,
sendHeight = data.height;
const threshold = data.threshold || 180;
@ -174,13 +180,16 @@ export function overwriteImageData(data) {
*/
export function sendDataToPrint(options, allUint8Array) {
const allLenth = allUint8Array.length;
console.log("====allLenth===", allLenth)
console.log("sendDataToPrint:allLenth=======", allLenth)
console.log("sendDataToPrint:allUint8Array-len=======", allUint8Array.length)
const writeArrayCopyer = allUint8Array.slice(0);
const print = (options, writeArray) => {
console.log("===writeArray.length===", writeArray.length)
if (writeArray.length) {
let curBuffer = writeArray.shift().buffer
sendDataToDevice({
...options,
value: writeArray.shift().buffer,
value: curBuffer,
lasterSuccess: () => {
options.onProgress &&
options.onProgress(Math.floor(((allLenth - writeArray.length) / allLenth) * 100));
@ -246,8 +255,6 @@ export function getImageCommandArray(opt = {}, imageInfo = {}) {
}
*/
export function getPrintImageWriteArray(opt = {}, imageInfo = {}) {
console.log('getPrintImageWriteArray:opt======', opt)
console.log('getPrintImageWriteArray:imageInfo=====', imageInfo)
const lineByLine = typeof opt.lineByLine !== 'boolean' ? true : opt.lineByLine;
const width = imageInfo.width;
let arr = imageInfo.array;