diff --git a/examples/pup/hub_common/ble_broadcast.py b/examples/pup/hub_common/ble_broadcast.py index 4413be6..7a9d5fb 100644 --- a/examples/pup/hub_common/ble_broadcast.py +++ b/examples/pup/hub_common/ble_broadcast.py @@ -17,7 +17,8 @@ while True: right_angle = right_motor.angle() # Set the broadcast data and start broadcasting if not already doing so. - hub.ble.broadcast(left_angle, right_angle) + data = (left_angle, right_angle) + hub.ble.broadcast(data) # Broadcasts are only sent every 100 milliseconds, so there is no reason # to call the broadcast() method more often than that. diff --git a/examples/pup/hub_common/ble_observe.py b/examples/pup/hub_common/ble_observe.py index c1f6988..87249a6 100644 --- a/examples/pup/hub_common/ble_observe.py +++ b/examples/pup/hub_common/ble_observe.py @@ -26,8 +26,7 @@ while True: # *data* contains the same values in the same order # that were passed to hub.ble.broadcast() on the # other hub. - left_angle = data[0] - right_angle = data[1] + left_angle, right_angle = data # Make the motors on this hub mirror the position of the # motors on the other hub. diff --git a/src/pybricks/_common.py b/src/pybricks/_common.py index d24cfe1..13c2827 100644 --- a/src/pybricks/_common.py +++ b/src/pybricks/_common.py @@ -1339,44 +1339,42 @@ class BLE: .. versionadded:: 3.3 """ - def broadcast(self, *args: Union[None, bool, int, float, str, bytes]) -> None: - """broadcast(data0, data1, ...) + def broadcast(self, data: Union[bool, int, float, str, bytes]) -> None: + """broadcast(data) - Starts broadcasting the given data values. + Starts broadcasting the given data on + the *broadcast_channel* you selected when initializing the hub. - Each value can be any of ``int``, ``float``, ``str``, ``bytes``, - ``None``, ``True``, or ``False``. The data is broadcasted on the - *broadcast_channel* you selected when initializing the hub. + Data may be of type ``int``, ``float``, ``str``, ``bytes``, + ``True``, or ``False``, or a tuple thereof. - The total data size is quite limited (26 bytes). ``None``, ``True`` and + The total data size is quite limited (26 bytes). ``True`` and ``False`` take 1 byte each. ``float`` takes 5 bytes. ``int`` takes 2 to 5 bytes depending on how big the number is. ``str`` and ``bytes`` take the number of bytes in the object plus one extra byte. - Params: - args: Zero or more values to be broadcast. - - + Args: + data: The value or values to be broadcast. .. versionadded:: 3.3 """ def observe( self, channel: int - ) -> Optional[Tuple[Union[None, bool, int, float, str, bytes], ...]]: - """observe(channel) -> tuple | None + ) -> Optional[Tuple[Union[bool, int, float, str, bytes], ...]]: + """observe(channel) -> bool | int | float | str | bytes | tuple | None Retrieves the last observed data for a given channel. + Receiving data is more reliable when the hub is not connected + to a computer or other devices at the same time. + Args: channel (int): The channel to observe (0 to 255). Returns: - A tuple of the received data or ``None`` if no recent data is - available. - - .. tip:: Receiving data is more reliable when the hub is not connected - to a computer or other devices at the same time. + The received data in the same format as it was sent, or ``None`` + if no recent data is available. .. versionadded:: 3.3 """ @@ -1386,8 +1384,8 @@ class BLE: Gets the average signal strength in dBm for the given channel. - This is useful for detecting how near the broadcasting device is. A close - device may have a signal strength around -40 dBm while a far away device + This indicates how near the broadcasting device is. Nearby devices + may have a signal strength around -40 dBm, while far away devices might have a signal strength around -70 dBm. Args: