Bump V3.0.22 (#110)

* change simulator svg

* change radio image

* Remove google fonts cdn

* change color of 'advanced' button

* font fix

* font fix 2

* display fix

* change fullsceen simulator bg

* Continuous servo

* handle continuous state

* adding shims

* update rendering for continuous servos

* fixing sim

* fix sig

* typo

* fix sim

* bump pxt

* bump pxt

* rerun travis

* Input blocks revision

- add Button and Pin event types
- merge onPinPressed & onPinReleased in new onPinEvent function
- create new onButtonEvent function

* update input blocks in docs and tests

* remove device_pin_release block

* Hide DAL.x behind Enum

* bring back deprecated blocks, but hide them

* shims and locales files

* fix input.input. typing

* remove buildpr

* bump V3

* update simulator aspect ratio

* add Loudness Block

* revoke loudness block

* Adds soundLevel

To be replaced by pxt-common-packages when DAL is updated.

* Remove P0 & P3 from AnalogPin

Co-authored-by: Juri <gitkraken@juriwolf.de>
This commit is contained in:
Amerlander
2020-09-08 11:04:25 +02:00
committed by GitHub
parent 98d8b2977b
commit 918af4f3ac
233 changed files with 9391 additions and 2739 deletions

View File

@ -4,6 +4,10 @@
"AcceleratorRange.OneG": "The accelerator measures forces up to 1 gravity",
"AcceleratorRange.TwoG": "The accelerator measures forces up to 2 gravity",
"Array": "Add, remove, and replace items in lists.",
"Array._popStatement": "Remove the last element from an array and return it.",
"Array._removeAtStatement": "Remove the element at a certain index.",
"Array._shiftStatement": "Remove the first element from an array and return it. This method changes the length of the array.",
"Array._unshiftStatement": "Add one element to the beginning of an array and return the new length of the array.",
"Array.concat": "Concatenates the values with another array.",
"Array.concat|param|arr": "The other array that is being concatenated with",
"Array.every": "Tests whether all elements in the array pass the test implemented by the provided function.",
@ -50,17 +54,20 @@
"Array.unshift": "Add one element to the beginning of an array and return the new length of the array.",
"Array@type": "Add, remove, and replace items in lists.",
"Boolean.toString": "Returns a string representation of an object.",
"Buffer.chunked": "Splits buffer into parts no larger than specified",
"Buffer.concat": "Return concatenation of current buffer and the given buffer\n\nConcatenates all buffers in the list",
"Buffer.create": "Allocate a new buffer.",
"Buffer.create|param|size": "number of bytes in the buffer",
"Buffer.equals": "Returns true if this and the other buffer hold the same data",
"Buffer.fill": "Fill (a fragment) of the buffer with given value.",
"Buffer.fromArray": "Create a new buffer initalized to bytes from given array.",
"Buffer.fromArray|param|bytes": "data to initalize with",
"Buffer.fromArray": "Create a new buffer initialized to bytes from given array.",
"Buffer.fromArray|param|bytes": "data to initialize with",
"Buffer.fromHex": "Create a new buffer, decoding a hex string",
"Buffer.fromUTF8": "Create a new buffer with UTF8-encoded string",
"Buffer.fromUTF8|param|str": "the string to put in the buffer",
"Buffer.getNumber": "Read a number in specified format from the buffer.",
"Buffer.getUint8": "Reads an unsigned byte at a particular location",
"Buffer.hash": "Compute k-bit FNV-1 non-cryptographic hash of the buffer.",
"Buffer.indexOf": "Return position of other buffer in current buffer",
"Buffer.isReadOnly": "Returns false when the buffer can be written to.",
"Buffer.length": "Returns the length of a Buffer object.",
@ -77,6 +84,7 @@
"Buffer.shift|param|start": "start offset in buffer. Default is 0.",
"Buffer.sizeOfNumberFormat": "Get the size in bytes of specified number format.",
"Buffer.slice": "Return a copy of a fragment of a buffer.",
"Buffer.toArray": "Read contents of buffer as an array in specified format",
"Buffer.toHex": "Convert a buffer to its hexadecimal representation.",
"Buffer.toString": "Convert a buffer to string assuming UTF8 encoding",
"Buffer.unpack": "Reads numbers from the buffer according to the format",
@ -220,8 +228,15 @@
"String.substr|param|length": "number of characters to extract",
"String.substr|param|start": "first character index; can be negative from counting from the end, eg:0",
"String.toLowerCase": "Converts the string to lower case characters.",
"String.trim": "Return a substring of the current string with whitespace removed from both ends",
"String@type": "Combine, split, and search text strings.",
"StringMap": "A dictionary from string key to string values",
"_py.range": "Returns a sequence of numbers up to but not including the limit\n\nIf more than one argument is passed, this argument is instead used for the first value in the range",
"_py.range|param|first": "The value to end the sequence before. This value will not show up in the result.",
"_py.range|param|step": "The value to increase or decrease by for each step in the range. Must be a nonzero integer",
"_py.range|param|stop": "The value to end the sequence before. This value will not show up in the result",
"_py.slice": "Returns a section of an array according to python's extended slice syntax",
"_py.stringSlice": "Returns a section of a string according to python's extended slice syntax",
"basic": "Provides access to basic micro:bit functionality.\n\nProvides access to basic micro:bit functionality.",
"basic.clearScreen": "Turn off all LEDs",
"basic.color": "Converts the color name to a number",
@ -256,6 +271,9 @@
"basic.turnRgbLedOff": "Sets the color on the build-in LED. Set to 0 to turn off.",
"console": "Reading and writing data to the console output.",
"console.addListener": "Adds a listener for the log messages",
"console.inspect": "Convert any object or value to a string representation",
"console.inspect|param|maxElements": "[optional] max number values in an object to include in output",
"console.inspect|param|obj": "value to be converted to a string",
"console.log": "Write a line of text to the console output.",
"console.logValue": "Write a name:value pair as a line of text to the console output.",
"console.logValue|param|name": "name of the value stream, eg: \"x\"",
@ -272,6 +290,7 @@
"control.eventTimestamp": "Gets the timestamp of the last event executed on the bus",
"control.eventValue": "Gets the value of the last event executed on the bus",
"control.eventValueId": "Returns the value of a C++ runtime constant",
"control.gcStats": "Get various statistics about the garbage collector (GC)",
"control.inBackground": "Schedules code that run in the background.",
"control.micros": "Gets current time in microseconds. Overflows every ~18 minutes.",
"control.millis": "Gets the number of milliseconds elapsed since power on.",
@ -282,12 +301,14 @@
"control.raiseEvent|param|src": "ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.",
"control.raiseEvent|param|value": "Component specific code indicating the cause of the event.",
"control.reset": "Resets the BBC micro:bit.",
"control.runInParallel": "Run other code in the parallel.",
"control.runtimeWarning": "Display warning in the simulator.",
"control.waitForEvent": "Blocks the calling thread until the specified event is raised.",
"control.waitMicros": "Blocks the current fiber for the given microseconds",
"control.waitMicros|param|micros": "number of micro-seconds to wait. eg: 4",
"convertToText": "Convert any value to text",
"convertToText|param|value": "value to be converted to text",
"forever": "Repeats the code forever in the background. On each iteration, allows other codes to run.",
"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",
@ -439,6 +460,9 @@
"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.pointBrightness": "Get the brightness state of the specified LED using x, y coordinates. (0,0) is upper left.",
"led.pointBrightness|param|x": "the horizontal coordinate of the LED",
"led.pointBrightness|param|y": "the vertical coordinate of the LED",
"led.point|param|x": "the horizontal coordinate of the LED",
"led.point|param|y": "the vertical coordinate of the LED",
"led.screenshot": "Takes a screenshot of the LED screen and returns an image.",
@ -454,6 +478,8 @@
"led.unplot": "Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.",
"led.unplot|param|x": "the horizontal coordinate of the LED",
"led.unplot|param|y": "the vertical coordinate of the LED",
"light.sendWS2812Buffer": "Sends a color buffer to a light strip",
"light.setMode": "Sets the light mode of a pin",
"motors": "Blocks to control the onboard motors",
"motors.dualMotorPower": "Controls two motors attached to the board. Switches to dual-motor mode!",
"motors.motorCommand": "Send break, coast or sleep commands to the motor. Has no effect in dual-motor mode.",
@ -464,15 +490,13 @@
"msgpack.unpackNumberArray": "Unpacks a buffer into a number array.",
"music": "Generation of music tones.",
"music.beat": "Returns the duration of a beat in milli-seconds",
"music.beginMelody": "Starts playing a melody.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
"music.beginMelody|param|melodyArray": "the melody array to play",
"music.beginMelody|param|options": "melody options, once / forever, in the foreground / background",
"music.beginMelody": "Use startMelody instead",
"music.builtInMelody": "Gets the melody array of a built-in melody.",
"music.changeTempoBy": "Change the tempo by the specified amount",
"music.changeTempoBy|param|bpm": "The change in beats per minute to the tempo, eg: 20",
"music.melodyEditor": "Create a melody with the melody editor.",
"music.noteFrequency": "Get the frequency of a note.",
"music.noteFrequency|param|name": "the note name, eg: Note.C",
"music.noteFrequency": "Gets the frequency of a note.",
"music.noteFrequency|param|name": "the note name",
"music.onEvent": "Registers code to run on various melody events",
"music.playMelody": "Play a melody from the melody editor.",
"music.playMelody|param|melody": "- string of up to eight notes [C D E F G A B C5] or rests [-] separated by spaces, which will be played one at a time, ex: \"E D G F B A C5 B \"",
@ -487,14 +511,24 @@
"music.setPlayTone": "Sets a custom playTone function for playing melodies",
"music.setTempo": "Sets the tempo to the specified amount",
"music.setTempo|param|bpm": "The new tempo in beats per minute, eg: 120",
"music.setVolume": "Set the default output volume of the sound synthesizer.",
"music.setVolume|param|volume": "the volume 0...255",
"music.speakerPlayTone": "Plays a tone through ``speaker`` for the given duration.",
"music.speakerPlayTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.speakerPlayTone|param|ms": "tone duration in milliseconds (ms)",
"music.startMelody": "Starts playing a melody.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
"music.startMelody|param|melodyArray": "the melody array to play",
"music.startMelody|param|options": "melody options, once / forever, in the foreground / background",
"music.stopMelody": "Stops the melodies",
"music.stopMelody|param|options": "which melody to stop",
"music.tempo": "Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.",
"music.volume": "Returns the current output volume of the sound synthesizer.",
"parseFloat": "Convert a string to a number.",
"parseInt": "Convert a string to an integer.",
"parseInt": "Convert a string to an integer.\n\n\nIf this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.\nAll other strings are considered decimal.",
"parseInt|param|radix": "optional A value between 2 and 36 that specifies the base of the number in text.",
"parseInt|param|text": "A string to convert into an integral number. eg: \"123\"",
"pause": "Pause for the specified time in milliseconds",
"pause|param|ms": "how long to pause for, eg: 100, 200, 500, 1000, 2000",
"pins": "Control currents in Pins for analog/digital signals, servos, i2c, ...",
"pins.C10": "Pin C10",
"pins.C11": "Pin C11",
@ -513,18 +547,21 @@
"pins.P1": "Pin P1",
"pins.P2": "Pin P2",
"pins.P3": "Pin P3",
"pins.analogPitch": "Emit a pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.",
"pins.analogPitch": "Emit a plse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.",
"pins.analogPitchVolume": "Gets the volume the pitch pin from 0..255",
"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": "of pin to read from, eg: AnalogPin.P1",
"pins.analogReadPin|param|name": "pin to write to, eg: AnalogPin.P0",
"pins.analogSetPeriod": "Configure the pulse-width modulation (PWM) period of the analog output in microseconds.\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, eg: AnalogPin.P1",
"pins.analogSetPeriod|param|name": "analog pin to set period to, eg: AnalogPin.P0",
"pins.analogSetPitchPin": "Set the pin used when using analog pitch or music.",
"pins.analogSetPitchPin|param|name": "pin to modulate pitch from",
"pins.analogSetPitchVolume": "Sets the volume on the pitch pin",
"pins.analogSetPitchVolume|param|volume": "the intensity of the sound from 0..255",
"pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.",
"pins.analogWritePin|param|name": "of pin to write to, eg: AnalogPin.P1",
"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",
@ -550,17 +587,18 @@
"pins.pulseIn": "Return the duration of a pulse at a pin in microseconds.",
"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.pushButton": "Mounts a push button on the given pin",
"pins.servoSetContinuous": "Specifies that a continuous servo is connected.",
"pins.servoSetPulse": "Configure the IO pin as an analog/pwm output and set a pulse width. The period is 20 ms period and the pulse width is set based on the value given in **microseconds** or `1/1000` milliseconds.",
"pins.servoSetPulse|param|micros": "pulse duration in micro seconds, eg:1500",
"pins.servoSetPulse|param|name": "pin name",
"pins.servoWritePin": "Write 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, eg: AnalogPin.P1",
"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": "Configure 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": "Configure the pull direction of of a pin.",
"pins.setPull": "Configure the pull directiion of of a pin.",
"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.spiFormat": "Set the SPI bits and mode",
@ -569,8 +607,14 @@
"pins.spiFrequency": "Set the SPI frequency",
"pins.spiFrequency|param|frequency": "the clock frequency, eg: 1000000",
"pins.spiPins": "Set the MOSI, MISO, SCK pins used by the SPI connection",
"pins.spiTransfer": "Write to and read from the SPI slave at the same time",
"pins.spiTransfer|param|command": "Data to be sent to the SPI slave (can be null)",
"pins.spiTransfer|param|response": "Data received from the SPI slave (can be null)",
"pins.spiWrite": "Write to the SPI slave and return the response",
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
"randint": "Returns a pseudorandom number between min and max included.\nIf both numbers are integral, the result is integral.",
"randint|param|max": "the upper inclusive bound, eg: 10",
"randint|param|min": "the lower inclusive bound, eg: 0",
"serial": "Reading and writing data over a serial connection.",
"serial.NEW_LINE": "The string used to mark a new line, default is \\r\\n",
"serial.delimiters": "Return the corresponding delimiter string",
@ -587,6 +631,7 @@
"serial.redirect|param|rate": "the new baud rate. eg: 115200",
"serial.redirect|param|rx": "the new reception pin, eg: SerialPin.P1",
"serial.redirect|param|tx": "the new transmission pin, eg: SerialPin.P0",
"serial.setBaudRate": "Set the baud rate of the serial port",
"serial.setRxBufferSize": "Sets the size of the RX buffer in bytes",
"serial.setRxBufferSize|param|size": "length of the rx buffer in bytes, eg: 32",
"serial.setTxBufferSize": "Sets the size of the TX buffer in bytes",

View File

@ -7,12 +7,16 @@
"AcceleratorRange.OneG|block": "1g",
"AcceleratorRange.TwoG": "The accelerator measures forces up to 2 gravity",
"AcceleratorRange.TwoG|block": "2g",
"Array._popStatement|block": "remove last value from %list",
"Array._removeAtStatement|block": "%list| remove value at %index",
"Array._shiftStatement|block": "remove first value from %list",
"Array._unshiftStatement|block": "%list| insert %value| at beginning",
"Array.indexOf|block": "%list| find index of %value",
"Array.insertAt|block": "%list| insert at %index| value %value",
"Array.length|block": "length of %VALUE",
"Array.pop|block": "get and remove last value from %list",
"Array.push|block": "%list| add value %value| to end",
"Array.removeAt|block": "%list| remove value at %index",
"Array.removeAt|block": "%list| get and remove value at %index",
"Array.reverse|block": "reverse %list",
"Array.shift|block": "get and remove first value from %list",
"Array.unshift|block": "%list| insert %value| at beginning",
@ -55,12 +59,17 @@
"Colors.Violet|block": "violet",
"Colors.White|block": "white",
"Colors.Yellow|block": "yellow",
"Delimiters.CarriageReturn|block": "carriage return (\r)",
"Delimiters.Colon|block": ":",
"Delimiters.Comma|block": ",",
"Delimiters.Dollar|block": "$",
"Delimiters.Fullstop|block": ".",
"Delimiters.Hash|block": "#",
"Delimiters.NewLine|block": "new line",
"Delimiters.NewLine|block": "new line (\n)",
"Delimiters.Pipe|block": "|",
"Delimiters.SemiColon|block": ";",
"Delimiters.Space|block": "space",
"Delimiters.Tab|block": "tab (\t)",
"Dimension.Strength|block": "strength",
"Dimension.X|block": "x",
"Dimension.Y|block": "y",
@ -152,7 +161,7 @@
"Melodies.Chase|block": "chase",
"Melodies.Dadadadum|block": "dadadum",
"Melodies.Entertainer|block": "entertainer",
"Melodies.Funeral|block": "funereal",
"Melodies.Funeral|block": "funeral",
"Melodies.Funk|block": "funk",
"Melodies.JumpDown|block": "jump down",
"Melodies.JumpUp|block": "jump up",
@ -241,6 +250,7 @@
"String.split|block": "split %this=text|at %separator",
"String.substr|block": "substring of %this=text|from %start|of length %length",
"String|block": "String",
"_py|block": "_py",
"basic.clearScreen|block": "clear screen",
"basic.color|block": "%c",
"basic.forever|block": "forever",
@ -295,7 +305,7 @@
"game.setScore|block": "set score %points",
"game.startCountdown|block": "start countdown|(ms) %duration",
"game|block": "game",
"images.arrowImage|block": "arrow image %i=device_arrow",
"images.arrowImage|block": "arrow image %i",
"images.arrowNumber|block": "%arrow",
"images.createBigImage|block": "create big image",
"images.createImage|block": "create image",
@ -324,6 +334,7 @@
"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.pointBrightness|block": "point|x %x|y %y brightness",
"led.point|block": "point|x %x|y %y",
"led.setBrightness|block": "set brightness %value",
"led.setDisplayMode|block": "set display mode $mode",
@ -331,13 +342,13 @@
"led.toggle|block": "toggle|x %x|y %y",
"led.unplot|block": "unplot|x %x|y %y",
"led|block": "led",
"light|block": "light",
"motors.dualMotorPower|block": "motor %motor|at %percent \\%",
"motors.motorCommand|block": "motor %command",
"motors.motorPower|block": "motor on at %percent \\%",
"motors|block": "motors",
"msgpack|block": "msgpack",
"music.beat|block": "%fraction|beat",
"music.beginMelody|block": "start melody %melody=device_builtin_melody| repeating %options",
"music.builtInMelody|block": "%melody",
"music.changeTempoBy|block": "change tempo by (bpm)|%value",
"music.melodyEditor|block": "$melody",
@ -348,15 +359,20 @@
"music.rest|block": "rest(ms)|%duration=device_beat",
"music.ringTone|block": "ring tone (Hz)|%note=device_note",
"music.setTempo|block": "set tempo to (bpm)|%value",
"music.setVolume|block": "set volume %volume",
"music.startMelody|block": "start melody %melody=device_builtin_melody| repeating %options",
"music.stopMelody|block": "stop melody $options",
"music.tempo|block": "tempo (bpm)",
"music.volume|block": "volume",
"music|block": "music",
"parseFloat|block": "parse to number %text",
"parseInt|block": "parse to integer %text",
"pins.analogPitchVolume|block": "analog pitch volume",
"pins.analogPitch|block": "analog pitch %frequency|for (ms) %ms",
"pins.analogReadPin|block": "analog read|pin %name",
"pins.analogSetPeriod|block": "analog set period|pin %pin|to (µs)%micros",
"pins.analogSetPitchPin|block": "analog set pitch pin %name",
"pins.analogSetPitchVolume|block": "analog set pitch volume $volume",
"pins.analogWritePin|block": "analog write|pin %name|to %value",
"pins.digitalReadPin|block": "digital read|pin %name",
"pins.digitalWritePin|block": "digital write|pin %name|to %value",
@ -375,6 +391,7 @@
"pins.spiPins|block": "spi set pins|MOSI %mosi|MISO %miso|SCK %sck",
"pins.spiWrite|block": "spi write %value",
"pins|block": "pins",
"randint|block": "pick random %min|to %limit",
"serial.delimiters|block": "%del",
"serial.onDataReceived|block": "serial|on data received %delimiters=serial_delimiter_conv",
"serial.readBuffer|block": "serial|read buffer %length",
@ -383,6 +400,7 @@
"serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv",
"serial.redirectToUSB|block": "serial|redirect to USB",
"serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate",
"serial.setBaudRate|block": "serial|set baud rate %rate",
"serial.setRxBufferSize|block": "serial set rx buffer size to $size",
"serial.setTxBufferSize|block": "serial set tx buffer size to $size",
"serial.setWriteLinePadding|block": "serial set write line padding to $length",
@ -411,6 +429,7 @@
"{id:category}Images": "Images",
"{id:category}Input": "Input",
"{id:category}Led": "Led",
"{id:category}Light": "Light",
"{id:category}Math": "Math",
"{id:category}MicrobitPin": "MicrobitPin",
"{id:category}Motors": "Motors",
@ -422,5 +441,15 @@
"{id:category}PwmOnlyPin": "PwmOnlyPin",
"{id:category}Serial": "Serial",
"{id:category}String": "String",
"{id:category}Text": "Text"
"{id:category}Text": "Text",
"{id:category}_py": "_py",
"{id:group}Configuration": "Configuration",
"{id:group}Melody": "Melody",
"{id:group}Melody Advanced": "Melody Advanced",
"{id:group}Modify": "Modify",
"{id:group}Operations": "Operations",
"{id:group}Read": "Read",
"{id:group}Tempo": "Tempo",
"{id:group}Tone": "Tone",
"{id:group}Volume": "Volume"
}

View File

@ -131,4 +131,4 @@ namespace basic {
void pause(int ms) {
fiber_sleep(ms);
}
}
}

View File

@ -74,3 +74,19 @@ namespace basic {
showString(Math.roundWithPrecision(value, 2).toString(), interval);
}
}
/**
* Pause for the specified time in milliseconds
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
*/
function pause(ms: number): void {
basic.pause(ms);
}
/**
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute
*/
function forever(a: () => void): void {
basic.forever(a);
}

View File

@ -1,10 +1,10 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="pins_on_pulsed" x="-157" y="130">
<field name="pin">DigitalPin.P5</field>
<field name="pin">DigitalPin.C5</field>
<field name="pulse">PulseValue.Low</field>
<statement name="HANDLER">
<block type="device_set_analog_pin">
<field name="name">AnalogPin.P9</field>
<field name="name">AnalogPin.C6</field>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
@ -12,7 +12,7 @@
</value>
<next>
<block type="device_set_analog_period">
<field name="pin">AnalogPin.P10</field>
<field name="pin">AnalogPin.C6</field>
<value name="micros">
<shadow type="math_number">
<field name="NUM">20000</field>
@ -20,7 +20,7 @@
</value>
<next>
<block type="device_set_digital_pin">
<field name="name">DigitalPin.P6</field>
<field name="name">DigitalPin.C6</field>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
@ -28,7 +28,7 @@
</value>
<next>
<block type="device_set_servo_pin">
<field name="name">AnalogPin.P13</field>
<field name="name">AnalogPin.C5</field>
<value name="value">
<shadow type="math_number">
<field name="NUM">5</field>
@ -36,7 +36,7 @@
</value>
<next>
<block type="device_set_servo_pulse">
<field name="value">AnalogPin.P8</field>
<field name="value">AnalogPin.C6</field>
<value name="micros">
<shadow type="math_number" id="Hx4bpmg|8KSH=b_`+XtP">
<field name="NUM">1500</field>
@ -65,7 +65,7 @@
<field name="NUM">0</field>
</shadow>
<block type="pins_pulse_in">
<field name="name">DigitalPin.P9</field>
<field name="name">DigitalPin.C9</field>
<field name="value">PulseValue.Low</field>
</block>
</value>
@ -102,7 +102,7 @@
<field name="NUM">0</field>
</shadow>
<block type="device_get_digital_pin">
<field name="name">DigitalPin.P9</field>
<field name="name">DigitalPin.C9</field>
</block>
</value>
<value name="value">
@ -110,7 +110,7 @@
<field name="NUM">0</field>
</shadow>
<block type="device_get_analog_pin">
<field name="name">AnalogPin.P9</field>
<field name="name">AnalogPin.C6</field>
</block>
</value>
<value name="repeat">
@ -120,12 +120,12 @@
</value>
<next>
<block type="spi_pins">
<field name="mosi">DigitalPin.P11</field>
<field name="miso">DigitalPin.P9</field>
<field name="sck">DigitalPin.P10</field>
<field name="mosi">DigitalPin.C11</field>
<field name="miso">DigitalPin.C9</field>
<field name="sck">DigitalPin.C10</field>
<next>
<block type="device_set_pull">
<field name="pin">DigitalPin.P9</field>
<field name="pin">DigitalPin.C9</field>
<field name="pull">PinPullMode.PullDown</field>
<next>
<block type="device_analog_pitch">
@ -141,11 +141,11 @@
</value>
<next>
<block type="device_set_pin_events">
<field name="pin">DigitalPin.P8</field>
<field name="pin">DigitalPin.C8</field>
<field name="type">PinEventType.Touch</field>
<next>
<block type="device_analog_set_pitch_pin">
<field name="name">AnalogPin.P9</field>
<field name="name">AnalogPin.C6</field>
<next>
<block type="spi_format">
<value name="bits">

View File

@ -150,31 +150,31 @@
<field name="mode">DisplayMode.Greyscale</field>
<next>
<block type="device_set_analog_pin">
<field name="name">AnalogPin.P4</field>
<field name="name">AnalogPin.C4</field>
<value name="value">
<shadow type="math_number_minmax" id=",:%8N*FL3wa-zFQ[+^$9">
<mutation min="0" max="1023" label="Value"></mutation>
<field name="SLIDER">1023</field>
</shadow>
<block type="device_get_analog_pin">
<field name="name">AnalogPin.P13</field>
<field name="name">AnalogPin.C5</field>
</block>
</value>
<next>
<block type="device_set_digital_pin">
<field name="name">DigitalPin.P10</field>
<field name="name">DigitalPin.C10</field>
<value name="value">
<shadow type="math_number_minmax" id="W~pvdj%jFEj?EHmT{81Z">
<mutation min="0" max="1" label="Value"></mutation>
<field name="SLIDER">0</field>
</shadow>
<block type="device_get_digital_pin">
<field name="name">DigitalPin.P15</field>
<field name="name">DigitalPin.C15</field>
</block>
</value>
<next>
<block type="device_set_analog_period">
<field name="pin">AnalogPin.P9</field>
<field name="pin">AnalogPin.C6</field>
<value name="micros">
<shadow type="math_number" id="4a@.1MdG`n=p;34mQOpC">
<field name="NUM">1234</field>
@ -230,7 +230,7 @@
</value>
<next>
<block type="device_set_servo_pulse">
<field name="value">AnalogPin.P14</field>
<field name="value">AnalogPin.C4</field>
<value name="micros">
<shadow type="math_number" id="@*C3kzJkeeUQ@s$N5?K}">
<field name="NUM">1500</field>
@ -510,7 +510,7 @@
</statement>
</block>
<block type="pins_on_pulsed" x="1538" y="929">
<field name="pin">DigitalPin.P10</field>
<field name="pin">DigitalPin.C10</field>
<field name="pulse">PulseValue.Low</field>
<statement name="HANDLER">
<block type="i2c_writenumber">
@ -575,8 +575,8 @@
<next>
<block type="spi_pins">
<field name="mosi">DigitalPin.P9</field>
<field name="miso">DigitalPin.P14</field>
<field name="sck">DigitalPin.P16</field>
<field name="miso">DigitalPin.C14</field>
<field name="sck">DigitalPin.C16</field>
<next>
<block type="control_reset"></block>
</next>

View File

@ -9,14 +9,18 @@ PXT_ABI(__aeabi_ddiv)
PXT_ABI(__aeabi_dmul)
extern "C" void target_panic(int error_code) {
#if !MICROBIT_CODAL
// wait for serial to flush
wait_us(300000);
sleep_us(300000);
#endif
microbit_panic(error_code);
}
#if !MICROBIT_CODAL
extern "C" void target_reset() {
microbit_reset();
}
#endif
uint32_t device_heap_size(uint8_t heap_index); // defined in microbit-dal
@ -27,7 +31,9 @@ MicroBitEvent lastEvent;
void platform_init() {
microbit_seed_random();
seedRandom(microbit_random(0x7fffffff));
int seed = microbit_random(0x7fffffff);
DMESG("random seed: %d", seed);
seedRandom(seed);
}
void initMicrobitGC() {
@ -43,7 +49,25 @@ struct FreeList {
FreeList *next;
};
void dispatchForeground(MicroBitEvent e, void *action) {
lastEvent = e;
auto value = fromInt(e.value);
runAction1((Action)action, value);
}
void deleteListener(MicroBitListener *l) {
if (l->cb_param == (void (*)(MicroBitEvent, void *))dispatchForeground) {
decr((Action)(l->cb_arg));
unregisterGCPtr((Action)(l->cb_arg));
}
}
static void initCodal() {
// TODO!!!
#ifndef MICROBIT_CODAL
uBit.messageBus.setListenerDeletionCallback(deleteListener);
#endif
// repeat error 4 times and restart as needed
microbit_panic_timeout(4);
}
@ -54,27 +78,11 @@ void dumpDmesg() {}
// An adapter for the API expected by the run-time.
// ---------------------------------------------------------------------------
// We have the invariant that if [dispatchEvent] is registered against the DAL
// for a given event, then [handlersMap] contains a valid entry for that
// event.
void dispatchEvent(MicroBitEvent e) {
lastEvent = e;
auto curr = findBinding(e.source, e.value);
auto value = fromInt(e.value);
if (curr)
runAction1(curr->action, value);
curr = findBinding(e.source, DEVICE_EVT_ANY);
if (curr)
runAction1(curr->action, value);
}
void registerWithDal(int id, int event, Action a, int flags) {
// first time?
if (!findBinding(id, event))
uBit.messageBus.listen(id, event, dispatchEvent, flags);
setBinding(id, event, a);
uBit.messageBus.ignore(id, event, dispatchForeground);
uBit.messageBus.listen(id, event, dispatchForeground, a);
incr(a);
registerGCPtr(a);
}
void fiberDone(void *a) {
@ -92,7 +100,11 @@ void sleep_ms(unsigned ms) {
}
void sleep_us(uint64_t us) {
#if MICROBIT_CODAL
target_wait_us(us);
#else
wait_us(us);
#endif
}
void forever_stub(void *a) {
@ -232,21 +244,43 @@ void setThreadContext(ThreadContext *ctx) {
currentFiber->user_data = ctx;
}
#if !MICROBIT_CODAL
#define tcb_get_stack_base(tcb) (tcb).stack_base
#endif
static void *threadAddressFor(Fiber *fib, void *sp) {
if (fib == currentFiber)
return sp;
return (uint8_t *)sp + ((uint8_t *)fib->stack_top - (uint8_t *)fib->tcb.stack_base);
return (uint8_t *)sp + ((uint8_t *)fib->stack_top - (uint8_t *)tcb_get_stack_base(fib->tcb));
}
void gcProcessStacks(int flags) {
// check scheduler is initialized
if (!currentFiber) {
// make sure we allocate something to at least initalize the memory allocator
void * volatile p = xmalloc(1);
void *volatile p = xmalloc(1);
xfree(p);
return;
}
#ifdef MICROBIT_GET_FIBER_LIST_SUPPORTED
for (Fiber *fib = get_fiber_list(); fib; fib = fib->next) {
auto ctx = (ThreadContext *)fib->user_data;
if (!ctx)
continue;
for (auto seg = &ctx->stack; seg; seg = seg->next) {
auto ptr = (TValue *)threadAddressFor(fib, seg->top);
auto end = (TValue *)threadAddressFor(fib, seg->bottom);
if (flags & 2)
DMESG("RS%d:%p/%d", cnt++, ptr, end - ptr);
// VLOG("mark: %p - %p", ptr, end);
while (ptr < end) {
gcProcess(*ptr++);
}
}
}
#else
int numFibers = list_fibers(NULL);
Fiber **fibers = (Fiber **)xmalloc(sizeof(Fiber *) * numFibers);
int num2 = list_fibers(fibers);
@ -262,8 +296,10 @@ void gcProcessStacks(int flags) {
for (auto seg = &ctx->stack; seg; seg = seg->next) {
auto ptr = (TValue *)threadAddressFor(fib, seg->top);
auto end = (TValue *)threadAddressFor(fib, seg->bottom);
if (flags & 2)
DMESG("RS%d:%p/%d", cnt++, ptr, end - ptr);
if (flags & 2) {
DMESG("RS%d:%p/%d", cnt, ptr, end - ptr);
cnt++;
}
// VLOG("mark: %p - %p", ptr, end);
while (ptr < end) {
gcProcess(*ptr++);
@ -271,6 +307,7 @@ void gcProcessStacks(int flags) {
}
}
xfree(fibers);
#endif
}
} // namespace pxt

View File

@ -17,15 +17,15 @@ namespace console {
*/
//% weight=90
//% help=console/log blockGap=8
//% text.shadowOptions.toString=true
export function log(text: string): void {
export function log(text: any): void {
let stringified = inspect(text);
// pad text on the 32byte boundar
text += "\r\n";
control.__log(text);
stringified += "\r\n";
control.__log(stringified);
// send to listeners
if (listeners)
for (let i = 0; i < listeners.length; ++i)
listeners[i](text);
listeners[i](stringified);
}
/**
@ -35,8 +35,9 @@ namespace console {
*/
//% weight=88 blockGap=8
//% help=console/log-value
export function logValue(name: string, value: number): void {
log(name ? `${name}: ${value}` : `${value}`)
export function logValue(name: any, value: number): void {
const nameText = inspect(name);
log(nameText ? `${nameText}: ${value}` : `${value}`)
}
/**
@ -50,4 +51,44 @@ namespace console {
listeners = [];
listeners.push(listener);
}
/**
* Convert any object or value to a string representation
* @param obj value to be converted to a string
* @param maxElements [optional] max number values in an object to include in output
*/
export function inspect(obj: any, maxElements = 20): string {
if (typeof obj == "string") {
return obj;
} else if (typeof obj == "number") {
return "" + obj;
} else if (Array.isArray(obj)) {
const asArr = (obj as Array<string>);
if (asArr.length <= maxElements) {
return asArr.join(",");
} else {
return `${asArr.slice(0, maxElements).join(",")}...`;
}
} else {
const asString = obj + "";
if (asString != "[object Object]"
&& asString != "[Object]") { // on arcade at least, default toString is [Object] on hardware instead of standard
return asString;
}
let keys = Object.keys(obj);
const snipped = keys.length > maxElements;
if (snipped) {
keys = keys.slice(0, maxElements);
}
return `{${
keys.reduce(
(prev, currKey) => prev + `\n ${currKey}: ${obj[currKey]}`,
""
) + (snipped ? "\n ..." : "")
}
}`;
}
}
}

View File

@ -274,7 +274,7 @@ namespace control {
//% help=control/wait-micros weight=29
//% blockId="control_wait_us" block="wait (µs)%micros"
void waitMicros(int micros) {
wait_us(micros);
sleep_us(micros);
}
/**
@ -297,7 +297,7 @@ namespace control {
//% help=control/on-event
//% blockExternalInputs=1
void onEvent(int src, int value, Action handler, int flags = 0) {
if (!flags) flags = EventFlags::QueueIfBusy;
if (!flags) flags = ::EventFlags::QueueIfBusy;
registerWithDal(src, value, handler, (int)flags);
}
@ -325,6 +325,7 @@ namespace control {
* Make a friendly name for the device based on its serial number
*/
//% blockId="control_device_name" block="device name" weight=10 blockGap=8
//% help=control/device-name
//% advanced=true
String deviceName() {
return mkString(microbit_friendly_name(), -1);
@ -334,6 +335,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
//% help=control/device-serial-number
//% advanced=true
int deviceSerialNumber() {
return microbit_serial_number();

View File

@ -4,11 +4,19 @@
//% weight=1 color="#42495F" icon="\uf233"
//% advanced=true
namespace control {
/**
* Run other code in the parallel.
*/
//% hidden=1
export function runInParallel(a: () => void) {
control.inBackground(a);
}
/**
* Returns the value of a C++ runtime constant
*/
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
//% help=control/event-source-id
//% shim=TD_ID advanced=true
export function eventSourceId(id: EventBusSource): number {
return id;
@ -17,6 +25,7 @@ namespace control {
* Returns the value of a C++ runtime constant
*/
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
//% help=control/event-value-id
//% shim=TD_ID advanced=true
export function eventValueId(id: EventBusValue): number {
return id;
@ -63,4 +72,4 @@ namespace control {
//% blockId=variable_to_text blockNamespace="text"
function convertToText(value: any): string {
return "" + value;
}
}

1851
libs/core/dal.d.ts vendored

File diff suppressed because it is too large Load Diff

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

@ -35,7 +35,7 @@ declare namespace basic {
A = 1, // MICROBIT_ID_BUTTON_A
B = 2, // MICROBIT_ID_BUTTON_B
//% block="A+B"
AB = 26, // MICROBIT_ID_BUTTON_AB
AB = 3, // MICROBIT_ID_BUTTON_AB
}
@ -60,10 +60,10 @@ declare namespace basic {
declare const enum TouchPin {
P0 = 19, // MICROBIT_ID_IO_P12
P1 = 7, // MICROBIT_ID_IO_P0
P2 = 8, // MICROBIT_ID_IO_P1
P3 = 23, // MICROBIT_ID_IO_P16
P0 = 112, // MICROBIT_ID_IO_P12
P1 = 100, // MICROBIT_ID_IO_P0
P2 = 101, // MICROBIT_ID_IO_P1
P3 = 116, // MICROBIT_ID_IO_P16
}
@ -221,51 +221,51 @@ declare namespace input {
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_B = 2, // MICROBIT_ID_BUTTON_B
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_AB = 26, // MICROBIT_ID_BUTTON_AB
MICROBIT_ID_BUTTON_AB = 3, // MICROBIT_ID_BUTTON_AB
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_RADIO = 29, // MICROBIT_ID_RADIO
MICROBIT_ID_RADIO = 9, // MICROBIT_ID_RADIO
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_GESTURE = 27, // MICROBIT_ID_GESTURE
MICROBIT_ID_GESTURE = 13, // MICROBIT_ID_GESTURE
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_ACCELEROMETER = 4, // MICROBIT_ID_ACCELEROMETER
MICROBIT_ID_ACCELEROMETER = 5, // MICROBIT_ID_ACCELEROMETER
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P0 = 7, // MICROBIT_ID_IO_P0
MICROBIT_ID_IO_P0 = 100, // MICROBIT_ID_IO_P0
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P1 = 8, // MICROBIT_ID_IO_P1
MICROBIT_ID_IO_P1 = 101, // MICROBIT_ID_IO_P1
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P2 = 9, // MICROBIT_ID_IO_P2
MICROBIT_ID_IO_P2 = 102, // MICROBIT_ID_IO_P2
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P3 = 10, // MICROBIT_ID_IO_P3
MICROBIT_ID_IO_P3 = 103, // MICROBIT_ID_IO_P3
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P4 = 11, // MICROBIT_ID_IO_P4
MICROBIT_ID_IO_P4 = 104, // MICROBIT_ID_IO_P4
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P5 = 12, // MICROBIT_ID_IO_P5
MICROBIT_ID_IO_P5 = 105, // MICROBIT_ID_IO_P5
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P6 = 13, // MICROBIT_ID_IO_P6
MICROBIT_ID_IO_P6 = 106, // MICROBIT_ID_IO_P6
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P7 = 14, // MICROBIT_ID_IO_P7
MICROBIT_ID_IO_P7 = 107, // MICROBIT_ID_IO_P7
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P8 = 15, // MICROBIT_ID_IO_P8
MICROBIT_ID_IO_P8 = 108, // MICROBIT_ID_IO_P8
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P9 = 16, // MICROBIT_ID_IO_P9
MICROBIT_ID_IO_P9 = 109, // MICROBIT_ID_IO_P9
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P10 = 17, // MICROBIT_ID_IO_P10
MICROBIT_ID_IO_P10 = 110, // MICROBIT_ID_IO_P10
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P11 = 18, // MICROBIT_ID_IO_P11
MICROBIT_ID_IO_P11 = 111, // MICROBIT_ID_IO_P11
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P12 = 19, // MICROBIT_ID_IO_P12
MICROBIT_ID_IO_P12 = 112, // MICROBIT_ID_IO_P12
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P13 = 20, // MICROBIT_ID_IO_P13
MICROBIT_ID_IO_P13 = 113, // MICROBIT_ID_IO_P13
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P14 = 21, // MICROBIT_ID_IO_P14
MICROBIT_ID_IO_P14 = 114, // MICROBIT_ID_IO_P14
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P15 = 22, // MICROBIT_ID_IO_P15
MICROBIT_ID_IO_P15 = 115, // MICROBIT_ID_IO_P15
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P16 = 23, // MICROBIT_ID_IO_P16
MICROBIT_ID_IO_P16 = 116, // MICROBIT_ID_IO_P16
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P19 = 24, // MICROBIT_ID_IO_P19
MICROBIT_ID_IO_P19 = 119, // MICROBIT_ID_IO_P19
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P20 = 25, // MICROBIT_ID_IO_P20
MICROBIT_ID_IO_P20 = 120, // MICROBIT_ID_IO_P20
//% blockIdentity="control.eventSourceId"
MES_DEVICE_INFO_ID = 1103, // MES_DEVICE_INFO_ID
//% blockIdentity="control.eventSourceId"
@ -405,11 +405,11 @@ declare namespace input {
declare const enum EventFlags {
//%
QueueIfBusy = 0x0010, // MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY
QueueIfBusy = 16, // MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY
//%
DropIfBusy = 0x0020, // MESSAGE_BUS_LISTENER_DROP_IF_BUSY
DropIfBusy = 32, // MESSAGE_BUS_LISTENER_DROP_IF_BUSY
//%
Reentrant = 0x0008, // MESSAGE_BUS_LISTENER_REENTRANT
Reentrant = 8, // MESSAGE_BUS_LISTENER_REENTRANT
}
declare namespace control {
}
@ -449,35 +449,37 @@ declare namespace motors {
declare const enum DigitalPin {
P0 = 19, // MICROBIT_ID_IO_P12
P1 = 7, // MICROBIT_ID_IO_P0
P2 = 8, // MICROBIT_ID_IO_P1
P3 = 23, // MICROBIT_ID_IO_P16
C4 = 10, // MICROBIT_ID_IO_P3
C5 = 11, // MICROBIT_ID_IO_P4
C6 = 17, // MICROBIT_ID_IO_P10
C7 = 20, // MICROBIT_ID_IO_P13
C8 = 21, // MICROBIT_ID_IO_P14
C9 = 22, // MICROBIT_ID_IO_P15
C10 = 16, // MICROBIT_ID_IO_P9
C11 = 14, // MICROBIT_ID_IO_P7
C12 = 13, // MICROBIT_ID_IO_P6
C16 = 9, // MICROBIT_ID_IO_P2
C17 = 15, // MICROBIT_ID_IO_P8
C18 = 25, // MICROBIT_ID_IO_P20
C19 = 24, // MICROBIT_ID_IO_P19
P0 = 112, // MICROBIT_ID_IO_P12
P1 = 100, // MICROBIT_ID_IO_P0
P2 = 101, // MICROBIT_ID_IO_P1
P3 = 116, // MICROBIT_ID_IO_P16
C4 = 103, // MICROBIT_ID_IO_P3
C5 = 104, // MICROBIT_ID_IO_P4
C6 = 110, // MICROBIT_ID_IO_P10
C7 = 113, // MICROBIT_ID_IO_P13
C8 = 114, // MICROBIT_ID_IO_P14
C9 = 115, // MICROBIT_ID_IO_P15
C10 = 109, // MICROBIT_ID_IO_P9
C11 = 107, // MICROBIT_ID_IO_P7
C12 = 106, // MICROBIT_ID_IO_P6
C16 = 102, // MICROBIT_ID_IO_P2
C17 = 108, // MICROBIT_ID_IO_P8
C18 = 120, // MICROBIT_ID_IO_P20
C19 = 119, // MICROBIT_ID_IO_P19
}
declare const enum AnalogPin {
P1 = 7, // MICROBIT_ID_IO_P0
P2 = 8, // MICROBIT_ID_IO_P1
C4 = 10, // MICROBIT_ID_IO_P3
C5 = 11, // MICROBIT_ID_IO_P4
C6 = 17, // MICROBIT_ID_IO_P10
C16 = 9, // MICROBIT_ID_IO_P2
C17 = 15, // MICROBIT_ID_IO_P8
MIC = 50, // MICROBIT_ID_IO_P21
P0 = 112, // MICROBIT_ID_IO_P12
P1 = 100, // MICROBIT_ID_IO_P0
P2 = 101, // MICROBIT_ID_IO_P1
P3 = 116, // MICROBIT_ID_IO_P16
C4 = 103, // MICROBIT_ID_IO_P3
C5 = 104, // MICROBIT_ID_IO_P4
C6 = 110, // MICROBIT_ID_IO_P10
C16 = 102, // MICROBIT_ID_IO_P2
C17 = 108, // MICROBIT_ID_IO_P8
MIC = 121, // MICROBIT_ID_IO_P21
}
@ -501,23 +503,23 @@ declare namespace motors {
declare const enum PinEventType {
//% block="edge"
Edge = 1, // MICROBIT_PIN_EVENT_ON_EDGE
Edge = 2, // MICROBIT_PIN_EVENT_ON_EDGE
//% block="pulse"
Pulse = 2, // MICROBIT_PIN_EVENT_ON_PULSE
Pulse = 3, // MICROBIT_PIN_EVENT_ON_PULSE
//% block="touch"
Touch = 3, // MICROBIT_PIN_EVENT_ON_TOUCH
Touch = 4, // MICROBIT_PIN_EVENT_ON_TOUCH
//% block="none"
None = 0, // MICROBIT_PIN_EVENT_NONE
}
declare const enum SerialPin {
P0 = 19, // MICROBIT_ID_IO_P12
P1 = 7, // MICROBIT_ID_IO_P0
P2 = 8, // MICROBIT_ID_IO_P1
P3 = 23, // MICROBIT_ID_IO_P16
C16 = 9, // MICROBIT_ID_IO_P2
C17 = 15, // MICROBIT_ID_IO_P8
P0 = 112, // MICROBIT_ID_IO_P12
P1 = 100, // MICROBIT_ID_IO_P0
P2 = 101, // MICROBIT_ID_IO_P1
P3 = 116, // MICROBIT_ID_IO_P16
C16 = 102, // MICROBIT_ID_IO_P2
C17 = 108, // MICROBIT_ID_IO_P8
USB_TX = 1001,
USB_RX = 1002,
}
@ -547,22 +549,6 @@ declare namespace motors {
//% block=1200
BaudRate1200 = 1200,
}
declare const enum Delimiters {
//% block="new line"
NewLine = 1,
//% block=","
Comma = 2,
//% block="$"
Dollar = 3,
//% block=":"
Colon = 4,
//% block="."
Fullstop = 5,
//% block="#"
Hash = 6,
}
declare namespace serial {
}

View File

@ -7,4 +7,4 @@ namespace Math {
export function randomBoolean(): boolean {
return Math.randomRange(0, 1) === 1;
}
}
}

View File

@ -210,7 +210,7 @@ namespace images {
//% weight=50 blockGap=8
//% help=images/arrow-image
//% blockId=builtin_arrow_image block="arrow image %i=device_arrow"
//% blockId=builtin_arrow_image block="arrow image %i"
export function arrowImage(i: ArrowNames): Image {
switch (i) {
// compass directions

View File

@ -11,7 +11,7 @@ void RefMImage::destroy(RefMImage *t) {
}
void RefMImage::print(RefMImage *t) {
DMESG("RefMImage %p r=%d size=%d x %d", t, t->refcnt, img->width, img->height);
DMESG("RefMImage %p size=%d x %d", t, t->img->width, t->img->height);
}
void RefMImage::makeWritable() {
@ -52,6 +52,22 @@ Image createImage(ImageLiteral_ leds) {
Image createBigImage(ImageLiteral_ leds) {
return createImage(leds);
}
//%
Buffer charCodeBuffer(int charCode) {
if(charCode < MICROBIT_FONT_ASCII_START || charCode > MICROBIT_FONT_ASCII_END)
return NULL;
#if MICROBIT_CODAL
auto font = codal::BitmapFont::getSystemFont();
#else
auto font = MicroBitFont::getSystemFont();
#endif
const int offset = (charCode - MICROBIT_FONT_ASCII_START) * 5;;
const uint8_t* charBuffer = font.characters + offset;
return PXT_CREATE_BUFFER(charBuffer, 5);
}
} // namespace images
namespace ImageMethods {
@ -83,7 +99,7 @@ void showImage(Image sprite, int xOffset, int interval = 400) {
//% parts="ledmatrix"
void plotFrame(Image i, int xOffset) {
// TODO showImage() used in original implementation
plotImage(i, xOffset * 5);
plotImage(i, xOffset * i->img->height);
}
/**
@ -178,6 +194,6 @@ bool pixel(Image i, int x, int y) {
//% weight=70 help=images/show-frame
//% parts="ledmatrix"
void showFrame(Image i, int frame, int interval = 400) {
showImage(i, frame * 5, interval);
showImage(i, frame * i->img->height, interval);
}
} // namespace ImageMethods

View File

@ -350,17 +350,17 @@ namespace input {
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8
//% parts="compass"
//% advanced=true
int magneticForce(Dimension dimension) {
if (!uBit.compass.isCalibrated())
uBit.compass.calibrate();
switch (dimension) {
case Dimension::X: return uBit.compass.getX() / 1000;
case Dimension::Y: return uBit.compass.getY() / 1000;
case Dimension::Z: return uBit.compass.getZ() / 1000;
case Dimension::Strength: return uBit.compass.getFieldStrength() / 1000;
}
return 0;
TNumber magneticForce(Dimension dimension) {
if (!uBit.compass.isCalibrated())
uBit.compass.calibrate();
double d = 0;
switch (dimension) {
case Dimension::X: d = uBit.compass.getX(); break;
case Dimension::Y: d = uBit.compass.getY(); break;
case Dimension::Z: d = uBit.compass.getZ(); break;
case Dimension::Strength: d = uBit.compass.getFieldStrength() ; break;
}
return fromDouble(d / 1000.0);
}
/**

View File

@ -25,6 +25,7 @@ namespace input {
* Attaches code to run when the device is shaken.
* @param body TODO
*/
//% deprecated=true
//% help=input/on-shake
export function onShake(body: () => void): void {
onGesture(Gesture.Shake, body);
@ -76,4 +77,27 @@ namespace input {
export function runningTimeMicros() {
return control.micros();
}
/**
* gets the level of loudness in 0-100%
*/
//% blockId="loudness"
//% block="Loudness"
export function soundLevel(): number {
let value = 0
let max = 0
let min = 1023
for (let index = 0; index < 32; index++) {
value = pins.analogReadPin(AnalogPin.MIC)
if (value > max) {
max = value
} else if (value < min) {
min = value
}
}
value = (max - min) * 977 / 10000
return value
}
}

View File

@ -62,18 +62,18 @@ namespace led {
}
/**
* Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.
* Get the brightness state of the specified LED using x, y coordinates. (0,0) is upper left.
* @param x the horizontal coordinate of the LED
* @param y the vertical coordinate of the LED
*/
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y"
//% help=led/point-brightness weight=76
//% blockId=device_point_brightness block="point|x %x|y %y brightness"
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
bool point(int x, int y) {
int pix = uBit.display.image.getPixelValue(x, y);
return pix > 0;
//% advanced=true
int pointBrightness(int x, int y) {
return uBit.display.image.getPixelValue(x, y);
}
/**

View File

@ -2,7 +2,20 @@
* Control of the LED screen.
*/
//% color=#8169E6 weight=97
namespace led {
namespace led {
/**
* Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.
* @param x the horizontal coordinate of the LED
* @param y the vertical coordinate of the 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
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
export function point(x: number, y: number): boolean {
return led.pointBrightness(x, y) > 0;
}
// what's the current high value
let barGraphHigh = 0;
@ -142,6 +155,4 @@
}
led.setBrightness(0);
}
}

40
libs/core/light.cpp Normal file
View File

@ -0,0 +1,40 @@
#include "pxt.h"
#if MICROBIT_CODAL
#include "neopixel.h"
#else
extern "C" void neopixel_send_buffer_core(DevicePin *pin, const uint8_t *ptr, int numBytes);
__attribute__((noinline)) static void neopixel_send_buffer(DevicePin &pin, const uint8_t *ptr,
int numBytes) {
// setup pin as digital
pin.setDigitalValue(0);
__disable_irq();
neopixel_send_buffer_core(&pin, ptr, numBytes);
__enable_irq();
}
#endif
namespace light {
/**
* Sends a color buffer to a light strip
**/
//% advanced=true
//%
void sendWS2812Buffer(Buffer buf, int pin) {
if (!buf || !buf->length)
return;
neopixel_send_buffer(*pxt::getPin(pin), buf->data, buf->length);
}
/**
* Sets the light mode of a pin
**/
//% advanced=true
//%
void setMode(int pin, int mode) {
}
} // namespace light

View File

@ -46,7 +46,7 @@ enum Melodies {
Birthday,
//% block="wedding" blockIdentity=music.builtInMelody
Wedding,
//% block="funereal" blockIdentity=music.builtInMelody
//% block="funeral" blockIdentity=music.builtInMelody
Funeral,
//% block="punchline" blockIdentity=music.builtInMelody
Punchline,

View File

@ -173,12 +173,13 @@ enum MusicEvent {
* Generation of music tones.
*/
//% color=#DF4600 weight=98 icon="\uf025"
//% groups='["Melody", "Tone", "Volume", "Tempo", "Melody Advanced"]'
namespace music {
const INTERNAL_MELODY_ENDED = 5;
let beatsPerMinute: number = 120;
//% whenUsed
const freqs = hex`
//% whenUsed
const freqs = hex`
1f00210023002500270029002c002e003100340037003a003e004100450049004e00520057005c00620068006e00
75007b0083008b0093009c00a500af00b900c400d000dc00e900f70006011501260137014a015d01720188019f01
b801d201ee010b022a024b026e029302ba02e40210033f037003a403dc03170455049704dd0427057505c8052006
@ -194,11 +195,12 @@ namespace music {
*/
//% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" blockGap=8
//% parts="headphone"
//% parts="speaker"
//% useEnumVal=1
//% group="Tone"
export function playTone(frequency: number, ms: number): void {
if (_playTone) _playTone(frequency, ms);
else speakerPlayTone(frequency, ms);
else pins.analogPitch(frequency, ms);
}
/**
@ -207,8 +209,9 @@ namespace music {
*/
//% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" blockGap=8
//% parts="headphone"
//% parts="speaker"
//% useEnumVal=1
//% group="Tone"
export function ringTone(frequency: number): void {
playTone(frequency, 0);
}
@ -219,29 +222,29 @@ namespace music {
*/
//% help=music/rest weight=79
//% blockId=device_rest block="rest(ms)|%duration=device_beat"
//% parts="headphone"
//% parts="speaker"
//% group="Tone"
export function rest(ms: number): void {
playTone(0, ms);
}
/**
* Get the frequency of a note.
* @param name the note name, eg: Note.C
* Gets the frequency of a note.
* @param name the note name
*/
//% weight=1 help=music/note-frequency
//% weight=50 help=music/note-frequency
//% blockId=device_note block="%name"
//% shim=TD_ID
//% color="#FFFFFF" colorSecondary="#FFFFFF"
//% shim=TD_ID color="#FFFFFF" colorSecondary="#FFFFFF"
//% name.fieldEditor="note" name.defl="262"
//% name.fieldOptions.decompileLiterals=true
//% useEnumVal=1
//% weight=10 blockGap=8
//% group="Tone"
//% blockGap=8
export function noteFrequency(name: Note): number {
return name;
}
function init() {
if (beatsPerMinute <= 0) beatsPerMinute = 120;
}
@ -251,6 +254,8 @@ namespace music {
*/
//% help=music/beat weight=49
//% blockId=device_beat block="%fraction|beat"
//% group="Tempo"
//% blockGap=8
export function beat(fraction?: BeatFraction): number {
init();
if (fraction == null) fraction = BeatFraction.Whole;
@ -271,6 +276,7 @@ namespace music {
*/
//% help=music/tempo weight=40
//% blockId=device_tempo block="tempo (bpm)" blockGap=8
//% group="Tempo"
export function tempo(): number {
init();
return beatsPerMinute;
@ -282,6 +288,7 @@ namespace music {
*/
//% help=music/change-tempo-by weight=39
//% blockId=device_change_tempo block="change tempo by (bpm)|%value" blockGap=8
//% group="Tempo"
export function changeTempoBy(bpm: number): void {
init();
setTempo(beatsPerMinute + bpm);
@ -294,6 +301,7 @@ namespace music {
//% help=music/set-tempo weight=38
//% blockId=device_set_tempo block="set tempo to (bpm)|%value"
//% bpm.min=4 bpm.max=400
//% group="Tempo"
export function setTempo(bpm: number): void {
init();
if (bpm > 0) {
@ -311,6 +319,7 @@ namespace music {
//% weight=50 help=music/builtin-melody
//% blockId=device_builtin_melody block="%melody"
//% blockHidden=true
//% group="Melody Advanced"
export function builtInMelody(melody: Melodies): string[] {
return getMelody(melody);
}
@ -320,10 +329,21 @@ namespace music {
*/
//% blockId=melody_on_event block="music on %value"
//% help=music/on-event weight=59 blockGap=32
//% group="Melody Advanced"
export function onEvent(value: MusicEvent, handler: () => void) {
control.onEvent(MICROBIT_MELODY_ID, value, handler);
}
/**
* Use startMelody instead
*/
//% hidden=1 deprecated=1
//% parts="speaker"
//% group="Melody Advanced"
export function beginMelody(melodyArray: string[], options: MelodyOptions = 1) {
return startMelody(melodyArray, options);
}
/**
* Starts playing a melody.
* Notes are expressed as a string of characters with this format: NOTE[octave][:duration]
@ -332,8 +352,9 @@ namespace music {
*/
//% help=music/begin-melody weight=60 blockGap=16
//% blockId=device_start_melody block="start melody %melody=device_builtin_melody| repeating %options"
//% parts="headphone"
export function beginMelody(melodyArray: string[], options: MelodyOptions = 1) {
//% parts="speaker"
//% group="Melody Advanced"
export function startMelody(melodyArray: string[], options: MelodyOptions = 1) {
init();
if (currentMelody != undefined) {
if (((options & MelodyOptions.OnceInBackground) == 0)
@ -382,7 +403,8 @@ namespace music {
//% melody.shadow="melody_editor"
//% tempo.min=40 tempo.max=500
//% tempo.defl=120
//% parts=headphone
//% parts=speaker
//% group="Melody"
export function playMelody(melody: string, tempo: number) {
melody = melody || "";
setTempo(tempo);
@ -402,7 +424,7 @@ namespace music {
}
}
music.beginMelody(notes, MelodyOptions.Once)
music.startMelody(notes, MelodyOptions.Once)
control.waitForEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);
}
@ -419,6 +441,7 @@ namespace music {
//% melody.fieldOptions.decompileIndirectFixedInstances="true"
//% melody.fieldOptions.onParentBlock="true"
//% shim=TD_ID
//% group="Melody"
export function melodyEditor(melody: string): string {
return melody;
}
@ -429,12 +452,13 @@ namespace music {
*/
//% help=music/stop-melody weight=59 blockGap=16
//% blockId=device_stop_melody block="stop melody $options"
//% parts="headphone"
//% parts="speaker"
//% group="Melody Advanced"
export function stopMelody(options: MelodyStopOptions) {
if (options & MelodyStopOptions.Background)
beginMelody([], MelodyOptions.OnceInBackground);
startMelody([], MelodyOptions.OnceInBackground);
if (options & MelodyStopOptions.Foreground)
beginMelody([], MelodyOptions.Once);
startMelody([], MelodyOptions.Once);
}
/**
@ -442,10 +466,38 @@ namespace music {
*/
//% help=music/set-play-tone
//% advanced=true
//% group="Tone"
export function setPlayTone(f: (frequency: number, duration: number) => void) {
_playTone = f;
}
/**
* Set the default output volume of the sound synthesizer.
* @param volume the volume 0...255
*/
//% blockId=synth_set_volume block="set volume %volume"
//% parts="speaker"
//% volume.min=0 volume.max=255
//% volume.defl=127
//% help=music/set-volume
//% weight=70
//% group="Volume"
export function setVolume(volume: number): void {
pins.analogSetPitchVolume(volume);
}
/**
* Returns the current output volume of the sound synthesizer.
*/
//% blockId=synth_get_volume block="volume"
//% parts="speaker"
//% help=music/volume
//% weight=69
//% group="Volume"
export function volume(): number {
return pins.analogPitchVolume();
}
function playNextNote(melody: Melody): void {
// cache elements
let currNote = melody.nextNote();

View File

@ -21,8 +21,8 @@ enum class DigitalPin {
};
enum class AnalogPin {
P1 = MICROBIT_ID_IO_P0, // edge connector 1
P2 = MICROBIT_ID_IO_P1, // edge connector 2
P1 = MICROBIT_ID_IO_P0, // edge connector 1
P2 = MICROBIT_ID_IO_P1, // edge connector 2
C4 = MICROBIT_ID_IO_P3, // LED matrix C1
C5 = MICROBIT_ID_IO_P4, // LED matrix C2
C6 = MICROBIT_ID_IO_P10, // LED matrix C3
@ -83,6 +83,10 @@ MicroBitPin *getPin(int id) {
case MICROBIT_ID_IO_P19: return &uBit.io.P19;
case MICROBIT_ID_IO_P20: return &uBit.io.P20;
case MICROBIT_ID_IO_P21: return &uBit.io.P21;
#if MICROBIT_CODAL
case 1001: return &uBit.io.usbTx;
case 1002: return &uBit.io.usbRx;
#endif
default: return NULL;
}
}
@ -113,7 +117,7 @@ namespace pins {
//% 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"
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="250"
int digitalReadPin(DigitalPin name) {
PINREAD(getDigitalValue());
}
@ -127,14 +131,14 @@ namespace pins {
//% 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"
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="250"
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 of pin to read from, eg: AnalogPin.P1
* @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"
@ -146,7 +150,7 @@ namespace pins {
/**
* Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name of pin to write to, eg: AnalogPin.P1
* @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
@ -161,7 +165,7 @@ namespace pins {
/**
* Configure the pulse-width modulation (PWM) period of the analog output in microseconds.
* 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, eg: AnalogPin.P1
* @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
@ -180,7 +184,7 @@ namespace pins {
//% help=pins/on-pulsed weight=22 blockGap=16 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"
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
void onPulsed(DigitalPin name, PulseValue pulse, Action body) {
MicroBitPin* pin = getPin((int)name);
if (!pin) return;
@ -209,7 +213,7 @@ namespace pins {
//% weight=20 advanced=true
//% help=pins/pulse-in
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="250"
int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) {
MicroBitPin* pin = getPin((int)name);
if (!pin) return 0;
@ -244,7 +248,7 @@ namespace pins {
/**
* Write 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, eg: AnalogPin.P1
* @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
@ -282,6 +286,8 @@ namespace pins {
MicroBitPin* pitchPin = NULL;
MicroBitPin* pitchPin2 = NULL;
uint8_t pitchVolume = 0xff;
/**
* Set the pin used when using analog pitch or music.
@ -292,50 +298,95 @@ namespace pins {
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="250"
void analogSetPitchPin(AnalogPin name) {
pitchPin = getPin((int)name);
pitchPin = getPin((int)name);
pitchPin2 = NULL;
}
void pinAnalogSetPitch(MicroBitPin* pin, int frequency, int ms) {
if (frequency <= 0 || pitchVolume == 0) {
pin->setAnalogValue(0);
} else {
int v = 1 << (pitchVolume >> 5);
pin->setAnalogValue(v);
pin->setAnalogPeriodUs(1000000/frequency);
}
}
/**
* Emit a pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* Sets the volume on the pitch pin
* @param volume the intensity of the sound from 0..255
*/
//% blockId=device_analog_set_pitch_volume block="analog set pitch volume $volume"
//% help=pins/analog-set-pitch-volume weight=3 advanced=true
//% volume.min=0 volume.max=255
void analogSetPitchVolume(int volume) {
pitchVolume = max(0, min(0xff, volume));
}
/**
* Gets the volume the pitch pin from 0..255
*/
//% blockId=device_analog_pitch_volume block="analog pitch volume"
//% help=pins/analog-pitch-volume weight=3 advanced=true
int analogPitchVolume() {
return pitchVolume;
}
/**
* Emit a plse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* @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
void analogPitch(int frequency, int ms) {
if (pitchPin == NULL)
analogSetPitchPin(AnalogPin::P1);
if (frequency <= 0) {
pitchPin->setAnalogValue(0);
} else {
pitchPin->setAnalogValue(512);
pitchPin->setAnalogPeriodUs(1000000/frequency);
}
if (ms > 0) {
fiber_sleep(ms);
pitchPin->setAnalogValue(0);
// TODO why do we use wait_ms() here? it's a busy wait I think
wait_ms(5);
// init pins if needed
if (NULL == pitchPin) {
pitchPin = getPin((int)AnalogPin::P0);
#ifdef SOUND_MIRROR_EXTENSION
pitchPin2 = &SOUND_MIRROR_EXTENSION;
#endif
}
// set pitch
if (NULL != pitchPin)
pinAnalogSetPitch(pitchPin, frequency, ms);
if (NULL != pitchPin2)
pinAnalogSetPitch(pitchPin2, frequency, ms);
// clear pitch
if (ms > 0) {
fiber_sleep(ms);
if (NULL != pitchPin)
pitchPin->setAnalogValue(0);
if (NULL != pitchPin2)
pitchPin2->setAnalogValue(0);
fiber_sleep(5);
}
}
/**
* Configure the pull direction of of a pin.
* Configure the pull directiion of of a pin.
* @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 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"
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
void setPull(DigitalPin name, PinPullMode pull) {
#if MICROBIT_CODAL
codal::PullMode m = pull == PinPullMode::PullDown
? codal::PullMode::Down
: pull == PinPullMode::PullUp ? codal::PullMode::Up
: codal::PullMode::None;
PINOP(setPull(m));
#else
PinMode m = pull == PinPullMode::PullDown
? PinMode::PullDown
: pull == PinPullMode::PullUp ? PinMode::PullUp
: PinMode::PullNone;
PINOP(setPull(m));
#endif
}
/**
@ -347,7 +398,7 @@ 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"
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
void setEvents(DigitalPin name, PinEventType type) {
getPin((int)name)->eventOn((int)type);
}
@ -362,6 +413,12 @@ namespace pins {
return mkBuffer(NULL, size);
}
#if MICROBIT_CODAL
#define BUFFER_TYPE uint8_t*
#else
#define BUFFER_TYPE char*
#endif
/**
* Read `size` bytes from a 7-bit I2C `address`.
*/
@ -369,7 +426,7 @@ namespace pins {
Buffer i2cReadBuffer(int address, int size, bool repeat = false)
{
Buffer buf = createBuffer(size);
uBit.i2c.read(address << 1, (char*)buf->data, size, repeat);
uBit.i2c.read(address << 1, (BUFFER_TYPE)buf->data, size, repeat);
return buf;
}
@ -379,7 +436,7 @@ namespace pins {
//%
int i2cWriteBuffer(int address, Buffer buf, bool repeat = false)
{
return uBit.i2c.write(address << 1, (char*)buf->data, buf->length, repeat);
return uBit.i2c.write(address << 1, (BUFFER_TYPE)buf->data, buf->length, repeat);
}
SPI* spi = NULL;
@ -400,6 +457,30 @@ namespace pins {
return p->write(value);
}
/**
* Write to and read from the SPI slave at the same time
* @param command Data to be sent to the SPI slave (can be null)
* @param response Data received from the SPI slave (can be null)
*/
//% help=pins/spi-transfer argsNullable
void spiTransfer(Buffer command, Buffer response) {
if (!command && !response)
target_panic(PANIC_INVALID_ARGUMENT);
if (command && response && command->length != response->length)
target_panic(PANIC_INVALID_ARGUMENT);
auto p = allocSPI();
unsigned len = command ? command->length : response->length;
#if MICROBIT_CODAL
p->transfer(command ? command->data : NULL, command ? len : 0,
response ? response->data : NULL, response ? len : 0);
#else
for (unsigned i = 0; i < len; ++i) {
int v = p->write(command ? command->data[i] : 0);
if (response) response->data[i] = v;
}
#endif
}
/**
* Set the SPI frequency
* @param frequency the clock frequency, eg: 1000000
@ -423,6 +504,12 @@ namespace pins {
p->format(bits, mode);
}
#if MICROBIT_CODAL
#define PIN_ARG(pin) *(getPin((int)(pin)))
#else
#define PIN_ARG(pin) (getPin((int)(pin)))->name
#endif
/**
* Set the MOSI, MISO, SCK pins used by the SPI connection
*
@ -440,7 +527,18 @@ namespace pins {
delete spi;
spi = NULL;
}
spi = new SPI(PIN_ARG(mosi), PIN_ARG(miso), PIN_ARG(sck));
}
spi = new SPI(getPin((int)mosi)->name, getPin((int)miso)->name, getPin((int)sck)->name);
/**
* Mounts a push button on the given pin
*/
//% help=pins/push-button advanced=true
void pushButton(DigitalPin pin) {
#if MICROBIT_CODAL
new MicroBitButton(PIN_ARG(pin), (int)pin, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW, codal::PullMode::Up);
#else
new MicroBitButton(PIN_ARG(pin), PinMode::PullUp);
#endif
}
}

View File

@ -1,4 +1,4 @@
const enum PinEvent {
enum PinEvent {
//% block="pulse high"
PulseHigh = DAL.MICROBIT_PIN_EVT_PULSE_HI, // DEVICE_PIN_EVT_PULSE_HI
//% block="pulse low"

View File

@ -1,3 +1,5 @@
#include "nrf.h"
// helpful define to handle C++ differences in package
#define PXT_MICROBIT_TAGGED_INT 1
#define PXT_POWI 1

View File

@ -33,6 +33,14 @@ static inline ImageData *imageBytes(ImageLiteral_ lit) {
return (ImageData *)lit;
}
#if MICROBIT_CODAL
// avoid clashes with codal-defined classes
#define Image MImage
#define Button MButton
#endif
typedef MicroBitPin DevicePin;
typedef RefMImage *Image;
extern MicroBit uBit;

View File

@ -17,6 +17,8 @@
"core.cpp",
"pxt-helpers.ts",
"helpers.ts",
"pxt-python.d.ts",
"pxt-python-helpers.ts",
"pinscompat.ts",
"configkeys.h",
"gc.cpp",
@ -31,6 +33,8 @@
"gestures.jres",
"control.ts",
"control.cpp",
"interval.ts",
"gcstats.ts",
"console.ts",
"game.ts",
"led.cpp",
@ -50,18 +54,50 @@
"trig.cpp",
"fixed.ts",
"templates.ts",
"sendbuffer.s",
"light.cpp",
"parts/speaker.svg",
"parts/headphone.svg",
"parts/dcmotor.svg",
"_locales/de/core-jsdoc-strings.json",
"_locales/de/core-strings.json"
],
"testFiles": [],
"public": true,
"dependencies": {},
"dalDTS": {
"compileServiceVariant": "mbcodal",
"includeDirs": [
"libraries/codal-core/inc",
"libraries/codal-microbit/inc",
"libraries/codal-microbit/model",
"libraries/codal-microbit/inc/compat",
"pxtapp"
],
"excludePrefix": [
"USB_",
"REQUEST_",
"LIS3DH_",
"FXOS8700_",
"MMA8",
"LSM303_",
"MAG_",
"MPU6050_",
"REF_TAG_",
"HF2_",
"PXT_REF_TAG_",
"MS_",
"SCSI_"
]
},
"yotta": {
"config": {
"microbit-dal": {
"fiber_user_data": 1
}
},
"optionalConfig": {
"microbit-dal": {
"fiber_user_data": 1,
"bluetooth": {
"private_addressing": 0,
"advertising_timeout": 0,

View File

@ -19,6 +19,18 @@ void debuglog(const char *format, ...);
#define GC_BLOCK_SIZE 256
#define NON_GC_HEAP_RESERVATION 1024
#ifdef CODAL_CONFIG_H
#define MICROBIT_CODAL 1
#else
#define MICROBIT_CODAL 0
#endif
#if !MICROBIT_CODAL
#undef DMESG
#define DMESG NOLOG
#endif
#undef BYTES_TO_WORDS
#endif

View File

@ -166,17 +166,17 @@
"target": {
"pinInstantiationIdx": 0
},
"style": "solder",
"style": "croc",
"orientation": "+Z"
},
{
"target": "threeVolt",
"style": "solder",
"style": "croc",
"orientation": "+Z"
},
{
"target": "ground",
"style": "solder",
"style": "croc",
"orientation": "+Z"
}
],

48
libs/core/sendbuffer.s Normal file
View File

@ -0,0 +1,48 @@
.syntax unified
.section .text.neopixel_send_buffer_core
.global neopixel_send_buffer_core
neopixel_send_buffer_core:
push {r4,r5,r6,r7,lr}
mov r4, r1 // ptr
mov r5, r2 // len
ldr r0, [r0, #8] // get mbed DigitalOut from MicroBitPin
ldr r1, [r0, #4] // r1-mask for this pin
ldr r2, [r0, #16] // r2-clraddr
ldr r3, [r0, #12] // r3-setaddr
b .start
.nextbit: // C0
str r1, [r3, #0] // pin := hi C2
tst r6, r0 // C3
bne .islate // C4
str r1, [r2, #0] // pin := lo C6
.islate:
lsrs r6, r6, #1 // r6 >>= 1 C7
bne .justbit // C8
// not just a bit - need new byte
adds r4, #1 // r4++ C9
subs r5, #1 // r5-- C10
bcc .stop // if (r5<0) goto .stop C11
.start:
movs r6, #0x80 // reset mask C12
nop // C13
.common: // C13
str r1, [r2, #0] // pin := lo C15
// always re-load byte - it just fits with the cycles better this way
ldrb r0, [r4, #0] // r0 := *r4 C17
b .nextbit // C20
.justbit: // C10
// no nops, branch taken is already 3 cycles
b .common // C13
.stop:
str r1, [r2, #0] // pin := lo
pop {r4,r5,r6,r7,pc}

View File

@ -3,6 +3,7 @@
#define MICROBIT_SERIAL_READ_BUFFER_LENGTH 64
// make sure USB_TX and USB_RX don't overlap with other pin ids
// also, 1001,1002 need to be kept in sync with getPin() function
enum SerialPin {
P0 = MICROBIT_ID_IO_P12,
P1 = MICROBIT_ID_IO_P0,
@ -39,21 +40,6 @@ enum BaudRate {
BaudRate1200 = 1200
};
enum Delimiters {
//% block="new line"
NewLine = 1,
//% block=","
Comma = 2,
//% block="$"
Dollar = 3,
//% block=":"
Colon = 4,
//% block="."
Fullstop = 5,
//% block="#"
Hash = 6,
};
//% weight=2 color=#002050 icon="\uf287"
//% advanced=true
namespace serial {
@ -142,12 +128,14 @@ namespace serial {
bool tryResolvePin(SerialPin p, PinName& name) {
switch(p) {
#if !MICROBIT_CODAL
case SerialPin::USB_TX: name = USBTX; return true;
case SerialPin::USB_RX: name = USBRX; return true;
#endif
default:
auto pin = getPin(p);
if (NULL != pin) {
name = pin->name;
name = (PinName)pin->name;
return true;
}
}
@ -170,21 +158,49 @@ namespace serial {
//% rx.fieldOptions.tooltips="false"
//% blockGap=8
void redirect(SerialPin tx, SerialPin rx, BaudRate rate) {
#if MICROBIT_CODAL
if (getPin(tx) && getPin(rx))
uBit.serial.redirect(*getPin(tx), *getPin(rx));
uBit.serial.setBaud(rate);
#else
PinName txn;
PinName rxn;
if (tryResolvePin(tx, txn) && tryResolvePin(rx, rxn))
uBit.serial.redirect(txn, rxn);
uBit.serial.baud((int)rate);
#endif
}
/**
Set the baud rate of the serial port
*/
//% weight=10
//% blockId=serial_setbaudrate block="serial|set baud rate %rate"
//% blockGap=8 inlineInputMode=inline
//% help=serial/set-baud-rate
//% group="Configuration" advanced=true
void setBaudRate(BaudRate rate) {
#if MICROBIT_CODAL
uBit.serial.setBaud(rate);
#else
uBit.serial.baud((int)rate);
#endif
}
/**
* Direct the serial input and output to use the USB connection.
*/
//% weight=9 help=serial/redirect-to-usb
//% blockId=serial_redirect_to_usb block="serial|redirect to USB"
void redirectToUSB() {
#if MICROBIT_CODAL
uBit.serial.redirect(uBit.io.usbTx, uBit.io.usbRx);
uBit.serial.setBaud(115200);
#else
uBit.serial.redirect(USBTX, USBRX);
uBit.serial.baud(115200);
#endif
}
/**

View File

@ -1,3 +1,28 @@
const enum Delimiters {
//% block="new line (\n)"
NewLine = 10,
//% block=","
Comma = 44,
//% block="$"
Dollar = 36,
//% block=":"
Colon = 58,
//% block="."
Fullstop = 46,
//% block="#"
Hash = 35,
//% block="carriage return (\r)"
CarriageReturn = 13,
//% block="space"
Space = 32,
//% block="tab (\t)"
Tab = 9,
//% block="|"
Pipe = 124,
//% block=";"
SemiColon = 59,
}
/**
* Reading and writing data over a serial connection.
*/
@ -8,6 +33,7 @@ namespace serial {
* The string used to mark a new line, default is \r\n
*/
export let NEW_LINE = "\r\n";
export let NEW_LINE_DELIMITER: Delimiters = Delimiters.NewLine;
let writeLinePadding = 32;
/**
@ -89,7 +115,7 @@ namespace serial {
//% blockId=serial_read_line block="serial|read line"
//% weight=20 blockGap=8
export function readLine(): string {
return serial.readUntil(delimiters(Delimiters.NewLine));
return serial.readUntil(delimiters(NEW_LINE_DELIMITER));
}
/**
@ -98,17 +124,6 @@ namespace serial {
//% blockId="serial_delimiter_conv" block="%del"
//% weight=1 blockHidden=true
export function delimiters(del: Delimiters): string {
// even though it might not look like, this is more
// (memory) efficient than the C++ implementation, because the
// strings are statically allocated and take no RAM
switch (del) {
case Delimiters.NewLine: return "\n"
case Delimiters.Comma: return ","
case Delimiters.Dollar: return "$"
case Delimiters.Colon: return ":"
case Delimiters.Fullstop: return "."
case Delimiters.Hash: return "#"
default: return "\n"
}
return String.fromCharCode(del as number);
}
}

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

@ -344,7 +344,7 @@ declare namespace input {
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8
//% parts="compass"
//% advanced=true shim=input::magneticForce
function magneticForce(dimension: Dimension): int32;
function magneticForce(dimension: Dimension): number;
/**
* Obsolete, compass calibration is automatic.
@ -453,6 +453,7 @@ declare namespace control {
* Make a friendly name for the device based on its serial number
*/
//% blockId="control_device_name" block="device name" weight=10 blockGap=8
//% help=control/device-name
//% advanced=true shim=control::deviceName
function deviceName(): string;
@ -460,6 +461,7 @@ declare 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
//% help=control/device-serial-number
//% advanced=true shim=control::deviceSerialNumber
function deviceSerialNumber(): int32;
@ -521,16 +523,17 @@ declare namespace led {
function unplot(x: int32, y: int32): void;
/**
* Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.
* Get the brightness state of the specified LED using x, y coordinates. (0,0) is upper left.
* @param x the horizontal coordinate of the LED
* @param y the vertical coordinate of the LED
*/
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y"
//% help=led/point-brightness weight=76
//% blockId=device_point_brightness block="point|x %x|y %y brightness"
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1 shim=led::point
function point(x: int32, y: int32): boolean;
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
//% advanced=true shim=led::pointBrightness
function pointBrightness(x: int32, y: int32): int32;
/**
* Get the screen brightness from 0 (off) to 255 (full bright).
@ -642,7 +645,7 @@ declare namespace pins {
//% 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" shim=pins::digitalReadPin
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::digitalReadPin
function digitalReadPin(name: DigitalPin): int32;
/**
@ -654,12 +657,12 @@ declare namespace pins {
//% 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
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" shim=pins::digitalWritePin
function digitalWritePin(name: DigitalPin, value: int32): void;
/**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name of pin to read from, eg: AnalogPin.P1
* @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"
@ -669,7 +672,7 @@ declare namespace pins {
/**
* Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name of pin to write to, eg: AnalogPin.P1
* @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
@ -682,7 +685,7 @@ declare namespace pins {
/**
* Configure the pulse-width modulation (PWM) period of the analog output in microseconds.
* 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, eg: AnalogPin.P1
* @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
@ -699,7 +702,7 @@ declare namespace pins {
//% help=pins/on-pulsed weight=22 blockGap=16 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
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" shim=pins::onPulsed
function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void;
/**
@ -720,12 +723,12 @@ declare namespace pins {
//% 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
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="250" maxDuration.defl=2000000 shim=pins::pulseIn
function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: int32): int32;
/**
* Write 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, eg: AnalogPin.P1
* @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
@ -764,7 +767,23 @@ declare namespace pins {
function analogSetPitchPin(name: AnalogPin): void;
/**
* Emit a pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* Sets the volume on the pitch pin
* @param volume the intensity of the sound from 0..255
*/
//% blockId=device_analog_set_pitch_volume block="analog set pitch volume $volume"
//% help=pins/analog-set-pitch-volume weight=3 advanced=true
//% volume.min=0 volume.max=255 shim=pins::analogSetPitchVolume
function analogSetPitchVolume(volume: int32): void;
/**
* Gets the volume the pitch pin from 0..255
*/
//% blockId=device_analog_pitch_volume block="analog pitch volume"
//% help=pins/analog-pitch-volume weight=3 advanced=true shim=pins::analogPitchVolume
function analogPitchVolume(): int32;
/**
* Emit a plse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* @param frequency frequency to modulate in Hz.
* @param ms duration of the pitch in milli seconds.
*/
@ -773,14 +792,14 @@ declare namespace pins {
function analogPitch(frequency: int32, ms: int32): void;
/**
* Configure the pull direction of of a pin.
* Configure the pull directiion of of a pin.
* @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 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
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" shim=pins::setPull
function setPull(name: DigitalPin, pull: PinPullMode): void;
/**
@ -792,7 +811,7 @@ declare 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" shim=pins::setEvents
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250" shim=pins::setEvents
function setEvents(name: DigitalPin, type: PinEventType): void;
/**
@ -822,6 +841,14 @@ declare namespace pins {
//% blockId=spi_write block="spi write %value" shim=pins::spiWrite
function spiWrite(value: int32): int32;
/**
* Write to and read from the SPI slave at the same time
* @param command Data to be sent to the SPI slave (can be null)
* @param response Data received from the SPI slave (can be null)
*/
//% help=pins/spi-transfer argsNullable shim=pins::spiTransfer
function spiTransfer(command: Buffer, response: Buffer): void;
/**
* Set the SPI frequency
* @param frequency the clock frequency, eg: 1000000
@ -852,6 +879,12 @@ declare namespace pins {
//% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4
//% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="250" shim=pins::spiPins
function spiPins(mosi: DigitalPin, miso: DigitalPin, sck: DigitalPin): void;
/**
* Mounts a push button on the given pin
*/
//% help=pins/push-button advanced=true shim=pins::pushButton
function pushButton(pin: DigitalPin): void;
}
@ -926,6 +959,16 @@ declare namespace serial {
//% blockGap=8 shim=serial::redirect
function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void;
/**
Set the baud rate of the serial port
*/
//% weight=10
//% blockId=serial_setbaudrate block="serial|set baud rate %rate"
//% blockGap=8 inlineInputMode=inline
//% help=serial/set-baud-rate
//% group="Configuration" advanced=true shim=serial::setBaudRate
function setBaudRate(rate: BaudRate): void;
/**
* Direct the serial input and output to use the USB connection.
*/
@ -1039,6 +1082,12 @@ declare interface Buffer {
*/
//% shim=BufferMethods::write
write(dstOffset: int32, src: Buffer): void;
/**
* Compute k-bit FNV-1 non-cryptographic hash of the buffer.
*/
//% shim=BufferMethods::hash
hash(bits: int32): uint32;
}
declare namespace control {
@ -1056,5 +1105,21 @@ declare namespace control {
//% deprecated=1 shim=control::createBufferFromUTF8
function createBufferFromUTF8(str: string): Buffer;
}
declare namespace light {
/**
* Sends a color buffer to a light strip
**/
//% advanced=true
//% shim=light::sendWS2812Buffer
function sendWS2812Buffer(buf: Buffer, pin: int32): void;
/**
* Sets the light mode of a pin
**/
//% advanced=true
//% shim=light::setMode
function setMode(pin: int32, mode: int32): void;
}
// Auto-generated. Do not edit. Really.