lancaster-university / microbit-dal

http://lancaster-university.github.io/microbit-docs
Other
254 stars 130 forks source link

Animate function does not work with negative stride #351

Open microbit-mark opened 6 years ago

microbit-mark commented 6 years ago

When stride argument for the animatemethod has a neagtive value the micro:bit does nothing. We would expect it to animate in the opposite direction. eg

#include "MicroBit.h"

MicroBit uBit;

int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();

    // Setup a simple triangular waveform.
    MicroBitImage img("1 0 0 0 0 0 0 0 0 1\n0 1 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 0 1 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n");

     uBit.display.animate(img, 200, -1);
}
carlosperate commented 6 years ago

Just to clarify @microbit-mark, when this code is run on a micro:bit nothing is displayed in the LED matrix, is that correct?

microbit-mark commented 6 years ago

Yep. nothing is displayed on the micro:bit. Using uBit.display.animate(img, 200, 1); works

finneyj commented 6 years ago

Thanks @microbit-mark and @carlosperate

Based on a quick scan of the code, it looks like you currently need to specify an explicit starting position if you want negative scrolling: https://github.com/lancaster-university/microbit-dal/blob/master/source/drivers/MicroBitDisplay.cpp#L934

Can you try your code again with the optional fourth parameter set, as indicated here: https://lancaster-university.github.io/microbit-docs/ubit/display/#int-animate-microbitimage-image-int-delay-int-stride-int-startingposition

I guess it will be roughly -the_width_of_your_image ...

microbit-mark commented 6 years ago

I've tried variations on uBit.display.animate(img, 200, -1,-10) but can't get a working example of negative scrolling animation using the waveform sample.

microbit-mark commented 6 years ago

@finneyj anything else I can try?

microbit-pauline commented 5 years ago

Assigning to @microbit-sam as a BAU DAL activity

microbit-mark commented 5 years ago

Had another request in support for this, so polling the issue.

microbit-mark commented 5 years ago

micro:bit support: 20935 Another support request for this issue

martinwork commented 5 years ago

I think I have fixed this. I'll make a PR.

microbit-mark commented 4 years ago

micro:bit support: 38373 Another support request re this issue Are we able to merge the fix?

microbit-mark commented 3 years ago

Raised again in microbit support: 42107

microbit-mark commented 3 years ago

Raised in microbit support: 44708 Also reproduces on V2. @martinwork does your PR https://github.com/lancaster-university/microbit-dal/pull/427 still apply for both board variants? This would be a good one to progress as it crops up every so often.

martinwork commented 3 years ago

@microbit-mark V2 and V1 look the same with negative stride, using the test below, so hopefully the changes needed in CODAL would be similar. Would you like a PR like this for the DAL js-event-semantics branch and one for CODAL?

#include "MicroBit.h"

MicroBit uBit;

MicroBitImage img("255 0 0 0 0 0 0 0 0 255\n"
                  "0 255 0 0 0 0 0 0 255 0\n"
                  "0 0 255 0 0 0 0 255 0 0\n"
                  "0 0 0 255 0 0 255 0 0 0\n"
                  "0 0 0 0 255 255 0 0 0 0\n");

void onButtonA(MicroBitEvent e)
{
    int stride = -1;
    uBit.display.stopAnimation();
    uBit.display.clear();
    uBit.display.animate(img, 1000, stride, 2, 0);
}

void onButtonB(MicroBitEvent e)
{
    int stride = 1;
    uBit.display.stopAnimation();
    uBit.display.clear();
    uBit.display.animate(img, 1000, stride, 2, 0);
}

int  main()
{
    uBit.init();

    uBit.messageBus.listen( MICROBIT_ID_BUTTON_A,  MICROBIT_BUTTON_EVT_CLICK, onButtonA);
    uBit.messageBus.listen( MICROBIT_ID_BUTTON_B,  MICROBIT_BUTTON_EVT_CLICK, onButtonB);

    release_fiber();
}
microbit-mark commented 3 years ago

Raised again in micro:bit support: 46440

@martinwork

Would you like a PR like this for the DAL js-event-semantics branch and one for CODAL?

It would be great to fix this for all board variants . I'll leave the prioritisation with you and @finneyj as to where and when.

martinwork commented 2 years ago

DAL js-event-semantics branch: https://github.com/lancaster-university/microbit-dal/pull/485 CODAL: https://github.com/lancaster-university/codal-core/pull/145