Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Widget
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Android Widget
Widget
Commits
1ec9ee45
Commit
1ec9ee45
authored
May 13, 2022
by
tongzifang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix leak
parent
d399515e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
12 deletions
+29
-12
build.gradle
zqtoolkit/build.gradle
+1
-1
ScaleHub.kt
zqtoolkit/src/main/java/com/qmai/zqtoolkit/ScaleHub.kt
+18
-4
SunmiScaleKit.kt
...it/src/main/java/com/qmai/zqtoolkit/base/SunmiScaleKit.kt
+4
-6
ZqScaleKit.kt
...olkit/src/main/java/com/qmai/zqtoolkit/base/ZqScaleKit.kt
+1
-1
ScaleBaseKit.kt
...c/main/java/com/qmai/zqtoolkit/base/scale/ScaleBaseKit.kt
+5
-0
No files found.
zqtoolkit/build.gradle
View file @
1ec9ee45
...
@@ -30,7 +30,7 @@ android {
...
@@ -30,7 +30,7 @@ android {
}
}
}
}
group
'com.qmai.android.zqtoolkit'
group
'com.qmai.android.zqtoolkit'
version
'1.0.
6.20
'
version
'1.0.
7
'
gradlePublish
{
gradlePublish
{
...
...
zqtoolkit/src/main/java/com/qmai/zqtoolkit/ScaleHub.kt
View file @
1ec9ee45
...
@@ -9,6 +9,7 @@ import kotlinx.coroutines.*
...
@@ -9,6 +9,7 @@ import kotlinx.coroutines.*
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.flow.MutableSharedFlow
import
kotlinx.coroutines.flow.SharedFlow
import
kotlinx.coroutines.flow.SharedFlow
import
kotlinx.coroutines.flow.collect
import
kotlinx.coroutines.flow.collect
import
kotlin.coroutines.EmptyCoroutineContext
/**
/**
* tongzi
* tongzi
...
@@ -21,8 +22,8 @@ object ScaleHub : ScaleBaseAction {
...
@@ -21,8 +22,8 @@ object ScaleHub : ScaleBaseAction {
val
connectState
:
SharedFlow
<
ConnectState
>
=
_connectState
val
connectState
:
SharedFlow
<
ConnectState
>
=
_connectState
private
val
_livingWeight
=
MutableSharedFlow
<
LivingWeight
>()
private
val
_livingWeight
=
MutableSharedFlow
<
LivingWeight
>()
val
livingWeight
:
SharedFlow
<
LivingWeight
>
=
_livingWeight
val
livingWeight
:
SharedFlow
<
LivingWeight
>
=
_livingWeight
private
var
connectJob
:
Job
?
=
null
private
var
connectJob
:
CoroutineScope
?
=
null
private
var
weightJob
:
Job
?
=
null
private
var
weightJob
:
CoroutineScope
?
=
null
private
val
scaleKit
by
lazy
{
private
val
scaleKit
by
lazy
{
when
{
when
{
ScaleChecker
.
isSUNMI
()
->
{
ScaleChecker
.
isSUNMI
()
->
{
...
@@ -36,7 +37,14 @@ object ScaleHub : ScaleBaseAction {
...
@@ -36,7 +37,14 @@ object ScaleHub : ScaleBaseAction {
override
fun
connect
(
cxt
:
Context
?,
port
:
String
?,
buad
:
String
?)
{
override
fun
connect
(
cxt
:
Context
?,
port
:
String
?,
buad
:
String
?)
{
// var trueCxt = cxt?.applicationContext
// var trueCxt = cxt?.applicationContext
connectJob
=
GlobalScope
.
launch
(
context
=
Dispatchers
.
IO
)
{
//称只给连一个端口,其他端口用其他hub
if
(
isScaleSuccess
())
{
return
}
if
(
connectJob
==
null
)
{
connectJob
=
CoroutineScope
(
EmptyCoroutineContext
)
}
connectJob
?.
launch
(
context
=
Dispatchers
.
IO
)
{
scaleKit
.
connect
(
cxt
,
port
,
buad
)
scaleKit
.
connect
(
cxt
,
port
,
buad
)
if
(
scaleKit
is
ZqScaleKit
)
{
if
(
scaleKit
is
ZqScaleKit
)
{
LEDHub
.
connect
()
LEDHub
.
connect
()
...
@@ -56,7 +64,9 @@ object ScaleHub : ScaleBaseAction {
...
@@ -56,7 +64,9 @@ object ScaleHub : ScaleBaseAction {
scaleKit
.
disconnect
()
scaleKit
.
disconnect
()
LEDHub
.
clearLED
()
LEDHub
.
clearLED
()
weightJob
?.
cancel
()
weightJob
?.
cancel
()
weightJob
=
null
connectJob
?.
cancel
()
connectJob
?.
cancel
()
connectJob
=
null
}
}
...
@@ -88,7 +98,11 @@ object ScaleHub : ScaleBaseAction {
...
@@ -88,7 +98,11 @@ object ScaleHub : ScaleBaseAction {
//读取重量、皮重
//读取重量、皮重
override
fun
readData
()
{
override
fun
readData
()
{
weightJob
=
GlobalScope
.
launch
(
context
=
Dispatchers
.
IO
)
{
if
(
weightJob
==
null
)
{
weightJob
=
CoroutineScope
(
EmptyCoroutineContext
)
}
connectJob
?.
launch
(
context
=
Dispatchers
.
IO
)
{
scaleKit
.
readData
()
scaleKit
.
readData
()
collectWeightData
()
collectWeightData
()
}
}
...
...
zqtoolkit/src/main/java/com/qmai/zqtoolkit/base/SunmiScaleKit.kt
View file @
1ec9ee45
...
@@ -78,12 +78,10 @@ object SunmiScaleKit : ScaleBaseKit() {
...
@@ -78,12 +78,10 @@ object SunmiScaleKit : ScaleBaseKit() {
override
fun
disconnect
()
{
override
fun
disconnect
()
{
if
(
isScaleSuccess
())
{
super
.
disconnect
()
stopReadData
()
mScaleManager
?.
onDestroy
()
mScaleManager
?.
onDestroy
()
mScaleManager
=
null
mScaleManager
=
null
Log
.
v
(
TAG
,
"disconnect"
)
Log
.
v
(
TAG
,
"disconnect"
)
}
}
}
...
...
zqtoolkit/src/main/java/com/qmai/zqtoolkit/base/ZqScaleKit.kt
View file @
1ec9ee45
...
@@ -48,7 +48,7 @@ object ZqScaleKit : ScaleBaseKit() {
...
@@ -48,7 +48,7 @@ object ZqScaleKit : ScaleBaseKit() {
private
var
job
:
Job
?
=
null
private
var
job
:
Job
?
=
null
override
fun
disconnect
()
{
override
fun
disconnect
()
{
s
topReadData
()
s
uper
.
disconnect
()
val
ebDisconnect
=
zqeb
.
EB_Disconnect
()
val
ebDisconnect
=
zqeb
.
EB_Disconnect
()
Log
.
v
(
TAG
,
String
.
format
(
"ebDisconnect: %s"
,
ebDisconnect
))
Log
.
v
(
TAG
,
String
.
format
(
"ebDisconnect: %s"
,
ebDisconnect
))
}
}
...
...
zqtoolkit/src/main/java/com/qmai/zqtoolkit/base/scale/ScaleBaseKit.kt
View file @
1ec9ee45
...
@@ -24,6 +24,11 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
...
@@ -24,6 +24,11 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
val
_livingWeight
=
MutableSharedFlow
<
LivingWeight
>()
val
_livingWeight
=
MutableSharedFlow
<
LivingWeight
>()
val
livingWeight
:
SharedFlow
<
LivingWeight
>
=
_livingWeight
val
livingWeight
:
SharedFlow
<
LivingWeight
>
=
_livingWeight
override
fun
disconnect
()
{
stopReadData
()
updateState
(
ConnectState
(
false
,
"断开连接"
))
}
override
fun
updateState
(
state
:
ConnectState
)
{
override
fun
updateState
(
state
:
ConnectState
)
{
GlobalScope
.
launch
(
context
=
Dispatchers
.
IO
)
{
GlobalScope
.
launch
(
context
=
Dispatchers
.
IO
)
{
_connectState
.
emit
(
state
)
_connectState
.
emit
(
state
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment