add function to reset the UART back to USB
This commit is contained in:
		@@ -3,6 +3,12 @@
 | 
				
			|||||||
This target allow to program a [Calliope](http://calliope.cc/) using 
 | 
					This target allow to program a [Calliope](http://calliope.cc/) using 
 | 
				
			||||||
PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt)).
 | 
					PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt)).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### BUILD COMMENTS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- build libs/core/dal.d.ts new requires some meddling, as the `#define` parser does not parse `#ifdef` and thus
 | 
				
			||||||
 | 
					has some conflicts with double defines constants
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[](https://travis-ci.org/Microsoft/pxt-calliope)
 | 
					[](https://travis-ci.org/Microsoft/pxt-calliope)
 | 
				
			||||||
 | 
					
 | 
				
			||||||

 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -253,6 +253,7 @@
 | 
				
			|||||||
  "serial.redirect|param|rate": "the new baud rate. eg: 115200",
 | 
					  "serial.redirect|param|rate": "the new baud rate. eg: 115200",
 | 
				
			||||||
  "serial.redirect|param|rx": "the new reception pin, eg: SerialPin.P1",
 | 
					  "serial.redirect|param|rx": "the new reception pin, eg: SerialPin.P1",
 | 
				
			||||||
  "serial.redirect|param|tx": "the new transmission pins, eg: SerialPin.P0",
 | 
					  "serial.redirect|param|tx": "the new transmission pins, eg: SerialPin.P0",
 | 
				
			||||||
 | 
					  "serial.reset": "Reset the serial instance to use the USBTX and USBRX at the default baud rate.",
 | 
				
			||||||
  "serial.writeLine": "Prints a line of text to the serial",
 | 
					  "serial.writeLine": "Prints a line of text to the serial",
 | 
				
			||||||
  "serial.writeNumber": "Prints a numeric value to the serial",
 | 
					  "serial.writeNumber": "Prints a numeric value to the serial",
 | 
				
			||||||
  "serial.writeString": "Sends a piece of text through Serial connection.",
 | 
					  "serial.writeString": "Sends a piece of text through Serial connection.",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -233,6 +233,7 @@
 | 
				
			|||||||
  "serial.readString|block": "serial|read string",
 | 
					  "serial.readString|block": "serial|read string",
 | 
				
			||||||
  "serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv",
 | 
					  "serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv",
 | 
				
			||||||
  "serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate",
 | 
					  "serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate",
 | 
				
			||||||
 | 
					  "serial.reset|block": "serial pin reset",
 | 
				
			||||||
  "serial.writeLine|block": "serial|write line %text",
 | 
					  "serial.writeLine|block": "serial|write line %text",
 | 
				
			||||||
  "serial.writeNumber|block": "serial|write number %value",
 | 
					  "serial.writeNumber|block": "serial|write number %value",
 | 
				
			||||||
  "serial.writeString|block": "serial|write string %text",
 | 
					  "serial.writeString|block": "serial|write string %text",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,4 +100,16 @@ namespace serial {
 | 
				
			|||||||
      uBit.serial.redirect(txp->name, rxp->name);
 | 
					      uBit.serial.redirect(txp->name, rxp->name);
 | 
				
			||||||
      uBit.serial.baud((int)rate);
 | 
					      uBit.serial.baud((int)rate);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   /**
 | 
				
			||||||
 | 
					    * Reset the serial instance to use the USBTX and USBRX at the default baud rate.
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    //% weight=10
 | 
				
			||||||
 | 
					    //% help=serial/reset
 | 
				
			||||||
 | 
					    //% blockId=serial_reset block="serial pin reset"
 | 
				
			||||||
 | 
					    //% blockExternalInputs=1
 | 
				
			||||||
 | 
					    void reset() {
 | 
				
			||||||
 | 
					      uBit.serial.redirect(USBTX, USBRX);
 | 
				
			||||||
 | 
					      uBit.serial.baud(MICROBIT_SERIAL_DEFAULT_BAUD_RATE);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										9
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -760,6 +760,15 @@ declare namespace serial {
 | 
				
			|||||||
    //% 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 shim=serial::redirect
 | 
					    //% blockExternalInputs=1 shim=serial::redirect
 | 
				
			||||||
    function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void;
 | 
					    function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Reset the serial instance to use the USBTX and USBRX at the default baud rate.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    //% weight=10
 | 
				
			||||||
 | 
					    //% help=serial/reset
 | 
				
			||||||
 | 
					    //% blockId=serial_reset block="serial pin reset"
 | 
				
			||||||
 | 
					    //% blockExternalInputs=1 shim=serial::reset
 | 
				
			||||||
 | 
					    function reset(): void;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,10 @@
 | 
				
			|||||||
        "libs/core",
 | 
					        "libs/core",
 | 
				
			||||||
        "libs/radio",
 | 
					        "libs/radio",
 | 
				
			||||||
        "libs/devices",
 | 
					        "libs/devices",
 | 
				
			||||||
        "libs/bluetooth"
 | 
					        "libs/bluetooth",
 | 
				
			||||||
 | 
					        "libs/pxt-calliope-bc95",
 | 
				
			||||||
 | 
					        "libs/pxt-calliope-bunt",
 | 
				
			||||||
 | 
					        "libs/pxt-isl29125"
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    "cloud": {
 | 
					    "cloud": {
 | 
				
			||||||
        "workspace": false,
 | 
					        "workspace": false,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user