lancaster-university / microbit-dal

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

Get the busy status for the display #360

Open scabot opened 6 years ago

scabot commented 6 years ago

Hello

I think it is valuable to be able to tell when the display is busy, especially when working without the scheduler and the entire MicroBit env, so we can busy wait for it.

I added a small method to MicroBitDisplay to that.

What is the best practice to suggest this change:

In MicrobitDisplay.h

bool isBusy();

In MicroBitDisplay.cpp

bool MicroBitDisplay::isBusy()
{
    return (animationMode != ANIMATION_MODE_NONE && animationMode != ANIMATION_MODE_STOPPED);
}

I use it like this:

void show_message()
{
    ++strIndex;
    ManagedString message(read_str_data());

    while(display.isBusy())
        __WFE();

    display.scrollAsync(message);
}

int main()
{
    serial.baud(MICROBIT_SERIAL_DEFAULT_BAUD_RATE);
    serial.format();
    serial.attach(ignore_data);
    serial.puts(clear.toCharArray());
    while(1) {
        StringData *strData = write_str_data();
        memset(strData, 0, BUFFER_LENGTH);
        strData->init();
        serial.attach(have_data);
        serial.puts(greeting.toCharArray());
        readDone = READ_IN_PROGRESS;
        while(!readDone) {
            __WFE();
        }
        serial.attach(ignore_data);
        switch(readDone)
        {
            case READ_DONE_NORMAL:
                show_message();
                break;
            case READ_DONE_SIZE_ERROR:
                serial.puts("\033[1;35m\r\nMessage too long\r\n");
                break;
            case READ_DONE_RESET:
                break;
        }
    }
}
pelikhan commented 5 years ago

@finneyj is there an event we can wait on to acheive the same result?