desc:气泵转速设置

main
xiaowusky 1 year ago
parent c9c7a4838f
commit e7a78ef572

@ -46,6 +46,8 @@ object GasPortUtils {
ComMultiPortUtils.sendMsg(PORT_PATH, CMD.SENSOR_3) ComMultiPortUtils.sendMsg(PORT_PATH, CMD.SENSOR_3)
Thread.sleep(READ_MSG_INTERVAL) Thread.sleep(READ_MSG_INTERVAL)
ComMultiPortUtils.sendMsg(PORT_PATH, CMD.SENSOR_4) ComMultiPortUtils.sendMsg(PORT_PATH, CMD.SENSOR_4)
Thread.sleep(READ_MSG_INTERVAL)
ComMultiPortUtils.sendMsg(PORT_PATH, CMD.SENSOR_5)
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
@ -55,4 +57,8 @@ object GasPortUtils {
readGasMsgThread!!.start() readGasMsgThread!!.start()
} }
} }
fun setSpeed(speed: Int) {
ComMultiPortUtils.sendMsg(PORT_PATH, CMD.buildSpeedCmd(speed))
}
} }

@ -2,9 +2,20 @@ package com.yinuo.safetywatcher.watcher.port.cmd
class CMD { class CMD {
companion object { companion object {
fun buildSpeedCmd(speed: Int): ByteArray {
var legalSpeed = speed
if (speed < 0) {
legalSpeed = 0
} else if (speed > 9) {
legalSpeed = 9
}
return byteArrayOf(0x01, 0x06, 0x05, 0x00, 0x00, legalSpeed.toByte()).crc16()
}
val SENSOR_1 = byteArrayOf(0x01, 0x03, 0x00, 0x00, 0x00, 0x0A).crc16() val SENSOR_1 = byteArrayOf(0x01, 0x03, 0x00, 0x00, 0x00, 0x0A).crc16()
val SENSOR_2 = byteArrayOf(0x01, 0x03, 0x01, 0x00, 0x00, 0x0A).crc16() val SENSOR_2 = byteArrayOf(0x01, 0x03, 0x01, 0x00, 0x00, 0x0A).crc16()
val SENSOR_3 = byteArrayOf(0x01, 0x03, 0x02, 0x00, 0x00, 0x0A).crc16() val SENSOR_3 = byteArrayOf(0x01, 0x03, 0x02, 0x00, 0x00, 0x0A).crc16()
val SENSOR_4 = byteArrayOf(0x01, 0x03, 0x03, 0x00, 0x00, 0x0A).crc16() val SENSOR_4 = byteArrayOf(0x01, 0x03, 0x03, 0x00, 0x00, 0x0A).crc16()
val SENSOR_5 = byteArrayOf(0x01, 0x03, 0x04, 0x00, 0x00, 0x0A).crc16()
} }
} }

@ -157,8 +157,9 @@ class HomeActivity : NoOptionsActivity() {
//mHasSensorData = true //mHasSensorData = true
mBinding.errorView.visibility = mBinding.errorView.visibility =
if (!AppData.hasCameraData()) View.VISIBLE else View.GONE if (!AppData.hasCameraData()) View.VISIBLE else View.GONE
val errorRes = // val errorRes =
if (!AppData.hasCameraData() && !AppData.hasSensorData()) R.drawable.ic_nosingal else R.drawable.ic_icon // if (!AppData.hasCameraData() && !AppData.hasSensorData()) R.drawable.ic_nosingal else R.drawable.ic_icon
val errorRes = R.drawable.ic_nosingal
mBinding.errorView.setImageResource(errorRes) mBinding.errorView.setImageResource(errorRes)
} }
} }

@ -3,9 +3,11 @@ package com.yinuo.safetywatcher.watcher.ui
import android.view.View import android.view.View
import android.widget.SeekBar import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener import android.widget.SeekBar.OnSeekBarChangeListener
import com.common.commonlib.utils.MMKVUtils
import com.yinuo.safetywatcher.R import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivitySpeedSettingBinding import com.yinuo.safetywatcher.databinding.ActivitySpeedSettingBinding
import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
import com.yinuo.safetywatcher.watcher.port.GasPortUtils
class SpeedSettingActivity : NoOptionsActivity() { class SpeedSettingActivity : NoOptionsActivity() {
@ -22,12 +24,12 @@ class SpeedSettingActivity : NoOptionsActivity() {
} }
override fun initView() { override fun initView() {
val initLight = 0 val initSpeed = getDefaultSpeed()
mBinding.sbSpeed.progress = initLight mBinding.sbSpeed.progress = initSpeed
mBinding.tvSpeed.text = getShowPercent(initLight) mBinding.tvSpeed.text = getShowSpeed(initSpeed)
mBinding.sbSpeed.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { mBinding.sbSpeed.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) { override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
mBinding.tvSpeed.text = getShowPercent(p1) mBinding.tvSpeed.text = getShowSpeed(p1)
} }
override fun onStartTrackingTouch(p0: SeekBar?) { override fun onStartTrackingTouch(p0: SeekBar?) {
@ -42,20 +44,34 @@ class SpeedSettingActivity : NoOptionsActivity() {
onBackPressed() onBackPressed()
} }
mBinding.tvConfirm.setOnClickListener { mBinding.tvConfirm.setOnClickListener {
setSpeed() setSpeed(mBinding.sbSpeed.progress)
onBackPressed() onBackPressed()
} }
} }
private fun getDefaultSpeed(): Int {
var localSpeed = MMKVUtils.getInt("speed")
if (localSpeed < 0) {
localSpeed = 4
}
return localSpeed
}
/** /**
* 设置转速 * 设置转速
*/ */
private fun setSpeed() { private fun setSpeed(speedProgress: Int) {
TODO("Not yet implemented") var legalSpeed = speedProgress
if (speedProgress < 0) {
legalSpeed = 0
} else if (speedProgress > 9) {
legalSpeed = 9
}
MMKVUtils.put("speed", legalSpeed)
GasPortUtils.setSpeed(legalSpeed)
} }
private fun getShowPercent(initLight: Int): CharSequence? { private fun getShowSpeed(speed: Int): CharSequence? {
val percent = (initLight/255f * 100).toInt() return "${speed + 1}"
return "$percent%"
} }
} }

@ -173,6 +173,11 @@
android:textSize="@dimen/_36dp" /> android:textSize="@dimen/_36dp" />
</LinearLayout> </LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/_2dp"
android:background="@color/_242f4d" />
<LinearLayout <LinearLayout
android:id="@+id/item_speed" android:id="@+id/item_speed"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -19,10 +19,10 @@
android:layout_height="@dimen/_100dp" android:layout_height="@dimen/_100dp"
android:layout_marginStart="@dimen/_140dp" android:layout_marginStart="@dimen/_140dp"
android:layout_marginTop="@dimen/_160dp" android:layout_marginTop="@dimen/_160dp"
android:max="100" android:max="9"
android:min="0" android:min="0"
android:padding="0dp" android:padding="0dp"
android:progress="20" /> android:progress="4" />
<TextView <TextView
android:id="@+id/tv_speed" android:id="@+id/tv_speed"
@ -31,7 +31,6 @@
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/_185dp" android:layout_marginTop="@dimen/_185dp"
android:layout_marginEnd="@dimen/_121dp" android:layout_marginEnd="@dimen/_121dp"
android:text="55%"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="@dimen/_36dp" /> android:textSize="@dimen/_36dp" />

@ -48,7 +48,7 @@ object MMKVUtils {
} }
fun getInt(key: String, vararg args: Any): Int { fun getInt(key: String, vararg args: Any): Int {
return getKV(*args).getInt(key, 0) return getKV(*args).getInt(key, -1)
} }
fun getLong(key: String, vararg args: Any): Long { fun getLong(key: String, vararg args: Any): Long {

Loading…
Cancel
Save