Skip to content

Commit 99b57dc

Browse files
committed
ble/pybricks: Add protocol v1.1.0 features
The v3.1.x firmware bumps the protocol version to v1.1.0 and adds a few new features.
1 parent edaf06b commit 99b57dc

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
### Added
10+
- Added support for Pybricks Protocol v1.1.0.
11+
712
## [1.0.0-alpha.10] - 2021-06-27
813
### Added
914
- Support for Python 3.9.

pybricksdev/ble/pybricks.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"""
1818

1919
from enum import IntEnum
20+
from struct import unpack
21+
from typing import Literal, Tuple
2022

2123
import semver
2224

@@ -34,7 +36,7 @@ def _pybricks_uuid(short: int) -> str:
3436
.. availability:: Since Pybricks protocol v1.0.0.
3537
"""
3638

37-
PYBRICKS_PROTOCOL_VERSION = semver.VersionInfo(1)
39+
PYBRICKS_PROTOCOL_VERSION = semver.VersionInfo(1, 1, 0)
3840
"""The minimum required Pybricks protocol version supported by this library."""
3941

4042
# The Pybricks protocol is defined at:
@@ -118,6 +120,12 @@ class Status(IntEnum):
118120
.. availability:: Since Pybricks protocol v1.0.0.
119121
"""
120122

123+
SHUTDOWN = 7
124+
"""Hub shutdown was requested.
125+
126+
.. availability:: Since Pybricks protocol v1.1.0.
127+
"""
128+
121129
@property
122130
def flag(self) -> int:
123131
"""Gets the value of the enum as a bit flag."""
@@ -162,3 +170,29 @@ def _standard_uuid(short: int) -> str:
162170
163171
.. availability:: Since Pybricks protocol v1.0.0.
164172
"""
173+
174+
PNP_ID_UUID = _standard_uuid(0x2A50)
175+
"""Standard PnP ID UUID
176+
177+
Vendor ID is :data:`pybricks.ble.lwp3.LEGO_CID`. Product ID is one of
178+
:class:`pybricks.ble.lwp3.bytecodes.HubKind`. Revision is ``0`` for most
179+
hubs or ``1`` for MINDSTORMS Robot Inventor Hub.
180+
181+
.. availability:: Since Pybricks protocol v1.1.0.
182+
"""
183+
184+
185+
def unpack_pnp_id(data: bytes) -> Tuple[Literal["BT", "USB"], int, int, int]:
186+
"""
187+
Unpacks raw data from the PnP ID characteristic.
188+
189+
Args:
190+
data: The raw data
191+
192+
Returns:
193+
Tuple containing the vendor ID type (``'BT'`` or ``'USB'``), the vendor
194+
ID, the product ID and the product revision.
195+
"""
196+
vid_type, vid, pid, rev = unpack("<BHHH", data)
197+
vid_type = "BT" if vid_type else "USB"
198+
return vid_type, vid, pid, rev

0 commit comments

Comments
 (0)