Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
visualcloud
/
Vmatrix-client-taro
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4451ecdc
authored
Nov 14, 2019
by
hank
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改蓝牙连接
parent
33eed3a1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
8 deletions
+67
-8
src/common/utils.ts
+42
-1
src/pages/home/device/device_list/index.tsx
+19
-7
src/pages/system/wifi_list/index.tsx
+6
-0
No files found.
src/common/utils.ts
View file @
4451ecdc
...
...
@@ -2,7 +2,46 @@ import Taro, { arrayBuffer } from '@tarojs/taro'
import
{
Header
}
from
'react-navigation'
import
AsyncStorage
from
'@react-native-community/async-storage'
import
{
bluetooth
}
from
'./adapter'
function
Utf8ArrayToStr
(
array
)
{
let
out
,
i
,
len
,
c
let
char2
,
char3
out
=
''
len
=
array
.
length
i
=
0
while
(
i
<
len
)
{
c
=
array
[
i
++
]
switch
(
c
>>
4
)
{
case
0
:
case
1
:
case
2
:
case
3
:
case
4
:
case
5
:
case
6
:
case
7
:
// 0xxxxxxx
out
+=
String
.
fromCharCode
(
c
)
break
case
12
:
case
13
:
// 110x xxxx 10xx xxxx
char2
=
array
[
i
++
]
out
+=
String
.
fromCharCode
(((
c
&
0x1f
)
<<
6
)
|
(
char2
&
0x3f
))
break
case
14
:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2
=
array
[
i
++
]
char3
=
array
[
i
++
]
out
+=
String
.
fromCharCode
(
((
c
&
0x0f
)
<<
12
)
|
((
char2
&
0x3f
)
<<
6
)
|
((
char3
&
0x3f
)
<<
0
)
)
break
}
}
return
out
}
/** 连接参数 */
export
function
concatParam
(
data
:
any
):
string
{
return
Object
.
entries
(
data
)
...
...
@@ -78,7 +117,9 @@ export function getBLEState(buffer: ArrayBuffer) {
/** 解析蓝牙接收到的数据 */
export
function
getBLEData
(
buffer
:
ArrayBuffer
)
{
return
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
buffer
.
slice
(
1
,
buffer
.
byteLength
)))
console
.
log
(
Utf8ArrayToStr
(
new
Uint8Array
(
buffer
.
slice
(
1
,
buffer
.
byteLength
))))
// return String.fromCharCode.apply(null, new Uint8Array(buffer.slice(1, buffer.byteLength)))
return
Utf8ArrayToStr
(
new
Uint8Array
(
buffer
.
slice
(
1
,
buffer
.
byteLength
)))
}
/** 获取蓝牙的 */
...
...
src/pages/home/device/device_list/index.tsx
View file @
4451ecdc
...
...
@@ -146,21 +146,33 @@ class MyDevice extends Component {
})
const
mode
=
JSON
.
parse
(
result
).
model
||
'OWN'
const
code
=
JSON
.
parse
(
result
).
qrcode
console
.
log
(
result
,
mode
,
code
)
// console.log(result, mode, code)
if
(
!
code
)
{
showMyToast
({
title
:
'添加失败~'
})
return
false
}
if
(
mode
===
'TV'
&&
code
)
{
await
api
.
common
.
addDeviceToken
(
code
)
showMyToast
({
title
:
'添加成功~'
})
api
.
common
.
addDeviceToken
(
code
)
.
then
(()
=>
{
showMyToast
({
title
:
'添加成功~'
})
})
.
catch
(()
=>
{
showMyToast
({
title
:
'添加失败~'
})
})
this
.
page
=
1
this
.
getDate
()
}
if
(
mode
===
'OWN'
&&
code
)
{
if
(
(
mode
===
'OWN'
||
mode
===
'OWNRESET'
)
&&
code
)
{
const
res
=
await
Ble
.
openBle
(
code
)
const
{
deviceId
}
=
res
Taro
.
navigateTo
({
url
:
`/pages/system/wifi_list/index?deviceId=
${
deviceId
}
`
})
Taro
.
navigateTo
({
url
:
`/pages/system/wifi_list/index?deviceId=
${
deviceId
}
&mode=
${
mode
}
`
})
}
}
catch
(
error
)
{
console
.
error
(
error
)
showMyToast
({
result
:
error
,
title
:
'添加失败~'
})
console
.
log
(
error
)
}
}
}
...
...
src/pages/system/wifi_list/index.tsx
View file @
4451ecdc
...
...
@@ -156,6 +156,7 @@ class WifiList extends Component {
async
onConfirm
()
{
const
{
id
,
type
}
=
this
.
activeWLAN
const
{
password
,
deviceId
}
=
this
const
{
mode
}
=
this
.
$router
.
params
if
(
id
===
undefined
||
!
deviceId
)
return
if
(
type
!==
'OPEN'
&&
password
.
length
<
8
)
{
showMyToast
({
title
:
'wifi 密码少于8位'
})
...
...
@@ -165,6 +166,11 @@ class WifiList extends Component {
try
{
Taro
.
showLoading
({
title
:
'连接中...'
})
await
Ble
.
postWifiPassword
(
id
,
password
,
deviceId
)
if
(
mode
&&
mode
===
'OWNRESET'
)
{
setTimeout
(()
=>
{
Taro
.
navigateBack
()
},
500
)
}
// Taro.hideLoading()
}
catch
(
error
)
{
console
.
error
(
error
)
...
...
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