diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index b17358d..a4540ca 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -43,6 +43,7 @@ import com.casic.detector.databinding.ActivityMainBinding import com.casic.detector.databinding.DialogInstallMarkerBinding import com.casic.detector.databinding.DialogSearchMarkerBinding +import com.casic.detector.databinding.DialogSearchMarkerNewBinding import com.casic.detector.extensions.appendDownloadUrl import com.casic.detector.extensions.compressImage import com.casic.detector.extensions.drawCircle @@ -117,6 +118,7 @@ private val backDrawables by lazy { HashMap() } private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } + private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -133,7 +135,7 @@ /***inner class 需要用到*****start*/ private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) + .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() @@ -359,7 +361,8 @@ /** * 改为Dialog方式,避免频繁打开/关闭串口 * */ - searchDialog.show() +// searchDialog.show() + searchNewDialog.show() } //自由巡检 @@ -421,6 +424,8 @@ Log.d(kTag, "$kTag => $hex") if (searchDialog.isDetectMarker) { searchDialog.bindingValue(hex) + } else if (searchNewDialog.isDetectMarker) { + searchNewDialog.bindingValue(hex) } else if (installDialog.isReadMarker) { val markerId = hex.take(20).hexToString() if (markerId.isNumber()) { @@ -1415,4 +1420,217 @@ super.dismiss() } } + + /**探测标识器新对话框****************************************************************************/ + inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + + private val binding: DialogSearchMarkerNewBinding by binding() + private val decimal by lazy { DecimalFormat("0.0") } + private var isPlaying = false + private var markerId = "" + private lateinit var searchMarkerTimer: Timer + private lateinit var signalTask: TimerTask + private lateinit var energyTask: TimerTask + private lateinit var countDownTimer: CountDownTimer + + var isDetectMarker = false + var taskBean: TaskBean? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + this.initDialogLayoutParams(1f) + binding.depthButton.setOnClickListener { + signalTask.cancel() + energyTask.cancel() + searchMarkerTimer.cancel() + + out.write('3'.code) + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isNotEmpty()) { + val tag = when (result.first().identifierType) { + "EM30" -> '7' + "EM50" -> '8' + "EM14" -> '9' + else -> '1' + } + if (tag == '1') { + "此标识器无法读取埋深!".show(context) + } else { + // 发送读取标识器埋设深度指令 + LoadingDialogHub.show(this@MainActivity, "正在测距,请稍后...") + out.write(tag.code) + out.flush() + countDownTimer = object : CountDownTimer(15 * 1000, 1000) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + LoadingDialogHub.dismiss() + "探测此标识器深度超时,请重试".show(context) + initTimer() + } + } + countDownTimer.start() + } + } else { + "标识器未安装,安装成功后才可读取埋深!".show(context) + } + } + + binding.markerInfoButton.setOnClickListener { + //查库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isNotEmpty()) { + context.navigatePageTo(result.first().toJson()) + } else { + context.navigatePageTo(markerId) + } + } + } + + override fun onStart() { + super.onStart() + //调高串口电位 + gpioManager.setGpioHigh("18") + + initTimer() + + isDetectMarker = true + } + + fun bindingValue(hex: String) { + if (hex.startsWith("4E")) { + try { + //4E转为String为N,代表能量值 + //用能量值转动表盘 + val energyResponse = hex.take(10).hexToString() + val energy = energyResponse.substring(1).toInt() + if (energy >= 4000) { + isPlaying = if (!isPlaying) { + soundPool.play(fastSoundResourceId, 1f, 1f, 0, 0, 1f) + true + } else { + soundPool.pause(fastSoundResourceId) + false + } + } else { + isPlaying = if (!isPlaying) { + soundPool.play(slowSoundResourceId, 1f, 1f, 0, 0, 1f) + true + } else { + soundPool.pause(slowSoundResourceId) + false + } + } + + //通过设置进度条表示能量值 + binding.energyPgBar.progress = energy + binding.energyValueView.text = "${energy}dB" + + if (energy <= 700) {//18° + binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) + + binding.depthButton.isEnabled = false + binding.depthButton.setTextColor(Color.parseColor("#CCCCCC")) + binding.depthButton.setBackgroundResource(R.mipmap.left_button_disable) + binding.markerInfoButton.isEnabled = false + binding.markerInfoButton.setTextColor(Color.parseColor("#CCCCCC")) + binding.markerInfoButton.setBackgroundResource(R.mipmap.right_button_disable) + + binding.searchResultView.text = "未检测到标识器" + binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) + binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) + } else if (energy >= 4100) { + binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) + } else { + binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) + } + } catch (e: NumberFormatException) { + e.printStackTrace() + } + } else if (hex.startsWith("53")) { + LoadingDialogHub.dismiss() + countDownTimer.cancel() + try { + val depthResponse = hex.take(10).hexToString() + val depth = depthResponse.drop(2).toInt() + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") + .setOnDialogButtonClickListener(object : + AlertMessageDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + initTimer() + } + }).build().show() + } catch (e: NumberFormatException) { + e.printStackTrace() + } + } else { + val id = hex.take(20).hexToString() + if (id.isNumber()) { + markerId = id + + binding.depthButton.isEnabled = true + binding.depthButton.setTextColor(Color.WHITE) + binding.depthButton.setBackgroundResource(R.mipmap.left_button_enable) + binding.markerInfoButton.isEnabled = true + binding.markerInfoButton.setTextColor(Color.WHITE) + binding.markerInfoButton.setBackgroundResource(R.mipmap.right_button_enable) + + binding.searchResultView.text = "已检测到标识器" + binding.searchResultView.setTextColor(Color.parseColor("#428d00")) + binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_green) + + //自动上传标识器 + taskBean = DataBaseManager.get.queryTaskLabelByIdAndState(markerId, "未开始") +// taskBean?.apply { +// /** +// * 此taskCode是 [com.casic.detector.model.TaskModel.MessageModel.TaskDetailInfosModel] 里面的主键,也就是这个标签在数据库里面的主键 +// * */ +// taskViewModel.uploadMarker(taskCode) +// } + } + } + } + + private fun initTimer() { + searchMarkerTimer = Timer() + + signalTask = object : TimerTask() { + override fun run() { + out.write('2'.code) + out.flush() + } + } + + energyTask = object : TimerTask() { + override fun run() { + out.write('6'.code) + out.flush() + } + } + + //错开信号和能量定时器 + searchMarkerTimer.schedule(signalTask, 0, 201) + searchMarkerTimer.schedule(energyTask, 0, 251) + } + + override fun dismiss() { + signalTask.cancel() + energyTask.cancel() + searchMarkerTimer.cancel() + //降低串口电位 + gpioManager.setGpioLow("18") + isDetectMarker = false + soundPool.autoPause() + super.dismiss() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index b17358d..a4540ca 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -43,6 +43,7 @@ import com.casic.detector.databinding.ActivityMainBinding import com.casic.detector.databinding.DialogInstallMarkerBinding import com.casic.detector.databinding.DialogSearchMarkerBinding +import com.casic.detector.databinding.DialogSearchMarkerNewBinding import com.casic.detector.extensions.appendDownloadUrl import com.casic.detector.extensions.compressImage import com.casic.detector.extensions.drawCircle @@ -117,6 +118,7 @@ private val backDrawables by lazy { HashMap() } private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } + private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -133,7 +135,7 @@ /***inner class 需要用到*****start*/ private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) + .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() @@ -359,7 +361,8 @@ /** * 改为Dialog方式,避免频繁打开/关闭串口 * */ - searchDialog.show() +// searchDialog.show() + searchNewDialog.show() } //自由巡检 @@ -421,6 +424,8 @@ Log.d(kTag, "$kTag => $hex") if (searchDialog.isDetectMarker) { searchDialog.bindingValue(hex) + } else if (searchNewDialog.isDetectMarker) { + searchNewDialog.bindingValue(hex) } else if (installDialog.isReadMarker) { val markerId = hex.take(20).hexToString() if (markerId.isNumber()) { @@ -1415,4 +1420,217 @@ super.dismiss() } } + + /**探测标识器新对话框****************************************************************************/ + inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + + private val binding: DialogSearchMarkerNewBinding by binding() + private val decimal by lazy { DecimalFormat("0.0") } + private var isPlaying = false + private var markerId = "" + private lateinit var searchMarkerTimer: Timer + private lateinit var signalTask: TimerTask + private lateinit var energyTask: TimerTask + private lateinit var countDownTimer: CountDownTimer + + var isDetectMarker = false + var taskBean: TaskBean? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + this.initDialogLayoutParams(1f) + binding.depthButton.setOnClickListener { + signalTask.cancel() + energyTask.cancel() + searchMarkerTimer.cancel() + + out.write('3'.code) + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isNotEmpty()) { + val tag = when (result.first().identifierType) { + "EM30" -> '7' + "EM50" -> '8' + "EM14" -> '9' + else -> '1' + } + if (tag == '1') { + "此标识器无法读取埋深!".show(context) + } else { + // 发送读取标识器埋设深度指令 + LoadingDialogHub.show(this@MainActivity, "正在测距,请稍后...") + out.write(tag.code) + out.flush() + countDownTimer = object : CountDownTimer(15 * 1000, 1000) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + LoadingDialogHub.dismiss() + "探测此标识器深度超时,请重试".show(context) + initTimer() + } + } + countDownTimer.start() + } + } else { + "标识器未安装,安装成功后才可读取埋深!".show(context) + } + } + + binding.markerInfoButton.setOnClickListener { + //查库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isNotEmpty()) { + context.navigatePageTo(result.first().toJson()) + } else { + context.navigatePageTo(markerId) + } + } + } + + override fun onStart() { + super.onStart() + //调高串口电位 + gpioManager.setGpioHigh("18") + + initTimer() + + isDetectMarker = true + } + + fun bindingValue(hex: String) { + if (hex.startsWith("4E")) { + try { + //4E转为String为N,代表能量值 + //用能量值转动表盘 + val energyResponse = hex.take(10).hexToString() + val energy = energyResponse.substring(1).toInt() + if (energy >= 4000) { + isPlaying = if (!isPlaying) { + soundPool.play(fastSoundResourceId, 1f, 1f, 0, 0, 1f) + true + } else { + soundPool.pause(fastSoundResourceId) + false + } + } else { + isPlaying = if (!isPlaying) { + soundPool.play(slowSoundResourceId, 1f, 1f, 0, 0, 1f) + true + } else { + soundPool.pause(slowSoundResourceId) + false + } + } + + //通过设置进度条表示能量值 + binding.energyPgBar.progress = energy + binding.energyValueView.text = "${energy}dB" + + if (energy <= 700) {//18° + binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) + + binding.depthButton.isEnabled = false + binding.depthButton.setTextColor(Color.parseColor("#CCCCCC")) + binding.depthButton.setBackgroundResource(R.mipmap.left_button_disable) + binding.markerInfoButton.isEnabled = false + binding.markerInfoButton.setTextColor(Color.parseColor("#CCCCCC")) + binding.markerInfoButton.setBackgroundResource(R.mipmap.right_button_disable) + + binding.searchResultView.text = "未检测到标识器" + binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) + binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) + } else if (energy >= 4100) { + binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) + } else { + binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) + } + } catch (e: NumberFormatException) { + e.printStackTrace() + } + } else if (hex.startsWith("53")) { + LoadingDialogHub.dismiss() + countDownTimer.cancel() + try { + val depthResponse = hex.take(10).hexToString() + val depth = depthResponse.drop(2).toInt() + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") + .setOnDialogButtonClickListener(object : + AlertMessageDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + initTimer() + } + }).build().show() + } catch (e: NumberFormatException) { + e.printStackTrace() + } + } else { + val id = hex.take(20).hexToString() + if (id.isNumber()) { + markerId = id + + binding.depthButton.isEnabled = true + binding.depthButton.setTextColor(Color.WHITE) + binding.depthButton.setBackgroundResource(R.mipmap.left_button_enable) + binding.markerInfoButton.isEnabled = true + binding.markerInfoButton.setTextColor(Color.WHITE) + binding.markerInfoButton.setBackgroundResource(R.mipmap.right_button_enable) + + binding.searchResultView.text = "已检测到标识器" + binding.searchResultView.setTextColor(Color.parseColor("#428d00")) + binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_green) + + //自动上传标识器 + taskBean = DataBaseManager.get.queryTaskLabelByIdAndState(markerId, "未开始") +// taskBean?.apply { +// /** +// * 此taskCode是 [com.casic.detector.model.TaskModel.MessageModel.TaskDetailInfosModel] 里面的主键,也就是这个标签在数据库里面的主键 +// * */ +// taskViewModel.uploadMarker(taskCode) +// } + } + } + } + + private fun initTimer() { + searchMarkerTimer = Timer() + + signalTask = object : TimerTask() { + override fun run() { + out.write('2'.code) + out.flush() + } + } + + energyTask = object : TimerTask() { + override fun run() { + out.write('6'.code) + out.flush() + } + } + + //错开信号和能量定时器 + searchMarkerTimer.schedule(signalTask, 0, 201) + searchMarkerTimer.schedule(energyTask, 0, 251) + } + + override fun dismiss() { + signalTask.cancel() + energyTask.cancel() + searchMarkerTimer.cancel() + //降低串口电位 + gpioManager.setGpioLow("18") + isDetectMarker = false + soundPool.autoPause() + super.dismiss() + } + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_progress_bar.xml b/app/src/main/res/drawable/bg_progress_bar.xml new file mode 100644 index 0000000..8a6cd5f --- /dev/null +++ b/app/src/main/res/drawable/bg_progress_bar.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index b17358d..a4540ca 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -43,6 +43,7 @@ import com.casic.detector.databinding.ActivityMainBinding import com.casic.detector.databinding.DialogInstallMarkerBinding import com.casic.detector.databinding.DialogSearchMarkerBinding +import com.casic.detector.databinding.DialogSearchMarkerNewBinding import com.casic.detector.extensions.appendDownloadUrl import com.casic.detector.extensions.compressImage import com.casic.detector.extensions.drawCircle @@ -117,6 +118,7 @@ private val backDrawables by lazy { HashMap() } private val installDialog by lazy { InstallMarkerDialog(this) } private val searchDialog by lazy { SearchMarkerDialog(this) } + private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private var clickTime: Long = 0 private var labelBeans = ArrayList() private var clusterOverlay: ClusterOverlay? = null @@ -133,7 +135,7 @@ /***inner class 需要用到*****start*/ private val taskViewModel by lazy { ViewModelProvider(this)[TaskViewModel::class.java] } private val attr = AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) + .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build() private val soundPool = SoundPool.Builder().setMaxStreams(16).setAudioAttributes(attr).build() @@ -359,7 +361,8 @@ /** * 改为Dialog方式,避免频繁打开/关闭串口 * */ - searchDialog.show() +// searchDialog.show() + searchNewDialog.show() } //自由巡检 @@ -421,6 +424,8 @@ Log.d(kTag, "$kTag => $hex") if (searchDialog.isDetectMarker) { searchDialog.bindingValue(hex) + } else if (searchNewDialog.isDetectMarker) { + searchNewDialog.bindingValue(hex) } else if (installDialog.isReadMarker) { val markerId = hex.take(20).hexToString() if (markerId.isNumber()) { @@ -1415,4 +1420,217 @@ super.dismiss() } } + + /**探测标识器新对话框****************************************************************************/ + inner class SearchMarkerNewDialog(context: Context) : Dialog(context) { + + private val binding: DialogSearchMarkerNewBinding by binding() + private val decimal by lazy { DecimalFormat("0.0") } + private var isPlaying = false + private var markerId = "" + private lateinit var searchMarkerTimer: Timer + private lateinit var signalTask: TimerTask + private lateinit var energyTask: TimerTask + private lateinit var countDownTimer: CountDownTimer + + var isDetectMarker = false + var taskBean: TaskBean? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + this.initDialogLayoutParams(1f) + binding.depthButton.setOnClickListener { + signalTask.cancel() + energyTask.cancel() + searchMarkerTimer.cancel() + + out.write('3'.code) + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isNotEmpty()) { + val tag = when (result.first().identifierType) { + "EM30" -> '7' + "EM50" -> '8' + "EM14" -> '9' + else -> '1' + } + if (tag == '1') { + "此标识器无法读取埋深!".show(context) + } else { + // 发送读取标识器埋设深度指令 + LoadingDialogHub.show(this@MainActivity, "正在测距,请稍后...") + out.write(tag.code) + out.flush() + countDownTimer = object : CountDownTimer(15 * 1000, 1000) { + override fun onTick(millisUntilFinished: Long) { + + } + + override fun onFinish() { + LoadingDialogHub.dismiss() + "探测此标识器深度超时,请重试".show(context) + initTimer() + } + } + countDownTimer.start() + } + } else { + "标识器未安装,安装成功后才可读取埋深!".show(context) + } + } + + binding.markerInfoButton.setOnClickListener { + //查库 + val result = DataBaseManager.get.queryLabelById(markerId) + if (result.isNotEmpty()) { + context.navigatePageTo(result.first().toJson()) + } else { + context.navigatePageTo(markerId) + } + } + } + + override fun onStart() { + super.onStart() + //调高串口电位 + gpioManager.setGpioHigh("18") + + initTimer() + + isDetectMarker = true + } + + fun bindingValue(hex: String) { + if (hex.startsWith("4E")) { + try { + //4E转为String为N,代表能量值 + //用能量值转动表盘 + val energyResponse = hex.take(10).hexToString() + val energy = energyResponse.substring(1).toInt() + if (energy >= 4000) { + isPlaying = if (!isPlaying) { + soundPool.play(fastSoundResourceId, 1f, 1f, 0, 0, 1f) + true + } else { + soundPool.pause(fastSoundResourceId) + false + } + } else { + isPlaying = if (!isPlaying) { + soundPool.play(slowSoundResourceId, 1f, 1f, 0, 0, 1f) + true + } else { + soundPool.pause(slowSoundResourceId) + false + } + } + + //通过设置进度条表示能量值 + binding.energyPgBar.progress = energy + binding.energyValueView.text = "${energy}dB" + + if (energy <= 700) {//18° + binding.energyTipsView.text = "标识器信号较弱,可能距离较远" + binding.energyTipsView.setTextColor(Color.parseColor("#8D1717")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_red) + + binding.depthButton.isEnabled = false + binding.depthButton.setTextColor(Color.parseColor("#CCCCCC")) + binding.depthButton.setBackgroundResource(R.mipmap.left_button_disable) + binding.markerInfoButton.isEnabled = false + binding.markerInfoButton.setTextColor(Color.parseColor("#CCCCCC")) + binding.markerInfoButton.setBackgroundResource(R.mipmap.right_button_disable) + + binding.searchResultView.text = "未检测到标识器" + binding.searchResultView.setTextColor(Color.parseColor("#8D1717")) + binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_red) + } else if (energy >= 4100) { + binding.energyTipsView.text = "标识器信号极强,可能在正下方" + binding.energyTipsView.setTextColor(Color.parseColor("#428d00")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_green) + } else { + binding.energyTipsView.text = "已靠近标识器,请继续移动位置" + binding.energyTipsView.setTextColor(Color.parseColor("#8C5700")) + binding.energyTipsView.setBackgroundResource(R.mipmap.bg_large_text_yellow) + } + } catch (e: NumberFormatException) { + e.printStackTrace() + } + } else if (hex.startsWith("53")) { + LoadingDialogHub.dismiss() + countDownTimer.cancel() + try { + val depthResponse = hex.take(10).hexToString() + val depth = depthResponse.drop(2).toInt() + AlertMessageDialog.Builder().setContext(context).setTitle("温馨提示") + .setMessage("标识器埋深:${depth}厘米").setPositiveButton("知道了") + .setOnDialogButtonClickListener(object : + AlertMessageDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + initTimer() + } + }).build().show() + } catch (e: NumberFormatException) { + e.printStackTrace() + } + } else { + val id = hex.take(20).hexToString() + if (id.isNumber()) { + markerId = id + + binding.depthButton.isEnabled = true + binding.depthButton.setTextColor(Color.WHITE) + binding.depthButton.setBackgroundResource(R.mipmap.left_button_enable) + binding.markerInfoButton.isEnabled = true + binding.markerInfoButton.setTextColor(Color.WHITE) + binding.markerInfoButton.setBackgroundResource(R.mipmap.right_button_enable) + + binding.searchResultView.text = "已检测到标识器" + binding.searchResultView.setTextColor(Color.parseColor("#428d00")) + binding.searchResultView.setBackgroundResource(R.mipmap.bg_small_text_green) + + //自动上传标识器 + taskBean = DataBaseManager.get.queryTaskLabelByIdAndState(markerId, "未开始") +// taskBean?.apply { +// /** +// * 此taskCode是 [com.casic.detector.model.TaskModel.MessageModel.TaskDetailInfosModel] 里面的主键,也就是这个标签在数据库里面的主键 +// * */ +// taskViewModel.uploadMarker(taskCode) +// } + } + } + } + + private fun initTimer() { + searchMarkerTimer = Timer() + + signalTask = object : TimerTask() { + override fun run() { + out.write('2'.code) + out.flush() + } + } + + energyTask = object : TimerTask() { + override fun run() { + out.write('6'.code) + out.flush() + } + } + + //错开信号和能量定时器 + searchMarkerTimer.schedule(signalTask, 0, 201) + searchMarkerTimer.schedule(energyTask, 0, 251) + } + + override fun dismiss() { + signalTask.cancel() + energyTask.cancel() + searchMarkerTimer.cancel() + //降低串口电位 + gpioManager.setGpioLow("18") + isDetectMarker = false + soundPool.autoPause() + super.dismiss() + } + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_progress_bar.xml b/app/src/main/res/drawable/bg_progress_bar.xml new file mode 100644 index 0000000..8a6cd5f --- /dev/null +++ b/app/src/main/res/drawable/bg_progress_bar.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_search_demo.xml b/app/src/main/res/layout/activity_search_demo.xml deleted file mode 100644 index dbe732b..0000000 --- a/app/src/main/res/layout/activity_search_demo.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - -