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
dd288242
Commit
dd288242
authored
Jan 13, 2025
by
martin hou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: added bluetooth connection information obtaining
parent
ad38a3a4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
2 deletions
+55
-2
jensen.d.ts
jensen.d.ts
+11
-0
index.tsx
src/index.tsx
+6
-0
jensen.js
src/utils/jensen.js
+38
-2
No files found.
jensen.d.ts
View file @
dd288242
...
@@ -18,6 +18,16 @@ export type FileInfo = {
...
@@ -18,6 +18,16 @@ export type FileInfo = {
signature
:
string
;
signature
:
string
;
};
};
export
type
BluetoothStatus
=
{
status
:
string
;
mac
?:
string
;
name
?:
string
;
a2dp
?:
boolean
;
hfp
?:
boolean
;
avrcp
?:
boolean
;
battery
?:
number
;
}
export
type
BluetoothDevice
=
{
export
type
BluetoothDevice
=
{
name
:
string
;
name
:
string
;
mac
:
string
;
mac
:
string
;
...
@@ -122,6 +132,7 @@ declare class Jensen {
...
@@ -122,6 +132,7 @@ declare class Jensen {
scanDevices
:
(
seconds
?:
number
)
=>
Promise
<
BluetoothDevice
[]
>
;
scanDevices
:
(
seconds
?:
number
)
=>
Promise
<
BluetoothDevice
[]
>
;
connectBTDevice
:
(
mac
:
string
,
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
connectBTDevice
:
(
mac
:
string
,
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
disconnectBTDevice
:
(
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
disconnectBTDevice
:
(
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
getBluetoothStatus
:
(
seconds
?:
number
)
=>
Promise
<
BluetoothStatus
>
;
}
}
export
=
Jensen
;
export
=
Jensen
;
src/index.tsx
View file @
dd288242
...
@@ -83,6 +83,11 @@ export function Home() {
...
@@ -83,6 +83,11 @@ export function Home() {
console
.
log
(
files
);
console
.
log
(
files
);
}
}
const
getBluetoothStatus
=
async
()
=>
{
let
info
=
await
jensen
.
getBluetoothStatus
();
alert
(
JSON
.
stringify
(
info
));
}
return
(
return
(
<>
<>
<
div
style=
{
{
display
:
'flex'
,
flexDirection
:
'row'
,
gap
:
'16px'
,
padding
:
'16px'
,
alignItems
:
'center'
}
}
>
<
div
style=
{
{
display
:
'flex'
,
flexDirection
:
'row'
,
gap
:
'16px'
,
padding
:
'16px'
,
alignItems
:
'center'
}
}
>
...
@@ -96,6 +101,7 @@ export function Home() {
...
@@ -96,6 +101,7 @@ export function Home() {
Get Time
Get Time
</
button
>
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
listFiles
}
>
List Files
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
listFiles
}
>
List Files
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
getBluetoothStatus
}
>
Bluetooth Status
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
bluetoothScan
}
>
Bluetooth Scan
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
bluetoothScan
}
>
Bluetooth Scan
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
disconnectBTDevice
}
>
Bluetooth Disconnect
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
disconnectBTDevice
}
>
Bluetooth Disconnect
</
button
>
</
div
>
</
div
>
...
...
src/utils/jensen.js
View file @
dd288242
...
@@ -24,6 +24,7 @@ const FACTORY_RESET = 0xf00b;
...
@@ -24,6 +24,7 @@ const FACTORY_RESET = 0xf00b;
const
BLUETOOTH_SCAN
=
0x1001
;
const
BLUETOOTH_SCAN
=
0x1001
;
const
BLUETOOTH_CMD
=
0x1002
;
const
BLUETOOTH_CMD
=
0x1002
;
const
BLUETOOTH_STATUS
=
0x1003
;
const
TEST_SN_WRITE
=
0xf007
;
const
TEST_SN_WRITE
=
0xf007
;
const
RECORD_TEST_START
=
0xf008
;
const
RECORD_TEST_START
=
0xf008
;
...
@@ -55,7 +56,8 @@ const COMMAND_NAMES = {
...
@@ -55,7 +56,8 @@ const COMMAND_NAMES = {
[
RECORD_TEST_START
]:
'record test start'
,
[
RECORD_TEST_START
]:
'record test start'
,
[
RECORD_TEST_END
]:
'record test end'
,
[
RECORD_TEST_END
]:
'record test end'
,
[
BLUETOOTH_SCAN
]:
'bluetooth-scan'
,
[
BLUETOOTH_SCAN
]:
'bluetooth-scan'
,
[
BLUETOOTH_CMD
]:
'bluetooth-cmd'
[
BLUETOOTH_CMD
]:
'bluetooth-cmd'
,
[
BLUETOOTH_STATUS
]:
'bluetooth-status'
};
};
let
Logger
=
null
;
let
Logger
=
null
;
...
@@ -584,6 +586,11 @@ Jensen.prototype.disconnectBTDevice = async function(seconds) {
...
@@ -584,6 +586,11 @@ Jensen.prototype.disconnectBTDevice = async function(seconds) {
return
this
.
send
(
new
Command
(
BLUETOOTH_CMD
).
body
([
0x01
]),
seconds
);
return
this
.
send
(
new
Command
(
BLUETOOTH_CMD
).
body
([
0x01
]),
seconds
);
}
}
Jensen
.
prototype
.
getBluetoothStatus
=
async
function
(
seconds
)
{
if
(
this
.
model
!=
'hidock-p1'
)
return
null
;
return
this
.
send
(
new
Command
(
BLUETOOTH_STATUS
),
seconds
);
}
Jensen
.
prototype
.
listFiles
=
async
function
()
{
Jensen
.
prototype
.
listFiles
=
async
function
()
{
let
tag
=
'filelist'
;
let
tag
=
'filelist'
;
if
(
this
[
tag
]
!=
null
)
return
null
;
if
(
this
[
tag
]
!=
null
)
return
null
;
...
@@ -1145,7 +1152,7 @@ Jensen.registerHandler(GET_RECORDING_FILE, (msg) => {
...
@@ -1145,7 +1152,7 @@ Jensen.registerHandler(GET_RECORDING_FILE, (msg) => {
});
});
Jensen
.
registerHandler
(
BLUETOOTH_SCAN
,
(
msg
)
=>
{
Jensen
.
registerHandler
(
BLUETOOTH_SCAN
,
(
msg
)
=>
{
console
.
log
(
'bluetooth-scan'
,
msg
);
//
console.log('bluetooth-scan', msg);
let
nums
=
((
msg
.
body
[
0
]
&
0xff
)
<<
8
)
|
(
msg
.
body
[
1
]
&
0xff
);
let
nums
=
((
msg
.
body
[
0
]
&
0xff
)
<<
8
)
|
(
msg
.
body
[
1
]
&
0xff
);
let
devices
=
[];
let
devices
=
[];
let
decoder
=
new
TextDecoder
(
'UTF-8'
);
let
decoder
=
new
TextDecoder
(
'UTF-8'
);
...
@@ -1171,6 +1178,35 @@ Jensen.registerHandler(BLUETOOTH_SCAN, (msg) => {
...
@@ -1171,6 +1178,35 @@ Jensen.registerHandler(BLUETOOTH_SCAN, (msg) => {
return
devices
;
return
devices
;
});
});
Jensen
.
registerHandler
(
BLUETOOTH_STATUS
,
(
msg
)
=>
{
if
(
msg
.
body
.
length
==
0
)
return
{
status
:
'disconnected'
};
let
status
=
msg
.
body
[
0
];
if
(
status
==
1
)
return
{
status
:
'disconnected'
};
let
flen
=
((
msg
.
body
[
1
]
&
0xff
)
<<
8
)
|
(
msg
.
body
[
2
]
&
0xff
);
let
decoder
=
new
TextDecoder
(
'UTF-8'
);
let
sname
=
new
Uint8Array
(
flen
);
let
i
=
3
;
for
(
let
k
=
0
;
i
<
msg
.
body
.
length
&&
k
<
flen
;
i
++
,
k
++
)
{
sname
[
k
]
=
msg
.
body
[
i
]
&
0xff
;
}
let
mac
=
[];
for
(
let
k
=
0
;
i
<
msg
.
body
.
length
&&
k
<
6
;
k
++
)
{
let
m
=
(
msg
.
body
[
i
++
]).
toString
(
16
).
toUpperCase
();
mac
.
push
(
m
.
length
==
1
?
'0'
+
m
:
m
);
}
return
{
status
:
'connected'
,
mac
:
mac
.
join
(
'-'
),
name
:
decoder
.
decode
(
sname
),
a2dp
:
(
msg
.
body
[
i
++
]
&
0xff
)
==
1
,
hfp
:
(
msg
.
body
[
i
++
]
&
0xff
)
==
1
,
avrcp
:
(
msg
.
body
[
i
++
]
&
0xff
)
==
1
,
battery
:
parseInt
((
msg
.
body
[
i
++
]
&
0xff
)
/
255
*
100
)
};
});
Jensen
.
registerHandler
(
RECORD_TEST_START
,
commonMessageParser
);
Jensen
.
registerHandler
(
RECORD_TEST_START
,
commonMessageParser
);
Jensen
.
registerHandler
(
RECORD_TEST_END
,
commonMessageParser
);
Jensen
.
registerHandler
(
RECORD_TEST_END
,
commonMessageParser
);
Jensen
.
registerHandler
(
DEVICE_MSG_TEST
,
commonMessageParser
);
Jensen
.
registerHandler
(
DEVICE_MSG_TEST
,
commonMessageParser
);
...
...
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