优化识别及增加扫码枪逻辑

This commit is contained in:
2026-02-04 18:00:46 +08:00
parent 7596924d75
commit e2c0ed35ec
9 changed files with 152 additions and 35 deletions
@@ -39,6 +39,7 @@ import com.sw.dualscreen.model.response.ClickBackEvent
import com.sw.dualscreen.model.response.FoodInfo
import com.sw.dualscreen.model.response.FoodOrder
import com.sw.dualscreen.model.response.PaySuccessEvent
import com.sw.dualscreen.model.response.UpdateRefreshEvent
import com.sw.dualscreen.model.response.UserFaceModel
import com.sw.dualscreen.objbox.Food
import com.sw.dualscreen.objbox.FoodModule
@@ -155,6 +156,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
viewModel.getUserFaceCache(pageNo = 1)
setupCamera()
initData()
registerKeyEvent()
}
private fun initData() {
@@ -239,6 +241,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
super.registerDataChange()
SensorScaleUtils.addWeightListener { weight ->
log("registerDataChange weight = $weight")
//runOnUiThread { binding.tvShowWeight.text="${weight*1000}克" }
if (lastWeight - weight > 0.005) {
//及放及取,从秤上拿走超过5克
if (presentation?.mealPickupMode == 0) {
presentation?.updateWeight(weight)
lastWeight = weight
return@addWeightListener
}
}
if (isPageVisible.not() || isStartRecognize.not()) {
if (ActivityManager.currentActivity() is MainActivity) {
isPageVisible = true
@@ -246,7 +257,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
return@addWeightListener
}
val isWeightChange = abs(weight - lastWeight) > 0.05
//0.05
// val isWeightChange = abs(weight - lastWeight) > 0.02
val isWeightChange = weight - lastWeight > 0.02
log("recognizeByWeight---00001,weight=$weight,lastWeight=$lastWeight,isWeightChange=$isWeightChange")
recognizeByWeight(weight, isWeightChange)
}
@@ -256,8 +269,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
presentation?.updateWeight(weight)
if (weight <= 0.005) {
log("recognizeByWeight---00002,未超过5克")
////余量取餐,检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1
log("recognizeByWeight---00002秤重未超过5克")
//检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1
isRecognitionFood = true
return
}
@@ -270,11 +283,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
debouncer.debounce {
log("recognizeByWeight---00004")
recognizeFood()
if (presentation?.mealPickupMode == 0) {
lastWeight = weight
}
}
} else {
block()
}
lastWeight = weight
if (presentation?.mealPickupMode == 1) {
lastWeight = weight
}
}
private var startTime = 0L
@@ -291,14 +310,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}.start()
failCount = 0
}, failureCallback = {
runOnUiThread {
if (failCount >= 10) {
ToastUtils.showToast("相机异常,请稍后重试")
shutdownCamera()
setupCamera()
return@runOnUiThread
}
}
//ToastUtils.showToast("拍照异常,请重试")
failCount++
hideWaitingDialog()
@@ -553,7 +565,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} else {
//副屏未显示重新加载
isRecognitionFood = true
log("onResume-00001")
log("onResume-00001isRefreshPage=$isRefreshPage")
if (presentation == null || !presentation!!.isShowing) {
log("onResume-00002,副屏未显示,加载副屏")
lastWeight = 0.0
@@ -706,6 +718,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
})
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onUpdateRefreshEvent(event: UpdateRefreshEvent) {
isRefreshPage = true
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onPaySuccessEvent(event: PaySuccessEvent) {
isRefreshPage = true
@@ -938,7 +955,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val faceEntity = FaceEntity(
model.userId, null, Base64.decode(model.faceFeatureStr)
).also {
it.userType = "1"
//1-会员、2-临时用户
it.userType = if (model.isMember) "1" else "2"
it.cardNo = model.cardNo
}
faceList.add(faceEntity)
}