Skip to content

Commit

Permalink
pybricks.common.System: Add initial documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Jul 7, 2021
1 parent ce1456c commit 3ce741a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/api/hubs/cityhub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ City Hub

.. automethod:: pybricks.hubs::CityHub.battery.current

.. rubric:: System control

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

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

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

Status light examples
---------------------

Expand Down
8 changes: 8 additions & 0 deletions doc/api/hubs/movehub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ Move Hub

.. automethod:: pybricks.hubs::MoveHub.battery.current

.. rubric:: System control

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

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

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

Status light examples
---------------------

Expand Down
8 changes: 8 additions & 0 deletions doc/api/hubs/primehub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ Prime Hub / Inventor Hub

.. automethod:: pybricks.hubs::PrimeHub.battery.current

.. rubric:: System control

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

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

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

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

.. automethod:: pybricks.hubs::TechnicHub.battery.current

.. rubric:: System control

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

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

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

Status light examples
---------------------

Expand Down
38 changes: 38 additions & 0 deletions pybricks/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@
from .parameters import Direction, Stop


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.
Normally, the center button is used to stop a running script. You can
change or disable this behavior in order to use the button for other
purposes.
Arguments:
Button: A button such
as :attr:`Button.CENTER <pybricks.parameters.Button.CENTER>`,
or a tuple of multiple buttons. Choose ``None`` to disable the
stop button altogether.
"""
pass


class DCMotor:
"""Generic class to control simple motors without rotation sensors, such
as train motors."""
Expand Down
5 changes: 5 additions & 0 deletions pybricks/hubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ._common import (Speaker as _Speaker, Battery as _Battery,
ColorLight as _ColorLight, Keypad as _Keypad,
LightMatrix as _LightMatrix, IMU as _IMU,
System as _System,
SimpleAccelerometer as _SimpleAccelerometer)
from .media.ev3dev import Image as _Image
from .parameters import Button as _Button
Expand Down Expand Up @@ -37,6 +38,7 @@ class MoveHub:
battery = _Battery()
light = _ColorLight()
imu = _SimpleAccelerometer()
system = _System()


class CityHub:
Expand All @@ -46,6 +48,7 @@ class CityHub:
# In reality, they are instance attributes created by __init__.
battery = _Battery()
light = _ColorLight()
system = _System()


class TechnicHub:
Expand All @@ -56,6 +59,7 @@ class TechnicHub:
battery = _Battery()
light = _ColorLight()
imu = _IMU()
system = _System()

def __init__(self, top_side=_Axis.Z, front_side=_Axis.X):
"""__init__(top_side=Axis.Z, front_side=Axis.X)
Expand Down Expand Up @@ -90,6 +94,7 @@ class PrimeHub:
display = _LightMatrix(5, 5)
speaker = _Speaker()
imu = _IMU()
system = _System()

def __init__(self, top_side=_Axis.Z, front_side=_Axis.X):
"""__init__(top_side=Axis.Z, front_side=Axis.X)
Expand Down

0 comments on commit 3ce741a

Please sign in to comment.