73acf7e66ac578d727a5ed5f33c8affa5f22171e..5b125d5dfcb81014ca20d13e3dfd00b5ba3d0542
3 days ago lefengyang
console.log
5b125d diff | tree
3 days ago lefengyang
图片转点阵图
a775b1 diff | tree
3 days ago lefengyang
发送优化
a9c835 diff | tree
3 days ago lefengyang
发送前清除
b02060 diff | tree
3 days ago lefengyang
fix
317203 diff | tree
3 days ago lefengyang
取消使用预制动画
352a1d diff | tree
3 days ago lefengyang
多帧移动
ae667d diff | tree
3 days ago lefengyang
错别字
1e99f6 diff | tree
1 files renamed
2 files modified
1 files deleted
359 ■■■■■ changed files
docs/todo.md 4 ●●●● patch | view | raw | blame | history
docs/接口列表.xlsx patch | view | raw | blame | history
ledApp/pages/addTemplate/addTemplate.vue 217 ●●●●● patch | view | raw | blame | history
ledApp/pages/index/index.vue 138 ●●●● patch | view | raw | blame | history
docs/todo.md
File was deleted
docs/接口列表.xlsx
Binary files differ
ledApp/pages/addTemplate/addTemplate.vue
@@ -39,6 +39,11 @@
                    <uv-radio-group v-model="selectedPreset" placement="column" @change="changePreset" labelSize="26rpx">
                        <uv-radio
                            class="spec_radio"
                            label="无"
                            name="__none__">
                        </uv-radio>
                        <uv-radio
                            class="spec_radio"
                            v-for="(item, index) in presetList"
                            :key="index"
                            :label="'预制动画:'+item.name+'('+item.fpsTotal+'帧)'"
@@ -145,20 +150,22 @@
                    <uv-icon name="arrow-leftward" color="#333" size="30"></uv-icon>
                </view>
                <!-- 主操作按钮(收回/操作) - 移动模式下隐藏 -->
                <view class="controls" style="left: 30rpx;" v-if="!showMoveControls">
                <view class="controls" style="left: 30rpx;" v-if="!showMoveControls && !showMultiMoveControls">
                    <uv-button type="success" :plain="true" :text="showControls ? '收回' : '操作'" @click="toggleControls"></uv-button>
                </view>
                <!-- 主操作按钮组:颜色、移动、文字、清除、保存 -->
                <view class="controls" v-if="showControls && !showMoveControls">
                <view class="controls" v-if="showControls && !showMoveControls && !showMultiMoveControls">
                    <uv-button type="primary" :plain="true" text="颜色" @click="changeColor()"></uv-button>
                    <uv-button type="primary" :plain="true" text="移动" @click="enterMoveMode()"></uv-button>
                    <uv-button type="primary" :plain="true" text="单帧移动" @click="enterMoveMode()"></uv-button>
                    <uv-button type="primary" :plain="true" text="多帧移动" @click="enterMultiMoveMode()"></uv-button>
                    <uv-button type="primary" :plain="true" text="图片上传" @click="chooseImage()"></uv-button>
                    <uv-button type="primary" :plain="true" text="文字" @click="addText()"></uv-button>
                    <uv-button type="primary" :plain="true" text="清除" @click="clear()"></uv-button>
                    <uv-button type="primary" :plain="true" text="保存" @click="clickSaveData"></uv-button>
                </view>
                <!-- 移动模式按钮组:返回、左移、上移、下移、右移、180度旋转、左右镜像翻转、上下镜像翻转 -->
                <!-- 单帧移动按钮组:返回、左移、上移、下移、右移、180度旋转、左右镜像翻转、上下镜像翻转 -->
                <view class="controls" style="left: 30rpx;" v-if="showMoveControls">
                    <uv-button type="primary" :plain="true" text="返回" @click="exitMoveMode()"></uv-button>
                </view>
@@ -168,8 +175,22 @@
                    <uv-button type="primary" :plain="true" text="下移" @click="shiftDown()"></uv-button>
                    <uv-button type="primary" :plain="true" text="右移" @click="shiftRight()"></uv-button>
                    <uv-button type="primary" :plain="true" text="180°旋转" @click="rotate180()"></uv-button>
                    <uv-button type="primary" :plain="true" text="左右景象" @click="flipHorizontal()"></uv-button>
                    <uv-button type="primary" :plain="true" text="上下景象" @click="flipVertical()"></uv-button>
                    <uv-button type="primary" :plain="true" text="左右镜像" @click="flipHorizontal()"></uv-button>
                    <uv-button type="primary" :plain="true" text="上下镜像" @click="flipVertical()"></uv-button>
                </view>
                <!-- 多帧移动按钮组:操作对所有帧生效 -->
                <view class="controls" style="left: 30rpx;" v-if="showMultiMoveControls">
                    <uv-button type="primary" :plain="true" text="返回" @click="exitMultiMoveMode()"></uv-button>
                </view>
                <view class="controls move_controls" v-if="showMultiMoveControls">
                    <uv-button type="primary" :plain="true" text="左移" @click="multiShiftLeft()"></uv-button>
                    <uv-button type="primary" :plain="true" text="上移" @click="multiShiftUp()"></uv-button>
                    <uv-button type="primary" :plain="true" text="下移" @click="multiShiftDown()"></uv-button>
                    <uv-button type="primary" :plain="true" text="右移" @click="multiShiftRight()"></uv-button>
                    <uv-button type="primary" :plain="true" text="180°旋转" @click="multiRotate180()"></uv-button>
                    <uv-button type="primary" :plain="true" text="左右镜像" @click="multiFlipHorizontal()"></uv-button>
                    <uv-button type="primary" :plain="true" text="上下镜像" @click="multiFlipVertical()"></uv-button>
                </view>
                
                <!-- 文字生成图形 -->
@@ -342,7 +363,8 @@
                previewWidth: 24,
                previewHeight: 12,
                showControls: false,
            showMoveControls: false, // 移动模式按钮组开关
        showMoveControls: false, // 单帧移动模式按钮组开关
        showMultiMoveControls: false, // 多帧移动模式按钮组开关
            scrollLeft: 0,
                textType: 'overwrite',
                tempText: '',
@@ -402,6 +424,16 @@
                })
            },
            changePreset(val) {
                console.log('changePreset', val)
                // 选择"无":将动画帧复原为空白(保留当前屏幕规格/动画方式/帧数/速度)
                if (val === '__none__') {
                    this.fpsList = []
                    this.total = 1
                    this.fpsData = []
                    this.pixelData = []
                    this.gridRect = null
                    return
                }
                const preset = this.presetList.find(item => item.name === val)
                if (preset) {
                    this.specVal = preset.screen
@@ -804,6 +836,7 @@
            // 进入移动模式:隐藏主按钮组,显示移动按钮组
            enterMoveMode() {
                this.showMoveControls = true
                this.showMultiMoveControls = false
                this.showControls = false
            },
            // 退出移动模式:恢复主按钮组
@@ -811,6 +844,69 @@
                this.showMoveControls = false
                this.showControls = true
            },
            // 进入多帧移动模式:隐藏主按钮组,显示多帧移动按钮组
            enterMultiMoveMode() {
                this.showMultiMoveControls = true
                this.showMoveControls = false
                this.showControls = false
            },
            // 退出多帧移动模式:恢复主按钮组
            exitMultiMoveMode() {
                this.showMultiMoveControls = false
                this.showControls = true
            },
            // 对所有已编辑帧执行同一种单帧变换
            // action: 单帧变换方法名(shiftLeft/shiftUp/shiftDown/shiftRight/rotate180/flipHorizontal/flipVertical)
            applyTransformToAllFrames(action) {
                const currentIndex = this.fpsIndex
                // 以编辑区当前显示的数据(可能包含未保存的修改)作为当前帧的数据源
                let currentData = this.pixelData ? this.pixelData.slice() : this.pixelData
                for (let i = 0; i < this.fpsList.length; i++) {
                    if (i === currentIndex) continue
                    const frame = this.fpsList[i]
                    if (frame === null || frame === undefined) continue
                    // 复用单帧变换逻辑:临时把该帧作为编辑数据执行变换后写回
                    this.pixelData = frame.slice()
                    this[action]()
                    this.$set(this.fpsList, i, this.pixelData.slice())
                }
                // 对当前正在编辑的帧执行相同变换,刷新画布显示
                this.pixelData = currentData.slice()
                this[action]()
                // 当前帧此前已保存过则同步写回,保证所有帧数据一致;未编辑过的帧(null)仍由"保存"按钮写入
                const stored = this.fpsList[currentIndex]
                if (stored !== null && stored !== undefined) {
                    this.$set(this.fpsList, currentIndex, this.pixelData.slice())
                }
            },
            // 多帧移动:所有帧同时左移
            multiShiftLeft() {
                this.applyTransformToAllFrames('shiftLeft')
            },
            // 多帧移动:所有帧同时上移
            multiShiftUp() {
                this.applyTransformToAllFrames('shiftUp')
            },
            // 多帧移动:所有帧同时下移
            multiShiftDown() {
                this.applyTransformToAllFrames('shiftDown')
            },
            // 多帧移动:所有帧同时右移
            multiShiftRight() {
                this.applyTransformToAllFrames('shiftRight')
            },
            // 多帧移动:所有帧同时180度旋转
            multiRotate180() {
                this.applyTransformToAllFrames('rotate180')
            },
            // 多帧移动:所有帧同时左右镜像
            multiFlipHorizontal() {
                this.applyTransformToAllFrames('flipHorizontal')
            },
            // 多帧移动:所有帧同时上下镜像
            multiFlipVertical() {
                this.applyTransformToAllFrames('flipVertical')
            },
            toggleControls() {
                this.showControls = !this.showControls;
            },
@@ -854,6 +950,7 @@
                this.pixelData = new Array(this.height * colCount).fill('')
                // 重置按钮组状态,下次打开回到主操作界面
                this.showMoveControls = false
                this.showMultiMoveControls = false
                this.showControls = false
            },
            // 复制当前帧
@@ -1160,6 +1257,112 @@
                });
            },
            
            // 选择图片(相册或拍照)
            chooseImage() {
                uni.chooseImage({
                    count: 1,
                    sizeType: ['compressed'],
                    sourceType: ['album', 'camera'],
                    success: (res) => {
                        console.log('chooseImage', JSON.stringify(res))
                        const tempFilePath = res.tempFilePaths[0]
                        uni.showLoading({ title: '转换中', mask: true })
                        this.imageToDotMatrix(tempFilePath).then(pixelArray => {
                            this.pixelData = pixelArray
                            uni.hideLoading()
                        }).catch(err => {
                            uni.hideLoading()
                            console.error('图片转点阵失败:', err)
                            uni.showToast({ title: '图片转点阵失败', icon: 'none' })
                        })
                    }
                })
            },
            // 将图片转成点数据,参考generateDotMatrix的采样逻辑
            imageToDotMatrix(imagePath) {
                return new Promise((resolve, reject) => {
                    // 先获取图片信息,得到原始宽高用于按比例缩放
                    uni.getImageInfo({
                        src: imagePath,
                        success: (imgInfo) => {
                            console.log('getImageInfo', JSON.stringify(imgInfo))
                            const imgW = imgInfo.width
                            const imgH = imgInfo.height
                            if (!imgW || !imgH) {
                                reject(new Error('图片尺寸异常'))
                                return
                            }
                            // 等比缩放,使图片完整包含在画布内并居中
                            const scale = Math.min(this.canvasWidth / imgW, this.canvasHeight / imgH)
                            const drawW = imgW * scale
                            const drawH = imgH * scale
                            const drawX = (this.canvasWidth - drawW) / 2
                            const drawY = (this.canvasHeight - drawH) / 2
                            ctx = uni.createCanvasContext('myCanvas', this)
                            ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
                            // 将缩放后的图片绘制到画布
                            ctx.drawImage(imagePath, drawX, drawY, drawW, drawH)
                            ctx.draw(false, () => {
                                setTimeout(() => {
                                    uni.canvasGetImageData({
                                        canvasId: 'myCanvas',
                                        x: 0,
                                        y: 0,
                                        width: this.canvasWidth,
                                        height: this.canvasHeight,
                                        success: (res) => {
                                            console.log('canvasGetImageData', JSON.stringify(res))
                                            const imageData = res.data
                                            const colCount = this.width * (this.modeVal == 2 ? 10 : 1)
                                            const pixelArray = new Array(this.height * colCount).fill('')
                                            const cellWidth = this.canvasWidth / colCount
                                            const cellHeight = this.canvasHeight / this.height
                                            if (!imageData) {
                                                reject(new Error('读取图片像素数据异常'))
                                                return
                                            }
                                            // 按格子采样,判断每个格子是否为前景(暗)像素
                                            for (let y = 0; y < this.height; y++) {
                                                for (let x = 0; x < colCount; x++) {
                                                    let darkPixels = 0
                                                    let totalPixels = 0
                                                    for (let py = 0; py < cellHeight; py++) {
                                                        for (let px = 0; px < cellWidth; px++) {
                                                            const pixelY = Math.floor(y * cellHeight + py)
                                                            const pixelX = Math.floor(x * cellWidth + px)
                                                            const idx = (pixelY * this.canvasWidth + pixelX) * 4
                                                            const r = imageData[idx]
                                                            const g = imageData[idx + 1]
                                                            const b = imageData[idx + 2]
                                                            const a = imageData[idx + 3]
                                                            const brightness = 0.3 * r + 0.59 * g + 0.11 * b
                                                            if (brightness < 128 && a > 128) {
                                                                darkPixels++
                                                            }
                                                            totalPixels++
                                                        }
                                                    }
                                                    const isDark = darkPixels / totalPixels > 0.3
                                                    const arrayIndex = y * colCount + x
                                                    pixelArray[arrayIndex] = isDark ? this.color : ''
                                                }
                                            }
                                            resolve(pixelArray)
                                        },
                                        fail: (err) => {
                                            reject(err)
                                        }
                                    })
                                }, 1000)
                            })
                        },
                        fail: (err) => {
                            reject(err)
                        }
                    })
                })
            },
            openPreview() {
                if (this.fpsList.length === 0 || this.fpsList.every(f => f === null || f === undefined)) {
                    uni.showToast({
ledApp/pages/index/index.vue
@@ -191,7 +191,10 @@
                dId: '' ,//已连接的设备id,
                devKwh: '',
                platform: '',
                screenOn: true
                screenOn: true,
                waitDallThenSend: false, // 标记:收到DALL清除所有信息指令回应后,再开始发送INST帧
                instTimer: null, // INST发送超时计时器:发送INST帧后等待回应,超过5秒未收到则判定发送失败
                instSendAborted: false // 标记:INST发送已失败/中止,收到迟到的回应时忽略,不再继续发送
            }
        },
        onLoad() {
@@ -377,7 +380,7 @@
                console.log('--------------', item);
                uni.showLoading({
                    title: '发送中...',
                    title: '发送中0%',
                    mask: true
                });
@@ -402,7 +405,12 @@
                }
                if (this.ledData.length > 0) {
                    this.commandINST(this.ledData[this.ledCurrent]);
                    // 重置发送状态:清除残留计时器、重置失败标记
                    this.clearInstTimer();
                    this.instSendAborted = false;
                    // 向智能壳发送INST帧前,先发送一次清除所有信息指令(DALL),待智能壳回应后再开始发送
                    this.waitDallThenSend = true;
                    this.commandDALL();
                } else {
                    uni.hideLoading();
                    uni.showToast({
@@ -494,7 +502,7 @@
                var that = this
                uni.setBLEMTU({
                    deviceId: this.deviceId,
                    mtu: 80, // 最大值一般 512,蓝牙 4.2 通常支持 247
                    mtu: 512, // 最大值一般 512,蓝牙 4.2 通常支持 247
                    success: (res) => {
                        console.log('设置MTU成功:', res);
                        uni.hideLoading();
@@ -587,7 +595,8 @@
            },
            //向低功耗蓝牙设备特征值中写入二进制数据
            writeBLECharacteristicValue(buffer) {
            //keepLoading: 发送INST帧(含DALL前置指令、结束帧)过程中保持进度loading,发送成功后不关闭
            writeBLECharacteristicValue(buffer, keepLoading = false) {
                const that = this
                uni.writeBLECharacteristicValue({
                    deviceId: this.deviceId,
@@ -597,7 +606,9 @@
                    writeType: 'write',
                    success: (res) => {
                        //console.log('写入指令发送成功----', res);
                        uni.hideLoading();
                        if (!keepLoading) {
                            uni.hideLoading();
                        }
                    },
                    fail: (err) => {
                        //console.log('写入指令发送失败----', err);
@@ -706,6 +717,67 @@
                    this.writeBLECharacteristicValue(buffer)
                }, 500);
            },
            // 清除所有信息指令(DALL)
            commandDALL() {
                // 1.手机发指令:启动字节+帧头+包头段(0x43+简易绑定号+屏大小)+DALL+CRC校验码+帧尾。
                // 2.智能壳回指令:启动字节+帧头+包头段+DALL+返回标志+加密地址+CRC校验码+帧尾。
                // 构建指令数据
                const startBytes = new Array(10).fill(0x55); // 10个启动字节
                const frameHeader = 0x7E; // 帧头
                const packageType = 0x43; // 包类型
                // 使用新的简易绑定号生成函数
                const simpleBindId = this.generateSimpleBindId();
                // 屏大小 (2 bytes)
                const screenSize = [0x0C, 0x18];
                const packageHeader = [packageType, ...simpleBindId, ...screenSize];
                const command = [0x44, 0x41, 0x4C, 0x4C]; // "DALL"的ASCII码
                // 组合数据
                const data = [
                    ...startBytes,
                    frameHeader,
                    ...packageHeader,
                    ...command
                ];
                // 计算CRC校验码(从包头段开始计算)
                const crc = this.calcCRC16(data.slice(11));
                // 添加CRC和帧尾
                data.push((crc >> 8) & 0xFF); // CRC高8位
                data.push(crc & 0xFF); // CRC低8位
                data.push(frameHeader); // 帧尾
                console.log('DALL data----', this.hexArrayToHexString(data))
                const buffer = new Uint8Array(data).buffer;
                setTimeout(() => {
                    this.writeBLECharacteristicValue(buffer, true)
                }, 50);
            },
            // 启动INST发送超时计时器:发送INST帧后等待智能壳回应,超过5秒未收到则判定发送失败
            startInstTimer() {
                this.clearInstTimer();
                this.instTimer = setTimeout(() => {
                    this.handleInstTimeout();
                }, 5000);
            },
            // 清除INST发送超时计时器
            clearInstTimer() {
                if (this.instTimer) {
                    clearTimeout(this.instTimer);
                    this.instTimer = null;
                }
            },
            // INST发送超时处理:停止发送并提示发送失败
            handleInstTimeout() {
                this.instTimer = null;
                this.instSendAborted = true;
                uni.hideLoading();
                uni.showToast({
                    title: '发送失败',
                    icon: 'none',
                    mask: true
                });
            },
            //添加信息指令(INST)
            commandINST(hexString) {
                // 1.手机发指令:启动+帧头+包头段(0x43+简易绑定号+屏大小)+INST+信息属性+文件名+总帧数+当前帧*+块描述+块数据+CRC校验码+帧尾
@@ -764,11 +836,19 @@
                //console.log(this.ledCurrent, '----INST data----', this.hexArrayToHexString(data))
                //const buffer = new Uint8Array(data).buffer;
                console.log('第几帧-------',this.ledCurrent)
                setTimeout(() => {
                // 根据总帧数和已发送数量更新发送进度(当前帧发送前,已发送ledCurrent帧),范围10%~99%
                const sendPercent = Math.max(10, Math.min(99, Math.round(this.ledCurrent / this.ledTotal * 100)));
                uni.showLoading({
                    title: '发送中' + sendPercent + '%',
                    mask: true
                });
                setTimeout(async () => {
                    //this.writeBLECharacteristicValue(buffer)
                    this.sendBLEDataInChunks(
                        this.hexArrayToHexString(data)
                    )
                    const ok = await this.sendBLEDataInChunks(this.hexArrayToHexString(data))
                    if (ok) {
                        // 数据发送成功后启动超时计时器,等待智能壳回应,超过5秒未收到则判定发送失败
                        this.startInstTimer()
                    }
                }, 50);
            },
            // 发送结束针
@@ -821,7 +901,9 @@
                const endbuffer = new Uint8Array(endData).buffer;
                setTimeout(() => {
                    this.writeBLECharacteristicValue(endbuffer)
                    this.writeBLECharacteristicValue(endbuffer, true)
                    // 结束帧发送后启动超时计时器,等待智能壳回应,超过5秒未收到则判定发送失败
                    this.startInstTimer()
                }, 50);
            },
            async sendBLEDataInChunks(hexStr) {
@@ -852,14 +934,19 @@
                            })
                        })
                    } catch (err) {
                        console.error(`🚫 发送中断,第 ${i + 1} 包发送失败`)
                        console.error(`🚫 发送中断,第 ${i + 1} 帧发送失败`, err)
                        uni.hideLoading();
                        break
                        uni.showToast({
                            title: `🚫 发送中断,第 ${i + 1} 帧发送失败`,
                            duration: 4000
                        });
                        return false
                    }
                    // 延迟下一包发送
                    await new Promise(r => setTimeout(r, interval))
                }
                //console.log("🎉 数据发送完成")
                return true
            },
            // 读取电量
            commandPOWR() {
@@ -977,6 +1064,12 @@
                            } else if (resName == 'PLAY') {
                            } else if (resName == 'INST') {
                                // 收到INST回应,清除发送超时计时器
                                that.clearInstTimer();
                                // 若已因超时中止发送,忽略迟到的回应,不再继续发送
                                if (that.instSendAborted) {
                                    return;
                                }
                                // 添加动画帧
                                that.ledCurrent++
                                if (that.ledCurrent < that.ledTotal) {
@@ -986,15 +1079,24 @@
                                    // });
                                    that.commandINST(that.ledData[that.ledCurrent]);
                                } else if (that.ledCurrent == that.ledTotal) {
                                    // uni.showLoading({
                                    //  title: '发送结束帧',
                                    //  mask: true
                                    // });
                                    // 所有数据帧已发送完成,发送结束帧,进度显示100%
                                    uni.showLoading({
                                        title: '发送中100%',
                                        mask: true
                                    });
                                    that.commandEnd()
                                } else {
                                    // 结束帧应答(ledCurrent == ledTotal + 1),全部发送完成,隐藏loading
                                    uni.hideLoading();
                                }
                            } else if (resName == 'DALL') {
                                // 清除所有信息指令回应:返回标志0x30工作无异常,0x31工作有异常
                                if (that.waitDallThenSend) {
                                    that.waitDallThenSend = false;
                                    // 收到DALL回应后,开始发送第一帧INST
                                    that.commandINST(that.ledData[that.ledCurrent]);
                                }
                            } else if (resName == 'POWR') {
                                // 查询电量
                                let capacityHex = result.slice(-8, -6); // "0a"