pxt-calliope/libs/microbit/serial.cpp

23 lines
551 B
C++
Raw Normal View History

2016-04-02 07:00:42 +02:00
#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() {
2016-04-14 23:29:28 +02:00
return uBit.serial.readUntil(ManagedString("\r\n")).leakData();
2016-04-02 07:00:42 +02:00
}
/**
* Sends a piece of text through Serial connection.
*/
2016-04-26 19:29:05 +02:00
//% blockId=serial_writestring block="serial write %text"
2016-04-02 07:00:42 +02:00
void writeString(StringData *text) {
2016-04-14 23:29:28 +02:00
uBit.serial.send(ManagedString(text));
2016-04-02 07:00:42 +02:00
}
}