Compare commits

...

64 Commits

Author SHA1 Message Date
9c5c699fe7 0.7.17 2017-01-05 13:31:30 -08:00
dcede1703a fixing link 2017-01-05 13:31:05 -08:00
5d33ab019d 0.7.16 2017-01-05 13:30:30 -08:00
f7ec452ea0 updated steps 2017-01-05 13:30:14 -08:00
20260e8933 fixes to docs 2017-01-05 13:28:06 -08:00
d7704934e8 0.7.15 2017-01-05 13:17:24 -08:00
f1eafb0a6e Bump pxt-core to 0.8.5 2017-01-05 13:17:21 -08:00
27d6a8281a Inchworm (#331)
* images for inchworm project

* binding pictures

* updated inchworm lesson
2017-01-05 10:00:36 -08:00
a59394646c fixed docs 2017-01-05 07:37:46 -08:00
6851169dbe 0.7.14 2017-01-05 07:10:13 -08:00
36b3486194 Bump pxt-core to 0.8.3 2017-01-05 07:10:12 -08:00
5d8ccd1d6d adding namespace to api categories (#330)
* adding namespace to api categories

* add icon for led

* adding icons for control, game, images, pins and serial.
2017-01-05 07:01:50 -08:00
c713fe9bf4 0.7.13 2017-01-04 13:08:54 -08:00
f682e5e694 insertAt support for array (#328)
* Adding insertAt and setLength to array

* implemented review comments

* Bump pxt-core to 0.8.2
2017-01-04 13:07:58 -08:00
93d90a2bde Few extra typing fixes. 2017-01-03 12:14:25 -08:00
a54504f31c Updating bluebird typings path 2017-01-03 11:38:21 -08:00
a7adf0e6c6 minor ui fixes 2017-01-02 15:09:49 -08:00
9965f169b2 0.7.12 2016-12-31 07:28:12 -08:00
8bf755c15c fixing eddystone uid encoding 2016-12-31 07:25:27 -08:00
d0b2a7db62 0.7.11 2016-12-31 06:49:30 -08:00
780192da3b Bump pxt-core to 0.7.13 2016-12-31 06:49:28 -08:00
07c1f08d18 fix for Microsoft/pxt#1014 2016-12-31 06:36:05 -08:00
25ac847266 converging with other targets on blockly toolbox width 2016-12-31 02:51:24 -08:00
63c8342b86 ui changes accompanying pxt mobile ui fixes 2016-12-31 01:43:45 -08:00
ea2bd7ba10 Merge pull request #326 from Microsoft/array
Array enhancements
2016-12-30 15:09:16 -08:00
cec2d1e8af 0.7.10 2016-12-30 15:05:31 -08:00
1b289b688b Bump pxt-core to 0.7.12 2016-12-30 15:05:28 -08:00
0cf91580cb Merge pull request #327 from Microsoft/pr/toggletheming
Blocks / JS menu toggle theming
2016-12-30 15:00:32 -08:00
392ebc8d07 0.7.9 2016-12-30 14:18:06 -08:00
9068aab12b Bump pxt-core to 0.7.11 2016-12-30 14:18:03 -08:00
85327a4e69 0.7.8 2016-12-30 13:50:03 -08:00
021260b3a4 Bump pxt-core to 0.7.10 2016-12-30 13:50:00 -08:00
4def93d7c5 Blocks / JS menu toggle theming 2016-12-30 13:07:16 -08:00
9aca0c19fc Merge branch 'master' into array 2016-12-23 19:53:06 -08:00
3fcbdbdd82 Array reimplementation as single segment with support for missing values 2016-12-23 19:49:15 -08:00
4b7b6eebca 0.7.7 2016-12-23 08:59:08 -08:00
2da0cf1178 support for buffer signature (#325) 2016-12-23 08:58:38 -08:00
141cb24e3d 0.7.6 2016-12-22 23:18:35 -08:00
35483487af Bump pxt-core to 0.7.9 2016-12-22 23:18:32 -08:00
ec3a805326 0.7.5 2016-12-22 11:35:58 -08:00
780d8bcf8d Bump pxt-core to 0.7.6 2016-12-22 11:35:56 -08:00
f9a12cac64 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-12-22 11:32:01 -08:00
03c2df3277 fixed default projects 2016-12-22 11:31:50 -08:00
a7e98ccb3d Change default product names for Electron app; Add release manifest 2016-12-21 12:31:00 -08:00
1014d2f361 0.7.4 2016-12-20 16:30:14 -08:00
89f20a64d5 Bump pxt-core to 0.7.5 2016-12-20 16:30:12 -08:00
fae36a74af 0.7.3 2016-12-20 13:06:13 -08:00
7e57c59b6f Bump pxt-core to 0.7.4 2016-12-20 13:06:09 -08:00
3141e12f4c support for 8G gestures 2016-12-20 13:05:06 -08:00
4ebe9f595a fix for Microsoft/pxt#961 2016-12-20 12:38:00 -08:00
50f0e85884 docs updates 2016-12-20 12:31:25 -08:00
e28b5d48d4 0.7.2 2016-12-19 16:08:31 -08:00
562e96e09e Bump pxt-core to 0.7.2 2016-12-19 16:08:21 -08:00
6c5088f811 update LESS variables 2016-12-19 16:08:01 -08:00
d5ccb7ad02 0.7.1 2016-12-19 14:11:17 -08:00
ade5176d21 upgraded to 0.7 2016-12-19 14:10:57 -08:00
d2f6d51c19 0.6.46 2016-12-19 14:10:12 -08:00
92b60a251d On start support (#324)
* annotating APIs to support onstart

* missed file

* updated templates

* adding new lines in main.ts

* fixing docs

* removing onstart

* updated docs

* updated various docs

* more docs

* adding upgrade policies for blocks

* updated pxt reference

* placing on start under "basic"
2016-12-19 14:09:35 -08:00
de9f2d7e67 More appropriate Electron app bundle ID on Mac OS 2016-12-19 07:59:52 -08:00
4de5e3bd11 0.6.45 2016-12-18 20:57:52 -08:00
86a33e8f65 Bump pxt-core to 0.6.7 2016-12-18 20:57:50 -08:00
89010b6a8a 0.6.44 2016-12-16 20:26:41 -08:00
48d4668a7a Bump pxt-core to 0.6.6 2016-12-16 20:26:39 -08:00
a2755dc4d2 annotate apis to support multiple forever blocks 2016-12-16 16:47:36 -08:00
90 changed files with 1201 additions and 444 deletions

2
.gitignore vendored
View File

@ -15,7 +15,7 @@ clients/win10/app/bld
clients/win10/*.opendb
clients/**/bin/**
clients/**/obj/**
clients/electron/projects
electron-out
hexcache
*.user

View File

@ -1,4 +1,4 @@
/// <reference path="../node_modules/pxt-core/typings/node/node.d.ts"/>
/// <reference path="../node_modules/pxt-core/typings/globals/node/index.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
import * as path from "path";

View File

@ -11,4 +11,4 @@ Math.random(5);
## See Also
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables)
[logic](/blocks/logic), [loops](/blocks/loops), [math](/blocks/math), [variables](/blocks/variables), [on-start](/blocks/on-start)

View File

@ -86,12 +86,14 @@ if (led.point(1,1) && led.point(2,2)) {
When you compare two Numbers, you get a Boolean value, such as the comparison `x < 5` in the code below:
```blocks
let x = Math.random(5)
if(x < 5) {
basic.showString("low");
} else {
basic.showString("high");
}
input.onButtonPressed(Button.A, () => {
let x = Math.random(5)
if(x < 5) {
basic.showString("low");
} else {
basic.showString("high");
}
})
```
See the documentation on [Numbers](/reference/types/number) for more information on comparing two Numbers. You can also [compare strings](/reference/types/string-functions) using the `equals` function.

View File

@ -14,13 +14,15 @@ Click on the dark blue gear icon (see above) to add an *else* or *if* to the cur
### Example: adjusting screen brightness
```blocks
if(input.lightLevel()<100){
led.setBrightness(255);
}
```
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255` when the button A is pressed:
If the [light level](/reference/input/light-level) is `< 100`, this code sets the brightness to `255`:
```blocks
input.onButtonPressed(Button.A, () => {
if(input.lightLevel()<100){
led.setBrightness(255);
}
})
```
### See also

View File

@ -4,14 +4,21 @@
Run part of the program the number of times you say.
```block
for(let i = 0; i <= 4; ++i) {
}
```
### Example: Count to 4
This program will show the numbers 0, 1, 2, 3, and 4 one after another on the LED screen.
```blocks
for(let i = 0; i < 5; ++i) {
basic.showNumber(i)
}
input.onButtonPressed(Button.A, () => {
for(let i = 0; i < 5; ++i) {
basic.showNumber(i)
}
})
```
### See also

View File

@ -2,7 +2,7 @@
Repeat code while a [Boolean](/blocks/logic/boolean) `condition` is true.
```blocks
```block
while(true) {
}
```
@ -16,11 +16,13 @@ The condition is tested before any code runs. Which means that if the condition
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
```blocks
let index = 4;
while(index >= 0) {
led.plot(index, index);
index--;
}
input.onButtonPressed(Button.A, () => {
let index = 4;
while(index >= 0) {
led.plot(index, index);
index--;
}
})
```
### See also

22
docs/blocks/on-start.md Normal file
View File

@ -0,0 +1,22 @@
# On Start
An event that runs when the program starts.
The ``on start`` is a special event that runs when the program starts, before any other event.
Use this event to initialize your program.
## Example
In this example, ``on start`` sets a dimmer brightness on the screen and the button handler shows a string.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showString("Hello!")
})
led.setBrightness(50)
```
## What about JavaScript?
``on-start`` only exists in the block editor. In JavaScript, all code executes sequentially from the first line.

View File

@ -33,7 +33,7 @@ basic.forever(() => {
When this program runs, you will see a smiley face, then a blank
screen, then a smiley again -- it never stops! (That's because of the
``forever`` block.)
`[basic.forever(() => {})]` block.)
Click **Download** to move your program to the @boardname@!
Make sure to follow the instructions.

View File

@ -17,7 +17,7 @@ input.onButtonPressed(Button.A, () => {
#### ~hint
The ``showString`` block can show letters, numbers, and punctuation
The `[basic.showString("HI")]` block can show letters, numbers, and punctuation
on the @boardname@ screen.
#### ~
@ -33,7 +33,7 @@ input.onButtonPressed(Button.B, () => {
#### ~hint
You can find the letter `B` by clicking the letter `A` on the
``onButtonPressed`` block.
`[input.onButtonPressed(Button.A, () => {})]` block.
#### ~

View File

@ -23,8 +23,8 @@ input.onButtonPressed(Button.B, () => {
```
### ~hint
The ``pick random true or false`` block randomly tells the ``if``
block `true` or `false`. If the ``pick`` block picked `true`, the
The `[Math.randomBoolean()]` block randomly tells the ``if``
block `true` or `false`. If value picked is `true`, the
``if`` block shows the letter `H`. Otherwise, it shows the letter `T`.
That's it!

View File

@ -9,7 +9,7 @@ There are 25 bright LEDs on the @boardname@ screen. Let's use them to create som
### Happy unhappy face
Draw an unhappy face instead of the blank screen. Click on the dots
in the second ``show leds`` block until it matches the blocks below.
in the second `[basic.showLeds("")]` block until it matches the blocks below.
Now you have an **animation** (cartoon) that shows a happy face,
then an unhappy one, then a happy one again, forever (or until
you turn off your @boardname@)!
@ -36,7 +36,7 @@ Click **Download** to move your program to the @boardname@!
### Your turn!
Pile up more ``show leds`` blocks to create an animation! Create an
Pile up more `[basic.showLeds("")]` blocks to create an animation! Create an
animation with at least 5 pictures. What does this animation show?
```blocks
@ -87,12 +87,6 @@ basic.forever(() => {
```
Click **Download** to move your program to the @boardname@!
#### ~hint
You can find the ``show leds`` block in the **Basic** part of the editor.
#### ~
### ~button /getting-started/buttons
NEXT: BUTTONS
### ~

View File

@ -66,6 +66,10 @@ Fun games to build with your @boardname@.
```codecard
[{
"name": "Inchworm",
"url":"/projects/inchworm",
"imageUrl":"/static/mb/projects/inchworm.jpg"
}, {
"name": "Timing gates",
"url":"/projects/timing-gates",
"imageUrl":"/static/mb/projects/timing-gates.jpg"

View File

@ -10,7 +10,9 @@ Let's start by adding a variable where you can store data. Then rename the varia
```blocks
let light = input.lightLevel();
input.onButtonPressed(Button.A, () => {
let light = input.lightLevel();
});
```
We want to play music on button pressed in order to register an event handler that will execute whenever when you run a script and click on button pressed on the simulator. We must start by opening the Input drawer and adding `on button pressed` A. Then add a block `rest` to plays nothing for a `1/16` beat. Modify your code so that your code looks like this.

40
docs/projects/inchworm.md Normal file
View File

@ -0,0 +1,40 @@
# Inchworm
### @description A inchworm like robot built with the micro:bit
### ~avatar avatar
Make a funny inchworm robot!
### ~
https://youtu.be/BiZLjugXMbM
## Duration
3 Activities, approx 30-45 min each based on familiarity with the coding concepts
## Materials
* Cardboard pieces (recycle!)
* Glue gun or Tape (masking, duct tape, and/or packing tape)
* Scissors that can cut cardboard
* 1 @boardname@, battery holder and 2 AAA batteries
* 3 Crocodile clips
* 1 micro servo 9g SG90
* 1 paper clip
![Materials](/static/mb/projects/inchworm/materials.jpg)
## Activities
* [Servo](/projects/inchworm/servo)
* [Chassis](/projects/inchworm/chassis)
* [Code](/projects/inchworm/code)
### ~button /projects/inchworm/servo
Let's get started!
### ~

View File

@ -0,0 +1,88 @@
# Chassis
### @description Building the cardboard inchworm
### ~avatar avatar
Turn a piece of cardboard into an inchworm!
### ~
## Duration: ~45 minutes
## Materials
* Cardboard
* Scissors or cutters
* glue gun or tape
* 1 paper clip
## Step 1: cardboard
Cutout a cardboard rectangle. You can use the @boardname@ as a ruler to figure out the size.
![](/static/mb/projects/inchworm/chassis1.jpg)
## Step 2: center fold
Fold the cardboard in half over the short edge.
![](/static/mb/projects/inchworm/chassis2.jpg)
## Step 3: legs
Fold each end so they rest flat on the ground.
![](/static/mb/projects/inchworm/chassis3.jpg)
## Step 4: front teeth
Fold each corners on one end of the cardbard. This will be the front of the inchworm which is supposed to grip the ground.
![](/static/mb/projects/inchworm/chassis4.jpg)
## Step 5: back teeth
Using a scissor or a cutter (watch the fingers!), cut out various strips in the other edge. Fold one after the other.
![](/static/mb/projects/inchworm/chassis5.jpg)
## Step 6: mounting the board
Using tape or a glue gun, mount the @boardname@ on one side and the microservo on the cardobard.
![](/static/mb/projects/inchworm/chassis6.jpg)
## Step 7: mounting the servo
Attach the servo on the **edge** of the other cardboard side.
![](/static/mb/projects/inchworm/chassis7.jpg)
## Step 8: Cable clean up (optional)
Use tape to route the cables nicely on the inchworm.
![](/static/mb/projects/inchworm/chassis8.jpg)
## Step 9: attaching paper clip to servo
Unfold a paper clip and attach it to the servo arm.
![](/static/mb/projects/inchworm/clip2.jpg)
## Step 10: attaching paper clip to cardboard
Slide the folder paper clip into the cardboard, and use tape to secure it.
You might need to toy around with the size of the clip so that the servo rotation opens the inchworm sufficiently.
![](/static/mb/projects/inchworm/clip3.jpg)
## Step 11: it's ready!
Your inchworm is ready!
![](/static/mb/projects/inchworm/ready.jpg)
### ~button /projects/inchworm/code
NEXT: Code
### ~

View File

@ -0,0 +1,48 @@
# Code
### @description code to make the inchworm alive
### ~avatar avatar
Add code to make the inchworm move.
### ~
## Duration: ~30 minutes
## Step 1: walk forever
In order for the inchworm to move, the @boardname@ needs to command the servo to go between ``0`` and ``180`` degrees
at a certain pace. In the code below, the user pressed button ``A`` to launch the inchworm.
```blocks
input.onButtonPressed(Button.A, () => {
pins.servoWritePin(AnalogPin.P0, 0)
basic.pause(500)
pins.servoWritePin(AnalogPin.P0, 180)
basic.pause(500)
});
```
### ~ hint
You may have noticed that the inchworm can be rather slow or simply won't move. Try to improve the design of your legs, teeth
so that the inchworm goes as fast as possible. Trying it on carpet also great helps avoiding skidding.
### ~
## Step 2: radio controlled inchworm
You will need 2 @boardname@ for this part. By using the radio, we can make the inchworm controlled by another @boardname@.
Download the code below to the @boardname@ on the inchworm and another "controller" @boardname@. Whenere A is pressed, the inchworm will move once.
```blocks
radio.onDataPacketReceived(({receivedNumber}) => {
pins.servoWritePin(AnalogPin.P0, 0)
basic.pause(500)
pins.servoWritePin(AnalogPin.P0, 180)
basic.pause(500)
})
input.onButtonPressed(Button.A, () => {
radio.sendNumber(0)
})
```

View File

@ -0,0 +1,130 @@
# Preparing the servo
### @description Connecting the servo to crocodile clips
### ~avatar avatar
Equip the microservo with crocodile clips.
### ~
## Duration: ~30 minutes
## Materials
* Cutting pliers or wire cutter
* Tape (masking, duct tape, and/or packing tape)
* 3 crocodile clips, yellow, red and black.
* 1 micro servo 9g (SG90)
## Using a microservo with the @boardname@
The @boardname@ provides just enough current to operate the SG90 microservo.
The servo requires 3 connections: GND, 3V and a logic pin.
In this tutorial, we will equip the servo with crocodile clips to make it easier to use.
However, you could also use a shield or female to crocodile clips to acheive the same effect.
If you are running a class or activity, you should consider preparing all servos before hand.
### ~ hint
Kitronik wrote an excellent in-depth guide about using servos with the @boardname@.
Check it out at https://www.kitronik.co.uk/blog/using-bbc-microbit-control-servo/ .
### ~
## Step 1: cutout the connector
Using the cutting pliers, cut out the dark plastic connector.
![](/static/mb/projects/inchworm/servo1.jpg)
## Step 2: strip out cables
Using the plier or a wire stripper, strip the plastic from the cables.
![](/static/mb/projects/inchworm/servo2.jpg)
## Step 3: threading the servo cablers
Thread the servo cables.
![](/static/mb/projects/inchworm/servo3.jpg)
## Step 4: crocobile clip claps
Cut a crocodile cable in two and strip out the casing.
If possible try to use the same cable colors as the servo!
![](/static/mb/projects/inchworm/servo4.jpg)
## Step 5: thread cables together
Place the cables next to each other
![](/static/mb/projects/inchworm/servo5.jpg)
... and thread them together.
![](/static/mb/projects/inchworm/servo6.jpg)
### ~ hint
It is very **important** to ensure that there is a good connection between the 2 cables.
If the connection is weak, the microservo will not receive enough current and it will not work.
If you have access to a soldering iron, we strongly recommend to solver this connection.
### ~
## Step 4: protect the connection
Protect the connection with electrical or duct tape.
![](/static/mb/projects/inchworm/servo7.jpg)
## Step 5: repeat for all cables
Repeat the same process until all cables are connected.
![](/static/mb/projects/inchworm/servo8.jpg)
## Step 6: testing!
It's time to test that your connection are all proper and that the servo will function **when the @boardname@ is powered by battery**.
* Connect the microservo to the @boardname@. Black cable on ``GND``, red cable on ``3V`` and remaining cable on ``P0``.
![](/static/mb/projects/inchworm/circuit1.jpg)
### ~ hint
When attaching the crocodile clips to the pins, don't hesitate to grab the side of the board with the jaws.
![](/static/mb/projects/inchworm/circuit2.jpg)
### ~
* Download the following code to your @boardname@
```blocks
let a = 0
basic.forever(() => {
a = input.acceleration(Dimension.X)
pins.servoWritePin(AnalogPin.P0, pins.map(
a,
-512,
512,
0,
180
))
})
```
* When powered by USB, make sure that the servo moves when you tilt the board.
* When powered by batteries **only**, make sure that the servo moves when you tilt the board.
If your servo seems to sutter and stay stuck at a particular position, it means that it is not receiving enough power.
This is probably due to a weak connection or low battery level. Check each connection and check your batteries.
### ~button /projects/inchworm/chassis
NEXT: Chassis
### ~

View File

@ -37,7 +37,7 @@ input.onButtonPressed(Button.B, () => {
We will use the @boardname@'s compass to detect the magnet. Compass's tell us what direction we are pointing by detecting the Earth's magnetic field but they can also detect any other magnet nearby. We will use that to check if our magnet is next to the @boardname@ by using the [magnetic force](/reference/input/magnetic-force) block found in the input menu's 'more' section. As we only want to measure the strength we change the drop down to select 'strength':
```blocks
```block
input.magneticForce(Dimension.Strength)
```
@ -50,16 +50,19 @@ If you have ever played with magnets you know they have two ends, often called a
So in the code below we will check if the absolute value of our magnetic field strength reading is more than 100 and save the result of that check in a new variable called 'isSwitched':
```blocks
let isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
let force = Math.abs(input.magneticForce(Dimension.Strength));
let isSwitched = force > 100
```
## Step 4: running our 'magnet nearby' check all the time
At the moment our code to detect the magnet being nearby will only run once so we need to put it into a [forever](/reference/basic/forever) block so that it keeps getting run again and again checking for the magnet to come near to the @boardname@. We should also make sure 'isSwitched' is false when our program starts.
```blocks
let force = 0;
let isSwitched = false;
basic.forever(() => {
let isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
force = Math.abs(input.magneticForce(Dimension.Strength));
isSwitched = force > 100
})
```
@ -68,10 +71,11 @@ basic.forever(() => {
Now we can check the value of our variable 'isSwitched' whenever we want and we will know that the magnet is nearby if it's value is 'true'. Let's use that to change how the buttons work and complete the code for our trick. We will add an 'if, else' block to each button's code and check if we should swap over what each button displays because 'isSwitched' is equal to true:
```blocks
let force = 0;
let isSwitched = false;
basic.forever(() => {
isSwitched = Math.abs(input.magneticForce(Dimension.Strength)) > 100
force = Math.abs(input.magneticForce(Dimension.Strength));
isSwitched = force > 100
})
input.onButtonPressed(Button.A, () => {

View File

@ -18,15 +18,15 @@ and updates the screen with the direction.
basic.forever(() => {
let heading = input.compassHeading()
if (heading < 45) {
basic.showString("N", 100)
basic.showString("N")
} else if (heading < 135) {
basic.showString("E", 100)
basic.showString("E")
}
else if (heading < 225) {
basic.showString("S", 100)
basic.showString("S")
}
else {
basic.showString("W", 100)
basic.showString("W")
}
})
```
@ -40,7 +40,7 @@ You can use a program like this to count things with your @boardname@.
```blocks
let num = 0
basic.forever(() => {
basic.showNumber(num, 150)
basic.showNumber(num)
})
input.onButtonPressed(Button.A, () => {
num = num + 1
@ -56,10 +56,10 @@ Try this on your @boardname@:
```blocks
basic.forever(() => {
basic.showNumber(6789, 150)
basic.showNumber(6789)
})
input.onButtonPressed(Button.A, () => {
basic.showNumber(2, 150)
basic.showNumber(2)
})
```

View File

@ -35,7 +35,8 @@ bluetooth.uartWriteValue("", 0);
## Eddystone
```cards
bluetooth.advertiseUrl("https://pxt.microbit.org/", 7);
bluetooth.advertiseUid(42, 1, 7, true);
bluetooth.advertiseUrl("https://pxt.microbit.org/", 7, true);
bluetooth.stopAdvertising();
```

View File

@ -0,0 +1,37 @@
# Avertise UID Buffer
Advertises a UID via the Eddystone protocol over Bluetooth.
## ~hint
### Eddystone
Bluetooth beacons are used to indicate proximity to a place or object of interest.
Beacons use Bluetooth advertising to broadcast a small amount of data,
which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application.
There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data.
iBeacon is Apple's beacon message format. Eddystone comes from Google.
Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ .
## ~
```sig
bluetooth.advertiseUidBuffer(pins.createBuffer(16), 7, true);
```
### Parameters
* ``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).
* ``connectable`` - a [boolean](/reference/type/boolean) indicating whether or not the micro:bit should accept connections.
## See Also
[stop-advertising](/reference/bluetooth/stop-advertising), [advertise-uid](/reference/bluetooth/advertise-uid)
```package
bluetooth
```

View File

@ -0,0 +1,46 @@
# Avertise UID
Advertises a UID via the Eddystone protocol over Bluetooth.
## ~hint
### Eddystone
Bluetooth beacons are used to indicate proximity to a place or object of interest.
Beacons use Bluetooth advertising to broadcast a small amount of data,
which can be received and acted upon by anyone in range with a suitable device and software, typically a smartphone and application.
There are various beacon message formats, which define the way Bluetooth advertising packets are used as containers for beacon data.
iBeacon is Apple's beacon message format. Eddystone comes from Google.
Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/ .
## ~
```sig
bluetooth.advertiseUid(42, 1, 7, true);
```
### Parameters
* ``namespace`` last 4 bytes of the namespace uid (6 to 9)
* ``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).
* ``connectable`` - a [boolean](/reference/type/boolean) indicating whether or not the micro:bit should accept connections.
## Encoding
The bytes of ``namespace`` and ``instance`` are encoded to generate the 10 bytes UID namespace and 6 bytes UID instance.
```
UID namespace: [0, ..., namespace]
UID instance: [0, ..., instance]
```
## See Also
[stop-advertising](/reference/bluetooth/stop-advertising), [advertise-uid-buffer](/reference/bluetooth/advertise-uid-buffer)
```package
bluetooth
```

View File

@ -25,6 +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.
* ``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.
### Example: Broadcast a secret code
@ -34,7 +35,7 @@ bluetooth.advertiseUrl("https://pxt.io?secret=42", 7, true);
## See Also
[stop-advertising](/reference/bluetooth/stop-advertising)
[stop-advertising](/reference/bluetooth/stop-advertising), [advertise-uid](/reference/bluetooth/advertise-uid)
```package
bluetooth

BIN
docs/static/mb/projects/inchworm.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

View File

@ -1,14 +1,14 @@
{
"applicationName": "pxt-microbit-oss",
"dataFolderName": ".pxt-microbit-oss",
"darwinBundleIdentifier": "com.microsoft.pxtoss",
"nameShort": "PXT Microbit - OSS",
"nameLong": "PXT Microbit - OSS",
"darwinBundleIdentifier": "com.microsoft.pxtmicrobitoss",
"nameShort": "PXT microbit - OSS",
"nameLong": "PXT micro:bit - OSS",
"targetId": "pxt-microbit",
"win32AppId": "{{92db071a-6f58-4938-8c97-13c873f4da13}",
"win32AppUserModelId": "Microsoft.PXTMicrobitOss",
"win32DirName": "Microsoft PXT-Microbit - OSS",
"win32AppUserModelId": "Microsoft.PXTmicrobitOss",
"win32DirName": "Microsoft PXT microbit - OSS",
"win32MutexName": "pxtmicrobitoss",
"win32NameVersion": "Microsoft PXT-Microbit-OSS",
"win32RegValueName": "PXTMicrobitOss"
"win32NameVersion": "Microsoft PXT microbit-OSS",
"win32RegValueName": "PXTmicrobitOss"
}

9
electron/release.json Normal file
View File

@ -0,0 +1,9 @@
{
"versions": {
"0": {
"latest": "v0.6.45",
"banned": [],
"prompt": "v0.0.0"
}
}
}

View File

@ -1,62 +1,3 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="device_forever">
<statement name="HANDLER">
<block type="device_show_leds">
<field name="LED00">FALSE</field>
<field name="LED10">FALSE</field>
<field name="LED20">FALSE</field>
<field name="LED30">FALSE</field>
<field name="LED40">FALSE</field>
<field name="LED01">FALSE</field>
<field name="LED11">TRUE</field>
<field name="LED21">FALSE</field>
<field name="LED31">TRUE</field>
<field name="LED41">FALSE</field>
<field name="LED02">FALSE</field>
<field name="LED12">FALSE</field>
<field name="LED22">FALSE</field>
<field name="LED32">FALSE</field>
<field name="LED42">FALSE</field>
<field name="LED03">TRUE</field>
<field name="LED13">FALSE</field>
<field name="LED23">FALSE</field>
<field name="LED33">FALSE</field>
<field name="LED43">TRUE</field>
<field name="LED04">FALSE</field>
<field name="LED14">TRUE</field>
<field name="LED24">TRUE</field>
<field name="LED34">TRUE</field>
<field name="LED44">FALSE</field>
<next>
<block type="device_show_leds">
<field name="LED00">FALSE</field>
<field name="LED10">FALSE</field>
<field name="LED20">FALSE</field>
<field name="LED30">FALSE</field>
<field name="LED40">FALSE</field>
<field name="LED01">FALSE</field>
<field name="LED11">FALSE</field>
<field name="LED21">FALSE</field>
<field name="LED31">FALSE</field>
<field name="LED41">FALSE</field>
<field name="LED02">FALSE</field>
<field name="LED12">FALSE</field>
<field name="LED22">FALSE</field>
<field name="LED32">FALSE</field>
<field name="LED42">FALSE</field>
<field name="LED03">FALSE</field>
<field name="LED13">FALSE</field>
<field name="LED23">FALSE</field>
<field name="LED33">FALSE</field>
<field name="LED43">FALSE</field>
<field name="LED04">FALSE</field>
<field name="LED14">FALSE</field>
<field name="LED24">FALSE</field>
<field name="LED34">FALSE</field>
<field name="LED44">FALSE</field>
</block>
</next>
</block>
</statement>
</block>
<block type="pxt-on-start"></block>
</xml>

View File

@ -1,16 +1 @@
basic.forever(() => {
basic.showLeds(`
. # . # .
# . # . #
# . . . #
. # . # .
. . # . .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
})

View File

@ -1,5 +1,14 @@
{
"bluetooth": "Support for additional Bluetooth services.",
"bluetooth": "Support for additional Bluetooth services.\n\nSupport for additional Bluetooth services.",
"bluetooth.advertiseUid": "Advertise an Eddystone UID",
"bluetooth.advertiseUidBuffer": "Advertise an Eddystone UID",
"bluetooth.advertiseUidBuffer|param|connectable": "true to keep bluetooth connectable for other services, false otherwise.",
"bluetooth.advertiseUidBuffer|param|nsAndInstance": "16 bytes buffer of namespace (bytes 0-9) and instance (bytes 10-15)",
"bluetooth.advertiseUidBuffer|param|power": "power level between 0 and 7, eg: 7",
"bluetooth.advertiseUid|param|connectable": "true to keep bluetooth connectable for other services, false otherwise.",
"bluetooth.advertiseUid|param|instance": "4 last bytes of the instance uid",
"bluetooth.advertiseUid|param|ns": "4 last bytes of the namespace uid",
"bluetooth.advertiseUid|param|power": "power level between 0 and 7, eg: 7",
"bluetooth.advertiseUrl": "Advertise an Eddystone URL",
"bluetooth.advertiseUrl|param|connectable": "true to keep bluetooth connectable for other services, false otherwise.",
"bluetooth.advertiseUrl|param|power": "power level between 0 and 7, eg: 7",

View File

@ -1,4 +1,5 @@
{
"bluetooth.advertiseUid|block": "bluetooth advertise UID|namespace (bytes 6-9)%ns|instance (bytes 2-6)%instance|with power %power|connectable %connectable",
"bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power|connectable %connectable",
"bluetooth.onBluetoothConnected|block": "on bluetooth connected",
"bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected",

View File

@ -7,7 +7,7 @@ using namespace pxt;
/**
* Support for additional Bluetooth services.
*/
//% color=#0082FB weight=20
//% color=#0082FB weight=20 icon="\uf294"
namespace bluetooth {
MicroBitUARTService *uart = NULL;
@ -137,6 +137,24 @@ namespace bluetooth {
uBit.bleManager.setTransmitPower(power);
}
/**
* Advertise an Eddystone UID
* @param nsAndInstance 16 bytes buffer of namespace (bytes 0-9) and instance (bytes 10-15)
* @param power power level between 0 and 7, eg: 7
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
*/
//% parts=bluetooth weight=12 advanced=true
void advertiseUidBuffer(Buffer nsAndInstance, int power, bool connectable) {
ManagedBuffer buf(nsAndInstance);
if (buf.length() != 16) return;
power = min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power));
int8_t level = CALIBRATED_POWERS[power];
uint8_t uidNs[10]; buf.readBytes(uidNs, 0, 10);
uint8_t uidInst[6]; buf.readBytes(uidInst, 10, 6);
uBit.bleManager.advertiseEddystoneUid((const char*)uidNs, (const char*)uidInst, level, connectable);
}
/**
* Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).
* @param power power level between 0 (minimal) and 7 (maximum), eg: 7.

View File

@ -1,7 +1,7 @@
/**
* Support for additional Bluetooth services.
*/
//% color=#0082FB weight=20
//% color=#0082FB weight=20 icon="\uf294"
namespace bluetooth {
/**
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.
@ -46,4 +46,21 @@ namespace bluetooth {
// dummy implementation for simulator
return "???"
}
/**
* Advertise an Eddystone UID
* @param ns 4 last bytes of the namespace uid
* @param instance 4 last bytes of the instance uid
* @param power power level between 0 and 7, eg: 7
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
*/
//% blockId=eddystone_advertise_uid block="bluetooth advertise UID|namespace (bytes 6-9)%ns|instance (bytes 2-6)%instance|with power %power|connectable %connectable"
//% parts=bluetooth weight=12 blockGap=8
//% help=bluetooth/advertise-uid blockExternalInputs=1
export function advertiseUid(ns: number, instance: number, power: number, connectable: boolean) {
const buf = pins.createBuffer(16);
buf.setNumber(NumberFormat.Int32BE, 6, ns);
buf.setNumber(NumberFormat.Int32BE, 12, instance);
bluetooth.advertiseUidBuffer(buf, power, connectable);
}
}

View File

@ -30,14 +30,14 @@
"event_service": 1,
"device_info_service": 1,
"eddystone_url": 1,
"eddystone_uid": 0,
"eddystone_uid": 1,
"open": 0,
"pairing_mode": 1,
"whitelist": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM"
}
},
"gatt_table_size": "0x700"
},
"gatt_table_size": "0x700"
}
},
"userConfigs": [
{

View File

@ -4,7 +4,7 @@
/**
* Support for additional Bluetooth services.
*/
//% color=#0082FB weight=20
//% color=#0082FB weight=20 icon="\uf294"
declare namespace bluetooth {
/**
@ -92,6 +92,15 @@ declare namespace bluetooth {
//% help=bluetooth/advertise-url blockExternalInputs=1 shim=bluetooth::advertiseUrl
function advertiseUrl(url: string, power: number, connectable: boolean): void;
/**
* Advertise an Eddystone UID
* @param nsAndInstance 16 bytes buffer of namespace (bytes 0-9) and instance (bytes 10-15)
* @param power power level between 0 and 7, eg: 7
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
*/
//% parts=bluetooth weight=12 advanced=true shim=bluetooth::advertiseUidBuffer
function advertiseUidBuffer(nsAndInstance: Buffer, power: number, connectable: boolean): void;
/**
* Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).
* @param power power level between 0 (minimal) and 7 (maximum), eg: 7.

View File

@ -1,62 +1,3 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="device_forever">
<statement name="HANDLER">
<block type="device_show_leds">
<field name="LED00">FALSE</field>
<field name="LED10">FALSE</field>
<field name="LED20">FALSE</field>
<field name="LED30">FALSE</field>
<field name="LED40">FALSE</field>
<field name="LED01">FALSE</field>
<field name="LED11">TRUE</field>
<field name="LED21">FALSE</field>
<field name="LED31">TRUE</field>
<field name="LED41">FALSE</field>
<field name="LED02">FALSE</field>
<field name="LED12">FALSE</field>
<field name="LED22">FALSE</field>
<field name="LED32">FALSE</field>
<field name="LED42">FALSE</field>
<field name="LED03">TRUE</field>
<field name="LED13">FALSE</field>
<field name="LED23">FALSE</field>
<field name="LED33">FALSE</field>
<field name="LED43">TRUE</field>
<field name="LED04">FALSE</field>
<field name="LED14">TRUE</field>
<field name="LED24">TRUE</field>
<field name="LED34">TRUE</field>
<field name="LED44">FALSE</field>
<next>
<block type="device_show_leds">
<field name="LED00">FALSE</field>
<field name="LED10">FALSE</field>
<field name="LED20">FALSE</field>
<field name="LED30">FALSE</field>
<field name="LED40">FALSE</field>
<field name="LED01">FALSE</field>
<field name="LED11">FALSE</field>
<field name="LED21">FALSE</field>
<field name="LED31">FALSE</field>
<field name="LED41">FALSE</field>
<field name="LED02">FALSE</field>
<field name="LED12">FALSE</field>
<field name="LED22">FALSE</field>
<field name="LED32">FALSE</field>
<field name="LED42">FALSE</field>
<field name="LED03">FALSE</field>
<field name="LED13">FALSE</field>
<field name="LED23">FALSE</field>
<field name="LED33">FALSE</field>
<field name="LED43">FALSE</field>
<field name="LED04">FALSE</field>
<field name="LED14">FALSE</field>
<field name="LED24">FALSE</field>
<field name="LED34">FALSE</field>
<field name="LED44">FALSE</field>
</block>
</next>
</block>
</statement>
</block>
<block type="pxt-on-start"></block>
</xml>

View File

@ -1,16 +1 @@
basic.forever(() => {
basic.showLeds(`
. # . # .
# . # . #
# . . . #
. # . # .
. . # . .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
})

View File

@ -33,6 +33,8 @@
"DisplayMode.Greyscale|block": "greyscale",
"EventCreationMode.CreateAndFire": "MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).",
"EventCreationMode.CreateOnly": "MicroBitEvent is initialised, and no further processing takes place.",
"Gesture.EightG": "Raised when a 8G shock is detected",
"Gesture.EightG|block": "8g",
"Gesture.FreeFall": "Raised when the board is falling!",
"Gesture.FreeFall|block": "free fall",
"Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical",

View File

@ -4,7 +4,7 @@
/**
* Provides access to basic micro:bit functionality.
*/
//% color=#0078D7 weight=100
//% color=#0078D7 weight=100 icon="\uf00a"
namespace basic {
/**
@ -13,7 +13,7 @@ namespace basic {
*/
//% help=basic/show-number
//% weight=96
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
//% blockId=device_show_number block="show|number %number" blockGap=8
//% async
//% parts="ledmatrix"
void showNumber(int value, int interval = 150) {
@ -50,7 +50,7 @@ namespace basic {
*/
//% help=basic/show-string
//% weight=87 blockGap=8
//% block="show|string %text" icon="\uf031"
//% block="show|string %text"
//% async
//% blockId=device_print_message
//% parts="ledmatrix"
@ -73,7 +73,7 @@ namespace basic {
* Turn off all LEDs
*/
//% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
//% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix"
void clearScreen() {
uBit.display.image.clear();
@ -112,7 +112,7 @@ namespace basic {
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute
*/
//% help=basic/forever weight=55 blockGap=8
//% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1
//% blockId=device_forever block="forever" icon="\uf01e"
void forever(Action a) {
if (a != 0) {

View File

@ -121,7 +121,7 @@ namespace control {
/**
* Schedules code that run in the background.
*/
//% help=control/in-background
//% help=control/in-background blockAllowMultiple=1
//% blockId="control_in_background" block="run in background" blockGap=8
void inBackground(Action a) {
runInBackground(a);

View File

@ -1,7 +1,7 @@
/**
* Runtime and event utilities.
*/
//% weight=1 color="#333333"
//% weight=1 color="#333333" icon="\uf233"
//% advanced=true
namespace control {
@ -31,7 +31,7 @@ namespace control {
/**
* If the condition is false, display msg on serial console, and panic with code 098.
*/
export function assert(condition: boolean, msg ?: string) {
export function assert(condition: boolean, msg?: string) {
if (!condition) {
console.log("ASSERTION FAILED")
if (msg != null) {

View File

@ -153,13 +153,19 @@ namespace Array_ {
//%
int length(RefCollection *c) { return c->length(); }
//%
void setLength(RefCollection *c, int newLength) { c->setLength(newLength); }
//%
void push(RefCollection *c, uint32_t x) { c->push(x); }
//%
uint32_t pop(RefCollection *c) { return c->pop(); }
//%
uint32_t getAt(RefCollection *c, int x) { return c->getAt(x); }
//%
void removeAt(RefCollection *c, int x) { c->removeAt(x); }
void setAt(RefCollection *c, int x, uint32_t y) { c->setAt(x, y); }
//%
void setAt(RefCollection *c, int x, uint32_t y) { c->setAt(x, y); }
uint32_t removeAt(RefCollection *c, int x) { return c->removeAt(x); }
//%
void insertAt(RefCollection *c, int x, uint32_t value) { c->insertAt(x, value); }
//%
int indexOf(RefCollection *c, uint32_t x, int start) { return c->indexOf(x, start); }
//%

View File

@ -115,6 +115,11 @@ declare namespace basic {
*/
//% block="6g"
SixG = 9, // MICROBIT_ACCELEROMETER_EVT_6G
/**
* Raised when a 8G shock is detected
*/
//% block="8g"
EightG = 10, // MICROBIT_ACCELEROMETER_EVT_8G
}
declare namespace input {
}

View File

@ -21,7 +21,7 @@ enum LedSpriteProperty {
/**
* A single-LED sprite game engine
*/
//% color=#008272 weight=32
//% color=#008272 weight=32 icon="\uf11b"
//% advanced=true
namespace game {
let _score: number = 0;

View File

@ -3,7 +3,7 @@
/**
* Creation, manipulation and display of LED images.
*/
//% color=#5C2D91 weight=31
//% color=#5C2D91 weight=31 icon="\uf03e"
//% advanced=true
namespace images {
/**

View File

@ -104,10 +104,15 @@ enum class Gesture {
* Raised when a 6G shock is detected
*/
//% block="6g"
SixG = MICROBIT_ACCELEROMETER_EVT_6G
SixG = MICROBIT_ACCELEROMETER_EVT_6G,
/**
* Raised when a 8G shock is detected
*/
//% block="8g"
EightG = MICROBIT_ACCELEROMETER_EVT_8G
};
//% color=300 weight=99
//% color=300 weight=99 icon="\uf192"
namespace input {
/**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
@ -115,7 +120,7 @@ namespace input {
* @param body code to run when event is raised
*/
//% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
//% blockId=device_button_event block="on button|%NAME|pressed"
//% parts="buttonpair"
void onButtonPressed(Button button, Action body) {
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
@ -127,14 +132,15 @@ namespace input {
* @param body code to run when gesture is raised
*/
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
//% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer"
void onGesture(Gesture gesture, Action body) {
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
int gi = (int)gesture;
if (gi == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
uBit.accelerometer.setRange(4);
else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6)
else if ((gi == MICROBIT_ACCELEROMETER_EVT_6G || gi == MICROBIT_ACCELEROMETER_EVT_8G) && uBit.accelerometer.getRange() < 6)
uBit.accelerometer.setRange(8);
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
registerWithDal(MICROBIT_ID_GESTURE, gi, body);
}
/**
@ -143,7 +149,7 @@ namespace input {
* @param body the code to run when the pin is pressed
*/
//% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %name|pressed" icon="\uf094"
//% blockId=device_pin_event block="on pin %name|pressed"
void onPinPressed(TouchPin name, Action body) {
auto pin = getPin((int)name);
if (!pin) return;
@ -159,7 +165,7 @@ namespace input {
* @param body the code to run when the pin is released
*/
//% help=input/on-pin-released weight=6 blockGap=8
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094"
//% blockId=device_pin_released block="on pin %NAME|released"
//% advanced=true
void onPinReleased(TouchPin name, Action body) {
auto pin = getPin((int)name);
@ -194,7 +200,7 @@ namespace input {
* @param name pin used to detect the touch, eg: TouchPin.P0
*/
//% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
//% blockGap=8
bool pinIsPressed(TouchPin name) {
auto pin = getPin((int)name);
@ -212,7 +218,7 @@ namespace input {
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
* @param dimension TODO
*/
//% help=input/acceleration weight=58 icon="\uf135"
//% help=input/acceleration weight=58
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
//% parts="accelerometer"
int acceleration(Dimension dimension) {
@ -229,7 +235,7 @@ namespace input {
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
*/
//% help=input/light-level weight=57
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
//% blockId=device_get_light_level block="light level" blockGap=8
//% parts="ledmatrix"
int lightLevel() {
return uBit.display.readLightLevel();
@ -239,7 +245,7 @@ namespace input {
* Get the current compass heading in degrees.
*/
//% help=input/compass-heading
//% weight=56 icon="\uf14e"
//% weight=56
//% blockId=device_heading block="compass heading (°)" blockGap=8
//% parts="compass"
int compassHeading() {
@ -250,7 +256,7 @@ namespace input {
/**
* Gets the temperature in Celsius degrees (°C).
*/
//% weight=55 icon="\uf06d"
//% weight=55
//% help=input/temperature
//% blockId=device_temperature block="temperature (°C)" blockGap=8
//% parts="thermometer"
@ -263,7 +269,7 @@ namespace input {
* @param kind TODO
*/
//% help=input/rotation weight=52
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8
//% parts="accelerometer" advanced=true
int rotation(Rotation kind) {
switch (kind) {
@ -278,7 +284,7 @@ namespace input {
* @param dimension TODO
*/
//% help=input/magnetic-force weight=51
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8
//% parts="compass"
//% advanced=true
int magneticForce(Dimension dimension) {
@ -298,7 +304,7 @@ namespace input {
* Gets the number of milliseconds elapsed since power on.
*/
//% help=input/running-time weight=50
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017"
//% blockId=device_get_running_time block="running time (ms)"
//% advanced=true
int runningTime() {
return system_timer_current_time();
@ -315,7 +321,7 @@ namespace input {
* @param range a value describe the maximum strengh of acceleration measured
*/
//% help=input/set-accelerometer-range
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range"
//% weight=5
//% parts="accelerometer"
//% advanced=true

View File

@ -1,7 +1,7 @@
/**
* Events and data from sensors
*/
//% color=#B4009E weight=99
//% color=#B4009E weight=99 icon="\uf192"
namespace input {
/**
* Attaches code to run when the screen is facing up.

View File

@ -8,7 +8,7 @@ enum class DisplayMode_ {
// TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
};
//% color=3 weight=35
//% color=3 weight=35 icon="\uf205"
namespace led {
/**
@ -17,7 +17,7 @@ namespace led {
* @param y TODO
*/
//% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix"
void plot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 1);
@ -29,7 +29,7 @@ namespace led {
* @param y TODO
*/
//% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix"
void unplot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 0);
@ -41,7 +41,7 @@ namespace led {
* @param y TODO
*/
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
//% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix"
bool point(int x, int y) {
int pix = uBit.display.image.getPixelValue(x, y);
@ -52,7 +52,7 @@ namespace led {
* Get the screen brightness from 0 (off) to 255 (full bright).
*/
//% help=led/brightness weight=60
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
//% blockId=device_get_brightness block="brightness" blockGap=8
//% parts="ledmatrix"
//% advanced=true
int brightness() {
@ -64,7 +64,7 @@ namespace led {
* @param value the brightness value, eg:255, 127, 0
*/
//% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
//% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix"
//% advanced=true
void setBrightness(int value) {
@ -75,7 +75,7 @@ namespace led {
* Cancels the current animation and clears other pending animations.
*/
//% weight=50 help=led/stop-animation
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
//% blockId=device_stop_animation block="stop animation"
//% parts="ledmatrix"
//% advanced=true
void stopAnimation() {
@ -95,7 +95,7 @@ namespace led {
/**
* Turns on or off the display
*/
//% help=led/enable blockId=device_led_enable block="led enable %on" icon="\uf04d"
//% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix"
void enable(bool on) {
if (on) uBit.display.enable();

View File

@ -1,7 +1,7 @@
/**
* Control of the LED screen.
*/
//% color=#5C2D91 weight=97
//% color=#5C2D91 weight=97 icon="\uf205"
namespace led {
// what's the current high value

View File

@ -129,7 +129,7 @@ enum BeatFraction {
/**
* Generation of music tones through pin ``P0``.
*/
//% color=#D83B01 weight=98
//% color=#D83B01 weight=98 icon="\uf025"
namespace music {
let beatsPerMinute: number = 120;
@ -139,7 +139,7 @@ namespace music {
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" blockGap=8
//% parts="headphone"
export function playTone(frequency: number, ms: number): void {
pins.analogPitch(frequency, ms);
@ -150,7 +150,7 @@ namespace music {
* @param frequency pitch of the tone to play in Hertz (Hz)
*/
//% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" blockGap=8
//% parts="headphone"
export function ringTone(frequency: number): void {
pins.analogPitch(frequency, 0);

View File

@ -1,7 +1,7 @@
/**
* Control currents in Pins for analog/digital signals, servos, i2c, ...
*/
//% color=#A80000 weight=30
//% color=#A80000 weight=30 icon="\uf140"
//% advanced=true
namespace pins {
/**

View File

@ -141,63 +141,373 @@ namespace pxt {
printf("RefRecord %p r=%d size=%d bytes\n", r, r->refcnt, r->getVTable()->numbytes);
}
void RefCollection::push(uint32_t x) {
if (isRef()) incr(x);
data.push_back(x);
uint32_t Segment::get(uint32_t i)
{
#ifdef DEBUG_BUILD
printf("In Segment::get index:%u\n", i);
this->print();
#endif
if (i < length)
{
if (data[i] != Segment::MissingValue)
{
return data[i];
}
error(ERR_MISSING_VALUE);
return 0;
}
error(ERR_OUT_OF_BOUNDS);
return 0;
}
uint32_t RefCollection::getAt(int x) {
if (in_range(x)) {
uint32_t tmp = data.at(x);
if (isRef()) incr(tmp);
void Segment::set(uint32_t i, uint32_t value)
{
if (i < size)
{
data[i] = value;
}
else if (i < Segment::MaxSize)
{
growByMin(i + 1);
data[i] = value;
}
if (length <= i)
{
length = i + 1;
}
#ifdef DEBUG_BUILD
printf("In Segment::set\n");
this->print();
#endif
return;
}
uint16_t Segment::growthFactor(uint16_t size)
{
if (size == 0)
{
return 4;
}
if (size < 64)
{
return size * 2; // Double
}
if (size < 512)
{
return size * 5/3; //Grow by 1.66 rate
}
return size + 256; //Grow by constant rate
}
void Segment::growByMin(uint16_t minSize)
{
growBy(max(minSize, growthFactor(size)));
}
void Segment::growBy(uint16_t newSize)
{
#ifdef DEBUG_BUILD
printf("growBy: %d\n", newSize);
this->print();
#endif
if (size < newSize)
{
//this will throw if unable to allocate
uint32_t *tmp = (uint32_t*)(::operator new(newSize * sizeof(uint32_t)));
//Copy existing data
if (size)
{
memcpy(tmp, data, size * sizeof(uint32_t));
}
//fill the rest with missing values;
for(uint16_t i = size; i < newSize; i++)
{
tmp[i] = Segment::MissingValue;
}
//free older segment;
::operator delete(data);
data = tmp;
size = newSize;
#ifdef DEBUG_BUILD
printf("growBy - after reallocation\n");
this->print();
#endif
}
//else { no shrinking yet; }
return;
}
void Segment::ensure(uint16_t newSize)
{
if (newSize < size)
{
return;
}
growByMin(newSize);
}
void Segment::setLength(uint32_t newLength)
{
if (newLength > size)
{
ensure(length);
}
length = newLength;
return;
}
void Segment::push(uint32_t value)
{
this->set(length, value);
}
uint32_t Segment::pop()
{
#ifdef DEBUG_BUILD
printf("In Segment::pop\n");
this->print();
#endif
if (length > 0)
{
uint32_t value = data[length];
data[length] = Segment::MissingValue;
--length;
return value;
}
error(ERR_OUT_OF_BOUNDS);
return 0;
}
//this function removes an element at index i and shifts the rest of the elements to
//left to fill the gap
uint32_t Segment::remove(uint32_t i)
{
#ifdef DEBUG_BUILD
printf("In Segment::remove index:%u\n", i);
this->print();
#endif
if (i < length)
{
//value to return
uint32_t ret = data[i];
if (i + 1 < length)
{
//Move the rest of the elements to fill in the gap.
memmove(data + i, data + i + 1, (length - i - 1) * sizeof(uint32_t));
}
length--;
data[length] = Segment::MissingValue;
#ifdef DEBUG_BUILD
printf("After Segment::remove index:%u\n", i);
this->print();
#endif
return ret;
}
error(ERR_OUT_OF_BOUNDS);
return 0;
}
//this function inserts element value at index i by shifting the rest of the elements right.
void Segment::insert(uint32_t i, uint32_t value)
{
#ifdef DEBUG_BUILD
printf("In Segment::insert index:%u value:%u\n", i, value);
this->print();
#endif
if (i < length)
{
ensure(length + 1);
if (i + 1 < length)
{
//Move the rest of the elements to fill in the gap.
memmove(data + i + 1, data + i, (length - i) * sizeof(uint32_t));
}
data[i] = value;
length++;
}
else
{
//This is insert beyond the length, just call set which will adjust the length
set(i, value);
}
#ifdef DEBUG_BUILD
printf("After Segment::insert index:%u\n", i);
this->print();
#endif
}
void Segment::print()
{
printf("Segment: %x, length: %u, size: %u\n", data, (uint)length, (uint)size);
for(uint i = 0; i < size; i++)
{
printf("%d ",(uint)data[i]);
}
printf("\n");
}
bool Segment::isValidIndex(uint32_t i)
{
if (i > length || data[i] == Segment::MissingValue)
{
return false;
}
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()
{
#ifdef DEBUG_BUILD
printf("In Segment::destroy\n");
this->print();
#endif
length = size = 0;
::operator delete(data);
data = nullptr;
}
void RefCollection::push(uint32_t x)
{
if (isRef()) incr(x);
head.push(x);
}
uint32_t RefCollection::pop()
{
uint32_t ret = head.pop();
if (isRef())
{
incr(ret);
}
return ret;
}
uint32_t RefCollection::getAt(int i)
{
if (head.isValidIndex(i))
{
uint32_t tmp = head.get(i);
if (isRef())
{
incr(tmp);
}
return tmp;
}
else {
else
{
error(ERR_OUT_OF_BOUNDS);
return 0;
}
}
void RefCollection::removeAt(int x) {
if (!in_range(x))
return;
if (isRef()) decr(data.at(x));
data.erase(data.begin()+x);
}
void RefCollection::setAt(int x, uint32_t y) {
if (!in_range(x))
return;
if (isRef()) {
decr(data.at(x));
incr(y);
uint32_t RefCollection::removeAt(int i)
{
if (!head.isValidIndex((uint32_t)i))
{
error(ERR_OUT_OF_BOUNDS);
return 0;
}
data.at(x) = y;
if (isRef())
{
decr(head.get(i));
}
return head.remove(i);
}
int RefCollection::indexOf(uint32_t x, int start) {
if (!in_range(start))
return -1;
void RefCollection::insertAt(int i, uint32_t value)
{
if (i < length())
{
head.insert(i, value);
if (isRef())
{
incr(value);
}
}
else
{
error(ERR_OUT_OF_BOUNDS);
}
}
if (isString()) {
StringData *xx = (StringData*)x;
for (uint32_t i = start; i < data.size(); ++i) {
StringData *ee = (StringData*)data.at(i);
if (xx->len == ee->len && memcmp(xx->data, ee->data, xx->len) == 0)
return (int)i;
void RefCollection::setAt(int i, uint32_t value)
{
if (isRef())
{
if (head.isValidIndex((uint32_t)i))
{
decr(head.get(i));
}
} else {
for (uint32_t i = start; i < data.size(); ++i)
if (data.at(i) == x)
incr(value);
}
head.set(i, value);
}
int RefCollection::indexOf(uint32_t x, int start)
{
if (isString())
{
StringData *xx = (StringData*)x;
uint32_t i = start;
while(head.getNextValidIndex(start, &i))
{
StringData *ee = (StringData*)head.get(i);
if (xx->len == ee->len && memcmp(xx->data, ee->data, xx->len) == 0)
{
return (int)i;
}
start = i;
}
}
else
{
uint32_t i = start;
while(head.getNextValidIndex(start, &i))
{
if (head.get(i) == x)
{
return (int)i;
}
start = i;
}
}
return -1;
}
int RefCollection::removeElement(uint32_t x) {
int RefCollection::removeElement(uint32_t x)
{
int idx = indexOf(x, 0);
if (idx >= 0) {
removeAt(idx);
@ -239,17 +549,23 @@ namespace pxt {
void RefCollection::destroy()
{
if (this->isRef())
for (uint32_t i = 0; i < this->data.size(); ++i) {
decr(this->data[i]);
this->data[i] = 0;
{
uint32_t start = 0;
uint32_t i = 0;
while(head.getNextValidIndex(start, &i))
{
decr(this->head.get(i));
start = i;
}
this->data.resize(0);
}
this->head.destroy();
delete this;
}
void RefCollection::print()
{
printf("RefCollection %p r=%d flags=%d size=%d [%p, ...]\n", this, refcnt, getFlags(), data.size(), data.size() > 0 ? data[0] : 0);
printf("RefCollection %p r=%d flags=%d size=%d\n", this, refcnt, getFlags(), head.getLength());
head.print();
}
PXT_VTABLE_CTOR(RefAction) {}

View File

@ -1,7 +1,7 @@
#ifndef __PXT_H
#define __PXT_H
// #define DEBUG_MEMLEAKS 1
//#define DEBUG_MEMLEAKS 1
#pragma GCC diagnostic ignored "-Wunused-parameter"
@ -38,6 +38,7 @@ namespace pxt {
ERR_OUT_OF_BOUNDS = 8,
ERR_REF_DELETED = 7,
ERR_SIZE = 9,
ERR_MISSING_VALUE = 10,
} ERROR;
extern const uint32_t functionsAndBytecode[];
@ -167,11 +168,53 @@ namespace pxt {
}
};
class Segment {
private:
uint32_t* data;
uint16_t length;
uint16_t size;
static const uint16_t MaxSize = 0xFFFF;
static const uint32_t MissingValue = 0x80000000;
static uint16_t growthFactor(uint16_t size);
void growByMin(uint16_t minSize);
void growBy(uint16_t newSize);
void ensure(uint16_t newSize);
public:
Segment() : data (nullptr), length(0), size(0) {};
uint32_t get(uint32_t i);
void set(uint32_t i, uint32_t value);
uint32_t getLength() { return length;};
void setLength(uint32_t newLength);
void push(uint32_t value);
uint32_t pop();
uint32_t remove(uint32_t i);
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);
void destroy();
void print();
};
// A ref-counted collection of either primitive or ref-counted objects (String, Image,
// user-defined record, another collection)
class RefCollection
: public RefObject
{
private:
Segment head;
public:
// 1 - collection of refs (need decr)
// 2 - collection of strings (in fact we always have 3, never 2 alone)
@ -179,23 +222,23 @@ namespace pxt {
inline bool isRef() { return getFlags() & 1; }
inline bool isString() { return getFlags() & 2; }
std::vector<uint32_t> data;
RefCollection(uint16_t f);
inline bool in_range(int x) {
return (0 <= x && x < (int)data.size());
}
inline int length() { return data.size(); }
void destroy();
void print();
uint32_t length() { return head.getLength();}
void setLength(uint32_t newLength) { head.setLength(newLength); }
void push(uint32_t x);
uint32_t getAt(int x);
void removeAt(int x);
void setAt(int x, uint32_t y);
uint32_t pop();
uint32_t getAt(int i);
void setAt(int i, uint32_t x);
//removes the element at index i and shifts the other elements left
uint32_t removeAt(int i);
//inserts the element at index i and moves the other elements right.
void insertAt(int i, uint32_t x);
int indexOf(uint32_t x, int start);
int removeElement(uint32_t x);
};

View File

@ -34,7 +34,7 @@ enum Delimiters {
Hash = 6,
};
//% weight=2 color=30
//% weight=2 color=30 icon="\uf287"
//% advanced=true
namespace serial {
// note that at least one // followed by % is needed per declaration!
@ -92,7 +92,10 @@ namespace serial {
//% blockId=serial_redirect block="serial|redirect to|TX %tx|RX %rx|at baud rate %rate"
//% blockExternalInputs=1
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);
}
}

View File

@ -1,7 +1,7 @@
/**
* Reading and writing data over a serial connection.
*/
//% weight=2 color=#002050
//% weight=2 color=#002050 icon="\uf287"
//% advanced=true
namespace serial {
/**

60
libs/core/shims.d.ts vendored
View File

@ -4,7 +4,7 @@
/**
* Creation, manipulation and display of LED images.
*/
//% color=#5C2D91 weight=31
//% color=#5C2D91 weight=31 icon="\uf03e"
//% advanced=true
declare namespace images {
@ -126,7 +126,7 @@ declare interface Image {
/**
* Provides access to basic micro:bit functionality.
*/
//% color=#0078D7 weight=100
//% color=#0078D7 weight=100 icon="\uf00a"
declare namespace basic {
/**
@ -135,7 +135,7 @@ declare namespace basic {
*/
//% help=basic/show-number
//% weight=96
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec"
//% blockId=device_show_number block="show|number %number" blockGap=8
//% async
//% parts="ledmatrix" interval.defl=150 shim=basic::showNumber
function showNumber(value: number, interval?: number): void;
@ -160,7 +160,7 @@ declare namespace basic {
*/
//% help=basic/show-string
//% weight=87 blockGap=8
//% block="show|string %text" icon="\uf031"
//% block="show|string %text"
//% async
//% blockId=device_print_message
//% parts="ledmatrix" interval.defl=150 shim=basic::showString
@ -170,7 +170,7 @@ declare namespace basic {
* Turn off all LEDs
*/
//% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" icon="\uf12d"
//% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix" shim=basic::clearScreen
function clearScreen(): void;
@ -195,7 +195,7 @@ declare namespace basic {
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute
*/
//% help=basic/forever weight=55 blockGap=8
//% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1
//% blockId=device_forever block="forever" icon="\uf01e" shim=basic::forever
function forever(a: () => void): void;
@ -211,7 +211,7 @@ declare namespace basic {
//% color=300 weight=99
//% color=300 weight=99 icon="\uf192"
declare namespace input {
/**
@ -220,7 +220,7 @@ declare namespace input {
* @param body code to run when event is raised
*/
//% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
//% blockId=device_button_event block="on button|%NAME|pressed"
//% parts="buttonpair" shim=input::onButtonPressed
function onButtonPressed(button: Button, body: () => void): void;
@ -230,7 +230,7 @@ declare namespace input {
* @param body code to run when gesture is raised
*/
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
//% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer" shim=input::onGesture
function onGesture(gesture: Gesture, body: () => void): void;
@ -240,7 +240,7 @@ declare namespace input {
* @param body the code to run when the pin is pressed
*/
//% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %name|pressed" icon="\uf094" shim=input::onPinPressed
//% blockId=device_pin_event block="on pin %name|pressed" shim=input::onPinPressed
function onPinPressed(name: TouchPin, body: () => void): void;
/**
@ -249,7 +249,7 @@ declare namespace input {
* @param body the code to run when the pin is released
*/
//% help=input/on-pin-released weight=6 blockGap=8
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094"
//% blockId=device_pin_released block="on pin %NAME|released"
//% advanced=true shim=input::onPinReleased
function onPinReleased(name: TouchPin, body: () => void): void;
@ -269,7 +269,7 @@ declare namespace input {
* @param name pin used to detect the touch, eg: TouchPin.P0
*/
//% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
//% blockGap=8 shim=input::pinIsPressed
function pinIsPressed(name: TouchPin): boolean;
@ -277,7 +277,7 @@ declare namespace input {
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
* @param dimension TODO
*/
//% help=input/acceleration weight=58 icon="\uf135"
//% help=input/acceleration weight=58
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
//% parts="accelerometer" shim=input::acceleration
function acceleration(dimension: Dimension): number;
@ -286,7 +286,7 @@ declare namespace input {
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
*/
//% help=input/light-level weight=57
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185"
//% blockId=device_get_light_level block="light level" blockGap=8
//% parts="ledmatrix" shim=input::lightLevel
function lightLevel(): number;
@ -294,7 +294,7 @@ declare namespace input {
* Get the current compass heading in degrees.
*/
//% help=input/compass-heading
//% weight=56 icon="\uf14e"
//% weight=56
//% blockId=device_heading block="compass heading (°)" blockGap=8
//% parts="compass" shim=input::compassHeading
function compassHeading(): number;
@ -302,7 +302,7 @@ declare namespace input {
/**
* Gets the temperature in Celsius degrees (°C).
*/
//% weight=55 icon="\uf06d"
//% weight=55
//% help=input/temperature
//% blockId=device_temperature block="temperature (°C)" blockGap=8
//% parts="thermometer" shim=input::temperature
@ -313,7 +313,7 @@ declare namespace input {
* @param kind TODO
*/
//% help=input/rotation weight=52
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197"
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8
//% parts="accelerometer" advanced=true shim=input::rotation
function rotation(kind: Rotation): number;
@ -322,7 +322,7 @@ declare namespace input {
* @param dimension TODO
*/
//% help=input/magnetic-force weight=51
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076"
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8
//% parts="compass"
//% advanced=true shim=input::magneticForce
function magneticForce(dimension: Dimension): number;
@ -331,7 +331,7 @@ declare namespace input {
* Gets the number of milliseconds elapsed since power on.
*/
//% help=input/running-time weight=50
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017"
//% blockId=device_get_running_time block="running time (ms)"
//% advanced=true shim=input::runningTime
function runningTime(): number;
@ -346,7 +346,7 @@ declare namespace input {
* @param range a value describe the maximum strengh of acceleration measured
*/
//% help=input/set-accelerometer-range
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135"
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range"
//% weight=5
//% parts="accelerometer"
//% advanced=true shim=input::setAccelerometerRange
@ -362,7 +362,7 @@ declare namespace control {
/**
* Schedules code that run in the background.
*/
//% help=control/in-background
//% help=control/in-background blockAllowMultiple=1
//% blockId="control_in_background" block="run in background" blockGap=8 shim=control::inBackground
function inBackground(a: () => void): void;
@ -427,7 +427,7 @@ declare namespace control {
//% color=3 weight=35
//% color=3 weight=35 icon="\uf205"
declare namespace led {
/**
@ -436,7 +436,7 @@ declare namespace led {
* @param y TODO
*/
//% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::plot
function plot(x: number, y: number): void;
@ -446,7 +446,7 @@ declare namespace led {
* @param y TODO
*/
//% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::unplot
function unplot(x: number, y: number): void;
@ -456,7 +456,7 @@ declare namespace led {
* @param y TODO
*/
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c"
//% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix" shim=led::point
function point(x: number, y: number): boolean;
@ -464,7 +464,7 @@ declare namespace led {
* Get the screen brightness from 0 (off) to 255 (full bright).
*/
//% help=led/brightness weight=60
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8
//% blockId=device_get_brightness block="brightness" blockGap=8
//% parts="ledmatrix"
//% advanced=true shim=led::brightness
function brightness(): number;
@ -474,7 +474,7 @@ declare namespace led {
* @param value the brightness value, eg:255, 127, 0
*/
//% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042"
//% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix"
//% advanced=true shim=led::setBrightness
function setBrightness(value: number): void;
@ -483,7 +483,7 @@ declare namespace led {
* Cancels the current animation and clears other pending animations.
*/
//% weight=50 help=led/stop-animation
//% blockId=device_stop_animation block="stop animation" icon="\uf04d"
//% blockId=device_stop_animation block="stop animation"
//% parts="ledmatrix"
//% advanced=true shim=led::stopAnimation
function stopAnimation(): void;
@ -499,7 +499,7 @@ declare namespace led {
/**
* Turns on or off the display
*/
//% help=led/enable blockId=device_led_enable block="led enable %on" icon="\uf04d"
//% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix" shim=led::enable
function enable(on: boolean): void;
@ -658,7 +658,7 @@ declare namespace pins {
//% weight=2 color=30
//% weight=2 color=30 icon="\uf287"
//% advanced=true
declare namespace serial {

View File

@ -24,7 +24,7 @@ using namespace pxt;
// payload: string length (9), string (10 ... 28)
#define PACKET_TYPE_STRING 2
//% color=270 weight=34
//% color=270 weight=34 icon="\uf012"
namespace radio {
// -------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
/**
* Communicate data using radio packets
*/
//% color=#E3008C weight=34
//% color=#E3008C weight=34 icon="\uf012"
namespace radio {
export class Packet {
/**

View File

@ -2,7 +2,7 @@
//% color=270 weight=34
//% color=270 weight=34 icon="\uf012"
declare namespace radio {
/**

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.6.43",
"version": "0.7.17",
"description": "micro:bit target for PXT",
"keywords": [
"JavaScript",
@ -34,6 +34,6 @@
"semantic-ui-less": "^2.2.4"
},
"dependencies": {
"pxt-core": "0.6.5"
"pxt-core": "0.8.5"
}
}

View File

@ -57,6 +57,12 @@
"bluetooth\\s*\\.uartRead\\s*\\((.*?)\\)": "bluetooth.uartReadUntil($1)",
"bluetooth\\s*\\.uartWrite\\s*\\((.*?)\\)": "bluetooth.uartWriteUntil($1)"
}
},
{
"type": "blockId",
"map": {
"device_get_acceleration": "device_acceleration"
}
}
]
},
@ -64,7 +70,9 @@
"mathBlocks": true,
"loopsBlocks": true,
"logicBlocks": true,
"variablesBlocks": true
"variablesBlocks": true,
"onStartColor": "#0078D7",
"onStartNamespace": "basic"
},
"simulator": {
"autoRun": true,

View File

@ -1,4 +1,4 @@
/// <reference path="../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
/// <reference path="../node_modules/pxt-core/typings/globals/bluebird/index.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtrunner.d.ts"/>

View File

@ -178,6 +178,7 @@ namespace pxsim.bluetooth {
// TODO
}
export function advertiseUrl(url: string, power: number, connectable: boolean) { }
export function advertiseUidBuffer(nsAndInstance: Buffer, power: number, connectable: boolean) { }
export function stopAdvertising() { }
export function setTransmitPower(power: number) {}
}

View File

@ -1,4 +1,4 @@
/// <reference path="../../node_modules/pxt-core/typings/bluebird/bluebird.d.ts"/>
/// <reference path="../../node_modules/pxt-core/typings/globals/bluebird/index.d.ts"/>
/// <reference path="../../node_modules/pxt-core/built/pxtsim.d.ts"/>
namespace pxsim.visuals {

View File

@ -11908,62 +11908,111 @@
:10071000F19501004198010039B1010099B901003A
:10072000D5C901009D26020061270200C180010099
:10073000708E3B92C615A841C49866C975EE519754
:100740002D0CF6CB4FCF31AA3852319F38B256E537
:100740002D0CF6CB4FCF31AA187FF87FFC58A9E9C2
:100750000000000000000000000000000000000099
:1007600000B5002001B4002001B4002001B4002035
:1007700000028C30024602BC01BCE8F745FC01B423
:10078000E8F7CAFC01BCF9F731FA0098F9F72EFA3C
:1007900001B000BD00B5002001B4069801B4069870
:1007A000014601BCF8F759FE01B4039801B405985D
:1007B000014601BCF8F751FE014601BCF8F753FEB3
:1007C00001B4059801B40798014601BCF8F745FE4D
:1007D000014601BCF8F743FE01B40498014601BC90
:1007E000F8F739FE0090FFE7009801B000BD00B5B2
:1007F000002001B4002000900298002802D0FF20C1
:100800000090FFE7059801B4F9F7C9F9059801B41C
:10081000059801B40398034604BC02BC0098F9F79C
:100820000AF901BCF9F7E2F90598F9F7DFF901B027
:1008300000BD00B5002001B40020E8F77DFB00906A
:10084000FFE7009801B000BDFFFF000020B50D4696
:1008500000200002A83001B40120000290300146BF
:1008600001BCE8F70FFA00200002B83001B4012003
:1008700000029030014601BCE8F704FA20BD0000F8
:10088000FFFF05000500000000000000010001005E
:100890000000000000000000000000010101002A2B
:1008A000FFFF050005000000000000000000000040
:1008B0000000000000000000000000000000002A0E
:1008C00041140E2FB82FA2BB4C00A3010000000062
:1008D0007B22636F6D7072657373696F6E223A224B
:1008E0004C5A4D41222C2268656164657253697AC5
:1008F00065223A3133392C227465787453697A65EC
:10090000223A323439342C226E616D65223A2262E9
:100910006C6F636B73626C696E6B227D5D0000802F
:1009200000490A000000000000003D888867041CA0
:10093000BCC1C8A25578869B4D69261C354501422D
:100940001948E37B0692B2DBE3A99A218E18EFA542
:100950006421FF3A50DF5CB84D25B831BC1D9BD0F7
:10096000A3720BD23F36166C9FFADA84711D2EB338
:100970003291D1DEB646B0BE0FFADE6FD7AD7C1134
:10098000573353851403078AD6AEE9A5C8D021B2E0
:100990007FFAB45E1D9AF8C10C1AEF12B167A5C2B6
:1009A000329D2DC02570F67BAF4E1FC2923CE042B7
:1009B00028E478417276160D1F06CE6E0CCBD84C0B
:1009C000B456FF79CC0DE99E98FE0D65BED6F7842E
:1009D000890D2B69552360DED35DCD22F579D8E4EE
:1009E000F214F5717F1C2CEF0D59E583D995AC807D
:1009F0000624B660B3E376A4C5A4C62BC0B1766066
:100A00005B5E6DBBD94336CEF28C58753EF5E6176A
:100A10000D454E5EA91A60E7F9BAA6413CFDB93210
:100A2000CC8DC16D25BCBA7ECF28A19D88036FAD4A
:100A30008EF21F6085E68BBD74D011870E15C5320E
:100A4000CAB0F268C6FF6A8E3DB568FF545C98A5CF
:100A5000041DFD9090BB3978F3995097661EE126EE
:100A60000993D095AB665AE4626AC471DC13A6D4CC
:100A700012F078262A98D778E53BE920E252773DB4
:100A8000206C0C9FA0E8589826BD5F95814AC5BE92
:100A90007BC997717460085C806C1CD9B85CCD33DD
:100AA0000016DD6FD865555605505938E15B941135
:100AB000D2FAC2F686783310D2E2FF86A151000046
:1007600000B5002001B401B401B401B401B401200A
:1007700001B4002001B4002001B400200002F630D2
:10078000024602BC01BCE8F73FFC014601BC02B4D2
:10079000F9F7B0FC01BCF9F729FA022001B40020F6
:1007A00001B4002001B4012000021A30024602BC4C
:1007B00001BCE8F729FC014601BC02B4F9F79AFC38
:1007C00001BCF9F713FA002001B4002001B40120A4
:1007D00000024030024602BC01BCE8F715FC01B43F
:1007E000E8F79AFC01BCF9F701FA02209621E7F735
:1007F00021FF01200002483001B4012000029030A6
:10080000014601BCE8F73EFA012000025830E8F743
:10081000CDF801B4962001460098F9F72FF901BCF4
:10082000F9F7E4F90120E7F73FFEE7F785FDE8F780
:1008300065FAE7F7AFFE0020E7F71CFEE7F784FD57
:100840000020E7F7F9FD0020E7F714FE0020E7F7A6
:1008500083FD0098F9F7CAF90298F9F7C7F90498E7
:10086000F9F7C4F905B000BD00B5002001B4069841
:1008700001B40698014601BCF8F7EFFD01B40398F6
:1008800001B40598014601BCF8F7E7FD014601BC3B
:10089000F8F7E9FD01B4059801B40798014601BCD9
:1008A000F8F7DBFD014601BCF8F7D9FD01B4049867
:1008B000014601BCF8F7CFFD0090FFE7009801B0BA
:1008C00000BD00B5002001B400200090029800286F
:1008D00002D0FF200090FFE7059801B4F9F75FF917
:1008E000059801B4059801B40398034604BC02BC02
:1008F0000098F9F7A0F801BCF9F778F90598F9F72D
:1009000075F901B000BD00B5002001B40020E8F782
:1009100013FB0090FFE7009801B000BDFFFF00004F
:1009200020B50D46002001B401B404200190002040
:100930000090009801B40298014601BCF8F767FDE9
:10094000002805D000980121F8F785FD0090F0E718
:1009500000200021F8F75BFD002800D0FFE702B07F
:1009600020BD0000FFFF000020B50D46002001B4AF
:1009700001B40120002819D004200121F8F76BFDF3
:10098000019000200090009801B40298014601BC3B
:10099000F8F73DFD002805D000980121F8F75BFD30
:1009A0000090F0E71420E7F79BFDE2E702B020BDDE
:1009B000FFFF000020B50D466420E7F791FD20BD44
:1009C000FFFF05000500000000000000010001001D
:1009D0000000000000010000000100010101002AE8
:1009E000FFFF060048656C6C6F21000000000000EE
:1009F00041140E2FB82FA2BB55006F03000000005A
:100A00007B22636F6D7072657373696F6E223A2219
:100A10004C5A4D41222C2268656164657253697A93
:100A200065223A3133352C227465787453697A65BE
:100A3000223A343236362C226E616D65223A2261BA
:100A400077652D696E73706972696E672073637262
:100A5000697074227D5D000080003111000000008B
:100A60000000003D888867041CBCC1C8A255788678
:100A70009B4D69261C354501421948E37B0692B21D
:100A8000DBE3A99A218E18EFA56421FF3A50DF5CC1
:100A9000B84D25B831BC1D9BD0A3720BD23F361682
:100AA0006C9FFADA84711D2EC9AC893737C3C8E24E
:100AB0003144571FA844D7A3963E762405463739BC
:100AC000562C2741749E7ADF8947F2C0F16D27E6E4
:100AD000671D21D7B68962CD4A32EB0C6D831DCEDE
:100AE000D938679D3E575063D676C5D1AD67714AF8
:100AF000DF5E908FB74BF1BA71BE31AF0D068F211B
:100B000042E1428B1A26AEB037DFB75E85844F6F65
:100B10007EFD07E78A8E10F0509394D2D3D10F89CF
:100B200079E24994B05EC5B4191F8F8732BA2EADF1
:100B3000BDA33AEA6B799E8F238650EED8A213129A
:100B40004CE8DBDF1CBC54075FAB965AB71F196437
:100B500057356BE317D9558961C31B5E7A253D8BE9
:100B6000101FCAEA6E9334AFDEB378209D13B0B283
:100B7000BBD03BC203BE98A78036163F9B529787D7
:100B800047E2EBB8DB41A6C2DE8D0437572CBDC867
:100B900070C5D57E332A3633384DAC966B5EE0F89F
:100BA0001A4FFBEE3BD5FE46C1FF358742209871B8
:100BB000585520F96EAAEF9324E9B1252895D54719
:100BC0006CFC464A13EB3A3899E7D46BA3C2027B1C
:100BD0008A502E8AA3F91A7AFD6DD225F44D72102F
:100BE00013FB3F888E41786D06AA9C6CBC12DB4DCE
:100BF000FCEAB9619A1C30A75D2426231876ED041F
:100C0000E1F6A1976F1202A06C6DA23FB9ED17B982
:100C10004661EAE80727E90B820F1648E858286B77
:100C2000C4312974DA972D1A5681A72E31DA22FFA2
:100C3000C68CE7BBCBACAA9EBD6FF5C91D62E4B9FB
:100C40009C1B6E664633ECFCC88C169A8DF048539C
:100C50009687FAB48B5DD1A1CC7568CBA05DBDC27F
:100C6000E485A7A1BA020C34F54A5876D5793EF24C
:100C7000240921FA568D22B801545A7140A289D50F
:100C8000C96E7F553E45B8911C762CA743E18DDF98
:100C90007FDB0D260FF7DC95B1454CB8B4A06BEEA9
:100CA000BBAB7A21557231ADDA411E05EDAD8E7ABE
:100CB000FCE220D686E36BD35922FC6BDA31BDD43B
:100CC000FF06648ED8A908BADFF63CE91A3B5874CF
:100CD00070836F6C9461A68A19299865D6BA06B894
:100CE00063C874A840820066F1BD40FC0816A4F8F1
:100CF000B8505B1E18047413CFA130569896E37950
:100D0000941201C53A972167887F1258FB9D85B3DD
:100D1000D1111EFAFB63E87B849CE3166143E8F281
:100D2000B3EA7C8B03B40E241F13F43DD24309ECC9
:100D30000B7F066F94CC1DFC0606F9B2284BA2BDB2
:100D4000BBBA5A03F54A5646DB56956B1D5CEC9FC1
:100D50005112F313C27CED0D7921A38A36C35D01D4
:100D6000485A30A244E32C82C52EEB6C9F260F51CB
:100D700076E9E1C367F794A852FDAC99CA3B1364C6
:100D80006F4F839EA694170E8339279977896845FC
:100D900011BD5F9646D7966E61E47FCF282FBD4C7C
:100DA0001709BFF597D59E441D6CDB5B74C44A1DC3
:100DB000C29F9A9190DFE13600061A2252F094FF0A
:100DC000BEF48D7000000000000000000000000074
:10C00000903C002061DC030073DC030075DC03005E
:10C010000000000000000000000000000000000020
:10C0200000000000000000000000000069C10300E3

View File

@ -29,7 +29,7 @@
*******************************/
@mainMenuHeight: 5rem;
@mobileMenuHeight: 5rem;
@mobileMenuHeight: 4.4rem;
@simulatorBackground: #FDFDFF;
@blocklySvgColor: #ecf0f1;

View File

@ -57,6 +57,7 @@
.blocklyToolboxDiv, .monacoToolboxDiv {
background-color: white !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);
}
.blocklyFlyoutBackground {
@ -76,12 +77,12 @@
/* Blockly Toolbox Buttons */
.blocklyToolboxButtons .blocklyAddPackageButton {
&:extend(.ui.inverted.pink.button all);
&:extend(.circular all);
&:extend(.ui.circular.button all);
}
.blocklyToolboxButtons .blocklyUndoButton {
&:extend(.ui.inverted.blue.button all);
&:extend(.circular all);
&:extend(.ui.circular.button all);
}
/*******************************
@ -111,44 +112,16 @@
#filelist {
background: transparent !important;
}
.organization {
top: auto;
}
}
/* Tablet */
@media only screen and (min-width: @tabletBreakpoint) and (max-width: @largestTabletScreen) {
.organization {
top: auto;
}
/* Blockly Toolbox buttons */
#blocklyToolboxButtons, #monacoToolboxButtons {
margin-right: 0.5rem;
margin-left: 0.5rem;
}
}
/* Small Monitor */
@media only screen and (min-width: @computerBreakpoint) and (max-width: @largestSmallMonitor) {
.organization {
top: auto;
}
/* Blockly Toolbox buttons */
#blocklyToolboxButtons, #monacoToolboxButtons {
margin-right: 1rem;
margin-left: 1rem;
}
}
/* Large Monitor */
@media only screen and (min-width: @largeMonitorBreakpoint) {
.blocklyTreeRow {
width: 230px;
padding-left: 1rem;
}
/* Blockly Toolbox buttons */
#blocklyToolboxButtons, #monacoToolboxButtons {
margin-right: 2rem;
margin-left: 2rem;
}
}