refactor(device): 优化设备角色判断和串口配置逻辑
- 移除 Weigher2 的初始化代码从 InitActivity 到 BaseApp - 将设备角色判断与串口配置逻辑合并到应用启动流程中 - 主设备配置为 /dev/ttyS7,子设备配置为 /dev/ttyS4 - 简化设备角色分配的条件判断逻辑
This commit is contained in:
@@ -13,6 +13,7 @@ import com.shuwei.dish.match.ui.InitActivity.Companion.TAG
|
|||||||
import com.shuwei.dish.match.utils.AppUtil
|
import com.shuwei.dish.match.utils.AppUtil
|
||||||
import com.shuwei.dish.match.utils.BootReceiver
|
import com.shuwei.dish.match.utils.BootReceiver
|
||||||
import com.shuwei.dish.match.utils.CrashHandler
|
import com.shuwei.dish.match.utils.CrashHandler
|
||||||
|
import com.shuwei.dish.match.utils.Weigher2
|
||||||
|
|
||||||
|
|
||||||
class BaseApp : Application() {
|
class BaseApp : Application() {
|
||||||
@@ -28,10 +29,13 @@ class BaseApp : Application() {
|
|||||||
GlobalData.deviceId = deviceId
|
GlobalData.deviceId = deviceId
|
||||||
|
|
||||||
// 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
// 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
||||||
GlobalData.deviceRole = if (deviceId == "8fc2ab34-2137-3112-acca-f884ea8736d4") {
|
// 主设备是/dev/ttyS7,子设备是/dev/ttyS4
|
||||||
DeviceRole.MASTER
|
if (deviceId == "8fc2ab34-2137-3112-acca-f884ea8736d4") {
|
||||||
|
GlobalData.deviceRole = DeviceRole.MASTER
|
||||||
|
Weigher2.setDevicePort("/dev/ttyS7")
|
||||||
} else {
|
} else {
|
||||||
DeviceRole.SLAVE
|
GlobalData.deviceRole = DeviceRole.SLAVE
|
||||||
|
Weigher2.setDevicePort("/dev/ttyS4")
|
||||||
}
|
}
|
||||||
Log.d(TAG, "设备角色: ${GlobalData.deviceRole}")
|
Log.d(TAG, "设备角色: ${GlobalData.deviceRole}")
|
||||||
|
|
||||||
|
|||||||
@@ -58,14 +58,6 @@ class InitActivity : BaseActivity() {
|
|||||||
|
|
||||||
initViewModel()
|
initViewModel()
|
||||||
|
|
||||||
// 主设备上/dev/ttyS7,子设备是/dev/ttyS4
|
|
||||||
Weigher2.setDevicePort(
|
|
||||||
if (GlobalData.deviceId == "8fc2ab34-2137-3112-acca-f884ea8736d4") {
|
|
||||||
"/dev/ttyS7"
|
|
||||||
} else {
|
|
||||||
"/dev/ttyS4"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
WeightUtil.init()
|
WeightUtil.init()
|
||||||
WeightUtil.getWeight()
|
WeightUtil.getWeight()
|
||||||
WeightUtil.startContinuousRead()
|
WeightUtil.startContinuousRead()
|
||||||
|
|||||||
Reference in New Issue
Block a user