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
This commit is contained in:
		@@ -17,44 +17,18 @@
 | 
			
		||||
        "config": {
 | 
			
		||||
            "microbit-dal": {
 | 
			
		||||
                "bluetooth": {
 | 
			
		||||
                    "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
 | 
			
		||||
                    "enabled": 1
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        "optionalConfig": {
 | 
			
		||||
            "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"
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        "userConfigs": [
 | 
			
		||||
            {
 | 
			
		||||
                "description": "Unsecure: Anyone can connect via Bluetooth.",
 | 
			
		||||
                "description": "No Pairing Required: Anyone can connect via Bluetooth.",
 | 
			
		||||
                "config": {
 | 
			
		||||
                    "microbit-dal": {
 | 
			
		||||
                        "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": {
 | 
			
		||||
                    "microbit-dal": {
 | 
			
		||||
                        "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": {
 | 
			
		||||
                    "microbit-dal": {
 | 
			
		||||
                        "bluetooth": {
 | 
			
		||||
 
 | 
			
		||||
@@ -58,6 +58,7 @@
 | 
			
		||||
  "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.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.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",
 | 
			
		||||
@@ -167,13 +168,14 @@
 | 
			
		||||
  "control.waitMicros": "Blocks the current fiber for the given microseconds",
 | 
			
		||||
  "control.waitMicros|param|micros": "number of micro-seconds to wait. eg: 4",
 | 
			
		||||
  "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.brightness": "Reports the ``brightness` of a sprite on the LED screen",
 | 
			
		||||
  "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|param|ms": "TODO",
 | 
			
		||||
  "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|param|angle": "TODO",
 | 
			
		||||
  "game.LedSprite.changeXBy": "Changes the ``x`` position by the given amount",
 | 
			
		||||
@@ -182,19 +184,18 @@
 | 
			
		||||
  "game.LedSprite.changeYBy|param|y": "TODO",
 | 
			
		||||
  "game.LedSprite.change|param|property": "the name of the property to change",
 | 
			
		||||
  "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|param|sprite": "TODO",
 | 
			
		||||
  "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.direction": "Reports the current direction of a sprite",
 | 
			
		||||
  "game.LedSprite.get": "Gets a property of the sprite",
 | 
			
		||||
  "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|param|x": "TODO",
 | 
			
		||||
  "game.LedSprite.goTo|param|y": "TODO",
 | 
			
		||||
  "game.LedSprite.ifOnEdgeBounce": "If touching the edge of the stage, then bounce away.",
 | 
			
		||||
  "game.LedSprite.isTouching": "Reports true if sprite is touching specified sprite",
 | 
			
		||||
  "game.LedSprite.ifOnEdgeBounce": "If touching the edge of the stage and facing towards it, then turn away.",
 | 
			
		||||
  "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.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.off": "Turns off the sprite (on by default)",
 | 
			
		||||
  "game.LedSprite.on": "Turns on the sprite (on by default)",
 | 
			
		||||
@@ -202,7 +203,7 @@
 | 
			
		||||
  "game.LedSprite.setBlink": "Sets the blink duration interval in millisecond.",
 | 
			
		||||
  "game.LedSprite.setBlink|param|ms": "TODO",
 | 
			
		||||
  "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|param|degrees": "TODO",
 | 
			
		||||
  "game.LedSprite.setX": "Set the ``x`` position of a sprite",
 | 
			
		||||
@@ -221,28 +222,31 @@
 | 
			
		||||
  "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|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.createSprite": "Creates a new LED sprite pointing to the right.",
 | 
			
		||||
  "game.createSprite|param|x": "sprite horizontal 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.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.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.level": "Gets the current level",
 | 
			
		||||
  "game.levelUp": "Increments the level and display a message.",
 | 
			
		||||
  "game.life": "Gets the current life",
 | 
			
		||||
  "game.pause": "Pauses the game rendering engine to allow other animations",
 | 
			
		||||
  "game.removeLife": "Removes some life",
 | 
			
		||||
  "game.removeLife|param|life": "TODO",
 | 
			
		||||
  "game.resume": "Resumes the game rendering engine",
 | 
			
		||||
  "game.score": "Gets the current score",
 | 
			
		||||
  "game.setLife": "Sets the current life value",
 | 
			
		||||
  "game.setLife|param|value": "TODO",
 | 
			
		||||
  "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.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.startStopwatch": "Starts a stopwatch timer. `current time` will return the elapsed time.",
 | 
			
		||||
  "images": "Creation, manipulation and display of LED images.",
 | 
			
		||||
@@ -252,26 +256,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|param|dimension": "TODO",
 | 
			
		||||
  "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.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|param|dimension": "TODO",
 | 
			
		||||
  "input.onButtonPressed": "Do something when a button (``A``, ``B`` or both ``A+B``) is pressed",
 | 
			
		||||
  "input.onButtonPressed|param|body": "TODO",
 | 
			
		||||
  "input.onButtonPressed|param|button": "TODO",
 | 
			
		||||
  "input.onButtonPressed": "Do something when a button (A, B or both A+B) is pushed down and released again.",
 | 
			
		||||
  "input.onButtonPressed|param|body": "code to run when event is raised",
 | 
			
		||||
  "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|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|param|body": "TODO",
 | 
			
		||||
  "input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.",
 | 
			
		||||
  "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|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|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|param|body": "TODO",
 | 
			
		||||
  "input.onScreenUp": "Attaches code to run when the screen is facing up.",
 | 
			
		||||
@@ -279,15 +285,17 @@
 | 
			
		||||
  "input.onShake": "Attaches code to run when the device is shaken.",
 | 
			
		||||
  "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|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|param|kind": "TODO",
 | 
			
		||||
  "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|param|range": "a value describe the maximum strengh of acceleration measured",
 | 
			
		||||
  "input.temperature": "Gets the temperature in Celsius degrees (°C).",
 | 
			
		||||
  "led": "Control of the LED screen.",
 | 
			
		||||
  "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.fadeIn": "Fades in the screen display.",
 | 
			
		||||
  "led.fadeIn|param|ms": "TODO",
 | 
			
		||||
@@ -298,8 +306,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|param|high": "maximum value. If 0, maximum value adjusted automatically, eg: 0",
 | 
			
		||||
  "led.plotBarGraph|param|value": "current value to plot",
 | 
			
		||||
  "led.plot|param|x": "TODO",
 | 
			
		||||
  "led.plot|param|y": "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.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|param|x": "TODO",
 | 
			
		||||
  "led.point|param|y": "TODO",
 | 
			
		||||
@@ -349,24 +361,24 @@
 | 
			
		||||
  "parseInt": "Convert A string to an integer.",
 | 
			
		||||
  "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|param|frequency": "TODO",
 | 
			
		||||
  "pins.analogPitch|param|ms": "TODO",
 | 
			
		||||
  "pins.analogPitch|param|frequency": "frequency to modulate in Hz.",
 | 
			
		||||
  "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|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|param|micros": "period in micro seconds. eg:20000",
 | 
			
		||||
  "pins.analogSetPeriod|param|name": "analog pin to set period to",
 | 
			
		||||
  "pins.analogSetPitchPin": "Sets the pin used when using `pins->analog pitch`.",
 | 
			
		||||
  "pins.analogSetPitchPin|param|name": "TODO",
 | 
			
		||||
  "pins.analogSetPeriod|param|name": "analog pin to set period to, eg: AnalogPin.P0",
 | 
			
		||||
  "pins.analogSetPitchPin": "Sets the pin used when using `analog pitch` or music.",
 | 
			
		||||
  "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|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.createBuffer": "Create a new zero-initialized 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|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|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.i2cReadBuffer": "Read `size` bytes from a 7-bit I2C `address`.",
 | 
			
		||||
  "pins.i2cReadNumber": "Read one number from 7-bit I2C address.",
 | 
			
		||||
@@ -379,23 +391,31 @@
 | 
			
		||||
  "pins.map|param|toLow": "the lower bound of the value's target range",
 | 
			
		||||
  "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|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.pulseIn": "Returns the duration of a pulse in microseconds",
 | 
			
		||||
  "pins.pulseIn|param|name": "the pin which measures the pulse",
 | 
			
		||||
  "pins.pulseIn|param|value": "the value of the pulse (default high)",
 | 
			
		||||
  "pins.pulseIn|param|name": "the pin which measures the pulse, eg: DigitalPin.P0",
 | 
			
		||||
  "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|param|micros": "pulse duration in micro seconds, eg:1500",
 | 
			
		||||
  "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|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.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|type": "the type of events for this pin to emit, eg: PinEventType.Edge",
 | 
			
		||||
  "pins.setPull": "Configures the pull of this pin.",
 | 
			
		||||
  "pins.setPull|param|name": "pin to set the pull mode on",
 | 
			
		||||
  "pins.setPull|param|pull": "one of the mbed pull configurations: PullUp, PullDown, PullNone ",
 | 
			
		||||
  "pins.setPull|param|name": "pin to set the pull mode on, eg: DigitalPin.P0",
 | 
			
		||||
  "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.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|param|value": "Data to be sent to the SPI slave",
 | 
			
		||||
  "serial": "Reading and writing data over a serial connection.",
 | 
			
		||||
 
 | 
			
		||||
@@ -53,6 +53,8 @@
 | 
			
		||||
  "DisplayMode.Greyscale|block": "greyscale",
 | 
			
		||||
  "EventCreationMode.CreateAndFire": "MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).",
 | 
			
		||||
  "EventCreationMode.CreateOnly": "MicroBitEvent is initialised, and no further processing takes place.",
 | 
			
		||||
  "Gesture.EightG": "Raised when a 8G shock is detected",
 | 
			
		||||
  "Gesture.EightG|block": "8g",
 | 
			
		||||
  "Gesture.FreeFall": "Raised when the board is falling!",
 | 
			
		||||
  "Gesture.FreeFall|block": "free fall",
 | 
			
		||||
  "Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical",
 | 
			
		||||
@@ -147,6 +149,22 @@
 | 
			
		||||
  "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",
 | 
			
		||||
  "MotorCommand.Break|block": "break",
 | 
			
		||||
  "MotorCommand.Coast|block": "coast",
 | 
			
		||||
@@ -213,6 +231,7 @@
 | 
			
		||||
  "control.waitMicros|block": "wait (µs)%micros",
 | 
			
		||||
  "control|block": "control",
 | 
			
		||||
  "game.LedSprite.change|block": "%sprite|change %property|by %value",
 | 
			
		||||
  "game.LedSprite.delete|block": "delete %this",
 | 
			
		||||
  "game.LedSprite.get|block": "%sprite|%property",
 | 
			
		||||
  "game.LedSprite.ifOnEdgeBounce|block": "%sprite|if on edge, bounce",
 | 
			
		||||
  "game.LedSprite.isTouchingEdge|block": "%sprite|touching edge?",
 | 
			
		||||
@@ -223,7 +242,10 @@
 | 
			
		||||
  "game.addScore|block": "change score by|%points",
 | 
			
		||||
  "game.createSprite|block": "create sprite at|x: %x|y: %y",
 | 
			
		||||
  "game.gameOver|block": "game over",
 | 
			
		||||
  "game.pause|block": "pause",
 | 
			
		||||
  "game.resume|block": "resume",
 | 
			
		||||
  "game.score|block": "score",
 | 
			
		||||
  "game.setScore|block": "set score %points",
 | 
			
		||||
  "game.startCountdown|block": "start countdown|(ms) %duration",
 | 
			
		||||
  "game|block": "game",
 | 
			
		||||
  "images.arrowImage|block": "arrow image %i=device_arrow",
 | 
			
		||||
@@ -234,21 +256,25 @@
 | 
			
		||||
  "images|block": "images",
 | 
			
		||||
  "input.acceleration|block": "acceleration (mg)|%NAME",
 | 
			
		||||
  "input.buttonIsPressed|block": "button|%NAME|is pressed",
 | 
			
		||||
  "input.calibrateCompass|block": "calibrate compass",
 | 
			
		||||
  "input.compassHeading|block": "compass heading (°)",
 | 
			
		||||
  "input.lightLevel|block": "light level",
 | 
			
		||||
  "input.magneticForce|block": "magnetic force (µT)|%NAME",
 | 
			
		||||
  "input.onButtonPressed|block": "on button|%NAME|pressed",
 | 
			
		||||
  "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.pinIsPressed|block": "pin %NAME|is pressed",
 | 
			
		||||
  "input.rotation|block": "rotation (°)|%NAME",
 | 
			
		||||
  "input.runningTimeMicros|block": "running time (micros)",
 | 
			
		||||
  "input.runningTime|block": "running time (ms)",
 | 
			
		||||
  "input.setAccelerometerRange|block": "set accelerometer|range %range",
 | 
			
		||||
  "input.temperature|block": "temperature (°C)",
 | 
			
		||||
  "input|block": "input",
 | 
			
		||||
  "led.brightness|block": "brightness",
 | 
			
		||||
  "led.enable|block": "led enable %on",
 | 
			
		||||
  "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.point|block": "point|x %x|y %y",
 | 
			
		||||
  "led.setBrightness|block": "set brightness %value",
 | 
			
		||||
@@ -290,6 +316,9 @@
 | 
			
		||||
  "pins.servoWritePin|block": "servo write|pin %name|to %value",
 | 
			
		||||
  "pins.setEvents|block": "set pin %pin|to emit %type|events",
 | 
			
		||||
  "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|block": "pins",
 | 
			
		||||
  "serial.delimiters|block": "%del",
 | 
			
		||||
 
 | 
			
		||||
@@ -35,9 +35,8 @@ namespace basic {
 | 
			
		||||
    //% async
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    void showNumber(int value, int interval = 150) {
 | 
			
		||||
      if (interval < 0)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
      if (interval <= 0)
 | 
			
		||||
        interval = 1;
 | 
			
		||||
      ManagedString t(value);
 | 
			
		||||
      if (value < 0 || value >= 10) {
 | 
			
		||||
        uBit.display.scroll(t, interval);
 | 
			
		||||
@@ -55,7 +54,7 @@ namespace basic {
 | 
			
		||||
    //% weight=95 blockGap=8
 | 
			
		||||
    //% imageLiteral=1 async
 | 
			
		||||
    //% blockId=device_show_leds
 | 
			
		||||
    //% block="show leds"
 | 
			
		||||
    //% block="show leds" icon="\uf00a"
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    void showLeds(ImageLiteral leds, int interval = 400) {
 | 
			
		||||
      uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
 | 
			
		||||
@@ -73,8 +72,8 @@ namespace basic {
 | 
			
		||||
    //% blockId=device_print_message
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    void showString(StringData *text, int interval = 150) {
 | 
			
		||||
      if (interval < 0)
 | 
			
		||||
        return;
 | 
			
		||||
      if (interval <= 0)
 | 
			
		||||
        interval = 1;
 | 
			
		||||
      ManagedString s(text);
 | 
			
		||||
      int l = s.length();
 | 
			
		||||
      if (l == 0) {
 | 
			
		||||
@@ -93,6 +92,7 @@ namespace basic {
 | 
			
		||||
    //% help=basic/clear-screen weight=79
 | 
			
		||||
    //% blockId=device_clear_display block="clear screen"
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    //% advanced=true
 | 
			
		||||
    void clearScreen() {
 | 
			
		||||
      uBit.display.image.clear();
 | 
			
		||||
    }
 | 
			
		||||
@@ -105,7 +105,7 @@ namespace basic {
 | 
			
		||||
    //% help=basic/show-animation imageLiteral=1 async
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    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.
 | 
			
		||||
     * @param body code to execute
 | 
			
		||||
     */
 | 
			
		||||
    //% help=basic/forever weight=55 blockGap=8
 | 
			
		||||
    //% blockId=device_forever block="forever"
 | 
			
		||||
    //% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1 afterOnStart=true
 | 
			
		||||
    //% blockId=device_forever block="forever" icon="\uf01e"
 | 
			
		||||
    void forever(Action a) {
 | 
			
		||||
      if (a != 0) {
 | 
			
		||||
        incr(a);
 | 
			
		||||
@@ -145,7 +145,7 @@ namespace basic {
 | 
			
		||||
     */
 | 
			
		||||
    //% help=basic/pause weight=54
 | 
			
		||||
    //% async block="pause (ms) %pause"
 | 
			
		||||
    //% blockId=device_pause
 | 
			
		||||
    //% blockId=device_pause icon="\uf110"
 | 
			
		||||
    void pause(int ms) {
 | 
			
		||||
      fiber_sleep(ms);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,97 +20,190 @@ enum class EventCreationMode {
 | 
			
		||||
// TODO shouldn't these be renamed to something more sensible anyways?
 | 
			
		||||
 | 
			
		||||
enum EventBusSource {
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_BUTTON_A_ = MICROBIT_ID_BUTTON_A,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_BUTTON_B_ = MICROBIT_ID_BUTTON_B,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_BUTTON_AB_ = MICROBIT_ID_BUTTON_AB,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_RADIO_ = MICROBIT_ID_RADIO,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_GESTURE_ = MICROBIT_ID_GESTURE,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_ACCELEROMETER_ = MICROBIT_ID_ACCELEROMETER,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P0_ = MICROBIT_ID_IO_P0,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P1_ = MICROBIT_ID_IO_P1,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P2_ = MICROBIT_ID_IO_P2,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P3_ = MICROBIT_ID_IO_P3,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P4_ = MICROBIT_ID_IO_P4,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P5_ = MICROBIT_ID_IO_P5,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P6_ = MICROBIT_ID_IO_P6,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P7_ = MICROBIT_ID_IO_P7,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P8_ = MICROBIT_ID_IO_P8,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P9_ = MICROBIT_ID_IO_P9,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P10_ = MICROBIT_ID_IO_P10,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P11_ = MICROBIT_ID_IO_P11,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P12_ = MICROBIT_ID_IO_P12,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P13_ = MICROBIT_ID_IO_P13,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P14_ = MICROBIT_ID_IO_P14,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P15_ = MICROBIT_ID_IO_P15,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P16_ = MICROBIT_ID_IO_P16,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P19_ = MICROBIT_ID_IO_P19,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P20_ = MICROBIT_ID_IO_P20,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P21_ = MICROBIT_ID_IO_P21,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_DEVICE_INFO_ID_ = MES_DEVICE_INFO_ID,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_SIGNAL_STRENGTH_ID_ = MES_SIGNAL_STRENGTH_ID,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_DPAD_CONTROLLER_ID_ = MES_DPAD_CONTROLLER_ID,
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_BROADCAST_GENERAL_ID_ = MES_BROADCAST_GENERAL_ID,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum EventBusValue {
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_RADIO_EVT_DATAGRAM_ = MICROBIT_RADIO_EVT_DATAGRAM,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE_ = MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_PIN_EVT_RISE_ = MICROBIT_PIN_EVT_RISE,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_PIN_EVT_FALL_ = MICROBIT_PIN_EVT_FALL,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_PIN_EVT_PULSE_HI_ = MICROBIT_PIN_EVT_PULSE_HI,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_PIN_EVT_PULSE_LO_ = MICROBIT_PIN_EVT_PULSE_LO,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM1_ = MES_ALERT_EVT_ALARM1,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM2_ = MES_ALERT_EVT_ALARM2,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM3_ = MES_ALERT_EVT_ALARM3,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM4_ = MES_ALERT_EVT_ALARM4,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM5_ = MES_ALERT_EVT_ALARM5,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM6_ = MES_ALERT_EVT_ALARM6,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_PLAY_RINGTONE_ = MES_ALERT_EVT_PLAY_RINGTONE,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_PLAY_SOUND_ = MES_ALERT_EVT_PLAY_SOUND,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_VIBRATE_ = MES_ALERT_EVT_VIBRATE,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_DISPLAY_OFF_ = MES_DEVICE_DISPLAY_OFF,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_DISPLAY_ON_ = MES_DEVICE_DISPLAY_ON,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_GESTURE_DEVICE_SHAKEN_ = MES_DEVICE_GESTURE_DEVICE_SHAKEN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_INCOMING_CALL_ = MES_DEVICE_INCOMING_CALL,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_INCOMING_MESSAGE_ = MES_DEVICE_INCOMING_MESSAGE,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_ORIENTATION_LANDSCAPE_ = MES_DEVICE_ORIENTATION_LANDSCAPE,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_ORIENTATION_PORTRAIT_ = MES_DEVICE_ORIENTATION_PORTRAIT,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_1_DOWN_ = MES_DPAD_BUTTON_1_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_1_UP_ = MES_DPAD_BUTTON_1_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_2_DOWN_ = MES_DPAD_BUTTON_2_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_2_UP_ = MES_DPAD_BUTTON_2_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_3_DOWN_ = MES_DPAD_BUTTON_3_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_3_UP_ = MES_DPAD_BUTTON_3_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_4_DOWN_ = MES_DPAD_BUTTON_4_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_4_UP_ = MES_DPAD_BUTTON_4_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_A_DOWN_ = MES_DPAD_BUTTON_A_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_A_UP_ = MES_DPAD_BUTTON_A_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_B_DOWN_ = MES_DPAD_BUTTON_B_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_B_UP_ = MES_DPAD_BUTTON_B_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_C_DOWN_ = MES_DPAD_BUTTON_C_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_C_UP_ = MES_DPAD_BUTTON_C_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_D_DOWN_ = MES_DPAD_BUTTON_D_DOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DPAD_BUTTON_D_UP_ = MES_DPAD_BUTTON_D_UP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_FORWARD_ = MES_REMOTE_CONTROL_EVT_FORWARD,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_NEXTTRACK_ = MES_REMOTE_CONTROL_EVT_NEXTTRACK,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_PAUSE_ = MES_REMOTE_CONTROL_EVT_PAUSE,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_PLAY_ = MES_REMOTE_CONTROL_EVT_PLAY,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_PREVTRACK_ = MES_REMOTE_CONTROL_EVT_PREVTRACK,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_REWIND_ = MES_REMOTE_CONTROL_EVT_REWIND,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_STOP_ = MES_REMOTE_CONTROL_EVT_STOP,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_VOLUMEDOWN_ = MES_REMOTE_CONTROL_EVT_VOLUMEDOWN,
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_VOLUMEUP_ = MES_REMOTE_CONTROL_EVT_VOLUMEUP,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -126,7 +219,7 @@ namespace control {
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    void inBackground(Action 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).
 | 
			
		||||
     */
 | 
			
		||||
    //% 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
 | 
			
		||||
    void raiseEvent(int src, int value, EventCreationMode mode) {
 | 
			
		||||
        MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode);
 | 
			
		||||
@@ -167,6 +261,7 @@ namespace control {
 | 
			
		||||
     * 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"
 | 
			
		||||
    //% help=control/on-event
 | 
			
		||||
    //% blockExternalInputs=1
 | 
			
		||||
    void onEvent(int src, int value, Action handler) {
 | 
			
		||||
        registerWithDal(src, value, handler);
 | 
			
		||||
@@ -176,6 +271,7 @@ namespace control {
 | 
			
		||||
    * Gets the value of the last event executed on the bus
 | 
			
		||||
    */
 | 
			
		||||
    //% blockId=control_event_value" block="event value"
 | 
			
		||||
    //% help=control/event-value
 | 
			
		||||
    //% weight=18
 | 
			
		||||
    int eventValue() {
 | 
			
		||||
        return pxt::lastEvent.value;
 | 
			
		||||
@@ -185,6 +281,7 @@ namespace control {
 | 
			
		||||
    * Gets the timestamp of the last event executed on the bus
 | 
			
		||||
    */
 | 
			
		||||
    //% blockId=control_event_timestamp" block="event timestamp"
 | 
			
		||||
    //% help=control/event-timestamp
 | 
			
		||||
    //% weight=19 blockGap=8
 | 
			
		||||
    int eventTimestamp() {
 | 
			
		||||
        return pxt::lastEvent.timestamp;
 | 
			
		||||
@@ -194,6 +291,7 @@ namespace control {
 | 
			
		||||
     * Gets a friendly name for the device derived from the its serial number
 | 
			
		||||
     */
 | 
			
		||||
    //% blockId="control_device_name" block="device name" weight=10 blockGap=8
 | 
			
		||||
    //% advanced=true
 | 
			
		||||
    StringData* deviceName() {
 | 
			
		||||
        return ManagedString(microbit_friendly_name()).leakData();
 | 
			
		||||
    }
 | 
			
		||||
@@ -202,6 +300,7 @@ namespace control {
 | 
			
		||||
    * Derive a unique, consistent serial number of this device from internal data.
 | 
			
		||||
    */
 | 
			
		||||
    //% blockId="control_device_serial_number" block="device serial number" weight=9
 | 
			
		||||
    //% advanced=true
 | 
			
		||||
    int deviceSerialNumber() {
 | 
			
		||||
        return microbit_serial_number();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ namespace control {
 | 
			
		||||
         * Returns the value of a C++ runtime constant
 | 
			
		||||
         */
 | 
			
		||||
        //% 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 {
 | 
			
		||||
            return id;
 | 
			
		||||
        }
 | 
			
		||||
@@ -17,7 +17,7 @@ namespace control {
 | 
			
		||||
         * Returns the value of a C++ runtime constant
 | 
			
		||||
         */
 | 
			
		||||
        //% weight=1 weight=19 blockId="control_event_value_id" block="%id"
 | 
			
		||||
    //% shim=TD_ID
 | 
			
		||||
        //% shim=TD_ID advanced=true
 | 
			
		||||
        export function eventValueId(id: EventBusValue): number {
 | 
			
		||||
            return id;
 | 
			
		||||
        }
 | 
			
		||||
@@ -47,3 +47,4 @@ namespace control {
 | 
			
		||||
        //% shim=pxtrt::runtimeWarning
 | 
			
		||||
        export function runtimeWarning(message: string) { }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
@@ -29,6 +29,15 @@ namespace String_ {
 | 
			
		||||
      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; }
 | 
			
		||||
 | 
			
		||||
@@ -112,6 +121,15 @@ namespace Number_ {
 | 
			
		||||
    int div(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_ {
 | 
			
		||||
@@ -220,17 +238,12 @@ namespace pxt {
 | 
			
		||||
    return bytecode[17] * 2;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
#ifndef PAGE_SIZE
 | 
			
		||||
 | 
			
		||||
#define PAGE_SIZE 1
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  //%
 | 
			
		||||
  uint32_t afterProgramPage() {
 | 
			
		||||
    uint32_t ptr = (uint32_t)&bytecode[0];
 | 
			
		||||
    ptr += programSize();
 | 
			
		||||
    ptr = (ptr + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
 | 
			
		||||
    if (ptr % PAGE_SIZE != 0)
 | 
			
		||||
      ptr = (ptr & ~(PAGE_SIZE-1)) + PAGE_SIZE;
 | 
			
		||||
    return ptr;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										134
									
								
								libs/core/enums.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										134
									
								
								libs/core/enums.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -116,6 +116,47 @@ declare namespace basic {
 | 
			
		||||
     */
 | 
			
		||||
    //% block="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 {
 | 
			
		||||
}
 | 
			
		||||
@@ -138,98 +179,191 @@ declare namespace input {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    declare const enum EventBusSource {
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_BUTTON_A = 1,  // MICROBIT_ID_BUTTON_A
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_BUTTON_B = 2,  // MICROBIT_ID_BUTTON_B
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_BUTTON_AB = 26,  // MICROBIT_ID_BUTTON_AB
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_RADIO = 29,  // MICROBIT_ID_RADIO
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_GESTURE = 27,  // MICROBIT_ID_GESTURE
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_ACCELEROMETER = 4,  // MICROBIT_ID_ACCELEROMETER
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P0 = 7,  // MICROBIT_ID_IO_P0
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P1 = 8,  // MICROBIT_ID_IO_P1
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P2 = 9,  // MICROBIT_ID_IO_P2
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P3 = 10,  // MICROBIT_ID_IO_P3
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P4 = 11,  // MICROBIT_ID_IO_P4
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P5 = 12,  // MICROBIT_ID_IO_P5
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P6 = 13,  // MICROBIT_ID_IO_P6
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P7 = 14,  // MICROBIT_ID_IO_P7
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P8 = 15,  // MICROBIT_ID_IO_P8
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P9 = 16,  // MICROBIT_ID_IO_P9
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P10 = 17,  // MICROBIT_ID_IO_P10
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P11 = 18,  // MICROBIT_ID_IO_P11
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P12 = 19,  // MICROBIT_ID_IO_P12
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P13 = 20,  // MICROBIT_ID_IO_P13
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P14 = 21,  // MICROBIT_ID_IO_P14
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P15 = 22,  // MICROBIT_ID_IO_P15
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P16 = 23,  // MICROBIT_ID_IO_P16
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P19 = 24,  // MICROBIT_ID_IO_P19
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P20 = 25,  // MICROBIT_ID_IO_P20
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MICROBIT_ID_IO_P21 = 50,  // MICROBIT_ID_IO_P21
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_DEVICE_INFO_ID = 1103,  // MES_DEVICE_INFO_ID
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_SIGNAL_STRENGTH_ID = 1101,  // MES_SIGNAL_STRENGTH_ID
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_DPAD_CONTROLLER_ID = 1104,  // MES_DPAD_CONTROLLER_ID
 | 
			
		||||
    //% blockIdentity="control.eventSourceId"
 | 
			
		||||
    MES_BROADCAST_GENERAL_ID = 2000,  // MES_BROADCAST_GENERAL_ID
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    declare const enum EventBusValue {
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_RADIO_EVT_DATAGRAM = 1,  // MICROBIT_RADIO_EVT_DATAGRAM
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1,  // MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_PIN_EVT_RISE = 2,  // MICROBIT_PIN_EVT_RISE
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MICROBIT_PIN_EVT_FALL = 3,  // MICROBIT_PIN_EVT_FALL
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM1 = 6,  // MES_ALERT_EVT_ALARM1
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM2 = 7,  // MES_ALERT_EVT_ALARM2
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM3 = 8,  // MES_ALERT_EVT_ALARM3
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM4 = 9,  // MES_ALERT_EVT_ALARM4
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM5 = 10,  // MES_ALERT_EVT_ALARM5
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_ALERT_EVT_ALARM6 = 11,  // MES_ALERT_EVT_ALARM6
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_DISPLAY_ON = 6,  // MES_DEVICE_DISPLAY_ON
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_GESTURE_DEVICE_SHAKEN = 4,  // MES_DEVICE_GESTURE_DEVICE_SHAKEN
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_INCOMING_CALL = 7,  // MES_DEVICE_INCOMING_CALL
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_INCOMING_MESSAGE = 8,  // MES_DEVICE_INCOMING_MESSAGE
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_ORIENTATION_LANDSCAPE = 1,  // MES_DEVICE_ORIENTATION_LANDSCAPE
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_DEVICE_ORIENTATION_PORTRAIT = 2,  // MES_DEVICE_ORIENTATION_PORTRAIT
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    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
 | 
			
		||||
    //% blockIdentity="control.eventValueId"
 | 
			
		||||
    MES_REMOTE_CONTROL_EVT_VOLUMEUP = 8,  // MES_REMOTE_CONTROL_EVT_VOLUMEUP
 | 
			
		||||
    }
 | 
			
		||||
declare namespace control {
 | 
			
		||||
 
 | 
			
		||||
@@ -64,12 +64,12 @@ namespace ImageMethods {
 | 
			
		||||
     * @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
 | 
			
		||||
     */
 | 
			
		||||
    //% 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
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    void scrollImage(Image id, int frameOffset, int interval) {
 | 
			
		||||
      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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -105,15 +105,55 @@ enum class Gesture {
 | 
			
		||||
    * Raised when a 6G shock is detected
 | 
			
		||||
    */
 | 
			
		||||
    //% block="6g"
 | 
			
		||||
    SixG = MICROBIT_ACCELEROMETER_EVT_6G
 | 
			
		||||
    SixG = MICROBIT_ACCELEROMETER_EVT_6G,
 | 
			
		||||
    /**
 | 
			
		||||
    * Raised when a 8G shock is detected
 | 
			
		||||
    */
 | 
			
		||||
    //% block="8g"
 | 
			
		||||
    EightG = MICROBIT_ACCELEROMETER_EVT_8G
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//% color=#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 {
 | 
			
		||||
    /**
 | 
			
		||||
     * Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
 | 
			
		||||
     * @param button TODO
 | 
			
		||||
     * @param body TODO
 | 
			
		||||
     * Do something when a button (A, B or both A+B) is pushed down and released again.
 | 
			
		||||
     * @param button the button that needs to be pressed
 | 
			
		||||
     * @param body code to run when event is raised
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/on-button-pressed weight=85 blockGap=8
 | 
			
		||||
    //% blockId=device_button_event block="on button|%NAME|pressed"
 | 
			
		||||
@@ -124,26 +164,29 @@ namespace input {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    //% blockId=device_gesture_event block="on |%NAME"
 | 
			
		||||
    //% parts="accelerometer"
 | 
			
		||||
    //% NAME.fieldEditor="gridpicker" NAME.fieldOptions.columns=4
 | 
			
		||||
    void onGesture(Gesture gesture, Action body) {
 | 
			
		||||
        if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
 | 
			
		||||
            uBit.accelerometer.setRange(6);
 | 
			
		||||
        else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6)
 | 
			
		||||
        int gi = (int)gesture;
 | 
			
		||||
        if (gi == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
 | 
			
		||||
            uBit.accelerometer.setRange(4);
 | 
			
		||||
        else if ((gi == MICROBIT_ACCELEROMETER_EVT_6G || gi == MICROBIT_ACCELEROMETER_EVT_8G) && uBit.accelerometer.getRange() < 6)
 | 
			
		||||
            uBit.accelerometer.setRange(8);
 | 
			
		||||
        registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
 | 
			
		||||
        registerWithDal(MICROBIT_ID_GESTURE, gi, body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
     /**
 | 
			
		||||
     * Do something when a pin is pressed.
 | 
			
		||||
     * @param name the pin that needs to be 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, eg: TouchPin.P0
 | 
			
		||||
     * @param body the code to run when the pin is pressed
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/on-pin-pressed weight=83
 | 
			
		||||
    //% blockId=device_pin_event block="on pin %NAME|pressed"
 | 
			
		||||
    //% blockId=device_pin_event block="on pin %name|pressed"
 | 
			
		||||
    void onPinPressed(TouchPin name, Action body) {
 | 
			
		||||
        auto pin = getPin((int)name);
 | 
			
		||||
        if (!pin) return;
 | 
			
		||||
@@ -155,7 +198,7 @@ namespace input {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    //% 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``.
 | 
			
		||||
     * @param button the button to query the request, eg: Button.A
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/button-is-pressed weight=60
 | 
			
		||||
    //% 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.
 | 
			
		||||
     * @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
 | 
			
		||||
    //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
 | 
			
		||||
@@ -296,18 +340,31 @@ namespace input {
 | 
			
		||||
    /**
 | 
			
		||||
     * 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)"
 | 
			
		||||
    //% advanced=true
 | 
			
		||||
    int runningTime() {
 | 
			
		||||
        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.
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/calibrate weight=0
 | 
			
		||||
    void calibrate() { }
 | 
			
		||||
    //% help=input/calibrate-compass advanced=true
 | 
			
		||||
    //% blockId="input_compass_calibrate" block="calibrate compass"
 | 
			
		||||
    void calibrateCompass() { 
 | 
			
		||||
        uBit.compass.calibrate();        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the accelerometer sample range in gravities.
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
     * @param x TODO
 | 
			
		||||
     * @param y TODO
 | 
			
		||||
     * @param x the horizontal coordinate of the LED starting at 0
 | 
			
		||||
     * @param y the vertical coordinate of the LED starting at 0
 | 
			
		||||
     */
 | 
			
		||||
    //% help=led/plot weight=78
 | 
			
		||||
    //% blockId=device_plot block="plot|x %x|y %y" blockGap=8
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    //% x.min=0 x.max=4 y.min=0 y.max=4
 | 
			
		||||
    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
 | 
			
		||||
    //% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    //% x.min=0 x.max=4 y.min=0 y.max=4
 | 
			
		||||
    void unplot(int x, int y) {
 | 
			
		||||
      uBit.display.image.setPixelValue(x, y, 0);
 | 
			
		||||
    }
 | 
			
		||||
@@ -43,6 +64,7 @@ namespace led {
 | 
			
		||||
    //% help=led/point weight=76
 | 
			
		||||
    //% blockId=device_point block="point|x %x|y %y"
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    //% x.min=0 x.max=4 y.min=0 y.max=4
 | 
			
		||||
    bool point(int x, int y) {
 | 
			
		||||
      int pix = uBit.display.image.getPixelValue(x, y);
 | 
			
		||||
      return pix > 0;
 | 
			
		||||
@@ -67,6 +89,7 @@ namespace led {
 | 
			
		||||
    //% blockId=device_set_brightness block="set brightness %value"
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    //% advanced=true
 | 
			
		||||
    //% value.min=0 value.max=255
 | 
			
		||||
    void setBrightness(int value) {
 | 
			
		||||
       uBit.display.setBrightness(value);
 | 
			
		||||
    }
 | 
			
		||||
@@ -103,7 +126,7 @@ namespace led {
 | 
			
		||||
    /**
 | 
			
		||||
    * 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"
 | 
			
		||||
    void enable(bool on) {
 | 
			
		||||
        if (on) uBit.display.enable();
 | 
			
		||||
 
 | 
			
		||||
@@ -102,42 +102,52 @@ namespace pins {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        PINREAD(getDigitalValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
      * 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
 | 
			
		||||
      */
 | 
			
		||||
    //% help=pins/digital-write-pin weight=29
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        PINOP(setDigitalValue(value));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        PINREAD(getAnalogValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    //% help=pins/analog-write-pin weight=24
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        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.
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    //% help=pins/analog-set-period weight=23 blockGap=8
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        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``.
 | 
			
		||||
    * @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"
 | 
			
		||||
    //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
 | 
			
		||||
    //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
 | 
			
		||||
    void onPulsed(DigitalPin name, PulseValue pulse, Action body) {
 | 
			
		||||
        MicroBitPin* pin = getPin((int)name);
 | 
			
		||||
        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.
 | 
			
		||||
    */
 | 
			
		||||
    //% help=pins/pulse-duration
 | 
			
		||||
    //% help=pins/pulse-duration advanced=true
 | 
			
		||||
    //% blockId=pins_pulse_duration block="pulse duration (µs)"
 | 
			
		||||
    //% weight=21 blockGap=8
 | 
			
		||||
    int pulseDuration() {
 | 
			
		||||
@@ -179,12 +195,15 @@ namespace pins {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Returns the duration of a pulse in microseconds
 | 
			
		||||
    * @param name the pin which measures the pulse
 | 
			
		||||
    * @param value the value of the pulse (default high)
 | 
			
		||||
    * @param name the pin which measures the pulse, eg: DigitalPin.P0
 | 
			
		||||
    * @param value the value of the pulse, eg: PulseValue.High
 | 
			
		||||
    * @param maximum duration in micro-seconds
 | 
			
		||||
    */
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        MicroBitPin* pin = getPin((int)name);
 | 
			
		||||
        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).
 | 
			
		||||
     * @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
 | 
			
		||||
     */
 | 
			
		||||
    //% help=pins/servo-write-pin weight=20
 | 
			
		||||
    //% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        fixMotorIssue(name);
 | 
			
		||||
        PINOP(setServoValue(value));
 | 
			
		||||
@@ -237,6 +259,8 @@ namespace pins {
 | 
			
		||||
     */
 | 
			
		||||
    //% help=pins/servo-set-pulse weight=19
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        fixMotorIssue(name);
 | 
			
		||||
        PINOP(setServoPulseUs(micros));
 | 
			
		||||
@@ -246,19 +270,21 @@ namespace pins {
 | 
			
		||||
    MicroBitPin* pitchPin = NULL;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the pin used when using `pins->analog pitch`.
 | 
			
		||||
     * @param name TODO
 | 
			
		||||
     * Sets the pin used when using `analog pitch` or music.
 | 
			
		||||
     * @param name pin to modulate pitch from
 | 
			
		||||
     */
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        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.
 | 
			
		||||
     * @param frequency TODO
 | 
			
		||||
     * @param ms TODO
 | 
			
		||||
    * @param frequency frequency to modulate in Hz.
 | 
			
		||||
    * @param ms duration of the pitch in milli seconds.
 | 
			
		||||
    */
 | 
			
		||||
    //% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms"
 | 
			
		||||
    //% help=pins/analog-pitch weight=4 async advanced=true blockGap=8
 | 
			
		||||
@@ -283,11 +309,13 @@ namespace pins {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Configures the pull of this pin.
 | 
			
		||||
    * @param name pin to set the pull mode on
 | 
			
		||||
    * @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone 
 | 
			
		||||
    * @param name pin to set the pull mode on, eg: DigitalPin.P0
 | 
			
		||||
    * @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"
 | 
			
		||||
    //% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
 | 
			
		||||
    //% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
 | 
			
		||||
    void setPull(DigitalPin name, PinPullMode pull) {
 | 
			
		||||
        PinMode m = pull == PinPullMode::PullDown
 | 
			
		||||
            ? PinMode::PullDown
 | 
			
		||||
@@ -304,6 +332,8 @@ namespace pins {
 | 
			
		||||
    */
 | 
			
		||||
    //% help=pins/set-events weight=4 advanced=true
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        getPin((int)name)->eventOn((int)type);
 | 
			
		||||
    }
 | 
			
		||||
@@ -340,7 +370,7 @@ namespace pins {
 | 
			
		||||
    
 | 
			
		||||
    SPI* spi = NULL;
 | 
			
		||||
    SPI* allocSPI() {
 | 
			
		||||
        if (spi == NULL)
 | 
			
		||||
        if (NULL == spi)
 | 
			
		||||
            spi = new SPI(MOSI, MISO, SCK);
 | 
			
		||||
        return spi;
 | 
			
		||||
    }
 | 
			
		||||
@@ -349,11 +379,54 @@ namespace pins {
 | 
			
		||||
    * Write to the SPI slave and return the response
 | 
			
		||||
    * @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"
 | 
			
		||||
    int spiWrite(int value) {
 | 
			
		||||
        auto p = allocSPI();
 | 
			
		||||
        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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -269,9 +269,9 @@ namespace pxt {
 | 
			
		||||
 | 
			
		||||
      if (length > 0)
 | 
			
		||||
      {
 | 
			
		||||
        --length;
 | 
			
		||||
        uint32_t value = data[length];
 | 
			
		||||
        data[length] = Segment::DefaultValue;
 | 
			
		||||
        --length;
 | 
			
		||||
        return value;
 | 
			
		||||
      }
 | 
			
		||||
      return Segment::DefaultValue;
 | 
			
		||||
@@ -394,10 +394,7 @@ namespace pxt {
 | 
			
		||||
 | 
			
		||||
    uint32_t RefCollection::removeAt(int i)
 | 
			
		||||
    {
 | 
			
		||||
      if (isRef())
 | 
			
		||||
      {
 | 
			
		||||
        decr(head.get(i));
 | 
			
		||||
      } 
 | 
			
		||||
      // no decr() - we return the result
 | 
			
		||||
      return head.remove(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -464,7 +461,8 @@ namespace pxt {
 | 
			
		||||
    {
 | 
			
		||||
      int idx = indexOf(x, 0);
 | 
			
		||||
      if (idx >= 0) {
 | 
			
		||||
        removeAt(idx);
 | 
			
		||||
        uint32_t elt = removeAt(idx);
 | 
			
		||||
        if (isRef()) decr(elt);
 | 
			
		||||
        return 1;
 | 
			
		||||
      }
 | 
			
		||||
      return 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -160,6 +160,7 @@ namespace pxt {
 | 
			
		||||
    inline void unref()
 | 
			
		||||
    {
 | 
			
		||||
      //printf("DECR "); this->print();
 | 
			
		||||
      check(refcnt > 0, ERR_REF_DELETED);
 | 
			
		||||
      refcnt -= 2;
 | 
			
		||||
      if (refcnt == 0) {
 | 
			
		||||
        destroy();
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,18 @@
 | 
			
		||||
        "optionalConfig": {
 | 
			
		||||
            "microbit-dal": {
 | 
			
		||||
                "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"
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										223
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										223
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -56,7 +56,7 @@ declare interface Image {
 | 
			
		||||
     * @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
 | 
			
		||||
     */
 | 
			
		||||
    //% 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
 | 
			
		||||
    //% parts="ledmatrix" shim=ImageMethods::scrollImage
 | 
			
		||||
    scrollImage(frameOffset: number, interval: number): void;
 | 
			
		||||
@@ -156,7 +156,7 @@ declare namespace basic {
 | 
			
		||||
    //% weight=95 blockGap=8
 | 
			
		||||
    //% imageLiteral=1 async
 | 
			
		||||
    //% blockId=device_show_leds
 | 
			
		||||
    //% block="show leds"
 | 
			
		||||
    //% block="show leds" icon="\uf00a"
 | 
			
		||||
    //% parts="ledmatrix" interval.defl=400 shim=basic::showLeds
 | 
			
		||||
    function showLeds(leds: string, interval?: number): void;
 | 
			
		||||
 | 
			
		||||
@@ -178,7 +178,8 @@ declare namespace basic {
 | 
			
		||||
     */
 | 
			
		||||
    //% help=basic/clear-screen weight=79
 | 
			
		||||
    //% blockId=device_clear_display block="clear screen"
 | 
			
		||||
    //% parts="ledmatrix" shim=basic::clearScreen
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    //% advanced=true shim=basic::clearScreen
 | 
			
		||||
    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.
 | 
			
		||||
     * @param body code to execute
 | 
			
		||||
     */
 | 
			
		||||
    //% help=basic/forever weight=55 blockGap=8
 | 
			
		||||
    //% blockId=device_forever block="forever" shim=basic::forever
 | 
			
		||||
    //% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1 afterOnStart=true
 | 
			
		||||
    //% blockId=device_forever block="forever" icon="\uf01e" shim=basic::forever
 | 
			
		||||
    function forever(a: () => void): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -212,19 +213,19 @@ declare namespace basic {
 | 
			
		||||
     */
 | 
			
		||||
    //% help=basic/pause weight=54
 | 
			
		||||
    //% async block="pause (ms) %pause"
 | 
			
		||||
    //% blockId=device_pause shim=basic::pause
 | 
			
		||||
    //% blockId=device_pause icon="\uf110" shim=basic::pause
 | 
			
		||||
    function pause(ms: number): void;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //% color=#C90072 weight=99 icon="\uf192"
 | 
			
		||||
    //% color=#B4009E weight=99 icon="\uf192"
 | 
			
		||||
declare namespace input {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
 | 
			
		||||
     * @param button TODO
 | 
			
		||||
     * @param body TODO
 | 
			
		||||
     * Do something when a button (A, B or both A+B) is pushed down and released again.
 | 
			
		||||
     * @param button the button that needs to be pressed
 | 
			
		||||
     * @param body code to run when event is raised
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/on-button-pressed weight=85 blockGap=8
 | 
			
		||||
    //% blockId=device_button_event block="on button|%NAME|pressed"
 | 
			
		||||
@@ -233,25 +234,27 @@ declare namespace input {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Do something when a pin is pressed.
 | 
			
		||||
     * @param name the pin that needs to be 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, eg: TouchPin.P0
 | 
			
		||||
     * @param body the code to run when the pin is pressed
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/on-pin-pressed weight=83
 | 
			
		||||
    //% blockId=device_pin_event block="on pin %NAME|pressed" shim=input::onPinPressed
 | 
			
		||||
    //% blockId=device_pin_event block="on pin %name|pressed" shim=input::onPinPressed
 | 
			
		||||
    function onPinPressed(name: TouchPin, body: () => void): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    //% 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``.
 | 
			
		||||
     * @param button the button to query the request, eg: Button.A
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/button-is-pressed weight=60
 | 
			
		||||
    //% 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.
 | 
			
		||||
     * @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
 | 
			
		||||
    //% 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.
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/running-time weight=50
 | 
			
		||||
    //% help=input/running-time weight=50 blockGap=8
 | 
			
		||||
    //% blockId=device_get_running_time block="running time (ms)"
 | 
			
		||||
    //% advanced=true shim=input::runningTime
 | 
			
		||||
    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.
 | 
			
		||||
     */
 | 
			
		||||
    //% help=input/calibrate weight=0 shim=input::calibrate
 | 
			
		||||
    function calibrate(): void;
 | 
			
		||||
    //% help=input/calibrate-compass advanced=true
 | 
			
		||||
    //% blockId="input_compass_calibrate" block="calibrate compass" shim=input::calibrateCompass
 | 
			
		||||
    function calibrateCompass(): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the accelerometer sample range in gravities.
 | 
			
		||||
@@ -367,7 +380,7 @@ declare namespace control {
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    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).
 | 
			
		||||
     */
 | 
			
		||||
    //% 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
 | 
			
		||||
    function raiseEvent(src: number, value: number, mode?: EventCreationMode): void;
 | 
			
		||||
 | 
			
		||||
@@ -400,6 +414,7 @@ declare namespace control {
 | 
			
		||||
     * 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"
 | 
			
		||||
    //% help=control/on-event
 | 
			
		||||
    //% blockExternalInputs=1 shim=control::onEvent
 | 
			
		||||
    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
 | 
			
		||||
     */
 | 
			
		||||
    //% blockId=control_event_value" block="event value"
 | 
			
		||||
    //% help=control/event-value
 | 
			
		||||
    //% weight=18 shim=control::eventValue
 | 
			
		||||
    function eventValue(): number;
 | 
			
		||||
 | 
			
		||||
@@ -414,19 +430,22 @@ declare namespace control {
 | 
			
		||||
     * Gets the timestamp of the last event executed on the bus
 | 
			
		||||
     */
 | 
			
		||||
    //% blockId=control_event_timestamp" block="event timestamp"
 | 
			
		||||
    //% help=control/event-timestamp
 | 
			
		||||
    //% weight=19 blockGap=8 shim=control::eventTimestamp
 | 
			
		||||
    function eventTimestamp(): 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -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.
 | 
			
		||||
     * @param x TODO
 | 
			
		||||
     * @param y TODO
 | 
			
		||||
     * @param x the horizontal coordinate of the LED starting at 0
 | 
			
		||||
     * @param y the vertical coordinate of the LED starting at 0
 | 
			
		||||
     */
 | 
			
		||||
    //% help=led/plot weight=78
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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.
 | 
			
		||||
     * @param x TODO
 | 
			
		||||
@@ -452,7 +485,8 @@ declare namespace led {
 | 
			
		||||
     */
 | 
			
		||||
    //% help=led/unplot weight=77
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -462,7 +496,8 @@ declare namespace led {
 | 
			
		||||
     */
 | 
			
		||||
    //% help=led/point weight=76
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -481,7 +516,8 @@ declare namespace led {
 | 
			
		||||
    //% help=led/set-brightness weight=59
 | 
			
		||||
    //% blockId=device_set_brightness block="set brightness %value"
 | 
			
		||||
    //% parts="ledmatrix"
 | 
			
		||||
    //% advanced=true shim=led::setBrightness
 | 
			
		||||
    //% advanced=true
 | 
			
		||||
    //% value.min=0 value.max=255 shim=led::setBrightness
 | 
			
		||||
    function setBrightness(value: number): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -501,10 +537,16 @@ declare namespace led {
 | 
			
		||||
    //% parts="ledmatrix" advanced=true shim=led::setDisplayMode
 | 
			
		||||
    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    
 | 
			
		||||
     */
 | 
			
		||||
    //% 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
 | 
			
		||||
    function enable(on: boolean): void;
 | 
			
		||||
 | 
			
		||||
@@ -560,81 +602,103 @@ declare namespace pins {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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.
 | 
			
		||||
     * @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
 | 
			
		||||
     */
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
    //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" shim=pins::onPulsed
 | 
			
		||||
    //% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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)"
 | 
			
		||||
    //% weight=21 blockGap=8 shim=pins::pulseDuration
 | 
			
		||||
    function pulseDuration(): number;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the duration of a pulse in microseconds
 | 
			
		||||
     * @param name the pin which measures the pulse
 | 
			
		||||
     * @param value the value of the pulse (default high)
 | 
			
		||||
     * @param name the pin which measures the pulse, eg: DigitalPin.P0
 | 
			
		||||
     * @param value the value of the pulse, eg: PulseValue.High
 | 
			
		||||
     * @param maximum duration in micro-seconds
 | 
			
		||||
     */
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    //% help=pins/servo-write-pin weight=20
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -643,21 +707,25 @@ declare namespace pins {
 | 
			
		||||
     * @param micros pulse duration in micro seconds, eg:1500
 | 
			
		||||
     */
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the pin used when using `pins->analog pitch`.
 | 
			
		||||
     * @param name TODO
 | 
			
		||||
     * Sets the pin used when using `analog pitch` or music.
 | 
			
		||||
     * @param name pin to modulate pitch from
 | 
			
		||||
     */
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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 ms TODO
 | 
			
		||||
     * @param frequency frequency to modulate in Hz.
 | 
			
		||||
     * @param ms duration of the pitch in milli seconds.
 | 
			
		||||
     */
 | 
			
		||||
    //% 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
 | 
			
		||||
@@ -665,11 +733,13 @@ declare namespace pins {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Configures the pull of this pin.
 | 
			
		||||
     * @param name pin to set the pull mode on
 | 
			
		||||
     * @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone 
 | 
			
		||||
     * @param name pin to set the pull mode on, eg: DigitalPin.P0
 | 
			
		||||
     * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp
 | 
			
		||||
     */
 | 
			
		||||
    //% help=pins/set-pull weight=3
 | 
			
		||||
    //% blockId=device_set_pull block="set pull|pin %pin|to %pull" shim=pins::setPull
 | 
			
		||||
    //% help=pins/set-pull weight=3 advanced=true
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -679,7 +749,9 @@ declare namespace pins {
 | 
			
		||||
     * @param type the type of events for this pin to emit, eg: PinEventType.Edge
 | 
			
		||||
     */
 | 
			
		||||
    //% 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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -705,9 +777,40 @@ declare namespace pins {
 | 
			
		||||
     * Write to the SPI slave and return the response
 | 
			
		||||
     * @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
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user