Skip to content

Commit

Permalink
pybricks.common.System: Add shutdown method.
Browse files Browse the repository at this point in the history
Also drop reset() and update reset_reason() after pybricks/support#379
  • Loading branch information
laurensvalk committed Jul 7, 2021
1 parent 3ce741a commit 7643212
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
6 changes: 3 additions & 3 deletions doc/api/hubs/cityhub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ City Hub

.. rubric:: System control

.. automethod:: pybricks.hubs::MoveHub.system.reset
.. automethod:: pybricks.hubs::CityHub.system.set_stop_button

.. automethod:: pybricks.hubs::MoveHub.system.reset_reason
.. automethod:: pybricks.hubs::CityHub.system.shutdown

.. automethod:: pybricks.hubs::MoveHub.system.set_stop_button
.. automethod:: pybricks.hubs::CityHub.system.reset_reason

Status light examples
---------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/api/hubs/movehub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Move Hub

.. rubric:: System control

.. automethod:: pybricks.hubs::MoveHub.system.reset
.. automethod:: pybricks.hubs::MoveHub.system.set_stop_button

.. automethod:: pybricks.hubs::MoveHub.system.reset_reason
.. automethod:: pybricks.hubs::MoveHub.system.shutdown

.. automethod:: pybricks.hubs::MoveHub.system.set_stop_button
.. automethod:: pybricks.hubs::MoveHub.system.reset_reason

Status light examples
---------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/api/hubs/primehub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ Prime Hub / Inventor Hub

.. rubric:: System control

.. automethod:: pybricks.hubs::MoveHub.system.reset
.. automethod:: pybricks.hubs::PrimeHub.system.set_stop_button

.. automethod:: pybricks.hubs::MoveHub.system.reset_reason
.. automethod:: pybricks.hubs::PrimeHub.system.shutdown

.. automethod:: pybricks.hubs::MoveHub.system.set_stop_button
.. automethod:: pybricks.hubs::PrimeHub.system.reset_reason

.. 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
Expand Down
6 changes: 3 additions & 3 deletions doc/api/hubs/technichub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Technic Hub

.. rubric:: System control

.. automethod:: pybricks.hubs::MoveHub.system.reset
.. automethod:: pybricks.hubs::TechnicHub.system.set_stop_button

.. automethod:: pybricks.hubs::MoveHub.system.reset_reason
.. automethod:: pybricks.hubs::TechnicHub.system.shutdown

.. automethod:: pybricks.hubs::MoveHub.system.set_stop_button
.. automethod:: pybricks.hubs::TechnicHub.system.reset_reason

Status light examples
---------------------
Expand Down
36 changes: 17 additions & 19 deletions pybricks/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@
class System:
"""System control actions for a hub."""

def reset(self, action):
"""Shuts the hub down and optionally reboots.
Arguments:
action (int): Choose ``0`` to shut down, ``1`` to reboot,
or ``2`` to enter firmware update mode.
"""
pass

def reset_reason(self):
"""Gets the reason for the most recent reset.
Returns:
int: Gives ``0`` if the hub was shut down, or ``1`` if the hub
rebooted. It gives ``2`` if the watchdog timer expired, which
indicates a firmware issue.
"""
pass

def set_stop_button(self, button):
"""Sets the button or button combination that stops a running script.
Expand All @@ -44,6 +25,23 @@ def set_stop_button(self, button):
"""
pass

def shutdown(self):
"""Stops your program and shuts the hub down."""
pass

def reset_reason(self):
"""Finds out how and why the hub (re)booted. This can be useful to
diagnose some problems.
Returns:
int: Returns ``0`` if the hub was previously powered off
normally. Returns ``1`` if the hub rebooted automatically, like
after a firmware update. Returns ``2`` if the hub previously
crashed due to a watchdog timeout, which indicates a firmware
issue.
"""
pass


class DCMotor:
"""Generic class to control simple motors without rotation sensors, such
Expand Down

0 comments on commit 7643212

Please sign in to comment.