From 75e1b9ca9b73adbba7c74b95bbc19923e48edd14 Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Fri, 9 Jan 2026 00:00:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=80=92=E8=AE=A1=E6=97=B6=E5=88=B025?= =?UTF-8?q?=E7=A7=92=E6=97=B6=E5=88=BB=EF=BC=8C=E6=98=BE=E7=A4=BA=E4=B8=BA?= =?UTF-8?q?25/60?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/mixer/mixer.vue | 125 +++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 61 deletions(-) diff --git a/src/pages/mixer/mixer.vue b/src/pages/mixer/mixer.vue index f2a8439..107b9d6 100644 --- a/src/pages/mixer/mixer.vue +++ b/src/pages/mixer/mixer.vue @@ -89,7 +89,10 @@ Timer: - {{ channel.timerValue }} + + {{ channel.remainingTime }}/{{ channel.timerSeconds }} + + {{ channel.timerValue }} @@ -228,7 +231,7 @@ const channels = ref([ timerMode: 'Timer', timerValue: 'Not Set', remainingTime: 0, // 剩余秒数 - timerMinutes: 0 // 设置的分钟数 + timerSeconds: 0 // 设置的秒数 }, { id: 'CH2', @@ -241,7 +244,7 @@ const channels = ref([ timerMode: 'Timer', timerValue: 'Not Set', remainingTime: 0, - timerMinutes: 0 + timerSeconds: 0 }, { id: 'CH3', @@ -254,7 +257,7 @@ const channels = ref([ timerMode: 'Timer', timerValue: 'Not Set', remainingTime: 0, - timerMinutes: 0 + timerSeconds: 0 }, { id: 'CH4', @@ -267,7 +270,7 @@ const channels = ref([ timerMode: 'Timer', timerValue: 'Not Set', remainingTime: 0, - timerMinutes: 0 + timerSeconds: 0 }, { id: 'CH5', @@ -280,7 +283,7 @@ const channels = ref([ timerMode: 'Timer', timerValue: 'Not Set', remainingTime: 0, - timerMinutes: 0 + timerSeconds: 0 }, { id: 'CH6', @@ -293,7 +296,7 @@ const channels = ref([ timerMode: 'Timer', timerValue: 'Not Set', remainingTime: 0, - timerMinutes: 0 + timerSeconds: 0 } ]) @@ -424,12 +427,12 @@ const loadChannelData = (channelId) => { if (channel) { // 恢复保存的数据,但状态默认为停止 channel.runValue = data.runValue || channel.runValue - channel.timerMinutes = data.timerMinutes || 0 + channel.timerSeconds = data.timerSeconds || 0 channel.remainingTime = 0 channel.status = 'stopped' - if (channel.timerMinutes > 0) { - channel.timerValue = `Set ${channel.timerMinutes} min` + if (channel.timerSeconds > 0) { + channel.timerValue = `${channel.timerSeconds}s` } } } @@ -445,7 +448,7 @@ const saveChannelData = (channelId) => { if (channel) { const data = { runValue: channel.runValue, - timerMinutes: channel.timerMinutes + timerSeconds: channel.timerSeconds } uni.setStorageSync(STORAGE_KEY_PREFIX + channelId, JSON.stringify(data)) } @@ -582,14 +585,14 @@ const setTimer = (channelId) => { uni.showModal({ title: 'Timer Setting', editable: true, - placeholderText: 'Enter minutes (0-9999)', - content: channel.timerMinutes > 0 ? String(channel.timerMinutes) : '', + placeholderText: 'Enter seconds (0-9999)', + content: channel.timerSeconds > 0 ? String(channel.timerSeconds) : '', cancelText: 'Cancel', confirmText: 'OK', success: (res) => { if (res.confirm && res.content) { - const minutes = parseInt(res.content) - if (isNaN(minutes) || minutes < 0 || minutes > 9999) { + const seconds = parseInt(res.content) + if (isNaN(seconds) || seconds < 0 || seconds > 9999) { uni.showToast({ title: 'Please enter 0-9999', icon: 'none' @@ -597,12 +600,12 @@ const setTimer = (channelId) => { return } - console.log(`⏰ ${channel.name} 设置定时: ${channel.timerMinutes} -> ${minutes}分钟`) - addDebugLog(`⏰ ${channel.name} 设置定时: ${minutes}分钟`, 'info') + console.log(`⏰ ${channel.name} 设置定时: ${channel.timerSeconds} -> ${seconds}s`) + addDebugLog(`⏰ ${channel.name} 设置定时: ${seconds}s`, 'info') // ✅ 不立即修改状态,只发送命令 // 等待蓝牙设备反馈后,通过 onBLECharacteristicValueChange 监听器更新定时设置 - sendBluetoothCommand('setTimer', channelId, minutes) + sendBluetoothCommand('setTimer', channelId, seconds) uni.showToast({ title: `${channel.name} Timer Command Sent`, @@ -765,8 +768,8 @@ const startTimer = (channelId) => { // 清除旧定时器 stopTimer(channelId) - console.log(`⏱️ 启动定时器: ${channel.name}, 剩余时间: ${channel.remainingTime}秒`) - addDebugLog(`⏱️ ${channel.name} 启动定时器: ${Math.floor(channel.remainingTime / 60)}分钟`, 'info') + console.log(`⏱️ 启动定时器: ${channel.name}, 剩余时间: ${channel.remainingTime}s`) + addDebugLog(`⏱️ ${channel.name} 启动定时器: ${channel.remainingTime}s`, 'info') // 创建新定时器(后台倒计时,不显示给用户) timerIntervals.value[channelId] = setInterval(() => { @@ -849,8 +852,8 @@ const sendBluetoothCommand = (command, channelId, value) => { break case 'setTimer': - // 写入电机定时设置(0xFF04),单位:分钟 - writeMotorTimer(channelIndex, value) // 直接使用分钟数 + // 写入电机定时设置(0xFF04),单位:秒 + writeMotorTimer(channelIndex, value) // 直接使用秒数 break case 'query': @@ -939,15 +942,15 @@ const writeMotorSpeed = (channelIndex, speed, isBatch = false, batchChannels = [ } // 写入电机定时设置(0xFF04) - 格式:电机序号 + 定时时间(小端序) -const writeMotorTimer = (channelIndex, minutes) => { +const writeMotorTimer = (channelIndex, seconds) => { // 写格式:长度可变,每3个字节表示一组,采用电机序号+电机定时时间的方式 - // 例如:[1, 2, 5] 表示第1个电机定时1282分钟(2 + 5*256 = 1282) + // 例如:[1, 2, 5] 表示第1个电机定时1282秒(2 + 5*256 = 1282) const buffer = new ArrayBuffer(3) const dataView = new Uint8Array(buffer) dataView[0] = channelIndex + 1 // 电机序号(1-6) - dataView[1] = minutes & 0xFF // 定时时间低位 - dataView[2] = (minutes >> 8) & 0xFF // 定时时间高位 + dataView[1] = seconds & 0xFF // 定时时间低位 + dataView[2] = (seconds >> 8) & 0xFF // 定时时间高位 // 📝 使用专用的定时特征值UUID(0xFF04) const writeCharId = characteristicIds.value.timer || characteristicIds.value.write || '0xFF04' @@ -1218,7 +1221,7 @@ Operation: Read Data Description: Read timer remaining time Query data: -- Remaining time of 6 channels (minutes) +- Remaining time of 6 channels (seconds) Expected: 12 bytes Format: 2 bytes per channel (little-endian)` @@ -1375,8 +1378,8 @@ const initBluetoothCommunication = () => { addDebugLog(` ${channel.name}: ${channel.status} -> ${newStatus}`, 'warn') // 如果从非定时状态变为定时状态,启动定时器 - if (newStatus === 'timing' && channel.timerMinutes > 0) { - channel.remainingTime = channel.timerMinutes * 60 + if (newStatus === 'timing' && channel.timerSeconds > 0) { + channel.remainingTime = channel.timerSeconds startTimer(channel.id) } @@ -1528,8 +1531,8 @@ const parseMotorStatusOrSpeed = (dataView) => { console.log(`${channel.name} 状态变化: ${channel.status} -> ${newStatus}`) // 如果从非定时状态变为定时状态,启动定时器 - if (newStatus === 'timing' && channel.timerMinutes > 0) { - channel.remainingTime = channel.timerMinutes * 60 + if (newStatus === 'timing' && channel.timerSeconds > 0) { + channel.remainingTime = channel.timerSeconds startTimer(channel.id) } @@ -1557,40 +1560,40 @@ const parseMotorStatusOrSpeed = (dataView) => { const parseMotorTimer = (dataView, type = 'unknown') => { channels.value.forEach((channel, index) => { // 低位在前,高位在后(小端序) - const minutes = dataView[index * 2] | (dataView[index * 2 + 1] << 8) + const seconds = dataView[index * 2] | (dataView[index * 2 + 1] << 8) - if (minutes > 0) { + if (seconds > 0) { if (type === 'remaining') { // 明确是剩余时间(0xFF05) - channel.remainingTime = minutes * 60 // 转为秒 - console.log(`${channel.name} 剩余时间:`, minutes, '分钟') - addDebugLog(` ${channel.name}: 剩余 ${minutes}分钟`, 'info') + channel.remainingTime = seconds + console.log(`${channel.name} 剩余时间:`, seconds, 's') + addDebugLog(` ${channel.name}: 剩余 ${seconds}s`, 'info') } else if (type === 'setup') { // 明确是定时设置(0xFF04)- 根据设备反馈更新本地定时设置 - if (channel.timerMinutes !== minutes) { - console.log(`${channel.name} 定时设置变化: ${channel.timerMinutes} -> ${minutes} 分钟`) - addDebugLog(` ${channel.name}: 定时 ${channel.timerMinutes} -> ${minutes}分钟`, 'warn') - channel.timerMinutes = minutes - channel.timerValue = minutes > 0 ? `Set ${minutes} min` : 'Not Set' + if (channel.timerSeconds !== seconds) { + console.log(`${channel.name} 定时设置变化: ${channel.timerSeconds} -> ${seconds}s`) + addDebugLog(` ${channel.name}: 定时 ${channel.timerSeconds} -> ${seconds}s`, 'warn') + channel.timerSeconds = seconds + channel.timerValue = seconds > 0 ? `${seconds}s` : 'Not Set' // 保存到本地存储 saveChannelData(channel.id) } else { - console.log(`${channel.name} 定时未变: ${minutes}分钟`) + console.log(`${channel.name} 定时未变: ${seconds}s`) } } else { // 未知类型,根据当前状态智能判断(兼容旧逻辑) if (channel.status === 'timing' && channel.remainingTime > 0) { // 如果正在定时中且已有剩余时间,优先更新剩余时间 - channel.remainingTime = minutes * 60 - console.log(`${channel.name} 剩余时间(推测):`, minutes, '分钟') - addDebugLog(` ${channel.name}: 剩余 ${minutes}分钟(推测)`, 'info') + channel.remainingTime = seconds + console.log(`${channel.name} 剩余时间(推测):`, seconds, 's') + addDebugLog(` ${channel.name}: 剩余 ${seconds}s(推测)`, 'info') } else { // 否则当作定时设置 - 根据设备反馈更新本地定时设置 - if (channel.timerMinutes !== minutes) { - console.log(`${channel.name} 定时设置变化(推测): ${channel.timerMinutes} -> ${minutes} 分钟`) - addDebugLog(` ${channel.name}: 定时 ${minutes}分钟(推测)`, 'warn') - channel.timerMinutes = minutes - channel.timerValue = minutes > 0 ? `Set ${minutes} min` : 'Not Set' + if (channel.timerSeconds !== seconds) { + console.log(`${channel.name} 定时设置变化(推测): ${channel.timerSeconds} -> ${seconds}s`) + addDebugLog(` ${channel.name}: 定时 ${seconds}s(推测)`, 'warn') + channel.timerSeconds = seconds + channel.timerValue = seconds > 0 ? `${seconds}s` : 'Not Set' // 保存到本地存储 saveChannelData(channel.id) } @@ -1620,8 +1623,8 @@ const parseMotorAllProperties = (dataView) => { addDebugLog(` ${channel.name}: ${channel.status} -> ${newStatus}`, 'warn') // 如果从非定时状态变为定时状态,启动定时器 - if (newStatus === 'timing' && channel.timerMinutes > 0) { - channel.remainingTime = channel.timerMinutes * 60 + if (newStatus === 'timing' && channel.timerSeconds > 0) { + channel.remainingTime = channel.timerSeconds startTimer(channel.id) } @@ -1648,21 +1651,21 @@ const parseMotorAllProperties = (dataView) => { // 可以根据需要存储方向信息 // 定时设置(18-29字节)- 根据设备反馈更新本地定时设置 - const timerMinutes = dataView[18 + index * 2] | (dataView[18 + index * 2 + 1] << 8) - if (channel.timerMinutes !== timerMinutes) { - console.log(`${channel.name} 定时设置变化: ${channel.timerMinutes} -> ${timerMinutes}分钟`) - addDebugLog(` ${channel.name}: 定时 ${channel.timerMinutes} -> ${timerMinutes}分钟`, 'info') - channel.timerMinutes = timerMinutes - channel.timerValue = timerMinutes > 0 ? `Set ${timerMinutes} min` : 'Not Set' + const timerSeconds = dataView[18 + index * 2] | (dataView[18 + index * 2 + 1] << 8) + if (channel.timerSeconds !== timerSeconds) { + console.log(`${channel.name} 定时设置变化: ${channel.timerSeconds} -> ${timerSeconds}s`) + addDebugLog(` ${channel.name}: 定时 ${channel.timerSeconds} -> ${timerSeconds}s`, 'info') + channel.timerSeconds = timerSeconds + channel.timerValue = timerSeconds > 0 ? `${timerSeconds}s` : 'Not Set' // 保存到本地存储 saveChannelData(channel.id) } // 剩余时间(30-41字节) - const remainingMinutes = dataView[30 + index * 2] | (dataView[30 + index * 2 + 1] << 8) - channel.remainingTime = remainingMinutes * 60 // 转为秒 + const remainingSeconds = dataView[30 + index * 2] | (dataView[30 + index * 2 + 1] << 8) + channel.remainingTime = remainingSeconds - console.log(`${channel.name} 完整数据 - 状态:${channel.status}, 速度:${speed}, 方向:${direction}, 定时:${timerMinutes}分钟, 剩余:${remainingMinutes}分钟`) + console.log(`${channel.name} 完整数据 - 状态:${channel.status}, 速度:${speed}, 方向:${direction}, 定时:${timerSeconds}s, 剩余:${remainingSeconds}s`) }) }