Migrate serial
This commit is contained in:
parent
0130ecb0c2
commit
6bf46577f9
2
libs/microbit/enums.d.ts
vendored
2
libs/microbit/enums.d.ts
vendored
@ -268,5 +268,7 @@ declare namespace led {
|
||||
}
|
||||
declare namespace pins {
|
||||
}
|
||||
declare namespace serial {
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
@ -21,6 +21,7 @@
|
||||
"led.ts",
|
||||
"music.ts",
|
||||
"pins.cpp",
|
||||
"serial.cpp",
|
||||
"serial.ts"
|
||||
],
|
||||
"public": true,
|
||||
|
@ -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;
|
||||
|
38
libs/microbit/serial.cpp
Normal file
38
libs/microbit/serial.cpp
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -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
|
||||
|
30
libs/microbit/shims.d.ts
vendored
30
libs/microbit/shims.d.ts
vendored
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user