添加了副屏显示逻辑控制

This commit is contained in:
zxj
2025-08-01 15:57:12 +08:00
parent de4c5f1c75
commit c78279a66e
27 changed files with 817 additions and 191 deletions
@@ -1,148 +0,0 @@
package com.sw.plate.sdk
import android.util.Log
import com.sw.plate.utils.ThreadUtils
import com.sw.plate.utils.ToastUtils
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
import com.wabon.wbintelligenthardwaresdk.api.SensorScale.OnScaleResult
import kotlinx.coroutines.delay
typealias Callback = (Double) -> Unit
private const val TAG = "SensorScaleUtils"
/**
* 称 传感器计算
*/
object SensorScaleUtils {
const val serialPort = "/dev/ttyS7"
const val baudRate = 115200
private var mSensorScale: SensorScale? = null
private var isOpened: Boolean = false
private var callback: Callback? = {}
private fun init() {
mSensorScale = SensorScale(object : OnScaleResult {
/**
* 读取重量
*/
override fun readWeight(state: Int, value: Double) {
val stateStr = when (state) {
SensorScale.STATE_STABLE -> "稳定"
SensorScale.STATE_UNSTABLE -> "不稳定"
SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
else -> "未知"
}
// Log.d(TAG, "readWeight state = ${stateStr}, weight = $value")
// 只使用稳定值
if (state == SensorScale.STATE_STABLE) {
callback?.invoke(value)
}
}
/**
* 读取鉴别率
*/
override fun readIdentify(rate: Int) {
Log.e(TAG, "readIdentify rate = $rate")
}
override fun fail(errCode: Int) {
Log.e(TAG, "fail code = $errCode")
}
})
}
/**
* 开启称重
* @param autoScale 是否开启自动读取
*/
fun startScale(autoScale: Boolean = true, callback: Callback?) {
if (isOpened) {
startContinuousRead(callback = callback)
return
}
this.callback = callback
init()
mSensorScale?.openScale(serialPort, baudRate) { open ->
isOpened = open
Log.d(TAG, "isOpened = $isOpened")
if (open) {
if (autoScale) {
ThreadUtils.launchOnIo {
delay(1000)
// 打开后需要等待后才能调用,否则会 1001 SDK未初始化
mSensorScale?.startContinuousRead()
}
}
}
}
}
/**
* 开启自动读取重量
*/
fun startContinuousRead(callback: Callback?) {
this.callback = callback
Log.d(TAG, "开启自动读取 = $isOpened")
if (!isOpened) {
return
}
mSensorScale?.startContinuousRead()
}
/**
* 手动读取重量
*/
fun readWeight(callback: Callback?) {
this.callback = callback
Log.d(TAG, "isOpened = $isOpened")
if (!isOpened) {
return
}
mSensorScale?.readWeight()
}
/**
* 零位标定
*/
fun zero() {
if (!isOpened) return
mSensorScale?.zero {
Log.d(TAG, "零位标定操作成功")
ToastUtils.showToast("零位标定操作成功")
}
}
/**
* 去皮置零
*/
fun tare() {
if (!isOpened) return
mSensorScale?.tare {
Log.d(TAG, "去皮置零操作成功")
ToastUtils.showToast("去皮置零操作成功")
}
}
/**
* 停止自动读取重量
*/
fun stopContinuousRead() {
Log.d(TAG, "isOpened = $isOpened")
if (!isOpened) {
return
}
mSensorScale?.stopContinuousRead()
}
/**
* 关闭称重
*/
fun closeScale() {
isOpened = false
mSensorScale?.closeScale()
mSensorScale == null
}
}
@@ -422,7 +422,7 @@ public class FaceHelper implements FaceListener {
if (!contained) {
RecognizeInfo recognizeInfo = recognizeInfoMap.remove(key);
if (recognizeInfo != null) {
recognizeCallback.onNoticeChanged("");
recognizeCallback.onNoticeChanged("leave");
// 人脸离开时,通知特征提取线程,避免一直等待活体结果
synchronized (recognizeInfo.getWaitLock()) {
recognizeInfo.getWaitLock().notifyAll();