mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 01:24:17 +00:00
fake-api: init
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Laurens Valk and David Lechner
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -4,3 +4,7 @@ Fake Pybricks
|
||||
This is a standard Python 3.x library that provides the Pybricks API with a
|
||||
totally fake implementation. It is used to provide documentation and type
|
||||
hints for code completion.
|
||||
|
||||
Local install for developers: Navigate to this directory and then run
|
||||
``python3 setup.py sdist bdist_wheel``
|
||||
``pip3 install --user -e .``
|
||||
@@ -1,7 +0,0 @@
|
||||
"""Private base class for ports"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Port(Enum):
|
||||
pass
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
"""This module is for the LEGO BOOST Move Hub."""
|
||||
|
||||
import _pbport
|
||||
|
||||
from pblight import Light
|
||||
from pbsensor import TouchSensor
|
||||
|
||||
|
||||
class Port(_pbport.Port):
|
||||
"""The ports on the LEGO BOOST Move Hub"""
|
||||
HUB = -1
|
||||
"""The Move Hub itself"""
|
||||
|
||||
A = ord('A')
|
||||
"""Built-in motor 'A'"""
|
||||
|
||||
B = ord('B')
|
||||
"""Built-in motor 'B'"""
|
||||
|
||||
C = ord('C')
|
||||
"""I/O port 'C'"""
|
||||
|
||||
D = ord('D')
|
||||
"""I/O port 'D'"""
|
||||
|
||||
button = TouchSensor(Port.HUB)
|
||||
"""The button on the Move Hub"""
|
||||
|
||||
light = Light(Port.HUB)
|
||||
"""The light on the Move Hub"""
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
"""Lights can be built into programmable bricks or can be plugged into I/O
|
||||
ports."""
|
||||
|
||||
from collections import namedtuple
|
||||
from enum import Enum
|
||||
from typing import Union
|
||||
|
||||
from _pbport import Port
|
||||
|
||||
|
||||
class Color(Enum):
|
||||
"""Color names"""
|
||||
|
||||
red = 1
|
||||
"""The light will be red"""
|
||||
|
||||
orange = 2
|
||||
"""The light will be orange"""
|
||||
|
||||
yellow = 3
|
||||
"""The light will be yellow"""
|
||||
|
||||
green = 4
|
||||
"""The light will be green"""
|
||||
|
||||
blue = 5
|
||||
"""The light will be blue"""
|
||||
|
||||
purple = 6
|
||||
"""The light will be purple"""
|
||||
|
||||
white = 7
|
||||
"""The light will be white"""
|
||||
|
||||
RGB = namedtuple('RGB', 'r g b')
|
||||
"""Red, green, blue value"""
|
||||
|
||||
|
||||
class Pattern(Enum):
|
||||
"""Blink patterns"""
|
||||
|
||||
flash = 1
|
||||
"""The light will alternate between *color1* and *color2* once per
|
||||
second"""
|
||||
|
||||
fade = 2
|
||||
"""The light will fade gradually from *color1* to *color2* and back once
|
||||
per second"""
|
||||
|
||||
|
||||
class Light():
|
||||
"""Class representing a light"""
|
||||
def __init__(self, port: Port):
|
||||
"""Creates a new instance
|
||||
|
||||
Args:
|
||||
port: the port the light is connected to
|
||||
"""
|
||||
self._port = port
|
||||
|
||||
def on(self, color: Union[Color, RGB, None]) -> None:
|
||||
"""Turns the light on with the specified color
|
||||
|
||||
Args:
|
||||
color: the color
|
||||
"""
|
||||
pass
|
||||
|
||||
def off(self) -> None:
|
||||
pass
|
||||
|
||||
def blink(self, color1: Union[Color, RGB, None],
|
||||
color2: Union[Color, RGB, None], pattern: Pattern) -> None:
|
||||
"""Blinks the light using the specified pattern
|
||||
|
||||
Args:
|
||||
color1: the first color in the pattern
|
||||
color2: the second color in the pattern
|
||||
pattern: the pattern
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
def has_red(self) -> bool:
|
||||
"""Checks if the light can be red
|
||||
|
||||
Returns:
|
||||
``True`` if the light can be red
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def has_green(self) -> bool:
|
||||
"""Checks if the light can be green
|
||||
|
||||
Returns:
|
||||
``True`` if the light can be green
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def has_blue(self) -> bool:
|
||||
"""Checks if the light can be blue
|
||||
|
||||
Returns:
|
||||
``True`` if the light can be blue
|
||||
"""
|
||||
return False
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
"""Sensors are input devices."""
|
||||
|
||||
from _pbport import Port
|
||||
|
||||
|
||||
class TouchSensor():
|
||||
"""Represents a touch sensor with two states, pressed and released"""
|
||||
def __init__(self, port: Port):
|
||||
"""Creates a new instance
|
||||
|
||||
Raises:
|
||||
ValueError: The *port* is not a valid port
|
||||
RuntimeError: There is not a touch sensor connected to this port
|
||||
"""
|
||||
self._port = port
|
||||
|
||||
@property
|
||||
def is_pressed(self) -> bool:
|
||||
"""Checks if the touch sensor is pressed.
|
||||
|
||||
Returns:
|
||||
``True`` if the sensor is pressed, otherwise ``False``
|
||||
"""
|
||||
return False
|
||||
@@ -0,0 +1,7 @@
|
||||
"""Constant parameters/arguments for the Pybricks API."""
|
||||
|
||||
|
||||
class Color():
|
||||
"""LED colors or detected surface colors."""
|
||||
|
||||
red = 5
|
||||
@@ -0,0 +1,33 @@
|
||||
"""pypi compatible setup module.
|
||||
|
||||
This setup is based on:
|
||||
https://packaging.python.org/tutorials/distributing-packages/
|
||||
|
||||
|
||||
"""
|
||||
from setuptools import setup
|
||||
from codecs import open
|
||||
from os import path
|
||||
|
||||
|
||||
here = path.abspath(path.dirname(__file__))
|
||||
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
|
||||
long_description = f.read()
|
||||
|
||||
setup(
|
||||
name='pybricks',
|
||||
version='0.1',
|
||||
description='Pybricks',
|
||||
long_description=long_description,
|
||||
url='https://github.com/pybricks',
|
||||
author='Laurens Valk and David Lechner',
|
||||
author_email='laurensvalk@gmail.com',
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Programming Language :: Python :: 3',
|
||||
],
|
||||
keywords='lego mindstorms ev3',
|
||||
python_requires='>=3',
|
||||
packages=['pybricks'],
|
||||
)
|
||||
Reference in New Issue
Block a user