Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3c8db28e4 | ||
|
|
2c0e19a120 | ||
|
|
595eb788b2 | ||
|
|
2e15d22e9e | ||
|
|
57082654a9 | ||
|
|
8cbf7d38e3 | ||
|
|
a99a7325bf | ||
|
|
fa3ed9dd21 | ||
|
|
45fd40a553 | ||
|
|
5a18bea9eb | ||
|
|
d310312841 | ||
|
|
a4b93f7199 | ||
|
|
538a4b7bbf | ||
|
|
0078e7bc12 | ||
|
|
d2726133a9 | ||
|
|
00f4c9cbb3 | ||
|
|
e15da5dee1 | ||
|
|
85dda4ea84 | ||
|
|
a3ffe4e1cf | ||
|
|
90c4d4f73b | ||
|
|
6484d559d6 | ||
|
|
357436f14d | ||
|
|
85fe96b3fd | ||
|
|
cdac932c42 | ||
|
|
dcfc2a110d | ||
|
|
e9561f54c3 | ||
|
|
86f6b58d38 | ||
|
|
eee52a5c04 | ||
|
|
1a0b0eac71 | ||
|
|
5a98ae0bb8 | ||
|
|
a9eea9a618 | ||
|
|
3086c521e3 | ||
|
|
6788f79650 | ||
|
|
5900239045 | ||
|
|
248267ec2c | ||
|
|
9429075555 | ||
|
|
1fa871f2e7 | ||
|
|
04dab7df2c | ||
|
|
b6474467bc | ||
|
|
79ead74af4 | ||
|
|
0f8ff95b72 | ||
|
|
05028c4527 |
@@ -7,8 +7,11 @@ serial.writeLine("");
|
||||
serial.writeNumber(0);
|
||||
serial.writeValue("x", 0);
|
||||
serial.writeString("");
|
||||
serial.readUntil(",");
|
||||
serial.readLine();
|
||||
serial.readString();
|
||||
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
||||
serial.onDataReceived(",", () => {})
|
||||
```
|
||||
|
||||
### See Also
|
||||
|
||||
29
docs/reference/serial/on-data-received.md
Normal file
29
docs/reference/serial/on-data-received.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Serial On Data Received
|
||||
|
||||
Registers an event to be fired when one of the delimiter is matched.
|
||||
|
||||
|
||||
```sig
|
||||
serial.onDataReceived(",", () => {})
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `delimiters` is a [string](/reference/types/string) containing any of the character to match
|
||||
|
||||
### Example
|
||||
|
||||
Read values separated by `,`:
|
||||
|
||||
```blocks
|
||||
serial.onDataReceived(serial.delimiters(Delimiters.Comma), () => {
|
||||
basic.showString(serial.readUntil(serial.delimiters(Delimiters.Comma)))
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write line](/reference/serial/write-line),
|
||||
[serial write value](/reference/serial/write-value)
|
||||
|
||||
27
docs/reference/serial/read-string.md
Normal file
27
docs/reference/serial/read-string.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Serial Read String
|
||||
|
||||
Read the buffered serial data as a string
|
||||
|
||||
```sig
|
||||
serial.readString();
|
||||
```
|
||||
|
||||
### Returns
|
||||
|
||||
* a [string](/reference/types/string) containing input from the serial port. Empty if no data available.
|
||||
|
||||
### Example
|
||||
|
||||
The following program scrolls text on the screen as it arrives from serial.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showString(serial.readString());
|
||||
});
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[serial](/device/serial),
|
||||
[serial write line](/reference/serial/write-line),
|
||||
[serial write value](/reference/serial/write-value)
|
||||
@@ -31,6 +31,7 @@ and press **A** to scroll your text.
|
||||
### Step 5
|
||||
|
||||
Place more blocks to display a smiley when button **B** is pressed.
|
||||
Use the dropdown to find ``B``!
|
||||
|
||||
```block
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
@@ -59,3 +60,15 @@ input.onGesture(Gesture.Shake, () => {
|
||||
`)
|
||||
})
|
||||
```
|
||||
|
||||
### Step 7
|
||||
|
||||
Drag more blocks to display a random number when pin ``P0`` is touched.
|
||||
Hold your right thumb on the ``GND`` metal pin
|
||||
at press the ``0`` pin with your right hand to trigger this event.
|
||||
|
||||
```block
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.random(7))
|
||||
})
|
||||
```
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"versions": {
|
||||
"0": {
|
||||
"latest": "v0.6.45",
|
||||
"latest": "v0.7.29",
|
||||
"banned": [],
|
||||
"prompt": "v0.0.0"
|
||||
"prompt": "v0.7.29"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<block type="pxt-on-start"></block>
|
||||
<block type="device_forever"></block>
|
||||
</xml>
|
||||
@@ -231,8 +231,10 @@
|
||||
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
|
||||
"serial": "Reading and writing data over a serial connection.",
|
||||
"serial.delimiters": "Returns the delimiter corresponding string",
|
||||
"serial.onLineReceived": "Registers an event to be fired when a line has been received",
|
||||
"serial.onDataReceived": "Registers an event to be fired when one of the delimiter is matched.",
|
||||
"serial.onDataReceived|param|delimiters": "the characters to match received characters against.",
|
||||
"serial.readLine": "Reads a line of text from the serial port.",
|
||||
"serial.readString": "Reads the buffered received data as a string",
|
||||
"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.",
|
||||
|
||||
@@ -171,7 +171,9 @@
|
||||
"pins.spiWrite|block": "spi write %value",
|
||||
"pins|block": "pins",
|
||||
"serial.delimiters|block": "%del",
|
||||
"serial.onDataReceived|block": "serial|on data received %delimiters=serial_delimiter_conv",
|
||||
"serial.readLine|block": "serial|read line",
|
||||
"serial.readString|block": "serial|read string",
|
||||
"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.writeLine|block": "serial|write line %text",
|
||||
|
||||
@@ -21,7 +21,12 @@ namespace String_ {
|
||||
|
||||
//%
|
||||
int compare(StringData *s, StringData *that) {
|
||||
return strcmp(s->data, that->data);
|
||||
int compareResult = strcmp(s->data, that->data);
|
||||
if (compareResult < 0)
|
||||
return -1;
|
||||
else if (compareResult > 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//%
|
||||
|
||||
@@ -51,24 +51,27 @@ namespace serial {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a line of text from the serial port.
|
||||
*/
|
||||
//% help=serial/read-line
|
||||
//% blockId=serial_read_line block="serial|read line"
|
||||
//% weight=20 blockGap=8
|
||||
StringData* readLine() {
|
||||
return readUntil(ManagedString("\n").leakData());
|
||||
* Reads the buffered received data as a string
|
||||
*/
|
||||
//% blockId=serial_read_buffer block="serial|read string"
|
||||
//% weight=18
|
||||
StringData* readString() {
|
||||
int n = uBit.serial.getRxBufferSize();
|
||||
if (n == 0) return ManagedString("").leakData();
|
||||
return ManagedString(uBit.serial.read(n, MicroBitSerialMode::ASYNC)).leakData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event to be fired when one of the delimiter is matched
|
||||
* @param delimiters the characters to match received characters against. eg:"\n"
|
||||
* Registers an event to be fired when one of the delimiter is matched.
|
||||
* @param delimiters the characters to match received characters against.
|
||||
*/
|
||||
// help=serial/on-data-received
|
||||
// weight=18
|
||||
//% help=serial/on-data-received
|
||||
//% weight=18 blockId=serial_on_data_received block="serial|on data received %delimiters=serial_delimiter_conv"
|
||||
void onDataReceived(StringData* delimiters, Action body) {
|
||||
uBit.serial.eventOn(ManagedString(delimiters));
|
||||
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
|
||||
// lazy initialization of serial buffers
|
||||
uBit.serial.read(MicroBitSerialMode::ASYNC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,20 +38,20 @@ namespace serial {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an event to be fired when a line has been received
|
||||
*/
|
||||
// help=serial/on-line-received
|
||||
// blockId=serial_on_line_received block="serial on line received"
|
||||
// weight=21 blockGap=8
|
||||
export function onLineReceived(body: Action): void {
|
||||
// serial.onDataReceived("\n", body);
|
||||
* Reads a line of text from the serial port.
|
||||
*/
|
||||
//% help=serial/read-line
|
||||
//% blockId=serial_read_line block="serial|read line"
|
||||
//% weight=20 blockGap=8
|
||||
export function readLine(): string {
|
||||
return serial.readUntil(delimiters(Delimiters.NewLine));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the delimiter corresponding string
|
||||
*/
|
||||
//% blockId="serial_delimiter_conv" block="%del"
|
||||
//% weight=1
|
||||
//% weight=1 blockHidden=true
|
||||
export function delimiters(del: Delimiters): string {
|
||||
// even though it might not look like, this is more
|
||||
// (memory) efficient than the C++ implementation, because the
|
||||
|
||||
17
libs/core/shims.d.ts
vendored
17
libs/core/shims.d.ts
vendored
@@ -672,12 +672,19 @@ declare namespace serial {
|
||||
function readUntil(delimiter: string): string;
|
||||
|
||||
/**
|
||||
* Reads a line of text from the serial port.
|
||||
* Reads the buffered received data as a string
|
||||
*/
|
||||
//% help=serial/read-line
|
||||
//% blockId=serial_read_line block="serial|read line"
|
||||
//% weight=20 blockGap=8 shim=serial::readLine
|
||||
function readLine(): string;
|
||||
//% blockId=serial_read_buffer block="serial|read string"
|
||||
//% weight=18 shim=serial::readString
|
||||
function readString(): string;
|
||||
|
||||
/**
|
||||
* Registers an event to be fired when one of the delimiter is matched.
|
||||
* @param delimiters the characters to match received characters against.
|
||||
*/
|
||||
//% help=serial/on-data-received
|
||||
//% weight=18 blockId=serial_on_data_received block="serial|on data received %delimiters=serial_delimiter_conv" shim=serial::onDataReceived
|
||||
function onDataReceived(delimiters: string, body: () => void): void;
|
||||
|
||||
/**
|
||||
* Sends a piece of text through Serial connection.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.7.22",
|
||||
"version": "0.7.38",
|
||||
"description": "micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@@ -36,6 +36,6 @@
|
||||
"semantic-ui-less": "^2.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.8.12"
|
||||
"pxt-core": "0.10.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,8 @@
|
||||
"logicBlocks": true,
|
||||
"variablesBlocks": true,
|
||||
"onStartColor": "#0078D7",
|
||||
"onStartNamespace": "basic"
|
||||
"onStartNamespace": "basic",
|
||||
"onStartWeight": 54
|
||||
},
|
||||
"simulator": {
|
||||
"autoRun": true,
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace pxsim {
|
||||
radioState: RadioState;
|
||||
// TODO: not singletons
|
||||
neopixelState: NeoPixelState;
|
||||
servosState: MicroServosState;
|
||||
fileSystem: FileSystemState;
|
||||
|
||||
constructor() {
|
||||
@@ -53,7 +52,13 @@ namespace pxsim {
|
||||
0,
|
||||
DAL.MICROBIT_ID_IO_P19,
|
||||
DAL.MICROBIT_ID_IO_P20
|
||||
]
|
||||
],
|
||||
servos: {
|
||||
"P0": DAL.MICROBIT_ID_IO_P0,
|
||||
"P1": DAL.MICROBIT_ID_IO_P1,
|
||||
"P2": DAL.MICROBIT_ID_IO_P2,
|
||||
"P3": DAL.MICROBIT_ID_IO_P3
|
||||
}
|
||||
});
|
||||
this.builtinParts["radio"] = this.radioState = new RadioState(runtime);
|
||||
this.builtinParts["accelerometer"] = this.accelerometerState = new AccelerometerState(runtime);
|
||||
@@ -62,12 +67,7 @@ namespace pxsim {
|
||||
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
||||
this.builtinParts["compass"] = this.compassState = new CompassState();
|
||||
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
||||
this.builtinParts["microservo"] = this.servosState = new MicroServosState({
|
||||
"P0": DAL.MICROBIT_ID_IO_P0,
|
||||
"P1": DAL.MICROBIT_ID_IO_P1,
|
||||
"P2": DAL.MICROBIT_ID_IO_P2,
|
||||
"P3": DAL.MICROBIT_ID_IO_P3
|
||||
});
|
||||
this.builtinParts["microservo"] = this.edgeConnectorState;
|
||||
|
||||
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
||||
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
||||
|
||||
@@ -76,8 +76,7 @@ namespace pxsim.pins {
|
||||
if (!pin) return;
|
||||
|
||||
analogSetPeriod(pinId, 20000);
|
||||
const state = board().servosState.servoState(pinId);
|
||||
state.setAngle(value);
|
||||
pin.servoAngle = value;
|
||||
}
|
||||
|
||||
export function servoSetPulse(pinId: number, micros: number) {
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace pxsim {
|
||||
this.data = data;
|
||||
}
|
||||
public print() {
|
||||
console.log(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
||||
pxt.debug(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
||||
}
|
||||
public get(x: number, y: number): number {
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||
@@ -228,7 +228,7 @@ namespace pxsim.basic {
|
||||
clearScreen();
|
||||
pause(interval * 5);
|
||||
} else {
|
||||
if (s.length == 1) showLeds(createImageFromString(s + " "), interval * 5)
|
||||
if (s.length == 1) showLeds(createImageFromString(s), 0);
|
||||
else ImageMethods.scrollImage(createImageFromString(s + " "), 1, interval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,18 +35,14 @@ namespace pxsim.serial {
|
||||
board().writeSerial(s);
|
||||
}
|
||||
|
||||
export function readUntil(del: string): string {
|
||||
return readString();
|
||||
}
|
||||
|
||||
export function readString(): string {
|
||||
return board().serialState.readSerial();
|
||||
}
|
||||
|
||||
export function readLine(): string {
|
||||
return board().serialState.readSerial();
|
||||
}
|
||||
|
||||
export function readUntil(del: string): string {
|
||||
return readLine();
|
||||
}
|
||||
|
||||
export function onDataReceived(delimiters: string, handler: RefAction) {
|
||||
let b = board();
|
||||
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);
|
||||
|
||||
@@ -1,56 +1,3 @@
|
||||
/*******************************
|
||||
Site Overrides
|
||||
*******************************/
|
||||
|
||||
.ui.loader:before {
|
||||
border: none;
|
||||
border-radius: 0px;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.ui.loader:after {
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
border-radius: 0px;
|
||||
margin: 40px auto;
|
||||
background: transparent data-uri("static/loader.svg") no-repeat center center;
|
||||
background-size: 100%;
|
||||
-webkit-animation: loader-pxt @loaderSpeed infinite ease-in-out;
|
||||
animation: loader-pxt @loaderSpeed infinite ease-in-out;
|
||||
}
|
||||
|
||||
@-webkit-keyframes loader-pxt {
|
||||
0% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
opacity: 0}
|
||||
15% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(-@loaderAngle);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(-@loaderAngle); }
|
||||
50% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(@loaderAngle);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(@loaderAngle);
|
||||
opacity: 1}
|
||||
100% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
opacity: 0}
|
||||
}
|
||||
|
||||
@keyframes loader-pxt {
|
||||
0% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
opacity: 0}
|
||||
15% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(-10deg);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(-10deg); }
|
||||
50% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(10deg);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(10deg);
|
||||
opacity: 1}
|
||||
100% {
|
||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
||||
opacity: 0}
|
||||
}
|
||||
@@ -1,8 +1,3 @@
|
||||
/*******************************
|
||||
User Variable Overrides
|
||||
*******************************/
|
||||
|
||||
@loaderSpeed: 2s;
|
||||
@loaderAngle: 5deg;
|
||||
|
||||
@large : 200px;
|
||||
@@ -29,10 +29,18 @@
|
||||
&:extend(.orange all);
|
||||
}
|
||||
|
||||
.ui.button.editortools-btn {
|
||||
&:extend(.blue all);
|
||||
}
|
||||
|
||||
#filelist, #editortools {
|
||||
background: #fff url(https://az742082.vo.msecnd.net/pub/psopafpj) 0 0 repeat !important;
|
||||
}
|
||||
|
||||
#downloadArea {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
/*******************************
|
||||
Blockly
|
||||
*******************************/
|
||||
|
||||
Reference in New Issue
Block a user