diff --git a/libs/microbit/helpers.ts b/libs/microbit/helpers.ts new file mode 100644 index 00000000..1e6bad4a --- /dev/null +++ b/libs/microbit/helpers.ts @@ -0,0 +1,6 @@ +namespace console { + export function log(msg: string) { + serial.writeString(msg); + serial.writeString("\r\n"); + } +} diff --git a/libs/microbit/kind.json b/libs/microbit/kind.json index b675ddda..5d0fbf1d 100644 --- a/libs/microbit/kind.json +++ b/libs/microbit/kind.json @@ -7,10 +7,11 @@ "dal.d.ts", "enums.d.ts", "shims.d.ts", - "core.d.ts", + "ks-core.d.ts", "ksbit.h", "core.cpp", - "mbit.ts", + "ks-helpers.ts", + "helpers.ts", "images.cpp", "basic.cpp", "input.cpp", diff --git a/libs/microbit/mbit.ts b/libs/microbit/mbit.ts deleted file mode 100644 index c21980e5..00000000 --- a/libs/microbit/mbit.ts +++ /dev/null @@ -1,64 +0,0 @@ -type Action = () => void; - -namespace helpers { - export function arraySplice(arr: T[], start: number, len: number) { - if (start < 0) { - return; - } - for (let i = 0; i < len; ++i) { - arr.removeAt(start) - } - } -} - -namespace console { - export function log(msg: string) { - serial.writeString(msg); - serial.writeString("\r\n"); - } -} - -namespace Math { - export function clamp(min: number, max:number, value:number): number { - return Math.min(max, Math.max(min, value)); - } - - /** - * Returns the absolute value of a number (the value without regard to whether it is positive or negative). - * For example, the absolute value of -5 is the same as the absolute value of 5. - * @param x A numeric expression for which the absolute value is needed. - */ - export function abs(x: number): number - { - return x < 0 ? -x : x; - } - - /** - * Returns the sign of the x, indicating whether x is positive, negative or zero. - * @param x The numeric expression to test - */ - export function sign(x: number): number - { - if (x == 0) return 0; - if (x > 0) return 1; - return -1; - } - - /** - * Returns the larger of two supplied numeric expressions. - */ - export function max(a:number, b:number): number - { - if (a >= b) return a; - return b; - } - - /** - * Returns the smaller of two supplied numeric expressions. - */ - export function min(a:number, b:number): number - { - if (a <= b) return a; - return b; - } -}