Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
4054da3483 | ||
|
|
7052d27d6d | ||
|
|
365af8d672 | ||
|
|
5086ca308c | ||
|
|
c1af770afc | ||
|
|
e175e70d01 | ||
|
|
cbc228dca3 | ||
|
|
462127c661 | ||
|
|
487da05eca | ||
|
|
c938618d29 | ||
|
|
91321dab83 | ||
|
|
0cb3d6e44e | ||
|
|
7a98b06424 | ||
|
|
69c80d3aff | ||
|
|
1d82f08668 | ||
|
|
4681a68ffd | ||
|
|
0a69b773de | ||
|
|
3f66a1c16d | ||
|
|
d78781ad5a | ||
|
|
46281c3cd0 |
@@ -16,10 +16,10 @@ at a certain pace. In the code below, the user pressed button ``A`` to launch th
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
pins.servoWritePin(AnalogPin.P0, 0)
|
pins.servoWritePin(AnalogPin.P0, 0);
|
||||||
basic.pause(500)
|
basic.pause(500);
|
||||||
pins.servoWritePin(AnalogPin.P0, 180)
|
pins.servoWritePin(AnalogPin.P0, 180);
|
||||||
basic.pause(500)
|
basic.pause(500);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -46,3 +46,7 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
radio.sendNumber(0)
|
radio.sendNumber(0)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```package
|
||||||
|
radio
|
||||||
|
```
|
||||||
@@ -41,7 +41,7 @@ Using the cutting pliers, cut out the dark plastic connector.
|
|||||||
|
|
||||||
Using the plier or a wire stripper, strip the plastic from the cables.
|
Using the plier or a wire stripper, strip the plastic from the cables.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Step 3: threading the servo cablers
|
## Step 3: threading the servo cablers
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ bluetooth.advertiseUidBuffer(pins.createBuffer(16), 7, true);
|
|||||||
|
|
||||||
* ``buffer`` - a 16 bytes buffer containing the namespace (first 10 bytes) and instance (last 6 bytes).
|
* ``buffer`` - a 16 bytes buffer containing the namespace (first 10 bytes) and instance (last 6 bytes).
|
||||||
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
||||||
* ``connectable`` - a [boolean](/reference/type/boolean) indicating whether or not the micro:bit should accept connections.
|
* ``connectable`` - a [boolean](/blocks/logic/boolean) indicating whether or not the micro:bit should accept connections.
|
||||||
|
|
||||||
|
|
||||||
## See Also
|
## See Also
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ bluetooth.advertiseUid(42, 1, 7, true);
|
|||||||
* ``namespace`` last 4 bytes of the namespace uid (6 to 9)
|
* ``namespace`` last 4 bytes of the namespace uid (6 to 9)
|
||||||
* ``instance`` last 4 bytes of the instance (2 to 5)
|
* ``instance`` last 4 bytes of the instance (2 to 5)
|
||||||
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
||||||
* ``connectable`` - a [boolean](/reference/type/boolean) indicating whether or not the micro:bit should accept connections.
|
* ``connectable`` - a [boolean](/blocks/logic/boolean) indicating whether or not the micro:bit should accept connections.
|
||||||
|
|
||||||
## Encoding
|
## Encoding
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ bluetooth.advertiseUrl("https://pxt.microbit.org/", 7, true);
|
|||||||
|
|
||||||
* ``url`` - a [string](/reference/types/string) containing the URL to broadcast, at most 17 characters long, excluding the protocol (eg: ``https://``) which gets encoded as 1 byte.
|
* ``url`` - a [string](/reference/types/string) containing the URL to broadcast, at most 17 characters long, excluding the protocol (eg: ``https://``) which gets encoded as 1 byte.
|
||||||
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
|
||||||
* ``connectable`` - a [boolean](/reference/type/boolean) indicating whether or not the micro:bit should accept connections.
|
* ``connectable`` - a [boolean](/blocks/logic/boolean) indicating whether or not the micro:bit should accept connections.
|
||||||
|
|
||||||
### Example: Broadcast a secret code
|
### Example: Broadcast a secret code
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,11 @@ serial.writeLine("");
|
|||||||
serial.writeNumber(0);
|
serial.writeNumber(0);
|
||||||
serial.writeValue("x", 0);
|
serial.writeValue("x", 0);
|
||||||
serial.writeString("");
|
serial.writeString("");
|
||||||
|
serial.readUntil(",");
|
||||||
serial.readLine();
|
serial.readLine();
|
||||||
|
serial.readString();
|
||||||
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
||||||
|
serial.onDataReceived(",", () => {})
|
||||||
```
|
```
|
||||||
|
|
||||||
### See Also
|
### 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)
|
||||||
61
docs/static/avatar.svg
vendored
Normal file
61
docs/static/avatar.svg
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
role="img"
|
||||||
|
aria-labelledby="title desc"
|
||||||
|
xml:space="preserve"
|
||||||
|
enable-background="new 0 0 280 32.755"
|
||||||
|
height="52.672001"
|
||||||
|
width="52.672001"
|
||||||
|
version="1.1"
|
||||||
|
id="svg2"
|
||||||
|
inkscape:version="0.91 r13725"
|
||||||
|
sodipodi:docname="logo.square.black.svg"><sodipodi:namedview
|
||||||
|
pagecolor="#ff00ff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1536"
|
||||||
|
inkscape:window-height="801"
|
||||||
|
id="namedview14"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="2.0836233"
|
||||||
|
inkscape:cx="83.390493"
|
||||||
|
inkscape:cy="16.071144"
|
||||||
|
inkscape:window-x="-8"
|
||||||
|
inkscape:window-y="-8"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg2" /><rect
|
||||||
|
id="backgroundrect"
|
||||||
|
width="195.47368"
|
||||||
|
height="34.210526"
|
||||||
|
x="0"
|
||||||
|
y="18.461473"
|
||||||
|
class=""
|
||||||
|
style="fill:none;stroke:none" /><title
|
||||||
|
id="title"
|
||||||
|
lang="en-GB">BBC micro:bit</title><desc
|
||||||
|
id="desc"
|
||||||
|
lang="en-GB">BBC micro:bit logo</desc><metadata
|
||||||
|
id="metadata37"><rdf:rdf><cc:work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:work></rdf:rdf><rdf:RDF><cc:Work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title>BBC micro:bit</dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||||
|
id="defs35" /><path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
class=""
|
||||||
|
d="m 37.363,29.377 c -1.677,0 -3.035,-1.364 -3.035,-3.042 0,-1.678 1.357,-3.038 3.035,-3.038 1.684,0 3.039,1.36 3.039,3.038 0,1.678 -1.355,3.042 -3.039,3.042 M 15.052,23.3 c -1.677,0 -3.042,1.357 -3.042,3.035 0,1.678 1.363,3.042 3.042,3.042 1.674,0 3.036,-1.364 3.036,-3.042 0,-1.678 -1.363,-3.035 -3.036,-3.035 m -0.003,-5.99 22.576,0 c 4.979,0 9.027,4.047 9.027,9.027 0,4.979 -4.049,9.031 -9.027,9.031 l -22.576,0 c -4.977,0 -9.0299993,-4.053 -9.0299993,-9.031 C 6.0180007,21.357 10.072,17.31 15.049,17.31 m 22.576,24.076 c 8.299,0 15.047,-6.75 15.047,-15.049 0,-8.299 -6.748,-15.051 -15.047,-15.051 l -22.576,0 C 6.7500007,11.286 6.9250488e-7,18.038 6.9250488e-7,26.337 6.9250488e-7,34.636 6.7500007,41.386 15.049,41.386 l 22.576,0"
|
||||||
|
id="path21"
|
||||||
|
style="fill:#000000"
|
||||||
|
sodipodi:nodetypes="csssccsssccsssscccsssssc" /></svg>
|
||||||
|
After Width: | Height: | Size: 2.8 KiB |
61
docs/static/loader.svg
vendored
Normal file
61
docs/static/loader.svg
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
role="img"
|
||||||
|
aria-labelledby="title desc"
|
||||||
|
xml:space="preserve"
|
||||||
|
enable-background="new 0 0 280 32.755"
|
||||||
|
height="52.672001"
|
||||||
|
width="52.672001"
|
||||||
|
version="1.1"
|
||||||
|
id="svg2"
|
||||||
|
inkscape:version="0.91 r13725"
|
||||||
|
sodipodi:docname="logo.square.white.svg"><sodipodi:namedview
|
||||||
|
pagecolor="#ff00ff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1536"
|
||||||
|
inkscape:window-height="801"
|
||||||
|
id="namedview14"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="2.0836233"
|
||||||
|
inkscape:cx="83.390493"
|
||||||
|
inkscape:cy="16.071144"
|
||||||
|
inkscape:window-x="-8"
|
||||||
|
inkscape:window-y="-8"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg2" /><rect
|
||||||
|
id="backgroundrect"
|
||||||
|
width="195.47368"
|
||||||
|
height="34.210526"
|
||||||
|
x="0"
|
||||||
|
y="18.461473"
|
||||||
|
class=""
|
||||||
|
style="fill:none;stroke:none" /><title
|
||||||
|
id="title"
|
||||||
|
lang="en-GB">BBC micro:bit</title><desc
|
||||||
|
id="desc"
|
||||||
|
lang="en-GB">BBC micro:bit logo</desc><metadata
|
||||||
|
id="metadata37"><rdf:rdf><cc:work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:work></rdf:rdf><rdf:RDF><cc:Work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title>BBC micro:bit</dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||||
|
id="defs35" /><path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
class=""
|
||||||
|
d="m 37.363,29.377 c -1.677,0 -3.035,-1.364 -3.035,-3.042 0,-1.678 1.357,-3.038 3.035,-3.038 1.684,0 3.039,1.36 3.039,3.038 0,1.678 -1.355,3.042 -3.039,3.042 M 15.052,23.3 c -1.677,0 -3.042,1.357 -3.042,3.035 0,1.678 1.363,3.042 3.042,3.042 1.674,0 3.036,-1.364 3.036,-3.042 0,-1.678 -1.363,-3.035 -3.036,-3.035 m -0.003,-5.99 22.576,0 c 4.979,0 9.027,4.047 9.027,9.027 0,4.979 -4.049,9.031 -9.027,9.031 l -22.576,0 c -4.977,0 -9.0299993,-4.053 -9.0299993,-9.031 C 6.0180007,21.357 10.072,17.31 15.049,17.31 m 22.576,24.076 c 8.299,0 15.047,-6.75 15.047,-15.049 0,-8.299 -6.748,-15.051 -15.047,-15.051 l -22.576,0 C 6.7500007,11.286 6.9250488e-7,18.038 6.9250488e-7,26.337 6.9250488e-7,34.636 6.7500007,41.386 15.049,41.386 l 22.576,0"
|
||||||
|
id="path21"
|
||||||
|
style="fill:#ffffff"
|
||||||
|
sodipodi:nodetypes="csssccsssccsssscccsssssc" /></svg>
|
||||||
|
After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
@@ -5,15 +5,12 @@
|
|||||||
Place blocks in the workspace to scroll text on the screen.
|
Place blocks in the workspace to scroll text on the screen.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.showString("Hi!")
|
basic.showString("Hello!")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 2
|
### Step 2
|
||||||
|
|
||||||
Transfer your code in your @boardname@! Click the **Download** button
|
Click ``|Download|`` to transfer your code in your @boardname@!
|
||||||
and follow the instructions.
|
|
||||||
|
|
||||||
ANIMATEDGIF
|
|
||||||
|
|
||||||
### Step 3
|
### Step 3
|
||||||
|
|
||||||
@@ -22,20 +19,19 @@ Let's make it scroll when button **A** is pressed.
|
|||||||
|
|
||||||
```block
|
```block
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
basic.showString("Hi!")
|
basic.showString("Hello!")
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 4
|
### Step 4
|
||||||
|
|
||||||
Transfer your code in your @boardname@ and try pressing **A**.
|
Click ``|Download|`` to transfer your code
|
||||||
|
and press **A** to scroll your text.
|
||||||
ANIMATEDGIF
|
|
||||||
|
|
||||||
### Step 5
|
### Step 5
|
||||||
|
|
||||||
Place more blocks to display a smiley when button **B** is pressed.
|
Place more blocks to display a smiley when button **B** is pressed.
|
||||||
Download your code and try it!
|
Use the dropdown to find ``B``!
|
||||||
|
|
||||||
```block
|
```block
|
||||||
input.onButtonPressed(Button.B, () => {
|
input.onButtonPressed(Button.B, () => {
|
||||||
@@ -52,7 +48,6 @@ input.onButtonPressed(Button.B, () => {
|
|||||||
### Step 6
|
### Step 6
|
||||||
|
|
||||||
Drag more blocks to display a frownie when @boardname@ is shaken.
|
Drag more blocks to display a frownie when @boardname@ is shaken.
|
||||||
Download your code and try it!
|
|
||||||
|
|
||||||
```block
|
```block
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, () => {
|
||||||
@@ -65,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": {
|
"versions": {
|
||||||
"0": {
|
"0": {
|
||||||
"latest": "v0.6.45",
|
"latest": "v0.7.29",
|
||||||
"banned": [],
|
"banned": [],
|
||||||
"prompt": "v0.0.0"
|
"prompt": "v0.7.29"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<block type="pxt-on-start"></block>
|
<block type="pxt-on-start"></block>
|
||||||
|
<block type="device_forever"></block>
|
||||||
</xml>
|
</xml>
|
||||||
@@ -231,8 +231,10 @@
|
|||||||
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
|
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
|
||||||
"serial": "Reading and writing data over a serial connection.",
|
"serial": "Reading and writing data over a serial connection.",
|
||||||
"serial.delimiters": "Returns the delimiter corresponding string",
|
"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.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": "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.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.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.spiWrite|block": "spi write %value",
|
||||||
"pins|block": "pins",
|
"pins|block": "pins",
|
||||||
"serial.delimiters|block": "%del",
|
"serial.delimiters|block": "%del",
|
||||||
|
"serial.onDataReceived|block": "serial|on data received %delimiters=serial_delimiter_conv",
|
||||||
"serial.readLine|block": "serial|read line",
|
"serial.readLine|block": "serial|read line",
|
||||||
|
"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.writeLine|block": "serial|write line %text",
|
"serial.writeLine|block": "serial|write line %text",
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ namespace String_ {
|
|||||||
|
|
||||||
//%
|
//%
|
||||||
int compare(StringData *s, StringData *that) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//%
|
//%
|
||||||
@@ -76,7 +81,7 @@ namespace Boolean_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//%
|
//%
|
||||||
bool bang(bool v) { return !v; }
|
bool bang(int v) { return v == 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Number_ {
|
namespace Number_ {
|
||||||
|
|||||||
@@ -149,16 +149,10 @@ namespace pxt {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (i < length)
|
if (i < length)
|
||||||
{
|
|
||||||
if (data[i] != Segment::MissingValue)
|
|
||||||
{
|
{
|
||||||
return data[i];
|
return data[i];
|
||||||
}
|
}
|
||||||
error(ERR_MISSING_VALUE);
|
return Segment::DefaultValue;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segment::set(uint32_t i, uint32_t value)
|
void Segment::set(uint32_t i, uint32_t value)
|
||||||
@@ -223,12 +217,8 @@ namespace pxt {
|
|||||||
{
|
{
|
||||||
memcpy(tmp, data, size * sizeof(uint32_t));
|
memcpy(tmp, data, size * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
|
//fill the rest with default value
|
||||||
//fill the rest with missing values;
|
memset(tmp + size, Segment::DefaultValue, (newSize - size) * sizeof(uint32_t));
|
||||||
for(uint16_t i = size; i < newSize; i++)
|
|
||||||
{
|
|
||||||
tmp[i] = Segment::MissingValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//free older segment;
|
//free older segment;
|
||||||
::operator delete(data);
|
::operator delete(data);
|
||||||
@@ -280,12 +270,11 @@ namespace pxt {
|
|||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
uint32_t value = data[length];
|
uint32_t value = data[length];
|
||||||
data[length] = Segment::MissingValue;
|
data[length] = Segment::DefaultValue;
|
||||||
--length;
|
--length;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
return Segment::DefaultValue;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//this function removes an element at index i and shifts the rest of the elements to
|
//this function removes an element at index i and shifts the rest of the elements to
|
||||||
@@ -306,15 +295,14 @@ namespace pxt {
|
|||||||
memmove(data + i, data + i + 1, (length - i - 1) * sizeof(uint32_t));
|
memmove(data + i, data + i + 1, (length - i - 1) * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
length--;
|
length--;
|
||||||
data[length] = Segment::MissingValue;
|
data[length] = Segment::DefaultValue;
|
||||||
#ifdef DEBUG_BUILD
|
#ifdef DEBUG_BUILD
|
||||||
printf("After Segment::remove index:%u\n", i);
|
printf("After Segment::remove index:%u\n", i);
|
||||||
this->print();
|
this->print();
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
return Segment::DefaultValue;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//this function inserts element value at index i by shifting the rest of the elements right.
|
//this function inserts element value at index i by shifting the rest of the elements right.
|
||||||
@@ -360,32 +348,13 @@ namespace pxt {
|
|||||||
|
|
||||||
bool Segment::isValidIndex(uint32_t i)
|
bool Segment::isValidIndex(uint32_t i)
|
||||||
{
|
{
|
||||||
if (i > length || data[i] == Segment::MissingValue)
|
if (i > length)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Segment::getNextValidIndex(uint32_t i, uint32_t *result)
|
|
||||||
{
|
|
||||||
while (i < length)
|
|
||||||
{
|
|
||||||
if (data[i] != Segment::MissingValue)
|
|
||||||
{
|
|
||||||
*result = i;
|
|
||||||
|
|
||||||
#ifdef DEBUG_BUILD
|
|
||||||
printf("In Segment::getNextValidIndex result=%u\n",i);
|
|
||||||
this->print();
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Segment::destroy()
|
void Segment::destroy()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_BUILD
|
#ifdef DEBUG_BUILD
|
||||||
@@ -414,8 +383,6 @@ namespace pxt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RefCollection::getAt(int i)
|
uint32_t RefCollection::getAt(int i)
|
||||||
{
|
|
||||||
if (head.isValidIndex(i))
|
|
||||||
{
|
{
|
||||||
uint32_t tmp = head.get(i);
|
uint32_t tmp = head.get(i);
|
||||||
if (isRef())
|
if (isRef())
|
||||||
@@ -424,20 +391,9 @@ namespace pxt {
|
|||||||
}
|
}
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t RefCollection::removeAt(int i)
|
uint32_t RefCollection::removeAt(int i)
|
||||||
{
|
{
|
||||||
if (!head.isValidIndex((uint32_t)i))
|
|
||||||
{
|
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (isRef())
|
if (isRef())
|
||||||
{
|
{
|
||||||
decr(head.get(i));
|
decr(head.get(i));
|
||||||
@@ -446,8 +402,6 @@ namespace pxt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RefCollection::insertAt(int i, uint32_t value)
|
void RefCollection::insertAt(int i, uint32_t value)
|
||||||
{
|
|
||||||
if (i < length())
|
|
||||||
{
|
{
|
||||||
head.insert(i, value);
|
head.insert(i, value);
|
||||||
if (isRef())
|
if (isRef())
|
||||||
@@ -455,11 +409,6 @@ namespace pxt {
|
|||||||
incr(value);
|
incr(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RefCollection::setAt(int i, uint32_t value)
|
void RefCollection::setAt(int i, uint32_t value)
|
||||||
{
|
{
|
||||||
@@ -480,26 +429,31 @@ namespace pxt {
|
|||||||
{
|
{
|
||||||
StringData *xx = (StringData*)x;
|
StringData *xx = (StringData*)x;
|
||||||
uint32_t i = start;
|
uint32_t i = start;
|
||||||
while(head.getNextValidIndex(start, &i))
|
while(head.isValidIndex(i))
|
||||||
{
|
{
|
||||||
StringData *ee = (StringData*)head.get(i);
|
StringData *ee = (StringData*)head.get(i);
|
||||||
if (xx->len == ee->len && memcmp(xx->data, ee->data, xx->len) == 0)
|
if (ee == xx)
|
||||||
|
{
|
||||||
|
//handles ee being null
|
||||||
|
return (int) i;
|
||||||
|
}
|
||||||
|
if (ee && xx->len == ee->len && memcmp(xx->data, ee->data, xx->len) == 0)
|
||||||
{
|
{
|
||||||
return (int)i;
|
return (int)i;
|
||||||
}
|
}
|
||||||
start = i;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32_t i = start;
|
uint32_t i = start;
|
||||||
while(head.getNextValidIndex(start, &i))
|
while(head.isValidIndex(i))
|
||||||
{
|
{
|
||||||
if (head.get(i) == x)
|
if (head.get(i) == x)
|
||||||
{
|
{
|
||||||
return (int)i;
|
return (int)i;
|
||||||
}
|
}
|
||||||
start = i;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,12 +504,9 @@ namespace pxt {
|
|||||||
{
|
{
|
||||||
if (this->isRef())
|
if (this->isRef())
|
||||||
{
|
{
|
||||||
uint32_t start = 0;
|
for(uint32_t i = 0; i < this->head.getLength(); i++)
|
||||||
uint32_t i = 0;
|
|
||||||
while(head.getNextValidIndex(start, &i))
|
|
||||||
{
|
{
|
||||||
decr(this->head.get(i));
|
decr(this->head.get(i));
|
||||||
start = i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->head.destroy();
|
this->head.destroy();
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ namespace pxt {
|
|||||||
ERR_OUT_OF_BOUNDS = 8,
|
ERR_OUT_OF_BOUNDS = 8,
|
||||||
ERR_REF_DELETED = 7,
|
ERR_REF_DELETED = 7,
|
||||||
ERR_SIZE = 9,
|
ERR_SIZE = 9,
|
||||||
ERR_MISSING_VALUE = 10,
|
|
||||||
} ERROR;
|
} ERROR;
|
||||||
|
|
||||||
extern const uint32_t functionsAndBytecode[];
|
extern const uint32_t functionsAndBytecode[];
|
||||||
@@ -175,7 +174,7 @@ namespace pxt {
|
|||||||
uint16_t size;
|
uint16_t size;
|
||||||
|
|
||||||
static const uint16_t MaxSize = 0xFFFF;
|
static const uint16_t MaxSize = 0xFFFF;
|
||||||
static const uint32_t MissingValue = 0x80000000;
|
static const uint32_t DefaultValue = 0x0;
|
||||||
|
|
||||||
static uint16_t growthFactor(uint16_t size);
|
static uint16_t growthFactor(uint16_t size);
|
||||||
void growByMin(uint16_t minSize);
|
void growByMin(uint16_t minSize);
|
||||||
@@ -197,10 +196,6 @@ namespace pxt {
|
|||||||
uint32_t remove(uint32_t i);
|
uint32_t remove(uint32_t i);
|
||||||
void insert(uint32_t i, uint32_t value);
|
void insert(uint32_t i, uint32_t value);
|
||||||
|
|
||||||
//Returns true if there is a valid index greater than or equal to 'i', returns false otherwise
|
|
||||||
//If 'i' is valid returns it in 'result', if not tries to find the next valid
|
|
||||||
//index < length which is valid.
|
|
||||||
bool getNextValidIndex(uint32_t i, uint32_t *result);
|
|
||||||
bool isValidIndex(uint32_t i);
|
bool isValidIndex(uint32_t i);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|||||||
@@ -51,24 +51,27 @@ namespace serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a line of text from the serial port.
|
* Reads the buffered received data as a string
|
||||||
*/
|
*/
|
||||||
//% help=serial/read-line
|
//% blockId=serial_read_buffer block="serial|read string"
|
||||||
//% blockId=serial_read_line block="serial|read line"
|
//% weight=18
|
||||||
//% weight=20 blockGap=8
|
StringData* readString() {
|
||||||
StringData* readLine() {
|
int n = uBit.serial.getRxBufferSize();
|
||||||
return readUntil(ManagedString("\n").leakData());
|
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
|
* Registers an event to be fired when one of the delimiter is matched.
|
||||||
* @param delimiters the characters to match received characters against. eg:"\n"
|
* @param delimiters the characters to match received characters against.
|
||||||
*/
|
*/
|
||||||
// help=serial/on-data-received
|
//% help=serial/on-data-received
|
||||||
// weight=18
|
//% weight=18 blockId=serial_on_data_received block="serial|on data received %delimiters=serial_delimiter_conv"
|
||||||
void onDataReceived(StringData* delimiters, Action body) {
|
void onDataReceived(StringData* delimiters, Action body) {
|
||||||
uBit.serial.eventOn(ManagedString(delimiters));
|
uBit.serial.eventOn(ManagedString(delimiters));
|
||||||
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
|
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
|
* Reads a line of text from the serial port.
|
||||||
*/
|
*/
|
||||||
// help=serial/on-line-received
|
//% help=serial/read-line
|
||||||
// blockId=serial_on_line_received block="serial on line received"
|
//% blockId=serial_read_line block="serial|read line"
|
||||||
// weight=21 blockGap=8
|
//% weight=20 blockGap=8
|
||||||
export function onLineReceived(body: Action): void {
|
export function readLine(): string {
|
||||||
// serial.onDataReceived("\n", body);
|
return serial.readUntil(delimiters(Delimiters.NewLine));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the delimiter corresponding string
|
* Returns the delimiter corresponding string
|
||||||
*/
|
*/
|
||||||
//% blockId="serial_delimiter_conv" block="%del"
|
//% blockId="serial_delimiter_conv" block="%del"
|
||||||
//% weight=1
|
//% weight=1 blockHidden=true
|
||||||
export function delimiters(del: Delimiters): string {
|
export function delimiters(del: Delimiters): string {
|
||||||
// even though it might not look like, this is more
|
// even though it might not look like, this is more
|
||||||
// (memory) efficient than the C++ implementation, because the
|
// (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;
|
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_buffer block="serial|read string"
|
||||||
//% blockId=serial_read_line block="serial|read line"
|
//% weight=18 shim=serial::readString
|
||||||
//% weight=20 blockGap=8 shim=serial::readLine
|
function readString(): string;
|
||||||
function readLine(): 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.
|
* Sends a piece of text through Serial connection.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.7.19",
|
"version": "0.7.34",
|
||||||
"description": "micro:bit target for PXT",
|
"description": "micro:bit target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@@ -21,10 +21,12 @@
|
|||||||
"built/*.json",
|
"built/*.json",
|
||||||
"built/*.d.ts",
|
"built/*.d.ts",
|
||||||
"built/hexcache",
|
"built/hexcache",
|
||||||
|
"built/web",
|
||||||
"sim/public",
|
"sim/public",
|
||||||
"docs/*.md",
|
"docs/*.md",
|
||||||
"docs/*/*.md",
|
"docs/*/*.md",
|
||||||
"docs/*/*/*.md"
|
"docs/*/*/*.md",
|
||||||
|
"docs/static/icons/favicon.ico"
|
||||||
],
|
],
|
||||||
"main": "built/pxtrequire.js",
|
"main": "built/pxtrequire.js",
|
||||||
"typings": "built/pxtrequire.d.ts",
|
"typings": "built/pxtrequire.d.ts",
|
||||||
@@ -34,6 +36,6 @@
|
|||||||
"semantic-ui-less": "^2.2.4"
|
"semantic-ui-less": "^2.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-core": "0.8.7"
|
"pxt-core": "0.10.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,8 @@
|
|||||||
"logicBlocks": true,
|
"logicBlocks": true,
|
||||||
"variablesBlocks": true,
|
"variablesBlocks": true,
|
||||||
"onStartColor": "#0078D7",
|
"onStartColor": "#0078D7",
|
||||||
"onStartNamespace": "basic"
|
"onStartNamespace": "basic",
|
||||||
|
"onStartWeight": 54
|
||||||
},
|
},
|
||||||
"simulator": {
|
"simulator": {
|
||||||
"autoRun": true,
|
"autoRun": true,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace pxsim {
|
|||||||
radioState: RadioState;
|
radioState: RadioState;
|
||||||
// TODO: not singletons
|
// TODO: not singletons
|
||||||
neopixelState: NeoPixelState;
|
neopixelState: NeoPixelState;
|
||||||
servosState: MicroServosState;
|
|
||||||
fileSystem: FileSystemState;
|
fileSystem: FileSystemState;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -53,7 +52,13 @@ namespace pxsim {
|
|||||||
0,
|
0,
|
||||||
DAL.MICROBIT_ID_IO_P19,
|
DAL.MICROBIT_ID_IO_P19,
|
||||||
DAL.MICROBIT_ID_IO_P20
|
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["radio"] = this.radioState = new RadioState(runtime);
|
||||||
this.builtinParts["accelerometer"] = this.accelerometerState = new AccelerometerState(runtime);
|
this.builtinParts["accelerometer"] = this.accelerometerState = new AccelerometerState(runtime);
|
||||||
@@ -62,12 +67,7 @@ namespace pxsim {
|
|||||||
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
||||||
this.builtinParts["compass"] = this.compassState = new CompassState();
|
this.builtinParts["compass"] = this.compassState = new CompassState();
|
||||||
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
||||||
this.builtinParts["microservo"] = this.servosState = new MicroServosState({
|
this.builtinParts["microservo"] = this.edgeConnectorState;
|
||||||
"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.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
||||||
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
||||||
|
|||||||
@@ -76,8 +76,7 @@ namespace pxsim.pins {
|
|||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
|
|
||||||
analogSetPeriod(pinId, 20000);
|
analogSetPeriod(pinId, 20000);
|
||||||
const state = board().servosState.servoState(pinId);
|
pin.servoAngle = value;
|
||||||
state.setAngle(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function servoSetPulse(pinId: number, micros: number) {
|
export function servoSetPulse(pinId: number, micros: number) {
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public shiftRight(cols: number) {
|
public shiftRight(cols: number) {
|
||||||
for (let x = this.width - 1; x <= 0; --x)
|
for (let x = this.width - 1; x >= 0; --x)
|
||||||
for (let y = 0; y < 5; ++y)
|
for (let y = 0; y < 5; ++y)
|
||||||
this.set(x, y, x > cols ? this.get(x - cols, y) : 0);
|
this.set(x, y, x >= cols ? this.get(x - cols, y) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public clear(): void {
|
public clear(): void {
|
||||||
@@ -195,11 +195,16 @@ namespace pxsim.ImageMethods {
|
|||||||
board().ledMatrixState.animationQ.enqueue({
|
board().ledMatrixState.animationQ.enqueue({
|
||||||
interval: interval,
|
interval: interval,
|
||||||
frame: () => {
|
frame: () => {
|
||||||
//TODO: support right to left.
|
|
||||||
if (off >= leds.width || off < 0) return false;
|
if (off >= leds.width || off < 0) return false;
|
||||||
stride > 0 ? display.shiftLeft(stride) : display.shiftRight(-stride);
|
if (stride > 0) {
|
||||||
let c = Math.min(stride, leds.width - off);
|
display.shiftLeft(stride);
|
||||||
|
const c = Math.min(stride, leds.width - off);
|
||||||
leds.copyTo(off, c, display, 5 - stride)
|
leds.copyTo(off, c, display, 5 - stride)
|
||||||
|
} else {
|
||||||
|
display.shiftRight(-stride);
|
||||||
|
const c = Math.min(-stride, leds.width - off);
|
||||||
|
leds.copyTo(off, c, display, 0)
|
||||||
|
}
|
||||||
off += stride;
|
off += stride;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -223,7 +228,7 @@ namespace pxsim.basic {
|
|||||||
clearScreen();
|
clearScreen();
|
||||||
pause(interval * 5);
|
pause(interval * 5);
|
||||||
} else {
|
} 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);
|
else ImageMethods.scrollImage(createImageFromString(s + " "), 1, interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,18 +35,14 @@ namespace pxsim.serial {
|
|||||||
board().writeSerial(s);
|
board().writeSerial(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readUntil(del: string): string {
|
||||||
|
return readString();
|
||||||
|
}
|
||||||
|
|
||||||
export function readString(): string {
|
export function readString(): string {
|
||||||
return board().serialState.readSerial();
|
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) {
|
export function onDataReceived(delimiters: string, handler: RefAction) {
|
||||||
let b = board();
|
let b = board();
|
||||||
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);
|
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
@red: #EF767A;
|
@red: #EF767A;
|
||||||
@pink: #F46197;
|
@pink: #F46197;
|
||||||
@yellow: #FDE74C;
|
@yellow: #FDE74C;
|
||||||
|
@grey:#95a5a6;
|
||||||
|
|
||||||
/* Microbit.org colors */
|
/* Microbit.org colors */
|
||||||
@orange: #ff8b27;
|
@orange: #ff8b27;
|
||||||
@@ -35,9 +36,6 @@
|
|||||||
@mainMenuInvertedBackground: @blue;
|
@mainMenuInvertedBackground: @blue;
|
||||||
@mainMenuTutorialBackground: @orange;
|
@mainMenuTutorialBackground: @orange;
|
||||||
|
|
||||||
@mainMenuHeight: 5rem;
|
|
||||||
@mobileMenuHeight: 4.4rem;
|
|
||||||
|
|
||||||
@mainMenuBlocksJsToggleColor: @primaryColor;
|
@mainMenuBlocksJsToggleColor: @primaryColor;
|
||||||
|
|
||||||
@tutorialSelectedMenuColor: @blue;
|
@tutorialSelectedMenuColor: @blue;
|
||||||
@@ -55,6 +53,7 @@
|
|||||||
--------------------*/
|
--------------------*/
|
||||||
|
|
||||||
@simulatorBackground: #FDFDFF;
|
@simulatorBackground: #FDFDFF;
|
||||||
|
@editorToolsBackground: @simulatorBackground;
|
||||||
@blocklySvgColor: #ecf0f1;
|
@blocklySvgColor: #ecf0f1;
|
||||||
|
|
||||||
/*-------------------
|
/*-------------------
|
||||||
|
|||||||
@@ -12,16 +12,11 @@
|
|||||||
Add your custom CSS here
|
Add your custom CSS here
|
||||||
*******************************/
|
*******************************/
|
||||||
|
|
||||||
.download-button {
|
.ui.button.download-button {
|
||||||
&:extend(.ui.button all);
|
|
||||||
&:extend(.purple all);
|
&:extend(.purple all);
|
||||||
}
|
}
|
||||||
|
|
||||||
.download-button.download-button-full {
|
.ui.button.download-button:hover {
|
||||||
&:extend(.ui.inverted.purple.button all);
|
|
||||||
}
|
|
||||||
|
|
||||||
.download-button:hover {
|
|
||||||
&:extend(.green all);
|
&:extend(.green all);
|
||||||
color: black !important;
|
color: black !important;
|
||||||
}
|
}
|
||||||
@@ -30,15 +25,22 @@
|
|||||||
&:extend(.ui.inverted.button all);
|
&:extend(.ui.inverted.button all);
|
||||||
}
|
}
|
||||||
|
|
||||||
.getting-started-btn {
|
.ui.button.getting-started-btn {
|
||||||
&:extend(.ui.button all);
|
|
||||||
&:extend(.orange all);
|
&:extend(.orange all);
|
||||||
}
|
}
|
||||||
|
|
||||||
#filelist {
|
.ui.button.editortools-btn {
|
||||||
|
&:extend(.blue all);
|
||||||
|
}
|
||||||
|
|
||||||
|
#filelist, #editortools {
|
||||||
background: #fff url(https://az742082.vo.msecnd.net/pub/psopafpj) 0 0 repeat !important;
|
background: #fff url(https://az742082.vo.msecnd.net/pub/psopafpj) 0 0 repeat !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#downloadArea {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
Blockly
|
Blockly
|
||||||
*******************************/
|
*******************************/
|
||||||
@@ -62,12 +64,11 @@
|
|||||||
.blocklyToolboxDiv, .monacoToolboxDiv {
|
.blocklyToolboxDiv, .monacoToolboxDiv {
|
||||||
background-color: white !important;
|
background-color: white !important;
|
||||||
border-left: 1px solid #ecf0f1 !important;
|
border-left: 1px solid #ecf0f1 !important;
|
||||||
box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.12), 0px 2px 2px 0px rgba(0,0,0,0.24);
|
box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.12), 0px 0px 2px 0px rgba(0,0,0,0.24);
|
||||||
}
|
}
|
||||||
|
|
||||||
.blocklyFlyoutBackground {
|
.blocklyFlyoutBackground {
|
||||||
fill: #525A67 !important;
|
fill: #525A67 !important;
|
||||||
fill-opacity: 0.5 !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove shadow around blockly blocks */
|
/* Remove shadow around blockly blocks */
|
||||||
@@ -80,14 +81,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Blockly Toolbox Buttons */
|
/* Blockly Toolbox Buttons */
|
||||||
.blocklyToolboxButtons .blocklyAddPackageButton {
|
.ui.button.blocklyAddPackageButton {
|
||||||
&:extend(.ui.inverted.pink.button all);
|
&:extend(.pink all);
|
||||||
&:extend(.ui.circular.button all);
|
|
||||||
}
|
|
||||||
|
|
||||||
.blocklyToolboxButtons .blocklyUndoButton {
|
|
||||||
&:extend(.ui.inverted.blue.button all);
|
|
||||||
&:extend(.ui.circular.button all);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
@@ -121,6 +116,9 @@
|
|||||||
|
|
||||||
/* Tablet */
|
/* Tablet */
|
||||||
@media only screen and (min-width: @tabletBreakpoint) and (max-width: @largestTabletScreen) {
|
@media only screen and (min-width: @tabletBreakpoint) and (max-width: @largestTabletScreen) {
|
||||||
|
#filelist {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Small Monitor */
|
/* Small Monitor */
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
@input : 'pxt';
|
@input : 'pxt';
|
||||||
@label : 'pxt';
|
@label : 'pxt';
|
||||||
@list : 'pxt';
|
@list : 'pxt';
|
||||||
@loader : 'pulsar';
|
@loader : 'pxt';
|
||||||
@rail : 'pxt';
|
@rail : 'pxt';
|
||||||
@reveal : 'pxt';
|
@reveal : 'pxt';
|
||||||
@segment : 'pxt';
|
@segment : 'pxt';
|
||||||
|
|||||||
Reference in New Issue
Block a user