Migrate serial

This commit is contained in:
Michal Moskal 2016-04-01 22:00:42 -07:00
parent 0130ecb0c2
commit 6bf46577f9
6 changed files with 72 additions and 27 deletions

View File

@ -268,5 +268,7 @@ declare namespace led {
} }
declare namespace pins { declare namespace pins {
} }
declare namespace serial {
}
// Auto-generated. Do not edit. Really. // Auto-generated. Do not edit. Really.

View File

@ -21,6 +21,7 @@
"led.ts", "led.ts",
"music.ts", "music.ts",
"pins.cpp", "pins.cpp",
"serial.cpp",
"serial.ts" "serial.ts"
], ],
"public": true, "public": true,

View File

@ -116,7 +116,7 @@ namespace music {
* Gets the frequency of a note. * Gets the frequency of a note.
* @param name TODO * @param name TODO
*/ */
//% shim=TD_ID weight=50 help=music/note-frequency //% weight=50 help=music/note-frequency
//% blockId=device_note block="%note" //% blockId=device_note block="%note"
export function noteFrequency(name: Note): number { export function noteFrequency(name: Note): number {
return name; return name;

38
libs/microbit/serial.cpp Normal file
View 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();
}
}

View File

@ -17,32 +17,6 @@ namespace serial {
writeString(value.toString()); 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. * Writes a ``name: value`` pair line to the serial.
* @param name name of the value stream, eg: x * @param name name of the value stream, eg: x

View File

@ -452,4 +452,34 @@ declare namespace pins {
function analogPitch(frequency: number, ms: number): void; 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. // Auto-generated. Do not edit. Really.