Commit c230942a authored by tongzifang's avatar tongzifang

1.2.0

parent 7e8082a6
......@@ -30,7 +30,7 @@ android {
}
}
group 'com.qmai.android.zqtoolkit'
version '1.1.8'
version '1.2.0'
gradlePublish {
......
......@@ -28,7 +28,6 @@ object ZqScaleKit : ScaleBaseKit() {
get() = 4
override val SCALE_TYPE: QmScaleBrand
get() = QmScaleBrand.ZQEB
private var connectCache = mutableListOf<Boolean>()
override fun connect(cxt: Context?, scale: ScaleInfo) {
......
......@@ -4,6 +4,7 @@ import android.content.Context
import com.qmai.zqtoolkit.ConnectState
import com.qmai.zqtoolkit.LivingWeight
import com.qmai.zqtoolkit.ScaleInfo
import com.qmai.zqtoolkit.base.ZqScaleKit
import com.qmai.zqtoolkit.config.QmScaleBrand
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
......@@ -32,6 +33,11 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
private var stableWeight = mutableListOf<String>()
var connectCache = mutableListOf<Boolean>()
private val readErrLimit = 10
private var readErrCache = mutableListOf<Boolean>()
override fun connect(
cxt: Context?,
scale: ScaleInfo
......@@ -59,6 +65,7 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
GlobalScope.launch(context = Dispatchers.IO) {
//稳定状态且读数正常
if (weight.isStable && !weight.isReadErr) {
readErrCache.clear()
when {
stableWeight.size == STABLE_COUNT -> {
if (stableWeight.toSet().size == 1) {
......@@ -74,7 +81,18 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
}
else -> stableWeight.add(weight.weight)
}
} else _livingWeight.emit(weight)
} else {
_livingWeight.emit(weight)
if (weight.isReadErr)
when {
readErrCache.size >= readErrLimit -> {
if (readErrCache.toSet().size == 1)
disconnect()
connectCache.clear()
}
else -> readErrCache.add(true)
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment