desc:修改最大量程相关

main
xiaowusky
parent 62290e3f55
commit 7490cf9bec

@ -159,13 +159,13 @@ fun saveGasUnit(gasType: String, unit: String) {
MMKVUtils.put("unit_$gasType", unit) MMKVUtils.put("unit_$gasType", unit)
} }
/** ///**
* 获取气体传感器量程 // * 获取气体传感器量程
*/ // */
fun getGasRange(gasType: String): String { //fun getGasRange(gasType: String): String {
val typeEnum = getGasTypeEnumByDesc(gasType) // val typeEnum = getGasTypeEnumByDesc(gasType)
return "0~${typeEnum.rangMax} ${getDefaultUnit(gasType)}" // return "0~${typeEnum.rangMax} ${getDefaultUnit(gasType)}"
} //}
fun ppm2mgm3(ppmValue: Float, molecular: Int): Float { fun ppm2mgm3(ppmValue: Float, molecular: Int): Float {
return ppmValue * molecular * PPM_TO_MGM3_CONVERSION_RATE return ppmValue * molecular * PPM_TO_MGM3_CONVERSION_RATE

@ -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.O2
import com.yinuo.safetywatcher.watcher.port.cmd.ResponseHelper import com.yinuo.safetywatcher.watcher.port.cmd.ResponseHelper
import com.yinuo.safetywatcher.watcher.port.cmd.getGasTypeEnumByCode import com.yinuo.safetywatcher.watcher.port.cmd.getGasTypeEnumByCode
import com.yinuo.safetywatcher.watcher.port.cmd.getGasTypeEnumByDesc
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -32,7 +33,7 @@ object ParseHelper {
private val devicesApi by lazy { private val devicesApi by lazy {
DevicesApi() DevicesApi()
} }
private val gasMap = hashMapOf<String, Gas>() private val gasRangeMaxMap = hashMapOf<String, Long>()
private val unConvertValueMap = hashMapOf<String, Float>() private val unConvertValueMap = hashMapOf<String, Float>()
private var mWarnListener: ((String, Warning?) -> Unit)? = null; private var mWarnListener: ((String, Warning?) -> Unit)? = null;
fun setWarnChangeListener(onChange: (String, Warning?) -> Unit) { 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( c18.plus(c17).plus(java.lang.Long.toBinaryString(valueHexLong)).toInt(2) / 10f.pow(
pointNum pointNum
) )
// // 量程 // 量程
// val rangHex: String = HexUtils.byteArrToHex(it, 11, 11 + 2) val rangHex: String = HexUtils.byteArrToHex(it, 11, 11 + 2)
// val rangHexLong: Long = HexUtils.hexToLong(rangHex) val rangHexLong: Long = HexUtils.hexToLong(rangHex)
gasRangeMaxMap[type.desc] = rangHexLong
// // 温度 // // 温度
// val temperatureHex: String = HexUtils.byteArrToHex(it, 17, 17 + 2) // val temperatureHex: String = HexUtils.byteArrToHex(it, 17, 17 + 2)
// val temperature: Long = HexUtils.hexToLong(temperatureHex) // val temperature: Long = HexUtils.hexToLong(temperatureHex)
// 是否超量程 // 是否超量程
val overRange = value > type.rangMax || status == 8 val overRange = value > rangHexLong || status == 8
LogUtils.w("receive msg 单位转换前 $type, 浓度 = $value $unit, 最大量程 = ${type.rangMax}") LogUtils.w("receive msg 单位转换前 $type, 浓度 = $value $unit, 最大量程 = $rangHexLong")
if (overRange) { if (overRange) {
value = type.rangMax.toFloat() value = rangHexLong.toFloat()
} }
value = correctValueByOtherGas(type, value) value = correctValueByOtherGas(type, value)
@ -168,8 +170,8 @@ object ParseHelper {
val warning = dealWarning(typeEnum, value, min, max, unit, overRange) val warning = dealWarning(typeEnum, value, min, max, unit, overRange)
gas.warnTxt = getShowWarnTxt(warning) gas.warnTxt = getShowWarnTxt(warning)
// 存储临时数据 // // 存储临时数据
gasMap[typeEnum.desc] = gas // gasRangeMaxMap[typeEnum.desc] = gas
val gasDao = DBUtils.gasDao() val gasDao = DBUtils.gasDao()
gasDao.insert(gas) gasDao.insert(gas)
@ -361,4 +363,8 @@ object ParseHelper {
} }
return 0f return 0f
} }
fun getGasRangeMax(type: String): Long {
return gasRangeMaxMap[type] ?: getGasTypeEnumByDesc(type).rangMax.toLong()
}
} }

@ -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.CH4_H2
import com.yinuo.safetywatcher.watcher.port.cmd.O2 import com.yinuo.safetywatcher.watcher.port.cmd.O2
import com.yinuo.safetywatcher.watcher.port.cmd.VOCS 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.getLocalGasUnit
import com.yinuo.safetywatcher.watcher.port.saveGasUnit import com.yinuo.safetywatcher.watcher.port.saveGasUnit
import com.yinuo.safetywatcher.watcher.utils.hideIme import com.yinuo.safetywatcher.watcher.utils.hideIme
@ -43,6 +42,7 @@ class SensorSettingActivity : NoOptionsActivity() {
var gasName = "" var gasName = ""
var sensorIndex = -1 var sensorIndex = -1
var showRbView: View? = null
override fun initView() { override fun initView() {
gasName = intent.getStringExtra("GasType")!! gasName = intent.getStringExtra("GasType")!!
@ -53,10 +53,12 @@ class SensorSettingActivity : NoOptionsActivity() {
mBinding.rgUnit.visibility = View.GONE mBinding.rgUnit.visibility = View.GONE
mBinding.rbLel.visibility = View.GONE mBinding.rbLel.visibility = View.GONE
mBinding.rbVol.visibility = View.VISIBLE mBinding.rbVol.visibility = View.VISIBLE
showRbView = mBinding.rbVol
} else if (gasName == CH4_H2) { } else if (gasName == CH4_H2) {
mBinding.rgUnit.visibility = View.GONE mBinding.rgUnit.visibility = View.GONE
mBinding.rbVol.visibility = View.GONE mBinding.rbVol.visibility = View.GONE
mBinding.rbLel.visibility = View.VISIBLE mBinding.rbLel.visibility = View.VISIBLE
showRbView = mBinding.rbLel
} else { } else {
mBinding.rgUnit.visibility = View.VISIBLE mBinding.rgUnit.visibility = View.VISIBLE
mBinding.rbVol.visibility = View.GONE mBinding.rbVol.visibility = View.GONE
@ -66,8 +68,10 @@ class SensorSettingActivity : NoOptionsActivity() {
} }
if (localGasUnit == UNIT_PPM) { if (localGasUnit == UNIT_PPM) {
mBinding.rbPpm.isChecked = true mBinding.rbPpm.isChecked = true
showRbView = mBinding.rbPpm
} else { } else {
mBinding.rbMgm3.isChecked = true mBinding.rbMgm3.isChecked = true
showRbView = mBinding.rbMgm3
} }
} }
@ -82,9 +86,10 @@ class SensorSettingActivity : NoOptionsActivity() {
} else { } else {
mBinding.etName.setText("${gasName}传感器") mBinding.etName.setText("${gasName}传感器")
} }
val gasRange = getGasRange(gasName) val gasRange = ParseHelper.getGasRangeMax(gasName)
mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange") // mBinding.etStep.text = getString(R.string.sensor_step_txt).plus(": $gasRange")
mBinding.etGasName.setText(gasNickName ?: "") mBinding.etStep.hint = "最大量程:$gasRange $localGasUnit"
mBinding.etGasName.hint = "气体名称:$gasNickName"
} }
} }
@ -171,7 +176,7 @@ class SensorSettingActivity : NoOptionsActivity() {
} }
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
if (event.action == KeyEvent.ACTION_DOWN) { if (event.action == KeyEvent.ACTION_DOWN) {
mBinding.tvWarnSetting.requestFocus() mBinding.etStep.requestFocus()
return@setOnKeyListener true return@setOnKeyListener true
} }
} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
@ -183,6 +188,27 @@ class SensorSettingActivity : NoOptionsActivity() {
return@setOnKeyListener false 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 -> mBinding.etName.setOnFocusChangeListener { _, hasFocus ->
if (!hasFocus) { if (!hasFocus) {
mBinding.etName.hideIme() mBinding.etName.hideIme()
@ -227,6 +253,8 @@ class SensorSettingActivity : NoOptionsActivity() {
val gasNickName = mBinding.etGasName.text.toString() val gasNickName = mBinding.etGasName.text.toString()
saveGasNickName(gasName, gasNickName) saveGasNickName(gasName, gasNickName)
// TODO 量程
val checkedRadioButtonId = mBinding.rgUnit.checkedRadioButtonId val checkedRadioButtonId = mBinding.rgUnit.checkedRadioButtonId
var selectedUnit = UNIT_PPM var selectedUnit = UNIT_PPM
if (checkedRadioButtonId == R.id.rb_mgm3) { if (checkedRadioButtonId == R.id.rb_mgm3) {

@ -67,15 +67,18 @@
android:textColorHint="@color/white" android:textColorHint="@color/white"
android:textSize="@dimen/_30dp" /> android:textSize="@dimen/_30dp" />
<TextView <EditText
android:id="@+id/et_step" android:id="@+id/et_step"
android:layout_width="@dimen/_600dp" android:layout_width="@dimen/_600dp"
android:layout_height="@dimen/_100dp" android:layout_height="@dimen/_100dp"
android:layout_marginTop="@dimen/_40dp" android:layout_marginTop="@dimen/_40dp"
android:background="@drawable/cloud_sync_btn_bg" android:background="@drawable/cloud_sync_btn_bg"
android:gravity="center_vertical" android:gravity="center_vertical"
android:focusable="true"
android:hint="@string/sensor_step_txt" android:hint="@string/sensor_step_txt"
android:paddingStart="@dimen/_30dp" android:paddingStart="@dimen/_30dp"
android:inputType="number"
android:nextFocusDown="@id/et_step"
android:textColor="@color/white" android:textColor="@color/white"
android:textColorHint="@color/white" android:textColorHint="@color/white"
android:textSize="@dimen/_30dp" /> android:textSize="@dimen/_30dp" />

Loading…
Cancel
Save