Compare commits

...

27 Commits

Author SHA1 Message Date
Peli de Halleux
3bf6f9a2ae typo 2018-02-13 08:00:45 -08:00
Peli de Halleux
74f38d41a3 upgrading pxt 2018-02-13 07:58:00 -08:00
Peli de Halleux
34af44d299 badge does not work 2017-12-15 14:54:29 -08:00
Peli de Halleux
1199845c52 added build status 2017-12-15 14:53:51 -08:00
Peli de Halleux
003150643d run latest bump build until live 2017-12-15 14:49:36 -08:00
Peli de Halleux
500de7fb13 1.0.20 2017-12-15 14:47:23 -08:00
Peli de Halleux
88934881f9 upgrading various simulator parts 2017-12-15 14:45:38 -08:00
Peli de Halleux
433e8c8805 adding neopixel/microturtle 2017-12-15 14:42:11 -08:00
Sam El-Husseini
b8b7d3d1b8 1.0.19 2017-12-14 13:31:15 -08:00
Sam El-Husseini
052cca94a2 UI changes to be inline with latest v0 (#16) 2017-12-14 13:30:47 -08:00
Peli de Halleux
93dd793fb7 Merge branch 'master' of https://github.com/Microsoft/pxt-calliope 2017-12-14 11:50:29 -08:00
Peli de Halleux
41c2012d42 windows app squeleton 2017-12-14 11:50:24 -08:00
Peli de Halleux
d4934b19d1 Update README.md 2017-12-14 11:24:44 -08:00
Peli de Halleux
4f741981e3 1.0.18 2017-12-14 11:22:23 -08:00
Peli de Halleux
e93ae5e01b adjusting old styles 2017-12-14 11:21:55 -08:00
Peli de Halleux
baee733aad 1.0.17 2017-12-14 11:06:09 -08:00
Peli de Halleux
13f252c6f4 support for icons (#15) 2017-12-14 11:04:59 -08:00
Peli de Halleux
694c24406f 1.0.16 2017-12-14 11:01:07 -08:00
Peli de Halleux
2250aa9d4b Upgrades (#14)
* enable tracing

* more config adjustments

* upgrading images

* upgrading input

* upgrading led

* upgraded pins api

* upgrade runtime

* upgrading pxt.h

* upgrading basic.cpp

* upgraded control

* upgraded control.ts

* upgrading core.cpp

* updating shims

* fixing merge issues

* upgrading BLE config
2017-12-14 11:00:47 -08:00
Peli de Halleux
a1f1911eb0 Merge branch 'master' of https://github.com/Microsoft/pxt-calliope 2017-12-14 10:40:07 -08:00
Peli de Halleux
a5f8e9a643 upgrading game apis (#13) 2017-12-14 10:34:32 -08:00
Peli de Halleux
5a6cbf2639 upgrading music APIs (#12) 2017-12-14 10:34:04 -08:00
Peli de Halleux
ff11e70c84 more config adjustments 2017-12-14 09:57:49 -08:00
Peli de Halleux
a6487f62c0 enable tracing 2017-12-14 09:53:08 -08:00
Peli de Halleux
63047454cb 1.0.15 2017-12-14 08:59:49 -08:00
Peli de Halleux
1373c2616c enabling functions and arrays 2017-12-14 08:59:39 -08:00
Peli de Halleux
739584e465 bump master to 1.0.13 2017-12-14 05:30:11 -08:00
92 changed files with 2494 additions and 854 deletions

View File

@@ -1,10 +1,9 @@
# Calliope target for Microsoft MakeCode # Calliope target for Microsoft MakeCode
This target is hosted at https://makecode.calliope.cc. This target is hosted at https://makecode.calliope.cc.
## Hosted editor and build ## Hosted editor and build
Hosted at: https://c371bd6d-007a-42fb-a45c-39891824b813.pxt.io</br>
Jenkins build: https://ci2.dot.net/job/Private/job/pxt_project_teal/job/master/ Jenkins build: https://ci2.dot.net/job/Private/job/pxt_project_teal/job/master/

View File

@@ -1,3 +1,3 @@
{ {
"appref": "v0.8.30" "appref": "v"
} }

View File

@@ -17,44 +17,18 @@
"config": { "config": {
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {
"enabled": 1, "enabled": 1
"pairing_mode": 1,
"private_addressing": 0,
"open": 0,
"whitelist": 1,
"advertising_timeout": 0,
"tx_power": 6,
"dfu_service": 1,
"event_service": 0,
"device_info_service": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM",
"eddystone_url": 1,
"eddystone_uid": 1
} }
} }
}, },
"optionalConfig": { "optionalConfig": {
"microbit-dal": { "microbit-dal": {
"bluetooth": {
"private_addressing": 0,
"advertising_timeout": 0,
"tx_power": 6,
"dfu_service": 1,
"event_service": 1,
"device_info_service": 1,
"eddystone_url": 1,
"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": [ "userConfigs": [
{ {
"description": "Unsecure: Anyone can connect via Bluetooth.", "description": "No Pairing Required: Anyone can connect via Bluetooth.",
"config": { "config": {
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {
@@ -67,7 +41,7 @@
} }
}, },
{ {
"description": "JustWorks pairing (default): Button press to pair.", "description": "JustWorks pairing (default): Pairing is automatic once the pairing is initiated.",
"config": { "config": {
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {
@@ -80,7 +54,7 @@
} }
}, },
{ {
"description": "Passkey pairing: Button press and 6 digit key to pair.", "description": "Passkey pairing: Pairing requires 6 digit key to pair.",
"config": { "config": {
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {

View File

@@ -58,6 +58,7 @@
"EventCreationMode": "How to create the event.", "EventCreationMode": "How to create the event.",
"EventCreationMode.CreateAndFire": "MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).", "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.", "EventCreationMode.CreateOnly": "MicroBitEvent is initialised, and no further processing takes place.",
"Gesture.EightG": "Raised when a 8G shock is detected",
"Gesture.FreeFall": "Raised when the board is falling!", "Gesture.FreeFall": "Raised when the board is falling!",
"Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical", "Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical",
"Gesture.LogoUp": "Raised when the logo is upward and the screen is vertical", "Gesture.LogoUp": "Raised when the logo is upward and the screen is vertical",
@@ -138,7 +139,12 @@
"basic.showAnimation": "Shows a sequence of LED screens as an animation.", "basic.showAnimation": "Shows a sequence of LED screens as an animation.",
"basic.showAnimation|param|interval": "time in milliseconds between each redraw", "basic.showAnimation|param|interval": "time in milliseconds between each redraw",
"basic.showAnimation|param|leds": "pattern of LEDs to turn on/off", "basic.showAnimation|param|leds": "pattern of LEDs to turn on/off",
"basic.showArrow": "Shows an arrow on screent",
"basic.showArrow|param|direction": "the direction of the arrow",
"basic.showArrow|param|interval": "the amount of time (milliseconds) to show the icon. Default is 600.",
"basic.showIcon": "Draws the selected icon on the LED screen", "basic.showIcon": "Draws the selected icon on the LED screen",
"basic.showIcon|param|icon": "the predifined icon id",
"basic.showIcon|param|interval": "the amount of time (milliseconds) to show the icon. Default is 600.",
"basic.showLeds": "Draws an image on the LED screen.", "basic.showLeds": "Draws an image on the LED screen.",
"basic.showLeds|param|interval": "time in milliseconds to pause after drawing", "basic.showLeds|param|interval": "time in milliseconds to pause after drawing",
"basic.showLeds|param|leds": "the pattern of LED to turn on/off", "basic.showLeds|param|leds": "the pattern of LED to turn on/off",
@@ -167,13 +173,14 @@
"control.waitMicros": "Blocks the current fiber for the given microseconds", "control.waitMicros": "Blocks the current fiber for the given microseconds",
"control.waitMicros|param|micros": "number of micro-seconds to wait. eg: 4", "control.waitMicros|param|micros": "number of micro-seconds to wait. eg: 4",
"game": "A single-LED sprite game engine", "game": "A single-LED sprite game engine",
"game.LedSprite": "A game sprite rendered as a single LED",
"game.LedSprite.blink": "Reports the ``blink`` duration of a sprite", "game.LedSprite.blink": "Reports the ``blink`` duration of a sprite",
"game.LedSprite.brightness": "Reports the ``brightness` of a sprite on the LED screen", "game.LedSprite.brightness": "Reports the ``brightness` of a sprite on the LED screen",
"game.LedSprite.change": "Changes a property of the sprite", "game.LedSprite.change": "Changes a property of the sprite",
"game.LedSprite.changeBlinkBy": "Changes the ``blink`` duration by the given amount of millisecons", "game.LedSprite.changeBlinkBy": "Changes the ``blink`` duration by the given amount of millisecons",
"game.LedSprite.changeBlinkBy|param|ms": "TODO", "game.LedSprite.changeBlinkBy|param|ms": "TODO",
"game.LedSprite.changeBrightnessBy": "Changes the ``y`` position by the given amount", "game.LedSprite.changeBrightnessBy": "Changes the ``y`` position by the given amount",
"game.LedSprite.changeBrightnessBy|param|value": "TODO", "game.LedSprite.changeBrightnessBy|param|value": "the value to change brightness",
"game.LedSprite.changeDirectionBy": "Changes the ``direction`` position by the given amount by turning right", "game.LedSprite.changeDirectionBy": "Changes the ``direction`` position by the given amount by turning right",
"game.LedSprite.changeDirectionBy|param|angle": "TODO", "game.LedSprite.changeDirectionBy|param|angle": "TODO",
"game.LedSprite.changeXBy": "Changes the ``x`` position by the given amount", "game.LedSprite.changeXBy": "Changes the ``x`` position by the given amount",
@@ -182,19 +189,18 @@
"game.LedSprite.changeYBy|param|y": "TODO", "game.LedSprite.changeYBy|param|y": "TODO",
"game.LedSprite.change|param|property": "the name of the property to change", "game.LedSprite.change|param|property": "the name of the property to change",
"game.LedSprite.change|param|value": "amount of change, eg: 1", "game.LedSprite.change|param|value": "amount of change, eg: 1",
"game.LedSprite.delete": "Deletes the sprite from the game engine. All further operation of the sprite will not have any effect.", "game.LedSprite.delete": "Deletes the sprite from the game engine. The sprite will no longer appear on the screen or interact with other sprites.",
"game.LedSprite.delete|param|sprite": "TODO",
"game.LedSprite.direction": "Reports the current direction of a sprite", "game.LedSprite.direction": "Reports the current direction of a sprite",
"game.LedSprite.get": "Gets a property of the sprite", "game.LedSprite.get": "Gets a property of the sprite",
"game.LedSprite.get|param|property": "the name of the property to change", "game.LedSprite.get|param|property": "the name of the property to change",
"game.LedSprite.goTo": "Go to this position on the screen", "game.LedSprite.goTo": "Go to this position on the screen",
"game.LedSprite.goTo|param|x": "TODO", "game.LedSprite.goTo|param|x": "TODO",
"game.LedSprite.goTo|param|y": "TODO", "game.LedSprite.goTo|param|y": "TODO",
"game.LedSprite.ifOnEdgeBounce": "If touching the edge of the stage, then bounce away.", "game.LedSprite.ifOnEdgeBounce": "If touching the edge of the stage and facing towards it, then turn away.",
"game.LedSprite.isTouching": "Reports true if sprite is touching specified sprite", "game.LedSprite.isTouching": "Reports true if sprite has the same position as specified sprite",
"game.LedSprite.isTouchingEdge": "Reports true if sprite is touching an edge", "game.LedSprite.isTouchingEdge": "Reports true if sprite is touching an edge",
"game.LedSprite.isTouching|param|other": "TODO", "game.LedSprite.isTouching|param|other": "TODO",
"game.LedSprite.move": "Move a certain number of LEDs", "game.LedSprite.move": "Move a certain number of LEDs in the current direction",
"game.LedSprite.move|param|leds": "number of leds to move, eg: 1, -1", "game.LedSprite.move|param|leds": "number of leds to move, eg: 1, -1",
"game.LedSprite.off": "Turns off the sprite (on by default)", "game.LedSprite.off": "Turns off the sprite (on by default)",
"game.LedSprite.on": "Turns on the sprite (on by default)", "game.LedSprite.on": "Turns on the sprite (on by default)",
@@ -202,7 +208,7 @@
"game.LedSprite.setBlink": "Sets the blink duration interval in millisecond.", "game.LedSprite.setBlink": "Sets the blink duration interval in millisecond.",
"game.LedSprite.setBlink|param|ms": "TODO", "game.LedSprite.setBlink|param|ms": "TODO",
"game.LedSprite.setBrightness": "Set the ``brightness`` of a sprite", "game.LedSprite.setBrightness": "Set the ``brightness`` of a sprite",
"game.LedSprite.setBrightness|param|brightness": "TODO", "game.LedSprite.setBrightness|param|brightness": "the brightness from 0 (off) to 255 (on), eg: 255.",
"game.LedSprite.setDirection": "Set the direction of the current sprite, rounded to the nearest multiple of 45", "game.LedSprite.setDirection": "Set the direction of the current sprite, rounded to the nearest multiple of 45",
"game.LedSprite.setDirection|param|degrees": "TODO", "game.LedSprite.setDirection|param|degrees": "TODO",
"game.LedSprite.setX": "Set the ``x`` position of a sprite", "game.LedSprite.setX": "Set the ``x`` position of a sprite",
@@ -221,28 +227,31 @@
"game.LedSprite.y": "Reports the ``y`` position of a sprite on the LED screen", "game.LedSprite.y": "Reports the ``y`` position of a sprite on the LED screen",
"game.addLife": "Adds life points to the current life", "game.addLife": "Adds life points to the current life",
"game.addLife|param|lives": "TODO", "game.addLife|param|lives": "TODO",
"game.addScore": "Adds points to the current score", "game.addScore": "Adds points to the current score and shows an animation",
"game.addScore|param|points": "amount of points to change, eg: 1", "game.addScore|param|points": "amount of points to change, eg: 1",
"game.createSprite": "Creates a new LED sprite pointing to the right.", "game.createSprite": "Creates a new LED sprite pointing to the right.",
"game.createSprite|param|x": "sprite horizontal coordinate, eg: 2", "game.createSprite|param|x": "sprite horizontal coordinate, eg: 2",
"game.createSprite|param|y": "sprite vertical coordinate, eg: 2", "game.createSprite|param|y": "sprite vertical coordinate, eg: 2",
"game.currentTime": "Gets the remaining time (since `start countdown`) or current time (since the device started or `start stopwatch`) in milliseconds.", "game.currentTime": "Gets the remaining time (since `start countdown`) or current time (since the device started or `start stopwatch`) in milliseconds.",
"game.gameOver": "Displays a game over animation.", "game.gameOver": "Displays a game over animation and the score.",
"game.invalidSprite": "Gets an invalid sprite; used to initialize locals.", "game.invalidSprite": "Gets an invalid sprite; used to initialize locals.",
"game.isGameOver": "Indicates if the game is display the game over sequence.", "game.isGameOver": "Indicates if the game is display the game over sequence.",
"game.isPaused": "Indicates if the game rendering is paused to allow other animations",
"game.isRunning": "Gets a value indicating if the game is still running. Returns `false` if game over.", "game.isRunning": "Gets a value indicating if the game is still running. Returns `false` if game over.",
"game.level": "Gets the current level", "game.level": "Gets the current level",
"game.levelUp": "Increments the level and display a message.", "game.levelUp": "Increments the level and display a message.",
"game.life": "Gets the current life", "game.life": "Gets the current life",
"game.pause": "Pauses the game rendering engine to allow other animations",
"game.removeLife": "Removes some life", "game.removeLife": "Removes some life",
"game.removeLife|param|life": "TODO", "game.removeLife|param|life": "TODO",
"game.resume": "Resumes the game rendering engine",
"game.score": "Gets the current score", "game.score": "Gets the current score",
"game.setLife": "Sets the current life value", "game.setLife": "Sets the current life value",
"game.setLife|param|value": "TODO", "game.setLife|param|value": "TODO",
"game.setScore": "Sets the current score value", "game.setScore": "Sets the current score value",
"game.setScore|param|value": "TODO", "game.setScore|param|value": "new score value.",
"game.showScore": "Displays the score on the screen.", "game.showScore": "Displays the score on the screen.",
"game.startCountdown": "Starts a game countdown timer", "game.startCountdown": "Shows an animation, then starts a game countdown timer, which causes Game Over when it reaches 0",
"game.startCountdown|param|ms": "countdown duration in milliseconds, eg: 10000", "game.startCountdown|param|ms": "countdown duration in milliseconds, eg: 10000",
"game.startStopwatch": "Starts a stopwatch timer. `current time` will return the elapsed time.", "game.startStopwatch": "Starts a stopwatch timer. `current time` will return the elapsed time.",
"images": "Creation, manipulation and display of LED images.", "images": "Creation, manipulation and display of LED images.",
@@ -252,26 +261,28 @@
"input.acceleration": "Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)", "input.acceleration": "Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)",
"input.acceleration|param|dimension": "TODO", "input.acceleration|param|dimension": "TODO",
"input.buttonIsPressed": "Get the button state (pressed or not) for ``A`` and ``B``.", "input.buttonIsPressed": "Get the button state (pressed or not) for ``A`` and ``B``.",
"input.calibrate": "Obsolete, compass calibration is automatic.", "input.buttonIsPressed|param|button": "the button to query the request, eg: Button.A",
"input.calibrateCompass": "Obsolete, compass calibration is automatic.",
"input.compassHeading": "Get the current compass heading in degrees.", "input.compassHeading": "Get the current compass heading in degrees.",
"input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.", "input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.",
"input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.", "input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.",
"input.magneticForce|param|dimension": "TODO", "input.magneticForce|param|dimension": "TODO",
"input.onButtonPressed": "Do something when a button (``A``, ``B`` or both ``A+B``) is pressed", "input.onButtonPressed": "Do something when a button (A, B or both A+B) is pushed down and released again.",
"input.onButtonPressed|param|body": "TODO", "input.onButtonPressed|param|body": "code to run when event is raised",
"input.onButtonPressed|param|button": "TODO", "input.onButtonPressed|param|button": "the button that needs to be pressed",
"input.onGesture": "Do something when when a gesture is done (like shaking the micro:bit).", "input.onGesture": "Do something when when a gesture is done (like shaking the micro:bit).",
"input.onGesture|param|body": "TODO", "input.onGesture|param|body": "code to run when gesture is raised",
"input.onGesture|param|gesture": "the type of gesture to track, eg: Gesture.Shake",
"input.onLogoDown": "Attaches code to run when the logo is oriented downwards and the board is vertical.", "input.onLogoDown": "Attaches code to run when the logo is oriented downwards and the board is vertical.",
"input.onLogoDown|param|body": "TODO", "input.onLogoDown|param|body": "TODO",
"input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.", "input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.",
"input.onLogoUp|param|body": "TODO", "input.onLogoUp|param|body": "TODO",
"input.onPinPressed": "Do something when a pin is pressed.", "input.onPinPressed": "Do something when a pin is touched and released again (while also touching the GND pin).",
"input.onPinPressed|param|body": "the code to run when the pin is pressed", "input.onPinPressed|param|body": "the code to run when the pin is pressed",
"input.onPinPressed|param|name": "the pin that needs to be pressed", "input.onPinPressed|param|name": "the pin that needs to be pressed, eg: TouchPin.P0",
"input.onPinReleased": "Do something when a pin is released.", "input.onPinReleased": "Do something when a pin is released.",
"input.onPinReleased|param|body": "the code to run when the pin is released", "input.onPinReleased|param|body": "the code to run when the pin is released",
"input.onPinReleased|param|name": "the pin that needs to be released", "input.onPinReleased|param|name": "the pin that needs to be released, eg: TouchPin.P0",
"input.onScreenDown": "Attaches code to run when the screen is facing down.", "input.onScreenDown": "Attaches code to run when the screen is facing down.",
"input.onScreenDown|param|body": "TODO", "input.onScreenDown|param|body": "TODO",
"input.onScreenUp": "Attaches code to run when the screen is facing up.", "input.onScreenUp": "Attaches code to run when the screen is facing up.",
@@ -279,15 +290,17 @@
"input.onShake": "Attaches code to run when the device is shaken.", "input.onShake": "Attaches code to run when the device is shaken.",
"input.onShake|param|body": "TODO", "input.onShake|param|body": "TODO",
"input.pinIsPressed": "Get the pin state (pressed or not). Requires to hold the ground to close the circuit.", "input.pinIsPressed": "Get the pin state (pressed or not). Requires to hold the ground to close the circuit.",
"input.pinIsPressed|param|name": "pin used to detect the touch", "input.pinIsPressed|param|name": "pin used to detect the touch, eg: TouchPin.P0",
"input.rotation": "The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.", "input.rotation": "The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.",
"input.rotation|param|kind": "TODO", "input.rotation|param|kind": "TODO",
"input.runningTime": "Gets the number of milliseconds elapsed since power on.", "input.runningTime": "Gets the number of milliseconds elapsed since power on.",
"input.runningTimeMicros": "Gets the number of microseconds elapsed since power on.",
"input.setAccelerometerRange": "Sets the accelerometer sample range in gravities.", "input.setAccelerometerRange": "Sets the accelerometer sample range in gravities.",
"input.setAccelerometerRange|param|range": "a value describe the maximum strengh of acceleration measured", "input.setAccelerometerRange|param|range": "a value describe the maximum strengh of acceleration measured",
"input.temperature": "Gets the temperature in Celsius degrees (°C).", "input.temperature": "Gets the temperature in Celsius degrees (°C).",
"led": "Control of the LED screen.", "led": "Control of the LED screen.",
"led.brightness": "Get the screen brightness from 0 (off) to 255 (full bright).", "led.brightness": "Get the screen brightness from 0 (off) to 255 (full bright).",
"led.displayMode": "Gets the current display mode",
"led.enable": "Turns on or off the display", "led.enable": "Turns on or off the display",
"led.fadeIn": "Fades in the screen display.", "led.fadeIn": "Fades in the screen display.",
"led.fadeIn|param|ms": "TODO", "led.fadeIn|param|ms": "TODO",
@@ -298,8 +311,12 @@
"led.plotBarGraph": "Displays a vertical bar graph based on the `value` and `high` value.\nIf `high` is 0, the chart gets adjusted automatically.", "led.plotBarGraph": "Displays a vertical bar graph based on the `value` and `high` value.\nIf `high` is 0, the chart gets adjusted automatically.",
"led.plotBarGraph|param|high": "maximum value. If 0, maximum value adjusted automatically, eg: 0", "led.plotBarGraph|param|high": "maximum value. If 0, maximum value adjusted automatically, eg: 0",
"led.plotBarGraph|param|value": "current value to plot", "led.plotBarGraph|param|value": "current value to plot",
"led.plot|param|x": "TODO", "led.plotBrightness": "Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.",
"led.plot|param|y": "TODO", "led.plotBrightness|param|brightness": "the brightness from 0 (off) to 255 (bright), eg:255",
"led.plotBrightness|param|x": "the horizontal coordinate of the LED starting at 0",
"led.plotBrightness|param|y": "the vertical coordinate of the LED starting at 0",
"led.plot|param|x": "the horizontal coordinate of the LED starting at 0",
"led.plot|param|y": "the vertical coordinate of the LED starting at 0",
"led.point": "Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.", "led.point": "Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.",
"led.point|param|x": "TODO", "led.point|param|x": "TODO",
"led.point|param|y": "TODO", "led.point|param|y": "TODO",
@@ -321,43 +338,52 @@
"motors.motorCommand": "Send break, coast or sleep commands to the motor. Has no effect in dual-motor mode.", "motors.motorCommand": "Send break, coast or sleep commands to the motor. Has no effect in dual-motor mode.",
"motors.motorPower": "Turns on the motor at a certain percent of power. Switches to single motor mode!", "motors.motorPower": "Turns on the motor at a certain percent of power. Switches to single motor mode!",
"motors.motorPower|param|power": "%percent of power sent to the motor. Negative power goes backward. eg: 50", "motors.motorPower|param|power": "%percent of power sent to the motor. Negative power goes backward. eg: 50",
"music": "Generation of music tones through pin ``P0``.", "music": "Generation of music tones.",
"music.beat": "Returns the duration of a beat in milli-seconds", "music.beat": "Returns the duration of a beat in milli-seconds",
"music.beginMelody": "Starts playing a melody.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
"music.beginMelody|param|melodyArray": "the melody array to play, eg: ['g5:1']",
"music.beginMelody|param|options": "melody options, once / forever, in the foreground / background",
"music.builtInMelody": "Gets the melody array of a built-in melody.",
"music.changeTempoBy": "Change the tempo by the specified amount", "music.changeTempoBy": "Change the tempo by the specified amount",
"music.changeTempoBy|param|bpm": "The change in beats per minute to the tempo, eg: 20", "music.changeTempoBy|param|bpm": "The change in beats per minute to the tempo, eg: 20",
"music.noteFrequency": "Gets the frequency of a note.", "music.noteFrequency": "Gets the frequency of a note.",
"music.noteFrequency|param|name": "the note name", "music.noteFrequency|param|name": "the note name, eg: Note.C",
"music.playTone": "Plays a tone through ``speaker`` for the given duration.", "music.onEvent": "Registers code to run on various melody events",
"music.playTone": "Plays a tone through pin ``P0`` for the given duration.",
"music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz)", "music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.playTone|param|ms": "tone duration in milliseconds (ms)", "music.playTone|param|ms": "tone duration in milliseconds (ms)",
"music.rest": "Rests (plays nothing) for a specified time through pin ``P0``.", "music.rest": "Rests (plays nothing) for a specified time through pin ``P0``.",
"music.rest|param|ms": "rest duration in milliseconds (ms)", "music.rest|param|ms": "rest duration in milliseconds (ms)",
"music.ringTone": "Plays a tone through ``speaker``.", "music.ringTone": "Plays a tone through pin ``P0``.",
"music.ringTone|param|frequency": "pitch of the tone to play in Hertz (Hz)", "music.ringTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.setPlayTone": "Sets a custom playTone function for playing melodies",
"music.setTempo": "Sets the tempo to the specified amount", "music.setTempo": "Sets the tempo to the specified amount",
"music.setTempo|param|bpm": "The new tempo in beats per minute, eg: 120", "music.setTempo|param|bpm": "The new tempo in beats per minute, eg: 120",
"music.speakerPlayTone": "Plays a tone through ``speaker`` for the given duration.",
"music.speakerPlayTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.speakerPlayTone|param|ms": "tone duration in milliseconds (ms)",
"music.tempo": "Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.", "music.tempo": "Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.",
"parseInt": "Convert A string to an integer.", "parseInt": "Convert A string to an integer.",
"pins": "Control currents in Pins for analog/digital signals, servos, i2c, ...", "pins": "Control currents in Pins for analog/digital signals, servos, i2c, ...",
"pins.analogPitch": "Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.", "pins.analogPitch": "Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.",
"pins.analogPitch|param|frequency": "TODO", "pins.analogPitch|param|frequency": "frequency to modulate in Hz.",
"pins.analogPitch|param|ms": "TODO", "pins.analogPitch|param|ms": "duration of the pitch in milli seconds.",
"pins.analogReadPin": "Read the connector value as analog, that is, as a value comprised between 0 and 1023.", "pins.analogReadPin": "Read the connector value as analog, that is, as a value comprised between 0 and 1023.",
"pins.analogReadPin|param|name": "pin to write to", "pins.analogReadPin|param|name": "pin to write to, eg: AnalogPin.P0",
"pins.analogSetPeriod": "Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.\nIf this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.", "pins.analogSetPeriod": "Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.\nIf this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.",
"pins.analogSetPeriod|param|micros": "period in micro seconds. eg:20000", "pins.analogSetPeriod|param|micros": "period in micro seconds. eg:20000",
"pins.analogSetPeriod|param|name": "analog pin to set period to", "pins.analogSetPeriod|param|name": "analog pin to set period to, eg: AnalogPin.P0",
"pins.analogSetPitchPin": "Sets the pin used when using `pins->analog pitch`.", "pins.analogSetPitchPin": "Sets the pin used when using `analog pitch` or music.",
"pins.analogSetPitchPin|param|name": "TODO", "pins.analogSetPitchPin|param|name": "pin to modulate pitch from",
"pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.", "pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.",
"pins.analogWritePin|param|name": "pin name to write to", "pins.analogWritePin|param|name": "pin name to write to, eg: AnalogPin.P0",
"pins.analogWritePin|param|value": "value to write to the pin between ``0`` and ``1023``. eg:1023,0", "pins.analogWritePin|param|value": "value to write to the pin between ``0`` and ``1023``. eg:1023,0",
"pins.createBuffer": "Create a new zero-initialized buffer.", "pins.createBuffer": "Create a new zero-initialized buffer.",
"pins.createBuffer|param|size": "number of bytes in the buffer", "pins.createBuffer|param|size": "number of bytes in the buffer",
"pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1", "pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1",
"pins.digitalReadPin|param|name": "pin to read from", "pins.digitalReadPin|param|name": "pin to read from, eg: DigitalPin.P0",
"pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.", "pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.",
"pins.digitalWritePin|param|name": "pin to write to", "pins.digitalWritePin|param|name": "pin to write to, eg: DigitalPin.P0",
"pins.digitalWritePin|param|value": "value to set on the pin, 1 eg,0", "pins.digitalWritePin|param|value": "value to set on the pin, 1 eg,0",
"pins.i2cReadBuffer": "Read `size` bytes from a 7-bit I2C `address`.", "pins.i2cReadBuffer": "Read `size` bytes from a 7-bit I2C `address`.",
"pins.i2cReadNumber": "Read one number from 7-bit I2C address.", "pins.i2cReadNumber": "Read one number from 7-bit I2C address.",
@@ -370,23 +396,31 @@
"pins.map|param|toLow": "the lower bound of the value's target range", "pins.map|param|toLow": "the lower bound of the value's target range",
"pins.map|param|value": "value to map in ranges", "pins.map|param|value": "value to map in ranges",
"pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.", "pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.",
"pins.onPulsed|param|name": "digital pin to register to, eg: DigitalPin.P0",
"pins.onPulsed|param|pulse": "the value of the pulse, eg: PulseValue.High",
"pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.", "pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.",
"pins.pulseIn": "Returns the duration of a pulse in microseconds", "pins.pulseIn": "Returns the duration of a pulse in microseconds",
"pins.pulseIn|param|name": "the pin which measures the pulse", "pins.pulseIn|param|name": "the pin which measures the pulse, eg: DigitalPin.P0",
"pins.pulseIn|param|value": "the value of the pulse (default high)", "pins.pulseIn|param|value": "the value of the pulse, eg: PulseValue.High",
"pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.", "pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.",
"pins.servoSetPulse|param|micros": "pulse duration in micro seconds, eg:1500", "pins.servoSetPulse|param|micros": "pulse duration in micro seconds, eg:1500",
"pins.servoSetPulse|param|name": "pin name", "pins.servoSetPulse|param|name": "pin name",
"pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).", "pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).",
"pins.servoWritePin|param|name": "pin to write to", "pins.servoWritePin|param|name": "pin to write to, eg: AnalogPin.P0",
"pins.servoWritePin|param|value": "angle or rotation speed, eg:180,90,0", "pins.servoWritePin|param|value": "angle or rotation speed, eg:180,90,0",
"pins.setEvents": "Configures the events emitted by this pin. Events can be subscribed to\nusing ``control.onEvent()``.", "pins.setEvents": "Configures the events emitted by this pin. Events can be subscribed to\nusing ``control.onEvent()``.",
"pins.setEvents|param|name": "pin to set the event mode on, eg: DigitalPin.P0", "pins.setEvents|param|name": "pin to set the event mode on, eg: DigitalPin.P0",
"pins.setEvents|param|type": "the type of events for this pin to emit, eg: PinEventType.Edge", "pins.setEvents|param|type": "the type of events for this pin to emit, eg: PinEventType.Edge",
"pins.setPull": "Configures the pull of this pin.", "pins.setPull": "Configures the pull of this pin.",
"pins.setPull|param|name": "pin to set the pull mode on", "pins.setPull|param|name": "pin to set the pull mode on, eg: DigitalPin.P0",
"pins.setPull|param|pull": "one of the mbed pull configurations: PullUp, PullDown, PullNone ", "pins.setPull|param|pull": "one of the mbed pull configurations, eg: PinPullMode.PullUp",
"pins.sizeOf": "Get the size in bytes of specified number format.", "pins.sizeOf": "Get the size in bytes of specified number format.",
"pins.spiFormat": "Sets the SPI bits and mode",
"pins.spiFormat|param|bits": "the number of bits, eg: 8",
"pins.spiFormat|param|mode": "the mode, eg: 3",
"pins.spiFrequency": "Sets the SPI frequency",
"pins.spiFrequency|param|frequency": "the clock frequency, eg: 1000000",
"pins.spiPins": "Sets the MOSI, MISO, SCK pins used by the SPI instance",
"pins.spiWrite": "Write to the SPI slave and return the response", "pins.spiWrite": "Write to the SPI slave and return the response",
"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.",

View File

@@ -17,9 +17,19 @@
"Array.shift|block": "get and remove first value from %list", "Array.shift|block": "get and remove first value from %list",
"Array.unshift|block": "%list| insert %value| at beginning", "Array.unshift|block": "%list| insert %value| at beginning",
"Array|block": "Array", "Array|block": "Array",
"ArrowNames.East|block": "East",
"ArrowNames.NorthEast|block": "North East",
"ArrowNames.NorthWest|block": "North West",
"ArrowNames.North|block": "North",
"ArrowNames.SouthEast|block": "South East",
"ArrowNames.SouthWest|block": "South West",
"ArrowNames.South|block": "South",
"ArrowNames.West|block": "West",
"BaudRate.BaudRate115200|block": "115200", "BaudRate.BaudRate115200|block": "115200",
"BaudRate.BaudRate56700|block": "57600", "BaudRate.BaudRate56700|block": "57600",
"BaudRate.BaudRate9600|block": "9600", "BaudRate.BaudRate9600|block": "9600",
"BeatFraction.Breve|block": "4",
"BeatFraction.Double|block": "2",
"BeatFraction.Eighth|block": "1/8", "BeatFraction.Eighth|block": "1/8",
"BeatFraction.Half|block": "1/2", "BeatFraction.Half|block": "1/2",
"BeatFraction.Quarter|block": "1/4", "BeatFraction.Quarter|block": "1/4",
@@ -51,6 +61,8 @@
"DisplayMode.Greyscale|block": "greyscale", "DisplayMode.Greyscale|block": "greyscale",
"EventCreationMode.CreateAndFire": "MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).", "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.", "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": "Raised when the board is falling!",
"Gesture.FreeFall|block": "free fall", "Gesture.FreeFall|block": "free fall",
"Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical", "Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical",
@@ -89,12 +101,12 @@
"IconNames.LeftTriangle|block": "left triangle", "IconNames.LeftTriangle|block": "left triangle",
"IconNames.Meh|block": "meh", "IconNames.Meh|block": "meh",
"IconNames.No|block": "no", "IconNames.No|block": "no",
"IconNames.Pacman|block": "pac man",
"IconNames.Pitchfork|block": "pitchfork", "IconNames.Pitchfork|block": "pitchfork",
"IconNames.QuarterNote|block": "quarter note", "IconNames.QuarterNote|block": "quarter note",
"IconNames.Rabbit|block": "rabbit", "IconNames.Rabbit|block": "rabbit",
"IconNames.Rollerskate|block": "roller skate", "IconNames.Rollerskate|block": "roller skate",
"IconNames.Sad|block": "sad", "IconNames.Sad|block": "sad",
"IconNames.Scissors|block": "scissors",
"IconNames.Silly|block": "silly", "IconNames.Silly|block": "silly",
"IconNames.Skull|block": "skull", "IconNames.Skull|block": "skull",
"IconNames.SmallDiamond|block": "small diamond", "IconNames.SmallDiamond|block": "small diamond",
@@ -121,10 +133,60 @@
"Math.randomBoolean|block": "pick random true or false", "Math.randomBoolean|block": "pick random true or false",
"Math.random|block": "pick random 0 to %limit", "Math.random|block": "pick random 0 to %limit",
"Math|block": "Math", "Math|block": "Math",
"Melodies.BaDing|block": "ba ding",
"Melodies.Baddy|block": "baddy",
"Melodies.Birthday|block": "birthday",
"Melodies.Blues|block": "blues",
"Melodies.Chase|block": "chase",
"Melodies.Dadadadum|block": "dadadum",
"Melodies.Entertainer|block": "entertainer",
"Melodies.Funeral|block": "funereal",
"Melodies.Funk|block": "funk",
"Melodies.JumpDown|block": "jump down",
"Melodies.JumpUp|block": "jump up",
"Melodies.Nyan|block": "nyan",
"Melodies.Ode|block": "ode",
"Melodies.PowerDown|block": "power down",
"Melodies.PowerUp|block": "power up",
"Melodies.Prelude|block": "prelude",
"Melodies.Punchline|block": "punchline",
"Melodies.Ringtone|block": "ringtone",
"Melodies.Wawawawaa|block": "wawawawaa",
"Melodies.Wedding|block": "wedding",
"MelodyOptions.ForeverInBackground|block": "forever in background",
"MelodyOptions.Forever|block": "forever",
"MelodyOptions.OnceInBackground|block": "once in background",
"MelodyOptions.Once|block": "once",
"MesDpadButtonInfo.ADown|block": "A down",
"MesDpadButtonInfo.AUp|block": "A up",
"MesDpadButtonInfo.BDown|block": "B down",
"MesDpadButtonInfo.BUp|block": "B up",
"MesDpadButtonInfo.CDown|block": "C down",
"MesDpadButtonInfo.CUp|block": "C up",
"MesDpadButtonInfo.DDown|block": "D down",
"MesDpadButtonInfo.DUp|block": "D up",
"MesDpadButtonInfo._1Down|block": "1 down",
"MesDpadButtonInfo._1Up|block": "1 up",
"MesDpadButtonInfo._2Down|block": "2 down",
"MesDpadButtonInfo._2Up|block": "2 up",
"MesDpadButtonInfo._3Down|block": "3 down",
"MesDpadButtonInfo._3Up|block": "3 up",
"MesDpadButtonInfo._4Down|block": "4 down",
"MesDpadButtonInfo._4Up|block": "4 up",
"Motor.AB|block": "A and B", "Motor.AB|block": "A and B",
"MotorCommand.Break|block": "break", "MotorCommand.Break|block": "break",
"MotorCommand.Coast|block": "coast", "MotorCommand.Coast|block": "coast",
"MotorCommand.Sleep|block": "sleep", "MotorCommand.Sleep|block": "sleep",
"MusicEvent.BackgroundMelodyEnded|block": "background melody ended",
"MusicEvent.BackgroundMelodyNotePlayed|block": "background melody note played",
"MusicEvent.BackgroundMelodyPaused|block": "background melody paused",
"MusicEvent.BackgroundMelodyRepeated|block": "background melody repeated",
"MusicEvent.BackgroundMelodyResumed|block": "background melody resumed",
"MusicEvent.BackgroundMelodyStarted|block": "background melody started",
"MusicEvent.MelodyEnded|block": "melody ended",
"MusicEvent.MelodyNotePlayed|block": "melody note played",
"MusicEvent.MelodyRepeated|block": "melody repeated",
"MusicEvent.MelodyStarted|block": "melody started",
"Note.CSharp3|block": "C#3", "Note.CSharp3|block": "C#3",
"Note.CSharp4|block": "C#4", "Note.CSharp4|block": "C#4",
"Note.CSharp5|block": "C#5", "Note.CSharp5|block": "C#5",
@@ -177,6 +239,7 @@
"control.waitMicros|block": "wait (µs)%micros", "control.waitMicros|block": "wait (µs)%micros",
"control|block": "control", "control|block": "control",
"game.LedSprite.change|block": "%sprite|change %property|by %value", "game.LedSprite.change|block": "%sprite|change %property|by %value",
"game.LedSprite.delete|block": "delete %this",
"game.LedSprite.get|block": "%sprite|%property", "game.LedSprite.get|block": "%sprite|%property",
"game.LedSprite.ifOnEdgeBounce|block": "%sprite|if on edge, bounce", "game.LedSprite.ifOnEdgeBounce|block": "%sprite|if on edge, bounce",
"game.LedSprite.isTouchingEdge|block": "%sprite|touching edge?", "game.LedSprite.isTouchingEdge|block": "%sprite|touching edge?",
@@ -187,7 +250,10 @@
"game.addScore|block": "change score by|%points", "game.addScore|block": "change score by|%points",
"game.createSprite|block": "create sprite at|x: %x|y: %y", "game.createSprite|block": "create sprite at|x: %x|y: %y",
"game.gameOver|block": "game over", "game.gameOver|block": "game over",
"game.pause|block": "pause",
"game.resume|block": "resume",
"game.score|block": "score", "game.score|block": "score",
"game.setScore|block": "set score %points",
"game.startCountdown|block": "start countdown|(ms) %duration", "game.startCountdown|block": "start countdown|(ms) %duration",
"game|block": "game", "game|block": "game",
"images.arrowImage|block": "arrow image %i=device_arrow", "images.arrowImage|block": "arrow image %i=device_arrow",
@@ -198,21 +264,25 @@
"images|block": "images", "images|block": "images",
"input.acceleration|block": "acceleration (mg)|%NAME", "input.acceleration|block": "acceleration (mg)|%NAME",
"input.buttonIsPressed|block": "button|%NAME|is pressed", "input.buttonIsPressed|block": "button|%NAME|is pressed",
"input.calibrateCompass|block": "calibrate compass",
"input.compassHeading|block": "compass heading (°)", "input.compassHeading|block": "compass heading (°)",
"input.lightLevel|block": "light level", "input.lightLevel|block": "light level",
"input.magneticForce|block": "magnetic force (µT)|%NAME", "input.magneticForce|block": "magnetic force (µT)|%NAME",
"input.onButtonPressed|block": "on button|%NAME|pressed", "input.onButtonPressed|block": "on button|%NAME|pressed",
"input.onGesture|block": "on |%NAME", "input.onGesture|block": "on |%NAME",
"input.onPinPressed|block": "on pin %NAME|pressed", "input.onPinPressed|block": "on pin %name|pressed",
"input.onPinReleased|block": "on pin %NAME|released", "input.onPinReleased|block": "on pin %NAME|released",
"input.pinIsPressed|block": "pin %NAME|is pressed", "input.pinIsPressed|block": "pin %NAME|is pressed",
"input.rotation|block": "rotation (°)|%NAME", "input.rotation|block": "rotation (°)|%NAME",
"input.runningTimeMicros|block": "running time (micros)",
"input.runningTime|block": "running time (ms)", "input.runningTime|block": "running time (ms)",
"input.setAccelerometerRange|block": "set accelerometer|range %range", "input.setAccelerometerRange|block": "set accelerometer|range %range",
"input.temperature|block": "temperature (°C)", "input.temperature|block": "temperature (°C)",
"input|block": "input", "input|block": "input",
"led.brightness|block": "brightness", "led.brightness|block": "brightness",
"led.enable|block": "led enable %on",
"led.plotBarGraph|block": "plot bar graph of %value |up to %high", "led.plotBarGraph|block": "plot bar graph of %value |up to %high",
"led.plotBrightness|block": "plot|x %x|y %y|brightness %brightness",
"led.plot|block": "plot|x %x|y %y", "led.plot|block": "plot|x %x|y %y",
"led.point|block": "point|x %x|y %y", "led.point|block": "point|x %x|y %y",
"led.setBrightness|block": "set brightness %value", "led.setBrightness|block": "set brightness %value",
@@ -225,8 +295,11 @@
"motors.motorPower|block": "motor on at %percent", "motors.motorPower|block": "motor on at %percent",
"motors|block": "motors", "motors|block": "motors",
"music.beat|block": "%fraction|beat", "music.beat|block": "%fraction|beat",
"music.beginMelody|block": "start melody %melody=device_builtin_melody| repeating %options",
"music.builtInMelody|block": "%melody",
"music.changeTempoBy|block": "change tempo by (bpm)|%value", "music.changeTempoBy|block": "change tempo by (bpm)|%value",
"music.noteFrequency|block": "%note", "music.noteFrequency|block": "%note",
"music.onEvent|block": "music on %value",
"music.playTone|block": "play|tone %note=device_note|for %duration=device_beat", "music.playTone|block": "play|tone %note=device_note|for %duration=device_beat",
"music.rest|block": "rest(ms)|%duration=device_beat", "music.rest|block": "rest(ms)|%duration=device_beat",
"music.ringTone|block": "ring tone (Hz)|%note=device_note", "music.ringTone|block": "ring tone (Hz)|%note=device_note",
@@ -251,6 +324,9 @@
"pins.servoWritePin|block": "servo write|pin %name|to %value", "pins.servoWritePin|block": "servo write|pin %name|to %value",
"pins.setEvents|block": "set pin %pin|to emit %type|events", "pins.setEvents|block": "set pin %pin|to emit %type|events",
"pins.setPull|block": "set pull|pin %pin|to %pull", "pins.setPull|block": "set pull|pin %pin|to %pull",
"pins.spiFormat|block": "spi format|bits %bits|mode %mode",
"pins.spiFrequency|block": "spi frequency %frequency",
"pins.spiPins|block": "spi set pins|MOSI %mosi|MISO %miso|SCK %sck",
"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",

View File

@@ -6,7 +6,7 @@
*/ */
//% color=#54C9C9 weight=100 icon="\uf00a" //% color=#54C9C9 weight=100 icon="\uf00a"
namespace basic { namespace basic {
/** /**
* Sets the color on the build-in LED. Set to 0 to turn off. * Sets the color on the build-in LED. Set to 0 to turn off.
*/ */
//% blockId=device_set_led_color block="set led to %color=color_id" //% blockId=device_set_led_color block="set led to %color=color_id"
@@ -34,10 +34,9 @@ namespace basic {
//% blockId=device_show_number block="show|number %number" blockGap=8 //% blockId=device_show_number block="show|number %number" blockGap=8
//% async //% async
//% parts="ledmatrix" //% parts="ledmatrix"
void showNumber(int value, int interval = 150) { void showNumber(int value, int interval = 150) {
if (interval < 0) if (interval <= 0)
return; interval = 1;
ManagedString t(value); ManagedString t(value);
if (value < 0 || value >= 10) { if (value < 0 || value >= 10) {
uBit.display.scroll(t, interval); uBit.display.scroll(t, interval);
@@ -51,11 +50,11 @@ namespace basic {
* @param leds the pattern of LED to turn on/off * @param leds the pattern of LED to turn on/off
* @param interval time in milliseconds to pause after drawing * @param interval time in milliseconds to pause after drawing
*/ */
//% help=basic/show-leds //% help=basic/show-leds
//% weight=95 blockGap=8 //% weight=95 blockGap=8
//% imageLiteral=1 async //% imageLiteral=1 async
//% blockId=device_show_leds //% blockId=device_show_leds
//% block="show leds" //% block="show leds" icon="\uf00a"
//% parts="ledmatrix" //% parts="ledmatrix"
void showLeds(ImageLiteral leds, int interval = 400) { void showLeds(ImageLiteral leds, int interval = 400) {
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval); uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
@@ -66,15 +65,15 @@ namespace basic {
* @param text the text to scroll on the screen, eg: "Hello!" * @param text the text to scroll on the screen, eg: "Hello!"
* @param interval how fast to shift characters; eg: 150, 100, 200, -100 * @param interval how fast to shift characters; eg: 150, 100, 200, -100
*/ */
//% help=basic/show-string //% help=basic/show-string
//% weight=87 blockGap=8 //% weight=87 blockGap=8
//% block="show|string %text" //% block="show|string %text"
//% async //% async
//% blockId=device_print_message //% blockId=device_print_message
//% parts="ledmatrix" //% parts="ledmatrix"
void showString(StringData *text, int interval = 150) { void showString(StringData *text, int interval = 150) {
if (interval < 0) if (interval <= 0)
return; interval = 1;
ManagedString s(text); ManagedString s(text);
int l = s.length(); int l = s.length();
if (l == 0) { if (l == 0) {
@@ -93,6 +92,7 @@ namespace basic {
//% help=basic/clear-screen weight=79 //% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" //% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true
void clearScreen() { void clearScreen() {
uBit.display.image.clear(); uBit.display.image.clear();
} }
@@ -105,7 +105,7 @@ namespace basic {
//% help=basic/show-animation imageLiteral=1 async //% help=basic/show-animation imageLiteral=1 async
//% parts="ledmatrix" //% parts="ledmatrix"
void showAnimation(ImageLiteral leds, int interval = 400) { void showAnimation(ImageLiteral leds, int interval = 400) {
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0); uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0, 0);
} }
/** /**
@@ -130,8 +130,8 @@ namespace basic {
* Repeats the code forever in the background. On each iteration, allows other codes to run. * Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute * @param body code to execute
*/ */
//% help=basic/forever weight=55 blockGap=8 //% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1 afterOnStart=true
//% blockId=device_forever block="forever" //% blockId=device_forever block="forever" icon="\uf01e"
void forever(Action a) { void forever(Action a) {
if (a != 0) { if (a != 0) {
incr(a); incr(a);
@@ -145,7 +145,7 @@ namespace basic {
*/ */
//% help=basic/pause weight=54 //% help=basic/pause weight=54
//% async block="pause (ms) %pause" //% async block="pause (ms) %pause"
//% blockId=device_pause //% blockId=device_pause icon="\uf110"
void pause(int ms) { void pause(int ms) {
fiber_sleep(ms); fiber_sleep(ms);
} }

View File

@@ -20,97 +20,190 @@ enum class EventCreationMode {
// TODO shouldn't these be renamed to something more sensible anyways? // TODO shouldn't these be renamed to something more sensible anyways?
enum EventBusSource { enum EventBusSource {
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_A_ = MICROBIT_ID_BUTTON_A, MICROBIT_ID_BUTTON_A_ = MICROBIT_ID_BUTTON_A,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_B_ = MICROBIT_ID_BUTTON_B, MICROBIT_ID_BUTTON_B_ = MICROBIT_ID_BUTTON_B,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_AB_ = MICROBIT_ID_BUTTON_AB, MICROBIT_ID_BUTTON_AB_ = MICROBIT_ID_BUTTON_AB,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_RADIO_ = MICROBIT_ID_RADIO, MICROBIT_ID_RADIO_ = MICROBIT_ID_RADIO,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_GESTURE_ = MICROBIT_ID_GESTURE, MICROBIT_ID_GESTURE_ = MICROBIT_ID_GESTURE,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_ACCELEROMETER_ = MICROBIT_ID_ACCELEROMETER, MICROBIT_ID_ACCELEROMETER_ = MICROBIT_ID_ACCELEROMETER,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P0_ = MICROBIT_ID_IO_P0, MICROBIT_ID_IO_P0_ = MICROBIT_ID_IO_P0,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P1_ = MICROBIT_ID_IO_P1, MICROBIT_ID_IO_P1_ = MICROBIT_ID_IO_P1,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P2_ = MICROBIT_ID_IO_P2, MICROBIT_ID_IO_P2_ = MICROBIT_ID_IO_P2,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P3_ = MICROBIT_ID_IO_P3, MICROBIT_ID_IO_P3_ = MICROBIT_ID_IO_P3,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P4_ = MICROBIT_ID_IO_P4, MICROBIT_ID_IO_P4_ = MICROBIT_ID_IO_P4,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P5_ = MICROBIT_ID_IO_P5, MICROBIT_ID_IO_P5_ = MICROBIT_ID_IO_P5,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P6_ = MICROBIT_ID_IO_P6, MICROBIT_ID_IO_P6_ = MICROBIT_ID_IO_P6,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P7_ = MICROBIT_ID_IO_P7, MICROBIT_ID_IO_P7_ = MICROBIT_ID_IO_P7,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P8_ = MICROBIT_ID_IO_P8, MICROBIT_ID_IO_P8_ = MICROBIT_ID_IO_P8,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P9_ = MICROBIT_ID_IO_P9, MICROBIT_ID_IO_P9_ = MICROBIT_ID_IO_P9,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P10_ = MICROBIT_ID_IO_P10, MICROBIT_ID_IO_P10_ = MICROBIT_ID_IO_P10,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P11_ = MICROBIT_ID_IO_P11, MICROBIT_ID_IO_P11_ = MICROBIT_ID_IO_P11,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P12_ = MICROBIT_ID_IO_P12, MICROBIT_ID_IO_P12_ = MICROBIT_ID_IO_P12,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P13_ = MICROBIT_ID_IO_P13, MICROBIT_ID_IO_P13_ = MICROBIT_ID_IO_P13,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P14_ = MICROBIT_ID_IO_P14, MICROBIT_ID_IO_P14_ = MICROBIT_ID_IO_P14,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P15_ = MICROBIT_ID_IO_P15, MICROBIT_ID_IO_P15_ = MICROBIT_ID_IO_P15,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P16_ = MICROBIT_ID_IO_P16, MICROBIT_ID_IO_P16_ = MICROBIT_ID_IO_P16,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P19_ = MICROBIT_ID_IO_P19, MICROBIT_ID_IO_P19_ = MICROBIT_ID_IO_P19,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P20_ = MICROBIT_ID_IO_P20, MICROBIT_ID_IO_P20_ = MICROBIT_ID_IO_P20,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P21_ = MICROBIT_ID_IO_P21, MICROBIT_ID_IO_P21_ = MICROBIT_ID_IO_P21,
//% blockIdentity="control.eventSourceId"
MES_DEVICE_INFO_ID_ = MES_DEVICE_INFO_ID, MES_DEVICE_INFO_ID_ = MES_DEVICE_INFO_ID,
//% blockIdentity="control.eventSourceId"
MES_SIGNAL_STRENGTH_ID_ = MES_SIGNAL_STRENGTH_ID, MES_SIGNAL_STRENGTH_ID_ = MES_SIGNAL_STRENGTH_ID,
//% blockIdentity="control.eventSourceId"
MES_DPAD_CONTROLLER_ID_ = MES_DPAD_CONTROLLER_ID, MES_DPAD_CONTROLLER_ID_ = MES_DPAD_CONTROLLER_ID,
//% blockIdentity="control.eventSourceId"
MES_BROADCAST_GENERAL_ID_ = MES_BROADCAST_GENERAL_ID, MES_BROADCAST_GENERAL_ID_ = MES_BROADCAST_GENERAL_ID,
}; };
enum EventBusValue { enum EventBusValue {
//% blockIdentity="control.eventValueId"
MICROBIT_EVT_ANY_ = MICROBIT_EVT_ANY, MICROBIT_EVT_ANY_ = MICROBIT_EVT_ANY,
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_DOWN_ = MICROBIT_BUTTON_EVT_DOWN,
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_UP_ = MICROBIT_BUTTON_EVT_UP,
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_CLICK_ = MICROBIT_BUTTON_EVT_CLICK, MICROBIT_BUTTON_EVT_CLICK_ = MICROBIT_BUTTON_EVT_CLICK,
//% blockIdentity="control.eventValueId"
MICROBIT_RADIO_EVT_DATAGRAM_ = MICROBIT_RADIO_EVT_DATAGRAM, MICROBIT_RADIO_EVT_DATAGRAM_ = MICROBIT_RADIO_EVT_DATAGRAM,
//% blockIdentity="control.eventValueId"
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE_ = MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE, MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE_ = MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_RISE_ = MICROBIT_PIN_EVT_RISE, MICROBIT_PIN_EVT_RISE_ = MICROBIT_PIN_EVT_RISE,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_FALL_ = MICROBIT_PIN_EVT_FALL, MICROBIT_PIN_EVT_FALL_ = MICROBIT_PIN_EVT_FALL,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_HI_ = MICROBIT_PIN_EVT_PULSE_HI, MICROBIT_PIN_EVT_PULSE_HI_ = MICROBIT_PIN_EVT_PULSE_HI,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_LO_ = MICROBIT_PIN_EVT_PULSE_LO, MICROBIT_PIN_EVT_PULSE_LO_ = MICROBIT_PIN_EVT_PULSE_LO,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM1_ = MES_ALERT_EVT_ALARM1, MES_ALERT_EVT_ALARM1_ = MES_ALERT_EVT_ALARM1,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM2_ = MES_ALERT_EVT_ALARM2, MES_ALERT_EVT_ALARM2_ = MES_ALERT_EVT_ALARM2,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM3_ = MES_ALERT_EVT_ALARM3, MES_ALERT_EVT_ALARM3_ = MES_ALERT_EVT_ALARM3,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM4_ = MES_ALERT_EVT_ALARM4, MES_ALERT_EVT_ALARM4_ = MES_ALERT_EVT_ALARM4,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM5_ = MES_ALERT_EVT_ALARM5, MES_ALERT_EVT_ALARM5_ = MES_ALERT_EVT_ALARM5,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM6_ = MES_ALERT_EVT_ALARM6, MES_ALERT_EVT_ALARM6_ = MES_ALERT_EVT_ALARM6,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_DISPLAY_TOAST_ = MES_ALERT_EVT_DISPLAY_TOAST, MES_ALERT_EVT_DISPLAY_TOAST_ = MES_ALERT_EVT_DISPLAY_TOAST,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_FIND_MY_PHONE_ = MES_ALERT_EVT_FIND_MY_PHONE, MES_ALERT_EVT_FIND_MY_PHONE_ = MES_ALERT_EVT_FIND_MY_PHONE,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_RINGTONE_ = MES_ALERT_EVT_PLAY_RINGTONE, MES_ALERT_EVT_PLAY_RINGTONE_ = MES_ALERT_EVT_PLAY_RINGTONE,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_SOUND_ = MES_ALERT_EVT_PLAY_SOUND, MES_ALERT_EVT_PLAY_SOUND_ = MES_ALERT_EVT_PLAY_SOUND,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_VIBRATE_ = MES_ALERT_EVT_VIBRATE, MES_ALERT_EVT_VIBRATE_ = MES_ALERT_EVT_VIBRATE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_PHOTO_MODE_ = MES_CAMERA_EVT_LAUNCH_PHOTO_MODE, MES_CAMERA_EVT_LAUNCH_PHOTO_MODE_ = MES_CAMERA_EVT_LAUNCH_PHOTO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_VIDEO_MODE_ = MES_CAMERA_EVT_LAUNCH_VIDEO_MODE, MES_CAMERA_EVT_LAUNCH_VIDEO_MODE_ = MES_CAMERA_EVT_LAUNCH_VIDEO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_START_VIDEO_CAPTURE_ = MES_CAMERA_EVT_START_VIDEO_CAPTURE, MES_CAMERA_EVT_START_VIDEO_CAPTURE_ = MES_CAMERA_EVT_START_VIDEO_CAPTURE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_PHOTO_MODE_ = MES_CAMERA_EVT_STOP_PHOTO_MODE, MES_CAMERA_EVT_STOP_PHOTO_MODE_ = MES_CAMERA_EVT_STOP_PHOTO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_CAPTURE_ = MES_CAMERA_EVT_STOP_VIDEO_CAPTURE, MES_CAMERA_EVT_STOP_VIDEO_CAPTURE_ = MES_CAMERA_EVT_STOP_VIDEO_CAPTURE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_MODE_ = MES_CAMERA_EVT_STOP_VIDEO_MODE, MES_CAMERA_EVT_STOP_VIDEO_MODE_ = MES_CAMERA_EVT_STOP_VIDEO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TAKE_PHOTO_ = MES_CAMERA_EVT_TAKE_PHOTO, MES_CAMERA_EVT_TAKE_PHOTO_ = MES_CAMERA_EVT_TAKE_PHOTO,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TOGGLE_FRONT_REAR_ = MES_CAMERA_EVT_TOGGLE_FRONT_REAR, MES_CAMERA_EVT_TOGGLE_FRONT_REAR_ = MES_CAMERA_EVT_TOGGLE_FRONT_REAR,
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_OFF_ = MES_DEVICE_DISPLAY_OFF, MES_DEVICE_DISPLAY_OFF_ = MES_DEVICE_DISPLAY_OFF,
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_ON_ = MES_DEVICE_DISPLAY_ON, MES_DEVICE_DISPLAY_ON_ = MES_DEVICE_DISPLAY_ON,
//% blockIdentity="control.eventValueId"
MES_DEVICE_GESTURE_DEVICE_SHAKEN_ = MES_DEVICE_GESTURE_DEVICE_SHAKEN, MES_DEVICE_GESTURE_DEVICE_SHAKEN_ = MES_DEVICE_GESTURE_DEVICE_SHAKEN,
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_CALL_ = MES_DEVICE_INCOMING_CALL, MES_DEVICE_INCOMING_CALL_ = MES_DEVICE_INCOMING_CALL,
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_MESSAGE_ = MES_DEVICE_INCOMING_MESSAGE, MES_DEVICE_INCOMING_MESSAGE_ = MES_DEVICE_INCOMING_MESSAGE,
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_LANDSCAPE_ = MES_DEVICE_ORIENTATION_LANDSCAPE, MES_DEVICE_ORIENTATION_LANDSCAPE_ = MES_DEVICE_ORIENTATION_LANDSCAPE,
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_PORTRAIT_ = MES_DEVICE_ORIENTATION_PORTRAIT, MES_DEVICE_ORIENTATION_PORTRAIT_ = MES_DEVICE_ORIENTATION_PORTRAIT,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_DOWN_ = MES_DPAD_BUTTON_1_DOWN, MES_DPAD_BUTTON_1_DOWN_ = MES_DPAD_BUTTON_1_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_UP_ = MES_DPAD_BUTTON_1_UP, MES_DPAD_BUTTON_1_UP_ = MES_DPAD_BUTTON_1_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_DOWN_ = MES_DPAD_BUTTON_2_DOWN, MES_DPAD_BUTTON_2_DOWN_ = MES_DPAD_BUTTON_2_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_UP_ = MES_DPAD_BUTTON_2_UP, MES_DPAD_BUTTON_2_UP_ = MES_DPAD_BUTTON_2_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_DOWN_ = MES_DPAD_BUTTON_3_DOWN, MES_DPAD_BUTTON_3_DOWN_ = MES_DPAD_BUTTON_3_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_UP_ = MES_DPAD_BUTTON_3_UP, MES_DPAD_BUTTON_3_UP_ = MES_DPAD_BUTTON_3_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_DOWN_ = MES_DPAD_BUTTON_4_DOWN, MES_DPAD_BUTTON_4_DOWN_ = MES_DPAD_BUTTON_4_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_UP_ = MES_DPAD_BUTTON_4_UP, MES_DPAD_BUTTON_4_UP_ = MES_DPAD_BUTTON_4_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_DOWN_ = MES_DPAD_BUTTON_A_DOWN, MES_DPAD_BUTTON_A_DOWN_ = MES_DPAD_BUTTON_A_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_UP_ = MES_DPAD_BUTTON_A_UP, MES_DPAD_BUTTON_A_UP_ = MES_DPAD_BUTTON_A_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_DOWN_ = MES_DPAD_BUTTON_B_DOWN, MES_DPAD_BUTTON_B_DOWN_ = MES_DPAD_BUTTON_B_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_UP_ = MES_DPAD_BUTTON_B_UP, MES_DPAD_BUTTON_B_UP_ = MES_DPAD_BUTTON_B_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_DOWN_ = MES_DPAD_BUTTON_C_DOWN, MES_DPAD_BUTTON_C_DOWN_ = MES_DPAD_BUTTON_C_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_UP_ = MES_DPAD_BUTTON_C_UP, MES_DPAD_BUTTON_C_UP_ = MES_DPAD_BUTTON_C_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_DOWN_ = MES_DPAD_BUTTON_D_DOWN, MES_DPAD_BUTTON_D_DOWN_ = MES_DPAD_BUTTON_D_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_UP_ = MES_DPAD_BUTTON_D_UP, MES_DPAD_BUTTON_D_UP_ = MES_DPAD_BUTTON_D_UP,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_FORWARD_ = MES_REMOTE_CONTROL_EVT_FORWARD, MES_REMOTE_CONTROL_EVT_FORWARD_ = MES_REMOTE_CONTROL_EVT_FORWARD,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_NEXTTRACK_ = MES_REMOTE_CONTROL_EVT_NEXTTRACK, MES_REMOTE_CONTROL_EVT_NEXTTRACK_ = MES_REMOTE_CONTROL_EVT_NEXTTRACK,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PAUSE_ = MES_REMOTE_CONTROL_EVT_PAUSE, MES_REMOTE_CONTROL_EVT_PAUSE_ = MES_REMOTE_CONTROL_EVT_PAUSE,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PLAY_ = MES_REMOTE_CONTROL_EVT_PLAY, MES_REMOTE_CONTROL_EVT_PLAY_ = MES_REMOTE_CONTROL_EVT_PLAY,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PREVTRACK_ = MES_REMOTE_CONTROL_EVT_PREVTRACK, MES_REMOTE_CONTROL_EVT_PREVTRACK_ = MES_REMOTE_CONTROL_EVT_PREVTRACK,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_REWIND_ = MES_REMOTE_CONTROL_EVT_REWIND, MES_REMOTE_CONTROL_EVT_REWIND_ = MES_REMOTE_CONTROL_EVT_REWIND,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_STOP_ = MES_REMOTE_CONTROL_EVT_STOP, MES_REMOTE_CONTROL_EVT_STOP_ = MES_REMOTE_CONTROL_EVT_STOP,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEDOWN_ = MES_REMOTE_CONTROL_EVT_VOLUMEDOWN, MES_REMOTE_CONTROL_EVT_VOLUMEDOWN_ = MES_REMOTE_CONTROL_EVT_VOLUMEDOWN,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEUP_ = MES_REMOTE_CONTROL_EVT_VOLUMEUP, MES_REMOTE_CONTROL_EVT_VOLUMEUP_ = MES_REMOTE_CONTROL_EVT_VOLUMEUP,
}; };
@@ -126,7 +219,7 @@ namespace control {
/** /**
* Schedules code that run in the background. * Schedules code that run in the background.
*/ */
//% help=control/in-background //% help=control/in-background blockAllowMultiple=1 afterOnStart=true
//% blockId="control_in_background" block="run in background" blockGap=8 //% blockId="control_in_background" block="run in background" blockGap=8
void inBackground(Action a) { void inBackground(Action a) {
runInBackground(a); runInBackground(a);
@@ -158,6 +251,7 @@ namespace control {
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE). * @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).
*/ */
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1 //% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1
//% help=control/raise-event
//% mode.defl=CREATE_AND_FIRE //% mode.defl=CREATE_AND_FIRE
void raiseEvent(int src, int value, EventCreationMode mode) { void raiseEvent(int src, int value, EventCreationMode mode) {
MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode); MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode);
@@ -167,6 +261,7 @@ namespace control {
* Raises an event in the event bus. * Raises an event in the event bus.
*/ */
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
//% help=control/on-event
//% blockExternalInputs=1 //% blockExternalInputs=1
void onEvent(int src, int value, Action handler) { void onEvent(int src, int value, Action handler) {
registerWithDal(src, value, handler); registerWithDal(src, value, handler);
@@ -176,6 +271,7 @@ namespace control {
* Gets the value of the last event executed on the bus * Gets the value of the last event executed on the bus
*/ */
//% blockId=control_event_value" block="event value" //% blockId=control_event_value" block="event value"
//% help=control/event-value
//% weight=18 //% weight=18
int eventValue() { int eventValue() {
return pxt::lastEvent.value; return pxt::lastEvent.value;
@@ -185,6 +281,7 @@ namespace control {
* Gets the timestamp of the last event executed on the bus * Gets the timestamp of the last event executed on the bus
*/ */
//% blockId=control_event_timestamp" block="event timestamp" //% blockId=control_event_timestamp" block="event timestamp"
//% help=control/event-timestamp
//% weight=19 blockGap=8 //% weight=19 blockGap=8
int eventTimestamp() { int eventTimestamp() {
return pxt::lastEvent.timestamp; return pxt::lastEvent.timestamp;
@@ -194,6 +291,7 @@ namespace control {
* Gets a friendly name for the device derived from the its serial number * Gets a friendly name for the device derived from the its serial number
*/ */
//% blockId="control_device_name" block="device name" weight=10 blockGap=8 //% blockId="control_device_name" block="device name" weight=10 blockGap=8
//% advanced=true
StringData* deviceName() { StringData* deviceName() {
return ManagedString(microbit_friendly_name()).leakData(); return ManagedString(microbit_friendly_name()).leakData();
} }
@@ -202,6 +300,7 @@ namespace control {
* Derive a unique, consistent serial number of this device from internal data. * Derive a unique, consistent serial number of this device from internal data.
*/ */
//% blockId="control_device_serial_number" block="device serial number" weight=9 //% blockId="control_device_serial_number" block="device serial number" weight=9
//% advanced=true
int deviceSerialNumber() { int deviceSerialNumber() {
return microbit_serial_number(); return microbit_serial_number();
} }

View File

@@ -4,46 +4,47 @@
//% weight=1 color="#42495F" icon="\uf233" //% weight=1 color="#42495F" icon="\uf233"
//% advanced=true //% advanced=true
namespace control { namespace control {
/** /**
* Returns the value of a C++ runtime constant * Returns the value of a C++ runtime constant
*/ */
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8 //% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
//% shim=TD_ID //% shim=TD_ID advanced=true
export function eventSourceId(id: EventBusSource): number { export function eventSourceId(id: EventBusSource): number {
return id; return id;
}
/**
* Returns the value of a C++ runtime constant
*/
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
//% shim=TD_ID
export function eventValueId(id: EventBusValue): number {
return id;
}
/**
* Display specified error code and stop the program.
*/
//% shim=pxtrt::panic
export function panic(code: number) { }
/**
* If the condition is false, display msg on serial console, and panic with code 098.
*/
export function assert(condition: boolean, msg ?: string) {
if (!condition) {
console.log("ASSERTION FAILED")
if (msg != null) {
console.log(msg)
}
panic(98)
} }
/**
* Returns the value of a C++ runtime constant
*/
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
//% shim=TD_ID advanced=true
export function eventValueId(id: EventBusValue): number {
return id;
}
/**
* Display specified error code and stop the program.
*/
//% shim=pxtrt::panic
export function panic(code: number) { }
/**
* If the condition is false, display msg on serial console, and panic with code 098.
*/
export function assert(condition: boolean, msg?: string) {
if (!condition) {
console.log("ASSERTION FAILED")
if (msg != null) {
console.log(msg)
}
panic(98)
}
}
/**
* Display warning in the simulator.
*/
//% shim=pxtrt::runtimeWarning
export function runtimeWarning(message: string) { }
} }
/**
* Display warning in the simulator.
*/
//% shim=pxtrt::runtimeWarning
export function runtimeWarning(message: string) { }
}

View File

@@ -29,6 +29,15 @@ namespace String_ {
return 0; return 0;
} }
//%
int compareDecr(StringData *s, StringData *that) {
int r = compare(s, that);
if (r == 0)
decr((uint32_t)that);
return r;
}
//% //%
int length(StringData *s) { return s->len; } int length(StringData *s) { return s->len; }
@@ -112,6 +121,15 @@ namespace Number_ {
int div(int x, int y) { return x / y; } int div(int x, int y) { return x / y; }
//% //%
int mod(int x, int y) { return x % y; } int mod(int x, int y) { return x % y; }
//%
bool eqDecr(int x, int y) {
if(x == y) {
decr(y);
return true;
}
return false;
}
} }
namespace Math_ { namespace Math_ {
@@ -220,17 +238,12 @@ namespace pxt {
return bytecode[17] * 2; return bytecode[17] * 2;
} }
#ifndef PAGE_SIZE
#define PAGE_SIZE 1
#endif
//% //%
uint32_t afterProgramPage() { uint32_t afterProgramPage() {
uint32_t ptr = (uint32_t)&bytecode[0]; uint32_t ptr = (uint32_t)&bytecode[0];
ptr += programSize(); ptr += programSize();
ptr = (ptr + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); if (ptr % PAGE_SIZE != 0)
ptr = (ptr & ~(PAGE_SIZE-1)) + PAGE_SIZE;
return ptr; return ptr;
} }
} }

134
libs/core/enums.d.ts vendored
View File

@@ -116,6 +116,47 @@ declare namespace basic {
*/ */
//% block="6g" //% block="6g"
SixG = 10, // MICROBIT_ACCELEROMETER_EVT_6G SixG = 10, // MICROBIT_ACCELEROMETER_EVT_6G
/**
* Raised when a 8G shock is detected
*/
//% block="8g"
EightG = 11, // MICROBIT_ACCELEROMETER_EVT_8G
}
declare const enum MesDpadButtonInfo {
//% block="A down"
ADown = 1, // MES_DPAD_BUTTON_A_DOWN
//% block="A up"
AUp = 2, // MES_DPAD_BUTTON_A_UP
//% block="B down"
BDown = 3, // MES_DPAD_BUTTON_B_DOWN
//% block="B up"
BUp = 4, // MES_DPAD_BUTTON_B_UP
//% block="C down"
CDown = 5, // MES_DPAD_BUTTON_C_DOWN
//% block="C up"
CUp = 6, // MES_DPAD_BUTTON_C_UP
//% block="D down"
DDown = 7, // MES_DPAD_BUTTON_D_DOWN
//% block="D up"
DUp = 8, // MES_DPAD_BUTTON_D_UP
//% block="1 down"
_1Down = 9, // MES_DPAD_BUTTON_1_DOWN
//% block="1 up"
_1Up = 10, // MES_DPAD_BUTTON_1_UP
//% block="2 down"
_2Down = 11, // MES_DPAD_BUTTON_2_DOWN
//% block="2 up"
_2Up = 12, // MES_DPAD_BUTTON_2_UP
//% block="3 down"
_3Down = 13, // MES_DPAD_BUTTON_3_DOWN
//% block="3 up"
_3Up = 14, // MES_DPAD_BUTTON_3_UP
//% block="4 down"
_4Down = 15, // MES_DPAD_BUTTON_4_DOWN
//% block="4 up"
_4Up = 16, // MES_DPAD_BUTTON_4_UP
} }
declare namespace input { declare namespace input {
} }
@@ -138,98 +179,191 @@ declare namespace input {
declare const enum EventBusSource { declare const enum EventBusSource {
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_A = 1, // MICROBIT_ID_BUTTON_A MICROBIT_ID_BUTTON_A = 1, // MICROBIT_ID_BUTTON_A
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_B = 2, // MICROBIT_ID_BUTTON_B MICROBIT_ID_BUTTON_B = 2, // MICROBIT_ID_BUTTON_B
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_AB = 26, // MICROBIT_ID_BUTTON_AB MICROBIT_ID_BUTTON_AB = 26, // MICROBIT_ID_BUTTON_AB
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_RADIO = 29, // MICROBIT_ID_RADIO MICROBIT_ID_RADIO = 29, // MICROBIT_ID_RADIO
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_GESTURE = 27, // MICROBIT_ID_GESTURE MICROBIT_ID_GESTURE = 27, // MICROBIT_ID_GESTURE
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_ACCELEROMETER = 4, // MICROBIT_ID_ACCELEROMETER MICROBIT_ID_ACCELEROMETER = 4, // MICROBIT_ID_ACCELEROMETER
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P0 = 7, // MICROBIT_ID_IO_P0 MICROBIT_ID_IO_P0 = 7, // MICROBIT_ID_IO_P0
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P1 = 8, // MICROBIT_ID_IO_P1 MICROBIT_ID_IO_P1 = 8, // MICROBIT_ID_IO_P1
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P2 = 9, // MICROBIT_ID_IO_P2 MICROBIT_ID_IO_P2 = 9, // MICROBIT_ID_IO_P2
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P3 = 10, // MICROBIT_ID_IO_P3 MICROBIT_ID_IO_P3 = 10, // MICROBIT_ID_IO_P3
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P4 = 11, // MICROBIT_ID_IO_P4 MICROBIT_ID_IO_P4 = 11, // MICROBIT_ID_IO_P4
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P5 = 12, // MICROBIT_ID_IO_P5 MICROBIT_ID_IO_P5 = 12, // MICROBIT_ID_IO_P5
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P6 = 13, // MICROBIT_ID_IO_P6 MICROBIT_ID_IO_P6 = 13, // MICROBIT_ID_IO_P6
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P7 = 14, // MICROBIT_ID_IO_P7 MICROBIT_ID_IO_P7 = 14, // MICROBIT_ID_IO_P7
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P8 = 15, // MICROBIT_ID_IO_P8 MICROBIT_ID_IO_P8 = 15, // MICROBIT_ID_IO_P8
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P9 = 16, // MICROBIT_ID_IO_P9 MICROBIT_ID_IO_P9 = 16, // MICROBIT_ID_IO_P9
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P10 = 17, // MICROBIT_ID_IO_P10 MICROBIT_ID_IO_P10 = 17, // MICROBIT_ID_IO_P10
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P11 = 18, // MICROBIT_ID_IO_P11 MICROBIT_ID_IO_P11 = 18, // MICROBIT_ID_IO_P11
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P12 = 19, // MICROBIT_ID_IO_P12 MICROBIT_ID_IO_P12 = 19, // MICROBIT_ID_IO_P12
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P13 = 20, // MICROBIT_ID_IO_P13 MICROBIT_ID_IO_P13 = 20, // MICROBIT_ID_IO_P13
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P14 = 21, // MICROBIT_ID_IO_P14 MICROBIT_ID_IO_P14 = 21, // MICROBIT_ID_IO_P14
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P15 = 22, // MICROBIT_ID_IO_P15 MICROBIT_ID_IO_P15 = 22, // MICROBIT_ID_IO_P15
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P16 = 23, // MICROBIT_ID_IO_P16 MICROBIT_ID_IO_P16 = 23, // MICROBIT_ID_IO_P16
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P19 = 24, // MICROBIT_ID_IO_P19 MICROBIT_ID_IO_P19 = 24, // MICROBIT_ID_IO_P19
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P20 = 25, // MICROBIT_ID_IO_P20 MICROBIT_ID_IO_P20 = 25, // MICROBIT_ID_IO_P20
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P21 = 50, // MICROBIT_ID_IO_P21 MICROBIT_ID_IO_P21 = 50, // MICROBIT_ID_IO_P21
//% blockIdentity="control.eventSourceId"
MES_DEVICE_INFO_ID = 1103, // MES_DEVICE_INFO_ID MES_DEVICE_INFO_ID = 1103, // MES_DEVICE_INFO_ID
//% blockIdentity="control.eventSourceId"
MES_SIGNAL_STRENGTH_ID = 1101, // MES_SIGNAL_STRENGTH_ID MES_SIGNAL_STRENGTH_ID = 1101, // MES_SIGNAL_STRENGTH_ID
//% blockIdentity="control.eventSourceId"
MES_DPAD_CONTROLLER_ID = 1104, // MES_DPAD_CONTROLLER_ID MES_DPAD_CONTROLLER_ID = 1104, // MES_DPAD_CONTROLLER_ID
//% blockIdentity="control.eventSourceId"
MES_BROADCAST_GENERAL_ID = 2000, // MES_BROADCAST_GENERAL_ID MES_BROADCAST_GENERAL_ID = 2000, // MES_BROADCAST_GENERAL_ID
} }
declare const enum EventBusValue { declare const enum EventBusValue {
//% blockIdentity="control.eventValueId"
MICROBIT_EVT_ANY = 0, // MICROBIT_EVT_ANY MICROBIT_EVT_ANY = 0, // MICROBIT_EVT_ANY
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_DOWN = 1, // MICROBIT_BUTTON_EVT_DOWN
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_UP = 2, // MICROBIT_BUTTON_EVT_UP
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_CLICK = 3, // MICROBIT_BUTTON_EVT_CLICK MICROBIT_BUTTON_EVT_CLICK = 3, // MICROBIT_BUTTON_EVT_CLICK
//% blockIdentity="control.eventValueId"
MICROBIT_RADIO_EVT_DATAGRAM = 1, // MICROBIT_RADIO_EVT_DATAGRAM MICROBIT_RADIO_EVT_DATAGRAM = 1, // MICROBIT_RADIO_EVT_DATAGRAM
//% blockIdentity="control.eventValueId"
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1, // MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1, // MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_RISE = 2, // MICROBIT_PIN_EVT_RISE MICROBIT_PIN_EVT_RISE = 2, // MICROBIT_PIN_EVT_RISE
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_FALL = 3, // MICROBIT_PIN_EVT_FALL MICROBIT_PIN_EVT_FALL = 3, // MICROBIT_PIN_EVT_FALL
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_HI = 4, // MICROBIT_PIN_EVT_PULSE_HI MICROBIT_PIN_EVT_PULSE_HI = 4, // MICROBIT_PIN_EVT_PULSE_HI
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_LO = 5, // MICROBIT_PIN_EVT_PULSE_LO MICROBIT_PIN_EVT_PULSE_LO = 5, // MICROBIT_PIN_EVT_PULSE_LO
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM1 = 6, // MES_ALERT_EVT_ALARM1 MES_ALERT_EVT_ALARM1 = 6, // MES_ALERT_EVT_ALARM1
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM2 = 7, // MES_ALERT_EVT_ALARM2 MES_ALERT_EVT_ALARM2 = 7, // MES_ALERT_EVT_ALARM2
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM3 = 8, // MES_ALERT_EVT_ALARM3 MES_ALERT_EVT_ALARM3 = 8, // MES_ALERT_EVT_ALARM3
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM4 = 9, // MES_ALERT_EVT_ALARM4 MES_ALERT_EVT_ALARM4 = 9, // MES_ALERT_EVT_ALARM4
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM5 = 10, // MES_ALERT_EVT_ALARM5 MES_ALERT_EVT_ALARM5 = 10, // MES_ALERT_EVT_ALARM5
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM6 = 11, // MES_ALERT_EVT_ALARM6 MES_ALERT_EVT_ALARM6 = 11, // MES_ALERT_EVT_ALARM6
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_DISPLAY_TOAST = 1, // MES_ALERT_EVT_DISPLAY_TOAST MES_ALERT_EVT_DISPLAY_TOAST = 1, // MES_ALERT_EVT_DISPLAY_TOAST
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_FIND_MY_PHONE = 5, // MES_ALERT_EVT_FIND_MY_PHONE MES_ALERT_EVT_FIND_MY_PHONE = 5, // MES_ALERT_EVT_FIND_MY_PHONE
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_RINGTONE = 4, // MES_ALERT_EVT_PLAY_RINGTONE MES_ALERT_EVT_PLAY_RINGTONE = 4, // MES_ALERT_EVT_PLAY_RINGTONE
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_SOUND = 3, // MES_ALERT_EVT_PLAY_SOUND MES_ALERT_EVT_PLAY_SOUND = 3, // MES_ALERT_EVT_PLAY_SOUND
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_VIBRATE = 2, // MES_ALERT_EVT_VIBRATE MES_ALERT_EVT_VIBRATE = 2, // MES_ALERT_EVT_VIBRATE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_PHOTO_MODE = 1, // MES_CAMERA_EVT_LAUNCH_PHOTO_MODE MES_CAMERA_EVT_LAUNCH_PHOTO_MODE = 1, // MES_CAMERA_EVT_LAUNCH_PHOTO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_VIDEO_MODE = 2, // MES_CAMERA_EVT_LAUNCH_VIDEO_MODE MES_CAMERA_EVT_LAUNCH_VIDEO_MODE = 2, // MES_CAMERA_EVT_LAUNCH_VIDEO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_START_VIDEO_CAPTURE = 4, // MES_CAMERA_EVT_START_VIDEO_CAPTURE MES_CAMERA_EVT_START_VIDEO_CAPTURE = 4, // MES_CAMERA_EVT_START_VIDEO_CAPTURE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_PHOTO_MODE = 6, // MES_CAMERA_EVT_STOP_PHOTO_MODE MES_CAMERA_EVT_STOP_PHOTO_MODE = 6, // MES_CAMERA_EVT_STOP_PHOTO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_CAPTURE = 5, // MES_CAMERA_EVT_STOP_VIDEO_CAPTURE MES_CAMERA_EVT_STOP_VIDEO_CAPTURE = 5, // MES_CAMERA_EVT_STOP_VIDEO_CAPTURE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_MODE = 7, // MES_CAMERA_EVT_STOP_VIDEO_MODE MES_CAMERA_EVT_STOP_VIDEO_MODE = 7, // MES_CAMERA_EVT_STOP_VIDEO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TAKE_PHOTO = 3, // MES_CAMERA_EVT_TAKE_PHOTO MES_CAMERA_EVT_TAKE_PHOTO = 3, // MES_CAMERA_EVT_TAKE_PHOTO
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TOGGLE_FRONT_REAR = 8, // MES_CAMERA_EVT_TOGGLE_FRONT_REAR MES_CAMERA_EVT_TOGGLE_FRONT_REAR = 8, // MES_CAMERA_EVT_TOGGLE_FRONT_REAR
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_OFF = 5, // MES_DEVICE_DISPLAY_OFF MES_DEVICE_DISPLAY_OFF = 5, // MES_DEVICE_DISPLAY_OFF
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_ON = 6, // MES_DEVICE_DISPLAY_ON MES_DEVICE_DISPLAY_ON = 6, // MES_DEVICE_DISPLAY_ON
//% blockIdentity="control.eventValueId"
MES_DEVICE_GESTURE_DEVICE_SHAKEN = 4, // MES_DEVICE_GESTURE_DEVICE_SHAKEN MES_DEVICE_GESTURE_DEVICE_SHAKEN = 4, // MES_DEVICE_GESTURE_DEVICE_SHAKEN
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_CALL = 7, // MES_DEVICE_INCOMING_CALL MES_DEVICE_INCOMING_CALL = 7, // MES_DEVICE_INCOMING_CALL
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_MESSAGE = 8, // MES_DEVICE_INCOMING_MESSAGE MES_DEVICE_INCOMING_MESSAGE = 8, // MES_DEVICE_INCOMING_MESSAGE
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_LANDSCAPE = 1, // MES_DEVICE_ORIENTATION_LANDSCAPE MES_DEVICE_ORIENTATION_LANDSCAPE = 1, // MES_DEVICE_ORIENTATION_LANDSCAPE
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_PORTRAIT = 2, // MES_DEVICE_ORIENTATION_PORTRAIT MES_DEVICE_ORIENTATION_PORTRAIT = 2, // MES_DEVICE_ORIENTATION_PORTRAIT
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_DOWN = 9, // MES_DPAD_BUTTON_1_DOWN MES_DPAD_BUTTON_1_DOWN = 9, // MES_DPAD_BUTTON_1_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_UP = 10, // MES_DPAD_BUTTON_1_UP MES_DPAD_BUTTON_1_UP = 10, // MES_DPAD_BUTTON_1_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_DOWN = 11, // MES_DPAD_BUTTON_2_DOWN MES_DPAD_BUTTON_2_DOWN = 11, // MES_DPAD_BUTTON_2_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_UP = 12, // MES_DPAD_BUTTON_2_UP MES_DPAD_BUTTON_2_UP = 12, // MES_DPAD_BUTTON_2_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_DOWN = 13, // MES_DPAD_BUTTON_3_DOWN MES_DPAD_BUTTON_3_DOWN = 13, // MES_DPAD_BUTTON_3_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_UP = 14, // MES_DPAD_BUTTON_3_UP MES_DPAD_BUTTON_3_UP = 14, // MES_DPAD_BUTTON_3_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_DOWN = 15, // MES_DPAD_BUTTON_4_DOWN MES_DPAD_BUTTON_4_DOWN = 15, // MES_DPAD_BUTTON_4_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_UP = 16, // MES_DPAD_BUTTON_4_UP MES_DPAD_BUTTON_4_UP = 16, // MES_DPAD_BUTTON_4_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_DOWN = 1, // MES_DPAD_BUTTON_A_DOWN MES_DPAD_BUTTON_A_DOWN = 1, // MES_DPAD_BUTTON_A_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_UP = 2, // MES_DPAD_BUTTON_A_UP MES_DPAD_BUTTON_A_UP = 2, // MES_DPAD_BUTTON_A_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_DOWN = 3, // MES_DPAD_BUTTON_B_DOWN MES_DPAD_BUTTON_B_DOWN = 3, // MES_DPAD_BUTTON_B_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_UP = 4, // MES_DPAD_BUTTON_B_UP MES_DPAD_BUTTON_B_UP = 4, // MES_DPAD_BUTTON_B_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_DOWN = 5, // MES_DPAD_BUTTON_C_DOWN MES_DPAD_BUTTON_C_DOWN = 5, // MES_DPAD_BUTTON_C_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_UP = 6, // MES_DPAD_BUTTON_C_UP MES_DPAD_BUTTON_C_UP = 6, // MES_DPAD_BUTTON_C_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_DOWN = 7, // MES_DPAD_BUTTON_D_DOWN MES_DPAD_BUTTON_D_DOWN = 7, // MES_DPAD_BUTTON_D_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_UP = 8, // MES_DPAD_BUTTON_D_UP MES_DPAD_BUTTON_D_UP = 8, // MES_DPAD_BUTTON_D_UP
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_FORWARD = 6, // MES_REMOTE_CONTROL_EVT_FORWARD MES_REMOTE_CONTROL_EVT_FORWARD = 6, // MES_REMOTE_CONTROL_EVT_FORWARD
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_NEXTTRACK = 4, // MES_REMOTE_CONTROL_EVT_NEXTTRACK MES_REMOTE_CONTROL_EVT_NEXTTRACK = 4, // MES_REMOTE_CONTROL_EVT_NEXTTRACK
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PAUSE = 2, // MES_REMOTE_CONTROL_EVT_PAUSE MES_REMOTE_CONTROL_EVT_PAUSE = 2, // MES_REMOTE_CONTROL_EVT_PAUSE
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PLAY = 1, // MES_REMOTE_CONTROL_EVT_PLAY MES_REMOTE_CONTROL_EVT_PLAY = 1, // MES_REMOTE_CONTROL_EVT_PLAY
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PREVTRACK = 5, // MES_REMOTE_CONTROL_EVT_PREVTRACK MES_REMOTE_CONTROL_EVT_PREVTRACK = 5, // MES_REMOTE_CONTROL_EVT_PREVTRACK
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_REWIND = 7, // MES_REMOTE_CONTROL_EVT_REWIND MES_REMOTE_CONTROL_EVT_REWIND = 7, // MES_REMOTE_CONTROL_EVT_REWIND
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_STOP = 3, // MES_REMOTE_CONTROL_EVT_STOP MES_REMOTE_CONTROL_EVT_STOP = 3, // MES_REMOTE_CONTROL_EVT_STOP
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEDOWN = 9, // MES_REMOTE_CONTROL_EVT_VOLUMEDOWN MES_REMOTE_CONTROL_EVT_VOLUMEDOWN = 9, // MES_REMOTE_CONTROL_EVT_VOLUMEDOWN
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEUP = 8, // MES_REMOTE_CONTROL_EVT_VOLUMEUP MES_REMOTE_CONTROL_EVT_VOLUMEUP = 8, // MES_REMOTE_CONTROL_EVT_VOLUMEUP
} }
declare namespace control { declare namespace control {

View File

@@ -32,22 +32,22 @@ namespace game {
let _countdownPause: number = 0; let _countdownPause: number = 0;
let _level: number = 1; let _level: number = 1;
let _gameId: number = 0; let _gameId: number = 0;
let img: Image; let _img: Image;
let sprites: LedSprite[]; let _sprites: LedSprite[];
let _paused: boolean = false;
let _backgroundAnimation = false; // indicates if an auxiliary animation (and fiber) is already running
/** /**
* Creates a new LED sprite pointing to the right. * Creates a new LED sprite pointing to the right.
* @param x sprite horizontal coordinate, eg: 2 * @param x sprite horizontal coordinate, eg: 2
* @param y sprite vertical coordinate, eg: 2 * @param y sprite vertical coordinate, eg: 2
*/ */
//% weight=60 //% weight=60 blockGap=8 help=game/create-sprite
//% blockId=game_create_sprite block="create sprite at|x: %x|y: %y" //% blockId=game_create_sprite block="create sprite at|x: %x|y: %y"
//% parts="ledmatrix" //% parts="ledmatrix"
export function createSprite(x: number, y: number): LedSprite { export function createSprite(x: number, y: number): LedSprite {
init(); init();
let p = new LedSprite(x, y); let p = new LedSprite(x, y);
sprites.push(p);
plot();
return p; return p;
} }
@@ -61,7 +61,7 @@ namespace game {
} }
/** /**
* Adds points to the current score * Adds points to the current score and shows an animation
* @param points amount of points to change, eg: 1 * @param points amount of points to change, eg: 1
*/ */
//% weight=10 help=game/add-score //% weight=10 help=game/add-score
@@ -69,18 +69,22 @@ namespace game {
//% parts="ledmatrix" //% parts="ledmatrix"
export function addScore(points: number): void { export function addScore(points: number): void {
setScore(_score + points); setScore(_score + points);
control.inBackground(() => { if (!_paused && !_backgroundAnimation) {
led.stopAnimation(); _backgroundAnimation = true;
basic.showAnimation(`0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 control.inBackground(() => {
0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 led.stopAnimation();
0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 basic.showAnimation(`0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0`, 20); 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
}); 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0`, 20);
_backgroundAnimation = false;
});
}
} }
/** /**
* Starts a game countdown timer * Shows an animation, then starts a game countdown timer, which causes Game Over when it reaches 0
* @param ms countdown duration in milliseconds, eg: 10000 * @param ms countdown duration in milliseconds, eg: 10000
*/ */
//% weight=9 help=game/start-countdown //% weight=9 help=game/start-countdown
@@ -96,6 +100,7 @@ namespace game {
_countdownPause = Math.max(500, ms); _countdownPause = Math.max(500, ms);
_startTime = -1; _startTime = -1;
_endTime = input.runningTime() + _countdownPause; _endTime = input.runningTime() + _countdownPause;
_paused = false;
control.inBackground(() => { control.inBackground(() => {
basic.pause(_countdownPause); basic.pause(_countdownPause);
gameOver(); gameOver();
@@ -104,7 +109,7 @@ namespace game {
} }
/** /**
* Displays a game over animation. * Displays a game over animation and the score.
*/ */
//% weight=8 help=game/game-over //% weight=8 help=game/game-over
//% blockId=game_game_over block="game over" //% blockId=game_game_over block="game over"
@@ -115,7 +120,6 @@ namespace game {
unplugEvents(); unplugEvents();
led.stopAnimation(); led.stopAnimation();
led.setBrightness(255); led.setBrightness(255);
led.setDisplayMode(DisplayMode.BackAndWhite);
while (true) { while (true) {
for (let i = 0; i < 8; i++) { for (let i = 0; i < 8; i++) {
basic.clearScreen(); basic.clearScreen();
@@ -146,8 +150,9 @@ namespace game {
/** /**
* Sets the current score value * Sets the current score value
* @param value TODO * @param value new score value.
*/ */
//% blockId=game_set_score block="set score %points" blockGap=8
//% weight=10 help=game/set-score //% weight=10 help=game/set-score
export function setScore(value: number): void { export function setScore(value: number): void {
_score = Math.max(0, value); _score = Math.max(0, value);
@@ -202,14 +207,15 @@ namespace game {
//% parts="ledmatrix" //% parts="ledmatrix"
export function removeLife(life: number): void { export function removeLife(life: number): void {
setLife(_life - life); setLife(_life - life);
control.inBackground(() => { if (!_paused)
led.stopAnimation(); control.inBackground(() => {
basic.showAnimation(`1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 led.stopAnimation();
basic.showAnimation(`1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0
1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0`, 40); 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0`, 40);
}); });
} }
/** /**
@@ -264,10 +270,38 @@ namespace game {
* Indicates if the game is display the game over sequence. * Indicates if the game is display the game over sequence.
*/ */
export function isGameOver(): boolean { export function isGameOver(): boolean {
let over: boolean;
return _isGameOver; return _isGameOver;
} }
/**
* Indicates if the game rendering is paused to allow other animations
*/
//%
export function isPaused(): boolean {
return _paused;
}
/**
* Pauses the game rendering engine to allow other animations
*/
//% blockId=game_pause block="pause"
//% advanced=true blockGap=8 help=game/pause
export function pause(): void {
plot()
_paused = true;
}
/**
* Resumes the game rendering engine
*/
//% blockId=game_resume block="resume"
//% advanced=true blockGap=8 help=game/resumeP
export function resume(): void {
_paused = false;
plot();
}
/** /**
* returns false if game can't start * returns false if game can't start
*/ */
@@ -287,29 +321,35 @@ namespace game {
}); });
} }
/**
* A game sprite rendered as a single LED
*/
//%
export class LedSprite { export class LedSprite {
private _x: number; private _x: number;
private _y: number; private _y: number;
private _dir: number; private _dir: number;
private _brightness: number; private _brightness: number;
private _blink: number; private _blink: number;
private _enabled: boolean;
constructor(x: number, y: number) { constructor(x: number, y: number) {
this._x = Math.clamp(0, 4, x); this._x = Math.clamp(0, 4, x);
this._y = Math.clamp(0, 4, y); this._y = Math.clamp(0, 4, y);
this._dir = 90; this._dir = 90;
this._brightness = 255; this._brightness = 255;
this._enabled = true;
init(); init();
sprites.push(this); _sprites.push(this);
plot(); plot();
} }
/** /**
* Move a certain number of LEDs * Move a certain number of LEDs in the current direction
* @param this the sprite to move * @param this the sprite to move
* @param leds number of leds to move, eg: 1, -1 * @param leds number of leds to move, eg: 1, -1
*/ */
//% weight=50 //% weight=50 help=game/move
//% blockId=game_move_sprite block="%sprite|move by %leds" blockGap=8 //% blockId=game_move_sprite block="%sprite|move by %leds" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
public move(leds: number): void { public move(leds: number): void {
@@ -355,10 +395,10 @@ namespace game {
} }
/** /**
* If touching the edge of the stage, then bounce away. * If touching the edge of the stage and facing towards it, then turn away.
* @param this TODO * @param this TODO
*/ */
//% weight=18 //% weight=18 help=game/if-on-edge-bounce
//% blockId=game_sprite_bounce block="%sprite|if on edge, bounce" //% blockId=game_sprite_bounce block="%sprite|if on edge, bounce"
//% parts="ledmatrix" //% parts="ledmatrix"
public ifOnEdgeBounce(): void { public ifOnEdgeBounce(): void {
@@ -412,7 +452,7 @@ namespace game {
* @param direction left or right * @param direction left or right
* @param degrees angle in degrees to turn, eg: 45, 90, 180, 135 * @param degrees angle in degrees to turn, eg: 45, 90, 180, 135
*/ */
//% weight=49 //% weight=49 help=game/turn
//% blockId=game_turn_sprite block="%sprite|turn %direction|by (°) %degrees" //% blockId=game_turn_sprite block="%sprite|turn %direction|by (°) %degrees"
public turn(direction: Direction, degrees: number) { public turn(direction: Direction, degrees: number) {
if (direction == Direction.Right) if (direction == Direction.Right)
@@ -444,7 +484,7 @@ namespace game {
* @param property the name of the property to change * @param property the name of the property to change
* @param the updated value * @param the updated value
*/ */
//% weight=29 //% weight=29 help=game/set
//% blockId=game_sprite_set_property block="%sprite|set %property|to %value" blockGap=8 //% blockId=game_sprite_set_property block="%sprite|set %property|to %value" blockGap=8
public set(property: LedSpriteProperty, value: number) { public set(property: LedSpriteProperty, value: number) {
switch (property) { switch (property) {
@@ -461,7 +501,7 @@ namespace game {
* @param property the name of the property to change * @param property the name of the property to change
* @param value amount of change, eg: 1 * @param value amount of change, eg: 1
*/ */
//% weight=30 //% weight=30 help=game/change
//% blockId=game_sprite_change_xy block="%sprite|change %property|by %value" blockGap=8 //% blockId=game_sprite_change_xy block="%sprite|change %property|by %value" blockGap=8
public change(property: LedSpriteProperty, value: number) { public change(property: LedSpriteProperty, value: number) {
switch (property) { switch (property) {
@@ -477,7 +517,7 @@ namespace game {
* Gets a property of the sprite * Gets a property of the sprite
* @param property the name of the property to change * @param property the name of the property to change
*/ */
//% weight=28 //% weight=28 help=game/get
//% blockId=game_sprite_property block="%sprite|%property" //% blockId=game_sprite_property block="%sprite|%property"
public get(property: LedSpriteProperty) { public get(property: LedSpriteProperty) {
switch (property) { switch (property) {
@@ -567,21 +607,21 @@ namespace game {
} }
/** /**
* Reports true if sprite is touching specified sprite * Reports true if sprite has the same position as specified sprite
* @param this TODO * @param this TODO
* @param other TODO * @param other TODO
*/ */
//% weight=20 //% weight=20 help=game/is-touching
//% blockId=game_sprite_touching_sprite block="%sprite|touching %other|?" blockGap=8 //% blockId=game_sprite_touching_sprite block="%sprite|touching %other|?" blockGap=8
public isTouching(other: LedSprite): boolean { public isTouching(other: LedSprite): boolean {
return this._x == other._x && this._y == other._y; return this._enabled && other._enabled && this._x == other._x && this._y == other._y;
} }
/** /**
* Reports true if sprite is touching an edge * Reports true if sprite is touching an edge
* @param this TODO * @param this TODO
*/ */
//% weight=19 //% weight=19 help=game/is-touching-edge
//% blockId=game_sprite_touching_edge block="%sprite|touching edge?" blockGap=8 //% blockId=game_sprite_touching_edge block="%sprite|touching edge?" blockGap=8
public isTouchingEdge(): boolean { public isTouchingEdge(): boolean {
return this._x == 0 || this._x == 4 || this._y == 0 || this._y == 4; return this._x == 0 || this._x == 4 || this._y == 0 || this._y == 4;
@@ -589,7 +629,7 @@ namespace game {
/** /**
* Turns on the sprite (on by default) * Turns on the sprite (on by default)
* @param this TODO * @param this the sprite
*/ */
public on(): void { public on(): void {
this.setBrightness(255); this.setBrightness(255);
@@ -597,7 +637,7 @@ namespace game {
/** /**
* Turns off the sprite (on by default) * Turns off the sprite (on by default)
* @param this TODO * @param this the sprite
*/ */
public off(): void { public off(): void {
this.setBrightness(0); this.setBrightness(0);
@@ -605,8 +645,8 @@ namespace game {
/** /**
* Set the ``brightness`` of a sprite * Set the ``brightness`` of a sprite
* @param this TODO * @param this the sprite
* @param brightness TODO * @param brightness the brightness from 0 (off) to 255 (on), eg: 255.
*/ */
//% parts="ledmatrix" //% parts="ledmatrix"
public setBrightness(brightness: number): void { public setBrightness(brightness: number): void {
@@ -616,8 +656,9 @@ namespace game {
/** /**
* Reports the ``brightness` of a sprite on the LED screen * Reports the ``brightness` of a sprite on the LED screen
* @param this TODO * @param this the sprite
*/ */
//% parts="ledmatrix"
public brightness(): number { public brightness(): number {
let r: number; let r: number;
return this._brightness; return this._brightness;
@@ -625,8 +666,8 @@ namespace game {
/** /**
* Changes the ``y`` position by the given amount * Changes the ``y`` position by the given amount
* @param this TODO * @param this the sprite
* @param value TODO * @param value the value to change brightness
*/ */
public changeBrightnessBy(value: number): void { public changeBrightnessBy(value: number): void {
this.setBrightness(this._brightness + value); this.setBrightness(this._brightness + value);
@@ -642,11 +683,15 @@ namespace game {
} }
/** /**
* Deletes the sprite from the game engine. All further operation of the sprite will not have any effect. * Deletes the sprite from the game engine. The sprite will no longer appear on the screen or interact with other sprites.
* @param sprite TODO * @param this sprite to delete
*/ */
public delete(sprite: LedSprite): void { //% weight=59 help=game/delete
sprites.removeElement(sprite); //% blockId="game_delete_sprite" block="delete %this"
public delete(): void {
this._enabled = false;
if (_sprites.removeElement(this))
plot();
} }
/** /**
@@ -686,30 +731,29 @@ namespace game {
r = (now / ps._blink) % 2; r = (now / ps._blink) % 2;
} }
if (r == 0) { if (r == 0) {
img.setPixelBrightness(ps._x, ps._y, img.pixelBrightness(ps._x, ps._y) + ps._brightness); _img.setPixelBrightness(ps._x, ps._y, _img.pixelBrightness(ps._x, ps._y) + ps._brightness);
} }
} }
} }
} }
function init(): void { function init(): void {
if (img == null) { if (_img) return;
img = images.createImage( const img = images.createImage(
`0 0 0 0 0 `0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0`); 0 0 0 0 0`);
sprites = (<LedSprite[]>[]); _sprites = (<LedSprite[]>[]);
led.setDisplayMode(DisplayMode.Greyscale); basic.forever(() => {
basic.forever(() => { basic.pause(30);
basic.pause(30); plot();
plot(); if (game.isGameOver()) {
if (game.isGameOver()) { basic.pause(600);
basic.pause(600); }
} });
}); _img = img;
}
} }
/** /**
@@ -717,15 +761,23 @@ namespace game {
*/ */
//% parts="ledmatrix" //% parts="ledmatrix"
function plot(): void { function plot(): void {
if (game.isGameOver()) { if (game.isGameOver() || game.isPaused() || !_img || _backgroundAnimation) {
return; return;
} }
let now = input.runningTime(); // ensure greyscale mode
img.clear(); const dm = led.displayMode();
for (let i = 0; i < sprites.length; i++) { if (dm != DisplayMode.Greyscale)
sprites[i]._plot(now); led.setDisplayMode(DisplayMode.Greyscale);
// render sprites
const now = input.runningTime();
_img.clear();
for (let i = 0; i < _sprites.length; i++) {
_sprites[i]._plot(now);
} }
img.plotImage(0); _img.plotImage(0);
// restore previous display mode
if (dm != DisplayMode.Greyscale)
led.setDisplayMode(dm);
} }
/** /**
@@ -737,4 +789,3 @@ namespace game {
} }
} }

View File

@@ -27,103 +27,143 @@ THE SOFTWARE.
enum IconNames { enum IconNames {
//% block="heart" //% block="heart"
//% blockImage=1
Heart = 0, Heart = 0,
//% block="small heart" //% block="small heart"
//% blockImage=1
SmallHeart, SmallHeart,
//% block="yes" //% block="yes"
//% blockImage=1
Yes, Yes,
//% block="no" //% block="no"
//% blockImage=1
No, No,
//% block="happy" //% block="happy"
//% blockImage=1
Happy, Happy,
//% block="sad" //% block="sad"
//% blockImage=1
Sad, Sad,
//% block="confused" //% block="confused"
//% blockImage=1
Confused, Confused,
//% block="angry" //% block="angry"
//% blockImage=1
Angry, Angry,
//% block="asleep" //% block="asleep"
//% blockImage=1
Asleep, Asleep,
//% block="surprised" //% block="surprised"
//% blockImage=1
Surprised, Surprised,
//% block="silly" //% block="silly"
//% blockImage=1
Silly, Silly,
//% block="fabulous" //% block="fabulous"
//% blockImage=1
Fabulous, Fabulous,
//% block="meh" //% block="meh"
//% blockImage=1
Meh, Meh,
//% block="t-shirt" //% block="t-shirt"
//% blockImage=1
TShirt, TShirt,
//% block="roller skate" //% block="roller skate"
//% blockImage=1
Rollerskate, Rollerskate,
//% block="duck" //% block="duck"
//% blockImage=1
Duck, Duck,
//% block="house" //% block="house"
//% blockImage=1
House, House,
//% block="tortoise" //% block="tortoise"
//% blockImage=1
Tortoise, Tortoise,
//% block="butterfly" //% block="butterfly"
//% blockImage=1
Butterfly, Butterfly,
//% block="stick figure" //% block="stick figure"
//% blockImage=1
StickFigure, StickFigure,
//% block="ghost" //% block="ghost"
//% blockImage=1
Ghost, Ghost,
//% block="sword" //% block="sword"
//% blockImage=1
Sword, Sword,
//% block="giraffe" //% block="giraffe"
//% blockImage=1
Giraffe, Giraffe,
//% block="skull" //% block="skull"
//% blockImage=1
Skull, Skull,
//% block="umbrella" //% block="umbrella"
//% blockImage=1
Umbrella, Umbrella,
//% block="snake" //% block="snake"
//% blockImage=1
Snake, Snake,
//% block="rabbit" //% block="rabbit"
//% blockImage=1
Rabbit, Rabbit,
//% block="cow" //% block="cow"
//% blockImage=1
Cow, Cow,
//% block="quarter note" //% block="quarter note"
//% blockImage=1
QuarterNote, QuarterNote,
//% block="eigth note" //% block="eigth note"
//% blockImage=1
EigthNote, EigthNote,
//% block="pitchfork" //% block="pitchfork"
//% blockImage=1
Pitchfork, Pitchfork,
//% block="pac man"
Pacman,
//% block="target" //% block="target"
//% blockImage=1
Target, Target,
//% block="triangle" //% block="triangle"
//% blockImage=1
Triangle, Triangle,
//% block="left triangle" //% block="left triangle"
//% blockImage=1
LeftTriangle, LeftTriangle,
//% block="chess board" //% block="chess board"
//% blockImage=1
Chessboard, Chessboard,
//% block="diamond" //% block="diamond"
//% blockImage=1
Diamond, Diamond,
//% block="small diamond" //% block="small diamond"
//% blockImage=1
SmallDiamond, SmallDiamond,
//% block="square" //% block="square"
//% blockImage=1
Square, Square,
//% block="small square" //% block="small square"
SmallSquare, //% blockImage=1
SmallSquare,
//% block="scissors"
//% blockImage=1
Scissors
} }
enum ArrowNames { enum ArrowNames {
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="North"
North = 0, North = 0,
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="North East"
NorthEast, NorthEast,
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="East"
East, East,
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="South East"
SouthEast, SouthEast,
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="South"
South, South,
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="South West"
SouthWest, SouthWest,
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="West"
West, West,
//% blockIdentity=images.arrowNumber //% blockIdentity=images.arrowNumber block="North West"
NorthWest, NorthWest,
} }
@@ -131,393 +171,376 @@ namespace basic {
/** /**
* Draws the selected icon on the LED screen * Draws the selected icon on the LED screen
* @param icon the predifined icon id
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/ */
//% weight=90 blockGap=8 //% weight=90 blockGap=8
//% blockId=basic_show_icon //% blockId=basic_show_icon
//% block="show icon %i" icon="\uf00a" //% block="show icon %i" icon="\uf00a"
//% parts="ledmatrix" //% parts="ledmatrix"
//% help=basic/show-icon //% help=basic/show-icon
export function showIcon(icon: IconNames) { //% i.fieldEditor="gridpicker"
//% i.fieldOptions.width="400" i.fieldOptions.columns="5"
//% i.fieldOptions.itemColour="black" i.fieldOptions.tooltips="true"
export function showIcon(icon: IconNames, interval = 600) {
let res = images.iconImage(icon) let res = images.iconImage(icon)
res.showImage(0) res.showImage(0, interval)
} }
/**
* Shows an arrow on screent
* @param direction the direction of the arrow
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/
//% weight=50 blockGap=8 //% weight=50 blockGap=8
//% blockId=basic_show_arrow //% blockId=basic_show_arrow
//% block="show arrow %i=device_arrow" //% block="show arrow %i=device_arrow"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true //% advanced=true
//% help=basic/show-arrow //% help=basic/show-arrow
export function showArrow(i: number) { export function showArrow(direction: number, interval = 600) {
let res = images.arrowImage(i) let res = images.arrowImage(direction)
res.showImage(0) res.showImage(0, interval)
} }
} }
namespace images { namespace images {
function getArrow(i : ArrowNames): string { //% weight=50 blockGap=8
switch(i) { //% help=images/arrow-image
//% blockId=builtin_arrow_image block="arrow image %i=device_arrow"
export function arrowImage(i: ArrowNames): Image {
switch (i) {
// compass directions // compass directions
case ArrowNames.North: return ` case ArrowNames.North: return images.createImage(`
. . # . . . . # . .
. # # # . . # # # .
# . # . # # . # . #
. . # . . . . # . .
. . # . .`; . . # . .`);
case ArrowNames.NorthEast: return ` case ArrowNames.NorthEast: return images.createImage(`
. . # # # . . # # #
. . . # # . . . # #
. . # . # . . # . #
. # . . . . # . . .
# . . . .`; # . . . .`);
case ArrowNames.East: return ` case ArrowNames.East: return images.createImage(`
. . # . . . . # . .
. . . # . . . . # .
# # # # # # # # # #
. . . # . . . . # .
. . # . .`; . . # . .`);
case ArrowNames.SouthEast: return ` case ArrowNames.SouthEast: return images.createImage(`
# . . . . # . . . .
. # . . . . # . . .
. . # . # . . # . #
. . . # # . . . # #
. . # # #`; . . # # #`);
case ArrowNames.South: return ` case ArrowNames.South: return images.createImage(`
. . # . . . . # . .
. . # . . . . # . .
# . # . # # . # . #
. # # # . . # # # .
. . # . .`; . . # . .`);
case ArrowNames.SouthWest: return ` case ArrowNames.SouthWest: return images.createImage(`
. . . . # . . . . #
. . . # . . . . # .
# . # . . # . # . .
# # . . . # # . . .
# # # . .`; # # # . .`);
case ArrowNames.West: return ` case ArrowNames.West: return images.createImage(`
. . # . . . . # . .
. # . . . . # . . .
# # # # # # # # # #
. # . . . . # . . .
. . # . .`; . . # . .`);
case ArrowNames.NorthWest: return ` case ArrowNames.NorthWest: return images.createImage(`
# # # . . # # # . .
# # . . . # # . . .
# . # . . # . # . .
. . . # . . . . # .
. . . . #`; . . . . #`);
default: return ` default: return images.createImage(`
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
`; `);
}
}
function getIcon(i: IconNames): string {
switch (i) {
case IconNames.Heart : return `
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`;
case IconNames.SmallHeart : return `
. . . . .
. # . # .
. # # # .
. . # . .
. . . . .`;
//faces
case IconNames.Happy: return `
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`;
case IconNames.Sad: return `
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`;
case IconNames.Confused: return `
. . . . .
. # . # .
. . . . .
. # . # .
# . # . #`;
case IconNames.Angry: return `
# . . . #
. # . # .
. . . . .
# # # # #
# . # . #`;
case IconNames.Asleep: return `
. . . . .
# # . # #
. . . . .
. # # # .
. . . . .`;
case IconNames.Surprised: return `
. # . # .
. . . . .
. . # . .
. # . # .
. . # . .`;
case IconNames.Silly: return `
# . . . #
. . . . .
# # # # #
. . . # #
. . . # #`;
case IconNames.Fabulous: return `
# # # # #
# # . # #
. . . . .
. # . # .
. # # # .`;
case IconNames.Meh: return `
# # . # #
. . . . .
. . . # .
. . # . .
. # . . .`;
case IconNames.Yes: return `
. . . . .
. . . . #
. . . # .
# . # . .
. # . . .`;
case IconNames.No: return `
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #`;
case IconNames.Triangle: return `
. . . . .
. . # . .
. # . # .
# # # # #
. . . . .`;
case IconNames.LeftTriangle: return `
# . . . .
# # . . .
# . # . .
# . . # .
# # # # #`;
case IconNames.Chessboard: return `
. # . # .
# . # . #
. # . # .
# . # . #
. # . # .`;
case IconNames.Diamond: return `
. . # . .
. # . # .
# . . . #
. # . # .
. . # . .`;
case IconNames.SmallDiamond: return `
. . . . .
. . # . .
. # . # .
. . # . .
. . . . .`;
case IconNames.Square: return `
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`;
case IconNames.SmallSquare: return `
. . . . .
. # # # .
. # . # .
. # # # .
. . . . .`;
// The following images were designed by Abbie Brooks.
case IconNames.TShirt: return `
# # . # #
# # # # #
. # # # .
. # # # .
. # # # .`;
case IconNames.Rollerskate: return `
. . . # #
. . . # #
# # # # #
# # # # #
. # . # .`;
case IconNames.Duck: return `
. # # . .
# # # . .
. # # # #
. # # # .
. .. . .`;
case IconNames.House: return `
. . # . .
. # # # .
# # # # #
. # # # .
. # . # .`;
case IconNames.Tortoise: return `
. . . . .
. # # # .
# # # # #
. # . # .
. . . . .`;
case IconNames.Butterfly: return `
# # . # #
# # # # #
. . # . .
# # # # #
# # . # #`;
case IconNames.StickFigure: return `
. . # . .
# # # # #
. . # . .
. # . # .
# . . . #`;
case IconNames.Ghost: return `
. # # # .
# . # . #
# # # # #
# # # # #
# . # . #`;
case IconNames.Sword: return `
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .`;
case IconNames.Giraffe: return `
# # . . .
. # . . .
. # . . .
. # # # .
. # . # .`;
case IconNames.Skull: return `
. # # # .
# . # . #
# # # # #
. # # # .
. # # # .`;
case IconNames.Umbrella: return `
. # # # .
# # # # #
. . # . .
# . # . .
# # # . .`;
case IconNames.Snake: return `
# # . . .
# # . # #
. # . # .
. # # # .
. . . . .`;
// animals
case IconNames.Rabbit: return `
# . # . .
# . # . .
# # # # .
# # . # .
# # # # .`;
case IconNames.Cow: return `
# . . . #
# . . . #
# # # # #
. # # # .
. . # . .`;
// musical notes
case IconNames.QuarterNote: return `
. . # . .
. . # . .
. . # . .
# # # . .
# # # . .`;
case IconNames.EigthNote: return `
. . # . .
. . # # .
. . # . #
# # # . .
# # # . .`;
// other icons
case IconNames.Pitchfork: return `
# . # . #
# . # . #
# # # # #
. . # . .
. . # . .`;
case IconNames.Pacman: return `
. # # # #
# # # # .
# # # . .
# # # # .
. # # # #`;
case IconNames.Target: return `
. . # . .
. # # # .
# # . # #
. # # # .
. . # . .`;
default: return `
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`;
} }
} }
//% weight=50 blockGap=8 //% weight=50 blockGap=8
//% help=images/icon-image
//% blockId=builtin_image block="icon image %i"
//% i.fieldEditor="gridpicker"
//% i.fieldOptions.width="400" i.fieldOptions.columns="5"
//% i.fieldOptions.itemColour="black" i.fieldOptions.tooltips="true"
export function iconImage(i: IconNames): Image {
switch (i) {
case IconNames.Heart: return images.createImage(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
case IconNames.SmallHeart: return images.createImage(`
. . . . .
. # . # .
. # # # .
. . # . .
. . . . .`);
//faces
case IconNames.Happy: return images.createImage(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`);
case IconNames.Sad: return images.createImage(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`);
case IconNames.Confused: return images.createImage(`
. . . . .
. # . # .
. . . . .
. # . # .
# . # . #`);
case IconNames.Angry: return images.createImage(`
# . . . #
. # . # .
. . . . .
# # # # #
# . # . #`);
case IconNames.Asleep: return images.createImage(`
. . . . .
# # . # #
. . . . .
. # # # .
. . . . .`);
case IconNames.Surprised: return images.createImage(`
. # . # .
. . . . .
. . # . .
. # . # .
. . # . .`);
case IconNames.Silly: return images.createImage(`
# . . . #
. . . . .
# # # # #
. . . # #
. . . # #`);
case IconNames.Fabulous: return images.createImage(`
# # # # #
# # . # #
. . . . .
. # . # .
. # # # .`);
case IconNames.Meh: return images.createImage(`
# # . # #
. . . . .
. . . # .
. . # . .
. # . . .`);
case IconNames.Yes: return images.createImage(`
. . . . .
. . . . #
. . . # .
# . # . .
. # . . .`);
case IconNames.No: return images.createImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #`);
case IconNames.Triangle: return images.createImage(`
. . . . .
. . # . .
. # . # .
# # # # #
. . . . .`);
case IconNames.LeftTriangle: return images.createImage(`
# . . . .
# # . . .
# . # . .
# . . # .
# # # # #`);
case IconNames.Chessboard: return images.createImage(`
. # . # .
# . # . #
. # . # .
# . # . #
. # . # .`);
case IconNames.Diamond: return images.createImage(`
. . # . .
. # . # .
# . . . #
. # . # .
. . # . .`);
case IconNames.SmallDiamond: return images.createImage(`
. . . . .
. . # . .
. # . # .
. . # . .
. . . . .`);
case IconNames.Square: return images.createImage(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`);
case IconNames.SmallSquare: return images.createImage(`
. . . . .
. # # # .
. # . # .
. # # # .
. . . . .`);
case IconNames.Scissors: return images.createImage(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #`);
// The following images were designed by Abbie Brooks.
case IconNames.TShirt: return images.createImage(`
# # . # #
# # # # #
. # # # .
. # # # .
. # # # .`);
case IconNames.Rollerskate: return images.createImage(`
. . . # #
. . . # #
# # # # #
# # # # #
. # . # .`);
case IconNames.Duck: return images.createImage(`
. # # . .
# # # . .
. # # # #
. # # # .
. . . . .`);
case IconNames.House: return images.createImage(`
. . # . .
. # # # .
# # # # #
. # # # .
. # . # .`);
case IconNames.Tortoise: return images.createImage(`
. . . . .
. # # # .
# # # # #
. # . # .
. . . . .`);
case IconNames.Butterfly: return images.createImage(`
# # . # #
# # # # #
. . # . .
# # # # #
# # . # #`);
case IconNames.StickFigure: return images.createImage(`
. . # . .
# # # # #
. . # . .
. # . # .
# . . . #`);
case IconNames.Ghost: return images.createImage(`
. # # # .
# . # . #
# # # # #
# # # # #
# . # . #`);
case IconNames.Sword: return images.createImage(`
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .`);
case IconNames.Giraffe: return images.createImage(`
# # . . .
. # . . .
. # . . .
. # # # .
. # . # .`);
case IconNames.Skull: return images.createImage(`
. # # # .
# . # . #
# # # # #
. # # # .
. # # # .`);
case IconNames.Umbrella: return images.createImage(`
. # # # .
# # # # #
. . # . .
# . # . .
# # # . .`);
case IconNames.Snake: return images.createImage(`
# # . . .
# # . # #
. # . # .
. # # # .
. . . . .`);
// animals
case IconNames.Rabbit: return images.createImage(`
# . # . .
# . # . .
# # # # .
# # . # .
# # # # .`);
case IconNames.Cow: return images.createImage(`
# . . . #
# . . . #
# # # # #
. # # # .
. . # . .`);
// musical notes
case IconNames.QuarterNote: return images.createImage(`
. . # . .
. . # . .
. . # . .
# # # . .
# # # . .`);
case IconNames.EigthNote: return images.createImage(`
. . # . .
. . # # .
. . # . #
# # # . .
# # # . .`);
// other icons
case IconNames.Pitchfork: return images.createImage(`
# . # . #
# . # . #
# # # # #
. . # . .
. . # . .`);
case IconNames.Target: return images.createImage(`
. . # . .
. # # # .
# # . # #
. # # # .
. . # . .`);
default: return images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`);
}
}
//% weight=50 blockGap=8
//% help=images/arrow-number
//% blockId=device_arrow block="%arrow" //% blockId=device_arrow block="%arrow"
//% shim=TD_ID //% shim=TD_ID
export function arrowNumber(arrow: ArrowNames): number { export function arrowNumber(arrow: ArrowNames): number {
return arrow; return arrow;
} }
//% weight=50 blockGap=8
//% blockId=builtin_arrow_image block="arrow image %i=device_arrow"
export function arrowImage(i: ArrowNames): Image {
let res = images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
return set(res, getArrow(i));
}
//% weight=50 blockGap=8
//% blockId=builtin_image block="icon image %i"
export function iconImage(i: IconNames): Image {
let res = images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
return set(res, getIcon(i));
}
function set(res: Image, s: string) {
let j = 0;
for (let x of s) {
if (x == "." || x == "#") {
res.setPixel(j % 5, j / 5, x == "#")
j++
}
}
return res
}
} }

View File

@@ -64,12 +64,12 @@ namespace ImageMethods {
* @param frameOffset x offset moved on each animation step, eg: 1, 2, 5 * @param frameOffset x offset moved on each animation step, eg: 1, 2, 5
* @param interval time between each animation step in milli seconds, eg: 200 * @param interval time between each animation step in milli seconds, eg: 200
*/ */
//% help=images/show-image weight=79 async blockNamespace=images //% help=images/scroll-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 //% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
void scrollImage(Image id, int frameOffset, int interval) { void scrollImage(Image id, int frameOffset, int interval) {
MicroBitImage i(id); MicroBitImage i(id);
uBit.display.animate(i, interval, frameOffset, MICROBIT_DISPLAY_WIDTH - 1); uBit.display.animate(i, interval, frameOffset, MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, 0);
} }

View File

@@ -105,15 +105,55 @@ enum class Gesture {
* Raised when a 6G shock is detected * Raised when a 6G shock is detected
*/ */
//% block="6g" //% 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=#C90072 weight=99 icon="\uf192" enum class MesDpadButtonInfo {
//% block="A down"
ADown = MES_DPAD_BUTTON_A_DOWN,
//% block="A up"
AUp = MES_DPAD_BUTTON_A_UP,
//% block="B down"
BDown = MES_DPAD_BUTTON_B_DOWN,
//% block="B up"
BUp = MES_DPAD_BUTTON_B_UP,
//% block="C down"
CDown = MES_DPAD_BUTTON_C_DOWN,
//% block="C up"
CUp = MES_DPAD_BUTTON_C_UP,
//% block="D down"
DDown = MES_DPAD_BUTTON_D_DOWN,
//% block="D up"
DUp = MES_DPAD_BUTTON_D_UP,
//% block="1 down"
_1Down = MES_DPAD_BUTTON_1_DOWN,
//% block="1 up"
_1Up = MES_DPAD_BUTTON_1_UP,
//% block="2 down"
_2Down = MES_DPAD_BUTTON_2_DOWN,
//% block="2 up"
_2Up = MES_DPAD_BUTTON_2_UP,
//% block="3 down"
_3Down = MES_DPAD_BUTTON_3_DOWN,
//% block="3 up"
_3Up = MES_DPAD_BUTTON_3_UP,
//% block="4 down"
_4Down = MES_DPAD_BUTTON_4_DOWN,
//% block="4 up"
_4Up = MES_DPAD_BUTTON_4_UP,
};
//% color=#B4009E weight=99 icon="\uf192"
namespace input { namespace input {
/** /**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed * Do something when a button (A, B or both A+B) is pushed down and released again.
* @param button TODO * @param button the button that needs to be pressed
* @param body TODO * @param body code to run when event is raised
*/ */
//% help=input/on-button-pressed weight=85 blockGap=8 //% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" //% blockId=device_button_event block="on button|%NAME|pressed"
@@ -124,26 +164,29 @@ namespace input {
/** /**
* Do something when when a gesture is done (like shaking the micro:bit). * Do something when when a gesture is done (like shaking the micro:bit).
* @param body TODO * @param gesture the type of gesture to track, eg: Gesture.Shake
* @param body code to run when gesture is raised
*/ */
//% help=input/on-gesture weight=84 blockGap=8 //% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" //% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer" //% parts="accelerometer"
//% NAME.fieldEditor="gridpicker" NAME.fieldOptions.columns=4
void onGesture(Gesture gesture, Action body) { void onGesture(Gesture gesture, Action body) {
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3) int gi = (int)gesture;
uBit.accelerometer.setRange(6); if (gi == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6) uBit.accelerometer.setRange(4);
else if ((gi == MICROBIT_ACCELEROMETER_EVT_6G || gi == MICROBIT_ACCELEROMETER_EVT_8G) && uBit.accelerometer.getRange() < 6)
uBit.accelerometer.setRange(8); uBit.accelerometer.setRange(8);
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body); registerWithDal(MICROBIT_ID_GESTURE, gi, body);
} }
/** /**
* Do something when a pin is pressed. * Do something when a pin is touched and released again (while also touching the GND pin).
* @param name the pin that needs to be pressed * @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed * @param body the code to run when the pin is pressed
*/ */
//% help=input/on-pin-pressed weight=83 //% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %NAME|pressed" //% blockId=device_pin_event block="on pin %name|pressed"
void onPinPressed(TouchPin name, Action body) { void onPinPressed(TouchPin name, Action body) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
if (!pin) return; if (!pin) return;
@@ -155,7 +198,7 @@ namespace input {
/** /**
* Do something when a pin is released. * Do something when a pin is released.
* @param name the pin that needs to be released * @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released * @param body the code to run when the pin is released
*/ */
//% help=input/on-pin-released weight=6 blockGap=8 //% help=input/on-pin-released weight=6 blockGap=8
@@ -172,6 +215,7 @@ namespace input {
/** /**
* Get the button state (pressed or not) for ``A`` and ``B``. * Get the button state (pressed or not) for ``A`` and ``B``.
* @param button the button to query the request, eg: Button.A
*/ */
//% help=input/button-is-pressed weight=60 //% help=input/button-is-pressed weight=60
//% block="button|%NAME|is pressed" //% block="button|%NAME|is pressed"
@@ -190,7 +234,7 @@ namespace input {
/** /**
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
* @param name pin used to detect the touch * @param name pin used to detect the touch, eg: TouchPin.P0
*/ */
//% help=input/pin-is-pressed weight=58 //% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
@@ -205,7 +249,7 @@ namespace input {
double y = uBit.accelerometer.getY(); double y = uBit.accelerometer.getY();
double z = uBit.accelerometer.getZ(); double z = uBit.accelerometer.getZ();
return (int)sqrt(x*x+y*y+z*z); return (int)sqrt(x*x+y*y+z*z);
} }
/** /**
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024) * Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
@@ -296,18 +340,31 @@ namespace input {
/** /**
* Gets the number of milliseconds elapsed since power on. * Gets the number of milliseconds elapsed since power on.
*/ */
//% help=input/running-time weight=50 //% help=input/running-time weight=50 blockGap=8
//% blockId=device_get_running_time block="running time (ms)" //% blockId=device_get_running_time block="running time (ms)"
//% advanced=true //% advanced=true
int runningTime() { int runningTime() {
return system_timer_current_time(); return system_timer_current_time();
} }
/**
* Gets the number of microseconds elapsed since power on.
*/
//% help=input/running-time-micros weight=49
//% blockId=device_get_running_time_micros block="running time (micros)"
//% advanced=true
int runningTimeMicros() {
return system_timer_current_time_us();
}
/** /**
* Obsolete, compass calibration is automatic. * Obsolete, compass calibration is automatic.
*/ */
//% help=input/calibrate weight=0 //% help=input/calibrate-compass advanced=true
void calibrate() { } //% blockId="input_compass_calibrate" block="calibrate compass"
void calibrateCompass() {
uBit.compass.calibrate();
}
/** /**
* Sets the accelerometer sample range in gravities. * Sets the accelerometer sample range in gravities.

View File

@@ -13,14 +13,34 @@ namespace led {
/** /**
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left. * Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x TODO * @param x the horizontal coordinate of the LED starting at 0
* @param y TODO * @param y the vertical coordinate of the LED starting at 0
*/ */
//% help=led/plot weight=78 //% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8 //% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
void plot(int x, int y) { void plot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 1); uBit.display.image.setPixelValue(x, y, 0xff);
}
/**
* Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x the horizontal coordinate of the LED starting at 0
* @param y the vertical coordinate of the LED starting at 0
* @param brightness the brightness from 0 (off) to 255 (bright), eg:255
*/
//% help=led/plot-brightness weight=78
//% blockId=device_plot_brightness block="plot|x %x|y %y|brightness %brightness" blockGap=8
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
//% advanced=true
void plotBrightness(int x, int y, int brightness) {
brightness = max(0, min(0xff, brightness));
// enable greyscale as needed
if (brightness != 0 && brightness != 0xff && uBit.display.getDisplayMode() != DISPLAY_MODE_GREYSCALE)
uBit.display.setDisplayMode(DISPLAY_MODE_GREYSCALE);
uBit.display.image.setPixelValue(x, y, brightness);
} }
/** /**
@@ -31,6 +51,7 @@ namespace led {
//% help=led/unplot weight=77 //% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8 //% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
void unplot(int x, int y) { void unplot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 0); uBit.display.image.setPixelValue(x, y, 0);
} }
@@ -43,6 +64,7 @@ namespace led {
//% help=led/point weight=76 //% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" //% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix" //% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
bool point(int x, int y) { bool point(int x, int y) {
int pix = uBit.display.image.getPixelValue(x, y); int pix = uBit.display.image.getPixelValue(x, y);
return pix > 0; return pix > 0;
@@ -67,6 +89,7 @@ namespace led {
//% blockId=device_set_brightness block="set brightness %value" //% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true //% advanced=true
//% value.min=0 value.max=255
void setBrightness(int value) { void setBrightness(int value) {
uBit.display.setBrightness(value); uBit.display.setBrightness(value);
} }
@@ -92,10 +115,18 @@ namespace led {
uBit.display.setDisplayMode((DisplayMode)mode); uBit.display.setDisplayMode((DisplayMode)mode);
} }
/**
* Gets the current display mode
*/
//% weight=1 parts="ledmatrix" advanced=true
DisplayMode_ displayMode() {
return (DisplayMode_)uBit.display.getDisplayMode();
}
/** /**
* Turns on or off the display * Turns on or off the display
*/ */
//% help=led/enable blockId=device_led_enable //% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix" //% advanced=true parts="ledmatrix"
void enable(bool on) { void enable(bool on) {
if (on) uBit.display.enable(); if (on) uBit.display.enable();

119
libs/core/melodies.ts Normal file
View File

@@ -0,0 +1,119 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed
in the accompanying AUTHORS file
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Melodies from file microbitmusictunes.c https://github.com/bbcmicrobit/MicroPython
enum Melodies {
//% block="dadadum" blockIdentity=music.builtInMelody
Dadadadum = 0,
//% block="entertainer" blockIdentity=music.builtInMelody
Entertainer,
//% block="prelude" blockIdentity=music.builtInMelody
Prelude,
//% block="ode" blockIdentity=music.builtInMelody
Ode,
//% block="nyan" blockIdentity=music.builtInMelody
Nyan,
//% block="ringtone" blockIdentity=music.builtInMelody
Ringtone,
//% block="funk" blockIdentity=music.builtInMelody
Funk,
//% block="blues" blockIdentity=music.builtInMelody
Blues,
//% block="birthday" blockIdentity=music.builtInMelody
Birthday,
//% block="wedding" blockIdentity=music.builtInMelody
Wedding,
//% block="funereal" blockIdentity=music.builtInMelody
Funeral,
//% block="punchline" blockIdentity=music.builtInMelody
Punchline,
//% block="baddy" blockIdentity=music.builtInMelody
Baddy,
//% block="chase" blockIdentity=music.builtInMelody
Chase,
//% block="ba ding" blockIdentity=music.builtInMelody
BaDing,
//% block="wawawawaa" blockIdentity=music.builtInMelody
Wawawawaa,
//% block="jump up" blockIdentity=music.builtInMelody
JumpUp,
//% block="jump down" blockIdentity=music.builtInMelody
JumpDown,
//% block="power up" blockIdentity=music.builtInMelody
PowerUp,
//% block="power down" blockIdentity=music.builtInMelody
PowerDown,
}
namespace music {
export function getMelody(melody: Melodies): string[] {
switch (melody) {
case Melodies.Dadadadum:
return ['r4:2', 'g', 'g', 'g', 'eb:8', 'r:2', 'f', 'f', 'f', 'd:8'];
case Melodies.Entertainer:
return ['d4:1', 'd#', 'e', 'c5:2', 'e4:1', 'c5:2', 'e4:1', 'c5:3', 'c:1', 'd', 'd#', 'e', 'c', 'd', 'e:2', 'b4:1', 'd5:2', 'c:4'];
case Melodies.Prelude:
return ['c4:1', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e'];
case Melodies.Ode:
return ['e4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'e:6', 'd:2', 'd:8', 'e:4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'd:6', 'c:2', 'c:8'];
case Melodies.Nyan:
return ['f#5:2', 'g#', 'c#:1', 'd#:2', 'b4:1', 'd5:1', 'c#', 'b4:2', 'b', 'c#5', 'd', 'd:1', 'c#', 'b4:1', 'c#5:1', 'd#', 'f#', 'g#', 'd#', 'f#', 'c#', 'd', 'b4', 'c#5', 'b4', 'd#5:2', 'f#', 'g#:1', 'd#', 'f#', 'c#', 'd#', 'b4', 'd5', 'd#', 'd', 'c#', 'b4', 'c#5', 'd:2', 'b4:1', 'c#5', 'd#', 'f#', 'c#', 'd', 'c#', 'b4', 'c#5:2', 'b4', 'c#5', 'b4', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'c#5', 'd#', 'b4', 'e5', 'd#', 'e', 'f#', 'b4:2', 'b', 'f#:1', 'g#', 'b', 'f#', 'e5', 'd#', 'c#', 'b4', 'f#', 'd#', 'e', 'f#', 'b:2', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'b', 'c#5', 'd#', 'b4', 'f#', 'g#', 'f#', 'b:2', 'b:1', 'a#', 'b', 'f#', 'g#', 'b', 'e5', 'd#', 'e', 'f#', 'b4:2', 'c#5'];
case Melodies.Ringtone:
return ['c4:1', 'd', 'e:2', 'g', 'd:1', 'e', 'f:2', 'a', 'e:1', 'f', 'g:2', 'b', 'c5:4'];
case Melodies.Funk:
return ['c2:2', 'c', 'd#', 'c:1', 'f:2', 'c:1', 'f:2', 'f#', 'g', 'c', 'c', 'g', 'c:1', 'f#:2', 'c:1', 'f#:2', 'f', 'd#'];
case Melodies.Blues:
return ['c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'f', 'a', 'c3', 'd', 'd#', 'd', 'c', 'a2', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'g', 'b', 'd3', 'f', 'f2', 'a', 'c3', 'd#', 'c2:2', 'e', 'g', 'e', 'g', 'f', 'e', 'd'];
case Melodies.Birthday:
return ['c4:3', 'c:1', 'd:4', 'c:4', 'f', 'e:8', 'c:3', 'c:1', 'd:4', 'c:4', 'g', 'f:8', 'c:3', 'c:1', 'c5:4', 'a4', 'f', 'e', 'd', 'a#:3', 'a#:1', 'a:4', 'f', 'g', 'f:8'];
case Melodies.Wedding:
return ['c4:4', 'f:3', 'f:1', 'f:8', 'c:4', 'g:3', 'e:1', 'f:8', 'c:4', 'f:3', 'a:1', 'c5:4', 'a4:3', 'f:1', 'f:4', 'e:3', 'f:1', 'g:8'];
case Melodies.Funeral:
return ['c3:4', 'c:3', 'c:1', 'c:4', 'd#:3', 'd:1', 'd:3', 'c:1', 'c:3', 'b2:1', 'c3:4'];
case Melodies.Punchline:
return ['c4:3', 'g3:1', 'f#', 'g', 'g#:3', 'g', 'r', 'b', 'c4'];
case Melodies.Baddy:
return ['c3:3', 'r', 'd:2', 'd#', 'r', 'c', 'r', 'f#:8'];
case Melodies.Chase:
return ['a4:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e', 'b4:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e'];
case Melodies.BaDing:
return ['b5:1', 'e6:3'];
case Melodies.Wawawawaa:
return ['e3:3', 'r:1', 'd#:3', 'r:1', 'd:4', 'r:1', 'c#:8'];
case Melodies.JumpUp:
return ['c5:1', 'd', 'e', 'f', 'g'];
case Melodies.JumpDown:
return ['g5:1', 'f', 'e', 'd', 'c'];
case Melodies.PowerUp:
return ['g4:1', 'c5', 'e', 'g:2', 'e:1', 'g:3'];
case Melodies.PowerDown:
return ['g5:1', 'd#', 'c', 'g4:2', 'b:1', 'c5:3'];
default:
return [];
}
}
}

View File

@@ -6,10 +6,9 @@ namespace music {
* @param frequency pitch of the tone to play in Hertz (Hz) * @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms) * @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
//% parts="speaker" async useEnumVal=1 //% parts="speaker" async useEnumVal=1
void playTone(int frequency, int ms) { void speakerPlayTone(int frequency, int ms) {
if(frequency > 0) uBit.soundmotor.soundOn(frequency); if(frequency > 0) uBit.soundmotor.soundOn(frequency);
else uBit.soundmotor.soundOff(); else uBit.soundmotor.soundOff();
if(ms > 0) { if(ms > 0) {

View File

@@ -119,15 +119,82 @@ enum BeatFraction {
//% block="1/8" //% block="1/8"
Eighth = 8, Eighth = 8,
//% block="1/16" //% block="1/16"
Sixteenth = 16 Sixteenth = 16,
//% block="2"
Double = 32,
//% block="4",
Breve = 64
}
enum MelodyOptions {
//% block="once""
Once = 1,
//% block="forever"
Forever = 2,
//% block="once in background"
OnceInBackground = 4,
//% block="forever in background"
ForeverInBackground = 8
}
enum MusicEvent {
//% block="melody note played"
MelodyNotePlayed = 1,
//% block="melody started"
MelodyStarted = 2,
//% block="melody ended"
MelodyEnded = 3,
//% block="melody repeated"
MelodyRepeated = 4,
//% block="background melody note played"
BackgroundMelodyNotePlayed = MelodyNotePlayed | 0xf0,
//% block="background melody started"
BackgroundMelodyStarted = MelodyStarted | 0xf0,
//% block="background melody ended"
BackgroundMelodyEnded = MelodyEnded | 0xf0,
//% block="background melody repeated"
BackgroundMelodyRepeated = MelodyRepeated | 0xf0,
//% block="background melody paused"
BackgroundMelodyPaused = 5 | 0xf0,
//% block="background melody resumed"
BackgroundMelodyResumed = 6 | 0xf0
} }
/** /**
* Generation of music tones through pin ``P0``. * Generation of music tones.
*/ */
//% color=#DF4600 weight=98 icon="\uf025" //% color=#DF4600 weight=98 icon="\uf025"
namespace music { namespace music {
let beatsPerMinute: number = 120; let beatsPerMinute: number = 120;
let freqTable: number[] = [];
let _playTone: (frequency: number, duration: number) => void;
const MICROBIT_MELODY_ID = 2000;
/**
* Plays a tone through pin ``P0`` for the given duration.
* @param frequency pitch of the tone to play in Hertz (Hz)
* @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" blockGap=8
//% parts="headphone"
//% useEnumVal=1
export function playTone(frequency: number, ms: number): void {
if (_playTone) _playTone(frequency, ms);
else speakerPlayTone(frequency, ms);
}
/**
* Plays a tone through pin ``P0``.
* @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" blockGap=8
//% parts="headphone"
//% useEnumVal=1
export function ringTone(frequency: number): void {
playTone(frequency, 0);
}
/** /**
* Rests (plays nothing) for a specified time through pin ``P0``. * Rests (plays nothing) for a specified time through pin ``P0``.
@@ -135,38 +202,28 @@ namespace music {
*/ */
//% help=music/rest weight=79 //% help=music/rest weight=79
//% blockId=device_rest block="rest(ms)|%duration=device_beat" //% blockId=device_rest block="rest(ms)|%duration=device_beat"
//% parts="speaker" //% parts="headphone"
export function rest(ms: number): void { export function rest(ms: number): void {
playTone(0, ms); playTone(0, ms);
} }
/**
* Plays a tone through ``speaker``.
* @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" blockGap=8
//% parts="speaker" async
//% useEnumVal=1
export function ringTone(frequency: number) {
playTone(frequency, 0);
}
/** /**
* Gets the frequency of a note. * Gets the frequency of a note.
* @param name the note name * @param name the note name, eg: Note.C
*/ */
//% weight=50 help=music/note-frequency //% weight=50 help=music/note-frequency
//% blockId=device_note block="%note" //% blockId=device_note block="%note"
//% shim=TD_ID blockHidden=true //% shim=TD_ID
//% blockFieldEditor="note_editor" //% note.fieldEditor="note" note.defl="262"
//% useEnumVal = 1 //% useEnumVal=1
export function noteFrequency(name: Note): number { export function noteFrequency(name: Note): number {
return name; return name;
} }
function init() { function init() {
if (beatsPerMinute <= 0) beatsPerMinute = 120; if (beatsPerMinute <= 0) beatsPerMinute = 120;
if (freqTable.length == 0) freqTable = [31, 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, 65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, 4186]
} }
/** /**
@@ -178,11 +235,15 @@ namespace music {
init(); init();
if (fraction == null) fraction = BeatFraction.Whole; if (fraction == null) fraction = BeatFraction.Whole;
let beat = 60000 / beatsPerMinute; let beat = 60000 / beatsPerMinute;
if (fraction == BeatFraction.Whole) return beat; switch (fraction) {
else if (fraction == BeatFraction.Half) return beat / 2; case BeatFraction.Half: return beat / 2;
else if (fraction == BeatFraction.Quarter) return beat / 4; case BeatFraction.Quarter: return beat / 4;
else if (fraction == BeatFraction.Eighth) return beat / 8; case BeatFraction.Eighth: return beat / 8;
else return beat / 16; case BeatFraction.Sixteenth: return beat / 16;
case BeatFraction.Double: return beat * 2;
case BeatFraction.Breve: return beat * 4;
default: return beat;
}
} }
/** /**
@@ -212,10 +273,166 @@ namespace music {
*/ */
//% help=music/set-tempo weight=38 //% help=music/set-tempo weight=38
//% blockId=device_set_tempo block="set tempo to (bpm)|%value" //% blockId=device_set_tempo block="set tempo to (bpm)|%value"
//% bpm.min=4 bpm.max=400
export function setTempo(bpm: number): void { export function setTempo(bpm: number): void {
init(); init();
if (bpm > 0) { if (bpm > 0) {
beatsPerMinute = Math.max(1, bpm); beatsPerMinute = Math.max(1, bpm);
} }
} }
let currentMelody: Melody;
let currentBackgroundMelody: Melody;
/**
* Gets the melody array of a built-in melody.
* @param name the note name, eg: Note.C
*/
//% weight=50 help=music/builtin-melody
//% blockId=device_builtin_melody block="%melody"
//% blockHidden=true
export function builtInMelody(melody: Melodies): string[] {
return getMelody(melody);
}
/**
* Registers code to run on various melody events
*/
//% blockId=melody_on_event block="music on %value"
//% help=music/on-event weight=59
export function onEvent(value: MusicEvent, handler: Action) {
control.onEvent(MICROBIT_MELODY_ID, value, handler);
}
/**
* Starts playing a melody.
* Notes are expressed as a string of characters with this format: NOTE[octave][:duration]
* @param melodyArray the melody array to play, eg: ['g5:1']
* @param options melody options, once / forever, in the foreground / background
*/
//% help=music/begin-melody weight=60 blockGap=8
//% blockId=device_start_melody block="start melody %melody=device_builtin_melody| repeating %options"
//% parts="headphone"
export function beginMelody(melodyArray: string[], options: MelodyOptions = 1) {
init();
if (currentMelody != undefined) {
if (((options & MelodyOptions.OnceInBackground) == 0)
&& ((options & MelodyOptions.ForeverInBackground) == 0)
&& currentMelody.background) {
currentBackgroundMelody = currentMelody;
currentMelody = null;
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyPaused);
}
if (currentMelody)
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyEnded : MusicEvent.MelodyEnded);
currentMelody = new Melody(melodyArray, options);
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyStarted : MusicEvent.MelodyStarted);
} else {
currentMelody = new Melody(melodyArray, options);
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyStarted : MusicEvent.MelodyStarted);
// Only start the fiber once
control.inBackground(() => {
while (currentMelody.hasNextNote()) {
playNextNote(currentMelody);
if (!currentMelody.hasNextNote() && currentBackgroundMelody) {
// Swap the background melody back
currentMelody = currentBackgroundMelody;
currentBackgroundMelody = null;
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.MelodyEnded);
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyResumed);
}
}
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyEnded : MusicEvent.MelodyEnded);
currentMelody = null;
})
}
}
/**
* Sets a custom playTone function for playing melodies
*/
//% help=music/set-play-tone
//% advanced=true
export function setPlayTone(f: (frequency: number, duration: number) => void) {
_playTone = f;
}
function playNextNote(melody: Melody): void {
// cache elements
let currNote = melody.nextNote();
let currentPos = melody.currentPos;
let currentDuration = melody.currentDuration;
let currentOctave = melody.currentOctave;
let note: number;
let isrest: boolean = false;
let beatPos: number;
let parsingOctave: boolean = true;
for (let pos = 0; pos < currNote.length; pos++) {
let noteChar = currNote.charAt(pos);
switch (noteChar) {
case 'c': case 'C': note = 1; break;
case 'd': case 'D': note = 3; break;
case 'e': case 'E': note = 5; break;
case 'f': case 'F': note = 6; break;
case 'g': case 'G': note = 8; break;
case 'a': case 'A': note = 10; break;
case 'b': case 'B': note = 12; break;
case 'r': case 'R': isrest = true; break;
case '#': note++; break;
case 'b': note--; break;
case ':': parsingOctave = false; beatPos = pos; break;
default: if (parsingOctave) currentOctave = parseInt(noteChar);
}
}
if (!parsingOctave) {
currentDuration = parseInt(currNote.substr(beatPos + 1, currNote.length - beatPos));
}
let beat = (60000 / beatsPerMinute) / 4;
if (isrest) {
music.rest(currentDuration * beat)
} else {
let keyNumber = note + (12 * (currentOctave - 1));
let frequency = keyNumber >= 0 && keyNumber < freqTable.length ? freqTable[keyNumber] : 0;
music.playTone(frequency, currentDuration * beat);
}
melody.currentDuration = currentDuration;
melody.currentOctave = currentOctave;
const repeating = melody.repeating && currentPos == melody.melodyArray.length - 1;
melody.currentPos = repeating ? 0 : currentPos + 1;
control.raiseEvent(MICROBIT_MELODY_ID, melody.background ? MusicEvent.BackgroundMelodyNotePlayed : MusicEvent.MelodyNotePlayed);
if (repeating)
control.raiseEvent(MICROBIT_MELODY_ID, melody.background ? MusicEvent.BackgroundMelodyRepeated : MusicEvent.MelodyRepeated);
}
class Melody {
public melodyArray: string[];
public currentDuration: number;
public currentOctave: number;
public currentPos: number;
public repeating: boolean;
public background: boolean;
constructor(melodyArray: string[], options: MelodyOptions) {
this.melodyArray = melodyArray;
this.repeating = ((options & MelodyOptions.Forever) != 0);
this.repeating = this.repeating ? true : ((options & MelodyOptions.ForeverInBackground) != 0)
this.background = ((options & MelodyOptions.OnceInBackground) != 0);
this.background = this.background ? true : ((options & MelodyOptions.ForeverInBackground) != 0);
this.currentDuration = 4; //Default duration (Crotchet)
this.currentOctave = 4; //Middle octave
this.currentPos = 0;
}
hasNextNote() {
return this.repeating || this.currentPos < this.melodyArray.length;
}
nextNote(): string {
const currentNote = this.melodyArray[this.currentPos];
return currentNote;
}
}
} }

View File

@@ -102,42 +102,52 @@ namespace pins {
/** /**
* Read the specified pin or connector as either 0 or 1 * Read the specified pin or connector as either 0 or 1
* @param name pin to read from * @param name pin to read from, eg: DigitalPin.P0
*/ */
//% help=pins/digital-read-pin weight=30 //% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
int digitalReadPin(DigitalPin name) { int digitalReadPin(DigitalPin name) {
PINREAD(getDigitalValue()); PINREAD(getDigitalValue());
} }
/** /**
* Set a pin or connector value to either 0 or 1. * Set a pin or connector value to either 0 or 1.
* @param name pin to write to * @param name pin to write to, eg: DigitalPin.P0
* @param value value to set on the pin, 1 eg,0 * @param value value to set on the pin, 1 eg,0
*/ */
//% help=pins/digital-write-pin weight=29 //% help=pins/digital-write-pin weight=29
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value" //% blockId=device_set_digital_pin block="digital write|pin %name|to %value"
//% value.min=0 value.max=1
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
void digitalWritePin(DigitalPin name, int value) { void digitalWritePin(DigitalPin name, int value) {
PINOP(setDigitalValue(value)); PINOP(setDigitalValue(value));
} }
/** /**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023. * Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
*/ */
//% help=pins/analog-read-pin weight=25 //% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
int analogReadPin(AnalogPin name) { int analogReadPin(AnalogPin name) {
PINREAD(getAnalogValue()); PINREAD(getAnalogValue());
} }
/** /**
* Set the connector value as analog. Value must be comprised between 0 and 1023. * Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name pin name to write to * @param name pin name to write to, eg: AnalogPin.P0
* @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0 * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0
*/ */
//% help=pins/analog-write-pin weight=24 //% help=pins/analog-write-pin weight=24
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8 //% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8
//% value.min=0 value.max=1023
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
void analogWritePin(AnalogPin name, int value) { void analogWritePin(AnalogPin name, int value) {
PINOP(setAnalogValue(value)); PINOP(setAnalogValue(value));
} }
@@ -145,20 +155,26 @@ namespace pins {
/** /**
* Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds. * Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.
* If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect. * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.
* @param name analog pin to set period to * @param name analog pin to set period to, eg: AnalogPin.P0
* @param micros period in micro seconds. eg:20000 * @param micros period in micro seconds. eg:20000
*/ */
//% help=pins/analog-set-period weight=23 blockGap=8 //% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" //% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false"
void analogSetPeriod(AnalogPin name, int micros) { void analogSetPeriod(AnalogPin name, int micros) {
PINOP(setAnalogPeriodUs(micros)); PINOP(setAnalogPeriodUs(micros));
} }
/** /**
* Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``. * Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.
* @param name digital pin to register to, eg: DigitalPin.P0
* @param pulse the value of the pulse, eg: PulseValue.High
*/ */
//% help=pins/on-pulsed weight=22 blockGap=8 //% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
void onPulsed(DigitalPin name, PulseValue pulse, Action body) { void onPulsed(DigitalPin name, PulseValue pulse, Action body) {
MicroBitPin* pin = getPin((int)name); MicroBitPin* pin = getPin((int)name);
if (!pin) return; if (!pin) return;
@@ -170,7 +186,7 @@ namespace pins {
/** /**
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler. * Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.
*/ */
//% help=pins/pulse-duration //% help=pins/pulse-duration advanced=true
//% blockId=pins_pulse_duration block="pulse duration (µs)" //% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21 blockGap=8 //% weight=21 blockGap=8
int pulseDuration() { int pulseDuration() {
@@ -179,12 +195,15 @@ namespace pins {
/** /**
* Returns the duration of a pulse in microseconds * Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse * @param name the pin which measures the pulse, eg: DigitalPin.P0
* @param value the value of the pulse (default high) * @param value the value of the pulse, eg: PulseValue.High
* @param maximum duration in micro-seconds * @param maximum duration in micro-seconds
*/ */
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value" //% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20 //% weight=20 advanced=true
//% help=pins/pulse-in
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) { int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) {
MicroBitPin* pin = getPin((int)name); MicroBitPin* pin = getPin((int)name);
if (!pin) return 0; if (!pin) return 0;
@@ -219,12 +238,15 @@ namespace pins {
/** /**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement). * Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
* @param value angle or rotation speed, eg:180,90,0 * @param value angle or rotation speed, eg:180,90,0
*/ */
//% help=pins/servo-write-pin weight=20 //% help=pins/servo-write-pin weight=20
//% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8 //% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
//% parts=microservo trackArgs=0 //% parts=microservo trackArgs=0
//% value.min=0 value.max=180
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
void servoWritePin(AnalogPin name, int value) { void servoWritePin(AnalogPin name, int value) {
fixMotorIssue(name); fixMotorIssue(name);
PINOP(setServoValue(value)); PINOP(setServoValue(value));
@@ -237,6 +259,8 @@ namespace pins {
*/ */
//% help=pins/servo-set-pulse weight=19 //% help=pins/servo-set-pulse weight=19
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros" //% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros"
//% value.fieldEditor="gridpicker" value.fieldOptions.columns=4
//% value.fieldOptions.tooltips="false"
void servoSetPulse(AnalogPin name, int micros) { void servoSetPulse(AnalogPin name, int micros) {
fixMotorIssue(name); fixMotorIssue(name);
PINOP(setServoPulseUs(micros)); PINOP(setServoPulseUs(micros));
@@ -246,48 +270,52 @@ namespace pins {
MicroBitPin* pitchPin = NULL; MicroBitPin* pitchPin = NULL;
/** /**
* Sets the pin used when using `pins->analog pitch`. * Sets the pin used when using `analog pitch` or music.
* @param name TODO * @param name pin to modulate pitch from
*/ */
//% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name" //% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name"
//% help=pins/analog-set-pitch weight=3 advanced=true //% help=pins/analog-set-pitch-pin weight=3 advanced=true
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
void analogSetPitchPin(AnalogPin name) { void analogSetPitchPin(AnalogPin name) {
pitchPin = getPin((int)name); pitchPin = getPin((int)name);
} }
/** /**
* Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin. * Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* @param frequency TODO * @param frequency frequency to modulate in Hz.
* @param ms TODO * @param ms duration of the pitch in milli seconds.
*/ */
//% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms" //% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms"
//% help=pins/analog-pitch weight=4 async advanced=true blockGap=8 //% help=pins/analog-pitch weight=4 async advanced=true blockGap=8
void analogPitch(int frequency, int ms) { void analogPitch(int frequency, int ms) {
if (pitchPin == NULL) if (pitchPin == NULL)
analogSetPitchPin(AnalogPin::P1); analogSetPitchPin(AnalogPin::P1);
if (frequency <= 0) { if (frequency <= 0) {
pitchPin->setAnalogValue(0);
} else {
pitchPin->setAnalogValue(512);
pitchPin->setAnalogPeriodUs(1000000/frequency);
}
if (ms > 0) {
fiber_sleep(ms);
pitchPin->setAnalogValue(0); pitchPin->setAnalogValue(0);
// TODO why do we use wait_ms() here? it's a busy wait I think } else {
wait_ms(5); pitchPin->setAnalogValue(512);
} pitchPin->setAnalogPeriodUs(1000000/frequency);
}
if (ms > 0) {
fiber_sleep(ms);
pitchPin->setAnalogValue(0);
// TODO why do we use wait_ms() here? it's a busy wait I think
wait_ms(5);
}
} }
/** /**
* Configures the pull of this pin. * Configures the pull of this pin.
* @param name pin to set the pull mode on * @param name pin to set the pull mode on, eg: DigitalPin.P0
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp
*/ */
//% help=pins/set-pull weight=3 //% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull" //% blockId=device_set_pull block="set pull|pin %pin|to %pull"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
void setPull(DigitalPin name, PinPullMode pull) { void setPull(DigitalPin name, PinPullMode pull) {
PinMode m = pull == PinPullMode::PullDown PinMode m = pull == PinPullMode::PullDown
? PinMode::PullDown ? PinMode::PullDown
@@ -304,6 +332,8 @@ namespace pins {
*/ */
//% help=pins/set-events weight=4 advanced=true //% help=pins/set-events weight=4 advanced=true
//% blockId=device_set_pin_events block="set pin %pin|to emit %type|events" //% blockId=device_set_pin_events block="set pin %pin|to emit %type|events"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
void setEvents(DigitalPin name, PinEventType type) { void setEvents(DigitalPin name, PinEventType type) {
getPin((int)name)->eventOn((int)type); getPin((int)name)->eventOn((int)type);
} }
@@ -337,10 +367,10 @@ namespace pins {
{ {
uBit.i2c.write(address << 1, (char*)buf->payload, buf->length, repeat); uBit.i2c.write(address << 1, (char*)buf->payload, buf->length, repeat);
} }
SPI* spi = NULL; SPI* spi = NULL;
SPI* allocSPI() { SPI* allocSPI() {
if (spi == NULL) if (NULL == spi)
spi = new SPI(MOSI, MISO, SCK); spi = new SPI(MOSI, MISO, SCK);
return spi; return spi;
} }
@@ -349,11 +379,54 @@ namespace pins {
* Write to the SPI slave and return the response * Write to the SPI slave and return the response
* @param value Data to be sent to the SPI slave * @param value Data to be sent to the SPI slave
*/ */
//% help=pins/spi-write weight=5 //% help=pins/spi-write weight=5 advanced=true
//% blockId=spi_write block="spi write %value" //% blockId=spi_write block="spi write %value"
int spiWrite(int value) { int spiWrite(int value) {
auto p = allocSPI(); auto p = allocSPI();
return p->write(value); return p->write(value);
} }
/**
* Sets the SPI frequency
* @param frequency the clock frequency, eg: 1000000
*/
//% help=pins/spi-frequency weight=4 advanced=true
//% blockId=spi_frequency block="spi frequency %frequency"
void spiFrequency(int frequency) {
auto p = allocSPI();
p->frequency(frequency);
}
/**
* Sets the SPI bits and mode
* @param bits the number of bits, eg: 8
* @param mode the mode, eg: 3
*/
//% help=pins/spi-format weight=3 advanced=true
//% blockId=spi_format block="spi format|bits %bits|mode %mode"
void spiFormat(int bits, int mode) {
auto p = allocSPI();
p->format(bits, mode);
}
/**
* Sets the MOSI, MISO, SCK pins used by the SPI instance
*
*/
//% help=pins/spi-pins weight=2 advanced=true
//% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck"
//% mosi.fieldEditor="gridpicker" mosi.fieldOptions.columns=4
//% mosi.fieldOptions.tooltips="false" mosi.fieldOptions.width="300"
//% miso.fieldEditor="gridpicker" miso.fieldOptions.columns=4
//% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="300"
//% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4
//% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="300"
void spiPins(DigitalPin mosi, DigitalPin miso, DigitalPin sck) {
if (NULL != spi) {
delete spi;
spi = NULL;
}
spi = new SPI(getPin((int)mosi)->name, getPin((int)miso)->name, getPin((int)sck)->name);
}
} }

View File

@@ -146,16 +146,16 @@ namespace pxt {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("In Segment::get index:%u\n", i); printf("In Segment::get index:%u\n", i);
this->print(); this->print();
#endif #endif
if (i < length) if (i < length)
{ {
return data[i]; return data[i];
} }
return Segment::DefaultValue; return Segment::DefaultValue;
} }
void Segment::set(uint32_t i, uint32_t value) void Segment::set(uint32_t i, uint32_t value)
{ {
if (i < size) if (i < size)
{ {
@@ -168,16 +168,16 @@ namespace pxt {
} }
if (length <= i) if (length <= i)
{ {
length = i + 1; length = i + 1;
} }
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("In Segment::set\n"); printf("In Segment::set\n");
this->print(); this->print();
#endif #endif
return; return;
} }
uint16_t Segment::growthFactor(uint16_t size) uint16_t Segment::growthFactor(uint16_t size)
{ {
@@ -201,12 +201,12 @@ namespace pxt {
growBy(max(minSize, growthFactor(size))); growBy(max(minSize, growthFactor(size)));
} }
void Segment::growBy(uint16_t newSize) void Segment::growBy(uint16_t newSize)
{ {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("growBy: %d\n", newSize); printf("growBy: %d\n", newSize);
this->print(); this->print();
#endif #endif
if (size < newSize) if (size < newSize)
{ {
//this will throw if unable to allocate //this will throw if unable to allocate
@@ -221,16 +221,16 @@ namespace pxt {
memset(tmp + size, Segment::DefaultValue, (newSize - size) * sizeof(uint32_t)); memset(tmp + size, Segment::DefaultValue, (newSize - size) * sizeof(uint32_t));
//free older segment; //free older segment;
::operator delete(data); ::operator delete(data);
data = tmp; data = tmp;
size = newSize; size = newSize;
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("growBy - after reallocation\n"); printf("growBy - after reallocation\n");
this->print(); this->print();
#endif #endif
} }
//else { no shrinking yet; } //else { no shrinking yet; }
return; return;
@@ -249,42 +249,42 @@ namespace pxt {
{ {
if (newLength > size) if (newLength > size)
{ {
ensure(length); ensure(length);
} }
length = newLength; length = newLength;
return; return;
} }
void Segment::push(uint32_t value) void Segment::push(uint32_t value)
{ {
this->set(length, value); this->set(length, value);
} }
uint32_t Segment::pop() uint32_t Segment::pop()
{ {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("In Segment::pop\n"); printf("In Segment::pop\n");
this->print(); this->print();
#endif #endif
if (length > 0) if (length > 0)
{ {
--length;
uint32_t value = data[length]; uint32_t value = data[length];
data[length] = Segment::DefaultValue; data[length] = Segment::DefaultValue;
--length;
return value; return value;
} }
return Segment::DefaultValue; return Segment::DefaultValue;
} }
//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
//left to fill the gap //left to fill the gap
uint32_t Segment::remove(uint32_t i) uint32_t Segment::remove(uint32_t i)
{ {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("In Segment::remove index:%u\n", i); printf("In Segment::remove index:%u\n", i);
this->print(); this->print();
#endif #endif
if (i < length) if (i < length)
{ {
//value to return //value to return
@@ -294,24 +294,24 @@ namespace pxt {
//Move the rest of the elements to fill in the gap. //Move the rest of the elements to fill in the gap.
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::DefaultValue; 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;
} }
return Segment::DefaultValue; return Segment::DefaultValue;
} }
//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.
void Segment::insert(uint32_t i, uint32_t value) void Segment::insert(uint32_t i, uint32_t value)
{ {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("In Segment::insert index:%u value:%u\n", i, value); printf("In Segment::insert index:%u value:%u\n", i, value);
this->print(); this->print();
#endif #endif
if (i < length) if (i < length)
{ {
@@ -322,7 +322,7 @@ namespace pxt {
memmove(data + i + 1, data + i, (length - i) * sizeof(uint32_t)); memmove(data + i + 1, data + i, (length - i) * sizeof(uint32_t));
} }
data[i] = value; data[i] = value;
length++; length++;
} }
else else
@@ -333,7 +333,7 @@ namespace pxt {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("After Segment::insert index:%u\n", i); printf("After Segment::insert index:%u\n", i);
this->print(); this->print();
#endif #endif
} }
void Segment::print() void Segment::print()
@@ -360,29 +360,29 @@ namespace pxt {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("In Segment::destroy\n"); printf("In Segment::destroy\n");
this->print(); this->print();
#endif #endif
length = size = 0; length = size = 0;
::operator delete(data); ::operator delete(data);
data = nullptr; data = nullptr;
} }
void RefCollection::push(uint32_t x) void RefCollection::push(uint32_t x)
{ {
if (isRef()) incr(x); if (isRef()) incr(x);
head.push(x); head.push(x);
} }
uint32_t RefCollection::pop() uint32_t RefCollection::pop()
{ {
uint32_t ret = head.pop(); uint32_t ret = head.pop();
if (isRef()) if (isRef())
{ {
incr(ret); incr(ret);
} }
return ret; return ret;
} }
uint32_t RefCollection::getAt(int i) uint32_t RefCollection::getAt(int i)
{ {
uint32_t tmp = head.get(i); uint32_t tmp = head.get(i);
if (isRef()) if (isRef())
@@ -392,27 +392,24 @@ namespace pxt {
return tmp; return tmp;
} }
uint32_t RefCollection::removeAt(int i) uint32_t RefCollection::removeAt(int i)
{ {
if (isRef()) // no decr() - we return the result
{
decr(head.get(i));
}
return head.remove(i); return head.remove(i);
} }
void RefCollection::insertAt(int i, uint32_t value) void RefCollection::insertAt(int i, uint32_t value)
{ {
head.insert(i, value); head.insert(i, value);
if (isRef()) if (isRef())
{ {
incr(value); incr(value);
} }
} }
void RefCollection::setAt(int i, uint32_t value) void RefCollection::setAt(int i, uint32_t value)
{ {
if (isRef()) if (isRef())
{ {
if (head.isValidIndex((uint32_t)i)) if (head.isValidIndex((uint32_t)i))
{ {
@@ -423,9 +420,9 @@ namespace pxt {
head.set(i, value); head.set(i, value);
} }
int RefCollection::indexOf(uint32_t x, int start) int RefCollection::indexOf(uint32_t x, int start)
{ {
if (isString()) if (isString())
{ {
StringData *xx = (StringData*)x; StringData *xx = (StringData*)x;
uint32_t i = start; uint32_t i = start;
@@ -443,8 +440,8 @@ namespace pxt {
} }
i++; i++;
} }
} }
else else
{ {
uint32_t i = start; uint32_t i = start;
while(head.isValidIndex(i)) while(head.isValidIndex(i))
@@ -460,11 +457,12 @@ namespace pxt {
return -1; return -1;
} }
int RefCollection::removeElement(uint32_t x) int RefCollection::removeElement(uint32_t x)
{ {
int idx = indexOf(x, 0); int idx = indexOf(x, 0);
if (idx >= 0) { if (idx >= 0) {
removeAt(idx); uint32_t elt = removeAt(idx);
if (isRef()) decr(elt);
return 1; return 1;
} }
return 0; return 0;
@@ -745,4 +743,4 @@ namespace pxt {
} }
} }
// vim: ts=2 sw=2 expandtab // vim: ts=2 sw=2 expandtab

View File

@@ -160,6 +160,7 @@ namespace pxt {
inline void unref() inline void unref()
{ {
//printf("DECR "); this->print(); //printf("DECR "); this->print();
check(refcnt > 0, ERR_REF_DELETED);
refcnt -= 2; refcnt -= 2;
if (refcnt == 0) { if (refcnt == 0) {
destroy(); destroy();

View File

@@ -27,6 +27,7 @@
"led.ts", "led.ts",
"motors.cpp", "motors.cpp",
"music.cpp", "music.cpp",
"melodies.ts",
"music.ts", "music.ts",
"pins.cpp", "pins.cpp",
"pins.ts", "pins.ts",
@@ -47,7 +48,18 @@
"optionalConfig": { "optionalConfig": {
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {
"enabled": 0 "private_addressing": 0,
"advertising_timeout": 0,
"tx_power": 6,
"dfu_service": 1,
"event_service": 1,
"device_info_service": 1,
"eddystone_url": 1,
"eddystone_uid": 1,
"open": 0,
"pairing_mode": 1,
"whitelist": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM"
} }
} }
} }

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

@@ -56,7 +56,7 @@ declare interface Image {
* @param frameOffset x offset moved on each animation step, eg: 1, 2, 5 * @param frameOffset x offset moved on each animation step, eg: 1, 2, 5
* @param interval time between each animation step in milli seconds, eg: 200 * @param interval time between each animation step in milli seconds, eg: 200
*/ */
//% help=images/show-image weight=79 async blockNamespace=images //% help=images/scroll-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 //% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
//% parts="ledmatrix" shim=ImageMethods::scrollImage //% parts="ledmatrix" shim=ImageMethods::scrollImage
scrollImage(frameOffset: number, interval: number): void; scrollImage(frameOffset: number, interval: number): void;
@@ -152,11 +152,11 @@ declare namespace basic {
* @param leds the pattern of LED to turn on/off * @param leds the pattern of LED to turn on/off
* @param interval time in milliseconds to pause after drawing * @param interval time in milliseconds to pause after drawing
*/ */
//% help=basic/show-leds //% help=basic/show-leds
//% weight=95 blockGap=8 //% weight=95 blockGap=8
//% imageLiteral=1 async //% imageLiteral=1 async
//% blockId=device_show_leds //% blockId=device_show_leds
//% block="show leds" //% block="show leds" icon="\uf00a"
//% parts="ledmatrix" interval.defl=400 shim=basic::showLeds //% parts="ledmatrix" interval.defl=400 shim=basic::showLeds
function showLeds(leds: string, interval?: number): void; function showLeds(leds: string, interval?: number): void;
@@ -165,9 +165,9 @@ declare namespace basic {
* @param text the text to scroll on the screen, eg: "Hello!" * @param text the text to scroll on the screen, eg: "Hello!"
* @param interval how fast to shift characters; eg: 150, 100, 200, -100 * @param interval how fast to shift characters; eg: 150, 100, 200, -100
*/ */
//% help=basic/show-string //% help=basic/show-string
//% weight=87 blockGap=8 //% weight=87 blockGap=8
//% block="show|string %text" //% block="show|string %text"
//% async //% async
//% blockId=device_print_message //% blockId=device_print_message
//% parts="ledmatrix" interval.defl=150 shim=basic::showString //% parts="ledmatrix" interval.defl=150 shim=basic::showString
@@ -178,7 +178,8 @@ declare namespace basic {
*/ */
//% help=basic/clear-screen weight=79 //% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" //% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix" shim=basic::clearScreen //% parts="ledmatrix"
//% advanced=true shim=basic::clearScreen
function clearScreen(): void; function clearScreen(): void;
/** /**
@@ -202,8 +203,8 @@ declare namespace basic {
* Repeats the code forever in the background. On each iteration, allows other codes to run. * Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute * @param body code to execute
*/ */
//% help=basic/forever weight=55 blockGap=8 //% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1 afterOnStart=true
//% blockId=device_forever block="forever" shim=basic::forever //% blockId=device_forever block="forever" icon="\uf01e" shim=basic::forever
function forever(a: () => void): void; function forever(a: () => void): void;
/** /**
@@ -212,19 +213,19 @@ declare namespace basic {
*/ */
//% help=basic/pause weight=54 //% help=basic/pause weight=54
//% async block="pause (ms) %pause" //% async block="pause (ms) %pause"
//% blockId=device_pause shim=basic::pause //% blockId=device_pause icon="\uf110" shim=basic::pause
function pause(ms: number): void; function pause(ms: number): void;
} }
//% color=#C90072 weight=99 icon="\uf192" //% color=#B4009E weight=99 icon="\uf192"
declare namespace input { declare namespace input {
/** /**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed * Do something when a button (A, B or both A+B) is pushed down and released again.
* @param button TODO * @param button the button that needs to be pressed
* @param body TODO * @param body code to run when event is raised
*/ */
//% help=input/on-button-pressed weight=85 blockGap=8 //% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" //% blockId=device_button_event block="on button|%NAME|pressed"
@@ -233,25 +234,27 @@ declare namespace input {
/** /**
* Do something when when a gesture is done (like shaking the micro:bit). * Do something when when a gesture is done (like shaking the micro:bit).
* @param body TODO * @param gesture the type of gesture to track, eg: Gesture.Shake
* @param body code to run when gesture is raised
*/ */
//% help=input/on-gesture weight=84 blockGap=8 //% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" //% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer" shim=input::onGesture //% parts="accelerometer"
//% NAME.fieldEditor="gridpicker" NAME.fieldOptions.columns=4 shim=input::onGesture
function onGesture(gesture: Gesture, body: () => void): void; function onGesture(gesture: Gesture, body: () => void): void;
/** /**
* Do something when a pin is pressed. * Do something when a pin is touched and released again (while also touching the GND pin).
* @param name the pin that needs to be pressed * @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed * @param body the code to run when the pin is pressed
*/ */
//% help=input/on-pin-pressed weight=83 //% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %NAME|pressed" shim=input::onPinPressed //% blockId=device_pin_event block="on pin %name|pressed" shim=input::onPinPressed
function onPinPressed(name: TouchPin, body: () => void): void; function onPinPressed(name: TouchPin, body: () => void): void;
/** /**
* Do something when a pin is released. * Do something when a pin is released.
* @param name the pin that needs to be released * @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released * @param body the code to run when the pin is released
*/ */
//% help=input/on-pin-released weight=6 blockGap=8 //% help=input/on-pin-released weight=6 blockGap=8
@@ -261,6 +264,7 @@ declare namespace input {
/** /**
* Get the button state (pressed or not) for ``A`` and ``B``. * Get the button state (pressed or not) for ``A`` and ``B``.
* @param button the button to query the request, eg: Button.A
*/ */
//% help=input/button-is-pressed weight=60 //% help=input/button-is-pressed weight=60
//% block="button|%NAME|is pressed" //% block="button|%NAME|is pressed"
@@ -271,7 +275,7 @@ declare namespace input {
/** /**
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
* @param name pin used to detect the touch * @param name pin used to detect the touch, eg: TouchPin.P0
*/ */
//% help=input/pin-is-pressed weight=58 //% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
@@ -335,16 +339,25 @@ declare namespace input {
/** /**
* Gets the number of milliseconds elapsed since power on. * Gets the number of milliseconds elapsed since power on.
*/ */
//% help=input/running-time weight=50 //% help=input/running-time weight=50 blockGap=8
//% blockId=device_get_running_time block="running time (ms)" //% blockId=device_get_running_time block="running time (ms)"
//% advanced=true shim=input::runningTime //% advanced=true shim=input::runningTime
function runningTime(): number; function runningTime(): number;
/**
* Gets the number of microseconds elapsed since power on.
*/
//% help=input/running-time-micros weight=49
//% blockId=device_get_running_time_micros block="running time (micros)"
//% advanced=true shim=input::runningTimeMicros
function runningTimeMicros(): number;
/** /**
* Obsolete, compass calibration is automatic. * Obsolete, compass calibration is automatic.
*/ */
//% help=input/calibrate weight=0 shim=input::calibrate //% help=input/calibrate-compass advanced=true
function calibrate(): void; //% blockId="input_compass_calibrate" block="calibrate compass" shim=input::calibrateCompass
function calibrateCompass(): void;
/** /**
* Sets the accelerometer sample range in gravities. * Sets the accelerometer sample range in gravities.
@@ -367,7 +380,7 @@ declare namespace control {
/** /**
* Schedules code that run in the background. * Schedules code that run in the background.
*/ */
//% help=control/in-background //% help=control/in-background blockAllowMultiple=1 afterOnStart=true
//% blockId="control_in_background" block="run in background" blockGap=8 shim=control::inBackground //% blockId="control_in_background" block="run in background" blockGap=8 shim=control::inBackground
function inBackground(a: () => void): void; function inBackground(a: () => void): void;
@@ -393,6 +406,7 @@ declare namespace control {
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE). * @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).
*/ */
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1 //% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1
//% help=control/raise-event
//% mode.defl=1 shim=control::raiseEvent //% mode.defl=1 shim=control::raiseEvent
function raiseEvent(src: number, value: number, mode?: EventCreationMode): void; function raiseEvent(src: number, value: number, mode?: EventCreationMode): void;
@@ -400,6 +414,7 @@ declare namespace control {
* Raises an event in the event bus. * Raises an event in the event bus.
*/ */
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
//% help=control/on-event
//% blockExternalInputs=1 shim=control::onEvent //% blockExternalInputs=1 shim=control::onEvent
function onEvent(src: number, value: number, handler: () => void): void; function onEvent(src: number, value: number, handler: () => void): void;
@@ -407,6 +422,7 @@ declare namespace control {
* Gets the value of the last event executed on the bus * Gets the value of the last event executed on the bus
*/ */
//% blockId=control_event_value" block="event value" //% blockId=control_event_value" block="event value"
//% help=control/event-value
//% weight=18 shim=control::eventValue //% weight=18 shim=control::eventValue
function eventValue(): number; function eventValue(): number;
@@ -414,19 +430,22 @@ declare namespace control {
* Gets the timestamp of the last event executed on the bus * Gets the timestamp of the last event executed on the bus
*/ */
//% blockId=control_event_timestamp" block="event timestamp" //% blockId=control_event_timestamp" block="event timestamp"
//% help=control/event-timestamp
//% weight=19 blockGap=8 shim=control::eventTimestamp //% weight=19 blockGap=8 shim=control::eventTimestamp
function eventTimestamp(): number; function eventTimestamp(): number;
/** /**
* Gets a friendly name for the device derived from the its serial number * Gets a friendly name for the device derived from the its serial number
*/ */
//% blockId="control_device_name" block="device name" weight=10 blockGap=8 shim=control::deviceName //% blockId="control_device_name" block="device name" weight=10 blockGap=8
//% advanced=true shim=control::deviceName
function deviceName(): string; function deviceName(): string;
/** /**
* Derive a unique, consistent serial number of this device from internal data. * Derive a unique, consistent serial number of this device from internal data.
*/ */
//% blockId="control_device_serial_number" block="device serial number" weight=9 shim=control::deviceSerialNumber //% blockId="control_device_serial_number" block="device serial number" weight=9
//% advanced=true shim=control::deviceSerialNumber
function deviceSerialNumber(): number; function deviceSerialNumber(): number;
} }
@@ -437,14 +456,28 @@ declare namespace led {
/** /**
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left. * Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x TODO * @param x the horizontal coordinate of the LED starting at 0
* @param y TODO * @param y the vertical coordinate of the LED starting at 0
*/ */
//% help=led/plot weight=78 //% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8 //% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::plot //% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::plot
function plot(x: number, y: number): void; function plot(x: number, y: number): void;
/**
* Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x the horizontal coordinate of the LED starting at 0
* @param y the vertical coordinate of the LED starting at 0
* @param brightness the brightness from 0 (off) to 255 (bright), eg:255
*/
//% help=led/plot-brightness weight=78
//% blockId=device_plot_brightness block="plot|x %x|y %y|brightness %brightness" blockGap=8
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
//% advanced=true shim=led::plotBrightness
function plotBrightness(x: number, y: number, brightness: number): void;
/** /**
* Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left. * Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x TODO * @param x TODO
@@ -452,7 +485,8 @@ declare namespace led {
*/ */
//% help=led/unplot weight=77 //% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8 //% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::unplot //% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::unplot
function unplot(x: number, y: number): void; function unplot(x: number, y: number): void;
/** /**
@@ -462,7 +496,8 @@ declare namespace led {
*/ */
//% help=led/point weight=76 //% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" //% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix" shim=led::point //% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::point
function point(x: number, y: number): boolean; function point(x: number, y: number): boolean;
/** /**
@@ -481,7 +516,8 @@ declare namespace led {
//% help=led/set-brightness weight=59 //% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value" //% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true shim=led::setBrightness //% advanced=true
//% value.min=0 value.max=255 shim=led::setBrightness
function setBrightness(value: number): void; function setBrightness(value: number): void;
/** /**
@@ -501,10 +537,16 @@ declare namespace led {
//% parts="ledmatrix" advanced=true shim=led::setDisplayMode //% parts="ledmatrix" advanced=true shim=led::setDisplayMode
function setDisplayMode(mode: DisplayMode): void; function setDisplayMode(mode: DisplayMode): void;
/**
* Gets the current display mode
*/
//% weight=1 parts="ledmatrix" advanced=true shim=led::displayMode
function displayMode(): DisplayMode;
/** /**
* Turns on or off the display * Turns on or off the display
*/ */
//% help=led/enable blockId=device_led_enable //% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix" shim=led::enable //% advanced=true parts="ledmatrix" shim=led::enable
function enable(on: boolean): void; function enable(on: boolean): void;
@@ -552,90 +594,111 @@ declare namespace music {
* @param frequency pitch of the tone to play in Hertz (Hz) * @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms) * @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 //% parts="speaker" async useEnumVal=1 shim=music::speakerPlayTone
//% parts="speaker" async useEnumVal=1 shim=music::playTone function speakerPlayTone(frequency: number, ms: number): void;
function playTone(frequency: number, ms: number): void;
} }
declare namespace pins { declare namespace pins {
/** /**
* Read the specified pin or connector as either 0 or 1 * Read the specified pin or connector as either 0 or 1
* @param name pin to read from * @param name pin to read from, eg: DigitalPin.P0
*/ */
//% help=pins/digital-read-pin weight=30 //% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 shim=pins::digitalReadPin //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300" shim=pins::digitalReadPin
function digitalReadPin(name: DigitalPin): number; function digitalReadPin(name: DigitalPin): number;
/** /**
* Set a pin or connector value to either 0 or 1. * Set a pin or connector value to either 0 or 1.
* @param name pin to write to * @param name pin to write to, eg: DigitalPin.P0
* @param value value to set on the pin, 1 eg,0 * @param value value to set on the pin, 1 eg,0
*/ */
//% help=pins/digital-write-pin weight=29 //% help=pins/digital-write-pin weight=29
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value" shim=pins::digitalWritePin //% blockId=device_set_digital_pin block="digital write|pin %name|to %value"
//% value.min=0 value.max=1
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300" shim=pins::digitalWritePin
function digitalWritePin(name: DigitalPin, value: number): void; function digitalWritePin(name: DigitalPin, value: number): void;
/** /**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023. * Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
*/ */
//% help=pins/analog-read-pin weight=25 //% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" shim=pins::analogReadPin //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::analogReadPin
function analogReadPin(name: AnalogPin): number; function analogReadPin(name: AnalogPin): number;
/** /**
* Set the connector value as analog. Value must be comprised between 0 and 1023. * Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name pin name to write to * @param name pin name to write to, eg: AnalogPin.P0
* @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0 * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0
*/ */
//% help=pins/analog-write-pin weight=24 //% help=pins/analog-write-pin weight=24
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8 shim=pins::analogWritePin //% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8
//% value.min=0 value.max=1023
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::analogWritePin
function analogWritePin(name: AnalogPin, value: number): void; function analogWritePin(name: AnalogPin, value: number): void;
/** /**
* Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds. * Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.
* If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect. * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.
* @param name analog pin to set period to * @param name analog pin to set period to, eg: AnalogPin.P0
* @param micros period in micro seconds. eg:20000 * @param micros period in micro seconds. eg:20000
*/ */
//% help=pins/analog-set-period weight=23 blockGap=8 //% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" shim=pins::analogSetPeriod //% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" shim=pins::analogSetPeriod
function analogSetPeriod(name: AnalogPin, micros: number): void; function analogSetPeriod(name: AnalogPin, micros: number): void;
/** /**
* Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``. * Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.
* @param name digital pin to register to, eg: DigitalPin.P0
* @param pulse the value of the pulse, eg: PulseValue.High
*/ */
//% help=pins/on-pulsed weight=22 blockGap=8 //% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" shim=pins::onPulsed //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300" shim=pins::onPulsed
function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void; function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void;
/** /**
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler. * Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.
*/ */
//% help=pins/pulse-duration //% help=pins/pulse-duration advanced=true
//% blockId=pins_pulse_duration block="pulse duration (µs)" //% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21 blockGap=8 shim=pins::pulseDuration //% weight=21 blockGap=8 shim=pins::pulseDuration
function pulseDuration(): number; function pulseDuration(): number;
/** /**
* Returns the duration of a pulse in microseconds * Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse * @param name the pin which measures the pulse, eg: DigitalPin.P0
* @param value the value of the pulse (default high) * @param value the value of the pulse, eg: PulseValue.High
* @param maximum duration in micro-seconds * @param maximum duration in micro-seconds
*/ */
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value" //% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20 maxDuration.defl=2000000 shim=pins::pulseIn //% weight=20 advanced=true
//% help=pins/pulse-in
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300" maxDuration.defl=2000000 shim=pins::pulseIn
function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: number): number; function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: number): number;
/** /**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement). * Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
* @param value angle or rotation speed, eg:180,90,0 * @param value angle or rotation speed, eg:180,90,0
*/ */
//% help=pins/servo-write-pin weight=20 //% help=pins/servo-write-pin weight=20
//% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8 //% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
//% parts=microservo trackArgs=0 shim=pins::servoWritePin //% parts=microservo trackArgs=0
//% value.min=0 value.max=180
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::servoWritePin
function servoWritePin(name: AnalogPin, value: number): void; function servoWritePin(name: AnalogPin, value: number): void;
/** /**
@@ -644,21 +707,25 @@ declare namespace pins {
* @param micros pulse duration in micro seconds, eg:1500 * @param micros pulse duration in micro seconds, eg:1500
*/ */
//% help=pins/servo-set-pulse weight=19 //% help=pins/servo-set-pulse weight=19
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros" shim=pins::servoSetPulse //% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros"
//% value.fieldEditor="gridpicker" value.fieldOptions.columns=4
//% value.fieldOptions.tooltips="false" shim=pins::servoSetPulse
function servoSetPulse(name: AnalogPin, micros: number): void; function servoSetPulse(name: AnalogPin, micros: number): void;
/** /**
* Sets the pin used when using `pins->analog pitch`. * Sets the pin used when using `analog pitch` or music.
* @param name TODO * @param name pin to modulate pitch from
*/ */
//% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name" //% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name"
//% help=pins/analog-set-pitch weight=3 advanced=true shim=pins::analogSetPitchPin //% help=pins/analog-set-pitch-pin weight=3 advanced=true
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::analogSetPitchPin
function analogSetPitchPin(name: AnalogPin): void; function analogSetPitchPin(name: AnalogPin): void;
/** /**
* Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin. * Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* @param frequency TODO * @param frequency frequency to modulate in Hz.
* @param ms TODO * @param ms duration of the pitch in milli seconds.
*/ */
//% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms" //% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms"
//% help=pins/analog-pitch weight=4 async advanced=true blockGap=8 shim=pins::analogPitch //% help=pins/analog-pitch weight=4 async advanced=true blockGap=8 shim=pins::analogPitch
@@ -666,11 +733,13 @@ declare namespace pins {
/** /**
* Configures the pull of this pin. * Configures the pull of this pin.
* @param name pin to set the pull mode on * @param name pin to set the pull mode on, eg: DigitalPin.P0
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp
*/ */
//% help=pins/set-pull weight=3 //% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull" shim=pins::setPull //% blockId=device_set_pull block="set pull|pin %pin|to %pull"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300" shim=pins::setPull
function setPull(name: DigitalPin, pull: PinPullMode): void; function setPull(name: DigitalPin, pull: PinPullMode): void;
/** /**
@@ -680,7 +749,9 @@ declare namespace pins {
* @param type the type of events for this pin to emit, eg: PinEventType.Edge * @param type the type of events for this pin to emit, eg: PinEventType.Edge
*/ */
//% help=pins/set-events weight=4 advanced=true //% help=pins/set-events weight=4 advanced=true
//% blockId=device_set_pin_events block="set pin %pin|to emit %type|events" shim=pins::setEvents //% blockId=device_set_pin_events block="set pin %pin|to emit %type|events"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300" shim=pins::setEvents
function setEvents(name: DigitalPin, type: PinEventType): void; function setEvents(name: DigitalPin, type: PinEventType): void;
/** /**
@@ -706,9 +777,40 @@ declare namespace pins {
* Write to the SPI slave and return the response * Write to the SPI slave and return the response
* @param value Data to be sent to the SPI slave * @param value Data to be sent to the SPI slave
*/ */
//% help=pins/spi-write weight=5 //% help=pins/spi-write weight=5 advanced=true
//% blockId=spi_write block="spi write %value" shim=pins::spiWrite //% blockId=spi_write block="spi write %value" shim=pins::spiWrite
function spiWrite(value: number): number; function spiWrite(value: number): number;
/**
* Sets the SPI frequency
* @param frequency the clock frequency, eg: 1000000
*/
//% help=pins/spi-frequency weight=4 advanced=true
//% blockId=spi_frequency block="spi frequency %frequency" shim=pins::spiFrequency
function spiFrequency(frequency: number): void;
/**
* Sets the SPI bits and mode
* @param bits the number of bits, eg: 8
* @param mode the mode, eg: 3
*/
//% help=pins/spi-format weight=3 advanced=true
//% blockId=spi_format block="spi format|bits %bits|mode %mode" shim=pins::spiFormat
function spiFormat(bits: number, mode: number): void;
/**
* Sets the MOSI, MISO, SCK pins used by the SPI instance
*
*/
//% help=pins/spi-pins weight=2 advanced=true
//% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck"
//% mosi.fieldEditor="gridpicker" mosi.fieldOptions.columns=4
//% mosi.fieldOptions.tooltips="false" mosi.fieldOptions.width="300"
//% miso.fieldEditor="gridpicker" miso.fieldOptions.columns=4
//% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="300"
//% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4
//% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="300" shim=pins::spiPins
function spiPins(mosi: DigitalPin, miso: DigitalPin, sck: DigitalPin): void;
} }

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "pxt-calliope", "name": "pxt-calliope",
"version": "1.0.13", "version": "1.0.19",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "pxt-calliope", "name": "pxt-calliope",
"version": "1.0.14", "version": "1.0.20",
"description": "Calliope Mini editor for PXT", "description": "Calliope Mini editor for PXT",
"keywords": [ "keywords": [
"JavaScript", "JavaScript",
@@ -36,7 +36,7 @@
"semantic-ui-less": "^2.2.4" "semantic-ui-less": "^2.2.4"
}, },
"dependencies": { "dependencies": {
"pxt-core": "0.14.32" "pxt-core": "0.17.4"
}, },
"scripts": { "scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis" "test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@@ -24,6 +24,10 @@
"deployDrives": "MINI", "deployDrives": "MINI",
"driveName": "MINI", "driveName": "MINI",
"hexMimeType": "application/x-calliope-hex", "hexMimeType": "application/x-calliope-hex",
"openocdScript": "source [find interface/cmsis-dap.cfg]; source [find target/nrf51.cfg]",
"flashUsableEnd": 245760,
"flashEnd": 245760,
"flashCodeAlign": 1024,
"upgrades": [ "upgrades": [
{ {
"type": "package", "type": "package",
@@ -54,11 +58,15 @@
"logicBlocks": true, "logicBlocks": true,
"variablesBlocks": true, "variablesBlocks": true,
"textBlocks": true, "textBlocks": true,
"listsBlocks": true,
"functionBlocks": true,
"onStartColor": "#54C9C9", "onStartColor": "#54C9C9",
"onStartNamespace": "basic" "onStartNamespace": "basic",
"onStartWeight": 54
}, },
"simulator": { "simulator": {
"autoRun": true, "autoRun": true,
"enableTrace": true,
"streams": true, "streams": true,
"aspectRatio": 1.13, "aspectRatio": 1.13,
"parts": false, "parts": false,
@@ -202,7 +210,7 @@
"hideSideDocs": true, "hideSideDocs": true,
"invertedMenu": true, "invertedMenu": true,
"invertedToolbox": true, "invertedToolbox": true,
"monacoToolbox": false, "monacoToolbox": true,
"hasAudio": true, "hasAudio": true,
"highContrast": true, "highContrast": true,
"simAnimationEnter": "rotate in", "simAnimationEnter": "rotate in",

295
pxtwapp/.gitignore vendored Normal file
View File

@@ -0,0 +1,295 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

48
pxtwapp/pxtwapp.sln Normal file
View File

@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "pxtwapp", "pxtwapp\pxtwapp.jsproj", "{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|ARM.ActiveCfg = Debug|ARM
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|ARM.Build.0 = Debug|ARM
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|ARM.Deploy.0 = Debug|ARM
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|x64.ActiveCfg = Debug|x64
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|x64.Build.0 = Debug|x64
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|x64.Deploy.0 = Debug|x64
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|x86.ActiveCfg = Debug|x86
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|x86.Build.0 = Debug|x86
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Debug|x86.Deploy.0 = Debug|x86
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|Any CPU.Build.0 = Release|Any CPU
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|Any CPU.Deploy.0 = Release|Any CPU
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|ARM.ActiveCfg = Release|ARM
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|ARM.Build.0 = Release|ARM
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|ARM.Deploy.0 = Release|ARM
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|x64.ActiveCfg = Release|x64
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|x64.Build.0 = Release|x64
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|x64.Deploy.0 = Release|x64
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|x86.ActiveCfg = Release|x86
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|x86.Build.0 = Release|x86
{34E8CDE2-3991-414E-BB19-BFF4BD5E031A}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -0,0 +1,40 @@
body {
margin: 10px;
background-color: #6633cc;
color: #FFFFFF;
font-family: 'Open Sans', 'Helvetica Neue', Arial, Helvetica, sans-serif;
}
.paramName {
font-size: 10px;
font-weight: bold;
}
.paramValue {
font-size: 10px;
padding-left: 10px;
}
.param {
margin-bottom: 8px;
}
#retryButton {
box-shadow: 0px 0em 0px 0px rgba(34, 36, 38, 0.15) inset;
outline: none;
border: none;
vertical-align: baseline;
padding: 0.78571429em 1.5em 0.78571429em;
text-transform: none;
font-weight: bold;
font-style: normal;
text-align: center;
text-decoration: none;
border-radius: 0.28571429rem;
background-color: #ff8b27;
margin: 15px 10px 100px 10px;
width: 80px;
height: 35px;
font-size: 15px;
color: #FFFFFF;
}

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Oops!</title>
<link href="msapp-error.css" rel="stylesheet" type="text/css" />
<script src="msapp-error.js" type="text/javascript"></script>
</head>
<body>
<h1>Oops! Please connect to the Internet.</h1>
<button id="retryButton">Retry</button>
<div id="failureUrl" class="param">
<span class="paramName">URL:</span>
<span id="failureUrlValue" class="paramValue"></span>
</div>
<div id="httpStatus" class="param">
<span class="paramName">HTTP status:</span>
<span id="httpStatusValue" class="paramValue"></span>
</div>
<div id="failureName">
<span class="paramName">Failure name:</span>
<span id="failureNameValue" class="paramValue"></span>
</div>
</body>
</html>

View File

@@ -0,0 +1,47 @@
(function () {
var validParameterNames = ["httpStatus", "failureName", "failureUrl"];
function parseQueryParameters() {
var query = location.search.slice(1);
return query.split("&").reduce(function (queryParameters, rawPair) {
var pair = rawPair.split("=").map(decodeURIComponent);
queryParameters[pair[0]] = pair[1];
return queryParameters;
}, {});
}
function initialize() {
var queryParameters = parseQueryParameters();
var url = queryParameters["failureUrl"];
var retryButton = document.getElementById("retryButton");
if (url) {
retryButton.addEventListener("click", (e) => {
window.location.href = url;
});
} else {
retryButton.style.display = none;
}
validParameterNames.forEach(function (parameterName) {
var parameterValue = queryParameters[parameterName];
if (parameterValue) {
document.getElementById(parameterName + "Value").textContent = parameterValue;
} else {
document.getElementById(parameterName).remove();
}
});
}
function updateOnlineStatus(e) {
var queryParameters = parseQueryParameters();
var url = queryParameters["failureUrl"];
if (url) {
window.location.href = url;
}
}
window.addEventListener("online", updateOnlineStatus);
document.addEventListener("DOMContentLoaded", initialize);
}());

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap uap3 mp">
<Identity Name="CalliopeMini" Version="1.0.0.0" Publisher="CN=calliope" />
<mp:PhoneIdentity PhoneProductId="5ddd542e-5ab4-48bc-b116-0782dc08ab97" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>Microsoft MakeCode for Calliope Mini</DisplayName>
<PublisherDisplayName>Calliope.cc</PublisherDisplayName>
<Logo>images\storelogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" StartPage="https://makecode.calliope.cc/">
<uap:ApplicationContentUriRules>
<uap:Rule Match="https://makecode.calliope.cc/" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://trg-calliope.userpxt.io/---simulator" Type="include" WindowsRuntimeAccess="none" />
<uap:Rule Match="https://makecode.calliope.cc/beta" Type="include" WindowsRuntimeAccess="all" />
<uap:Rule Match="https://trg-calliope.userpxt.io/beta---simulator" Type="include" WindowsRuntimeAccess="none" />
</uap:ApplicationContentUriRules>
<uap:VisualElements DisplayName="Microsoft MakeCode for Calliope Mini" Description="Microsoft MakeCode for Calliope Mini" BackgroundColor="#249899" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\SmallTile.png">
</uap:DefaultTile>
<uap:SplashScreen Image="images\SplashScreen.png" BackgroundColor="#303030" />
</uap:VisualElements>
<Extensions>
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="makecode">
<uap:DisplayName>Microsoft MakeCode binary file</uap:DisplayName>
<uap:SupportedFileTypes>
<uap:FileType ContentType="application/x-makecode-hex">.hex</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
<uap3:Extension Category="windows.appUriHandler">
<uap3:AppUriHandler>
<uap3:Host Name="makecode.calliope.cc" />
</uap3:AppUriHandler>
</uap3:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
<DeviceCapability Name="humaninterfacedevice">
<Device Id="vidpid:0d28 0204">
<Function Type="usage:FF00 *" />
</Device>
</DeviceCapability>
</Capabilities>
</Package>

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>34e8cde2-3991-414e-bb19-bff4bd5e031a</ProjectGuid>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0'">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).props" />
<PropertyGroup>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>$(VersionNumberMajor).$(VersionNumberMinor)</MinimumVisualStudioVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<PackageCertificateKeyFile>pxtwapp_TemporaryKey.pfx</PackageCertificateKeyFile>
<AppxAutoIncrementPackageRevision>true</AppxAutoIncrementPackageRevision>
<AppxBundle>Always</AppxBundle>
<AppxBundlePlatforms>x86|x64|arm</AppxBundlePlatforms>
<PackageCertificateThumbprint>BA3D3E800661F789BAE7216F8D6F76608D1C4D62</PackageCertificateThumbprint>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<Content Include="images\logo.png" />
<Content Include="images\SmallTile.scale-200.png" />
<Content Include="images\Square44x44Logo.altform-unplated_targetsize-48.png" />
<Content Include="images\Square44x44Logo.targetsize-48.png" />
<Content Include="images\storelogo.scale-200.png" />
<Content Include="msapp-error.js" />
<Content Include="msapp-error.css" />
<Content Include="msapp-error.html" />
<Content Include="images\SplashScreen.scale-200.png" />
<Content Include="images\Square150x150Logo.scale-200.png" />
<Content Include="images\Square44x44Logo.scale-200.png" />
<Content Include="images\Wide310x150Logo.scale-200.png" />
<None Include="pxtwapp_TemporaryKey.pfx" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).targets" />
<!-- To modify your build process, add your task inside one of the targets below then uncomment
that target and the DisableFastUpToDateCheck PropertyGroup.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
-->
</Project>

View File

@@ -18,6 +18,9 @@ namespace pxsim {
speakerState: SpeakerState; speakerState: SpeakerState;
fileSystem: FileSystemState; fileSystem: FileSystemState;
// visual
view: SVGElement;
constructor() { constructor() {
super() super()
@@ -94,7 +97,7 @@ namespace pxsim {
break; break;
case "serial": case "serial":
let data = (<SimulatorSerialMessage>msg).data || ""; let data = (<SimulatorSerialMessage>msg).data || "";
this.serialState.recieveData(data); this.serialState.receiveData(data);
break; break;
case "radiopacket": case "radiopacket":
let packet = <SimulatorRadioPacketMessage>msg; let packet = <SimulatorRadioPacketMessage>msg;
@@ -121,16 +124,22 @@ namespace pxsim {
fnArgs: fnArgs, fnArgs: fnArgs,
maxWidth: "100%", maxWidth: "100%",
maxHeight: "100%", maxHeight: "100%",
highContrast: msg.highContrast
}; };
const viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView({ const viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView({
visual: boardDef.visual visual: boardDef.visual,
highContrast: msg.highContrast
}), opts); }), opts);
document.body.innerHTML = ""; // clear children document.body.innerHTML = ""; // clear children
document.body.appendChild(viewHost.getView()); document.body.appendChild(this.view = viewHost.getView());
return Promise.resolve(); return Promise.resolve();
} }
screenshot(): string {
return svg.toDataUri(new XMLSerializer().serializeToString(this.view));
}
} }
export function initRuntimeWithDalBoard() { export function initRuntimeWithDalBoard() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -28,7 +28,7 @@ namespace pxsim {
this.data = data; this.data = data;
} }
public print() { public print() {
console.log(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`) // console.debug(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
} }
public get(x: number, y: number): number { public get(x: number, y: number): number {
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0; if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
@@ -131,15 +131,33 @@ namespace pxsim.images {
namespace pxsim.ImageMethods { namespace pxsim.ImageMethods {
export function showImage(leds: Image, offset: number, interval: number) { export function showImage(leds: Image, offset: number, interval: number) {
pxtrt.nullCheck(leds) pxtrt.nullCheck(leds)
leds.copyTo(offset, 5, board().ledMatrixState.image, 0) let cb = getResume();
runtime.queueDisplayUpdate() let first = true;
basic.pause(interval);
board().ledMatrixState.animationQ.enqueue({
interval,
frame: () => {
if (first) {
leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
first = false;
return true;
}
return false;
},
whenDone: cb
})
} }
export function plotImage(leds: Image, offset: number): void { export function plotImage(leds: Image, offset: number): void {
pxtrt.nullCheck(leds) pxtrt.nullCheck(leds)
leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
runtime.queueDisplayUpdate() board().ledMatrixState.animationQ.enqueue({
interval: 0,
frame: () => {
leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
return false;
}
})
} }
export function height(leds: Image): number { export function height(leds: Image): number {
@@ -216,15 +234,16 @@ namespace pxsim.ImageMethods {
namespace pxsim.basic { namespace pxsim.basic {
export function showNumber(x: number, interval: number) { export function showNumber(x: number, interval: number) {
if (interval < 0) return; if (interval <= 0)
interval = 1;
let leds = createImageFromString(x.toString()); let leds = createImageFromString(x.toString());
if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, 1, interval); if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, 1, interval);
else showLeds(leds, interval * 5); else showLeds(leds, interval * 5);
} }
export function showString(s: string, interval: number) { export function showString(s: string, interval: number) {
if (interval < 0) return; if (interval <= 0)
interval = 1;
if (s.length == 0) { if (s.length == 0) {
clearScreen(); clearScreen();
pause(interval * 5); pause(interval * 5);
@@ -254,7 +273,16 @@ namespace pxsim.basic {
namespace pxsim.led { namespace pxsim.led {
export function plot(x: number, y: number) { export function plot(x: number, y: number) {
board().ledMatrixState.image.set(x, y, 255); board().ledMatrixState.image.set(x, y, 0xff);
runtime.queueDisplayUpdate()
}
export function plotBrightness(x: number, y: number, brightness: number) {
const state = board().ledMatrixState;
brightness = Math.max(0, Math.min(0xff, brightness));
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
state.displayMode = DisplayMode.greyscale;
state.image.set(x, y, brightness);
runtime.queueDisplayUpdate() runtime.queueDisplayUpdate()
} }
@@ -272,7 +300,7 @@ namespace pxsim.led {
} }
export function setBrightness(value: number): void { export function setBrightness(value: number): void {
board().ledMatrixState.brigthness = value; board().ledMatrixState.brigthness = Math.max(0, Math.min(255, value));
runtime.queueDisplayUpdate() runtime.queueDisplayUpdate()
} }
@@ -286,6 +314,10 @@ namespace pxsim.led {
runtime.queueDisplayUpdate() runtime.queueDisplayUpdate()
} }
export function displayMode(): DisplayMode {
return board().ledMatrixState.displayMode;
}
export function screenshot(): Image { export function screenshot(): Image {
let img = createImage(5) let img = createImage(5)
board().ledMatrixState.image.copyTo(0, 5, img, 0); board().ledMatrixState.image.copyTo(0, 5, img, 0);

View File

@@ -7,7 +7,7 @@ namespace pxsim {
} }
namespace pxsim.music { namespace pxsim.music {
export function playTone(frequency: number, ms: number) { export function speakerPlayTone(frequency: number, ms: number) {
const b = board(); const b = board();
b.speakerState.frequency = frequency; b.speakerState.frequency = frequency;
b.speakerState.ms = ms; b.speakerState.ms = ms;

View File

@@ -1,8 +1,9 @@
namespace pxsim { namespace pxsim {
const SERIAL_BUFFER_LENGTH = 16;
export class SerialState { export class SerialState {
serialIn: string[] = []; serialIn: string[] = [];
public recieveData(data: string) { public receiveData(data: string) {
this.serialIn.push(); this.serialIn.push();
} }
@@ -13,18 +14,15 @@ namespace pxsim {
serialOutBuffer: string = ""; serialOutBuffer: string = "";
writeSerial(s: string) { writeSerial(s: string) {
for (let i = 0; i < s.length; ++i) { this.serialOutBuffer += s;
let c = s[i]; if (/\n/.test(this.serialOutBuffer) || this.serialOutBuffer.length > SERIAL_BUFFER_LENGTH) {
this.serialOutBuffer += c; Runtime.postMessage(<SimulatorSerialMessage>{
if (c == "\n") { type: 'serial',
Runtime.postMessage(<SimulatorSerialMessage>{ data: this.serialOutBuffer,
type: "serial", id: runtime.id,
data: this.serialOutBuffer, sim: true
id: runtime.id })
}) this.serialOutBuffer = '';
this.serialOutBuffer = ""
break;
}
} }
} }
} }
@@ -51,4 +49,8 @@ namespace pxsim.serial {
export function redirect(tx: number, rx: number, rate: number) { export function redirect(tx: number, rx: number, rate: number) {
// TODO? // TODO?
} }
export function redirectToUSB() {
// TODO
}
} }

View File

@@ -11,6 +11,8 @@
"Tinkertanker/pxt-ssd1306-microbit" "Tinkertanker/pxt-ssd1306-microbit"
], ],
"preferredRepos": [ "preferredRepos": [
"Microsoft/pxt-neopixel",
"Microsoft/pxt-microturtle",
"calliope-mini/pxt-calliope-modem", "calliope-mini/pxt-calliope-modem",
"calliope-mini/pxt-calliope-bc95", "calliope-mini/pxt-calliope-bc95",
"calliope-mini/pxt-calliope-esp", "calliope-mini/pxt-calliope-esp",

View File

@@ -11,10 +11,13 @@
Blockly Blockly
*******************************/ *******************************/
div.blocklyTreeRow { .blocklyToolboxDiv {
box-shadow: inset 0 -1px 0 0 #ecf0f1; padding:7px;
}
margin-bottom: 0px !important; div.blocklyTreeRow {
border-radius:8px;
box-shadow: inset 0 -1px 0 0 #ecf0f1;
-webkit-transition-property: background-color; /* Safari */ -webkit-transition-property: background-color; /* Safari */
-webkit-transition-duration: 1s; /* Safari */ -webkit-transition-duration: 1s; /* Safari */
@@ -29,15 +32,10 @@ span.blocklyTreeLabel {
} }
.blocklyToolboxDiv, .monacoToolboxDiv { .blocklyToolboxDiv, .monacoToolboxDiv {
background-color: white !important;
border-left: 1px solid #ecf0f1 !important; border-left: 1px solid #ecf0f1 !important;
box-shadow: 4px 0px 2px -4px rgba(0,0,0,0.12), 4px 0px 2px -4px rgba(0,0,0,0.24); box-shadow: 4px 0px 2px -4px rgba(0,0,0,0.12), 4px 0px 2px -4px rgba(0,0,0,0.24);
} }
.blocklyFlyoutBackground {
fill: #525A67 !important;
}
/* Remove shadow around blockly blocks */ /* Remove shadow around blockly blocks */
.blocklyPathDark, .blocklyPathLight { .blocklyPathDark, .blocklyPathLight {
display: none; display: none;
@@ -52,6 +50,10 @@ span.blocklyTreeLabel {
border-radius: 10px; border-radius: 10px;
} }
.blocklyFlyoutBackground {
fill: #42495F !important;
}
/* Mobile */ /* Mobile */
@media only screen and (max-width: @largestMobileScreen) { @media only screen and (max-width: @largestMobileScreen) {
.blocklyToolboxDiv, .monacoToolboxDiv { .blocklyToolboxDiv, .monacoToolboxDiv {

View File

@@ -4,10 +4,3 @@
@invertedBackground: #525A67; @invertedBackground: #525A67;
@dropdownMenuDistance: 0px; @dropdownMenuDistance: 0px;
/*******************************
PXT Theme Overrides
*******************************/
@mainMenuHeight: 5rem;
@mainMenuMinHeight: (@itemVerticalPadding * 2) + 2em;

View File

@@ -6,9 +6,6 @@
@fontName : 'Roboto Mono'; @fontName : 'Roboto Mono';
@emSize : 14px;
@fontSize : 13px;
/*------------------- /*-------------------
Site Colors Site Colors
--------------------*/ --------------------*/
@@ -35,8 +32,6 @@
PXT Overrides PXT Overrides
*******************************/ *******************************/
@mainMenuHeight: 5rem;
@mobileMenuHeight: 5rem;
@blocklyToolboxColor: #F6F4E6; @blocklyToolboxColor: #F6F4E6;
@blocklyFlyoutColor: #42495F;

View File

@@ -47,31 +47,8 @@
width: 100%; width: 100%;
} }
/******************************* #downloadArea {
Blockly background: transparent !important;
*******************************/
div.blocklyTreeRow {
border-radius:8px;
}
/* This removes any padding at the top of the toolbox */
div.blocklyTreeRoot {
padding: 0px !important;
}
/* Blockly Text */
div.blocklyTreeLabel {
font-family: @pageFont !important;
font-size:1rem !important;
}
.blocklyFlyoutBackground {
fill: @grey;
}
.blocklyToolboxDiv {
padding:7px;
} }
.organization { .organization {
@@ -85,8 +62,19 @@ div.blocklyTreeLabel {
} }
} }
/* Mobile */
@media only screen and (max-width: @largestMobileScreen) {
#filelist {
background: transparent !important;
}
}
/* 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 */
@@ -96,15 +84,3 @@ div.blocklyTreeLabel {
/* Large Monitor */ /* Large Monitor */
@media only screen and (min-width: @largeMonitorBreakpoint) { @media only screen and (min-width: @largeMonitorBreakpoint) {
} }
/*******************************
Menu Bar
*******************************/
#menubar {
height: 5rem;
}
#fileNameInput {
width: 350px;
}

View File

@@ -43,16 +43,16 @@
@form : 'default'; @form : 'default';
@grid : 'pxt'; @grid : 'pxt';
@menu : 'pxt'; @menu : 'pxt';
@message : 'default'; @message : 'pxt';
@table : 'default'; @table : 'default';
/* Modules */ /* Modules */
@accordion : 'default'; @accordion : 'default';
@checkbox : 'default'; @checkbox : 'default';
@dimmer : 'default'; @dimmer : 'pxt';
@dropdown : 'default'; @dropdown : 'default';
@embed : 'default'; @embed : 'default';
@modal : 'default'; @modal : 'pxt';
@nag : 'default'; @nag : 'default';
@popup : 'default'; @popup : 'default';
@progress : 'default'; @progress : 'default';
@@ -66,7 +66,7 @@
/* Views */ /* Views */
@ad : 'default'; @ad : 'default';
@card : 'default'; @card : 'pxt';
@comment : 'default'; @comment : 'default';
@feed : 'default'; @feed : 'default';
@item : 'default'; @item : 'default';
@@ -91,5 +91,9 @@
@fontPath : 'fonts'; @fontPath : 'fonts';
/*
@headerFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif;
@pageFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif;
*/
/* End Config */ /* End Config */