picked serial redirection fix from pxt-microbit (issue #961)

This commit is contained in:
thinkberg 2017-02-12 10:26:32 +01:00
parent 60f921c173
commit 56dc85e6ff

View File

@ -83,16 +83,19 @@ namespace serial {
/** /**
* Dynamically configuring the serial instance to use pins other than USBTX and USBRX. * Dynamically configuring the serial instance to use pins other than USBTX and USBRX.
* @param tx the new transmission pins * @param tx the new transmission pins, eg: SerialPin.P0
* @param rx the new reception pin * @param rx the new reception pin, eg: SerialPin.P1
* @param baud the new baud rate. eg: 115200 * @param rate the new baud rate. eg: 115200
*/ */
//% weight=10 //% weight=10
//% help=serial/redirect-to //% help=serial/redirect-to
//% blockId=serial_redirect block="serial|redirect to|TX %tx|RX %rx|at baud rate %rate" //% blockId=serial_redirect block="serial|redirect to|TX %tx|RX %rx|at baud rate %rate"
//% blockExternalInputs=1 //% blockExternalInputs=1
void redirect(SerialPin tx, SerialPin rx, BaudRate rate) { void redirect(SerialPin tx, SerialPin rx, BaudRate rate) {
uBit.serial.redirect((PinName)tx, (PinName)rx); MicroBitPin* txp = getPin(tx); if (!tx) return;
MicroBitPin* rxp = getPin(rx); if (!rx) return;
uBit.serial.redirect(txp->name, rxp->name);
uBit.serial.baud((int)rate); uBit.serial.baud((int)rate);
} }
} }