mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 01:24:17 +00:00
api: add type hints for v3
This updates the type hints for the current v3 API.
This commit is contained in:
committed by
David Lechner
parent
3a66b8e053
commit
db65f8d646
+50
-6
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
+28
-2
@@ -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): ...
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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): ...
|
||||
Reference in New Issue
Block a user