40 lines
1.1 KiB
TypeScript
Raw Normal View History

2016-04-05 15:59:25 -07:00
/**
* Reading and writing data over a serial connection.
*/
2016-03-30 10:46:40 -07:00
//% weight=2 color=30
2016-03-10 14:01:04 -08:00
namespace serial {
/**
* Prints a line of text to the serial
* @param value to send over serial
*/
2016-04-22 12:37:47 -07:00
//% help=serial/write-line
2016-04-26 10:29:05 -07:00
//% blockId=serial_writeline block="serial|write line %text"
2016-03-10 14:01:04 -08:00
export function writeLine(text: string): void {
writeString(text);
writeString("\r\n");
}
2016-04-15 16:40:51 -07:00
/**
* Prints a numeric value to the serial
*/
2016-04-26 10:29:05 -07:00
//% blockId=serial_writenumber block="serial|write number %value"
2016-04-15 16:40:51 -07:00
export function writeNumber(value: number): void {
writeString(value.toString());
}
2016-03-10 14:01:04 -08:00
/**
* Writes a ``name: value`` pair line to the serial.
* @param name name of the value stream, eg: x
* @param value to write
*/
//% weight=80
2016-04-22 12:37:47 -07:00
//% help=serial/write-value
2016-04-26 12:19:42 -07:00
//% blockId=serial_writevalue block="serial|write line %name|= %value"
2016-03-10 14:01:04 -08:00
export function writeValue(name: string, value: number): void {
writeString(name);
2016-04-15 16:40:51 -07:00
writeString(": ");
writeNumber(value);
writeLine("");
2016-03-10 14:01:04 -08:00
}
}