初始化提交

This commit is contained in:
王立帮
2024-07-19 10:16:00 +08:00
parent 4c7b571f20
commit 4a2d56dcc4
7084 changed files with 741212 additions and 63 deletions

View File

@@ -0,0 +1,653 @@
import * as Blockly from 'blockly/core';
const ACTUATOR_HUE = 100; //'#b574c2';
export const microbit_music_play_built_in = {
init: function () {
this.jsonInit({
"colour": ACTUATOR_HUE,
"nextStatement": null,
"previousStatement": null,
"inputsInline": true,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/music.html#built-in-melodies",
"message0": Blockly.Msg.MIXLY_MICROBIT_Play_built_in_melody,
"args0": [{
"name": "melody",
"options": [["DADADADUM", "DADADADUM"], ["ENTERTAINER", "ENTERTAINER"], ["PRELUDE", "PRELUDE"], ["ODE", "ODE"], ["NYAN", "NYAN"], ["RINGTONE", "RINGTONE"], ["FUNK", "FUNK"], ["BLUES", "BLUES"], ["BIRTHDAY", "BIRTHDAY"], ["WEDDING", "WEDDING"], ["FUNERAL", "FUNERAL"], ["PUNCHLINE", "PUNCHLINE"], ["PYTHON", "PYTHON"], ["BADDY", "BADDY"], ["CHASE", "CHASE"], ["BA_DING", "BA_DING"], ["WAWAWAWAA", "WAWAWAWAA"], ["JUMP_UP", "JUMP_UP"], ["JUMP_DOWN", "JUMP_DOWN"], ["POWER_UP", "POWER_UP"], ["POWER_DOWN", "POWER_DOWN"]],
"type": "field_dropdown"
}, {
// "check" : "Number",
"type": "input_value",
"name": "PIN"
}, {
"type": "input_dummy"
}, {
"checked": true,
"type": "field_checkbox",
"name": "wait"
}, {
"type": "input_dummy"
}, {
"checked": false,
"type": "field_checkbox",
"name": "loop"
}
]
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Play_built_in_melody1);
}
};
export const microbit_music_play_built_in_easy = {
init: function () {
this.jsonInit({
"colour": ACTUATOR_HUE,
"nextStatement": null,
"previousStatement": null,
"inputsInline": true,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/music.html#built-in-melodies",
"tooltip": "Play one of the built-in melodies. Indicate if you need to wait before continuing or continuously loop the melody.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Play_built_in_melody_easy,
"args0": [{
"name": "melody",
"options": [["DADADADUM", "DADADADUM"], ["ENTERTAINER", "ENTERTAINER"], ["PRELUDE", "PRELUDE"], ["ODE", "ODE"], ["NYAN", "NYAN"], ["RINGTONE", "RINGTONE"], ["FUNK", "FUNK"], ["BLUES", "BLUES"], ["BIRTHDAY", "BIRTHDAY"], ["WEDDING", "WEDDING"], ["FUNERAL", "FUNERAL"], ["PUNCHLINE", "PUNCHLINE"], ["PYTHON", "PYTHON"], ["BADDY", "BADDY"], ["CHASE", "CHASE"], ["BA_DING", "BA_DING"], ["WAWAWAWAA", "WAWAWAWAA"], ["JUMP_UP", "JUMP_UP"], ["JUMP_DOWN", "JUMP_DOWN"], ["POWER_UP", "POWER_UP"], ["POWER_DOWN", "POWER_DOWN"]],
"type": "field_dropdown"
}, {
// "check" : "Number",
"type": "input_value",
"name": "PIN"
}, {
"type": "input_dummy"
}
]
});
}
};
export const microbit_music_pitch_delay = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_TONE)
.appendField(Blockly.Msg.MIXLY_PIN)
.setCheck(Number);
this.appendValueInput('pitch')
.setCheck(Number)
//.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_FREQUENCY);
this.appendValueInput('duration')
.setCheck(Number)
//.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_DURATION);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MILLIS)
.appendField(Blockly.Msg.MIXLY_MICROBIT_WAIT);
this.appendDummyInput("")
.appendField(new Blockly.FieldCheckbox(true), 'wait');
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_TONE2);
}
};
export const microbit_music_pitch = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_TONE)
.appendField(Blockly.Msg.MIXLY_PIN)
.setCheck(Number);
this.appendValueInput('pitch')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_FREQUENCY);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_TONE);
}
};
export const microbit_music_play_list_of_notes = {
init: function () {
this.jsonInit({
"colour": ACTUATOR_HUE,
"nextStatement": null,
"previousStatement": null,
"inputsInline": true,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/music.html#musical-notation",
"message0": Blockly.Msg.MIXLY_MICROBIT_Play_notes,
"args0": [{
"check": "List",
"type": "input_value",
"name": "notes"
}, {
"type": "input_value",
"name": "PIN"
}, {
"checked": true,
"type": "field_checkbox",
"name": "wait"
}, {
"type": "input_dummy"
}, {
"checked": false,
"type": "field_checkbox",
"name": "loop"
}
]
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Play_notes1);
}
};
export const microbit_music_play_list_of_notes_easy = {
init: function () {
this.jsonInit({
"colour": ACTUATOR_HUE,
"nextStatement": null,
"previousStatement": null,
"inputsInline": true,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/music.html#musical-notation",
"tooltip": "Play a list of notes expressed in the special music language. Indicate if you need to wait before continuing or continuously loop the melody.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Play_notes,
"args0": [{
"check": "List",
"type": "input_value",
"name": "notes"
}, {
"type": "input_value",
"name": "PIN"
}, {
"type": "input_dummy"
}, {
"type": "input_dummy"
}, {
"type": "input_dummy"
}
]
});
}
};
export const microbit_music_reset = {
init: function () {
this.jsonInit({
"colour": ACTUATOR_HUE,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/music.html#music.reset",
"message0": Blockly.Msg.MIXLY_MICROBIT_Reset_music
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Reset_music);
}
};
//
export const microbit_music_stop = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput("PIN")
.appendField(Blockly.Msg.MIXLY_NOTONE)
.appendField(Blockly.Msg.MIXLY_PIN);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_NOTONE);
}
};
export const microbit_music_get_tempo = {
init: function () {
this.jsonInit({
"colour": ACTUATOR_HUE,
"output": "Array",
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/music.html#music.get_tempo",
"message0": Blockly.Msg.MIXLY_MICROBIT_Get_current_tempo
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Get_current_tempo);
}
};
export const tone_set_tempo = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('TICKS')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_SET_TEMPO)
.appendField(Blockly.Msg.MICROBIT_ACTUATOR_ticks);
this.appendValueInput('BPM')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_SPEED);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_SET_TEMPO1);
}
}
export const speech_say = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('VAR')
.setCheck(String)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_SAY, 'say'], [Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_SING, 'sing'], [Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_PRENOUNCE,
'pronounce']]), "MODE");
this.appendValueInput('pitch')
.setCheck(Number)
.appendField(Blockly.Msg.MICROBIT_SPEECH_pitch);
this.appendValueInput('speed')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_SPEED);
this.appendValueInput('mouth')
.setCheck(Number)
.appendField(Blockly.Msg.MICROBIT_SPEECH_mouth);
this.appendValueInput('throat')
.setCheck(Number)
.appendField(Blockly.Msg.MICROBIT_SPEECH_throat);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('MODE');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH;
var mode1 = Blockly.Msg.MIXLY_MICROBIT_TYPE_STRING
var TOOLTIPS = {
'say': Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_SAY,
'sing': Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_SING,
'pronounce': Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_PRENOUNCE
};
return mode0 + TOOLTIPS[mode] + mode1;
});
}
};
// export const speech_sing = {
// init: function () {
// this.setColour(ACTUATOR_HUE);
// this.appendValueInput('VAR')
// .setCheck(String)
// .appendField(Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_SING);
// this.appendValueInput('pitch')
// .setCheck(Number)
// .appendField(Blockly.Msg.MICROBIT_SPEECH_pitch);
// this.appendValueInput('speed')
// .setCheck(Number)
// .appendField(Blockly.Msg.MIXLY_SPEED);
// this.appendValueInput('mouth')
// .setCheck(Number)
// .appendField(Blockly.Msg.MICROBIT_SPEECH_mouth);
// this.appendValueInput('throat')
// .setCheck(Number)
// .appendField(Blockly.Msg.MICROBIT_SPEECH_throat);
// this.setPreviousStatement(true);
// this.setNextStatement(true);
// this.setInputsInline(true);
// }
// };
// export const speech_prenounce = {
// init: function () {
// this.setColour(ACTUATOR_HUE);
// this.appendValueInput('VAR')
// .setCheck(String)
// .appendField(Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_PRENOUNCE);
// this.appendValueInput('pitch')
// .setCheck(Number)
// .appendField(Blockly.Msg.MICROBIT_SPEECH_pitch);
// this.appendValueInput('speed')
// .setCheck(Number)
// .appendField(Blockly.Msg.MIXLY_SPEED);
// this.appendValueInput('mouth')
// .setCheck(Number)
// .appendField(Blockly.Msg.MICROBIT_SPEECH_mouth);
// this.appendValueInput('throat')
// .setCheck(Number)
// .appendField(Blockly.Msg.MICROBIT_SPEECH_throat);
// this.setPreviousStatement(true);
// this.setNextStatement(true);
// this.setInputsInline(true);
// }
// };
export const speech_say_easy = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('VAR')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_SAY);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
}
};
export const speech_sing_easy = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('VAR')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_SING);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
}
};
export const speech_pronounce_easy = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('VAR')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_ACTUATOR_SPEECH_PRENOUNCE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
}
};
export const speech_translate = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('VAR')
.setCheck(String)
.appendField(Blockly.Msg.MICROBIT_SPEECH_translation);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_MICROPYTHON_SOCKET_MAKE + Blockly.Msg.MIXLY_MICROBIT_TYPE_STRING + Blockly.Msg.MICROBIT_SPEECH_translation);
}
};
export const servo_move = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_SERVO)
.appendField(Blockly.Msg.MIXLY_PIN)
.setCheck(Number);
this.appendValueInput("DEGREE", Number)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_DEGREE_0_180);
// this.appendValueInput("DELAY_TIME", Number)
// .setCheck(Number)
// .setAlign(Blockly.inputs.Align.RIGHT)
// .appendField(Blockly.Msg.MIXLY_DELAY+'('+Blockly.Msg.MIXLY_MILLIS+')');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_SERVO_MOVE);
}
};
export const bit_motor_control = {
init: function () {
this.appendValueInput("speed")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_MOTOR)
.appendField(new Blockly.FieldDropdown([["M1", "1"], ["M2", "2"], ["M3", "3"], ["M4", "4"]]), "Motor")
.appendField(Blockly.Msg.MIXLY_SPEED);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([["Forward", "1*"], ["Reverse", "-1*"]]), "mode");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(ACTUATOR_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//RGB
export const display_rgb_init = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RGB)
this.appendValueInput("PIN", Number)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("LEDCOUNT")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_COUNT);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_RGB_PIN_COUNT);
}
};
export const display_rgb = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RGB)
// this.appendValueInput("PIN", Number)
// .setCheck(Number)
// .setAlign(Blockly.inputs.Align.RIGHT)
// .appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("_LED_")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_NUM);
this.appendValueInput("RVALUE")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_R);
this.appendValueInput("GVALUE")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_G);
this.appendValueInput("BVALUE")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_B);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('');
this.setTooltip(Blockly.Msg.MIXLY_RGB_NUM_R_G_B);
}
};
export const display_rgb2 = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RGB)
// this.appendValueInput("PIN", Number)
// .setCheck(Number)
// .setAlign(Blockly.inputs.Align.RIGHT)
// .appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("_LED_")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_NUM);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldColour("#ff0000"), "RGB_LED_COLOR");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
export const display_rgb_show = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RGB)
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_RGB_WRITE)
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('');
this.setTooltip(Blockly.Msg.MIXLY_ESP32_MUSIC_WRI);
}
};
export const MP3_INIT = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_SETUP + ' ' + Blockly.Msg.QJ00X_MP3);
this.appendValueInput("RX")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("RX#");
this.appendValueInput("TX")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("TX#");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
//MP3播放控制
var MP3_CONTROL_TYPE = [
[Blockly.Msg.MIXLY_MP3_PLAY, "play"],
[Blockly.Msg.MIXLY_MP3_PAUSE, "pause"],
[Blockly.Msg.MIXLY_MP3_NEXT, "next_track"],
[Blockly.Msg.MIXLY_MP3_PREV, "prev_track"],
[Blockly.Msg.MIXLY_MP3_VOL_UP, "inc_vol"],
[Blockly.Msg.MIXLY_MP3_VOL_DOWN, "dec_vol"]
];
//MP3模块
export const MP3_CONTROL = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.QJ00X_MP3);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_STAT)
.appendField(new Blockly.FieldDropdown(MP3_CONTROL_TYPE), "CONTROL_TYPE");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
//MP3循环模式
var MP3_LOOP_MODE_OPTIONS = [
[Blockly.Msg.MIXLY_MP3_LOOP_ALL, "0"],
[Blockly.Msg.MIXLY_MP3_LOOP_FOLDER, "1"],
[Blockly.Msg.MIXLY_MP3_LOOP_ONE, "2"],
[Blockly.Msg.MIXLY_MP3_LOOP_RAM, "3"]
];
//MP3模块循环模式
export const MP3_LOOP_MODE = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.QJ00X_MP3);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MP3_LOOP_MODE)
.appendField(Blockly.Msg.MIXLY_STAT)
.appendField(new Blockly.FieldDropdown(MP3_LOOP_MODE_OPTIONS), "LOOP_MODE");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
//MP3 设置EQ
var MP3_EQ_MODE_OPTIONS = [
[Blockly.Msg.MIXLY_MP3_EQ_NORMAL, "0"],
[Blockly.Msg.MIXLY_MP3_EQ_POP, "1"],
[Blockly.Msg.MIXLY_MP3_EQ_ROCK, "2"],
[Blockly.Msg.MIXLY_MP3_EQ_JAZZ, "3"],
[Blockly.Msg.MIXLY_MP3_EQ_CLASSIC, "4"],
[Blockly.Msg.MIXLY_MP3_EQ_BASS, "5"]
];
//MP3模块EQ模式
export const MP3_EQ_MODE = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.QJ00X_MP3);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MP3_EQ_MODE)
.appendField(Blockly.Msg.MIXLY_STAT)
.appendField(new Blockly.FieldDropdown(MP3_EQ_MODE_OPTIONS), "EQ_MODE");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
//MP3模块设置音量
export const MP3_VOL = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.QJ00X_MP3);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MP3_VOL);
this.appendValueInput("vol", Number)
.appendField(Blockly.Msg.MIXLY_STAT)
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
//MP3模块播放第N首
export const MP3_PLAY_NUM = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.QJ00X_MP3);
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_MP3_PLAY_NUM)
.setCheck(Number);
this.appendDummyInput("")
.appendField("首");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
export const MP3_PLAY_FOLDER = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.QJ00X_MP3);
this.appendValueInput("FOLDER", Number)
.appendField(Blockly.Msg.DFPLAYER_MINI_FOLDER)
.setCheck(Number);
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_MP3_PLAY_NUM)
.setCheck(Number);
this.appendDummyInput("")
.appendField("首");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};

View File

@@ -0,0 +1,307 @@
import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';
const COMMUNICATE_HUE = 140; //'#3288dd';
export const radio_ons = {
init: function () {
this.setColour(225);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_PY_COMMUNICATE_ON, 'on'], [Blockly.Msg.MIXLY_MICROBIT_PY_COMMUNICATE_OFF, 'off'], [Blockly.Msg.HTML_RESET, 'reset']]), "type")
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_COMMUNICATE_WIFI);
this.setInputsInline(true);
this.setOutput(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('type');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_PY_COMMUNICATE_WIFI;
var TOOLTIPS = {
'on': Blockly.Msg.MIXLY_MICROBIT_PY_COMMUNICATE_ON,
'off': Blockly.Msg.MIXLY_MICROBIT_PY_COMMUNICATE_OFF,
'reset': Blockly.Blockly.Msg.HTML_RESET
};
return TOOLTIPS[mode] + mode0;
});
}
};
export const microbit_radio_on = {
init: function () {
this.jsonInit({
"colour": 225,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/radio.html#radio.on",
"tooltip": "Turn on the radio. This needs to be explicitly called since the radio draws power and takes up memory that you may otherwise need.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Switch_on_radio
});
}
};
export const microbit_radio_off = {
init: function () {
this.jsonInit({
"colour": 225,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/radio.html#radio.off",
"tooltip": "Turn off the radio, thus saving power and memory.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Switch_off_radio
});
}
};
export const microbit_radio_config = {
init: function () {
this.jsonInit({
"colour": 225,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/radio.html#radio.config",
"tooltip": Blockly.Msg.MIXLY_MICROBIT_Configure_radio1,
"message0": Blockly.Msg.MIXLY_MICROBIT_Configure_radio,
"args0": [{
"min": 4,
"value": 32,
"type": "input_value",
"max": 251,
"name": "length"
}, {
"type": "input_dummy"
}, {
"min": 1,
"value": 3,
"type": "input_value",
"max": 32,
"name": "queue"
}, {
"type": "input_dummy"
}, {
"min": 0,
"value": 7,
"type": "input_value",
"max": 100,
"name": "channel"
}, {
"type": "input_dummy"
}, {
"name": "power",
"type": "input_value"
}, {
"type": "input_dummy"
}, {
"name": "address",
"type": "input_value"
}, {
"type": "input_dummy"
}, {
"name": "group",
"type": "input_value"
}, {
"type": "input_dummy"
}, {
"name": "data_rate",
"type": "input_value"
}
]
});
}
};
export const microbit_radio_reset = {
init: function () {
this.jsonInit({
"colour": 225,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/radio.html#radio.reset",
"tooltip": "Reset the radio to default settings.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Reset_radio
});
}
};
export const microbit_radio_send_string = {
init: function () {
this.jsonInit({
"colour": 225,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/radio.html#radio.send",
"tooltip": "Broadcast a text message.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Send_message,
"args0": [{
"check": "String",
"type": "input_value",
"name": "message"
}
]
});
}
};
export const radio_send_string = {
init: function () {
this.setColour(225);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_RADIO_SEND);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_MICROBIT_MSG, 'send'],
[Blockly.Msg.MIXLY_MICROBIT_MSG_BYTE, 'send_bytes']]), "type")
this.appendValueInput('data')
// .setCheck(String)
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Send_message1);
}
}
export const microbit_radio_receive = {
init: function () {
this.jsonInit({
"colour": 225,
"output": "String",
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/radio.html#radio.receive",
"tooltip": Blockly.Msg.MIXLY_MICROBIT_Receive_message,
"message0": Blockly.Msg.MIXLY_MICROBIT_Receive_message
});
}
};
export const radio_receive_string = {
init: function () {
this.setColour(225);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_Receive_message);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_MICROBIT_MSG, 'receive'],
[Blockly.Msg.MIXLY_MICROBIT_MSG_BYTE, 'receive_bytes'],
[Blockly.Msg.MIXLY_MICROBIT_MSG_FULL, 'receive_full']]), "type")
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Receive_message);
}
}
export const i2c_init = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("RX", Number)
//.appendField(Blockly.Msg.MIXLY_SETUP)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_SETUP)
.appendField("sda")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("TX", Number)
.appendField("scl")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput('freq')
.setCheck(Number)
.appendField("频率")
.setAlign(Blockly.inputs.Align.RIGHT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
}
};
export const i2c_read = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('address')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_READ_ADDRESS);
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_MATH_BYTE);
this.appendDummyInput()
.appendField(Blockly.Msg.CONTROLS_REPEAT_TITLE_REPEAT)
.appendField(new Blockly.FieldCheckbox(false), "is_repeated");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_READ);
}
}
export const i2c_write = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('address')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_WRITE_ADDRESS);
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_VALUE);
this.appendDummyInput()
.appendField(Blockly.Msg.CONTROLS_REPEAT_TITLE_REPEAT)
.appendField(new Blockly.FieldCheckbox(false), "is_repeated");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_WRITE);
}
}
export const spi_init = {
init: function () {
this.jsonInit({
"colour": COMMUNICATE_HUE,
"nextStatement": null,
"previousStatement": null,
"message0": Blockly.Msg.MIXLY_MICROBIT_SPI_INIT,
"args0": [{
"value": 1000000,
"type": "field_number",
"name": "freq"
}, {
"type": "input_dummy"
}, {
"value": 8,
"type": "field_number",
"name": "bits"
}, {
"type": "input_dummy"
}, {
"value": 0,
"type": "field_number",
"name": "mode"
}, {
"type": "input_dummy"
}, {
"name": "mosi",
"options": Profile.default.digital,
"type": "field_dropdown"
}, {
"name": "miso",
"options": Profile.default.digital,
"type": "field_dropdown"
}, {
"name": "sck",
"options": Profile.default.digital,
"type": "field_dropdown"
}
]
});
this.setFieldValue("15", "mosi")
this.setFieldValue("14", "miso")
this.setFieldValue("13", "sck")
}
};
export const spi_write = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_SPI_WRITE);
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_SPI_WRITE);
}
}

View File

@@ -0,0 +1,759 @@
import * as Blockly from 'blockly/core';
const DISPLAY_HUE = 180; //'#cc6688' //180;
// Blockly.FieldColour.COLOURS = ['#f00', '#e00', '#d00', '#c00', '#b00', '#a00',
// '#800', '#600', '#400', '#000'];
// Blockly.FieldColour.COLUMNS = 5;
// var IMG = [["HEART", "HEART"], ["HEART_SMALL", "HEART_SMALL"], ["HAPPY", "HAPPY"], ["SMILE", "SMILE"], ["SAD", "SAD"], ["CONFUSED", "CONFUSED"], ["ANGRY", "ANGRY"], ["ASLEEP", "ASLEEP"], ["SURPRISED", "SURPRISED"], ["SILLY", "SILLY"], ["FABULOUS", "FABULOUS"], ["MEH", "MEH"], ["YES", "YES"], ["NO", "NO"], ["CLOCK12", "CLOCK12"], ["CLOCK11", "CLOCK11"], ["CLOCK10", "CLOCK10"], ["CLOCK9", "CLOCK9"], ["CLOCK8", "CLOCK8"], ["CLOCK7", "CLOCK7"], ["CLOCK6", "CLOCK6"], ["CLOCK5", "CLOCK5"], ["CLOCK4", "CLOCK4"], ["CLOCK3", "CLOCK3"], ["CLOCK2", "CLOCK2"], ["CLOCK1", "CLOCK1"], ["ARROW_N", "ARROW_N"], ["ARROW_NE", "ARROW_NE"], ["ARROW_E", "ARROW_E"], ["ARROW_SE", "ARROW_SE"], ["ARROW_S", "ARROW_S"], ["ARROW_SW", "ARROW_SW"], ["ARROW_W", "ARROW_W"], ["ARROW_NW", "ARROW_NW"], ["TRIANGLE", "TRIANGLE"], ["TRIANGLE_LEFT", "TRIANGLE_LEFT"], ["CHESSBOARD", "CHESSBOARD"], ["DIAMOND", "DIAMOND"], ["DIAMOND_SMALL", "DIAMOND_SMALL"], ["SQUARE", "SQUARE"], ["SQUARE_SMALL", "SQUARE_SMALL"], ["RABBIT", "RABBIT"], ["COW", "COW"], ["MUSIC_CROTCHET", "MUSIC_CROTCHET"], ["MUSIC_QUAVER", "MUSIC_QUAVER"], ["MUSIC_QUAVERS", "MUSIC_QUAVERS"], ["PITCHFORK", "PITCHFORK"], ["XMAS", "XMAS"], ["PACMAN", "PACMAN"], ["TARGET", "TARGET"], ["TSHIRT", "TSHIRT"], ["ROLLERSKATE", "ROLLERSKATE"], ["DUCK", "DUCK"], ["HOUSE", "HOUSE"], ["TORTOISE", "TORTOISE"], ["BUTTERFLY", "BUTTERFLY"], ["STICKFIGURE", "STICKFIGURE"], ["GHOST", "GHOST"], ["SWORD", "SWORD"], ["GIRAFFE", "GIRAFFE"], ["SKULL", "SKULL"], ["UMBRELLA", "UMBRELLA"], ["SNAKE", "SNAKE"], ["ALL_CLOCKS", "ALL_CLOCKS"], ["ALL_ARROWS", "ALL_ARROWS"]];
export const microbit_display_clear = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.clear",
"message0": Blockly.Msg.MIXLY_MICROBIT_Clear_display
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Clear_display);
}
};
export const monitor_get_pixel = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('x')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_GET)
.appendField(Blockly.Msg.MIXLY_BRIGHTNESS)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_GET_POINT_X);
this.appendValueInput('y')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_PLOT_POINT_Y);
this.setInputsInline(true);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_BRIGHTNESS1);
}
};
export const monitor_bright_point = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('x')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_SET_BRIGHTNESS)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_GET_POINT_X);
this.appendValueInput('y')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_PLOT_POINT_Y);
this.appendValueInput('brightness')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_BRIGHTNESS);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_BRIGHTNESS2);
}
};
export const monitor_show_image_or_string = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('data')
.setCheck([String, "microbit_image"])
.appendField(Blockly.Msg.MIXLY_MICROBIT_SHOW_IMAGE_OR_STRING);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_SHOW_IMAGE_OR_STRING);
}
};
export const monitor_scroll_string = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('data')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_SCROLL_STRING);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
}
};
export const monitor_scroll_string_with_delay = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('data')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_SCROLL_STRING);
this.appendValueInput('delay')
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_DELAY);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MILLIS);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
}
};
export const microbit_display_show_image = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('PIN', String)
.setCheck("microbit_image")
.appendField(Blockly.Msg.OLED_BITMAP);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.OLED_BITMAP);
}
};
export const microbit_display_show_default_image = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"InputsInline": true,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.show",
"tooltip": "Show the referenced image on the display.",
"message0": Blockly.Msg.OLED_BITMAP,
"args0": [{
"name": "image",
"options": [["HEART", "HEART"], ["HEART_SMALL", "HEART_SMALL"], ["HAPPY", "HAPPY"], ["SMILE", "SMILE"], ["SAD", "SAD"], ["CONFUSED", "CONFUSED"], ["ANGRY", "ANGRY"], ["ASLEEP", "ASLEEP"], ["SURPRISED", "SURPRISED"], ["SILLY", "SILLY"], ["FABULOUS", "FABULOUS"], ["MEH", "MEH"], ["YES", "YES"], ["NO", "NO"], ["CLOCK12", "CLOCK12"], ["CLOCK11", "CLOCK11"], ["CLOCK10", "CLOCK10"], ["CLOCK9", "CLOCK9"], ["CLOCK8", "CLOCK8"], ["CLOCK7", "CLOCK7"], ["CLOCK6", "CLOCK6"], ["CLOCK5", "CLOCK5"], ["CLOCK4", "CLOCK4"], ["CLOCK3", "CLOCK3"], ["CLOCK2", "CLOCK2"], ["CLOCK1", "CLOCK1"], ["ARROW_N", "ARROW_N"], ["ARROW_NE", "ARROW_NE"], ["ARROW_E", "ARROW_E"], ["ARROW_SE", "ARROW_SE"], ["ARROW_S", "ARROW_S"], ["ARROW_SW", "ARROW_SW"], ["ARROW_W", "ARROW_W"], ["ARROW_NW", "ARROW_NW"], ["TRIANGLE", "TRIANGLE"], ["TRIANGLE_LEFT", "TRIANGLE_LEFT"], ["CHESSBOARD", "CHESSBOARD"], ["DIAMOND", "DIAMOND"], ["DIAMOND_SMALL", "DIAMOND_SMALL"], ["SQUARE", "SQUARE"], ["SQUARE_SMALL", "SQUARE_SMALL"], ["RABBIT", "RABBIT"], ["COW", "COW"], ["MUSIC_CROTCHET", "MUSIC_CROTCHET"], ["MUSIC_QUAVER", "MUSIC_QUAVER"], ["MUSIC_QUAVERS", "MUSIC_QUAVERS"], ["PITCHFORK", "PITCHFORK"], ["XMAS", "XMAS"], ["PACMAN", "PACMAN"], ["TARGET", "TARGET"], ["TSHIRT", "TSHIRT"], ["ROLLERSKATE", "ROLLERSKATE"], ["DUCK", "DUCK"], ["HOUSE", "HOUSE"], ["TORTOISE", "TORTOISE"], ["BUTTERFLY", "BUTTERFLY"], ["STICKFIGURE", "STICKFIGURE"], ["GHOST", "GHOST"], ["SWORD", "SWORD"], ["GIRAFFE", "GIRAFFE"], ["SKULL", "SKULL"], ["UMBRELLA", "UMBRELLA"], ["SNAKE", "SNAKE"], ["ALL_CLOCKS", "ALL_CLOCKS"], ["ALL_ARROWS", "ALL_ARROWS"]],
"type": "field_dropdown"
}
]
});
}
};
export const microbit_display_show_animation = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"inputsInline": true,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.show",
"message0": Blockly.Msg.MIXLY_MICROBIT_Animate_images_or_string,
"args0": [{
"check": [String, "List"],
"type": "input_value",
"name": "images"
}, {
"type": "input_value",
"name": "delay"
}, {
"type": "input_dummy"
}, {
"checked": true,
"type": "field_checkbox",
"name": "wait"
}, {
"type": "input_dummy"
}, {
"checked": false,
"type": "field_checkbox",
"name": "loop"
}, {
"type": "input_dummy"
}, {
"checked": false,
"type": "field_checkbox",
"name": "clear"
}
]
});
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_SHOW_delay + Blockly.Msg.MIXLY_MICROBIT_Animate_images1);
}
};
export const microbit_display_scroll_string_animation = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_SCROLL_STRING);
this.jsonInit({
"colour": DISPLAY_HUE,
"inputsInline": true,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.show",
"tooltip": "Display the list of images as an animation with a certain delay between each frame. Indicate if you need to wait before continuing, continuously loop the animation and clear the display when finished.",
"message0": Blockly.Msg.MIXLY_MICROBIT_SHOW_STRING,
"args0": [{
"check": String,
"type": "input_value",
"name": "images"
}, {
"type": "input_value",
"name": "delay"
}, {
"type": "input_dummy"
}, {
"checked": true,
"type": "field_checkbox",
"name": "wait"
}, {
"type": "input_dummy"
}, {
"checked": false,
"type": "field_checkbox",
"name": "loop"
}, {
"type": "input_dummy"
}, {
"checked": false,
"type": "field_checkbox",
"name": "clear"
}
]
});
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_MONITOR_SCROLL_STRING);
}
};
export const microbit_display_scroll = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.scroll",
"tooltip": "Scroll the referenced text across the display.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Scroll_message,
"args0": [{
"check": "String",
"type": "input_value",
"name": "message"
}
]
});
}
};
export const microbit_display_on = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_Turn_on_display, 'on'], [Blockly.Msg.MIXLY_MICROBIT_Turn_off_display, 'off']]), 'on_off')
.appendField(Blockly.Msg.MIXLY_MICROBIT_monitor);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('on_off');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_monitor;
var TOOLTIPS = {
'on': Blockly.Msg.MIXLY_MICROBIT_Turn_on_display,
'off': Blockly.Msg.MIXLY_MICROBIT_Turn_off_display
};
return TOOLTIPS[mode] + mode0;
});
}
};
export const microbit_display_off = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.off",
"tooltip": "Turn off the display.",
"message0": Blockly.Msg.MIXLY_MICROBIT_Turn_off_display
});
}
};
export const microbit_display_is_on = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"output": "Boolean",
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.is_on",
"message0": Blockly.Msg.MIXLY_MICROBIT_Display_is_on
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Display_is_on1);
}
};
export const microbit_image_builtins = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"args0": [{
"name": "image",
"options": [["HEART", "HEART"], ["HEART_SMALL", "HEART_SMALL"], ["HAPPY", "HAPPY"], ["SMILE", "SMILE"], ["SAD", "SAD"], ["CONFUSED", "CONFUSED"], ["ANGRY", "ANGRY"], ["ASLEEP", "ASLEEP"], ["SURPRISED", "SURPRISED"], ["SILLY", "SILLY"], ["FABULOUS", "FABULOUS"], ["MEH", "MEH"], ["YES", "YES"], ["NO", "NO"], ["CLOCK12", "CLOCK12"], ["CLOCK11", "CLOCK11"], ["CLOCK10", "CLOCK10"], ["CLOCK9", "CLOCK9"], ["CLOCK8", "CLOCK8"], ["CLOCK7", "CLOCK7"], ["CLOCK6", "CLOCK6"], ["CLOCK5", "CLOCK5"], ["CLOCK4", "CLOCK4"], ["CLOCK3", "CLOCK3"], ["CLOCK2", "CLOCK2"], ["CLOCK1", "CLOCK1"], ["ARROW_N", "ARROW_N"], ["ARROW_NE", "ARROW_NE"], ["ARROW_E", "ARROW_E"], ["ARROW_SE", "ARROW_SE"], ["ARROW_S", "ARROW_S"], ["ARROW_SW", "ARROW_SW"], ["ARROW_W", "ARROW_W"], ["ARROW_NW", "ARROW_NW"], ["TRIANGLE", "TRIANGLE"], ["TRIANGLE_LEFT", "TRIANGLE_LEFT"], ["CHESSBOARD", "CHESSBOARD"], ["DIAMOND", "DIAMOND"], ["DIAMOND_SMALL", "DIAMOND_SMALL"], ["SQUARE", "SQUARE"], ["SQUARE_SMALL", "SQUARE_SMALL"], ["RABBIT", "RABBIT"], ["COW", "COW"], ["MUSIC_CROTCHET", "MUSIC_CROTCHET"], ["MUSIC_QUAVER", "MUSIC_QUAVER"], ["MUSIC_QUAVERS", "MUSIC_QUAVERS"], ["PITCHFORK", "PITCHFORK"], ["XMAS", "XMAS"], ["PACMAN", "PACMAN"], ["TARGET", "TARGET"], ["TSHIRT", "TSHIRT"], ["ROLLERSKATE", "ROLLERSKATE"], ["DUCK", "DUCK"], ["HOUSE", "HOUSE"], ["TORTOISE", "TORTOISE"], ["BUTTERFLY", "BUTTERFLY"], ["STICKFIGURE", "STICKFIGURE"], ["GHOST", "GHOST"], ["SWORD", "SWORD"], ["GIRAFFE", "GIRAFFE"], ["SKULL", "SKULL"], ["UMBRELLA", "UMBRELLA"], ["SNAKE", "SNAKE"], ["ALL_CLOCKS", "ALL_CLOCKS"], ["ALL_ARROWS", "ALL_ARROWS"]],
"type": "field_dropdown"
}
],
"output": ["microbit_image", "List"],
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/image.html#attributes",
"tooltip": Blockly.Msg.MIXLY_MICROBIT_Built_in_image1,
"message0": Blockly.Msg.MIXLY_MICROBIT_Built_in_image
});
}
};
export const microbit_image_copy = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"args0": [{
"check": ["microbit_image", "List", String],
"type": "input_value",
"name": "image"
}
],
"output": "microbit_image",
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/image.html#microbit.Image.copy",
"message0": Blockly.Msg.MIXLY_MICROBIT_Copy_image
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Copy_image1);
}
};
export const microbit_image_invert = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"args0": [{
"check": ["microbit_image", "List", String],
"type": "input_value",
"name": "image"
}
],
"output": "microbit_image",
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/image.html#microbit.Image.invert",
"message0": Blockly.Msg.MIXLY_MICROBIT_Invert_image
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Invert_image1);
}
};
export const microbit_image_create = {
init: function () {
this.jsonInit({
"colour": DISPLAY_HUE,
"args0": [{
"type": "input_dummy"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "00"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "01"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "02"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "03"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "04"
}, {
"type": "input_dummy"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "10"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "11"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "12"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "13"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "14"
}, {
"type": "input_dummy"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "20"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "21"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "22"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "23"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "24"
}, {
"type": "input_dummy"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "30"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "31"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "32"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "33"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "34"
}, {
"type": "input_dummy"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "40"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "41"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "42"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "43"
}, {
"colour": "#000000",
"type": "field_colour",
"name": "44"
}
],
"output": "microbit_image",
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/image.html#microbit.Image",
"message0": Blockly.Msg.MIXLY_MICROBIT_Create_image
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Create_image1);
}
};
export const image_shift = {
init: function () {
var OPERATORS = [
[Blockly.Msg.MIXLY_UP, 'up'],
[Blockly.Msg.MIXLY_DOWN, 'down'],
[Blockly.Msg.MIXLY_LEFT, 'left'],
[Blockly.Msg.MIXLY_RIGHT, 'right'],
];
//this.setHelpUrl(Blockly.Msg.MATH_TRIG_HELPURL);
this.setColour(DISPLAY_HUE);
this.setOutput(true, "microbit_image");
this.setInputsInline(true);
this.appendValueInput('img')
.appendField(Blockly.Msg.DISPLAY_IMAGE_LET)
.setCheck(["microbit_image", "List", String]);
this.appendDummyInput('')
.appendField(Blockly.Msg.DISPLAY_IMAGE_LET2)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.appendValueInput('val')
.appendField(Blockly.Msg.DISPLAY_IMAGE_SHIFT)
.setCheck(Number);
this.appendDummyInput('')
.appendField(Blockly.Msg.DISPLAY_IMAGE_UNIT)
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var mode0 = Blockly.Msg.DISPLAY_IMAGE_LET;
var mode1 = Blockly.Msg.DISPLAY_IMAGE_LET2;
var mode2 = Blockly.Msg.DISPLAY_IMAGE_LET3;
var TOOLTIPS = {
'up': Blockly.Msg.MIXLY_UP,
'down': Blockly.Msg.MIXLY_DOWN,
'left': Blockly.Msg.MIXLY_LEFT,
'right': Blockly.Msg.MIXLY_RIGHT
};
return mode0 + mode1 + TOOLTIPS[mode] + mode2;
});
}
};
export const image_arithmetic = {
init: function () {
var OPERATORS = [
[Blockly.Msg.MICROBIT_DISPLAY_UNION, '+'],
[Blockly.Msg.MICROBIT_DISPLAY_MINUS, '-']
];
//this.setHelpUrl(Blockly.Msg.MATH_ARITHMETIC_HELPURL);
this.setColour(DISPLAY_HUE);
this.setOutput(true, "microbit_image");
this.appendValueInput('A')
// .setCheck(["microbit_image", "List", String])
.appendField(Blockly.Msg.MICROBIT_DISPLAY_MERGE_SHAPE);
this.appendValueInput('B')
// .setCheck(["microbit_image", "List", String])
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'+': Blockly.Msg.MIXLY_MICROBIT_image_add,
'-': Blockly.Msg.MIXLY_MICROBIT_image_reduce
};
return TOOLTIPS[mode];
});
}
};
// export const microbit_display_scroll_string = {
// init : function () {
// this.jsonInit({
// "colour" : DISPLAY_HUE,
// "inputsInline": true,
// "nextStatement" : null,
// "previousStatement" : null,
// "helpUrl" : "https://microbit-micropython.readthedocs.io/en/latest/display.html#microbit.display.show",
// "tooltip" : "Display the list of images as an animation with a certain delay between each frame. Indicate if you need to wait before continuing, continuously loop the animation and clear the display when finished.",
// "message0" : Blockly.Msg.MIXLY_MICROBIT_Scroll_string,
// "args0" : [{
// "check" : String,
// "type" : "input_value",
// "name" : "images"
// }, {
// "type" : "input_value",
// "name" : "delay"
// }, {
// "type" : "input_dummy"
// }, {
// "checked" : true,
// "type" : "field_checkbox",
// "name" : "wait"
// }, {
// "type" : "input_dummy"
// }, {
// "checked" : false,
// "type" : "field_checkbox",
// "name" : "loop"
// }, {
// "type" : "input_dummy"
// }, {
// "checked" : false,
// "type" : "field_checkbox",
// "name" : "clear"
// }
// ]
// });
// }
// };
export const group_lcd_print = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput("TEXT", String)
.setCheck([String, Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_DF_LCD)
.appendField('mylcd')
//.appendField(new Blockly.FieldTextInput('mylcd'), 'VAR')
.appendField(Blockly.Msg.MIXLY_LCD_PRINT1);
this.appendValueInput("TEXT2", String)
.setCheck([String, Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_LCD_PRINT2);
/*
this.appendValueInput("TEXT3", String)
.setCheck([String,Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_LCD_PRINT3);
this.appendValueInput("TEXT4", String)
.setCheck([String,Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_LCD_PRINT4);
*/
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_LCD_PRINT4_TOOLTIP);
}
};
export const group_lcd_init = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('device')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_SETUP)
.appendField(Blockly.Msg.MIXLY_DF_LCD)
.appendField('1602')
.appendField('mylcd')
.appendField(Blockly.Msg.MIXLY_LCD_ADDRESS);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_SETUP + Blockly.Msg.MIXLY_DF_LCD + Blockly.Msg.MIXLY_LCD_ADDRESS);
}
};
export const group_lcd_print2 = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput("row", Number)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_DF_LCD)
.appendField('mylcd')
.appendField(Blockly.Msg.MIXLY_LCD_ROW);
this.appendValueInput("column", Number)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_LCD_COLUMN);
this.appendValueInput("TEXT", String)
.setCheck([String, Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_LCD_PRINT);
this.setPreviousStatement(true, null);
this.setInputsInline(true);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_LCD_PRINT3_TOOLTIP);
}
};
export const group_lcd_power = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_DF_LCD)
.appendField('mylcd')
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "on()"], [Blockly.Msg.MIXLY_OFF, "off()"], [Blockly.Msg.MIXLY_LCD_STAT_CLEAR, "clear()"], [Blockly.Msg.MIXLY_LCD_NOBACKLIGHT, "backlight(False)"], [Blockly.Msg.MIXLY_LCD_BACKLIGHT, "backlight(True)"]]), "STAT");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('STAT');
var mode0 = Blockly.Msg.LISTS_SET_INDEX_SET;
var mode1 = Blockly.Msg.MIXLY_DF_LCD;
var TOOLTIPS = {
'on()': Blockly.Msg.MIXLY_ON,
'off()': Blockly.Msg.MIXLY_OFF,
'clear()': Blockly.Msg.MIXLY_LCD_STAT_CLEAR,
'backlight(off)': Blockly.Msg.MIXLY_LCD_NOBACKLIGHT,
'backlight(on)': Blockly.Msg.MIXLY_LCD_BACKLIGHT
};
return mode0 + mode1 + TOOLTIPS[mode];
});
}
};
export const lp2i_u8g_draw_4strings = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_DF_LCD + " OLED " + Blockly.Msg.OLEDDISPLAY);
//.appendField(new Blockly.FieldImage(Blockly.pathToBlockly + 'blocks/display-oled-128x64-i2c/display-oled-128x64-i2c.jpg', Blockly.Arduino.imageSize, Blockly.Arduino.imageSize));
this.appendValueInput("Text_line1", 'String')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("(128*64) " + Blockly.Msg.line1);
this.appendValueInput("Text_line2", 'String')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.line2);
this.appendValueInput("Text_line3", 'String')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.line3);
this.appendValueInput("Text_line4", 'String')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.line4);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(DISPLAY_HUE);
this.setTooltip(Blockly.Msg.MIXLY_DF_LCD + Blockly.Msg.OLEDDISPLAY + Blockly.Msg.MIXLY_MICROBIT_TYPE_STRING);
}
};
export const display_image_size = {
init: function () {
var OPERATORS = [
[Blockly.Msg.MIXLY_HEIGHT, 'height'],
[Blockly.Msg.MIXLY_WIDTH, 'width']
];
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET + Blockly.Msg.MIXLY_MICROBIT_IMAGE);
this.appendValueInput('VAR')
.setCheck("microbit_image")
// .appendField(Blockly.Msg.blockpy_USE_LIST);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setInputsInline(true);
this.setOutput(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET;
var mode1 = Blockly.Msg.MIXLY_MICROBIT_IMAGE
var TOOLTIPS = {
'height': Blockly.Msg.MIXLY_HEIGHT,
'width': Blockly.Msg.MIXLY_WIDTH,
};
return mode0 + mode1 + TOOLTIPS[mode];
});
}
};
export const display_fill = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendValueInput('SUB');
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_LCD_STAT_CLEAR, "0"],
[Blockly.Msg.MIXLY_HANDBIT_DISLPAY_OLED_FILL, "1"]
]), "key");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('key');
var TOOLTIPS = {
'0': Blockly.Msg.MIXLY_LCD_STAT_CLEAR,
'1': Blockly.Msg.MIXLY_HANDBIT_DISLPAY_OLED_FILL
};
return Blockly.Msg.MIXLY_DF_LCD + TOOLTIPS[mode];
});
}
};

View File

@@ -0,0 +1,274 @@
import * as Blockly from 'blockly/core';
const FACTORY_HUE = "#777777"//65;
export const factory_from_import = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField("from ")
.appendField(new Blockly.FieldTextInput('microbit'), 'path')
.appendField(" import ")
.appendField(new Blockly.FieldTextInput('*'), 'module');
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const factory_import = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField("import ")
.appendField(new Blockly.FieldTextInput('module'), 'module');
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const factory_function_noreturn = {
init: function () {
//console.log('init');
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('my_function'), 'NAME');
this.itemCount_ = 1;
this.arguments_ = ['x'];//add
this.updateShape_();
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
},
mutationToDom: function () {
//console.log('mutationToDom');
var container = document.createElement('mutation');
container.setAttribute('items', this.itemCount_);
//add
for (var i = 0; i < this.arguments_.length; i++) {
var parameter = document.createElement('arg');
parameter.setAttribute('name', this.arguments_[i]);
container.appendChild(parameter);
}
return container;
},
domToMutation: function (xmlElement) {
//console.log('domToMutation');
this.arguments_ = [];//add
//add
for (var i = 0; xmlElement.childNodes[i]; i++) {
let childNode = xmlElement.childNodes[i];
if (childNode.nodeName.toLowerCase() == 'arg') {
this.arguments_.push(childNode.getAttribute('name'));
}
}
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
this.updateShape_();
},
decompose: function (workspace) {
//console.log('decompose');
var containerBlock =
workspace.newBlock('factory_create_with_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK')
.connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('factory_create_with_item');
itemBlock.initSvg();
itemBlock.setFieldValue(this.arguments_[i], 'NAME');//add
connection.connect(itemBlock.previousConnection);
connection = itemBlock.nextConnection;
}
return containerBlock;
},
compose: function (containerBlock) {
//console.log('compose');
this.arguments_ = [];//add
var itemBlock = containerBlock.getInputTargetBlock('STACK');
// Count number of inputs.
var connections = [];
var i = 0;
while (itemBlock) {
this.arguments_.push(itemBlock.getFieldValue('NAME'));//add
connections[i] = itemBlock.valueConnection_;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
i++;
}
this.itemCount_ = i;
this.updateShape_();
// Reconnect any child blocks.
for (var i = 0; i < this.itemCount_; i++) {
if (connections[i]) {
this.getInput('ADD' + i)
.connection.connect(connections[i]);
}
}
},
saveConnections: function (containerBlock) {
//console.log('saveConnections');
var itemBlock = containerBlock.getInputTargetBlock('STACK');
var i = 0;
while (itemBlock) {
var input = this.getInput('ADD' + i);
itemBlock.valueConnection_ = input && input.connection.targetConnection;
i++;
itemBlock = itemBlock.nextConnection &&
itemBlock.nextConnection.targetBlock();
}
},
updateShape_: function () {
//console.log('updateShape_');
// Delete everything.
if (this.getInput('EMPTY')) {
this.removeInput('EMPTY');
} else {
var i = 0;
while (this.getInput('ADD' + i)) {
this.removeInput('ADD' + i);
i++;
}
}
// Rebuild block.
for (var i = 0; i < this.itemCount_; i++) {
this.appendValueInput('ADD' + i)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(this.arguments_[i]);
}
}
};
export const factory_create_with_container = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_PARAMS);
this.appendStatementInput('STACK');
this.contextMenu = false;
}
};
export const factory_create_with_item = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE + ':')
.appendField(new Blockly.FieldTextInput('x'), 'NAME');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.contextMenu = false;
}
};
export const factory_function_return = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('my_function'), 'NAME');
this.itemCount_ = 1;
this.arguments_ = ['x'];//add
this.updateShape_();
this.setOutput(true);
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
},
mutationToDom: factory_function_noreturn.mutationToDom,
domToMutation: factory_function_noreturn.domToMutation,
decompose: factory_function_noreturn.decompose,
compose: factory_function_noreturn.compose,
saveConnections: factory_function_noreturn.saveConnections,
updateShape_: factory_function_noreturn.updateShape_
};
export const factory_declare = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
.appendField("=")
.appendField(new Blockly.FieldTextInput('Test'), 'TYPE')
.appendField("()");
this.setPreviousStatement(true);
this.setNextStatement(true);
}
}
export const factory_callMethod_noreturn = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
.appendField('.')
.appendField(new Blockly.FieldTextInput('callMethod'), 'METHOD');
this.itemCount_ = 1;
this.arguments_ = ['x'];//add
this.updateShape_();
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
},
mutationToDom: factory_function_noreturn.mutationToDom,
domToMutation: factory_function_noreturn.domToMutation,
decompose: factory_function_noreturn.decompose,
compose: factory_function_noreturn.compose,
saveConnections: factory_function_noreturn.saveConnections,
updateShape_: factory_function_noreturn.updateShape_
};
export const factory_callMethod_return = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
.appendField('.')
.appendField(new Blockly.FieldTextInput('callMethod'), 'METHOD');
this.itemCount_ = 1;
this.arguments_ = ['x'];//add
this.updateShape_();
this.setOutput(true);
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
},
mutationToDom: factory_function_noreturn.mutationToDom,
domToMutation: factory_function_noreturn.domToMutation,
decompose: factory_function_noreturn.decompose,
compose: factory_function_noreturn.compose,
saveConnections: factory_function_noreturn.saveConnections,
updateShape_: factory_function_noreturn.updateShape_
};
export const factory_block = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('display.scroll("Hello World!")'), 'VALUE');
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const factory_block_return = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('test'), 'VALUE');
this.setOutput(true);
}
};
export const factory_block_with_textarea = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldMultilineInput('display.scroll("Hello World!")\ndisplay.scroll("Hello Mixly!")'), 'VALUE');
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const factory_block_return_with_textarea = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldMultilineInput('Hello\nMixly'), 'VALUE');
this.setOutput(true);
}
};

View File

@@ -0,0 +1,104 @@
import * as Blockly from 'blockly/core';
const BASE_HUE = 20//'#ae3838';//40;
export const inout_highlow = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_HIGH, "HIGH"], [Blockly.Msg.MIXLY_LOW, "LOW"]]), 'BOOL')
this.setOutput(true, Boolean);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_HIGHLOW);
}
};
export const inout_digital_read = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_DIGITALREAD_PIN)
.setCheck(Number);
this.setInputsInline(true);
this.setOutput(true, [Boolean, Number]);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_DIGITAL_READ);
}
};
export const inout_analog_write = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_ANALOGWRITE_PIN)
.setCheck(Number);
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_VALUE2)
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_WRITE_PY);
}
};
export const inout_analog_write_set = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_ANALOGWRITE_PIN)
.setCheck(Number);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_PERIOD_MIL)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_mSecond, "period"],
[Blockly.Msg.MIXLY_uSecond, "period_microseconds"]
]), "key");
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_STAT)
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_WRITE_SET);
}
};
export const inout_analog_read = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_ANALOGREAD_PIN)
.setCheck(Number);
this.setInputsInline(true);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_READ);
}
};
export const sensor_pin_pressed = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput('pin')
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_IS_TOUCHED);
this.setOutput(true, Boolean);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_sensor_pin_pressed);
}
};
export const inout_digital_write = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_DIGITALWRITE_PIN)
.setCheck(Number);
this.appendValueInput("STAT")
.appendField(Blockly.Msg.MIXLY_STAT)
.setCheck([Number, Boolean]);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.LANG_INOUT_DIGITAL_WRITE_TOOLTIP);
}
};

View File

@@ -0,0 +1,28 @@
const pins = {};
pins['microbit'] = {
description: "microbit_python",
// digital: [["P0", "DigitalPin.P0"], ["P1", "DigitalPin.P1"], ["P2", "DigitalPin.P2"], ["P3", "DigitalPin.P3"], ["P4", "DigitalPin.P4"], ["P5", "DigitalPin.P5"], ["P6", "DigitalPin.P6"], ["P7", "DigitalPin.P7"], ["P8", "DigitalPin.P8"], ["P9", "DigitalPin.P9"], ["P10", "DigitalPin.P10"], ["P11", "DigitalPin.P11"], ["P12", "DigitalPin.P12"], ["P13", "DigitalPin.P13"], ["P14", "DigitalPin.P14"], ["P15", "DigitalPin.P15"], ["P16", "DigitalPin.P16"], ["P17", "DigitalPin.P17"], ["P18", "DigitalPin.P18"], ["P19", "DigitalPin.P19"], ["P20", "DigitalPin.P20"]],
digital: [["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]],
//pwm: [["P0", "AnalogPin.P0"], ["P1", "AnalogPin.P1"], ["P2", "AnalogPin.P2"], ["P3", "AnalogPin.P3"], ["P4", "AnalogPin.P4"], ["P5", "AnalogPin.P5"], ["P6", "AnalogPin.P6"], ["P7", "AnalogPin.P7"], ["P8", "AnalogPin.P8"], ["P9", "AnalogPin.P9"], ["P10", "AnalogPin.P10"], ["P11", "AnalogPin.P11"], ["P12", "AnalogPin.P12"], ["P13", "AnalogPin.P13"], ["P14", "AnalogPin.P14"], ["P15", "AnalogPin.P15"], ["P16", "AnalogPin.P16"], ["P19", "AnalogPin.P19"], ["P20", "AnalogPin.P20"]],
pwm: [["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]],
analog: [["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P10", "10"]],
interrupt: [["P0", "0"], ["P1", "1"], ["P2", "2"]],
button: [["A", "button_a"], ["B", "button_b"]],
axis: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"]],
brightness: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"]],
builtinimg: [["HEART", "Image.HEART"], ["HEART_SMALL", "Image.HEART_SMALL"], ["HAPPY", "Image.HAPPY"], ["SMILE", "Image.SMILE"], ["SAD", "Image.SAD"], ["CONFUSED", "Image.CONFUSED"], ["ANGRY", "Image.ANGRY"], ["ASLEEP", "Image.ASLEEP"], ["SURPRISED", "Image.SURPRISED"], ["SILLY", "Image.SILLY"], ["FABULOUS", "Image.FABULOUS"], ["MEH", "Image.MEH"], ["YES", "Image.YES"], ["NO", "Image.NO"], ["CLOCK12", "Image.CLOCK12"], ["CLOCK11", "Image.CLOCK11"], ["CLOCK10", "Image.CLOCK10"], ["CLOCK9", "Image.CLOCK9"], ["CLOCK8", "Image.CLOCK8"], ["CLOCK7", "Image.CLOCK7"], ["CLOCK6", "Image.CLOCK6"], ["CLOCK5", "Image.CLOCK5"], ["CLOCK4", "Image.CLOCK4"], ["CLOCK3", "Image.CLOCK3"], ["CLOCK2", "Image.CLOCK2"], ["CLOCK1", "Image.CLOCK1"], ["ARROW_N", "Image.ARROW_N"], ["ARROW_NE", "Image.ARROW_NE"], ["ARROW_E", "Image.ARROW_E"], ["ARROW_SE", "Image.ARROW_SE"], ["ARROW_S", "Image.ARROW_S"], ["ARROW_SW", "Image.ARROW_SW"], ["ARROW_W", "Image.ARROW_W"], ["ARROW_NW", "Image.ARROW_NW"], ["TRIANGLE", "Image.TRIANGLE"], ["TRIANGLE_LEFT", "Image.TRIANGLE_LEFT"], ["CHESSBOARD", "Image.CHESSBOARD"], ["DIAMOND", "Image.DIAMOND"], ["DIAMOND_SMALL", "Image.DIAMOND_SMALL"], ["SQUARE", "Image.SQUARE"], ["SQUARE_SMALL", "Image.SQUARE_SMALL"], ["RABBIT", "Image.RABBIT"], ["COW", "Image.COW"], ["MUSIC_CROTCHET", "Image.MUSIC_CROTCHET"], ["MUSIC_QUAVER", "Image.MUSIC_QUAVER"], ["MUSIC_QUAVERS", "Image.MUSIC_QUAVERS"], ["PITCHFORK", "Image.PITCHFORK"], ["XMAS", "Image.XMAS"], ["PACMAN", "Image.PACMAN"], ["TARGET", "Image.TARGET"], ["TSHIRT", "Image.TSHIRT"], ["ROLLERSKATE", "Image.ROLLERSKATE"], ["DUCK", "Image.DUCK"], ["HOUSE", "Image.HOUSE"], ["TORTOISE", "Image.TORTOISE"], ["BUTTERFLY", "Image.BUTTERFLY"], ["STICKFIGURE", "Image.STICKFIGURE"], ["GHOST", "Image.GHOST"], ["SWORD", "Image.SWORD"], ["GIRAFFE", "Image.GIRAFFE"], ["SKULL", "Image.SKULL"], ["UMBRELLA", "Image.UMBRELLA"], ["SNAKE", "Image.SNAKE"], ["ALL_CLOCKS", "Image.ALL_CLOCKS"], ["ALL_ARROWS", "Image.ALL_ARROWS"]],
imglist: [["ALL_CLOCKS", "Image.ALL_CLOCKS"], ["ALL_ARROWS", "Image.ALL_ARROWS"]],
tone_notes: [
["NOTE_C3", "131"], ["NOTE_D3", "147"], ["NOTE_E3", "165"], ["NOTE_F3", "175"], ["NOTE_G3", "196"], ["NOTE_A3", "220"], ["NOTE_B3", "247"],
["NOTE_C4", "262"], ["NOTE_D4", "294"], ["NOTE_E4", "330"], ["NOTE_F4", "349"], ["NOTE_G4", "392"], ["NOTE_A4", "440"], ["NOTE_B4", "494"],
["NOTE_C5", "523"], ["NOTE_D5", "587"], ["NOTE_E5", "659"], ["NOTE_F5", "698"], ["NOTE_G5", "784"], ["NOTE_A5", "880"], ["NOTE_B5", "988"]
],
serial_pin: [["P0", "0"], ["P1", "1"], ["P2", "2"], ["P8", "8"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"]],
radio_power: [['0', '0'], ['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'], ['7', '7']],
radio_datarate: [["1Mbit", "RATE_1MBIT"], ["250Kbit", "RATE_250KBIT"], ["2Mbit", "RATE_2MBIT"]],
};
pins["Mithon CC"] = pins["microbit"];
export default pins;

View File

@@ -0,0 +1,210 @@
import * as Blockly from 'blockly/core';
const SENSOR_HUE = 40;
const ACTUATOR_HUE = 100;
const LOOPS_HUE = 120;
// Blockly.FieldColour.COLOURS = ['#0f0', '#0e0', '#0d0', '#0c0', '#0b0', '#0a0',
// '#080', '#060', '#040', '#000'];
// Blockly.FieldColour.COLUMNS = 5;
export const base_loop = {
init: function () {
this.jsonInit({
"message0": Blockly.Msg.CONTROLS_REPEAT_TITLE_REPEAT + Blockly.Msg.CONTROLS_REPEAT_INPUT_DO,
"message1": "%1",
"colour": LOOPS_HUE,
"args1": [
{
"type": "input_statement",
"name": "DO"
}
],
//"style":{"hat": "not"},
"tooltip": "",
"helpUrl": ""
});
//this.setPreviousStatement(true, null);
}
};
export const actuator_rgb_color = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RGB)
.appendField(Blockly.Msg.MIXLY_RGB_NUM);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_ALL, "0"],
["0", "1"],
["1", "2"],
["2", "3"],
["3", "4"]
]), 'LED')
.appendField(Blockly.Msg.HTML_COLOUR);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.COLOUR_RGB_RED, "255,0,0"],
[Blockly.Msg.COLOUR_RGB_ORANGE, "255,128,0"],
[Blockly.Msg.COLOUR_RGB_YELLOW, "255,255,0"],
[Blockly.Msg.COLOUR_RGB_GREEN, "0,255,0"],
[Blockly.Msg.COLOUR_RGB_CYAN, "0,255,255"],
[Blockly.Msg.COLOUR_RGB_BLUE, "0,0,255"],
[Blockly.Msg.COLOUR_RGB_PURPLE, "128,0,255"],
[Blockly.Msg.COLOUR_RGB_WHITE, "255,255,255"]
]), 'COLOR');
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
export const actuator_rgb_off = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RGB)
.appendField(Blockly.Msg.MIXLY_RGB_NUM);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_ALL, "0"],
["0", "1"],
["1", "2"],
["2", "3"],
["3", "4"]
]), 'LED')
.appendField(Blockly.Msg.MIXLY_MICROBIT_Turn_off_display);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
export const actuator_rgb = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RGB)
this.appendValueInput("_LED_")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_NUM);
this.appendValueInput("RVALUE")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_R);
this.appendValueInput("GVALUE")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_G);
this.appendValueInput("BVALUE")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RGB_B);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
export const actuator_motor_on = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MOTOR)
.appendField(Blockly.Msg.LCD_NUMBERING);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_ALL, "0"],
["1", "1"],
["2", "2"],
["3", "3"]
]), 'NUMBER');
this.appendValueInput('SPEED')
.appendField(Blockly.Msg.MIXLY_SPEED + "(0~12)")
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MICROBIT_Direction)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.CLOCKWISE, "1"],
[Blockly.Msg.ANTI_CLOCKWISE, "0"]
]), 'DIRECTION')
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
export const actuator_motor_off = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MOTOR)
.appendField(Blockly.Msg.LCD_NUMBERING);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_ALL, "0"],
["1", "1"],
["2", "2"],
["3", "3"]
]), 'NUMBER')
.appendField(Blockly.Msg.MIXLY_STOP);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
export const sensor_pin_near = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
.appendField(Blockly.Msg.LCD_NUMBERING)
.appendField(new Blockly.FieldDropdown([
["1", "1"],
["2", "2"]
]), 'NUMBER')
.appendField(Blockly.Msg.MIXLY_ESP32_NEAR);
this.setOutput(true, Number);
this.setInputsInline(true);
}
};
export const sensor_while_btn_pressed = {
init: function () {
this.setColour(20);
this.appendValueInput('btn')
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT + Blockly.Msg.MIXLY_BUTTON_PRESSED + Blockly.Msg.MIXLY_BUTTON)
.setCheck(Number);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
this.setInputsInline(true);
}
};
export const sensor_while_is_gesture = {
init: function () {
this.setColour(20);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT + Blockly.Msg.MIXLY_MICROBIT_JS_IS_GESTURE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_shake, "shake"], [Blockly.Msg.MIXLY_UP, "up"], [Blockly.Msg.MIXLY_DOWN, "down"], [Blockly.Msg.MIXLY_LEFT, "left"], [Blockly.Msg.MIXLY_RIGHT, "right"], [Blockly.Msg.MIXLY_MICROBIT_face_up, "face up"], [Blockly.Msg.MIXLY_MICROBIT_face_down, "face down"], [Blockly.Msg.MIXLY_MICROBIT_freefall, "freefall"], ["3g", "3g"], ["6g", "6g"], ["8g", "8g"]]), "gesture");
this.appendStatementInput('DO')
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
this.setInputsInline(true);
}
};
export const sensor_while_is_near = {
init: function () {
this.setColour(20);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT + Blockly.Msg.MIXLY_ESP32_EXTERN_NEAR)
.appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"]]), "near")
.appendField(Blockly.Msg.MIXLY_MITHON_NEAR);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
this.setInputsInline(true);
}
};

View File

@@ -0,0 +1,121 @@
import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';
const PINS_HUE = 230;
export const pins_digital = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.digital), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_analog = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.analog), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_button = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.button), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_pwm = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.pwm), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_interrupt = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.interrupt), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_serial = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.serial_pin), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_builtinimg = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.builtinimg), 'PIN');
this.setOutput(true, "microbit_image");
}
};
export const pins_imglist = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.imglist), 'PIN');
this.setOutput(true);
}
};
export const pins_axis = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.axis), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_brightness = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.brightness), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_tone_notes = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.tone_notes), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_radio_power = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.radio_power), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_radio_datarate = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.radio_datarate), 'PIN');
this.setOutput(true, Number);
}
};

View File

@@ -0,0 +1,646 @@
import * as Blockly from 'blockly/core';
const SENSOR_HUE = 40; //'#9e77c9'//40;
export const sensor_button_is_pressed = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('btn')
.appendField(Blockly.Msg.MIXLY_BUTTON)
.setCheck(Number);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_IS_PRESSED);
this.setOutput(true, Boolean);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_SENOR_IS_PRESSED);
}
};
export const sensor_button_was_pressed = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('btn')
.appendField(Blockly.Msg.MIXLY_BUTTON)
.setCheck(Number);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WAS_PRESSED);
this.setOutput(true, Boolean);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_SENOR_WAS_PRESSED);
}
};
export const sensor_button_get_presses = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('btn')
.appendField(Blockly.Msg.MIXLY_BUTTON)
.setCheck(Number);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_GET_PRESSES);
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN + Blockly.Msg.MIXLY_BUTTON + Blockly.Msg.MIXLY_GET_PRESSES);
}
};
export const sensor_current_gesture1 = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MICROBIT_Current_gesture)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_shake, "shake"], [Blockly.Msg.MIXLY_UP, "up"], [Blockly.Msg.MIXLY_DOWN, "down"], [Blockly.Msg.MIXLY_LEFT, "left"], [Blockly.Msg.MIXLY_RIGHT, "right"], [Blockly.Msg.MIXLY_MICROBIT_face_up, "face up"], [Blockly.Msg.MIXLY_MICROBIT_face_down, "face down"], [Blockly.Msg.MIXLY_MICROBIT_freefall, "freefall"], ["3g", "3g"], ["6g", "6g"], ["8g", "8g"]]), "gesture");
this.setOutput(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('gesture');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT;
var mode1 = Blockly.Msg.MSG.catSensor;
var mode2 = Blockly.Msg.MIXLY_MICROBIT_JS_STATE;
var mode3 = Blockly.Msg.MIXLY_MICROBIT_PERFORMANCE
var TOOLTIPS = {
'shake': Blockly.Msg.MIXLY_MICROBIT_shake,
'up': Blockly.Msg.MIXLY_UP,
'down': Blockly.Msg.MIXLY_DOWN,
'left': Blockly.Msg.MIXLY_LEFT,
'right': Blockly.Msg.MIXLY_RIGHT,
'face up': Blockly.Msg.MIXLY_MICROBIT_face_up,
'face down': Blockly.Msg.MIXLY_MICROBIT_face_down,
'freefall': Blockly.Msg.MIXLY_MICROBIT_freefall,
'3g': '3g',
'6g': '6g',
'8g': '8g'
};
return mode0 + mode1 + mode2 + TOOLTIPS[mode] + mode3;
});
}
};
export const sensor_current_gesture2 = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_WAS_GESTURE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_shake, "shake"], [Blockly.Msg.MIXLY_UP, "up"], [Blockly.Msg.MIXLY_DOWN, "down"], [Blockly.Msg.MIXLY_LEFT, "left"], [Blockly.Msg.MIXLY_RIGHT, "right"], [Blockly.Msg.MIXLY_MICROBIT_face_up, "face up"], [Blockly.Msg.MIXLY_MICROBIT_face_down, "face down"], [Blockly.Msg.MIXLY_MICROBIT_freefall, "freefall"], ["3g", "3g"], ["6g", "6g"], ["8g", "8g"]]), "gesture");
this.setOutput(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('gesture');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT;
var mode1 = Blockly.Msg.MSG.catSensor;
var mode2 = Blockly.Msg.MIXLY_MICROBIT_JS_STATE;
var mode3 = Blockly.Msg.MIXLY_MICROBIT_PERFORMANCE
var TOOLTIPS = {
'shake': Blockly.Msg.MIXLY_MICROBIT_shake,
'up': Blockly.Msg.MIXLY_UP,
'down': Blockly.Msg.MIXLY_DOWN,
'left': Blockly.Msg.MIXLY_LEFT,
'right': Blockly.Msg.MIXLY_RIGHT,
'face up': Blockly.Msg.MIXLY_MICROBIT_face_up,
'face down': Blockly.Msg.MIXLY_MICROBIT_face_down,
'freefall': Blockly.Msg.MIXLY_MICROBIT_freefall,
'3g': '3g',
'6g': '6g',
'8g': '8g'
};
return mode0 + mode1 + mode2 + TOOLTIPS[mode] + mode3;
});
}
};
export const controls_attachGestureInterrupt = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT_GESTURE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_shake, "shake"], [Blockly.Msg.MIXLY_UP, "up"], [Blockly.Msg.MIXLY_DOWN, "down"], [Blockly.Msg.MIXLY_LEFT, "left"], [Blockly.Msg.MIXLY_RIGHT, "right"], [Blockly.Msg.MIXLY_MICROBIT_face_up, "face up"], [Blockly.Msg.MIXLY_MICROBIT_face_down, "face down"], [Blockly.Msg.MIXLY_MICROBIT_freefall, "freefall"], ["3g", "3g"], ["6g", "6g"], ["8g", "8g"]]), "gesture");
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('gesture');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT;
var mode1 = Blockly.Msg.MSG.catSensor;
var mode2 = Blockly.Msg.MIXLY_MICROBIT_JS_STATE;
var mode3 = Blockly.Msg.MIXLY_MICROBIT_PERFORMANCE
var TOOLTIPS = {
'shake': Blockly.Msg.MIXLY_MICROBIT_shake,
'up': Blockly.Msg.MIXLY_UP,
'down': Blockly.Msg.MIXLY_DOWN,
'left': Blockly.Msg.MIXLY_LEFT,
'right': Blockly.Msg.MIXLY_RIGHT,
'face up': Blockly.Msg.MIXLY_MICROBIT_face_up,
'face down': Blockly.Msg.MIXLY_MICROBIT_face_down,
'freefall': Blockly.Msg.MIXLY_MICROBIT_freefall,
'3g': '3g',
'6g': '6g',
'8g': '8g'
};
return mode0 + mode1 + mode2 + TOOLTIPS[mode] + mode3;
});
}
};
export const controls_GestureLists = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_shake, "shake"], [Blockly.Msg.MIXLY_UP, "up"], [Blockly.Msg.MIXLY_DOWN, "down"], [Blockly.Msg.MIXLY_LEFT, "left"], [Blockly.Msg.MIXLY_RIGHT, "right"], [Blockly.Msg.MIXLY_MICROBIT_face_up, "face up"], [Blockly.Msg.MIXLY_MICROBIT_face_down, "face down"], [Blockly.Msg.MIXLY_MICROBIT_freefall, "freefall"], ["3g", "3g"], ["6g", "6g"], ["8g", "8g"]]), "gesture");
this.setInputsInline(true);
this.setOutput(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('gesture');
var TOOLTIPS = {
'shake': Blockly.Msg.MIXLY_MICROBIT_shake,
'up': Blockly.Msg.MIXLY_UP,
'down': Blockly.Msg.MIXLY_DOWN,
'left': Blockly.Msg.MIXLY_LEFT,
'right': Blockly.Msg.MIXLY_RIGHT,
'face up': Blockly.Msg.MIXLY_MICROBIT_face_up,
'face down': Blockly.Msg.MIXLY_MICROBIT_face_down,
'freefall': Blockly.Msg.MIXLY_MICROBIT_freefall,
'3g': '3g',
'6g': '6g',
'8g': '8g'
};
return TOOLTIPS[mode];
});
}
};
export const controls_attachGestureInterrupt2 = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_WAS_GESTURE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MICROBIT_shake, "shake"], [Blockly.Msg.MIXLY_UP, "up"], [Blockly.Msg.MIXLY_DOWN, "down"], [Blockly.Msg.MIXLY_LEFT, "left"], [Blockly.Msg.MIXLY_RIGHT, "right"], [Blockly.Msg.MIXLY_MICROBIT_face_up, "face up"], [Blockly.Msg.MIXLY_MICROBIT_face_down, "face down"], [Blockly.Msg.MIXLY_MICROBIT_freefall, "freefall"], ["3g", "3g"], ["6g", "6g"], ["8g", "8g"]]), "gesture");
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('gesture');
var mode0 = Blockly.Msg.CONTROLS_IF_MSG_IF;
var mode1 = Blockly.Msg.MSG.catSensor;
var mode2 = Blockly.Msg.MIXLY_MICROBIT_JS_WAS_GESTURE;
var mode3 = Blockly.Msg.MIXLY_MICROBIT_PERFORMANCE;
var TOOLTIPS = {
'shake': Blockly.Msg.MIXLY_MICROBIT_shake,
'up': Blockly.Msg.MIXLY_UP,
'down': Blockly.Msg.MIXLY_DOWN,
'left': Blockly.Msg.MIXLY_LEFT,
'right': Blockly.Msg.MIXLY_RIGHT,
'face up': Blockly.Msg.MIXLY_MICROBIT_face_up,
'face down': Blockly.Msg.MIXLY_MICROBIT_face_down,
'freefall': Blockly.Msg.MIXLY_MICROBIT_freefall,
'3g': '3g',
'6g': '6g',
'8g': '8g'
};
return mode0 + mode1 + mode2 + TOOLTIPS[mode] + mode3;
});
}
};
export const sensor_get_acceleration = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_ACCELERATION)
.appendField(new Blockly.FieldDropdown([
["x", "x"],
["y", "y"],
["z", "z"],
["(x,y,z)", "values"]
]), "key");
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_ACCELERATION);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('key');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET;
var mode1 = Blockly.Msg.MIXLY_MICROBIT_Direction;
var mode2 = Blockly.Msg.MIXLY_MICROBIT_JS_ACCELERATION1;
var TOOLTIPS = {
'x': 'x',
'y': 'y',
'z': 'z',
'(x,y,z)': Blockly.Msg.MIXLY_MICROBIT_Shiliang_Direction,
};
return mode0 + TOOLTIPS[mode] + mode1 + mode2;
});
}
};
export const sensor_set_acceleration = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_SET_ACCELERATION)
.appendField(new Blockly.FieldDropdown([
["1g", "AcceleratorRange.OneG"],
["2g", "AcceleratorRange.TwoG"],
["4g", "AcceleratorRange.FourG"],
["8g", "AcceleratorRange.EightG"]
]), "key");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_SET_ACCELERATION);
}
};
export const sensor_get_gestures = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_GET)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_MICROBIT_JS_GET_GESTURE, 'all'],
[Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT_GESTURE, 'current']
]), 'GES')
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_GESTURE);
this.setOutput(true, Number);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('GES');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_JS_GET;
var mode1 = Blockly.Msg.MIXLY_MICROBIT_JS_GESTURE;
var TOOLTIPS = {
'all': Blockly.Msg.MIXLY_MICROBIT_JS_GET_GESTURE,
'current': Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT_GESTURE
};
return mode0 + TOOLTIPS[mode] + mode1;
});
}
};
export const sensor_current_gesture = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT_GESTURE)
this.setOutput(true, Number);
this.setInputsInline(true);
}
};
export const sensor_light_level = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_LIGHT_LEVEL)
this.setOutput(true, Number);
this.setInputsInline(true);
}
};
export const sensor_calibrate_compass = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CALIBRATE_COMPASS)
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_CALIBRATE_COMPASS);
}
};
export const sensor_is_compass_calibrated = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_IS_COMPASS_CALIBRATED)
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_IS_COMPASS_CALIBRATED1);
}
};
export const sensor_compass_heading = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_BY_ANGLE)
this.setOutput(true, Number);
this.setInputsInline(true);
}
};
export const sensor_temperature = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_Board_temperature)
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Board_temperature);
}
};
export const sensor_field_strength = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_GET_COMPASS)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_MICROBIT_JS_FIELD_STRENGTH, 'get_field_strength'],
[Blockly.Msg.MIXLY_MICROBIT_JS_BY_ANGLE, 'heading'],
["x", "get_x"],
["y", "get_y"],
["z", "get_z"],
]), 'compass');
this.setOutput(true, Number);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('compass');
var mode0 = Blockly.Msg.MIXLY_MICROBIT_JS_GET_COMPASS;
var TOOLTIPS = {
'strength': Blockly.Msg.MIXLY_MICROBIT_JS_FIELD_STRENGTH,
'heading': Blockly.Msg.MIXLY_MICROBIT_JS_BY_ANGLE
};
return mode0 + TOOLTIPS[mode];
});
}
};
export const sensor_rotation = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_ROTATION)
.appendField(new Blockly.FieldDropdown([
["pitch", "Rotation.Pitch"],
["roll", "Rotation.Roll"]
]), "key");
this.setOutput(true, Number);
this.setInputsInline(true);
}
};
export const sensor_magnetic = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MAGETIC_FORCE)
.appendField(new Blockly.FieldDropdown([
["x", "Dimension.X"],
["y", "Dimension.Y"],
["z", "Dimension.Z"],
["strength", "Dimension.Strength"]
]), "key");
this.setOutput(true, Number);
this.setInputsInline(true);
}
};
export const sensor_distance_hrsc04 = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_CHAOSHENGBO)
.appendField("Trig")
.appendField(new Blockly.FieldDropdown([["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]]), "Trig")
.appendField("Echo")
.appendField(new Blockly.FieldDropdown([["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]]), "Echo");
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip("");
}
};
export const sensor_distance_hrsc04_ = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_CHAOSHENGBO)
.appendField("Trig")
.appendField(new Blockly.FieldDropdown([["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]]), "Trig")
.appendField("Echo")
.appendField(new Blockly.FieldDropdown([["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]]), "Echo");
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip();
}
};
export const DS1307_init = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_RTCINIT);
//this.appendDummyInput("").setAlign(Blockly.inputs.Align.RIGHT).appendField(new Blockly.FieldDropdown(RTCTypeList), 'RTCType');
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('myRTC');
this.appendValueInput("SDA")
.appendField("SDA#")
.setCheck(Number);
this.appendValueInput("SCL")
.appendField("SCL#")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_RTCINIT);
},
//mutation有问题暂时弃用
/*mutationToDom: function() {
var container = document.createElement('mutation');
var RTCType = (this.getFieldValue('RTCType') == 'DS1302');
console.log('======change in mutationToDom==========')
console.log(RTCType);
container.setAttribute('RTCType', RTCType);
return container;
},
domToMutation: function(xmlElement) {
var type = (xmlElement.getAttribute('RTCType') == 'true');
console.log('======change in domToMutation==========')
console.log(type);
this.updateShape_(type);
},
updateShape_: function(type) {
// Add or remove reset pin.
console.log('======change in updateShape_==========')
console.log(type);
if (type) {
console.log('why not me?')
this.appendValueInput("RST")
.appendField("RST#")
.setCheck(Number);
} else{
/*if (this.childBlocks_.length > 0) {
if (this.childBlocks_[length-1].type == 'Number') {
this.childBlocks_[length-1].unplug();
break;
}
}
this.removeInput('RST');
}
}*/
};
var RTC_TIME_TYPE = [
[Blockly.Msg.MIXLY_YEAR, "Year"],
[Blockly.Msg.MIXLY_MONTH, "Month"],
[Blockly.Msg.MIXLY_DAY, "Day"],
[Blockly.Msg.MIXLY_HOUR, "Hour"],
[Blockly.Msg.MIXLY_MINUTE, "Minute"],
[Blockly.Msg.MIXLY_SECOND, "Second"],
[Blockly.Msg.MIXLY_WEEK, "Week"],
[Blockly.Msg.MIXLY_MIX1, "Mix1"],
[Blockly.Msg.MIXLY_MIX2, "Mix2"],
];
//传感器-实时时钟块_获取时间
export const RTC_get_time = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RTCGETTIME);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('myRTC');
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldDropdown(RTC_TIME_TYPE), "TIME_TYPE");
this.setInputsInline(true);
this.setOutput(true, Number);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('TIME_TYPE');
var mode0 = Blockly.Msg.MIXLY_RTCGETTIME;
var TOOLTIPS = {
'Year': Blockly.Msg.MIXLY_YEAR,
'Month': Blockly.Msg.MIXLY_MONTH,
'Day': Blockly.Msg.MIXLY_DAY,
'Hour': Blockly.Msg.MIXLY_HOUR,
'Minute': Blockly.Msg.MIXLY_MINUTE,
'Second': Blockly.Msg.MIXLY_SECOND,
'Week': Blockly.Msg.MIXLY_WEEK,
'Mix1': Blockly.Msg.MIXLY_MIX1,
'Mix2': Blockly.Msg.MIXLY_MIX2
};
return mode0 + TOOLTIPS[mode];
});
}
};
export const RTC_set_time = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RTCSETTIME)
.appendField('myRTC');
this.appendValueInput("hour")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(" " + Blockly.Msg.MIXLY_HOUR);
this.appendValueInput("minute")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(" " + Blockly.Msg.MIXLY_MINUTE);
this.appendValueInput("second")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(" " + Blockly.Msg.MIXLY_SECOND);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(false);
this.setTooltip(Blockly.Msg.MIXLY_RTCSETTIME + Blockly.Msg.MIXLY_MIX2);
}
};
export const RTC_set_date = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RTCSETDATE)
.appendField('myRTC');
this.appendValueInput("year")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(" " + Blockly.Msg.MIXLY_YEAR);
this.appendValueInput("month")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(" " + Blockly.Msg.MIXLY_MONTH);
this.appendValueInput("day")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(" " + Blockly.Msg.MIXLY_DAY);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_RTCSETDATE + Blockly.Msg.MIXLY_MIX1);
}
};
export const sensor_compass_reset = {
init: function () {
this.jsonInit({
"colour": SENSOR_HUE,
"nextStatement": null,
"previousStatement": null,
"helpUrl": "https://microbit-micropython.readthedocs.io/en/latest/music.html#music.reset",
"message0": Blockly.Msg.MIXLY_MICROBIT_Reset_COMPASS
});
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Reset_COMPASS);
}
};
export const sensor_light = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_LIGHT);
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MICROBIT_SENSOR_LIGHT_TOOLTIP);
}
};
export const sensor_hrsc04_init = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_HCSR04_INIT)
//.appendField("sonar")
.appendField("Trig")
.appendField(new Blockly.FieldDropdown([["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]]), "Trig")
.appendField("Echo")
.appendField(new Blockly.FieldDropdown([["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P4", "4"], ["P5", "5"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P19", "19"], ["P20", "20"]]), "Echo");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip();
}
};
var TCS34725_GETRGB = [
[Blockly.Msg.COLOUR_RGB_RED, "0"],
[Blockly.Msg.COLOUR_RGB_GREEN, "1"],
[Blockly.Msg.COLOUR_RGB_BLUE, "2"]
];
export const TCS34725_Get_RGB = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.TCS34725_Get_RGB)
.appendField(new Blockly.FieldDropdown(TCS34725_GETRGB), "TCS34725_COLOR");
this.setInputsInline(true);
this.setOutput(true);
}
};

View File

@@ -0,0 +1,165 @@
import * as Blockly from 'blockly/core';
const SERIAL_HUE = 65; //'#58a8de'//65;
export const serial_print = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT", String)
.appendField("Serial " + Blockly.Msg.MIXLY_SERIAL_PRINT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);
}
};
export const serial_println = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT", String)
.appendField("Serial " + Blockly.Msg.MIXLY_SERIAL_PRINTLN);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.TEXT_PRINT_Huanhang_TOOLTIP + Blockly.Msg.TEXT_PRINT_TOOLTIP);
}
};
//打印16进制数
export const serial_print_hex = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT", Number)
.appendField("Serial " + Blockly.Msg.MIXLY_SERIAL_PRINT + " (" + Blockly.Msg.MATH_HEX + ")")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.TEXT_PRINT_HEX_TOOLTIP);
}
};
export const serial_receive_data_event = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput('char_marker')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_SERIAL_WHEN_CONTAIN_DATA)
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
}
};
export const serial_readstr = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField("Serial " + Blockly.Msg.MIXLY_SERIAL_READSTR);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_SERIAL_READ_STR);
}
};
export const serial_any = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField("Serial " + Blockly.Msg.MIXLY_SERIAL_AVAILABLE);
this.setOutput(true, Boolean);
this.setTooltip(Blockly.Msg.MIXLY_SERIAL_AVAILABLE1);
}
};
export const serial_readline = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_SERIAL_READ_LINE);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_SERIAL_READ_LINE1);
}
};
export const serial_readstr_until = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField("Serial " + Blockly.Msg.MIXLY_SERIAL_READSTR_UNTIL)
.appendField(new Blockly.FieldDropdown([
["new line", "serial.delimiters(Delimiters.NewLine)"],
[",", "serial.delimiters(Delimiters.Comma)"],
["$", "serial.delimiters(Delimiters.Dollar)"],
[":", "serial.delimiters(Delimiters.Colon)"],
[".", "serial.delimiters(Delimiters.Fullstop)"],
["#", "serial.delimiters(Delimiters.Hash)"]
]), "char_marker");
this.setInputsInline(true);
this.setOutput(true, String);
}
};
export const serial_softserial = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("RX", Number)
.appendField(Blockly.Msg.MIXLY_SETUP)
.appendField("RX#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("TX", Number)
.appendField("TX#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SERIAL_BEGIN)
.appendField(new Blockly.FieldDropdown([['115200', '115200'], ['57600', '57600'], ['38400', '38400'], ['28800', '28800'], ['19200', '19200'], ['14400', '14400'], ['9600', '9600']]), 'baudrate');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_SERIAL_softserial);
}
};
export const serial_begin = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField("Serial " + Blockly.Msg.MIXLY_SERIAL_BEGIN)
.appendField(new Blockly.FieldDropdown([['115200', '115200'], ['57600', '57600'], ['38400', '38400'], ['28800', '28800'], ['19200', '19200'], ['14400', '14400'], ['9600', '9600']]), 'baudrate');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.LISTS_SET_INDEX_SET + Blockly.Msg.MIXLY_SERIAL_BEGIN);
}
};
export const IO_input = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("VAR")
.appendField(Blockly.Msg.blockpy_inout_raw_input)
.setCheck(String);
this.setOutput(true);
this.setTooltip(Blockly.Msg.INOUT_input_TOOLTIP);
}
}
export const IO_print = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("VAR")
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.BLOCKPY_PRINT_TOOLTIP);
}
};
export const IO_print_inline = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("VAR")
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);
}
};

View File

@@ -0,0 +1,62 @@
import * as Blockly from 'blockly/core';
const SYSTEM_HUE = 120;
export const base_delay = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendValueInput("DELAY_TIME", Number)
.appendField(Blockly.Msg.MIXLY_DELAY + '(' + Blockly.Msg.MIXLY_MILLIS + ')')
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
}
};
export const controls_millis = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_RUNTIME + "(" + Blockly.Msg.MIXLY_MILLIS + ")");
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_MILLIS);
}
};
export const Panic_with_status_code = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendValueInput("STATUS_CODE", Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_Panic_with_status_code)
.setCheck(Number);
this.setPreviousStatement(true, null);
// this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Panic_with_status_code);
}
};
export const reset = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_Reset_micro);
this.setPreviousStatement(true);
// this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_Reset_micro);
}
};
export const controls_uname = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_CONTORL_UNAME);
this.setInputsInline(true);
this.setOutput(true);
this.setTooltip(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN + Blockly.Msg.MIXLY_MICROBIT_PY_CONTORL_UNAME);
}
};