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
Compare revisions
dded49dc3aff1b57178938a46a08e81a36658bb2 to 0783830dc362060a967ce9a708cd38aed93b3e11
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
Teckids/hacknfun/libs/mynit
Select target project
No results found
0783830dc362060a967ce9a708cd38aed93b3e11
Select Git revision
Branches
bleak
master
Swap
Target
Teckids/hacknfun/libs/mynit
Select target project
Teckids/hacknfun/libs/mynit
schubisu/esp-init
2 results
dded49dc3aff1b57178938a46a08e81a36658bb2
Select Git revision
Branches
bleak
master
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (5)
Make button list work
· bd079dd1
Nik | Klampfradler
authored
3 years ago
Verified
bd079dd1
Log device name and do not stop scan
· 5cbe207a
Nik | Klampfradler
authored
3 years ago
Verified
5cbe207a
Implement device button click to conncet to device
· ca60846b
Nik | Klampfradler
authored
3 years ago
Verified
ca60846b
Fix button actions for connect
· 2db55924
Nik | Klampfradler
authored
3 years ago
Verified
2db55924
Rewrite GATT connect to use example code
· 0783830d
Nik | Klampfradler
authored
3 years ago
Verified
0783830d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
companion/app.py
+40
-9
40 additions, 9 deletions
companion/app.py
companion/bluetooth.py
+17
-8
17 additions, 8 deletions
companion/bluetooth.py
companion/mynitcompanion.kv
+1
-1
1 addition, 1 deletion
companion/mynitcompanion.kv
with
58 additions
and
18 deletions
companion/app.py
View file @
0783830d
from
kivy.app
import
App
from
kivy.app
import
App
from
kivy.clock
import
mainthread
from
kivy.logger
import
Logger
from
kivy.logger
import
Logger
from
kivy.properties
import
ObjectProperty
from
kivy.properties
import
ObjectProperty
from
kivy.uix.button
import
Button
from
kivy.uix.button
import
Button
...
@@ -12,17 +13,30 @@ class DeviceListWidget(Widget):
...
@@ -12,17 +13,30 @@ class DeviceListWidget(Widget):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_
d
evi
ces_buttons_map
=
{}
self
.
_
pr
evi
ous_addresses
=
{}
def
update_device_buttons
(
self
,
devices
):
@mainthread
Logger
.
debug
(
"
Updating device
buttons
"
)
def
update_device_buttons
(
self
,
buttons
_map
):
self
.
_
device
s_
buttons
_map
=
devices
Logger
.
info
(
"
Updating
device
buttons
"
)
self
.
device_buttons
.
clear_widgets
()
for
address
,
info
in
buttons_map
.
items
():
for
label
,
device
in
self
.
_devices_buttons_map
.
items
():
if
address
in
self
.
_previous_addresses
:
Logger
.
debug
(
"
Adding button for %s
"
%
label
)
Logger
.
info
(
"
Button for %s already there, skipping
"
%
address
)
btn
=
Button
(
text
=
label
)
continue
label
,
cb_connect
=
info
Logger
.
info
(
"
Adding button for %s (%s)
"
%
(
address
,
label
))
btn
=
Button
(
text
=
label
,
on_press
=
cb_connect
)
self
.
device_buttons
.
add_widget
(
btn
)
self
.
device_buttons
.
add_widget
(
btn
)
self
.
_previous_addresses
[
address
]
=
btn
for
address
in
self
.
_previous_addresses
:
if
address
not
in
self
.
_previous_addresses
:
Logger
.
info
(
"
%s no longer in device list, removing button
"
%
address
)
self
.
remove_widget
(
self
.
_previous_addresses
[
address
])
del
self
.
_previous_addresses
[
address
]
class
MynitCompanionApp
(
App
):
class
MynitCompanionApp
(
App
):
...
@@ -32,4 +46,21 @@ class MynitCompanionApp(App):
...
@@ -32,4 +46,21 @@ class MynitCompanionApp(App):
self
.
_bluetooth
=
MynitBluetooth
(
self
)
self
.
_bluetooth
=
MynitBluetooth
(
self
)
def
update_device_list
(
self
,
devices
):
def
update_device_list
(
self
,
devices
):
self
.
widget
.
update_device_buttons
({
device
.
getAddress
():
device
for
device
in
devices
})
Logger
.
info
(
"
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
.
set_device
(
device
)
buttons_map
[
device
.
getAddress
()]
=
(
device
.
getName
(),
cb_connect
)
self
.
widget
.
update_device_buttons
(
buttons_map
)
def
build
(
self
):
self
.
widget
=
DeviceListWidget
()
return
self
.
widget
This diff is collapsed.
Click to expand it.
companion/bluetooth.py
View file @
0783830d
...
@@ -16,7 +16,7 @@ class MynitBluetooth(BluetoothDispatcher):
...
@@ -16,7 +16,7 @@ class MynitBluetooth(BluetoothDispatcher):
self
.
_app
=
app
self
.
_app
=
app
self
.
_available_devices
=
set
()
self
.
_available_devices
=
set
()
self
.
_
current_
device
=
None
self
.
_device
=
None
self
.
_characteristics
=
None
,
None
self
.
_characteristics
=
None
,
None
Logger
.
info
(
"
Starting BLE scanning
"
)
Logger
.
info
(
"
Starting BLE scanning
"
)
...
@@ -24,26 +24,35 @@ class MynitBluetooth(BluetoothDispatcher):
...
@@ -24,26 +24,35 @@ class MynitBluetooth(BluetoothDispatcher):
self
.
start_scan
()
self
.
start_scan
()
def
on_device
(
self
,
device
,
rssi
,
advertisement
):
def
on_device
(
self
,
device
,
rssi
,
advertisement
):
Logger
.
debug
(
"
BLE device discovered: %s
"
%
device
.
getAddress
())
Logger
.
info
(
"
BLE device discovered: %s
"
%
device
.
getAddress
())
self
.
stop_scan
()
if
device
not
in
self
.
_available_devices
:
if
device
not
in
self
.
_available_devices
:
Logger
.
info
(
"
New BLE device discovered: %s
"
%
device
.
getAddress
())
Logger
.
info
(
"
New BLE device discovered: %s
(%s)
"
%
(
device
.
getAddress
()
,
device
.
getName
())
)
self
.
_available_devices
.
add
(
device
)
self
.
_available_devices
.
add
(
device
)
self
.
_app
.
update_device_list
(
self
.
_available_devices
)
self
.
_app
.
update_device_list
(
self
.
_available_devices
)
def
set_device
(
self
,
device
):
self
.
_device
=
device
self
.
stop_scan
()
def
on_scan_completed
(
self
):
if
self
.
_device
:
self
.
connect_gatt
(
self
.
_device
)
def
on_connection_state_change
(
self
,
status
,
state
):
def
on_connection_state_change
(
self
,
status
,
state
):
Logger
.
debug
(
"
Connection state changed
"
)
Logger
.
info
(
"
Connection state changed
- state: %d, status: %d
"
%
(
state
,
status
)
)
if
status
==
GATT_SUCCESS
and
state
:
if
status
==
GATT_SUCCESS
:
Logger
.
info
(
"
Connection successful, discovering services
"
)
Logger
.
info
(
"
Connection successful, discovering services
"
)
self
.
_current_device
=
device
self
.
discover_services
()
self
.
discover_services
()
else
:
else
:
Logger
.
warning
(
"
Connection failed, disconnecting and resetting
"
)
Logger
.
warning
(
"
Connection failed, disconnecting and resetting
"
)
self
.
close_gatt
()
self
.
close_gatt
()
self
.
_current_device
=
None
self
.
_characteristics
=
None
,
None
self
.
_characteristics
=
None
,
None
self
.
_device
=
None
self
.
start_scan
()
def
on_services
(
self
,
status
,
services
):
def
on_services
(
self
,
status
,
services
):
Logger
.
info
(
"
Services discovered: %s
"
%
services
)
self
.
_characteristics
=
(
services
.
search
(
_UART_SERVICE_TX_UUID
),
services
.
search
(
_UART_SERVICE_RX_UUID
))
self
.
_characteristics
=
(
services
.
search
(
_UART_SERVICE_TX_UUID
),
services
.
search
(
_UART_SERVICE_RX_UUID
))
This diff is collapsed.
Click to expand it.
companion/mynitcompanion.kv
View file @
0783830d
#:kivy 1.0.9
#:kivy 1.0.9
DeviceListWidget:
<
DeviceListWidget
>
:
device_buttons: device_buttons
device_buttons: device_buttons
BoxLayout:
BoxLayout:
...
...
This diff is collapsed.
Click to expand it.