feat(sdk): 同步 iOS — 帧间隔 frameIntervalMs 配置化(默认 35ms)
1:1 复刻 iOS:DuooomiBleConfig 加 frameIntervalMs,BleProtocolService 构造期注入,sendFrames 改用 coerceIn(0,500)。清掉 FRAME_INTERVAL_MS 常量。 demo 加 ConfigField + SharedPreferences 持久化。 越界 warn 字符串与 iOS 逐字一致。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -69,6 +69,7 @@ fun DemoScreen(
|
||||
var configBrand by remember(sdk) { mutableStateOf(config.brand) }
|
||||
var configApiKey by remember(sdk) { mutableStateOf(config.apiKey) }
|
||||
var configScanPrefix by remember(sdk) { mutableStateOf(config.scanPrefix) }
|
||||
var configFrameIntervalMs by remember(sdk) { mutableStateOf(config.frameIntervalMs) }
|
||||
|
||||
// Local state
|
||||
var userId by remember { mutableStateOf("Cjgex9kTTTJq9u9RMOnc5hiIZTvrOOq3") }
|
||||
@@ -137,11 +138,12 @@ fun DemoScreen(
|
||||
ConfigField("brand", configBrand) { configBrand = it }
|
||||
ConfigField("apiKey", configApiKey) { configApiKey = it }
|
||||
ConfigField("scanPrefix", configScanPrefix) { configScanPrefix = it }
|
||||
ConfigField("frameIntervalMs", configFrameIntervalMs) { configFrameIntervalMs = it }
|
||||
Button(
|
||||
onClick = {
|
||||
onReload(DemoConfig(configBrand, configApiKey, configScanPrefix))
|
||||
onReload(DemoConfig(configBrand, configApiKey, configScanPrefix, configFrameIntervalMs))
|
||||
log(
|
||||
"SDK reloaded with brand=$configBrand, prefix=$configScanPrefix",
|
||||
"SDK reloaded with brand=$configBrand, prefix=$configScanPrefix, frameMs=$configFrameIntervalMs",
|
||||
LogLevel.SUCCESS
|
||||
)
|
||||
},
|
||||
|
||||
@@ -38,7 +38,8 @@ class MainActivity : ComponentActivity() {
|
||||
brand = prefs.getString(KEY_BRAND, DemoSecrets.BRAND) ?: DemoSecrets.BRAND,
|
||||
apiKey = prefs.getString(KEY_API_KEY, DemoSecrets.API_KEY) ?: DemoSecrets.API_KEY,
|
||||
scanPrefix = prefs.getString(KEY_SCAN_PREFIX, DemoSecrets.SCAN_NAME_PREFIX)
|
||||
?: DemoSecrets.SCAN_NAME_PREFIX
|
||||
?: DemoSecrets.SCAN_NAME_PREFIX,
|
||||
frameIntervalMs = prefs.getString(KEY_FRAME_INTERVAL_MS, "35") ?: "35"
|
||||
)
|
||||
|
||||
setContent {
|
||||
@@ -70,7 +71,8 @@ class MainActivity : ComponentActivity() {
|
||||
config = DuooomiBleConfig(
|
||||
apiKey = c.apiKey,
|
||||
brand = c.brand,
|
||||
scanNamePrefix = c.scanPrefix
|
||||
scanNamePrefix = c.scanPrefix,
|
||||
frameIntervalMs = c.frameIntervalMs.toIntOrNull() ?: 35
|
||||
)
|
||||
)
|
||||
|
||||
@@ -79,6 +81,7 @@ class MainActivity : ComponentActivity() {
|
||||
.putString(KEY_BRAND, c.brand)
|
||||
.putString(KEY_API_KEY, c.apiKey)
|
||||
.putString(KEY_SCAN_PREFIX, c.scanPrefix)
|
||||
.putString(KEY_FRAME_INTERVAL_MS, c.frameIntervalMs)
|
||||
.apply()
|
||||
}
|
||||
|
||||
@@ -104,11 +107,13 @@ class MainActivity : ComponentActivity() {
|
||||
const val KEY_BRAND = "demo.config.brand"
|
||||
const val KEY_API_KEY = "demo.config.apiKey"
|
||||
const val KEY_SCAN_PREFIX = "demo.config.scanPrefix"
|
||||
const val KEY_FRAME_INTERVAL_MS = "demo.config.frameIntervalMs"
|
||||
}
|
||||
}
|
||||
|
||||
data class DemoConfig(
|
||||
val brand: String,
|
||||
val apiKey: String,
|
||||
val scanPrefix: String
|
||||
val scanPrefix: String,
|
||||
val frameIntervalMs: String
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user