Commit c574501b authored by tongzifang's avatar tongzifang

优化稳定状态判断

parent ca71d6bc
...@@ -8,9 +8,9 @@ android { ...@@ -8,9 +8,9 @@ android {
defaultConfig { defaultConfig {
applicationId "com.qimai.android.widget" applicationId "com.qimai.android.widget"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 29
versionCode 11 versionCode 14
versionName "1.0.11" versionName "1.0.14"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
......
...@@ -30,7 +30,7 @@ android { ...@@ -30,7 +30,7 @@ android {
} }
} }
group 'com.qmai.android.zqtoolkit' group 'com.qmai.android.zqtoolkit'
version '1.0.7.43' version '1.0.7.45'
gradlePublish { gradlePublish {
......
...@@ -10,5 +10,5 @@ data class LivingWeight( ...@@ -10,5 +10,5 @@ data class LivingWeight(
val weight: String, val weight: String,
val unit: String, val unit: String,
val tare: String, val tare: String,
val isReadErr: Boolean? val isReadErr: Boolean
) )
...@@ -22,6 +22,8 @@ import com.qmai.zqtoolkit.utils.ScaleChecker ...@@ -22,6 +22,8 @@ import com.qmai.zqtoolkit.utils.ScaleChecker
object AclasScaleKit : ScaleBaseKit() { object AclasScaleKit : ScaleBaseKit() {
override val TAG: String override val TAG: String
get() = "AclasScaleKit" get() = "AclasScaleKit"
override val STABLE_COUNT: Int
get() = 4
override val SCALE_TYPE: QmScaleType override val SCALE_TYPE: QmScaleType
get() = QmScaleType.ACLAS get() = QmScaleType.ACLAS
private var aclasScaler: AclasScaler? = null private var aclasScaler: AclasScaler? = null
......
...@@ -20,7 +20,8 @@ import java.text.DecimalFormat ...@@ -20,7 +20,8 @@ import java.text.DecimalFormat
object SunmiScaleKit : ScaleBaseKit() { object SunmiScaleKit : ScaleBaseKit() {
override val TAG: String override val TAG: String
get() = "SunmiScaleKit" get() = "SunmiScaleKit"
override val STABLE_COUNT: Int
get() = 3
override val SCALE_TYPE: QmScaleType override val SCALE_TYPE: QmScaleType
get() = QmScaleType.SUNMI get() = QmScaleType.SUNMI
...@@ -66,7 +67,7 @@ object SunmiScaleKit : ScaleBaseKit() { ...@@ -66,7 +67,7 @@ object SunmiScaleKit : ScaleBaseKit() {
decimalFormat.format((i * 1.0f / 1000).toDouble()), decimalFormat.format((i * 1.0f / 1000).toDouble()),
"kg", "kg",
decimalFormat.format((i1 * 1.0f / 1000).toDouble()), decimalFormat.format((i1 * 1.0f / 1000).toDouble()),
i2 == 1 i2 and 1 != 1,
) )
) )
} }
......
...@@ -21,10 +21,11 @@ import kotlinx.coroutines.flow.flowOn ...@@ -21,10 +21,11 @@ import kotlinx.coroutines.flow.flowOn
object ZqScaleKit : ScaleBaseKit() { object ZqScaleKit : ScaleBaseKit() {
override val TAG: String override val TAG: String
get() = "ZqScaleKit" get() = "ZqScaleKit"
override val STABLE_COUNT: Int
get() = 4
override val SCALE_TYPE: QmScaleType override val SCALE_TYPE: QmScaleType
get() = QmScaleType.ZQEB get() = QmScaleType.ZQEB
private var stableWeight = mutableListOf<String>()
override fun connect(cxt: Context?, port: String?, buad: String?) { override fun connect(cxt: Context?, port: String?, buad: String?) {
super.connect(cxt, port, buad) super.connect(cxt, port, buad)
val ebConnect = val ebConnect =
...@@ -155,9 +156,6 @@ object ZqScaleKit : ScaleBaseKit() { ...@@ -155,9 +156,6 @@ object ZqScaleKit : ScaleBaseKit() {
&& strWeight.isNotEmpty() && strWeight.toFloat() < 0) && strWeight.isNotEmpty() && strWeight.toFloat() < 0)
) { ) {
strState = "OK" strState = "OK"
when {
stableWeight.size == 4 -> {
if (stableWeight.toSet().size == 1) {
updateWeight( updateWeight(
LivingWeight( LivingWeight(
true, true,
...@@ -167,14 +165,6 @@ object ZqScaleKit : ScaleBaseKit() { ...@@ -167,14 +165,6 @@ object ZqScaleKit : ScaleBaseKit() {
false false
) )
) )
}
stableWeight.clear()
}
stableWeight.size > 4 -> {
stableWeight.clear()
}
else -> stableWeight.add(strWeight)
}
} else { } else {
// when (Integer.valueOf(strRet[0])) { // when (Integer.valueOf(strRet[0])) {
// -3 -> strState = "Data wrong" // -3 -> strState = "Data wrong"
......
...@@ -5,6 +5,7 @@ import com.qmai.zqtoolkit.ConnectState ...@@ -5,6 +5,7 @@ import com.qmai.zqtoolkit.ConnectState
import com.qmai.zqtoolkit.LivingWeight import com.qmai.zqtoolkit.LivingWeight
import com.qmai.zqtoolkit.ScaleHub import com.qmai.zqtoolkit.ScaleHub
import com.qmai.zqtoolkit.ScaleInfo import com.qmai.zqtoolkit.ScaleInfo
import com.qmai.zqtoolkit.base.ZqScaleKit
import com.qmai.zqtoolkit.base.scale.ScaleBaseAction import com.qmai.zqtoolkit.base.scale.ScaleBaseAction
import com.qmai.zqtoolkit.base.scale.ScaleUpdateAction import com.qmai.zqtoolkit.base.scale.ScaleUpdateAction
import com.qmai.zqtoolkit.config.QmScaleType import com.qmai.zqtoolkit.config.QmScaleType
...@@ -22,6 +23,7 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction { ...@@ -22,6 +23,7 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
abstract val TAG: String abstract val TAG: String
abstract val SCALE_TYPE: QmScaleType abstract val SCALE_TYPE: QmScaleType
abstract val STABLE_COUNT: Int //顶尖称有假稳定情况,设置稳定达到一定次数后再给业务发数据
var lastTryScale: ScaleInfo? = null var lastTryScale: ScaleInfo? = null
private var lastConnectScale: ScaleInfo? = null private var lastConnectScale: ScaleInfo? = null
...@@ -31,6 +33,7 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction { ...@@ -31,6 +33,7 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
val _livingWeight = MutableSharedFlow<LivingWeight>() val _livingWeight = MutableSharedFlow<LivingWeight>()
val livingWeight: SharedFlow<LivingWeight> = _livingWeight val livingWeight: SharedFlow<LivingWeight> = _livingWeight
private var stableWeight = mutableListOf<String>()
override fun connect(cxt: Context?, port: String?, buad: String?) { override fun connect(cxt: Context?, port: String?, buad: String?) {
lastTryScale = ScaleInfo(port, buad, SCALE_TYPE) lastTryScale = ScaleInfo(port, buad, SCALE_TYPE)
...@@ -54,8 +57,22 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction { ...@@ -54,8 +57,22 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
override fun updateWeight(weight: LivingWeight) { override fun updateWeight(weight: LivingWeight) {
GlobalScope.launch(context = Dispatchers.IO) { GlobalScope.launch(context = Dispatchers.IO) {
//稳定状态且读数正常
if (weight.isStable && !weight.isReadErr) {
when {
stableWeight.size == STABLE_COUNT -> {
if (stableWeight.toSet().size == 1) {
_livingWeight.emit(weight) _livingWeight.emit(weight)
} }
stableWeight.clear()
}
stableWeight.size > STABLE_COUNT -> {
stableWeight.clear()
}
else -> stableWeight.add(weight.weight)
}
} else _livingWeight.emit(weight)
}
} }
......
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