From cabda63108dcb9813bbdeb670434ad3e87eb168e Mon Sep 17 00:00:00 2001 From: Sam El-Husseini <16690124+samelhusseini@users.noreply.github.com> Date: Thu, 31 May 2018 10:04:51 -0700 Subject: [PATCH] Move showNumber to TS and call showString (#829) --- libs/core/basic.cpp | 20 -------------------- libs/core/basic.ts | 15 +++++++++++++++ libs/core/pxt.json | 1 + libs/core/shims.d.ts | 11 ----------- 4 files changed, 16 insertions(+), 31 deletions(-) create mode 100644 libs/core/basic.ts diff --git a/libs/core/basic.cpp b/libs/core/basic.cpp index 0fae3c66..bad09dba 100644 --- a/libs/core/basic.cpp +++ b/libs/core/basic.cpp @@ -7,26 +7,6 @@ //% color=#0078D7 weight=100 icon="\uf00a" namespace basic { - /** - * Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll. - * @param interval speed of scroll; eg: 150, 100, 200, -100 - */ - //% help=basic/show-number - //% weight=96 - //% blockId=device_show_number block="show|number %number" blockGap=8 - //% async - //% parts="ledmatrix" - void showNumber(int value, int interval = 150) { - if (interval <= 0) - interval = 1; - ManagedString t(value); - if (value < 0 || value >= 10) { - uBit.display.scroll(t, interval); - } else { - uBit.display.printChar(t.charAt(0), interval * 5); - } - } - /** * Draws an image on the LED screen. * @param leds the pattern of LED to turn on/off diff --git a/libs/core/basic.ts b/libs/core/basic.ts new file mode 100644 index 00000000..379c686f --- /dev/null +++ b/libs/core/basic.ts @@ -0,0 +1,15 @@ +namespace basic { + + /** + * Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll. + * @param interval speed of scroll; eg: 150, 100, 200, -100 + */ + //% help=basic/show-number + //% weight=96 + //% blockId=device_show_number block="show|number %number" blockGap=8 + //% async + //% parts="ledmatrix" interval.defl=150 + export function showNumber(value: number, interval?: number) { + showString(value.toString(), interval); + } +} \ No newline at end of file diff --git a/libs/core/pxt.json b/libs/core/pxt.json index c6ef8634..e9970043 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -18,6 +18,7 @@ "codal.cpp", "images.cpp", "basic.cpp", + "basic.ts", "icons.ts", "icons.jres", "input.cpp", diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 1d7c1ed6..aced09b7 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -130,17 +130,6 @@ declare interface Image { //% color=#0078D7 weight=100 icon="\uf00a" declare namespace basic { - /** - * Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll. - * @param interval speed of scroll; eg: 150, 100, 200, -100 - */ - //% help=basic/show-number - //% weight=96 - //% blockId=device_show_number block="show|number %number" blockGap=8 - //% async - //% parts="ledmatrix" interval.defl=150 shim=basic::showNumber - function showNumber(value: int32, interval?: int32): void; - /** * Draws an image on the LED screen. * @param leds the pattern of LED to turn on/off