fix(shelf): 实现负漂移抑制以提高重量显示准确性

- 在ShelfV3Activity中针对-5克以内的负读数做归零处理,避免误导显示
- 修改获取重量逻辑,保证显示重量与真实重量区分
- 在ShelfV3Adapter中对空秤零点附近的小负重量做归零处理
- 优化重量单位显示逻辑,根据负漂移抑制后的值显示克或千克
- 更新local.properties中SDK路径配置
This commit is contained in:
mazengfei
2026-07-13 18:26:16 +08:00
parent 7ab8e09a46
commit 23d211bfdb
3 changed files with 13 additions and 7 deletions
@@ -155,8 +155,10 @@ class ShelfV3Activity : BaseActivity() {
binding.tvVegTypeName.text = model.vegTypeName
val weightG = model.weight ?: 0.0
realWeight = (weightG * 1000.0).toInt()
// 负漂移抑制:-5克以内的负读数显示时归零(realWeight 保持真实值)
val displayWeight = if (realWeight in -5..0) 0 else realWeight
binding.tvFoodWeight.text = if (weightG >= 1.0) "%.3f千克".format(weightG)
else "${realWeight}"
else "${displayWeight}"
startTime = System.currentTimeMillis()
}
@@ -354,8 +356,10 @@ class ShelfV3Activity : BaseActivity() {
val intervalTime = System.currentTimeMillis() - startTime
val weight = event.weight
log("格口${shelfModel?.slotNo}获取重量:${weight}克,间隔:${intervalTime}ms")
binding.tvFoodWeight.text = if (weight < 1000) "${weight}"
else "%.3f千克".format(weight / 1000.0)
// 负漂移抑制:-5克以内的负读数显示时归零
val displayWeight = if (weight in -5..0) 0 else weight
binding.tvFoodWeight.text = if (displayWeight < 1000) "${displayWeight}"
else "%.3f千克".format(displayWeight / 1000.0)
startTime = System.currentTimeMillis()
window.decorView.postDelayed({ Loading.dismiss() }, 1000)
}
@@ -43,10 +43,12 @@ class ShelfV3Adapter(list: MutableList<SlotModel>) :
binding.tvShelfName.text = item.slotNo.padStart(2, '0')
val weightG = item.weight ?: 0.0
// 负漂移抑制:空秤零点可能出现 -5克以内的负读数,显示时归零
val displayG = if (weightG in -0.005..0.0) 0.0 else weightG
binding.tvFoodWeight.run {
setTextColor(getColor(R.color.food_weight_orange))
text = if (abs(weightG) >= 1.0) "%.3f千克".format(weightG)
else "${(weightG * 1000.0).toInt()}"
text = if (abs(displayG) >= 1.0) "%.3f千克".format(displayG)
else "${(displayG * 1000.0).toInt()}"
}
val isBlank = item.materName.isNullOrBlank()
+2 -2
View File
@@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Fri Jun 26 09:17:18 CST 2026
sdk.dir=D\:\\Android\\sdk
#Thu Jul 02 16:04:28 CST 2026
sdk.dir=C\:\\Users\\MZF\\AppData\\Local\\Android\\Sdk