Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jensen
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
Skye Yu
jensen
Commits
c5620057
Commit
c5620057
authored
Nov 10, 2025
by
martin hou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加已配对设备列表的查询和设备回连消息
parent
86838102
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
3 deletions
+49
-3
jensen.d.ts
jensen.d.ts
+8
-2
jensen.js
src/utils/jensen.js
+41
-1
No files found.
jensen.d.ts
View file @
c5620057
...
...
@@ -55,8 +55,8 @@ export type BluetoothStatus = {
export
type
BluetoothDevice
=
{
name
:
string
;
// 设备名称
mac
:
string
;
// 设备MAC地址
rssi
:
number
;
// 设备信号强度
cod
:
number
;
// 设备类型编码
rssi
?:
number
;
// 设备信号强度
cod
?:
number
;
// 设备类型编码
};
// 操作系统枚举
...
...
@@ -285,6 +285,12 @@ declare class Jensen {
// 写入蓝牙设备列表
writeBluetoothDeviceList
:
(
mac_list
:
string
[],
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
// 获取已配对的蓝牙设备列表
getPairedDevices
:
(
seconds
?:
number
)
=>
Promise
<
BluetoothDevice
[]
>
;
// 设备回连
reconnectDevice
:
(
mac
:
string
,
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
// 获取实时音频流的设置信息,主要是确定设备端的实时音频的编码信息
getRealtimeSettings
:
()
=>
Promise
<
any
>
;
...
...
src/utils/jensen.js
View file @
c5620057
...
...
@@ -38,7 +38,7 @@ const BLUETOOTH_STATUS = 0x1003;
const
BT_SCAN
=
0x1005
;
const
BT_DEV_LIST
=
0x1006
;
const
BT_
WRITE
_DEV_LIST
=
0x1007
;
const
BT_
GET_PAIRED
_DEV_LIST
=
0x1007
;
const
TEST_SN_WRITE
=
0xf007
;
const
RECORD_TEST_START
=
0xf008
;
...
...
@@ -728,6 +728,22 @@ Jensen.prototype.getScanResults = async function (seconds) {
return
this
.
send
(
new
Command
(
BT_DEV_LIST
),
seconds
);
};
// 获取已配对的蓝牙设备列表
Jensen
.
prototype
.
getPairedDevices
=
async
function
(
seconds
)
{
if
(
this
.
model
.
indexOf
(
'hidock-p1'
)
==
-
1
)
return
null
;
return
this
.
send
(
new
Command
(
BT_GET_PAIRED_DEV_LIST
),
seconds
);
};
// 设备回连
Jensen
.
prototype
.
reconnectDevice
=
async
function
(
mac
,
seconds
)
{
if
(
this
.
model
.
indexOf
(
'hidock-p1'
)
==
-
1
)
return
null
;
let
marr
=
mac
.
split
(
'-'
);
if
(
marr
.
length
!=
6
)
throw
new
Error
(
'invalid mac'
);
let
addr
=
[];
for
(
let
i
=
0
;
i
<
marr
.
length
;
i
++
)
addr
[
i
]
=
parseInt
(
marr
[
i
],
16
);
return
this
.
send
(
new
Command
(
BLUETOOTH_CMD
).
body
([
0x03
].
concat
(
addr
)),
seconds
);
}
Jensen
.
prototype
.
setWebUSBTimeout
=
async
function
(
timeout
,
seconds
)
{
let
data
=
[];
...
...
@@ -1502,6 +1518,30 @@ Jensen.registerHandler(BLUETOOTH_SCAN, (msg) => {
return
devices
;
});
Jensen
.
registerHandler
(
BT_GET_PAIRED_DEV_LIST
,
(
msg
)
=>
{
if
(
msg
.
body
.
length
==
0
)
return
[];
let
nums
=
((
msg
.
body
[
0
]
&
0xff
)
<<
8
)
|
(
msg
.
body
[
1
]
&
0xff
);
let
devices
=
[];
let
decoder
=
new
TextDecoder
(
'UTF-8'
);
for
(
let
i
=
0
,
k
=
2
;
i
<
nums
;
i
++
)
{
let
len
=
((
msg
.
body
[
k
++
]
&
0xff
)
<<
8
)
|
(
msg
.
body
[
k
++
]
&
0xff
);
let
sname
=
new
Uint8Array
(
len
);
for
(
let
f
=
0
;
f
<
len
;
f
++
)
{
sname
[
f
]
=
msg
.
body
[
k
++
]
&
0xff
;
}
let
mac
=
[];
for
(
let
f
=
0
;
f
<
6
;
f
++
)
{
let
m
=
(
msg
.
body
[
k
++
]
&
0xff
).
toString
(
16
).
toUpperCase
();
mac
.
push
(
m
.
length
==
1
?
'0'
+
m
:
m
);
}
devices
.
push
({
name
:
decoder
.
decode
(
sname
),
mac
:
mac
.
join
(
'-'
)
});
}
return
devices
;
});
Jensen
.
registerHandler
(
BLUETOOTH_STATUS
,
(
msg
)
=>
{
if
(
msg
.
body
.
length
==
0
)
return
{
status
:
'disconnected'
};
let
status
=
msg
.
body
[
0
];
...
...
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