diff --git a/pybricks/_common.pyi b/pybricks/_common.pyi index db0ee0b..b491d4d 100644 --- a/pybricks/_common.pyi +++ b/pybricks/_common.pyi @@ -1,9 +1,10 @@ # SPDX-License-Identifier: MIT # Copyright (c) 2020 The Pybricks Authors -from typing import Iterable, List, Optional, Tuple, Union, overload +from pybricks.geometry import Matrix +from typing import Collection, Iterable, List, Optional, Tuple, Union, overload -from .parameters import Button, Color, Direction, Stop, Port +from .parameters import Button, Color, Direction, Side, Stop, Port, Axis from .media.ev3dev import SoundFile class DCMotor: @@ -59,7 +60,7 @@ class Motor(DCMotor): self, port: Port, positive_direction: Direction = Direction.CLOCKWISE, - gears: Optional[Union[List[int], List[List[int]]]] = None, + gears: Optional[Union[Collection[int], Collection[Collection[int]]]] = None, ): ... def angle(self) -> int: ... def speed(self) -> int: ... @@ -97,15 +98,58 @@ class Speaker: class Light: def on(self, brightness: int = 100) -> None: ... def off(self) -> None: ... + def blink(self, durations: Collection[int]) -> None: ... + def animate(self, brightness_values: Collection[int], interval: int) -> None: ... + def reset(self) -> None: ... class ColorLight: def on(self, color: Optional[Color]) -> None: ... def off(self) -> None: ... - def rgb(self, red: int, green: int, blue: int) -> None: ... + def blink(self, color: Color, durations: Collection[int]) -> None: ... + def animate(self, colors: Collection[Color], interval: int) -> None: ... + def reset(self) -> None: ... -class KeyPad: - def pressed(self) -> List[Button]:... +class LightArray: + def __init__(self, n: int): ... + def on(self, brightness: int) -> None: ... + def off(self) -> None: ... + def blink(self, durations: Collection[int]) -> None: ... + def animate(self, brightness_values: Collection[int], interval: int) -> None: ... + +class LightMatrix: + def __init__(self, rows: int, columns: int): ... + def orientation(self, up: Side) -> None: ... + def image(self, matrix: Matrix) -> None: ... + def animate(self, matrices: Collection[Matrix], interval, int) -> None: ... + def pixel(self, row: int, column: int, brightness: int = 100) -> None: ... + def off(self) -> None: ... + def number(self, number: int) -> None: ... + def char(self, char: str) -> None: ... + def text(self, text: str, on: int = 500, off: int = 50) -> None: ... + def reset(self) -> None: ... + +class Keypad: + def pressed(self) -> List[Button]: ... class Battery: def voltage(self) -> int: ... def current(self) -> int: ... + +class Accelerometer: + def neutral(self, top: Axis, front: Axis) -> None: ... + @overload + def acceleration(self) -> vector[float, float, float]: ... + @overload + def acceleration(self, axis: Axis) -> int: ... + def tilt(self) -> Tuple[int, int]: ... + def tapped(self) -> bool: ... + def shaken(self) -> bool: ... + def up(self) -> Side: ... + +class IMU(Accelerometer): + def heading(self) -> int: ... + def reset_heading(self, angle): ... + @overload + def gyro(self) -> scalar[float, float, float]: ... + @overload + def gyro(self, axis: Axis) -> int: ... diff --git a/pybricks/geometry.pyi b/pybricks/geometry.pyi new file mode 100644 index 0000000..4215d61 --- /dev/null +++ b/pybricks/geometry.pyi @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2020 The Pybricks Authors + +from typing import Collection, Optional, Tuple + +class Matrix: + def __init__(self, rows: Collection[int]): ... + @property + def T(self) -> Matrix: ... + @property + def shape(self) -> Tuple[int, int]: ... + +def vector(x: float, y: float, z: Optional[float] = None) -> Matrix: ... diff --git a/pybricks/hubs.pyi b/pybricks/hubs.pyi index 744936b..1f7a1ca 100644 --- a/pybricks/hubs.pyi +++ b/pybricks/hubs.pyi @@ -1,7 +1,7 @@ # SPDX-License-Identifier: MIT # Copyright (c) 2020 The Pybricks Authors -from ._common import Speaker, Battery, ColorLight, KeyPad +from ._common import Speaker, Battery, ColorLight, LightMatrix, Keypad from .media.ev3dev import Image class EV3Brick: @@ -9,4 +9,30 @@ class EV3Brick: speaker: Speaker battery: Battery light: ColorLight - buttons = KeyPad + buttons = Keypad + +class MoveHub: + battery: Battery + light: ColorLight + + +class CityHub: + battery: Battery + light: ColorLight + + +class TechnicHub: + battery: Battery + light: ColorLight + + +class PrimeHub: + battery: Battery + light: ColorLight + display: LightMatrix + buttons: Keypad + speaker: Speaker + + +class InventorHub(PrimeHub): ... + \ No newline at end of file diff --git a/pybricks/iodevices.py b/pybricks/iodevices.py index 6e14aea..4efb7a4 100644 --- a/pybricks/iodevices.py +++ b/pybricks/iodevices.py @@ -34,7 +34,7 @@ class PUPDevice: """ pass - def write(self, mode, values): + def write(self, mode, data): """Writes values to the sensor. Only selected sensors and modes support this. diff --git a/pybricks/iodevices.pyi b/pybricks/iodevices.pyi index 3badad3..b474374 100644 --- a/pybricks/iodevices.pyi +++ b/pybricks/iodevices.pyi @@ -1,14 +1,19 @@ # SPDX-License-Identifier: MIT # Copyright (c) 2020 The Pybricks Authors -from typing import Optional, Tuple +from typing import Dict, Optional, Tuple from .parameters import Port +class PUPDevice: + def __init__(self, port: Port): ... + def info(self) -> Dict[str, str]: ... + def read(self, mode: int) -> Tuple: ... + def write(self, mode: int, data: Tuple) -> None: ... + class LUMPDevice: def __init__(self, port: Port): ... def read(self, mode: int) -> Tuple: ... - def write(self, mode: int, values: Tuple): ... class Ev3devSensor: sensor_index: int diff --git a/pybricks/parameters.pyi b/pybricks/parameters.pyi index ca9665b..60caa0c 100644 --- a/pybricks/parameters.pyi +++ b/pybricks/parameters.pyi @@ -11,6 +11,10 @@ class Color: BROWN: Color ORANGE: Color PURPLE: Color + def __mul__(self, scale: float) -> Color: ... + def __rmul__(self, scale: float) -> Color: ... + def __truediv__(self, scale: float) -> Color: ... + def __floordiv__(self, scale: int) -> Color: ... class Port: A: Port @@ -42,3 +46,17 @@ class Button: UP: Button BEACON: Button RIGHT_UP: Button + +class Axis: + X: Axis + Y: Axis + Z: Axis + ALL: Axis + +class Side: + RIGHT: Side + FRONT: Side + TOP: Side + LEFT: Side + BACK: Side + BOTTOM: Side diff --git a/pybricks/pupdevices.pyi b/pybricks/pupdevices.pyi new file mode 100644 index 0000000..4fb9a32 --- /dev/null +++ b/pybricks/pupdevices.pyi @@ -0,0 +1,71 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2020 The Pybricks Authors + +from typing import Collection, List, Optional, Tuple + +from ._common import Keypad, DCMotor, ColorLight, LightArray, Motor as BaseMotor, Light as BaseLight + +from .parameters import Color, Direction, Port + +class Motor(BaseMotor): ... + +class RemoteControl: + light: ColorLight + buttons: Keypad + def __init__(self, device: str = None, timeout: int = 10000): ... + +class TiltSensor: + def __init__(self, port: Port): ... + def tilt(self) -> Tuple[int, int]: ... + +class ColorDistanceSensor: + """LEGO® Powered Up Color and Distance Sensor.""" + + light: ColorLight + def __init__(self, port: Port): ... + def color(self) -> Optional[Color]: ... + def ambient(self) -> int: ... + def reflection(self) -> int: ... + def detectable_colors(self, colors: Collection[Color]) -> None: ... + def hsv(self) -> Color: ... + def distance(self) -> int: ... + +class PFMotor(DCMotor): + def __init__( + self, + sensor: ColorDistanceSensor, + channel: int, + color: Color, + positive_direction: Direction = Direction.CLOCKWISE, + ): ... + +class ColorSensor: + lights: LightArray + def __init__(self, port: Port): ... + def color(self, surface: bool = True) -> Optional[Color]: ... + def detectable_colors(self, colors: Collection[Color]) -> None: ... + def hsv(self, surface: bool = True) -> Color: ... + def ambient(self) -> int: ... + def reflection(self) -> int: ... + +class UltrasonicSensor: + lights: LightArray + def __init__(self, port: Port): ... + def distance(self) -> int: ... + def presence(self) -> bool: ... + +class ForceSensor: + def __init__(self, port: Port): ... + def force(self) -> int: ... + def distance(self) -> int: ... + def pressed(self, force: int = 3) -> bool: ... + def touched(self) -> bool: ... + +class InfraredSensor: + def __init__(self, port: Port): ... + def reflection(self) -> int: ... + def distance(self) -> int: ... + def count(self) -> int: ... + +class Light(BaseLight): + def __init__(self, port: Port): ...