feat(sdk): 帧间隔 frameIntervalMs 配置化(默认 35ms,[0,500] clamp)
DuooomiBleConfig 新增 frameIntervalMs,BleProtocolService 构造期注入。 顺手清死代码 FrameConstants.frameIntervalNanos、修 sendFrames 0.035 字面量 (统一走 config)。demo 加可调输入框 + UserDefaults 持久化。 越界 warn 不抛错,使用点 min/max 兜底。 设计稿:docs/superpowers/specs/2026-05-20-frame-interval-config-design.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ final class BleProtocolService: BleClientDelegate {
|
||||
|
||||
weak var delegate: BleProtocolServiceDelegate?
|
||||
private let client: BleClient
|
||||
private let frameIntervalMs: Int
|
||||
private var isListening = false
|
||||
|
||||
/// 分包重组会话
|
||||
@@ -20,9 +21,10 @@ final class BleProtocolService: BleClientDelegate {
|
||||
|
||||
private var fragments: [String: FragmentSession] = [:]
|
||||
|
||||
init(client: BleClient) {
|
||||
init(client: BleClient, frameIntervalMs: Int) {
|
||||
self.client = client
|
||||
BleLog.i("Protocol service created", "Protocol")
|
||||
self.frameIntervalMs = frameIntervalMs
|
||||
BleLog.i("Protocol service created (frameIntervalMs=\(frameIntervalMs))", "Protocol")
|
||||
}
|
||||
|
||||
// MARK: - Start/Stop Listening
|
||||
@@ -90,8 +92,9 @@ final class BleProtocolService: BleClientDelegate {
|
||||
onProgress?(Double(index + 1) / Double(total))
|
||||
|
||||
if index + 1 < total {
|
||||
// Inter-frame delay 35ms
|
||||
DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 0.035) {
|
||||
// Inter-frame delay from config (clamped to [0,500]ms)
|
||||
let delaySec = Double(min(max(self.frameIntervalMs, 0), 500)) / 1000.0
|
||||
DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + delaySec) {
|
||||
sendFrame(at: index + 1)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user