Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
"isort.importStrategy": "fromEnvironment",
"isort.args":["--profile", "black"],
"flake8.importStrategy": "fromEnvironment",
"python.analysis.typeCheckingMode": "strict"
"python.analysis.typeCheckingMode": "strict",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
51 changes: 46 additions & 5 deletions bleak/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# -*- coding: utf-8 -*-
# Created on 2017-11-19 by hbldh <henrik.blidh@nedomkull.com>
"""
__init__.py
"""
import enum
import os
import platform
import sys

from bleak.exc import BleakError


class BleakBackend(enum.Enum):
P4Android = enum.auto()
BlueZDBus = enum.auto()
PythonistaCB = enum.auto()
CoreBluetooth = enum.auto()
WinRT = enum.auto()


def _detect_backend() -> BleakBackend:
if os.environ.get("P4A_BOOTSTRAP") is not None:
return BleakBackend.P4Android

if platform.system() == "Linux":
return BleakBackend.BlueZDBus

if sys.platform == "ios" and "Pythonista3.app" in sys.executable:
# Must be resolved before checking for "Darwin" (macOS),
# as both the Pythonista app for iOS and macOS
# return "Darwin" from platform.system()
return BleakBackend.PythonistaCB

if platform.system() == "Darwin":
return BleakBackend.CoreBluetooth

if platform.system() == "Windows":
return BleakBackend.WinRT

raise BleakError(f"Unsupported platform: {platform.system()}")


_bleak_backend = None


def get_backend() -> BleakBackend:
global _bleak_backend
if _bleak_backend is None:
_bleak_backend = _detect_backend()
return _bleak_backend
23 changes: 9 additions & 14 deletions bleak/backends/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
else:
from collections.abc import Buffer

from bleak.backends import BleakBackend, get_backend
from bleak.backends.characteristic import BleakGATTCharacteristic
from bleak.backends.descriptor import BleakGATTDescriptor
from bleak.backends.device import BLEDevice
Expand Down Expand Up @@ -213,20 +214,16 @@ def get_platform_client_backend_type() -> type[BaseBleakClient]:
"""
Gets the platform-specific :class:`BaseBleakClient` type.
"""
if os.environ.get("P4A_BOOTSTRAP") is not None:
backend = get_backend()
if backend == BleakBackend.P4Android:
from bleak.backends.p4android.client import BleakClientP4Android

return BleakClientP4Android

if platform.system() == "Linux":
elif backend == BleakBackend.BlueZDBus:
from bleak.backends.bluezdbus.client import BleakClientBlueZDBus

return BleakClientBlueZDBus

if sys.platform == "ios" and "Pythonista3.app" in sys.executable:
# Must be resolved before checking for "Darwin" (macOS),
# as both the Pythonista app for iOS and macOS
# return "Darwin" from platform.system()
elif backend == BleakBackend.PythonistaCB:
try:
from bleak_pythonista import BleakClientPythonistaCB

Expand All @@ -235,15 +232,13 @@ def get_platform_client_backend_type() -> type[BaseBleakClient]:
raise ImportError(
"Ensure you have `bleak-pythonista` package installed."
) from e

if platform.system() == "Darwin":
elif backend == BleakBackend.CoreBluetooth:
from bleak.backends.corebluetooth.client import BleakClientCoreBluetooth

return BleakClientCoreBluetooth

if platform.system() == "Windows":
elif backend == BleakBackend.WinRT:
from bleak.backends.winrt.client import BleakClientWinRT

return BleakClientWinRT

raise BleakError(f"Unsupported platform: {platform.system()}")
else:
raise BleakError(f"Unsupported backend: {backend}")
23 changes: 9 additions & 14 deletions bleak/backends/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections.abc import Callable, Coroutine, Hashable
from typing import Any, NamedTuple, Optional

from bleak.backends import BleakBackend, get_backend
from bleak.backends.device import BLEDevice
from bleak.exc import BleakError

Expand Down Expand Up @@ -286,20 +287,16 @@ def get_platform_scanner_backend_type() -> type[BaseBleakScanner]:
"""
Gets the platform-specific :class:`BaseBleakScanner` type.
"""
if os.environ.get("P4A_BOOTSTRAP") is not None:
backend = get_backend()
if backend == BleakBackend.P4Android:
from bleak.backends.p4android.scanner import BleakScannerP4Android

return BleakScannerP4Android

if platform.system() == "Linux":
elif backend == BleakBackend.BlueZDBus:
from bleak.backends.bluezdbus.scanner import BleakScannerBlueZDBus

return BleakScannerBlueZDBus

if sys.platform == "ios" and "Pythonista3.app" in sys.executable:
# Must be resolved before checking for "Darwin" (macOS),
# as both the Pythonista app for iOS and macOS
# return "Darwin" from platform.system()
elif backend == BleakBackend.PythonistaCB:
try:
from bleak_pythonista import BleakScannerPythonistaCB

Expand All @@ -308,15 +305,13 @@ def get_platform_scanner_backend_type() -> type[BaseBleakScanner]:
raise ImportError(
"Ensure you have `bleak-pythonista` package installed."
) from e

if platform.system() == "Darwin":
elif backend == BleakBackend.CoreBluetooth:
from bleak.backends.corebluetooth.scanner import BleakScannerCoreBluetooth

return BleakScannerCoreBluetooth

if platform.system() == "Windows":
elif backend == BleakBackend.WinRT:
from bleak.backends.winrt.scanner import BleakScannerWinRT

return BleakScannerWinRT

raise BleakError(f"Unsupported platform: {platform.system()}")
else:
raise BleakError(f"Unsupported backend: {backend}")
7 changes: 7 additions & 0 deletions nrf_dongle_fw/.west/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[manifest]
path = zephyr
file = west.yml

[zephyr]
base = zephyr

Binary file added nrf_dongle_fw/nrf52840dongle_hci_uart.zip
Binary file not shown.
23 changes: 23 additions & 0 deletions nrf_dongle_fw/setup_nrf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
nrf52840 Dongle Firmware
-------------------------
This is the nrf52840 Dongle Firmware for the integrationtests

Setup
1. install `nrfutil`
2. install `nrf5sdk-tools` via `nrfutil install nrf5sdk-tools`
3. `pip install west`
4. `cd nrf_dongle_fw`
5. `west init`
6. `west update`
7. `west build -b nrf52840dongle/nrf52840 zephyr/samples/bluetooth/hci_uart`
8. Create update package
```
nrfutil nrf5sdk-tools pkg generate \
--hw-version 52 \
--sd-req=0x00 \
--application build/zephyr/zephyr.hex \
--application-version 1 \
nrf52840dongle_hci_uart.zip
```
9. find dongle (on macos: `ls /dev/tty.usbmodem*`)
10. flash firmware: ``nrfutil nrf5sdk-tools dfu usb-serial -pkg nrf52840dongle_hci_uart.zip -p /dev/tty.usbmodemSOMESTRING``
Loading
Loading