diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt index 4a6b820..92916d3 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/GasUtilss.kt @@ -159,13 +159,13 @@ fun saveGasUnit(gasType: String, unit: String) { MMKVUtils.put("unit_$gasType", unit) } -/** - * 获取气体传感器量程 - */ -fun getGasRange(gasType: String): String { - val typeEnum = getGasTypeEnumByDesc(gasType) - return "0~${typeEnum.rangMax} ${getDefaultUnit(gasType)}" -} +///** +// * 获取气体传感器量程 +// */ +//fun getGasRange(gasType: String): String { +// val typeEnum = getGasTypeEnumByDesc(gasType) +// return "0~${typeEnum.rangMax} ${getDefaultUnit(gasType)}" +//} fun ppm2mgm3(ppmValue: Float, molecular: Int): Float { return ppmValue * molecular * PPM_TO_MGM3_CONVERSION_RATE diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt index 0414f9e..9aa5c3b 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/port/ParseHelper.kt @@ -17,6 +17,7 @@ import com.yinuo.safetywatcher.watcher.port.cmd.GasTypeEnum import com.yinuo.safetywatcher.watcher.port.cmd.O2 import com.yinuo.safetywatcher.watcher.port.cmd.ResponseHelper import com.yinuo.safetywatcher.watcher.port.cmd.getGasTypeEnumByCode +import com.yinuo.safetywatcher.watcher.port.cmd.getGasTypeEnumByDesc import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -32,7 +33,7 @@ object ParseHelper { private val devicesApi by lazy { DevicesApi() } - private val gasMap = hashMapOf() + private val gasRangeMaxMap = hashMapOf() private val unConvertValueMap = hashMapOf() private var mWarnListener: ((String, Warning?) -> Unit)? = null; fun setWarnChangeListener(onChange: (String, Warning?) -> Unit) { @@ -115,17 +116,18 @@ object ParseHelper { c18.plus(c17).plus(java.lang.Long.toBinaryString(valueHexLong)).toInt(2) / 10f.pow( pointNum ) -// // 量程 -// val rangHex: String = HexUtils.byteArrToHex(it, 11, 11 + 2) -// val rangHexLong: Long = HexUtils.hexToLong(rangHex) + // 量程 + val rangHex: String = HexUtils.byteArrToHex(it, 11, 11 + 2) + val rangHexLong: Long = HexUtils.hexToLong(rangHex) + gasRangeMaxMap[type.desc] = rangHexLong // // 温度 // val temperatureHex: String = HexUtils.byteArrToHex(it, 17, 17 + 2) // val temperature: Long = HexUtils.hexToLong(temperatureHex) // 是否超量程 - val overRange = value > type.rangMax || status == 8 - LogUtils.w("receive msg 单位转换前 $type, 浓度 = $value $unit, 最大量程 = ${type.rangMax}") + val overRange = value > rangHexLong || status == 8 + LogUtils.w("receive msg 单位转换前 $type, 浓度 = $value $unit, 最大量程 = $rangHexLong") if (overRange) { - value = type.rangMax.toFloat() + value = rangHexLong.toFloat() } value = correctValueByOtherGas(type, value) @@ -168,8 +170,8 @@ object ParseHelper { val warning = dealWarning(typeEnum, value, min, max, unit, overRange) gas.warnTxt = getShowWarnTxt(warning) - // 存储临时数据 - gasMap[typeEnum.desc] = gas +// // 存储临时数据 +// gasRangeMaxMap[typeEnum.desc] = gas val gasDao = DBUtils.gasDao() gasDao.insert(gas) @@ -361,4 +363,8 @@ object ParseHelper { } return 0f } + + fun getGasRangeMax(type: String): Long { + return gasRangeMaxMap[type] ?: getGasTypeEnumByDesc(type).rangMax.toLong() + } } \ No newline at end of file diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt index ff7d7af..015a487 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/SensorSettingActivity.kt @@ -18,7 +18,6 @@ import com.yinuo.safetywatcher.watcher.port.UNIT_PPM import com.yinuo.safetywatcher.watcher.port.cmd.CH4_H2 import com.yinuo.safetywatcher.watcher.port.cmd.O2 import com.yinuo.safetywatcher.watcher.port.cmd.VOCS -import com.yinuo.safetywatcher.watcher.port.getGasRange import com.yinuo.safetywatcher.watcher.port.getLocalGasUnit import com.yinuo.safetywatcher.watcher.port.saveGasUnit import com.yinuo.safetywatcher.watcher.utils.hideIme @@ -43,6 +42,7 @@ class SensorSettingActivity : NoOptionsActivity() { var gasName = "" var sensorIndex = -1 + var showRbView: View? = null override fun initView() { gasName = intent.getStringExtra("GasType")!! @@ -53,10 +53,12 @@ class SensorSettingActivity : NoOptionsActivity() { mBinding.rgUnit.visibility = View.GONE mBinding.rbLel.visibility = View.GONE mBinding.rbVol.visibility = View.VISIBLE + showRbView = mBinding.rbVol } else if (gasName == CH4_H2) { mBinding.rgUnit.visibility = View.GONE mBinding.rbVol.visibility = View.GONE mBinding.rbLel.visibility = View.VISIBLE + showRbView = mBinding.rbLel } else { mBinding.rgUnit.visibility = View.VISIBLE mBinding.rbVol.visibility = View.GONE @@ -66,8 +68,10 @@ class SensorSettingActivity : NoOptionsActivity() { } if (localGasUnit == UNIT_PPM) { mBinding.rbPpm.isChecked = true + showRbView = mBinding.rbPpm } else { mBinding.rbMgm3.isChecked = true + showRbView = mBinding.rbMgm3 } } @@ -82,9 +86,10 @@ class SensorSettingActivity : NoOptionsActivity() { } else { mBinding.etName.setText("${gasName}传感器") } - val gasRange = getGasRange(gasName) - mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange") - mBinding.etGasName.setText(gasNickName ?: "") + val gasRange = ParseHelper.getGasRangeMax(gasName) +// mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange") + mBinding.etStep.hint = "最大量程:$gasRange $localGasUnit" + mBinding.etGasName.hint = "气体名称:$gasNickName" } } @@ -171,7 +176,7 @@ class SensorSettingActivity : NoOptionsActivity() { } } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { if (event.action == KeyEvent.ACTION_DOWN) { - mBinding.tvWarnSetting.requestFocus() + mBinding.etStep.requestFocus() return@setOnKeyListener true } } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { @@ -183,6 +188,27 @@ class SensorSettingActivity : NoOptionsActivity() { return@setOnKeyListener false } + mBinding.etStep.setOnKeyListener { v, keyCode, event -> + if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { + if (event.action == KeyEvent.ACTION_DOWN) { + mBinding.etGasName.requestFocus() + return@setOnKeyListener true + } + } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { + if (event.action == KeyEvent.ACTION_DOWN) { +// mBinding.tvWarnSetting.requestFocus() + showRbView?.requestFocus() ?: mBinding.tvWarnSetting.requestFocus() + return@setOnKeyListener true + } + } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { + if (event.action == KeyEvent.ACTION_DOWN) { + mBinding.etStep.showIme() + return@setOnKeyListener true + } + } + return@setOnKeyListener false + } + mBinding.etName.setOnFocusChangeListener { _, hasFocus -> if (!hasFocus) { mBinding.etName.hideIme() @@ -227,6 +253,8 @@ class SensorSettingActivity : NoOptionsActivity() { val gasNickName = mBinding.etGasName.text.toString() saveGasNickName(gasName, gasNickName) + // TODO 量程 + val checkedRadioButtonId = mBinding.rgUnit.checkedRadioButtonId var selectedUnit = UNIT_PPM if (checkedRadioButtonId == R.id.rb_mgm3) { diff --git a/app/src/main/res/layout/activity_sensor_setting.xml b/app/src/main/res/layout/activity_sensor_setting.xml index c03e105..1f0cd5b 100644 --- a/app/src/main/res/layout/activity_sensor_setting.xml +++ b/app/src/main/res/layout/activity_sensor_setting.xml @@ -67,15 +67,18 @@ android:textColorHint="@color/white" android:textSize="@dimen/_30dp" /> -