diff --git a/libs/microbit/enums.d.ts b/libs/microbit/enums.d.ts index 5a031011..9737d884 100644 --- a/libs/microbit/enums.d.ts +++ b/libs/microbit/enums.d.ts @@ -268,5 +268,7 @@ declare namespace led { } declare namespace pins { } +declare namespace serial { +} // Auto-generated. Do not edit. Really. diff --git a/libs/microbit/kind.json b/libs/microbit/kind.json index f11f2f55..d2e363e3 100644 --- a/libs/microbit/kind.json +++ b/libs/microbit/kind.json @@ -21,6 +21,7 @@ "led.ts", "music.ts", "pins.cpp", + "serial.cpp", "serial.ts" ], "public": true, diff --git a/libs/microbit/music.ts b/libs/microbit/music.ts index 1fbca2e1..ca9d2a8f 100644 --- a/libs/microbit/music.ts +++ b/libs/microbit/music.ts @@ -116,7 +116,7 @@ namespace music { * Gets the frequency of a note. * @param name TODO */ - //% shim=TD_ID weight=50 help=music/note-frequency + //% weight=50 help=music/note-frequency //% blockId=device_note block="%note" export function noteFrequency(name: Note): number { return name; diff --git a/libs/microbit/serial.cpp b/libs/microbit/serial.cpp new file mode 100644 index 00000000..27738cd3 --- /dev/null +++ b/libs/microbit/serial.cpp @@ -0,0 +1,38 @@ +#include "ksbit.h" + +//% weight=2 color=30 +namespace serial { + // note that at least one // followed by % is needed per declaration! + + /** + * Reads a line of text from the serial port. + */ + //% + StringData* readString() { + return uBit.serial.readString().leakData(); + } + + /** + * Sends a piece of text through Serial connection. + */ + //% + void writeString(StringData *text) { + uBit.serial.sendString(ManagedString(text)); + } + + /** + * Sends the current pixel values, byte-per-pixel, over serial. + */ + //% + void writeScreen() { + uBit.serial.sendDisplayState(); + } + + /** + * Reads the screen from serial. + */ + //% + void readScreen() { + uBit.serial.readDisplayState(); + } +} diff --git a/libs/microbit/serial.ts b/libs/microbit/serial.ts index b1106b98..e4637dda 100644 --- a/libs/microbit/serial.ts +++ b/libs/microbit/serial.ts @@ -17,32 +17,6 @@ namespace serial { writeString(value.toString()); } - /** - * Reads a line of text from the serial port. - */ - //% shim=micro_bit::serialReadString - export function readString(): string { - return "" - } - - /** - * Sends a piece of text through Serial connection. - */ - //% shim=micro_bit::serialSendString - export function writeString(text: string): void { } - - /** - * Sends the current pixel values, byte-per-pixel, over serial. - */ - //% shim=micro_bit::serialSendDisplayState - export function writeScreen(): void { } - - /** - * Reads the screen from serial. - */ - //% shim=micro_bit::serialReadDisplayState - export function readScreen(): void { } - /** * Writes a ``name: value`` pair line to the serial. * @param name name of the value stream, eg: x diff --git a/libs/microbit/shims.d.ts b/libs/microbit/shims.d.ts index 3c347c23..90180d17 100644 --- a/libs/microbit/shims.d.ts +++ b/libs/microbit/shims.d.ts @@ -452,4 +452,34 @@ declare namespace pins { function analogPitch(frequency: number, ms: number): void; } + + + //% weight=2 color=30 +declare namespace serial { + + /** + * Reads a line of text from the serial port. + */ + //% shim=serial::readString + function readString(): string; + + /** + * Sends a piece of text through Serial connection. + */ + //% shim=serial::writeString + function writeString(text: string): void; + + /** + * Sends the current pixel values, byte-per-pixel, over serial. + */ + //% shim=serial::writeScreen + function writeScreen(): void; + + /** + * Reads the screen from serial. + */ + //% shim=serial::readScreen + function readScreen(): void; +} + // Auto-generated. Do not edit. Really.