diff --git a/doc/ev3dev/ev3brick.rst b/doc/ev3dev/ev3brick.rst index d36d7b6..8970185 100644 --- a/doc/ev3dev/ev3brick.rst +++ b/doc/ev3dev/ev3brick.rst @@ -8,22 +8,22 @@ Buttons ------- -.. autofunction:: pybricks.ev3brick.buttons +.. automethod:: pybricks.ev3brick.buttons.pressed Examples:: # Do something if the left button is pressed - if Button.LEFT in brick.buttons(): + if Button.LEFT in brick.buttons.pressed(): print("The left button is pressed.") :: # Wait until any of the buttons are pressed - while not any(brick.buttons()): + while not any(brick.buttons.pressed()): wait(10) # Wait until all buttons are released - while any(brick.buttons()): + while any(brick.buttons.pressed()): wait(10) diff --git a/doc/lpf2/lpf2devices.rst b/doc/lpf2/lpf2devices.rst index e3729c7..7eff05c 100644 --- a/doc/lpf2/lpf2devices.rst +++ b/doc/lpf2/lpf2devices.rst @@ -122,3 +122,18 @@ Color and Distance Sensor .. automethod:: pybricks._common.light.on .. automethod:: pybricks._common.light.off + +Other Devices +--------------- + +Remote Control +^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: pybricks.lpf2devices.RemoteControl + :no-members: + + .. automethod:: pybricks._common.light.on + + .. automethod:: pybricks._common.light.off + + .. automethod:: pybricks._common.buttons.pressed diff --git a/pybricks/_common.py b/pybricks/_common.py index eab574e..ae0d47a 100644 --- a/pybricks/_common.py +++ b/pybricks/_common.py @@ -557,6 +557,19 @@ class LightGrid(): pass +class KeyPad(): + """Get status of buttons on a keypad layout.""" + + def pressed(self): + """Check which buttons are currently pressed. + + :returns: List of pressed buttons. + :rtype: List of :class:`Button <.parameters.Button>` + + """ + pass + + class Battery(): """Get the status of a battery.""" @@ -589,3 +602,6 @@ light.rgb = ColorLight.rgb lights = ModuleType('LightArray') lights.on = LightArray.on lights.off = LightArray.off + +buttons = ModuleType('KeyPad') +buttons.pressed = KeyPad.pressed diff --git a/pybricks/ev3brick.py b/pybricks/ev3brick.py index 2124b56..d63dd81 100644 --- a/pybricks/ev3brick.py +++ b/pybricks/ev3brick.py @@ -1,19 +1,9 @@ """LEGO® MINDSTORMS® EV3 Brick.""" -from ._common import Speaker, Display, Battery, ColorLight - - -def buttons(): - """Check which buttons on the EV3 Brick are currently pressed. - - :returns: List of pressed buttons. - :rtype: List of :class:`Button ` - - """ - pass - +from ._common import Speaker, Display, Battery, ColorLight, KeyPad sound = Speaker() display = Display() battery = Battery() light = ColorLight() +buttons = KeyPad() diff --git a/pybricks/lpf2devices.py b/pybricks/lpf2devices.py index a54ed0d..72a8fe1 100644 --- a/pybricks/lpf2devices.py +++ b/pybricks/lpf2devices.py @@ -2,6 +2,9 @@ from ._common import Motor as CommonMotor, ColorLight +from ._common import KeyPad +# The above abviously needs fixing (but not until after fixing merge conflict) + class Motor(CommonMotor): """LEGO® Power Functions 2.0 motors""" @@ -17,6 +20,24 @@ class Motor(CommonMotor): pass +class RemoteControl(): + """LEGO® Power Functions 2.0 Bluetooth Remote Control/Handset (6214560)""" + + def __init__(self, device=None, timeout=10000): + """Connect the handset to the hub. + + Arguments: + device (str): Bluetooth address of the handset (? TODO ?). + If you do not specify a device identifier, the hub will + attempt to pair with any handset that is currently in + advertising mode. + timeout (:ref:`time`): The amount of time before giving up + searching. + """ + self.buttons = KeyPad() + self.light = ColorLight() + + class ColorDistanceSensor(): """LEGO® Power Functions 2.0 Color and Distance Sensor (?/6182145) """