Skip to content

Commit 32e7e57

Browse files
authored
add ts-only API that surfaces redirect return result (#6346)
1 parent edc231c commit 32e7e57

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

libs/core/serial.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace serial {
113113
}
114114

115115
/**
116-
* Read multiple characters from the receive buffer.
116+
* Read multiple characters from the receive buffer.
117117
* If length is positive, pauses until enough characters are present.
118118
* @param length default buffer length
119119
*/
@@ -144,8 +144,8 @@ namespace serial {
144144
case SerialPin::USB_TX: name = USBTX; return true;
145145
case SerialPin::USB_RX: name = USBRX; return true;
146146
#endif
147-
default:
148-
auto pin = getPin(p);
147+
default:
148+
auto pin = getPin(p);
149149
if (NULL != pin) {
150150
name = (PinName)pin->name;
151151
return true;
@@ -185,6 +185,22 @@ namespace serial {
185185
#endif
186186
}
187187

188+
//%
189+
int redirectWithStatus(SerialPin tx, SerialPin rx) {
190+
#if MICROBIT_CODAL
191+
if (getPin(tx) && getPin(rx)) {
192+
is_redirected = 1;
193+
return uBit.serial.redirect(*getPin(tx), *getPin(rx));
194+
}
195+
#else
196+
PinName txn;
197+
PinName rxn;
198+
if (tryResolvePin(tx, txn) && tryResolvePin(rx, rxn))
199+
return uBit.serial.redirect(txn, rxn);
200+
#endif
201+
return MICROBIT_INVALID_PARAMETER;
202+
}
203+
188204
/**
189205
Set the baud rate of the serial port
190206
*/

libs/core/shims.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ declare namespace serial {
10531053
function writeBuffer(buffer: Buffer): void;
10541054

10551055
/**
1056-
* Read multiple characters from the receive buffer.
1056+
* Read multiple characters from the receive buffer.
10571057
* If length is positive, pauses until enough characters are present.
10581058
* @param length default buffer length
10591059
*/

0 commit comments

Comments
 (0)