Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Μ
µnit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teckids
Projekt Hack-n-Fun
Libs
µnit
Commits
ca60846b
Verified
Commit
ca60846b
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Implement device button click to conncet to device
parent
5cbe207a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
companion/app.py
+21
-6
21 additions, 6 deletions
companion/app.py
companion/bluetooth.py
+6
-0
6 additions, 0 deletions
companion/bluetooth.py
with
27 additions
and
6 deletions
companion/app.py
+
21
−
6
View file @
ca60846b
...
...
@@ -16,14 +16,16 @@ class DeviceListWidget(Widget):
self
.
_devices_buttons_map
=
{}
@mainthread
def
update_device_buttons
(
self
,
devices
):
def
update_device_buttons
(
self
,
buttons_map
):
Logger
.
debug
(
"
Updating device buttons
"
)
self
.
_devices_buttons_map
=
devices
self
.
device_buttons
.
clear_widgets
()
for
label
,
device
in
self
.
_devices_buttons_map
.
items
():
Logger
.
debug
(
"
Adding button for %s
"
%
label
)
btn
=
Button
(
text
=
label
)
for
address
,
info
in
buttons_map
.
items
():
label
,
cb_connect
=
info
Logger
.
debug
(
"
Adding button for %s (%s)
"
%
(
address
,
label
))
btn
=
Button
(
text
=
label
,
on_press
=
cb_connect
)
self
.
device_buttons
.
add_widget
(
btn
)
...
...
@@ -34,7 +36,20 @@ class MynitCompanionApp(App):
self
.
_bluetooth
=
MynitBluetooth
(
self
)
def
update_device_list
(
self
,
devices
):
self
.
widget
.
update_device_buttons
({
device
.
getAddress
():
device
for
device
in
devices
})
Logger
.
debug
(
"
Updating device buttons
"
)
buttons_map
=
{}
for
device
in
devices
:
if
not
device
.
getName
():
Logger
.
info
(
"
Device %s skipped due to missing name
"
%
device
.
getAddress
())
continue
def
cb_connect
(
*
args
,
**
kwargs
):
self
.
_bluetooth
.
connect_by_device_address
(
device
.
getAddress
())
buttons_map
[
device
.
getAddress
()]
=
(
device
.
getName
(),
cb_connect
)
self
.
widget
.
update_device_buttons
(
buttons_map
)
def
build
(
self
):
self
.
widget
=
DeviceListWidget
()
...
...
This diff is collapsed.
Click to expand it.
companion/bluetooth.py
+
6
−
0
View file @
ca60846b
...
...
@@ -32,6 +32,11 @@ class MynitBluetooth(BluetoothDispatcher):
self
.
_app
.
update_device_list
(
self
.
_available_devices
)
def
connect_by_device_address
(
self
,
address
):
Logger
.
info
(
"
Connecting to %s
"
%
address
)
self
.
stop_scan
()
return
super
().
connect_by_device_address
(
address
)
def
on_connection_state_change
(
self
,
status
,
state
):
Logger
.
debug
(
"
Connection state changed
"
)
...
...
@@ -44,6 +49,7 @@ class MynitBluetooth(BluetoothDispatcher):
self
.
close_gatt
()
self
.
_current_device
=
None
self
.
_characteristics
=
None
,
None
self
.
start_scan
()
def
on_services
(
self
,
status
,
services
):
self
.
_characteristics
=
(
services
.
search
(
_UART_SERVICE_TX_UUID
),
services
.
search
(
_UART_SERVICE_RX_UUID
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment