mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
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
This commit is contained in:
parent
a676970359
commit
fa0af58c41
1 changed files with 7 additions and 2 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue