Commit Graph
52 Commits
Author SHA1 Message Date
Laurens Valk b89da4b061 api/common/ColorLight: add blink and animate
These are the generalizations of the corresponding methods for single color lights.
2020-08-25 13:38:09 +02:00
Laurens Valk b974ead0dc api/common/ColorLight: drop hsv function
The on() method takes a color type, which is an HSV color, so a separate hsv method is not needed.

hub.light.on(Color.GREEN)
hub.light.on(Color(120))
hub.light.on(Color(h=120, s=100, 50))
2020-08-25 13:38:09 +02:00
Laurens Valk 0427436df6 doc/common/LightGrid: clarify how blink and pattern relate
blink is just a simpler animation
2020-08-25 13:38:09 +02:00
Laurens Valk 4319b2fad8 api/common/Light: add blink and animate 2020-08-25 13:38:09 +02:00
Laurens Valk 0fb150be19 api/common/LightGrid: add animate method 2020-08-25 13:37:54 +02:00
Laurens Valk 6d0984f5fc api/common/LightGrid: simplify image method
Now it just displays a Matrix/2D list. We can omit manipulations like clear=False. Composing can be done by simply adding two matrices instead.

We also drop the compressed format. Instead we could have a helper function that gives you a
matrix based on a list of integers in the now-deleted format.
2020-08-25 12:42:14 +02:00
Laurens Valk b708fe283c api/common/LightGrid: rename char argument
This follows a change in the unreleased implementation.
2020-08-25 12:42:14 +02:00
Laurens Valk 74d59b43ac api/common/LightGrid: revise text method
Specify on and off time for consistency with future blink method.

Adding some off time helps reading text with subsequent charachters that are the same. For example, now "Hello" reads H e l l o instead of Helo.

Also drop wait argument for now because it is not currently implemented and may never be.
2020-08-25 12:42:10 +02:00
Laurens Valk 55c4c86c23 api/_common: fix speaker file kwarg
In the implementation, the kwarg is called "file". Instead of fixing the implementation which is already released, we fix the docs.
2020-07-07 09:50:36 +02:00
Laurens Valk 8078b6febb doc/_common/ColorLight: docstring clean up
This adds a (commented out) preview of the methods to the city hub light
2020-07-07 09:44:16 +02:00
Laurens Valk 8a43dc936a doc/signaltypes: add hue placeholder
We will have to add a helpful diagram, but having the placeholder allows us to link to it already.
2020-07-07 09:44:16 +02:00
Laurens Valk 7d1fbe9ce9 api/_common/Light: add reset to system behavior
This makes lights behave as they would if the user script did not use them at all.
2020-07-07 09:44:16 +02:00
Laurens Valk 38a1cf9712 api/_common/Light: drop repeat kwarg
The pattern will always repeat, for simplicity.
2020-07-07 09:44:16 +02:00
Laurens Valk 102039385a api/_common/ColorLight: add pattern
This adds the method equivalent to the recent addition of a single
color light. The only difference is that now a color is returned instead
of a single brightness. The provided color or HSV tuple will be stored
as RGB samples internally, as is already done for pbio light patterns.

In the simplest blinking form this could be:

hub.light.pattern(lambda t: Color.RED if t >= 1000 else None, 2000)

Or a fading, one-color sine:

def fade(time):
    v = sin(time/2000/pi)*50+50
    h = 360
    s = 100
    return (h, s, v)

hub.light.pattern(fade, 1000)
2020-07-07 09:44:16 +02:00
Laurens Valk e780a65007 api/_common/ColorLight: change rgb to hsv
This makes it much easier to have fine grained control
over colors and cycle through them easily (0--360).

This also makes it consistent with sensor APIs. Now you
can measure the color and plug it into this method.

We can make this change because none of
the implementations use this yet.

If we feel we miss out by dropping the RGB, it would be more fitting
to instead expose R, G, and B attributes which point to instances of
the Light class. However, this is using more memory for something that
isn't very useful.

We could also just provide generic color converters between rgb, hsv,
and perhaps hex html color strings, not tied to any particular light or
sensor.
2020-07-07 09:44:16 +02:00
Laurens Valk b8505ff218 api/_common/Light: introduce pattern
Currently, Pybricks has system patterns for builtin lights.
This adds a user method to set such a pattern.

For example, an indefinite sine pattern could be specified by

def fade(time):
    return sin(time/2000/pi)*50+50

hub.light.pattern(fade, 1000)

or a blinking pattern using

def blink(time):
    if time >= 1000:
        return 100
    else:
        return 0

hub.light.pattern(blink, 2000)

or briefly:

hub.light.pattern(lambda t: 100 if t >= 1000 else 0, 2000)

This combines the best of simplicity and efficiency: The user doesn't
have to calculate and provide an expensive list of floating points, but
provide a clean and adaptable method instead.
By sampling, we maintain a fixed length pattern which we can preallocate
for the hub lights, and the samples are calculated only once and the
callable may be garbage collected if given as lambda. Also, any
exceptions will be caught immediately during the one-off evaluation.
2020-07-07 09:44:16 +02:00
Laurens Valk 20fec6461a api/_common/LightGrid: make image more efficient
Usually, images are static, so they can be computed in advance instead of during runtime. This makes scripts smaller and much more memory efficient.

For example, now you can say:

HOUSE = 4685823

hub.grid.image(HOUSE)

since 4685823 =
```
0 0 1 0 0
0 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
```

We could also choose the binary format to allow for more generic screen sizes. If we allow a bit more space (2 words instead of 1), we could do 1 byte per row to allow screens up to 8x8. Right now, though, we choose 1 word < 31 bits which is a bit more efficient in MicroPython.

We can easily list numerous example in the docs or provide a simple visual calculator.

There is still a matrix method that takes a 2D matrix of intensities for full control during runtime, which is what the image() method was doing initially. This commit renames the old draft to matrix().
2020-07-07 09:44:16 +02:00
Laurens Valk 80840396aa api/pupdevices: add Powered Up Light 2020-06-08 15:26:19 +02:00
Laurens Valk 7498751ee3 doc/pupdevices: add diagrams with light indices
Make this clear once and for all.
This order comes from the sensor itself.
2020-05-27 13:58:30 +02:00
Laurens Valk 2d3e85f531 api/_common.LightArray: merge on and array method
Make it simpler with only one method to turn the lights on.
2020-05-27 13:58:30 +02:00
Laurens Valk 4de436e479 doc/motors: hide extra sections until ready
Avoid references to non-existing explanations.
2020-04-24 12:00:26 +02:00
David Lechner 87c2b6857f api: Use leading _ to hide internals in intellisense
Intellisense in VS Code (both jedi and ms python language server) picks
up all imported names and suggests them with equal priority for
code completion. By adding a leading underscore, intellisense lists
these with a lower priority, so they don't get in the way.

Also rename from builtins to _common while we are touching this to
better reflect the intention of the module (it contains types shared
by multiple modules, not builtin types like int).
2020-03-25 20:24:32 +01:00
Laurens Valk 529f8fe31c api: rename _common to builtins
Because this module describes devices that can be built into a hub or other device.

Since this design is now explicitly shown in
the docs as well, we don't need to hide this
module in the package.
2019-10-18 16:05:23 +02:00
Laurens Valk f5762447b4 doc: take sphinx workarounds out of api 2019-10-18 15:11:20 +02:00
Laurens Valk 5812333119 api: EV3Brick as class instead of module 2019-10-18 14:47:48 +02:00
Laurens Valk b5c9e3feb7 api: add simpler method for tilt
Provides a way of basic orientation checking independently of reference frame settings.
2019-07-04 11:55:01 +02:00
Laurens Valk d198c45845 api: add heading for devices with a gyro 2019-07-02 14:07:36 +02:00
Laurens Valk aa10118cfe api: add gestures 2019-07-02 13:49:52 +02:00
Laurens Valk e722451af1 api: add Axis.ALL identifier 2019-07-02 13:08:20 +02:00
Laurens Valk 240d21bcca api: split frame configuration into method
Because the __init__ for built-in IMUs won't be called
by the user.
2019-07-02 12:59:21 +02:00
Laurens Valk d48bbc3b80 api: tilt 2019-07-02 12:28:11 +02:00
Laurens Valk c722490b81 api: specify axes during setup 2019-07-02 12:13:05 +02:00
Laurens Valk e453cecb2e api: accelerometer drafts 2019-07-02 11:57:00 +02:00
Laurens Valk 20b4307d05 api: standardize on method for light groups
Turn on all the lights at the specified brightness.
2019-06-25 14:55:38 +02:00
Laurens Valk 0b67db897e api: generalize buttons
This makes the user code easier to read:

brick.buttons()

brick.buttons.pressed()

It also opens up possibility to add features in the future such as:
brick.buttons.released()  # return which buttons are not pressed
brick.buttons.clicked()  # return which buttons were clicked since we last checked

This follows the same style as the new light API: some devices have specific instances of a KeyPad class.

A good example that nicely demonstrates the concept is the LPF2 RemoteControl, which has instances of a ColorLight and a KeyPad. It's added in this commit.
2019-06-11 21:30:46 +02:00
Laurens Valk 12834ffc73 api: fix relative links due to package 2019-06-11 20:13:38 +02:00
Laurens Valk f6eb7674a9 conf: drop references to future work 2019-06-11 20:05:40 +02:00
Laurens Valk a0a77896d7 api: add text and number display to grid
Also, use row + column for setting pixels instead of x, y. Then it is the same indexing as matrices.
2019-06-11 16:38:17 +02:00
Laurens Valk 1970ef273d api: percentage as brightness 2019-06-08 12:12:49 +02:00
Laurens Valk b92eb447b4 doc: add extra units 2019-06-08 11:57:12 +02:00
Laurens Valk bc6fce6406 api: add light initializers 2019-06-07 16:29:38 +02:00
Laurens Valk bf16da463a api: update common light classes 2019-06-07 13:50:32 +02:00
Laurens Valk 8bc96822b2 api: add lights instance 2019-06-06 11:03:11 +02:00
Laurens Valk 8d4f6294d7 api: add LightArray 2019-06-05 16:03:05 +02:00
Laurens Valk 0013a74d72 drop class method identifier from docs
Same result as in 92e3735d63, but now achieved by patching the Sphinx configuration instead of patching the API.

Now it doesn't break the API for the purpose of checking and autocomplete, etc.
2019-06-05 13:57:04 +02:00
Laurens Valk 28a5329bb6 api/doc: pybricks is a package 2019-06-05 12:47:24 +02:00
Laurens Valk 727507d66d API: add light instance to ColorDistanceSensor
This is an experimental method for adding lights to some sensors.

And add workaround to make it show up correctly in the docs.

Also some doc8 formatting
2019-06-05 11:49:46 +02:00
Laurens Valk 8d37450fac api: flake8 2019-06-04 15:45:36 +02:00
Laurens Valk 92e3735d63 drop class method identifier from docs
For example, this changes

classmethod sound.beeps(number)
   Description

into

sound.beeps(number)
   Description
2019-06-03 15:22:57 +02:00
Laurens Valk f3c29971de api: lights on hubs are instances of generic class 2019-06-03 15:18:26 +02:00