1
0
forked from dyf/APP

6155点阵插件完成。

This commit is contained in:
liub
2025-08-07 08:48:02 +08:00
parent b3c0b74628
commit ca844723fa
4 changed files with 270 additions and 287 deletions

View File

@ -346,13 +346,17 @@
console.log("these.device=" + JSON.stringify(these.device));
if (these.device.deviceId) {
if (e.from === 'backbutton') {
these.getLinkBlue((res) => {
let res = {
devices: ble.data.LinkedList
};
if (res.devices.length == 0) {
console.log("没有已连接的蓝牙设备")
uni.navigateBack();
return;
return false;
}
let f = res.devices.find(function(v) {
return v.deviceId == these.device.deviceId;
@ -360,22 +364,22 @@
if (!f) {
console.log("该设备没有连接")
uni.navigateBack();
return;
return false;
}
uni.showModal({
title: '提示',
content: '是否断开与设备的蓝牙连接?',
success: function(res) {
if (res.confirm) {
ble.disconnectDevice(these.device.deviceId);
}
uni.navigateBack();
}
});
});
return true;
}
}
@ -646,44 +650,14 @@
var processAndSendImageData = function(pixels) {
return new Promise((resolve, reject) => {
// 创建RGB565格式的像素数据
const rgb565Data = convertToRGB565(pixels);
const rgb565Data = ble.convertToRGB565(pixels);
// 分包发送
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) {