6155点阵插件完成。
This commit is contained in:
@ -126,7 +126,7 @@
|
|||||||
},
|
},
|
||||||
fail: err => {
|
fail: err => {
|
||||||
// console.error(`处理第${i+1}行失败:`, err);
|
// console.error(`处理第${i+1}行失败:`, err);
|
||||||
reject(err
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -83,23 +83,25 @@
|
|||||||
<text class="usrtitle fleft">人员信息登记</text>
|
<text class="usrtitle fleft">人员信息登记</text>
|
||||||
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
|
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
|
||||||
<view class="clear"></view>
|
<view class="clear"></view>
|
||||||
|
<TextToHex class="TextToHex" ref="textToHex" :txts="textLines" :bgColor="'#000000'" :color="'#FFFFFF'"
|
||||||
|
:fontSize="16" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">单位:</text>
|
<text class="lbl">单位:</text>
|
||||||
<input class="value" v-model="user.company" placeholder="请输入单位" placeholder-class="usrplace" />
|
<input class="value" v-model="textLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">姓名:</text>
|
<text class="lbl">姓名:</text>
|
||||||
<input class="value" v-model="user.name" placeholder="请输入姓名" placeholder-class="usrplace" />
|
<input class="value" v-model="textLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">职位:</text>
|
<text class="lbl">职位:</text>
|
||||||
<input class="value" v-model="user.job" placeholder="请输入职位" placeholder-class="usrplace" />
|
<input class="value" v-model="textLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
|
||||||
</view>
|
</view>
|
||||||
<view class="item">
|
<view class="item">
|
||||||
<text class="lbl">ID号:</text>
|
<text class="lbl">ID号:</text>
|
||||||
<input class="value" v-model="user.id" placeholder="请输入ID" placeholder-class="usrplace" />
|
<input class="value" v-model="textLines[3]" placeholder="请输入ID" placeholder-class="usrplace" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="proinfo lamp">
|
<view class="proinfo lamp">
|
||||||
@ -144,8 +146,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ble from '@/api/6155/BlueHelper';
|
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
|
||||||
|
import bleTool from '@/utils/BleHelper.js';
|
||||||
|
var ble = null;
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -234,18 +237,13 @@
|
|||||||
cEdit: {
|
cEdit: {
|
||||||
mode: ''
|
mode: ''
|
||||||
},
|
},
|
||||||
user: {
|
textLines: ['黄石消防支队','菜英俊','小队长','HSXF01061'],
|
||||||
company: '黄石消防支队',
|
|
||||||
name: '菜英俊',
|
|
||||||
job: '小队长',
|
|
||||||
id: 'HSXF01061'
|
|
||||||
},
|
|
||||||
device: {
|
device: {
|
||||||
deviceId: '',
|
deviceId: '',
|
||||||
writeServiceId: '',
|
writeServiceId: '',
|
||||||
wirteCharactId: '',
|
wirteCharactId: '',
|
||||||
notifyServiceid:'',
|
notifyServiceid: '',
|
||||||
notifyCharactId:''
|
notifyCharactId: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -254,21 +252,57 @@
|
|||||||
var these = this;
|
var these = this;
|
||||||
let eventChannel = this.getOpenerEventChannel();
|
let eventChannel = this.getOpenerEventChannel();
|
||||||
|
|
||||||
eventChannel.on('detailData', function(data) {
|
//eventChannel.on('detailData', function(data) {
|
||||||
|
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
data: {
|
||||||
|
deviceMac: '35:06:00:EF:46:51',
|
||||||
|
bluetoothName: 'JQZM-EF4651',
|
||||||
|
deviceName: 'JQZM-EF4651',
|
||||||
|
devicePic: '',
|
||||||
|
id: '35:06:00:EF:46:51'
|
||||||
|
}
|
||||||
|
};
|
||||||
console.log("收到父页面的参数:" + JSON.stringify(data));
|
console.log("收到父页面的参数:" + JSON.stringify(data));
|
||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.device.deviceId = device.deviceMac;
|
these.device.deviceId = device.deviceMac;
|
||||||
these.formData.name = device.bluetoothName ? device.bluetoothName : device.deviceName;
|
these.formData.name = device.bluetoothName ? device.bluetoothName : device.deviceName;
|
||||||
these.formData.img = device.devicePic;
|
these.formData.img = device.devicePic;
|
||||||
these.formData.id = device.id;
|
these.formData.id = device.id;
|
||||||
})
|
//})
|
||||||
|
|
||||||
|
ble = bleTool.getBleTool();
|
||||||
|
ble.addReceiveCallback(these.bleValueNotify);
|
||||||
|
|
||||||
|
let startLink=()=>{
|
||||||
ble.featrueValueCallback = these.bleValueNotify;
|
ble.addDeviceFound((res) => {
|
||||||
|
console.log("发现新设备,",res);
|
||||||
|
let f = res.devices.find((v) => {
|
||||||
|
return v.name == device.deviceName;
|
||||||
|
});
|
||||||
|
if (f) {
|
||||||
|
console.log("找到了目标设备,正在连接:"+f.deviceId)
|
||||||
|
these.device.deviceId = f.deviceId;
|
||||||
|
these.formData.id = f.deviceId;
|
||||||
|
ble.LinkBlue(f.deviceId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ble.StartSearch();
|
||||||
|
}
|
||||||
|
if(ble.data.LinkedList && ble.data.LinkedList.length>0){
|
||||||
|
let f=ble.data.LinkedList.find((v)=>{
|
||||||
|
return v.name==device.deviceName;
|
||||||
|
});
|
||||||
|
if(!f){
|
||||||
|
startLink();
|
||||||
|
}else{
|
||||||
|
these.device.deviceId = f.deviceId;
|
||||||
|
these.formData.id = f.deviceId;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
startLink();
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
@ -280,36 +314,38 @@
|
|||||||
console.log("these.device=" + JSON.stringify(these.device));
|
console.log("these.device=" + JSON.stringify(these.device));
|
||||||
if (these.device.deviceId) {
|
if (these.device.deviceId) {
|
||||||
if (e.from === 'backbutton') {
|
if (e.from === 'backbutton') {
|
||||||
ble.getLinkBlue((res) => {
|
|
||||||
|
|
||||||
|
let res = {
|
||||||
|
devices: ble.data.LinkedList
|
||||||
|
};
|
||||||
|
|
||||||
if (res.devices.length == 0) {
|
if (res.devices.length == 0) {
|
||||||
console.log("没有已连接的蓝牙设备")
|
console.log("没有已连接的蓝牙设备")
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
let f = res.devices.find(function(v) {
|
let f = res.devices.find(function(v) {
|
||||||
return v.deviceId == these.device.deviceId;
|
return v.deviceId == these.device.deviceId;
|
||||||
});
|
|
||||||
if (!f) {
|
|
||||||
console.log("该设备没有连接")
|
|
||||||
uni.navigateBack();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uni.showModal({
|
|
||||||
title: '提示',
|
|
||||||
content: '是否断开与设备的蓝牙连接?',
|
|
||||||
success: function(res) {
|
|
||||||
if (res.confirm) {
|
|
||||||
ble.disconnectDevice(these.device.deviceId);
|
|
||||||
|
|
||||||
}
|
|
||||||
uni.navigateBack();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
if (!f) {
|
||||||
|
console.log("该设备没有连接")
|
||||||
|
uni.navigateBack();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '是否断开与设备的蓝牙连接?',
|
||||||
|
success: function(res) {
|
||||||
|
if (res.confirm) {
|
||||||
|
ble.disconnectDevice(these.device.deviceId);
|
||||||
|
|
||||||
|
}
|
||||||
|
uni.navigateBack();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,45 +373,12 @@
|
|||||||
methods: {
|
methods: {
|
||||||
getDevice: function() {
|
getDevice: function() {
|
||||||
var these = this;
|
var these = this;
|
||||||
|
console.log("these.device=",these.device);
|
||||||
if (this.device.deviceId && this.device.writeServiceId && this.device.wirteCharactId) {
|
console.log("LinkedList=",ble.data.LinkedList.LinkedList);
|
||||||
return this.device;
|
let f = ble.data.LinkedList.find((v) => {
|
||||||
}
|
return v.deviceId == these.device.deviceId;
|
||||||
|
|
||||||
let key = "linkedDevices";
|
|
||||||
var store = uni.getStorageInfoSync();
|
|
||||||
var f = store.keys.find(function(v) {
|
|
||||||
return v == key;
|
|
||||||
});
|
});
|
||||||
// console.log("倒计时:5");
|
|
||||||
var linkedDevices = [];
|
|
||||||
if (f) {
|
|
||||||
var str = uni.getStorageSync(key);
|
|
||||||
if (str) {
|
|
||||||
linkedDevices = JSON.parse(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// console.log("倒计时:4");
|
|
||||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
|
||||||
// console.log("倒计时:3");
|
|
||||||
f = linkedDevices.find(function(v) {
|
|
||||||
if(v.deviceId == these.device.deviceId){
|
|
||||||
these.device.writeServiceId=v.writeServiceId;
|
|
||||||
these.device.wirteCharactId=v.wirteCharactId;
|
|
||||||
these.device.notifyServiceid=v.notifyServiceid;
|
|
||||||
these.device.notifyCharactId=v.notifyCharactId;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
f = null;
|
|
||||||
}
|
|
||||||
return f;
|
return f;
|
||||||
},
|
},
|
||||||
bleValueNotify: function(data) {
|
bleValueNotify: function(data) {
|
||||||
@ -408,44 +411,14 @@
|
|||||||
var processAndSendImageData = function(pixels) {
|
var processAndSendImageData = function(pixels) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 创建RGB565格式的像素数据
|
// 创建RGB565格式的像素数据
|
||||||
const rgb565Data = convertToRGB565(pixels);
|
const rgb565Data = ble.convertToRGB565(pixels);
|
||||||
|
|
||||||
// 分包发送
|
// 分包发送
|
||||||
sendImagePackets(rgb565Data).then(resolve).catch(reject);
|
sendImagePackets(rgb565Data).then(resolve).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将RGBA转换为RGB565
|
|
||||||
var convertToRGB565 = function(pixels) {
|
|
||||||
|
|
||||||
var rgbaToRgb565 = function(r, g, b, a = 255) {
|
|
||||||
// 忽略透明度(如果需要考虑透明度,请根据需求处理)
|
|
||||||
|
|
||||||
// 将8位颜色值压缩到RGB565对应的位数
|
|
||||||
const r5 = Math.round((r / 255) * 31); // 5位:0-31
|
|
||||||
const g6 = Math.round((g / 255) * 63); // 6位:0-63
|
|
||||||
const b5 = Math.round((b / 255) * 31); // 5位:0-31
|
|
||||||
|
|
||||||
// 合并为16位整数
|
|
||||||
return (r5 << 11) | (g6 << 5) | b5;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = new Uint16Array(160 * 80);
|
|
||||||
let index = 0;
|
|
||||||
console.log("pixels.length=" + pixels.length);
|
|
||||||
for (let i = 0; i < pixels.length; i += 4) {
|
|
||||||
const r = pixels[i];
|
|
||||||
const g = pixels[i + 1];
|
|
||||||
const b = pixels[i + 2];
|
|
||||||
|
|
||||||
// 转换为RGB565 (R:5bit, G:6bit, B:5bit)
|
|
||||||
const rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
|
||||||
//let rgb565=rgbaToRgb565(r,g,b);
|
|
||||||
result[index++] = rgb565;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分包发送图片数据
|
// 分包发送图片数据
|
||||||
var sendImagePackets = function(imageData) {
|
var sendImagePackets = function(imageData) {
|
||||||
@ -528,7 +501,8 @@
|
|||||||
|
|
||||||
|
|
||||||
//发送数据包
|
//发送数据包
|
||||||
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer)
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
|
||||||
|
30)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log("发送一个包完成了");
|
console.log("发送一个包完成了");
|
||||||
these.Status.Progress.curr = currentPacket;
|
these.Status.Progress.curr = currentPacket;
|
||||||
@ -716,15 +690,21 @@
|
|||||||
}
|
}
|
||||||
dataView.setUint8(5, dataValue); // 数据
|
dataView.setUint8(5, dataValue); // 数据
|
||||||
dataView.setUint16(6, '9C41');
|
dataView.setUint16(6, '9C41');
|
||||||
|
|
||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
// 发送数据
|
// 发送数据
|
||||||
ble.LinkBlue(f.deviceId, () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer);
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
});
|
if(f){
|
||||||
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
|
||||||
|
|
||||||
|
}).catch((ex) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
handleItemClick(item, index) {
|
handleItemClick(item, index) {
|
||||||
@ -748,124 +728,129 @@
|
|||||||
|
|
||||||
this.Status.Pop.showPop = false;
|
this.Status.Pop.showPop = false;
|
||||||
},
|
},
|
||||||
sendUsr: function() {
|
async sendUsr(){
|
||||||
|
|
||||||
// this.alert(JSON.stringify(this.user));
|
// this.alert(JSON.stringify(this.user));
|
||||||
//生成位图并分包发送 //暂时弹出成功提示
|
//生成位图并分包发送 //暂时弹出成功提示
|
||||||
var these = this;
|
var these = this;
|
||||||
var textLines = [
|
let f = this.getDevice();
|
||||||
this.user.company,
|
if(!f){
|
||||||
this.user.name,
|
return;
|
||||||
this.user.job,
|
}
|
||||||
this.user.id
|
var sendTxtPackge = (rgbdata, type, str) => {
|
||||||
|
|
||||||
];
|
var promise = new Promise((resolve, reject) => {
|
||||||
var sendText = function() {
|
try {
|
||||||
|
|
||||||
|
let packetSize = 120; //每包均分的数量
|
||||||
|
let mode = rgbdata.length % packetSize; //最后一包的数量
|
||||||
|
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 : 0); //总包数量
|
||||||
|
let curr = 1; //当前包序号
|
||||||
|
|
||||||
|
let sendNext = () => {
|
||||||
|
|
||||||
|
if (curr > cnt) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("正在发送" + curr + "/" + cnt)
|
||||||
|
let bufferSize = 0;
|
||||||
|
if (curr == 1) {
|
||||||
|
bufferSize = packetSize * 2 + 5;
|
||||||
|
} else if (curr == cnt) {
|
||||||
|
bufferSize = mode > 0 ? (mode * 2) : (packetSize * 2);
|
||||||
|
} else {
|
||||||
|
bufferSize = packetSize * 2;
|
||||||
|
}
|
||||||
|
|
||||||
// 总数据包数
|
let buffer = new ArrayBuffer(bufferSize);
|
||||||
const totalPackets = textLines.length;
|
let dataView = new DataView(buffer);
|
||||||
let currentPacket = 1;
|
let startIndex = (curr - 1) * packetSize;
|
||||||
|
|
||||||
|
let endIndex = Math.min(startIndex + packetSize, rgbdata.length);
|
||||||
|
if (startIndex > endIndex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let packetData = rgbdata.slice(startIndex, endIndex); //取一片数据发送
|
||||||
|
|
||||||
|
let start = 0;
|
||||||
|
if (curr == 1) {
|
||||||
|
dataView.setUint8(0, 0x70);
|
||||||
|
dataView.setUint8(1, 0x65);
|
||||||
|
dataView.setUint8(2, type);
|
||||||
|
dataView.setUint16(3, str.length, false);
|
||||||
|
start = 5;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < packetData.length; i++) {
|
||||||
|
dataView.setUint16(start + i * 2, packetData[i], false); // 大端字节序
|
||||||
|
}
|
||||||
|
|
||||||
|
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||||
|
|
||||||
|
//发送数据包
|
||||||
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
|
||||||
|
console.log("发送成功,准备发送下一包" + curr)
|
||||||
|
curr++;
|
||||||
|
setTimeout(sendNext, inteval);
|
||||||
|
}).catch(err => {
|
||||||
|
console.log("出现错误", err)
|
||||||
|
if (err.code == '10007') {
|
||||||
|
setTimeout(sendNext, inteval);
|
||||||
|
} else {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 发送单个数据包
|
|
||||||
const sendNextPacket = () => {
|
|
||||||
if (currentPacket > totalPackets) {
|
|
||||||
these.Status.Pop = {
|
|
||||||
showPop: true, //是否显示弹窗
|
|
||||||
popType: 'custom',
|
|
||||||
bgColor: '#383934bd',
|
|
||||||
borderColor: '#BBE600',
|
|
||||||
textColor: '#ffffffde',
|
|
||||||
buttonBgColor: '#BBE600',
|
|
||||||
buttonTextColor: '#232323DE',
|
|
||||||
iconUrl: '/static/images/6155/DeviceDetail/sendSucc.png',
|
|
||||||
message: '人员信息发送成功',
|
|
||||||
buttonText: '确定',
|
|
||||||
clickEvt: 'SendUsr',
|
|
||||||
visiblePrompt: false,
|
|
||||||
promptTitle: '',
|
|
||||||
modelValue: '',
|
|
||||||
visibleClose: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
sendNext();
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("出现异常", ex)
|
||||||
|
reject(ex);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 获取当前行文字
|
return promise;
|
||||||
const text = textLines[currentPacket - 1] || '';
|
|
||||||
let arr = ""; // gbk.encode(text)
|
|
||||||
let gbkData = ""; //gbk.arr2hex(arr);
|
|
||||||
|
|
||||||
console.log(JSON.stringify(gbkData));
|
|
||||||
// 构建数据包
|
|
||||||
const bufferSize = 5 + text.length * 2; // 头部4字节 + 数据部分
|
|
||||||
const buffer = new ArrayBuffer(bufferSize);
|
|
||||||
const dataView = new DataView(buffer);
|
|
||||||
|
|
||||||
// 填充头部
|
|
||||||
dataView.setUint8(0, 0x55); // 帧头
|
|
||||||
dataView.setUint8(1, 0x03); // 帧类型:文字
|
|
||||||
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
|
|
||||||
dataView.setUint16(3, (text.length * 2).toString(16)); // 数据长度
|
|
||||||
console.log("gbkData.length=" + gbkData.length)
|
|
||||||
// 填充数据
|
|
||||||
for (let i = 1; i <= text.length * 2; i++) {
|
|
||||||
const highNibble = gbkData[i * 2 - 2]; // 高4位
|
|
||||||
const lowNibble = gbkData[i * 2 - 1]; // 低4位(如果是奇数长度,补0)
|
|
||||||
console.log("i=" + i + "," + highNibble + lowNibble)
|
|
||||||
// 组合高低位并转换为字节值
|
|
||||||
const byteValue = parseInt(highNibble + lowNibble, 16);
|
|
||||||
dataView.setUint8(5 + i - 1, byteValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
console.log("dataView.length=" + dataView.byteLength)
|
|
||||||
|
|
||||||
let f = these.getDevice();
|
|
||||||
if (f) {
|
|
||||||
// 发送数据包
|
|
||||||
ble.LinkBlue(f.deviceId, () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
ble.sendDataNew(f.deviceId, f.writeServiceId, f
|
|
||||||
.wirteCharactId, buffer).then(() => {
|
|
||||||
// 更新进度
|
|
||||||
console.log(
|
|
||||||
`发送文字数据包 ${currentPacket}/${totalPackets}: ${text}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// 发送下一个包
|
|
||||||
currentPacket++;
|
|
||||||
setTimeout(sendNextPacket, 100);
|
|
||||||
}).catch(err => {
|
|
||||||
// this.isSendingText = false;
|
|
||||||
uni.showToast({
|
|
||||||
title: '文字发送失败',
|
|
||||||
icon: 'none'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// }).catch(err => {
|
|
||||||
// this.isSendingText = false;
|
|
||||||
// console.log(`文字编码失败: ${err}`);
|
|
||||||
// uni.showToast({
|
|
||||||
// title: '编码失败',
|
|
||||||
// icon: 'none'
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
};
|
|
||||||
|
|
||||||
// 开始发送第一个包
|
|
||||||
sendNextPacket();
|
|
||||||
}
|
}
|
||||||
sendText();
|
var result = await this.$refs.textToHex.drawAndGetPixels();
|
||||||
|
|
||||||
|
|
||||||
|
let h3dic = [0x06, 0x07, 0x08];
|
||||||
|
let pros = [];
|
||||||
|
let flag=true;
|
||||||
|
for (var i = 0; i < result.length; i++) {
|
||||||
|
|
||||||
|
let str = this.textLines[i];
|
||||||
|
|
||||||
|
if (str.length > 0) {
|
||||||
|
|
||||||
|
let width = str.length * 16;
|
||||||
|
var rgb = ble.convertToRGB565(result[i].pixelData, width, 16);
|
||||||
|
try{
|
||||||
|
await sendTxtPackge(rgb, h3dic[i], str);
|
||||||
|
}catch(ex){
|
||||||
|
flag=false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if(flag){
|
||||||
|
uni.showModal({
|
||||||
|
title:"提示",
|
||||||
|
content:"发送成功"
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}else{
|
||||||
|
uni.showModal({
|
||||||
|
title:"错误",
|
||||||
|
content:"出现了异常发送失败"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
ack: function() {
|
ack: function() {
|
||||||
@ -898,12 +883,9 @@
|
|||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
if (f) {
|
if (f) {
|
||||||
// 发送数据
|
// 发送数据
|
||||||
ble.LinkBlue(f.deviceId, () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer);
|
|
||||||
}, 1000)
|
|
||||||
|
|
||||||
});
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -943,11 +925,9 @@
|
|||||||
let f = this.getDevice();
|
let f = this.getDevice();
|
||||||
if (f) {
|
if (f) {
|
||||||
// 发送数据
|
// 发送数据
|
||||||
ble.LinkBlue(f.deviceId, () => {
|
|
||||||
setTimeout(() => {
|
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30);
|
||||||
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer);
|
|
||||||
}, 100)
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1410,4 +1390,11 @@
|
|||||||
width: 70rpx;
|
width: 70rpx;
|
||||||
height: 70rpx;
|
height: 70rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.TextToHex {
|
||||||
|
position: fixed;
|
||||||
|
top: -99999rpx;
|
||||||
|
left: -99999rpx;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
@ -346,13 +346,17 @@
|
|||||||
console.log("these.device=" + JSON.stringify(these.device));
|
console.log("these.device=" + JSON.stringify(these.device));
|
||||||
if (these.device.deviceId) {
|
if (these.device.deviceId) {
|
||||||
if (e.from === 'backbutton') {
|
if (e.from === 'backbutton') {
|
||||||
these.getLinkBlue((res) => {
|
|
||||||
|
|
||||||
|
|
||||||
|
let res = {
|
||||||
|
devices: ble.data.LinkedList
|
||||||
|
};
|
||||||
|
|
||||||
if (res.devices.length == 0) {
|
if (res.devices.length == 0) {
|
||||||
console.log("没有已连接的蓝牙设备")
|
console.log("没有已连接的蓝牙设备")
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
let f = res.devices.find(function(v) {
|
let f = res.devices.find(function(v) {
|
||||||
return v.deviceId == these.device.deviceId;
|
return v.deviceId == these.device.deviceId;
|
||||||
@ -360,22 +364,22 @@
|
|||||||
if (!f) {
|
if (!f) {
|
||||||
console.log("该设备没有连接")
|
console.log("该设备没有连接")
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
content: '是否断开与设备的蓝牙连接?',
|
content: '是否断开与设备的蓝牙连接?',
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
ble.disconnectDevice(these.device.deviceId);
|
ble.disconnectDevice(these.device.deviceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -646,44 +650,14 @@
|
|||||||
var processAndSendImageData = function(pixels) {
|
var processAndSendImageData = function(pixels) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 创建RGB565格式的像素数据
|
// 创建RGB565格式的像素数据
|
||||||
const rgb565Data = convertToRGB565(pixels);
|
const rgb565Data = ble.convertToRGB565(pixels);
|
||||||
|
|
||||||
// 分包发送
|
// 分包发送
|
||||||
sendImagePackets(rgb565Data).then(resolve).catch(reject);
|
sendImagePackets(rgb565Data).then(resolve).catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将RGBA转换为RGB565
|
|
||||||
var convertToRGB565 = function(pixels) {
|
|
||||||
|
|
||||||
var rgbaToRgb565 = function(r, g, b, a = 255) {
|
|
||||||
// 忽略透明度(如果需要考虑透明度,请根据需求处理)
|
|
||||||
|
|
||||||
// 将8位颜色值压缩到RGB565对应的位数
|
|
||||||
const r5 = Math.round((r / 255) * 31); // 5位:0-31
|
|
||||||
const g6 = Math.round((g / 255) * 63); // 6位:0-63
|
|
||||||
const b5 = Math.round((b / 255) * 31); // 5位:0-31
|
|
||||||
|
|
||||||
// 合并为16位整数
|
|
||||||
return (r5 << 11) | (g6 << 5) | b5;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = new Uint16Array(160 * 80);
|
|
||||||
let index = 0;
|
|
||||||
console.log("pixels.length=" + pixels.length);
|
|
||||||
for (let i = 0; i < pixels.length; i += 4) {
|
|
||||||
const r = pixels[i];
|
|
||||||
const g = pixels[i + 1];
|
|
||||||
const b = pixels[i + 2];
|
|
||||||
|
|
||||||
// 转换为RGB565 (R:5bit, G:6bit, B:5bit)
|
|
||||||
const rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
|
||||||
//let rgb565=rgbaToRgb565(r,g,b);
|
|
||||||
result[index++] = rgb565;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分包发送图片数据
|
// 分包发送图片数据
|
||||||
var sendImagePackets = function(imageData) {
|
var sendImagePackets = function(imageData) {
|
||||||
|
@ -146,8 +146,21 @@ class BleHelper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//移除发现新设备的回调
|
||||||
|
removeDeviceFound() {
|
||||||
|
let key = this.getCurrentPagePath();
|
||||||
|
if (key) {
|
||||||
|
let f = this.cfg.onDeviceFound.findIndex((v) => {
|
||||||
|
return v.key == key;
|
||||||
|
});
|
||||||
|
if (f > -1) {
|
||||||
|
this.cfg.onDeviceFound.splice(f, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//设置接收到数据的回调
|
//添加接收到数据的回调
|
||||||
addReceiveCallback(callback) {
|
addReceiveCallback(callback) {
|
||||||
let key = this.getCurrentPagePath();
|
let key = this.getCurrentPagePath();
|
||||||
if (key) {
|
if (key) {
|
||||||
@ -165,18 +178,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置发现新设备的回调
|
|
||||||
removeDeviceFound() {
|
|
||||||
let key = this.getCurrentPagePath();
|
|
||||||
if (key) {
|
|
||||||
let f = this.cfg.onDeviceFound.findIndex((v) => {
|
|
||||||
return v.key == key;
|
|
||||||
});
|
|
||||||
if (f > -1) {
|
|
||||||
this.cfg.onDeviceFound.splice(f, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//设置接收到数据的回调
|
//设置接收到数据的回调
|
||||||
removeReceiveCallback() {
|
removeReceiveCallback() {
|
||||||
@ -192,6 +194,8 @@ class BleHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getError(ex) {
|
getError(ex) {
|
||||||
let code = ex.code;
|
let code = ex.code;
|
||||||
@ -939,7 +943,8 @@ class BleHelper {
|
|||||||
////console.log("无已连接设备");
|
////console.log("无已连接设备");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//向蓝牙设备发送数据,如果没连接将自动连接后再发
|
||||||
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms) {
|
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms) {
|
||||||
|
|
||||||
console.log("deviceid=" + deviceid + ",writeServiceId=" + writeServiceId + ",wirteCharactId=" +
|
console.log("deviceid=" + deviceid + ",writeServiceId=" + writeServiceId + ",wirteCharactId=" +
|
||||||
@ -1051,7 +1056,24 @@ class BleHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//将点阵数据转换成RGB565
|
||||||
|
convertToRGB565(pixels) {
|
||||||
|
const result = new Uint16Array(pixels.length/4);
|
||||||
|
let index = 0;
|
||||||
|
console.log("pixels.length=" + pixels.length);
|
||||||
|
for (let i = 0; i < pixels.length; i += 4) {
|
||||||
|
const r = pixels[i];
|
||||||
|
const g = pixels[i + 1];
|
||||||
|
const b = pixels[i + 2];
|
||||||
|
|
||||||
|
// 转换为RGB565 (R:5bit, G:6bit, B:5bit)
|
||||||
|
const rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||||
|
|
||||||
|
result[index++] = rgb565;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let instance = null;
|
let instance = null;
|
||||||
|
Reference in New Issue
Block a user