Skip to content

Should the display be cleared when trying to print an invalid character? #424

Open
@microbit-carlos

Description

@microbit-carlos

For example uBit.display.print("Hi O갎o") displays the O character 4 times in a row ( is 0xEA 0xB0 0x8E in UTF-8, which I can confirm is what I see compiled in the code). It does not blink, it's just permanently shown for 4x the animation time.

This is because when a character is "printed" on the display, it uses the image buffer in the display instance to render the character using Image::print(), which exits early if the character is out-of-range and doesn't change the image:
codal-core/source/types/Image.cpp#L578

So, when printing "Hi O갎o", it shows O for 4 iterations.

The change would be simple, in AnimatedDisplay::updatePrintText() we could check the return value from Image::print() and clear the display if the return is DEVICE_INVALID_PARAMETER:
codal-core/source/drivers/AnimatedDisplay.cpp#L182

This would align a bit more with what uBit.display.scroll() currently does, but it would be considered a change in behaviour (V1 and V2 do the same now), so maybe we might not want to change this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions