pybricks.common.System: Document new system info.

This commit is contained in:
Laurens Valk
2025-02-25 11:16:27 +01:00
parent c77b440270
commit 827eda031b
7 changed files with 39 additions and 46 deletions
+4
View File
@@ -6,6 +6,10 @@
## 3.5.0- 2024-04-11
### Changed
- Update API for firmware 3.6.0. See upstream changelog for details.
### Changed
- Bump version to 3.5.0 without additional changes.
-3
View File
@@ -64,8 +64,6 @@ City Hub
.. automethod:: pybricks.hubs::CityHub.system.set_stop_button
.. automethod:: pybricks.hubs::CityHub.system.name
.. automethod:: pybricks.hubs::CityHub.system.storage
You can store up to 128 bytes of data on this hub. The data is cleared
@@ -78,7 +76,6 @@ City Hub
.. automethod:: pybricks.hubs::CityHub.system.shutdown
.. automethod:: pybricks.hubs::CityHub.system.reset_reason
Status light examples
---------------------
+3 -5
View File
@@ -127,20 +127,18 @@ Essential Hub
.. rubric:: System control
.. automethod:: pybricks.hubs::EssentialHub.system.name
.. automethod:: pybricks.hubs::EssentialHub.system.info
.. automethod:: pybricks.hubs::EssentialHub.system.storage
You can store up to 512 bytes of data on this hub. The data is cleared
when you update the Pybricks firmware.
.. blockimg:: pybricks_blockHubShutdown_EssentialHub
.. automethod:: pybricks.hubs::EssentialHub.system.reset_storage
.. automethod:: pybricks.hubs::EssentialHub.system.shutdown
.. blockimg:: pybricks_blockHubShutdown_EssentialHub
.. automethod:: pybricks.hubs::EssentialHub.system.reset_reason
.. automethod:: pybricks.hubs::EssentialHub.system.shutdown
Status light examples
---------------------
-4
View File
@@ -88,8 +88,6 @@ Move Hub
.. automethod:: pybricks.hubs::MoveHub.system.set_stop_button
.. automethod:: pybricks.hubs::MoveHub.system.name
.. automethod:: pybricks.hubs::MoveHub.system.storage
You can store up to 128 bytes of data on this hub. The data is cleared
@@ -102,8 +100,6 @@ Move Hub
.. automethod:: pybricks.hubs::MoveHub.system.shutdown
.. automethod:: pybricks.hubs::MoveHub.system.reset_reason
Status light examples
---------------------
+4 -4
View File
@@ -182,7 +182,7 @@ Prime Hub / Inventor Hub
.. rubric:: System control
.. automethod:: pybricks.hubs::PrimeHub.system.name
.. automethod:: pybricks.hubs::PrimeHub.system.info
.. automethod:: pybricks.hubs::PrimeHub.system.storage
@@ -195,9 +195,9 @@ Prime Hub / Inventor Hub
.. automethod:: pybricks.hubs::PrimeHub.system.shutdown
.. automethod:: pybricks.hubs::PrimeHub.system.reset_reason
.. note:: The examples below use the ``PrimeHub`` class. The examples work fine
.. note::
The examples below use the ``PrimeHub`` class. The examples work fine
on both hubs because they are the identical. If you prefer, you can
change this to ``InventorHub``.
-4
View File
@@ -117,8 +117,6 @@ Technic Hub
.. automethod:: pybricks.hubs::TechnicHub.system.set_stop_button
.. automethod:: pybricks.hubs::TechnicHub.system.name
.. automethod:: pybricks.hubs::TechnicHub.system.storage
You can store up to 128 bytes of data on this hub. The data is cleared
@@ -131,8 +129,6 @@ Technic Hub
.. automethod:: pybricks.hubs::TechnicHub.system.shutdown
.. automethod:: pybricks.hubs::TechnicHub.system.reset_reason
Status light examples
---------------------
+28 -26
View File
@@ -69,32 +69,6 @@ class System:
Stops your program and shuts the hub down."""
def reset_reason(self) -> int:
"""reset_reason() -> int
Finds out how and why the hub (re)booted. This can be useful to
diagnose some problems.
Returns:
* ``0`` if the hub was previously powered off
normally.
* ``1`` if the hub rebooted automatically, like
after a firmware update.
* ``2`` if the hub previously
crashed due to a watchdog timeout, which indicates a firmware
issue.
"""
def name(self) -> str:
"""name() -> str
Gets the hub name. This is the name you see when connecting
via Bluetooth.
Returns:
The hub name.
"""
@overload
def storage(self, offset: int, *, read: int) -> bytes: ...
@@ -137,6 +111,34 @@ class System:
Resets all user settings to default values and erases user programs.
"""
def info(self) -> dict:
"""info() -> dict
Gets information about the hub as a dictionary with the following keys:
- ``"name"``: The hub name. This is the name you see when connecting
via Bluetooth.
- ``"reset_reason"``: Why the hub (re)booted. It is ``0`` if the hub
was previously powered off normally. It is ``1`` if the hub rebooted
automatically, like after a firmware update. It is ``2`` if the hub
previously crashed due to a watchdog timeout, which indicates a
firmware issue.
- ``"host_connected_ble"``: Whether the hub is connected to a computer,
tablet, or phone via Bluetooth.
- ``"program_start_type"``: It is ``1`` if the program started
automatically when the hub was powered on. It is ``2`` if the program
was started with the hub buttons. It is ``3`` if the program was
started from your connected computer.
Returns:
A dictionary with system info.
.. versionchanged:: 3.6
The name and reset reason where previously available as separate
methods. Now they are included in the info dictionary. The methods
are still available for compatibility.
"""
class DCMotor:
"""Generic class to control simple motors without rotation sensors, such