Redirecttousb (#604)

* add block to redirect back to USB

* added docs

* bump minor version
This commit is contained in:
Peli de Halleux 2017-12-14 06:44:48 -08:00 committed by GitHub
parent caa563ee30
commit b45f456736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 4 deletions

View File

@ -17,6 +17,7 @@ serial.onDataReceived(",", () => {})
```cards
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
serial.redirectToUSB();
serial.writeBuffer(pins.createBuffer(0));
serial.readBuffer(64);
```
@ -26,4 +27,5 @@ serial.readBuffer(64);
[writeLine](/reference/serial/write-line), [writeNumber](/reference/serial/write-number), [writeValue](/reference/serial/write-value),
[writeString](/reference/serial/write-string), [readUntil](/reference/serial/read-until), [readLine](/reference/serial/read-line),
[readString](/reference/serial/read-string), [onDataReceived](/reference/serial/on-data-received),
[redirect](/reference/serial/redirect-to), [writeBuffer](/reference/serial/write-buffer), [readBuffer](/reference/serial/read-buffer)
[redirect](/reference/serial/redirect-to), [writeBuffer](/reference/serial/write-buffer), [readBuffer](/reference/serial/read-buffer),
[redirectToUSB](/reference/serial/redirect-to-usb)

View File

@ -0,0 +1,12 @@
# Serial Redirect To USB
Dynamically configure the serial instance to use ``USBTX`` and ``USBRX``.
```sig
serial.redirectToUSB()
```
## See also
[serial](/device/serial),
[redirect](/reference/serial/redirect-to)

View File

@ -27,5 +27,6 @@ input.onButtonPressed(Button.A, () => {
## See also
[serial](/device/serial)
[serial](/device/serial),
[redirectToUSB](/reference/serial/redirect-to-usb)

View File

@ -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",

View File

@ -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",

View File

@ -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
View File

@ -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;
}

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.13.55",
"version": "0.14.0",
"description": "micro:bit target for Microsoft MakeCode (PXT)",
"keywords": [
"JavaScript",

View File

@ -49,4 +49,8 @@ namespace pxsim.serial {
export function redirect(tx: number, rx: number, rate: number) {
// TODO?
}
export function redirectToUSB() {
// TODO
}
}