Commit 73be14d1 authored by tongzifang's avatar tongzifang

顶尖改为USB

parent cc43970d
......@@ -8,9 +8,9 @@ android {
defaultConfig {
applicationId "com.qimai.android.widget"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
targetSdkVersion 28
versionCode 11
versionName "1.0.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
......@@ -18,6 +18,14 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
signingConfigs {
release {
keyAlias 'shopAssistant'
keyPassword 'qmai2020'
storeFile file('../shopAssistant.jks')
storePassword 'qmai2020'
}
}
buildTypes {
release {
......@@ -25,6 +33,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "widget_${variant.buildType.name}_${versionCode}_${versionName}.apk"
}
}
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
......
......@@ -3,6 +3,7 @@ package com.qimai.android.widget
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Color
import android.hardware.usb.UsbManager
import android.os.Bundle
import android.util.Log
import android.view.View
......@@ -12,11 +13,14 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import com.blankj.utilcode.util.ConvertUtils
import com.blankj.utilcode.util.DeviceUtils
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.Utils
import com.qmai.zqtoolkit.LEDHub
import com.qmai.zqtoolkit.ScaleHub
import com.qmai.zqtoolkit.config.QmScaleType
import com.qmai.zqtoolkit.config.ZQ_END
import com.qmai.zqtoolkit.config.ZQ_WEIGHT_START
import com.qmai.zqtoolkit.utils.ScaleChecker
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import java.util.*
......@@ -33,6 +37,7 @@ class ZqToolActivity : AppCompatActivity() {
private var etTare: EditText? = null
private var tvWeight: TextView? = null
private var tvLivingWeight: TextView? = null
private var tv_scale_info: TextView? = null
private var tvTare: TextView? = null
private var tvState: TextView? = null
private var butConnect: Button? = null
......@@ -74,6 +79,7 @@ class ZqToolActivity : AppCompatActivity() {
etTare = findViewById<View>(R.id.etTare) as EditText
tvWeight = findViewById<View>(R.id.tvWeight) as TextView
tvLivingWeight = findViewById<View>(R.id.tvLivingWeight) as TextView
tv_scale_info = findViewById<View>(R.id.tv_scale_info) as TextView
tvTare = findViewById<View>(R.id.tvTare) as TextView
tvState = findViewById<View>(R.id.tvState) as TextView
butConnect = findViewById<View>(R.id.ButConnect) as Button
......@@ -155,7 +161,13 @@ class ZqToolActivity : AppCompatActivity() {
override fun onNothingSelected(arg0: AdapterView<*>?) {}
}
var usbManager = Utils.getApp().getSystemService(Context.USB_SERVICE) as UsbManager?
usbManager?.deviceList?.forEach {
Log.v("cccc", GsonUtils.toJson(it.value))
// if (it.value.productId == ACLAS_PRODUCTID && it.value.vendorId == ACLAS_VENDORID) {
// return it.value.productName?:""
// }
}
lifecycleScope.launch {
ScaleHub.connectState.collect {
......@@ -164,7 +176,9 @@ class ZqToolActivity : AppCompatActivity() {
m_bConnected = it.isConnect
if (m_bConnected) {
butConnect?.text = "断开"
} else butConnect?.text = "连接"
} else {
butConnect?.text = "连接"
}
Log.d(TAG, it.toString())
}
}
......@@ -178,11 +192,13 @@ class ZqToolActivity : AppCompatActivity() {
tvWeight?.text = it.weight
tvState?.text = "稳定"
tvState?.setBackgroundColor(Color.GREEN)
tvLivingWeight?.text = "实时重量" + it.weight
tvLivingWeight?.text =
"实时重量" + it.weight + "time:" + System.currentTimeMillis()
} else {
tvState?.setBackgroundColor(Color.RED)
tvState?.text = "不稳定"
tvLivingWeight?.text = "实时重量" + it.weight
tvLivingWeight?.text =
"实时重量" + it.weight + "time:" + System.currentTimeMillis()
}
}
}
......@@ -273,10 +289,8 @@ class ZqToolActivity : AppCompatActivity() {
// }
try {
// ScaleHub.sendLEDTotalPrice(etdata?.text.toString())
// ScaleHub.sendLEDTotalPrice(etdata?.text.toString())
LEDHub.sendLEDLight(zero = false, stable = false, tare = true)
} catch (e: Exception) {
}
......
......@@ -236,6 +236,18 @@
</RadioGroup>
</TableRow>
<TableRow>
<TextView
android:id="@+id/tv_scale_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:textColor="@color/black"
android:text=""
android:textSize="32dp"></TextView>
</TableRow>
</TableLayout>
......
......@@ -30,7 +30,7 @@ android {
}
}
group 'com.qmai.android.zqtoolkit'
version '1.0.7.14'
version '1.0.7.40'
gradlePublish {
......
......@@ -3,6 +3,7 @@ package com.qmai.zqtoolkit.base
import android.content.Context
import android.hardware.usb.UsbManager
import android.util.Log
import androidx.constraintlayout.solver.GoalRow
import com.blankj.utilcode.util.GsonUtils
import com.example.scaler.AclasScaler
import com.example.scaler.AclasScaler.AclasScalerListener
......@@ -12,6 +13,7 @@ import com.qmai.zqtoolkit.base.scale.ScaleBaseKit
import com.qmai.zqtoolkit.config.ACLAS_PRODUCTID
import com.qmai.zqtoolkit.config.ACLAS_VENDORID
import com.qmai.zqtoolkit.config.QmScaleType
import com.qmai.zqtoolkit.utils.ScaleChecker
/**
* tongzi
......@@ -60,16 +62,12 @@ object AclasScaleKit : ScaleBaseKit() {
aclasScaler = AclasScaler(AclasScaler.Type_USB, it, aclasScalerListener)
}
}
//1. 获取usb设备列表
//2. 取 产品id 供应商ID对应 列表下标
val usbConnectIndex = cxt?.let { getAclasScaleIndex(it) }
if (usbConnectIndex != null) {
val aclasConnect = aclasScaler?.AclasConnect(usbConnectIndex)
Log.v(TAG, "aclasConnect:$aclasConnect")
} else {
updateState(ConnectState(false, "获取不到插入的设备"))
}
//
val usbConnectIndex = getAclasScaleIndex()
//val usbConnectIndex = 0
val aclasConnect = aclasScaler?.AclasConnect(usbConnectIndex)
Log.v(TAG, "aclasConnect:$aclasConnect")
}
override fun disconnect() {
......@@ -137,24 +135,17 @@ object AclasScaleKit : ScaleBaseKit() {
return super.isScaleSuccess() && aclasScaler?.AclasIsConnect() == true
}
//根据顶尖秤的productId vendorId 获取顶尖秤在usb列表的下标
private fun getAclasScaleIndex(context: Context): Int? {
val usbManager = context.getSystemService(Context.USB_SERVICE) as UsbManager
val deviceList = usbManager.deviceList
if (deviceList.isEmpty()) {
return null
} else {
var index = 0
usbManager.deviceList.forEach {
val usbDevice = it.value
if (usbDevice.productId == ACLAS_PRODUCTID && usbDevice.vendorId == ACLAS_VENDORID) {
return index
}
index++
private fun getAclasScaleIndex(): Int {
var usbIndex = 0
var aclasPname = ScaleChecker.getAclasPname()
if (aclasPname.isNotEmpty()) {
var comList = mutableListOf<String>()
aclasScaler?.getCommList(comList)
if (!comList.isNullOrEmpty()) {
usbIndex = comList.indexOfFirst { name -> name.contains(aclasPname)}
return usbIndex
}
}
return null
return usbIndex
}
}
\ No newline at end of file
......@@ -48,4 +48,18 @@ object ScaleChecker {
}
return false
}
/**
* 查找顶尖称的USB名称
*/
fun getAclasPname(): String {
var usbManager = Utils.getApp().getSystemService(Context.USB_SERVICE) as UsbManager?
usbManager?.deviceList?.forEach {
if (it.value.productId == ACLAS_PRODUCTID && it.value.vendorId == ACLAS_VENDORID) {
return it.value.deviceName
}
}
return ""
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment