Skip to content

Commit 2befceb

Browse files
markshannonntoll
authored andcommitted
Remove display.animate() and update docs.
1 parent c2b9914 commit 2befceb

File tree

10 files changed

+11
-159
lines changed

10 files changed

+11
-159
lines changed

docs/display.rst

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ Functions
2525
2626
Set the brightness of all LEDs to 0.
2727

28-
29-
.. py:function:: show(string, delay=400)
30-
31-
Display the ``string`` one letter at a time, with ``delay`` milliseconds
32-
between each pair of letters.
33-
34-
3528
.. py:function:: show(image)
3629
3730
Display the ``image``.
@@ -43,25 +36,14 @@ Functions
4336
``delay`` parameter controls how fast the text is scrolling. This function
4437
blocks until it is finished.
4538

39+
.. py:function:: show(iterable, delay, wait=True, loop=False, clear=False)
4640
47-
.. py:function:: animate(image, delay, stride, start, wait=True, loop=False)
48-
49-
Display the ``image`` starting with its ``start`` column, and scroll
50-
it every ``delay`` milliseconds to the right by ``stride`` columns, until
51-
the last column of the image is displayed.
52-
53-
If ``wait`` is ``True``, this function will block until the animation is
54-
finished, otherwise the animation will happen in the background.
55-
56-
If ``loop`` is ``True``, the animation will repeat forever.
57-
58-
59-
.. py:function:: animate(iterable, delay, wait=True, loop=False)
60-
61-
Display images from the ``iterable`` in sequence, with ``delay``
41+
Display images or letters from the ``iterable`` in sequence, with ``delay``
6242
milliseconds between them.
6343

6444
If ``wait`` is ``True``, this function will block until the animation is
6545
finished, otherwise the animation will happen in the background.
6646

6747
If ``loop`` is ``True``, the animation will repeat forever.
48+
49+
If ``clear`` is ``True``, the display will be cleared after the iterable has finished.

docs/microbit_micropython_api.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ The LED display is exposed via the `display` object::
4141
display.get_pixel(x, y) # gets the brightness of the pixel (x,y)
4242
display.set_pixel(x, y, val) # sets the brightness of the pixel (x,y) to val (between 0 and 9, inclusive)
4343
display.clear() # clears the display
44-
display.show(string, delay=400) # prints the string to the display one character at a time
45-
display.show(image, delay=400) # shows the image on the screen.
46-
display.scroll(string, delay=400) # scrolls a string across the display (more exciting than display.print)
47-
display.animate(image, delay, stride, start, wait=True, loop=False)
48-
display.animate(iterable, delay, wait=True, loop=False)
44+
display.show(image, delay=0, wait=True, loop=False, clear=False) # shows the image
45+
display.show(iterable, delay=400, wait=True, loop=False, clear=False) # shows each image or letter in the iterable, with delay ms. in between each.
46+
display.scroll(string, delay=400) # scrolls a string across the display (more exciting than display.show)
4947

5048
Pins
5149
----

inc/genhdr/qstrdefs.generated.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ QDEF(MP_QSTR_delay, (const byte*)"\x50\x05" "delay")
408408
QDEF(MP_QSTR_stride, (const byte*)"\xb8\x06" "stride")
409409
QDEF(MP_QSTR_wait, (const byte*)"\x8e\x04" "wait")
410410
QDEF(MP_QSTR_loop, (const byte*)"\x39\x04" "loop")
411-
QDEF(MP_QSTR_animate, (const byte*)"\x3e\x07" "animate")
412411
QDEF(MP_QSTR_crop, (const byte*)"\x0b\x04" "crop")
413412
QDEF(MP_QSTR_text, (const byte*)"\x98\x04" "text")
414413
QDEF(MP_QSTR_SlicedImage, (const byte*)"\xf6\x0b" "SlicedImage")
File renamed without changes.

inc/microbit/modmicrobit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ MP_DECLARE_CONST_FUN_OBJ(microbit_compass_get_z_obj);
175175
MP_DECLARE_CONST_FUN_OBJ(microbit_display_show_obj);
176176
MP_DECLARE_CONST_FUN_OBJ(microbit_display_scroll_obj);
177177
MP_DECLARE_CONST_FUN_OBJ(microbit_display_clear_obj);
178-
MP_DECLARE_CONST_FUN_OBJ(microbit_display_animate_obj);
179178
MP_DECLARE_CONST_FUN_OBJ(microbit_display_get_pixel_obj);
180179
MP_DECLARE_CONST_FUN_OBJ(microbit_display_set_pixel_obj);
181180
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_read_digital_obj);

inc/microbit/qstrdefsport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ Q(stride)
142142
Q(start)
143143
Q(wait)
144144
Q(loop)
145-
Q(animate)
146145
Q(copy)
147146
Q(crop)
148147
Q(slice)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
#include "py/runtime.h"
28-
#include "lib/utils/iters.h"
28+
#include "lib/iters.h"
2929

3030
typedef struct _repeat_iterator_t {
3131
mp_obj_base_t base;
@@ -40,7 +40,7 @@ STATIC mp_obj_t microbit_repeat_iter_next(mp_obj_t iter_in) {
4040
iter->iterator = mp_getiter(iter->iterable);
4141
result = mp_iternext(iter->iterator);
4242
if (result == MP_OBJ_STOP_ITERATION) {
43-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot repeat empty sequence."));
43+
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "cannot repeat empty sequence"));
4444
}
4545
}
4646
return result;

source/microbit/help.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ STATIC const mp_doc_t help_table_instances[] = {
100100
{&microbit_compass_get_z_obj, "Return magnetic field detected along micro:bit's Z axis.\nUsually, the compass returns the earth's magnetic field in micro-Tesla units.\nUnless...a strong magnet is nearby!\n"},
101101
// Display 5x5 LED grid
102102
{&microbit_display_obj, "micro:bit's 5x5 LED display.\n"},
103-
{&microbit_display_show_obj, "Use show(x) to print the string or image 'x' to the display. Try show('Hi!').\nUse show(s, i) to show string 's', one character at a time with a delay of\n'i' milliseconds.\n"},
103+
{&microbit_display_show_obj, "Use show(x) to print the string or images 'x' to the display. Try show('Hi!').\nUse show(s, i) to show string 's', one character at a time with a delay of\n'i' milliseconds.\n"},
104104
{&microbit_display_scroll_obj, "Use scroll(s) to scroll the string 's' across the display.\nUse scroll(s, i) to scroll string 's' with a delay of 'i' milliseconds after\neach character.\n"},
105105
{&microbit_display_clear_obj, "Use clear() to clear micro:bit's display.\n"},
106-
{&microbit_display_animate_obj, "Use animate(img, delay, stride, start=0, async=False, repeat=False) to animate\nimage 'img' with 'delay' milliseconds and 'stride' pixels offset between\nframes. Optional: 'start' offset from left hand side, 'async' to run in the\nbackground, 'repeat' to loop the animation.\n"},
107106
{&microbit_display_get_pixel_obj, "Use get_pixel(x, y) to return the display's brightness at LED pixel (x,y).\nBrightness can be from 0 (LED is off) to 9 (maximum LED brightness).\n"},
108107
{&microbit_display_set_pixel_obj, "Use set_pixel(x, y, b) to set the display at LED pixel (x,y) to brightness 'b'\nwhich can be set between 0 (off) to 9 (full brightness).\n"},
109108
// Pins

source/microbit/microbitdisplay.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C" {
3434
#include "modmicrobit.h"
3535
#include "microbitimage.h"
3636
#include "microbitdisplay.h"
37-
#include "lib/utils/iters.h"
37+
#include "lib/iters.h"
3838

3939
void microbit_display_show(microbit_display_obj_t *display, microbit_image_obj_t *image) {
4040
mp_int_t w = min(image->width(), 5);
@@ -334,39 +334,6 @@ void microbit_display_animate(microbit_display_obj_t *self, mp_obj_t iterable, m
334334
}
335335
}
336336

337-
STATIC mp_obj_t microbit_display_animate_func(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
338-
static const mp_arg_t animate_allowed_args[] = {
339-
{ MP_QSTR_image, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
340-
{ MP_QSTR_delay, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
341-
{ MP_QSTR_stride, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5} },
342-
{ MP_QSTR_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -5} },
343-
{ MP_QSTR_wait, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
344-
{ MP_QSTR_loop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
345-
};
346-
347-
// Parse the args.
348-
microbit_display_obj_t *self = (microbit_display_obj_t*)pos_args[0];
349-
mp_arg_val_t args[MP_ARRAY_SIZE(animate_allowed_args)];
350-
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(animate_allowed_args), animate_allowed_args, args);
351-
352-
mp_obj_t arg0 = args[0].u_obj;
353-
mp_int_t stride = args[2].u_int;
354-
mp_int_t start = args[3].u_int;
355-
mp_obj_t iterable;
356-
if (mp_obj_get_type(arg0) == &microbit_image_type) {
357-
// Convert single image into an iterable of images.
358-
iterable = microbit_image_slice((microbit_image_obj_t *)arg0, start, 5 /*width*/, stride);
359-
} else {
360-
iterable = arg0;
361-
}
362-
if (args[5].u_bool) { /* loop */
363-
iterable = microbit_repeat_iterator(iterable);
364-
}
365-
microbit_display_animate(self, iterable, args[1].u_int /*delay*/, true/*clear*/, args[4].u_bool /*wait?*/);
366-
return mp_const_none;
367-
}
368-
MP_DEFINE_CONST_FUN_OBJ_KW(microbit_display_animate_obj, 2, microbit_display_animate_func);
369-
370337
void microbit_display_scroll(microbit_display_obj_t *self, const char* str) {
371338
mp_obj_t iterable = scrolling_string_image_iterable(str, strlen(str), NULL, false);
372339
microbit_display_animate(self, iterable, MICROBIT_DEFAULT_SCROLL_SPEED, false, false);
@@ -448,7 +415,6 @@ STATIC const mp_map_elem_t microbit_display_locals_dict_table[] = {
448415
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_pixel), (mp_obj_t)&microbit_display_set_pixel_obj },
449416
{ MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)&microbit_display_show_obj },
450417
{ MP_OBJ_NEW_QSTR(MP_QSTR_scroll), (mp_obj_t)&microbit_display_scroll_obj },
451-
{ MP_OBJ_NEW_QSTR(MP_QSTR_animate), (mp_obj_t)&microbit_display_animate_obj },
452418
{ MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&microbit_display_clear_obj },
453419
};
454420

source/microbit/microbitimage.cpp

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -625,96 +625,6 @@ const mp_obj_type_t microbit_image_type = {
625625
.bases_tuple = MP_OBJ_NULL,
626626
/* .locals_dict = */ (mp_obj_t)&microbit_image_locals_dict,
627627
};
628-
629-
630-
/* Image slices */
631-
632-
typedef struct _image_slice_t {
633-
mp_obj_base_t base;
634-
microbit_image_obj_t *img;
635-
mp_int_t start;
636-
mp_int_t width;
637-
mp_int_t stride;
638-
} image_slice_t;
639-
640-
typedef struct _image_slice_iterator_t {
641-
mp_obj_base_t base;
642-
image_slice_t *slice;
643-
mp_int_t next_start;
644-
} image_slice_iterator_t;
645-
646-
extern const mp_obj_type_t microbit_sliced_image_type;
647-
extern const mp_obj_type_t microbit_sliced_image_iterator_type;
648-
649-
mp_obj_t microbit_image_slice(microbit_image_obj_t *img, mp_int_t start, mp_int_t width, mp_int_t stride) {
650-
image_slice_t *result = m_new_obj(image_slice_t);
651-
result->base.type = &microbit_sliced_image_type;
652-
result->img = img;
653-
result->start = start;
654-
result->width = width;
655-
result->stride = stride;
656-
return result;
657-
}
658-
659-
STATIC mp_obj_t get_microbit_image_slice_iter(mp_obj_t o_in) {
660-
image_slice_t *slice = (image_slice_t *)o_in;
661-
image_slice_iterator_t *result = m_new_obj(image_slice_iterator_t);
662-
result->base.type = &microbit_sliced_image_iterator_type;
663-
result->slice = slice;
664-
result->next_start = slice->start;
665-
return result;
666-
}
667-
668-
STATIC mp_obj_t microbit_image_slice_iter_next(mp_obj_t o_in) {
669-
image_slice_iterator_t *iter = (image_slice_iterator_t *)o_in;
670-
mp_obj_t result;
671-
microbit_image_obj_t *img = iter->slice->img;
672-
if (iter->slice->stride > 0 && iter->next_start >= img->width()) {
673-
return MP_OBJ_STOP_ITERATION;
674-
}
675-
if (iter->slice->stride < 0 && iter->next_start <= -iter->slice->width) {
676-
return MP_OBJ_STOP_ITERATION;
677-
}
678-
result = image_crop(img, iter->next_start, 0, iter->slice->width, img->height());
679-
iter->next_start += iter->slice->stride;
680-
return result;
681-
}
682-
683-
const mp_obj_type_t microbit_sliced_image_type = {
684-
{ &mp_type_type },
685-
.name = MP_QSTR_SlicedImage,
686-
.print = NULL,
687-
.make_new = NULL,
688-
.call = NULL,
689-
.unary_op = NULL,
690-
.binary_op = NULL,
691-
.attr = NULL,
692-
.subscr = NULL,
693-
.getiter = get_microbit_image_slice_iter,
694-
.iternext = NULL,
695-
.buffer_p = {NULL},
696-
.stream_p = NULL,
697-
.bases_tuple = MP_OBJ_NULL,
698-
MP_OBJ_NULL
699-
};
700-
701-
const mp_obj_type_t microbit_sliced_image_iterator_type = {
702-
{ &mp_type_type },
703-
.name = MP_QSTR_iterator,
704-
.print = NULL,
705-
.make_new = NULL,
706-
.call = NULL,
707-
.unary_op = NULL,
708-
.binary_op = NULL,
709-
.attr = NULL,
710-
.subscr = NULL,
711-
.getiter = mp_identity,
712-
.iternext = microbit_image_slice_iter_next,
713-
.buffer_p = {NULL},
714-
.stream_p = NULL,
715-
.bases_tuple = MP_OBJ_NULL,
716-
MP_OBJ_NULL
717-
};
718628

719629
typedef struct _scrolling_string_t {
720630
mp_obj_base_t base;

0 commit comments

Comments
 (0)