2025-04-16 18:15:18 +08:00
|
|
|
import BLESDK from './ble'
|
|
|
|
|
|
|
|
class taskQueue {
|
|
|
|
list = []
|
|
|
|
isExecute = false
|
|
|
|
overtime = null
|
|
|
|
|
|
|
|
addTask(buffer) {
|
2025-04-18 09:09:09 +08:00
|
|
|
if (!BLESDK.deviceInfo.state) return
|
2025-04-16 18:15:18 +08:00
|
|
|
this.list.push(buffer)
|
2025-04-18 09:09:09 +08:00
|
|
|
|
|
|
|
if (this.isExecute) return
|
|
|
|
this.executeTask()
|
2025-04-16 18:15:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
executeTask() {
|
|
|
|
this.isExecute = !!this.list.length
|
|
|
|
if (!this.list.length) return
|
2025-04-18 09:09:09 +08:00
|
|
|
if (!BLESDK.deviceInfo.state) {
|
|
|
|
this.list = []
|
|
|
|
this.isExecute = !!this.list.length
|
|
|
|
return
|
|
|
|
}
|
|
|
|
BLESDK.writeBleValue(new Uint8Array([...this.list[0]]).buffer)
|
2025-04-16 18:15:18 +08:00
|
|
|
this.list.shift()
|
|
|
|
|
|
|
|
this.overtime = setTimeout(() => {
|
2025-04-18 09:09:09 +08:00
|
|
|
this.stopOverTime()
|
2025-04-16 18:15:18 +08:00
|
|
|
this.executeTask()
|
2025-05-19 18:25:43 +08:00
|
|
|
}, 300)
|
2025-04-16 18:15:18 +08:00
|
|
|
}
|
|
|
|
stopOverTime() {
|
|
|
|
clearTimeout(this.overtime)
|
|
|
|
this.overtime = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new taskQueue()
|