串口数据处理

This commit is contained in:
马增飞
2025-08-06 19:31:18 +08:00
parent f0f89982be
commit 005e7eae53
8 changed files with 43 additions and 6 deletions
@@ -9,6 +9,7 @@ import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
@@ -37,6 +38,7 @@ import kotlin.random.Random
class ShelfActivity : BaseActivity() {
companion object {
private const val TAG = "ShelfActivity"
const val SHELF_MODEL = "shelfModel"
const val RECEIVER_DEVICE_INFO = "receiverDeviceInfo"
const val SHELF_WEIGHT = "shelfWeight"
@@ -119,6 +121,8 @@ class ShelfActivity : BaseActivity() {
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
intent?.let {
val data = it.getStringExtra(RECEIVER_DEVICE_INFO)
Log.d(TAG, "onReceive: $data")
realWeight = it.getIntExtra(SHELF_WEIGHT, 0)
binding.tvFoodWeight.text = "${realWeight}"
}