Redirecttousb (#604)
* add block to redirect back to USB * added docs * bump minor version
This commit is contained in:
@ -419,6 +419,7 @@
|
||||
"serial.readUntil": "Reads a line of text from the serial port and returns the buffer when the delimiter is met.",
|
||||
"serial.readUntil|param|delimiter": "text delimiter that separates each text chunk",
|
||||
"serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.",
|
||||
"serial.redirectToUSB": "Redirects the serial instance to USBTX and USBRX.",
|
||||
"serial.redirect|param|rate": "the new baud rate. eg: 115200",
|
||||
"serial.redirect|param|rx": "the new reception pin, eg: SerialPin.P1",
|
||||
"serial.redirect|param|tx": "the new transmission pins, eg: SerialPin.P0",
|
||||
|
@ -339,6 +339,7 @@
|
||||
"serial.readLine|block": "serial|read line",
|
||||
"serial.readString|block": "serial|read string",
|
||||
"serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv",
|
||||
"serial.redirectToUSB|block": "serial|redirect to USB",
|
||||
"serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate",
|
||||
"serial.writeBuffer|block": "serial|write buffer %buffer",
|
||||
"serial.writeLine|block": "serial|write line %text",
|
||||
|
@ -152,6 +152,7 @@ namespace serial {
|
||||
//% tx.fieldOptions.tooltips="false"
|
||||
//% rx.fieldEditor="gridpicker" rx.fieldOptions.columns=3
|
||||
//% rx.fieldOptions.tooltips="false"
|
||||
//% blockGap=8
|
||||
void redirect(SerialPin tx, SerialPin rx, BaudRate rate) {
|
||||
MicroBitPin* txp = getPin(tx); if (!tx) return;
|
||||
MicroBitPin* rxp = getPin(rx); if (!rx) return;
|
||||
@ -159,4 +160,14 @@ namespace serial {
|
||||
uBit.serial.redirect(txp->name, rxp->name);
|
||||
uBit.serial.baud((int)rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects the serial instance to USBTX and USBRX.
|
||||
*/
|
||||
//% weight=9 help=serial/redirect-to-usb
|
||||
//% blockId=serial_redirect_to_usb block="serial|redirect to USB"
|
||||
void redirectToUSB() {
|
||||
uBit.serial.redirect(USBTX, USBRX);
|
||||
uBit.serial.baud(115200);
|
||||
}
|
||||
}
|
||||
|
10
libs/core/shims.d.ts
vendored
10
libs/core/shims.d.ts
vendored
@ -831,8 +831,16 @@ declare namespace serial {
|
||||
//% tx.fieldEditor="gridpicker" tx.fieldOptions.columns=3
|
||||
//% tx.fieldOptions.tooltips="false"
|
||||
//% rx.fieldEditor="gridpicker" rx.fieldOptions.columns=3
|
||||
//% rx.fieldOptions.tooltips="false" shim=serial::redirect
|
||||
//% rx.fieldOptions.tooltips="false"
|
||||
//% blockGap=8 shim=serial::redirect
|
||||
function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void;
|
||||
|
||||
/**
|
||||
* Redirects the serial instance to USBTX and USBRX.
|
||||
*/
|
||||
//% weight=9 help=serial/redirect-to-usb
|
||||
//% blockId=serial_redirect_to_usb block="serial|redirect to USB" shim=serial::redirectToUSB
|
||||
function redirectToUSB(): void;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user