From fa0af58c416fb89fec0a3dd499dbcec844ca4757 Mon Sep 17 00:00:00 2001 From: Kreg Hanning Date: Tue, 25 Sep 2018 14:56:29 -0400 Subject: [PATCH] Make "display [Hello!] block yield until printing is done (#1599) * Make "display [Hello!] block yield until printing is done * Add 2 additional px to yield delay * Add 3 more additional px for large chars --- src/extensions/scratch3_microbit/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/extensions/scratch3_microbit/index.js b/src/extensions/scratch3_microbit/index.js index d32f2792a..0f9723179 100644 --- a/src/extensions/scratch3_microbit/index.js +++ b/src/extensions/scratch3_microbit/index.js @@ -813,17 +813,22 @@ class Scratch3MicroBitBlocks { /** * Display text on the 5x5 LED matrix. * @param {object} args - the block's arguments. - * @return {Promise} - a Promise that resolves after a tick. + * @return {Promise} - a Promise that resolves after the text is done printing. * Note the limit is 19 characters + * The print time is calculated by multiplying the number of horizontal pixels + * by the default scroll delay of 120ms. + * The number of horizontal pixels = 6px for each character in the string, + * 1px before the string, and 5px after the string. */ displayText (args) { const text = String(args.TEXT).substring(0, 19); if (text.length > 0) this._peripheral.displayText(text); + const yieldDelay = 120 * ((6 * text.length) + 6); return new Promise(resolve => { setTimeout(() => { resolve(); - }, BLESendInterval); + }, yieldDelay); }); }