fetch pxt-microbit v2.2.30 (#102)
* undo buttonEvent * fetch microbit v2.2.30 Co-authored-by: Amerlander <gitkraken@juriwolf.de>
This commit is contained in:
@ -89,8 +89,8 @@
|
||||
"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",
|
||||
"Gesture.ScreenDown": "Raised when the screen is pointing up and the board is horizontal",
|
||||
"Gesture.ScreenUp": "Raised when the screen is pointing down and the board is horizontal",
|
||||
"Gesture.ScreenDown": "Raised when the screen is pointing down and the board is horizontal",
|
||||
"Gesture.ScreenUp": "Raised when the screen is pointing up and the board is horizontal",
|
||||
"Gesture.Shake": "Raised when shaken",
|
||||
"Gesture.SixG": "Raised when a 6G shock is detected",
|
||||
"Gesture.ThreeG": "Raised when a 3G shock is detected",
|
||||
@ -273,6 +273,8 @@
|
||||
"control.eventValue": "Gets the value of the last event executed on the bus",
|
||||
"control.eventValueId": "Returns the value of a C++ runtime constant",
|
||||
"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.",
|
||||
"control.onEvent": "Registers an event handler.",
|
||||
"control.panic": "Display specified error code and stop the program.",
|
||||
"control.raiseEvent": "Raises an event in the event bus.",
|
||||
@ -281,6 +283,7 @@
|
||||
"control.raiseEvent|param|value": "Component specific code indicating the cause of the event.",
|
||||
"control.reset": "Resets the BBC micro:bit.",
|
||||
"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",
|
||||
@ -467,9 +470,13 @@
|
||||
"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.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 \"",
|
||||
"music.playMelody|param|tempo": "- number in beats per minute (bpm), dictating how long each note will play for",
|
||||
"music.playTone": "Plays a tone through pin ``P0`` for the given duration.",
|
||||
"music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz), eg: Note.C",
|
||||
"music.playTone|param|ms": "tone duration in milliseconds (ms)",
|
||||
|
@ -79,9 +79,9 @@
|
||||
"Gesture.LogoDown|block": "logo down",
|
||||
"Gesture.LogoUp": "Raised when the logo is upward and the screen is vertical",
|
||||
"Gesture.LogoUp|block": "logo up",
|
||||
"Gesture.ScreenDown": "Raised when the screen is pointing up and the board is horizontal",
|
||||
"Gesture.ScreenDown": "Raised when the screen is pointing down and the board is horizontal",
|
||||
"Gesture.ScreenDown|block": "screen down",
|
||||
"Gesture.ScreenUp": "Raised when the screen is pointing down and the board is horizontal",
|
||||
"Gesture.ScreenUp": "Raised when the screen is pointing up and the board is horizontal",
|
||||
"Gesture.ScreenUp|block": "screen up",
|
||||
"Gesture.Shake": "Raised when shaken",
|
||||
"Gesture.Shake|block": "shake",
|
||||
@ -262,9 +262,11 @@
|
||||
"control.eventValueId|block": "%id",
|
||||
"control.eventValue|block": "event value",
|
||||
"control.inBackground|block": "run in background",
|
||||
"control.millis|block": "millis (ms)",
|
||||
"control.onEvent|block": "on event|from %src=control_event_source_id|with value %value=control_event_value_id",
|
||||
"control.raiseEvent|block": "raise event|from source %src=control_event_source_id|with value %value=control_event_value_id",
|
||||
"control.reset|block": "reset",
|
||||
"control.waitForEvent|block": "wait for event|from %src|with value %value",
|
||||
"control.waitMicros|block": "wait (µs)%micros",
|
||||
"control|block": "control",
|
||||
"convertToText|block": "convert $value=math_number to text",
|
||||
@ -338,8 +340,10 @@
|
||||
"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",
|
||||
"music.noteFrequency|block": "%name",
|
||||
"music.onEvent|block": "music on %value",
|
||||
"music.playMelody|block": "play melody $melody at tempo $tempo|(bpm)",
|
||||
"music.playTone|block": "play|tone %note=device_note|for %duration=device_beat",
|
||||
"music.rest|block": "rest(ms)|%duration=device_beat",
|
||||
"music.ringTone|block": "ring tone (Hz)|%note=device_note",
|
||||
|
@ -223,6 +223,23 @@ namespace control {
|
||||
release_fiber();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of milliseconds elapsed since power on.
|
||||
*/
|
||||
//% help=control/millis weight=50
|
||||
//% blockId=control_running_time block="millis (ms)"
|
||||
int millis() {
|
||||
return system_timer_current_time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current time in microseconds. Overflows every ~18 minutes.
|
||||
*/
|
||||
//%
|
||||
int micros() {
|
||||
return system_timer_current_time_us() & 0x3fffffff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules code that run in the background.
|
||||
*/
|
||||
@ -232,6 +249,15 @@ namespace control {
|
||||
runInParallel(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks the calling thread until the specified event is raised.
|
||||
*/
|
||||
//% help=control/wait-for-event async
|
||||
//% blockId=control_wait_for_event block="wait for event|from %src|with value %value"
|
||||
void waitForEvent(int src, int value) {
|
||||
pxt::waitForEvent(src, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the BBC micro:bit.
|
||||
*/
|
||||
|
4
libs/core/enums.d.ts
vendored
4
libs/core/enums.d.ts
vendored
@ -111,13 +111,13 @@ declare namespace basic {
|
||||
//% jres=gestures.tiltbackwards
|
||||
LogoDown = 2, // MICROBIT_ACCELEROMETER_EVT_TILT_DOWN
|
||||
/**
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
*/
|
||||
//% block="screen up"
|
||||
//% jres=gestures.frontsideup
|
||||
ScreenUp = 5, // MICROBIT_ACCELEROMETER_EVT_FACE_UP
|
||||
/**
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
*/
|
||||
//% block="screen down"
|
||||
//% jres=gestures.backsideup
|
||||
|
@ -75,13 +75,13 @@ enum class Gesture {
|
||||
//% jres=gestures.tiltbackwards
|
||||
LogoDown = MICROBIT_ACCELEROMETER_EVT_TILT_DOWN,
|
||||
/**
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
*/
|
||||
//% block="screen up"
|
||||
//% jres=gestures.frontsideup
|
||||
ScreenUp = MICROBIT_ACCELEROMETER_EVT_FACE_UP,
|
||||
/**
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
*/
|
||||
//% block="screen down"
|
||||
//% jres=gestures.backsideup
|
||||
@ -363,26 +363,6 @@ namespace input {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of milliseconds elapsed since power on.
|
||||
*/
|
||||
//% 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.
|
||||
*/
|
||||
|
@ -55,4 +55,25 @@ namespace input {
|
||||
export function calibrate() {
|
||||
input.calibrateCompass();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of milliseconds elapsed since power on.
|
||||
*/
|
||||
//% help=input/running-time weight=50 blockGap=8
|
||||
//% blockId=device_get_running_time block="running time (ms)"
|
||||
//% advanced=true
|
||||
export function runningTime() {
|
||||
return control.millis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
export function runningTimeMicros() {
|
||||
return control.micros();
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +174,8 @@ enum MusicEvent {
|
||||
*/
|
||||
//% color=#DF4600 weight=98 icon="\uf025"
|
||||
namespace music {
|
||||
const INTERNAL_MELODY_ENDED = 5;
|
||||
|
||||
let beatsPerMinute: number = 120;
|
||||
//% whenUsed
|
||||
const freqs = hex`
|
||||
@ -358,14 +360,69 @@ namespace music {
|
||||
currentBackgroundMelody = null;
|
||||
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.MelodyEnded);
|
||||
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyResumed);
|
||||
control.raiseEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);
|
||||
}
|
||||
}
|
||||
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyEnded : MusicEvent.MelodyEnded);
|
||||
if (!currentMelody.background)
|
||||
control.raiseEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);
|
||||
currentMelody = null;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Play a melody from the melody editor.
|
||||
* @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 "
|
||||
* @param tempo - number in beats per minute (bpm), dictating how long each note will play for
|
||||
*/
|
||||
//% block="play melody $melody at tempo $tempo|(bpm)" blockId=playMelody
|
||||
//% weight=85 blockGap=8 help=music/play-melody
|
||||
//% melody.shadow="melody_editor"
|
||||
//% tempo.min=40 tempo.max=500
|
||||
//% tempo.defl=120
|
||||
//% parts=headphone
|
||||
export function playMelody(melody: string, tempo: number) {
|
||||
melody = melody || "";
|
||||
setTempo(tempo);
|
||||
let notes: string[] = melody.split(" ").filter(n => !!n);
|
||||
let newOctave = false;
|
||||
|
||||
// build melody string, replace '-' with 'R' and add tempo
|
||||
// creates format like "C5-174 B4 A G F E D C "
|
||||
for (let i = 0; i < notes.length; i++) {
|
||||
if (notes[i] === "-") {
|
||||
notes[i] = "R";
|
||||
} else if (notes[i] === "C5") {
|
||||
newOctave = true;
|
||||
} else if (newOctave) { // change the octave if necesary
|
||||
notes[i] += "4";
|
||||
newOctave = false;
|
||||
}
|
||||
}
|
||||
|
||||
music.beginMelody(notes, MelodyOptions.Once)
|
||||
control.waitForEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a melody with the melody editor.
|
||||
* @param melody
|
||||
*/
|
||||
//% block="$melody" blockId=melody_editor
|
||||
//% blockHidden = true
|
||||
//% weight=85 blockGap=8
|
||||
//% duplicateShadowOnDrag
|
||||
//% melody.fieldEditor="melody"
|
||||
//% melody.fieldOptions.decompileLiterals=true
|
||||
//% melody.fieldOptions.decompileIndirectFixedInstances="true"
|
||||
//% melody.fieldOptions.onParentBlock="true"
|
||||
//% shim=TD_ID
|
||||
export function melodyEditor(melody: string): string {
|
||||
return melody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the melodies
|
||||
* @param options which melody to stop
|
||||
|
36
libs/core/shims.d.ts
vendored
36
libs/core/shims.d.ts
vendored
@ -346,22 +346,6 @@ declare namespace input {
|
||||
//% advanced=true shim=input::magneticForce
|
||||
function magneticForce(dimension: Dimension): int32;
|
||||
|
||||
/**
|
||||
* Gets the number of milliseconds elapsed since power on.
|
||||
*/
|
||||
//% help=input/running-time weight=50 blockGap=8
|
||||
//% blockId=device_get_running_time block="running time (ms)"
|
||||
//% advanced=true shim=input::runningTime
|
||||
function runningTime(): int32;
|
||||
|
||||
/**
|
||||
* 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(): int32;
|
||||
|
||||
/**
|
||||
* Obsolete, compass calibration is automatic.
|
||||
*/
|
||||
@ -388,6 +372,19 @@ declare namespace input {
|
||||
//% advanced=true
|
||||
declare namespace control {
|
||||
|
||||
/**
|
||||
* Gets the number of milliseconds elapsed since power on.
|
||||
*/
|
||||
//% help=control/millis weight=50
|
||||
//% blockId=control_running_time block="millis (ms)" shim=control::millis
|
||||
function millis(): int32;
|
||||
|
||||
/**
|
||||
* Gets current time in microseconds. Overflows every ~18 minutes.
|
||||
*/
|
||||
//% shim=control::micros
|
||||
function micros(): int32;
|
||||
|
||||
/**
|
||||
* Schedules code that run in the background.
|
||||
*/
|
||||
@ -395,6 +392,13 @@ declare namespace control {
|
||||
//% blockId="control_in_background" block="run in background" blockGap=8 shim=control::inBackground
|
||||
function inBackground(a: () => void): void;
|
||||
|
||||
/**
|
||||
* Blocks the calling thread until the specified event is raised.
|
||||
*/
|
||||
//% help=control/wait-for-event async
|
||||
//% blockId=control_wait_for_event block="wait for event|from %src|with value %value" shim=control::waitForEvent
|
||||
function waitForEvent(src: int32, value: int32): void;
|
||||
|
||||
/**
|
||||
* Resets the BBC micro:bit.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user