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
15ce97f3
Commit
15ce97f3
authored
Jan 06, 2025
by
martin hou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add bluetooth device list
parent
2012b485
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
17 deletions
+66
-17
index.tsx
src/index.tsx
+66
-17
No files found.
src/index.tsx
View file @
15ce97f3
...
@@ -6,13 +6,15 @@ const jensen = new Jensen();
...
@@ -6,13 +6,15 @@ const jensen = new Jensen();
export
function
Home
()
{
export
function
Home
()
{
const
[
files
,
setFiles
]
=
useState
<
Jensen
.
FileInfo
[]
>
([]);
const
[
files
,
setFiles
]
=
useState
<
Jensen
.
FileInfo
[]
>
([]);
const
[
devices
,
setDevices
]
=
useState
<
Jensen
.
BluetoothDevice
[]
>
([]);
const
[
greeting
,
setGreeting
]
=
useState
<
string
|
null
>
(
null
);
useEffect
(()
=>
{
useEffect
(()
=>
{
jensen
.
connect
();
jensen
.
connect
();
jensen
.
onconnect
=
()
=>
{
jensen
.
onconnect
=
()
=>
{
console
.
log
(
'connect successfully'
);
console
.
log
(
'connect successfully'
);
jensen
.
listFiles
().
then
((
res
)
=>
{
jensen
.
getDeviceInfo
().
then
((
info
)
=>
{
setFiles
(
res
);
alert
(
info
.
sn
+
' connected'
);
});
});
};
};
},
[]);
},
[]);
...
@@ -30,19 +32,12 @@ export function Home() {
...
@@ -30,19 +32,12 @@ export function Home() {
let
bluetoothDevices
:
BluetoothDevice
[]
=
[];
let
bluetoothDevices
:
BluetoothDevice
[]
=
[];
const
bluetoothScan
=
async
()
=>
{
const
bluetoothScan
=
async
()
=>
{
setDevices
([]);
setGreeting
(
'scan started at: '
+
new
Date
().
toLocaleString
());
let
devices
=
await
jensen
.
scanDevices
();
let
devices
=
await
jensen
.
scanDevices
();
console
.
log
(
devices
);
// console.log(devices);
bluetoothDevices
=
devices
;
setDevices
(
devices
);
}
setGreeting
(
null
)
const
connectBTDevice
=
async
()
=>
{
let
idstr
=
prompt
(
'请输入需要连接的设备序号(从0开始):'
,
''
);
let
did
=
parseInt
(
idstr
||
''
);
if
(
isNaN
(
did
))
return
alert
(
'已取消'
);
let
dinfo
=
bluetoothDevices
[
did
];
if
(
dinfo
==
null
||
dinfo
==
undefined
)
return
alert
(
'无效序号'
);
let
r
=
await
jensen
.
connectBTDevice
(
dinfo
.
mac
);
console
.
log
(
r
);
}
}
const
disconnectBTDevice
=
async
()
=>
{
const
disconnectBTDevice
=
async
()
=>
{
...
@@ -50,17 +45,71 @@ export function Home() {
...
@@ -50,17 +45,71 @@ export function Home() {
console
.
log
(
r
);
console
.
log
(
r
);
}
}
const
clsBtnConnect
=
{
height
:
'30px'
,
padding
:
'0px 20px'
,
position
:
'absolute'
,
right
:
'0px'
,
top
:
'3px'
,
cursor
:
'pointer'
}
const
clsBleDevice
=
{
height
:
'40px'
,
lineHeight
:
'40px'
,
minWidth
:
'500px'
,
position
:
'relative'
,
display
:
'inline-block'
}
const
clsBleName
=
{
fontSize
:
'16px'
,
fontFamily
:
'consolas'
}
const
doConnectBluetooth
=
async
(
mac
:
string
)
=>
{
// alert(mac);
let
rst
=
await
jensen
.
connectBTDevice
(
mac
,
10
);
alert
(
'connect: '
+
rst
.
result
);
}
const
getTime
=
async
()
=>
{
let
time
=
await
jensen
.
getTime
();
alert
(
JSON
.
stringify
(
time
));
}
return
(
return
(
<
div
style=
{
{
display
:
'flex'
,
flexDirection
:
'column'
,
gap
:
'16px'
,
padding
:
'16px'
,
alignItems
:
'center'
}
}
>
<>
<
div
style=
{
{
display
:
'flex'
,
flexDirection
:
'row'
,
gap
:
'16px'
,
padding
:
'16px'
,
alignItems
:
'center'
}
}
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
()
=>
jensen
.
connect
()
}
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
()
=>
jensen
.
connect
()
}
>
C
lick to c
onnect
Connect
</
button
>
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
getFilePart
}
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
getFilePart
}
>
get File Part
get File Part
</
button
>
</
button
>
<
button
style=
{
{
width
:
'200px'
,
height
:
'50px'
}
}
onClick=
{
getTime
}
>
Get Time
</
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=
{
connectBTDevice
}
>
Bluetooth Connect
</
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
>
<
div
style=
{
{
padding
:
'0px 0px 0px 30px'
,
width
:
'500px'
}
}
>
<
h3
>
Bluetooth Device List:
</
h3
>
{
greeting
?
<
div
>
{
greeting
}
</
div
>
:
<></>
}
{
devices
&&
devices
.
length
?
(
devices
.
map
((
item
,
index
)
=>
{
return
(
<
div
style=
{
clsBleDevice
}
><
span
style=
{
clsBleName
}
>
(
{
item
.
mac
}
)
{
item
.
name
}
</
span
><
button
style=
{
clsBtnConnect
}
onClick=
{
()
=>
{
doConnectBluetooth
(
item
.
mac
)
}
}
>
Connect
</
button
></
div
>
);
})
)
:
(
<
div
>
no devices...
</
div
>
)
}
</
div
>
</>
);
);
}
}
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