初始化提交

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,276 @@
import * as Blockly from 'blockly/core';
const ACTUATOR_HUE = 100;
export const actuator_Servo_init = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput()
.appendField("初始化");
this.appendDummyInput()
.appendField("舵机");
this.appendValueInput("PIN", Number)
.appendField("管脚")
.setCheck(Number);
this.appendValueInput('time')
.appendField("定时器")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip();
}
};
export const actuator_Servo = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput()
.appendField("设置");
this.appendDummyInput()
.appendField("舵机");
this.appendValueInput("PIN", Number)
.appendField("管脚")
.setCheck(Number);
this.appendValueInput('range')
.appendField("角度")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip();
}
};
export const actuator_PAC9685_init = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput()
.appendField("初始化");
this.appendDummyInput()
.appendField("16路舵机");
this.appendValueInput('address')
.appendField("地址")
.setCheck(Number);
this.appendValueInput('SUB')
.setCheck("var")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("通信");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("使用PCA9685驱动16路舵机并备注IIC端口");
}
};
export const actuator_PAC9685_Servo = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendDummyInput()
.appendField("设置");
this.appendDummyInput()
.appendField("16路舵机");
this.appendValueInput("index")
.appendField("编号")
.setCheck(Number);
this.appendValueInput('range')
.appendField("角度")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("使用PCA9685驱动16路舵机输入编号机角度");
}
};
export const actuator_rgb_init = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.appendField("初始化")
.setCheck("var");
this.appendValueInput("PIN", Number)
.appendField("管脚")
.setCheck(Number);
this.appendValueInput('num')
.appendField("灯数")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip();
}
};
export const actuator_rgb_set = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.appendField("")
.setCheck("var");
this.appendValueInput('num')
.appendField("灯号")
.setCheck(Number);
this.appendValueInput('R')
.appendField("R值")
.setCheck(Number);
this.appendValueInput('G')
.appendField("G值")
.setCheck(Number);
this.appendValueInput('B')
.appendField("B值")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip();
}
};
export const actuator_rgb_display = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("生效");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip();
}
};
export const actuator_ms32006_init = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.appendField("初始化")
.setCheck("var");
this.appendDummyInput()
.appendField("电机驱动");
this.appendDummyInput()
.appendField("地址")
.appendField(new Blockly.FieldDropdown([['A', 'ms32006.ADDRESS_A'], ['B', 'ms32006.ADDRESS_B']]), 'mode');
this.appendValueInput('SUB1')
.setCheck("var")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("通信");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("初始化MS32006电机驱动使用I2C通信");
}
};
export const actuator_ms32006_dcmotor = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.appendField("直流电机")
.setCheck("var");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_Direction)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.CLOCKWISE, "ms32006.MOT_CW"],
[Blockly.Msg.ANTI_CLOCKWISE, "ms32006.MOT_CCW"],
[Blockly.Msg.MOTOR_N, "ms32006.MOT_N"],
[Blockly.Msg.MOTOR_P, "ms32006.MOT_P"]
]), "direction");
this.appendValueInput('speed')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_STEPPER_SET_SPEED);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("设置直流电机的状态及转速(0-100)");
}
};
export const actuator_ms32006_stepper = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.appendField("步进电机")
.setCheck("var");
this.appendDummyInput()
.appendField("选择")
.appendField(new Blockly.FieldDropdown([['A', 'ms32006.MOT_A'], ['B', 'ms32006.MOT_B']]), 'mode');
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_Direction)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.CLOCKWISE, "ms32006.MOT_CW"],
[Blockly.Msg.ANTI_CLOCKWISE, "ms32006.MOT_CCW"]
]), "direction");
this.appendValueInput('speed')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("转速");
this.appendValueInput('steps')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("步数");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("设置步进电机的状态、转速、步数(0-2047)");
}
};
//-新20211221------PID算法暂时放此处------------------------------------------//
export const PID_init = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.setCheck("var")
.appendField("初始化");
this.appendValueInput("P", Number)
.appendField("P值")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("I", Number)
.appendField("I值")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("D", Number)
.appendField("D值")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip("初始化PID算法");
}
};
//-新20211221------PID算法暂时放此处------------------------------------------//
export const PID_get_pid = {
init: function () {
this.setColour(ACTUATOR_HUE);
this.appendValueInput('SUB')
.setCheck("var")
.appendField("");
this.appendDummyInput()
.appendField("运算");
this.appendValueInput("error")
.appendField("偏移量")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("scaler")
.appendField("定标量")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("根据参数返回运算结果");
}
};

View File

@@ -0,0 +1,360 @@
import * as Blockly from 'blockly/core';
const AI_HUE = "#55839A";
export const tuple_anchor = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('anchor'), 'VAR')
.appendField('锚点参数= (')
.appendField(new Blockly.FieldTextInput('1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025'), 'TEXT')
.appendField(')');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("锚点参数");
}
};
export const tuple_calss = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('calss'), 'VAR')
.appendField('物品名称= [')
.appendField(new Blockly.FieldTextInput("'name1', 'name2', 'name3', 'name4'"), 'TEXT')
.appendField(']');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("将要识别的物品名称");
}
};
export const KPU_load = {
init: function () {
this.setColour(AI_HUE);
this.appendValueInput('SUB')
.appendField("")
.setCheck("var");
this.appendValueInput('path')
.appendField("模型加载")
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("从flash系统中加载模型");
}
};
export const KPU_load1 = {
init: function () {
this.setColour(AI_HUE);
this.appendValueInput('SUB')
.appendField("")
.setCheck("var");
this.appendValueInput('path')
.appendField("模型路径")
.setCheck(String);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("从文件系统中加载模型");
}
};
export const KPU_init_yolo2 = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("yolo2")
.appendField("初始化");
this.appendValueInput('SUB')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("网络模型")
.setCheck("var");
this.appendValueInput('threshold')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("概率阈值")
.setCheck(Number);
this.appendValueInput('nms_value')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("box_iou门限")
.setCheck(Number);
this.appendValueInput('anchor_num')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("锚点数")
.setCheck(Number);
this.appendValueInput('anchor')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("锚点参数");
//this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("初始化yolo2网络");
}
};
export const KPU_run_yolo2 = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("yolo2")
.appendField("运行网络");
this.appendValueInput('SUB')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("模型")
.setCheck("var");
this.appendValueInput('VAR')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("图像");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("运行yolo2网络");
}
};
export const KPU_forward = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("yolo2")
.appendField("前向运算");
this.appendValueInput('SUB')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("模型")
.setCheck("var");
this.appendValueInput('VAR')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("图像");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("运行网络前向运算");
}
};
export const KPU_analysis = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput()
.appendField("yolo2")
.appendField("模型解析");
this.appendValueInput('VAR')
.appendField("对象")
.setCheck("var");
this.appendDummyInput()
.appendField("获取")
.appendField(new Blockly.FieldDropdown([
["坐标-x", "x"],
["坐标-y", "y"],
["标识号", "classid"],
["置信度", "value"]
]), "key");
this.setOutput(true);
//this.setInputsInline(true);
this.setTooltip("对于模型解析,获取模型识别结果的目标坐标、标识好、置信度");
}
};
export const aionenet_nic_init = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_OneNET")
.appendField("连接WiFi");
this.appendValueInput('account')
.appendField("名称")
.setCheck(String);
this.appendValueInput('password')
.appendField("密码")
.setCheck(String);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("AI-Onenet平台 连接WiFi");
}
};
export const aionenet_token = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_OneNET")
.appendField("获鉴权码");
this.appendValueInput('account')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("账号")
.setCheck(String);
this.appendValueInput('password')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("密码")
.setCheck(String);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("AI-Onenet平台 需要注册平台才能使用账号获取用户鉴权码鉴权码一般24小时有效");
}
};
export const aionenet_API = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_OneNET")
.appendField("调取API");
this.appendValueInput('VAR')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("图像");
this.appendDummyInput()
.appendField("识别")
.appendField(new Blockly.FieldDropdown([
["人脸检测", "FACE_RECO"],
["人脸分析", "FACE_ATTRIBUTE"],
["人体检测", "BODY_RECO"],
["图像抄表", "AMMETER_READ"],
["内容测评", "IDENTIFY_PORN"],
["车牌信息", "NUMBER_PLATE_RECOGNITION"],
["宠物种类", "CAT_DOG_DETECTION"],
["火灾检测", "FIRE_DETECTION"]
]), "api");
this.appendValueInput('token')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("鉴权码")
.setCheck(String);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("AI-Onenet平台 调用平台API返回列表识别结果参数");
}
};
export const ailocal_training = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_Local")
.appendField("模型训练");
this.appendValueInput('calss')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("物品");
this.appendValueInput('sample')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("训练量")
.setCheck(Number);
this.appendValueInput('save')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("保存")
.setCheck(String);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("AI-Local本地模型训练 需要识别的物品名称、每个物品训练数量、保存的名称");
}
};
export const ailocal_loading = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_Local")
.appendField("模型加载");
this.appendValueInput('path')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("路径")
.setCheck(String);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("AI-Local 加载已经训练好的本地模型");
}
};
export const ailocal_predict = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_Local")
.appendField("运行模型");
this.appendValueInput('calss')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("物品");
this.appendValueInput('VAR')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("图像");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("AI-Local 采集图像运行模型将返回识别的物品名、置信度");
}
};
//---开始------------新增---20210302---------------------------------------------------
export const ai_face_init = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_Face")
.appendField("初始化 加载");
this.appendValueInput('FD')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("模型FD:")
.setCheck(String);
this.appendValueInput('LD')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("模型LD:")
.setCheck(String);
this.appendValueInput('FE')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("模型FE:")
.setCheck(String);
//this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("人脸分辨,初始化");
}
};
export const ai_face_train = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput("")
.appendField("AI_Face")
.appendField("运行识别");
this.appendValueInput('names')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("人名");
this.appendValueInput('VAR')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("图象");
this.appendValueInput('threshold')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("阈值")
.setCheck(Number);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("人脸分辨识别到人脸返回True无人脸返回False");
}
};
export const ai_face_info = {
init: function () {
this.setColour(AI_HUE);
this.appendDummyInput()
.appendField("AI_Face")
.appendField("识别解析");
this.appendDummyInput()
.appendField("获取")
.appendField(new Blockly.FieldDropdown([
["识别人名", "info_name"],
["置信度 %", "info_score"],
["脸部坐标", "info_face"],
["三官坐标", "info_organs"]
]), "key");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("人脸分辨,识别到人物名称,置信度,脸部坐标,三官(眼睛x2、鼻子、嘴巴*2)坐标");
}
};
//---开始------------新增---20210302---------------------------------------------------

View File

@@ -0,0 +1,161 @@
import * as Blockly from 'blockly/core';
const AV_HUE = "#2CAAD2";
export const spk_init = {
init: function () {
this.setColour(AV_HUE);
this.appendValueInput('SUB')
.setCheck("var")
.appendField("初始化");
this.appendValueInput("BCK", Number)
.appendField("BCK#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("WS", Number)
.appendField("WS#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("DAT", Number)
.appendField("DAT#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip("初始化配置扬声器,用于语音播放");
}
};
export const mic_init = {
init: function () {
this.setColour(AV_HUE);
this.appendValueInput('SUB')
.setCheck("var")
.appendField("初始化");
// this.appendValueInput("BCK", Number)
// .appendField("BCK#")
// .setCheck(Number)
// .setAlign(Blockly.inputs.Align.RIGHT)
// this.appendValueInput("WS", Number)
// .appendField("WS#")
// .setCheck(Number)
// .setAlign(Blockly.inputs.Align.RIGHT);
// this.appendValueInput("DAT", Number)
// .appendField("DAT#")
// .setCheck(Number)
// .setAlign(Blockly.inputs.Align.RIGHT);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip("初始化配置扬声器,用于语音播放");
}
};
//-新20210329------音频播放-------------------------------------------//
export const audio_play = {
init: function () {
this.setColour(AV_HUE);
this.appendDummyInput()
.appendField("Audio 音频播放");
this.appendValueInput('path')
.appendField("路径")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String);
this.appendValueInput('SUB')
.setCheck("var")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("设备");
this.appendValueInput('volume')
.appendField("音量(%)")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(Number);
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("音频播放");
}
};
//-新20210329------音频录制-------------------------------------------//
export const audio_record = {
init: function () {
this.setColour(AV_HUE);
this.appendDummyInput()
.appendField("Audio 音频录制");
this.appendValueInput('path')
.appendField("路径")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String);
this.appendValueInput('SUB')
.setCheck("var")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("设备");
this.appendValueInput('time')
.appendField("时长(s)")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(Number);
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("音频录制");
}
};
//-新20210329------视频播放-------------------------------------------//
export const video_play = {
init: function () {
this.setColour(AV_HUE);
this.appendDummyInput()
.appendField("Video 视频播放");
this.appendValueInput('path')
.appendField("路径")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String);
this.appendValueInput('SUB')
.setCheck("var")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("设备");
this.appendValueInput('volume')
.appendField("音量(%)")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(Number);
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("视频播放");
}
};
//-新20210329------视频录制-------------------------------------------//
export const video_record = {
init: function () {
this.setColour(AV_HUE);
this.appendDummyInput()
.appendField("Video 视频录制");
this.appendValueInput('path')
.appendField("路径")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String);
this.appendValueInput('SUB')
.setCheck("var")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("设备");
this.appendValueInput('time')
.appendField("时长(s)")
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(Number);
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("视频录制");
}
};

View File

@@ -0,0 +1,265 @@
import * as Blockly from 'blockly/core';
const CAMERA_HUE = "#bc9705"; //'#9e77c9'//40;
export const mode = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
["彩色图(YUV422)", "sensor.YUV422"],
["彩色图(RGB565)", "sensor.RGB565"],
["灰度图", "sensor.GRAYSCALE"]
]), "flag");
this.setOutput(true);
this.setTooltip();
}
};
export const size = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
["320x240", "sensor.QVGA"],
["240x240", "sensor.B240X240"],
["128x128", "sensor.B128X128"],
["64x64", "sensor.B64X64"]
]), "flag");
this.setOutput(true);
this.setTooltip();
}
};
export const camera_init = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera")
.appendField("初始化");
this.appendValueInput('key1')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("帧格式");
this.appendValueInput('key2')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("帧大小");
this.appendValueInput('key3')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("图捕捉");
this.appendValueInput('key4')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("跳帧数"); //this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("初始化摄像头,会自动扫描并获取摄像头型号");
}
};
export const camera_reset = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendDummyInput()
.appendField("初始化");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("初始化摄像头,会自动扫描并获取摄像头型号");
}
};
export const camera_set_pixformat = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('key')
.appendField("帧格式")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("设置摄像头输出格式");
}
};
export const camera_set_framesize = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('key')
.appendField("帧大小")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("设置摄像头输出帧大小");
}
};
export const camera_run = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('key')
.appendField("图捕捉")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("开启图像捕捉功能");
}
};
export const camera_skip_frames = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('frame')
.appendField("跳帧数")
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("摄像头跳过指定帧数");
}
};
export const camera_snapshot = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendDummyInput()
.appendField("获取图像");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("控制摄像头捕捉图像");
}
};
export const camera_shutdown = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('key')
.appendField("设为")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("启动/关闭摄像头");
}
};
export const camera_set_hmirror = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('key')
.appendField("水平镜像")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("设置摄像头水平镜像");
}
};
export const camera_set_vflip = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('key')
.appendField("垂直镜像")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("设置摄像头垂直镜像");
}
};
export const camera_set_colorbar = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendValueInput('key')
.appendField("彩条模式")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("将摄像头设置为彩条模式");
}
};
export const camera_getinfo = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendDummyInput()
.appendField("获取")
.appendField(new Blockly.FieldDropdown([
["分辨率宽度", "width"],
["分辨率高度", "height"],
["当前增益值", "get_gain_db"],
["帧缓冲图像", "get_fb"],
["类型型号ID", "get_id"]
]), "key");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("获取当前摄像头信息");
}
};
export const camera_setmun = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendDummyInput()
.appendField("设置")
.appendField(new Blockly.FieldDropdown([
["对比度", "set_contrast"],
["亮度值", "set_brightness"],
["增益值", "set_auto_gain"],
["饱和度", "set_saturation"]
]), "key");
this.appendValueInput('num')
.appendField("值为")
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("设置摄像头对比度、亮度、增益、饱和度");
}
};
export const camera_set_windowing = {
init: function () {
this.setColour(CAMERA_HUE);
this.appendDummyInput()
.appendField("Camera");
this.appendDummyInput()
.appendField("设置窗口");
this.appendValueInput('numa')
.appendField("宽为")
.setCheck(Number);
this.appendValueInput('numb')
.appendField("高为")
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("设置摄像头窗口大小");
}
};

View File

@@ -0,0 +1,453 @@
import * as Blockly from 'blockly/core';
const COMMUNICATE_HUE = 140;
export const communicate_ir_recv = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('PIN')
.appendField(Blockly.Msg.MIXLY_IR_RECEIVE);
this.appendDummyInput()
.appendField("获取编码");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_I2C_SCAN);
}
};
export const communicate_i2c_init = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('SUB')
.appendField("I2C " + Blockly.Msg.MIXLY_SETUP)
.setCheck("var");
this.appendValueInput("TX", Number)
.appendField("SCL#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("RX", Number)
.appendField("SDA#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendDummyInput()
.appendField("通道")
.appendField(new Blockly.FieldDropdown([['0', 'I2C0'], ['1', 'I2C1'], ['2', 'I2C2']]), 'mode');
this.appendValueInput('freq')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_FREQUENCY)
.setAlign(Blockly.inputs.Align.RIGHT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_I2C_INIT);
}
};
//--------新增-------------------------------------------------------
export const communicate_i2s_init = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('SUB')
.setCheck("var")
.appendField("I2S 初始化");
this.appendDummyInput()
.appendField("设备")
.appendField(new Blockly.FieldDropdown([['麦克风', 'mic'], ['扬声器', 'spk']]), 'mode');
this.appendValueInput("BCK", Number)
.appendField("BCK#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("WS", Number)
.appendField("WS#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("DAT", Number)
.appendField("DAT#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput('sample')
.appendField("采样率")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_I2C_INIT);
}
};
// 以下被禁用
export const communicate_i2c_read = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.appendField("I2C")
.setCheck("var");
this.appendValueInput('address')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_ESP32_RNUMBER);
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_MATH_BYTE);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_READ);
}
}
export const communicate_i2c_write = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.appendField("I2C")
.setCheck("var");
this.appendValueInput('address')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_ESP32_WNUMBER);
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_VALUE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_WRITE);
}
}
export const communicate_i2c_scan = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField(Blockly.Msg.MIXLY_ESP32_I2C_SCAN1);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_I2C_SCAN2);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_I2C_SCAN);
}
}
export const communicate_spi_init = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField(Blockly.Msg.MIXLY_ESP32_SPI_INIT);
this.appendValueInput('freq')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_SERIAL_BEGIN);
this.appendValueInput('polarity')
.setCheck(Number)
.appendField('polarity');
this.appendValueInput('phase')
.setCheck(Number)
.appendField('phase');
this.appendValueInput('sck')
.setCheck(Number)
.appendField('SCK');
this.appendValueInput('mosi')
.setCheck(Number)
.appendField('MOSI');
this.appendValueInput('miso')
.setCheck(Number)
.appendField('MISO');
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_INIT_TOOLTIP);
}
};
export const communicate_spi_set = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField(Blockly.Msg.MIXLY_SETTING + " SPI")
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_SERIAL_BEGIN);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_SET);
}
};
export const communicate_spi_buffer = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField(Blockly.Msg.MIXLY_ESP32_SET + 'SPI');
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_ESP32_SPI_BUFFER);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_BUFFER_SET);
}
};
export const communicate_spi_read = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('SPI');
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_SERIAL_READ);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_4DIGITDISPLAY_NOMBER2 + Blockly.Msg.LANG_MATH_BYTE)
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_READ);
}
}
export const communicate_spi_read_output = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('SPI');
this.appendValueInput('data')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_SERIAL_READ);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_4DIGITDISPLAY_NOMBER2 + Blockly.Msg.LANG_MATH_BYTE + ',' + Blockly.Msg.MIXLY_ESP32_SPI_OUTPUT);
this.appendValueInput('val')
.setCheck(Number);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_READ_OUTPUT);
}
}
export const communicate_spi_readinto = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('SPI');
this.appendValueInput('data')
.setCheck('var')
.appendField(Blockly.Msg.MIXLY_SERIAL_READ + Blockly.Msg.MIXLY_ESP32_SPI_BUFFER);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_READINTO);
}
}
export const communicate_spi_readinto_output = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('SPI');
this.appendValueInput('data')
.setCheck('var')
.appendField(Blockly.Msg.MIXLY_SERIAL_READ + Blockly.Msg.MIXLY_ESP32_SPI_BUFFER);
this.appendValueInput('val')
.setCheck(Number)
.appendField(',' + Blockly.Msg.MIXLY_ESP32_SPI_OUTPUT);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_READINTO_OUTPUT);
}
}
export const communicate_spi_write = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('SPI');
this.appendValueInput('data')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ESP32_WRITE);
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_WRITE);
}
};
export const communicate_spi_write_readinto = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('SPI');
this.appendValueInput('data')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ESP32_WRITE)
// .appendField(new Blockly.FieldDropdown([
// [Blockly.Msg.LANG_MATH_BYTE, "byte"],
// [Blockly.Msg.MIXLY_ESP32_SPI_BUFFER, "buffer"]
// ]), "op");
this.appendValueInput('val')
.setCheck('var')
.appendField(',' + Blockly.Msg.MIXLY_ESP32_BUFFER_READ);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SPI_WRITE_READINTO);
}
};
export const communicate_i2c_master_read = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField("I2C");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_READ);
this.setOutput(true, Number);
}
};
export const communicate_i2c_available = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField(Blockly.Msg.MIXLY_ESP32_READ + "I2C");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_SUCCESS);
this.setOutput(true, Boolean);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_I2C_AVAILABLE);
}
};
export const i2c_slave_onreceive = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_ONRECEIVE)
.setCheck(Number);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const communicate_ow_init = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('OneWire');
this.appendValueInput('BUS')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_SETUP + ' ' + Blockly.Msg.MIXLY_PIN);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_OW_INIT);
}
};
export const communicate_ow_scan = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('OneWire');
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_ONEWIRE_SCAN);
this.setOutput(true, 'List');
this.setTooltip(Blockly.Msg.MIXLY_ESP32_OW_SCAN);
}
};
export const communicate_ow_read = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('OneWire');
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_ONEWIRE_READ);
this.setOutput(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_OW_READ);
}
};
export const communicate_ow_write = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField('OneWire');
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_ESP32_WRITE)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.LANG_MATH_STRING, "write"],
[Blockly.Msg.LANG_MATH_BYTE, "writebyte"]
]), "op");
this.appendValueInput('byte')
.setCheck([Number, String]);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_OW_WRITE);
}
};
export const communicate_ow_select = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField(Blockly.Msg.MIXLY_ESP32_ONEWIRE_SELECT)
this.appendValueInput('byte')
.setCheck(String)
.appendField("ROM");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_OW_SELECT);
}
};
export const communicate_ow_reset = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('VAR')
.setCheck('var')
.appendField(Blockly.Msg.MIXLY_ESP32_ONEWIRE_RESET);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setOutput(false);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_OW_RESET);
}
};
export const i2c_init = communicate_i2c_init;
export const i2c_read = communicate_i2c_read;
export const i2c_write = communicate_i2c_write;
export const i2c_scan = communicate_i2c_scan;
export const spi_init = communicate_spi_init;
export const spi_set = communicate_spi_set;
export const spi_buffer = communicate_spi_buffer;
export const spi_read = communicate_spi_read;
export const spi_read_output = communicate_spi_read_output;
export const spi_readinto = communicate_spi_readinto;
export const spi_readinto_output = communicate_spi_readinto_output;
export const spi_write = communicate_spi_write;
export const spi_write_readinto = communicate_spi_write_readinto;
export const i2c_master_reader2 = communicate_i2c_master_read;
export const i2c_available = communicate_i2c_available;

View File

@@ -0,0 +1,273 @@
import * as Blockly from 'blockly/core';
const DISPLAY_HUE = 180; //'#cc6688' //180;
const SENSOR_HUE = 40;
export const angle = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
["0°", "0"],
["90°", "1"],
["180°", "2"],
["270°", "3"]
]), "flag");
this.setOutput(true);
this.setTooltip();
}
};
export const lcd_color = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
["黑色", "lcd.BLACK"],
["深蓝色", "lcd.NAVY"],
["蓝色", "lcd.BLUE"],
["深绿色", "lcd.DARKGREEN"],
["深青色", "lcd.DARKCYAN"],
["绿色", "lcd.GREEN"],
["青色", "lcd.CYAN"],
["褐红色", "lcd.MAROON"],
["紫色", "lcd.PURPLE"],
["橄榄色", "lcd.OLIVE"],
["深灰色", "lcd.DARKGREY"],
["绿黄色", "lcd.GREENYELLOW"],
["浅灰色", "lcd.LIGHTGREY"],
["红色", "lcd.RED"],
["洋红色", "lcd.MAGENTA"],
["粉红色", "lcd.PINK"],
["橙色", "lcd.ORANGE"],
["黄色", "lcd.YELLOW"],
["白色", "lcd.WHITE"]
]), "flag");
this.setOutput(true);
this.setTooltip();
}
};
export const on_off = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
["开启", "1"],
["关闭", "0"]
]), "flag");
this.setOutput(true);
this.setTooltip();
}
};
export const lcd_init = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD 初始化");
this.appendValueInput('freq')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("通信频率")
.setCheck(Number);
this.appendValueInput('color')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("背景颜色")
.setCheck(Number);
//this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("初始化LCD屏幕显示");
}
};
export const lcd_width = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD 获取 ");
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
["宽度", "width"],
["高度", "height"]
]), "key");
this.appendDummyInput()
.appendField("分辨率");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("获取LCD的宽度/高度(水平分辨率)");
}
};
export const lcd_colour = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD");
this.appendValueInput('key')
.appendField("系统颜色")
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("获取LCD的宽度/高度(水平分辨率)");
}
};
export const lcd_display = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD 显示图像");
this.appendValueInput('img')
.appendField("");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("在液晶屏上显示一张imageGRAYSCALE或RGB565");
}
};
export const lcd_clear = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD 清屏颜色");
this.appendValueInput('color')
.appendField("")
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("将液晶屏清空为指定的颜色");
}
};
export const lcd_rotation = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD 屏幕旋转");
this.appendValueInput('key')
.appendField("")
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("设置LCD屏幕方向");
}
};
export const lcd_mirror = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD 镜像显示");
this.appendValueInput('key')
.appendField("")
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("设置LCD是否镜面显示");
}
};
export const lcd_draw_string = {
init: function () {
this.setColour(DISPLAY_HUE);
this.appendDummyInput()
.appendField("LCD 绘制文本");
this.appendValueInput('x')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("坐标X")
.setCheck(Number);
this.appendValueInput('y')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("坐标Y")
.setCheck(Number);
this.appendValueInput('text')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("文本内容")
.setCheck(String);
this.appendValueInput('color_T')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("文本颜色")
.setCheck(Number);
this.appendValueInput('color_S')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("背景颜色")
.setCheck(Number);
//this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("在液晶屏上显示文本字符(不支持中文)");
}
};
export const touch_init = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField("Touch 初始化");
this.appendValueInput('I2C')
.appendField("通信")
.setCheck("var");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("初始化触摸屏");
}
};
export const touch_calibrate = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField("Touch 校准");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("校准屏幕,使屏幕显示和触摸屏像素能够对应");
}
};
export const touch_read = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField("Touch 获取 ");
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
["状态", "[0]"],
["坐标x", "[1]"],
["坐标y", "[2]"]
]), "key");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("读取当前屏幕的状态以及按下的点的坐标值");
}
};
//ts.STATUS_IDLE==0
//ts.STATUS_RELEASE==1
//ts.STATUS_PRESS==2
//ts.STATUS_MOVE==3
export const touch_info = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField("Touch 状态");
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
["空闲", "ts.STATUS_IDLE"],
["不按", "ts.STATUS_RELEASE"],
["按下", "ts.STATUS_PRESS"],
["移动", "ts.STATUS_MOVE"]
]), "key");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("读取当前屏幕的状态以及按下的点的坐标值");
}
};

View File

@@ -0,0 +1,286 @@
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('mixno'), '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);
}
};
export const factory_block_notes = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput()
.appendField("注解 #");
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('Welcome to MixGo'), 'VALUE')
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};

View File

@@ -0,0 +1,200 @@
import * as Blockly from 'blockly/core';
const HEAR_HUE = "#47B670";
export const asrloca_init = {
init: function () {
this.setColour(HEAR_HUE);
this.appendValueInput('SUB')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("初始化");
this.appendDummyInput("")
.appendField("硅麦")
.appendField(new Blockly.FieldDropdown([
["左声道", "0"],
["右声道", "1"]
]), "KEY");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("初始化语音识别,及需要麦克风输入通信设备");
}
};
export const asrloca_config = {
/**
* Block for creating a list with any number of elements of any type.
* @this Blockly.Block
*/
init: function () {
this.setColour(HEAR_HUE);
this.appendValueInput('SUB')
.appendField("添加词条")
.setCheck("var");
this.appendDummyInput()
.appendField(new Blockly.FieldLabel("拼音:阈值"), 'TIP')
.setAlign(Blockly.inputs.Align.RIGHT)
this.itemCount_ = 1;
this.updateShape_();
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setMutator(new Blockly.icons.MutatorIcon(['iot_publish_item'], this));
this.setTooltip("初始化语音识别,添加语音识别词条,需拼音中间-隔开,阈值");
},
/**
* Create XML to represent list inputs.
* @return {Element} XML storage element.
* @this Blockly.Block
*/
mutationToDom: function () {
var container = document.createElement('mutation');
container.setAttribute('items', this.itemCount_);
return container;
},
/**
* Parse XML to restore the list inputs.
* @param {!Element} xmlElement XML storage element.
* @this Blockly.Block
*/
domToMutation: function (xmlElement) {
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
this.updateShape_();
},
/**
* Populate the mutator's dialog with this block's components.
* @param {!Blockly.Workspace} workspace Mutator's workspace.
* @return {!Blockly.Block} Root block in mutator.
* @this Blockly.Block
*/
decompose: function (workspace) {
var containerBlock =
workspace.newBlock('iot_publish_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('iot_create_with_item');
itemBlock.initSvg();
connection.connect(itemBlock.previousConnection);
connection = itemBlock.nextConnection;
}
return containerBlock;
},
/**
* Reconfigure this block based on the mutator dialog's components.
* @param {!Blockly.Block} containerBlock Root block in mutator.
* @this Blockly.Block
*/
compose: function (containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
// Count number of inputs.
var connections = [];
var i = 0;
while (itemBlock) {
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]);
}
}
},
/**
* Store pointers to any connected child blocks.
* @param {!Blockly.Block} containerBlock Root block in mutator.
* @this Blockly.Block
*/
saveConnections: function (containerBlock) {
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();
}
},
/**
* Modify this block to have the correct number of inputs.
* @private
* @this Blockly.Block
*/
updateShape_: function () {
// Delete everything.
if (this.getInput('EMPTY')) {
this.removeInput('EMPTY');
}
var keyNames = [];
for (var i = 0; this.getInput('ADD' + i); i++) {
//this.getInput('VALUE' + i).removeField("KEY"+i);
keyNames.push(this.getFieldValue("KEY" + i))
this.removeInput('ADD' + i);
}
// Rebuild block.
if (this.itemCount_ == 0) {
this.getField('TIP')
.setValue("拼音:阈值");
} else {
this.getField('TIP')
.setValue("拼音:阈值");
for (var i = 0; i < this.itemCount_; i++) {
this.appendValueInput('ADD' + i)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('“')
.appendField(new Blockly.FieldTextInput(keyNames.length > i ? keyNames[i] : 'ni-hao'), 'KEY' + i)
.appendField('”:')
}
}
}, getVars: function () {
return [this.getFieldValue('VAR')];
},
renameVar: function (oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
this.setTitleValue(newName, 'VAR');
}
}
};
export const asrloca_recognize = {
init: function () {
this.setColour(HEAR_HUE);
this.appendValueInput('SUB')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("启动识别 返回结果");
this.setInputsInline(true);
this.setOutput(true, Number);
this.setTooltip("语音识别,获取识别结果");
}
};
export const asrloca_del = {
init: function () {
this.setColour(HEAR_HUE);
this.appendValueInput('SUB')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("注销识别 内存释放");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("语音识别,注销语音识别,释放内存");
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,154 @@
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_ESP32_INOUT_HIGHLOW_TOOLTIP);
}
};
export const inout_digital_init = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput()
.appendField("初始化 ");
this.appendDummyInput("")
//.appendField(Blockly.Msg.MIXLY_MICROPYTHON_AS)
// .appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_MODE+Blockly.Msg.LISTS_SET_INDEX_INPUT_TO)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_Digital_PINMODEOUT, "GPIO.OUT"],
[Blockly.Msg.MIXLY_Digital_PINMODEIN, "GPIO.IN"],
[Blockly.Msg.MIXLY_PINMODEPULLUP, "GPIO.IN, board.GPIO.PULL_UP"],
[Blockly.Msg.MIXLY_PINMODEPULLDOWN, "GPIO.IN, board.GPIO.PULL_DOWN"]
]), "MODE")
this.appendValueInput("PIN", Number)
.appendField("管脚")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_INOUT_DIGITAL_INIT_TOOLTIP);
}
};
export const inout_digital_write = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_Digital_PINMODEOUT)
.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.MIXLY_ESP32_INOUT_DIGITAL_WRITE_TOOLTIP);
}
};
export const inout_digital_read = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
.appendField(Blockly.Msg.MIXLY_Digital_PINMODEIN)
.setCheck(Number);
this.appendDummyInput()
.appendField("值");
this.setInputsInline(true);
this.setOutput(true, [Boolean, Number]);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_INOUT_DIGITAL_READ_TOOLTIP);
}
};
export const inout_pwm_init = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput()
.appendField("初始化 PWM输出");
this.appendValueInput("PIN", Number)
.appendField("管脚")
.setCheck(Number);
this.appendValueInput('freq')
.appendField("频率")
.setCheck(Number);
this.appendValueInput('VAR')
.appendField("定时器")
.setCheck("var");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("初始化PWM输出设置需要调用定时器");
}
};
export const inout_pwm_write = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField("PWM输出")
.setCheck(Number);
this.appendValueInput('pwm')
.appendField("占空比")
.setCheck(Number);
this.appendDummyInput()
.appendField("%");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("PWM输出,值范围为0-100%,可以为小数");
}
};
export const inout_pin_attachInterrupt = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput()
.appendField("硬件中断");
this.appendValueInput("PIN", Number)
.appendField("管键")
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MODE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_RISING, "GPIO.IRQ_RISING"], [Blockly.Msg.MIXLY_FALLING, "GPIO.IRQ_FALLING"], [Blockly.Msg.MIXLY_CHANGE, "GPIO.IRQ_BOTH"]]), "mode");
this.appendValueInput('DO')
.appendField(Blockly.Msg.MIXLY_DO)
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_INOUT_PIN_ATTACHINTERRUPT_TOOLTIP);
}
};
export const inout_pin_disirq = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput()
.appendField("取消中断");
this.appendValueInput("PIN", Number)
.appendField("管键")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("取消中断");
}
};

View File

@@ -0,0 +1,306 @@
import * as Blockly from 'blockly/core';
const IOT_HUE = '#637AAC';
export const iot_wifi_connect = {
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField("OneNET 连接WiFi");
this.appendValueInput('WIFINAME')
.setCheck(String)
.appendField(Blockly.Msg.HTML_NAME);
this.appendValueInput('PASSWORD')
.setCheck(String)
.appendField(Blockly.Msg.HTML_PASSWORD);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_WIFI_CONNECT_TOOLTIP);
}
};
export const iot_onenet_connect = {
init: function () {
this.setColour(IOT_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField("OneNET" + Blockly.Msg.TUPLE_JOIN);
this.appendValueInput('CLIENT')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_CLIENT);
this.appendValueInput('SERVER')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_SERVER);
this.appendValueInput('USERNAME')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_USERNAME);
this.appendValueInput('PASSWORD')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_PASSWORD);
this.appendValueInput('TOPIC')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_TOPIC);
this.appendValueInput('SUB')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_SUB);
//this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_CONNECT_TOOLTIP);
}
};
export const iot_onenet_disconnect = {
init: function () {
this.setColour(IOT_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField("OneNET")
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_DISCONNECT_ONENET);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
}
};
export const iot_onenet_check = {
init: function () {
this.setColour(IOT_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField("OneNET")
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_CHECK_ONENET);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_CHECK_TOOLTIP);
}
};
export const iot_onenet_publish_dict = {
init: function () {
this.setColour(IOT_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField("OneNET")
this.appendValueInput('DICT')
.appendField(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_PRINT_DATA)
.appendField(new Blockly.FieldCheckbox('TRUE'), 'is_print');
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_PUBLISH_DICT_TOOLTIP);
}
};
export const iot_onenet_publish = {
/**
* Block for creating a list with any number of elements of any type.
* @this Blockly.Block
*/
init: function () {
this.setColour(IOT_HUE);
this.appendValueInput('VAR')
.setCheck("var")
.appendField("OneNET")
.setAlign(Blockly.inputs.Align.RIGHT)
this.appendDummyInput()
.appendField(new Blockly.FieldLabel(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET), 'TIP')
.setAlign(Blockly.inputs.Align.RIGHT)
this.itemCount_ = 2;
this.updateShape_();
this.setInputsInline(false);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setMutator(new Blockly.icons.MutatorIcon(['iot_publish_item'], this));
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_PUBLISH_TOOLTIP);
},
/**
* Create XML to represent list inputs.
* @return {Element} XML storage element.
* @this Blockly.Block
*/
mutationToDom: function () {
var container = document.createElement('mutation');
container.setAttribute('items', this.itemCount_);
return container;
},
/**
* Parse XML to restore the list inputs.
* @param {!Element} xmlElement XML storage element.
* @this Blockly.Block
*/
domToMutation: function (xmlElement) {
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
this.updateShape_();
},
/**
* Populate the mutator's dialog with this block's components.
* @param {!Blockly.Workspace} workspace Mutator's workspace.
* @return {!Blockly.Block} Root block in mutator.
* @this Blockly.Block
*/
decompose: function (workspace) {
var containerBlock =
workspace.newBlock('iot_publish_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('iot_create_with_item');
itemBlock.initSvg();
connection.connect(itemBlock.previousConnection);
connection = itemBlock.nextConnection;
}
return containerBlock;
},
/**
* Reconfigure this block based on the mutator dialog's components.
* @param {!Blockly.Block} containerBlock Root block in mutator.
* @this Blockly.Block
*/
compose: function (containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
// Count number of inputs.
var connections = [];
var i = 0;
while (itemBlock) {
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]);
}
}
},
/**
* Store pointers to any connected child blocks.
* @param {!Blockly.Block} containerBlock Root block in mutator.
* @this Blockly.Block
*/
saveConnections: function (containerBlock) {
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();
}
},
/**
* Modify this block to have the correct number of inputs.
* @private
* @this Blockly.Block
*/
updateShape_: function () {
// Delete everything.
if (this.getInput('EMPTY')) {
this.removeInput('EMPTY');
}
var keyNames = [];
for (var i = 0; this.getInput('ADD' + i); i++) {
//this.getInput('VALUE' + i).removeField("KEY"+i);
keyNames.push(this.getFieldValue("KEY" + i))
this.removeInput('ADD' + i);
}
// Rebuild block.
if (this.itemCount_ == 0) {
this.getField('TIP')
.setValue(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET_EMPTY);
} else {
this.getField('TIP')
.setValue(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET);
for (var i = 0; i < this.itemCount_; i++) {
this.appendValueInput('ADD' + i)
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(
new Blockly.FieldTextInput(
keyNames.length > i
? keyNames[i]
: '"key' + (i + 1) + '"'),
'KEY' + i)
.appendField(":")
}
}
}, getVars: function () {
return [this.getFieldValue('VAR')];
},
renameVar: function (oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
this.setTitleValue(newName, 'VAR');
}
}
};
export const iot_publish_container = {
/**
* Mutator block for list container.
* @this Blockly.Block
*/
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_TYPE_DICT);
this.appendStatementInput('STACK');
this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_CONTAINER_TOOLTIP);
this.contextMenu = false;
}
};
export const iot_publish_item = {
/**
* Mutator bolck for adding items.
* @this Blockly.Block
*/
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TITLE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TOOLTIP);
this.contextMenu = false;
}
};
export const iot_create_with_item = {
/**
* Mutator bolck for adding items.
* @this Blockly.Block
*/
init: function () {
this.setColour(IOT_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TITLE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TOOLTIP);
this.contextMenu = false;
}
};
export const iot_wificonnect = iot_wifi_connect;
export const iot_onenetconnect = iot_onenet_connect;
export const iot_onenetdisconnect = iot_onenet_disconnect;
export const iot_checkonenet = iot_onenet_check;
export const iot_publish = iot_onenet_publish;

View File

@@ -0,0 +1,19 @@
const pins = {};
pins['k210'] = {
description: "MicroPython[K210_MixGo AI]",
digital_pin: [["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P17", "17"], ["P18", "18"], ["P19", "19"], ["P20", "20"], ["P21", "21"], ["P22", "22"], ["P23", "23"], ["P24", "24"], ["P25", "25"]],
digital: [["P0", "0"], ["P1", "1"], ["P2", "2"], ["P3", "3"], ["P6", "6"], ["P7", "7"], ["P8", "8"], ["P9", "9"], ["P10", "10"], ["P11", "11"], ["P12", "12"], ["P13", "13"], ["P14", "14"], ["P15", "15"], ["P16", "16"], ["P17", "17"], ["P18", "18"], ["P19", "19"], ["P20", "20"], ["P21", "21"], ["P22", "22"], ["P23", "23"], ["P24", "24"], ["P25", "25"], ["P30", "30"], ["P31", "31"], ["P32", "32"], ["P33", "33"], ["P34", "34"], ["P35", "35"]],
button: [["A", "button_a"], ["B", "button_b"]],
axis: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"]],
exlcdh: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"]],
exlcdv: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"]],
serial_pin: [["pin0", "0"], ["pin1", "1"], ["pin2", "2"], ["pin8", "8"], ["pin12", "12"], ["pin13", "13"], ["pin14", "14"], ["pin15", "15"], ["pin16", "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"]],
one_more: [["ONE_SHOT", "ONE_SHOT"], ["PERIODIC", "PERIODIC"]],
};
pins["MixGo AI"] = pins["k210"];
export default pins;

View File

@@ -0,0 +1,444 @@
import * as Blockly from 'blockly/core';
const MATH_HUE = 230; //'#e49f16';
Blockly.FieldTextInput.math_number_validator = function (text) {
//return window.isNaN(text) ? null : String(text);
var pattern = /^-?(0X|0x|0O|0o|0B|0b)?[a-fA-F0-9]{1,}(\.[a-fA-F0-9]+)?$/;
return pattern.test(text) ? String(text) : null;//校验,二 八 十 十六进制匹配
// return String(text);//不再校验
};
Blockly.FieldTextInput.math_number_validator_include_blank = function (text) {
if (text === "") {
return "";
}
var pattern = /^-?(0X|0x|0O|0o|0B|0b)?[a-fA-F0-9]{1,}(\.[a-fA-F0-9]+)?$/;
return pattern.test(text) ? String(text) : null;//校验,二 八 十 十六进制匹配
};
export const math_number = {
/**
* Block for numeric value.
* @this Blockly.Block
*/
init: function () {
this.setColour(MATH_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldTextInput('0',
Blockly.FieldTextInput.math_number_validator), 'NUM');
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MATH_NUMBER_TOOLTIP);
}
};
export const math_constant = {
init: function () {
this.setColour(MATH_HUE);
var constant =
[['π', 'pi'], ['e', 'e']];
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_PYTHON_MATH_CONSTANT)
.appendField(new Blockly.FieldDropdown(constant), 'CONSTANT')
this.setOutput(true, Number);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('CONSTANT');
var TOOLTIPS = {
'pi': Blockly.Msg.MIXLY_PYTHON_MATH_CONSTANT_PI_TOOLTIP,
'e': Blockly.Msg.MIXLY_PYTHON_MATH_CONSTANT_E_TOOLTIP
};
return TOOLTIPS[mode];
});
}
};
export const math_arithmetic = {
/**
* Block for basic arithmetic operator.
* @this Blockly.Block
*/
init: function () {
var OPERATORS = [
['+', 'ADD'],
['-', 'MINUS'],
['×', 'MULTIPLY'],
['÷', 'DIVIDE'],
['%', 'QUYU'],
['//', 'ZHENGCHU'],
['**', 'POWER']
];
//this.setHelpUrl(Blockly.Msg.MATH_ARITHMETIC_HELPURL);
this.setColour(MATH_HUE);
this.setOutput(true);
this.appendValueInput('A')
this.appendValueInput('B')
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setInputsInline(true);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'ADD': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD,
'MINUS': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS,
'MULTIPLY': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY,
'DIVIDE': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE,
'QUYU': Blockly.Msg.MATH_MODULO_TOOLTIP,
'ZHENGCHU': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE,
'POWER': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER
};
return TOOLTIPS[mode];
});
}
};
export const math_selfcalcu = {
/**
* Block for basic arithmetic operator.
* @this Blockly.Block
*/
init: function () {
var OPERATORS = [
['+=', 'ADD'],
['-=', 'MINUS'],
['×=', 'MULTIPLY'],
['÷=', 'DIVIDE'],
['%=', 'QUYU'],
['//=', 'ZHENGCHU'],
['**=', 'POWER']
];
this.setColour(MATH_HUE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendValueInput('A')
this.appendValueInput('B')
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'ADD': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_ADD,
'MINUS': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MINUS,
'MULTIPLY': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_MULTIPLY,
'DIVIDE': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE,
'QUYU': Blockly.Msg.MATH_MODULO_TOOLTIP,
'ZHENGCHU': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_DIVIDE,
'POWER': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER
};
return TOOLTIPS[mode];
});
}
};
export const math_bit = {
init: function () {
var OPERATORS = [
['&', '&'],
['|', '|'],
['>>', '>>'],
['<<', '<<']
];
this.setColour(MATH_HUE);
this.setOutput(true, Number);
this.appendValueInput('A')
.setCheck(Number);
this.appendValueInput('B')
.setCheck(Number)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setInputsInline(true);
this.setTooltip("位运算");
}
};
export const math_trig = {
/**
* Block for trigonometry operators.
* @this Blockly.Block
*/
init: function () {
var OPERATORS = [
['sin', 'SIN'],
['cos', 'COS'],
['tan', 'TAN'],
['asin', 'ASIN'],
['acos', 'ACOS'],
['atan', 'ATAN'],
['-', '-'],
['ln', 'LN'],
['log10', 'LOG10'],
['e^', 'EXP'],
['10^', 'POW10']
];
//this.setHelpUrl(Blockly.Msg.MATH_TRIG_HELPURL);
this.setColour(MATH_HUE);
this.setOutput(true, Number);
this.appendValueInput('NUM')
.setCheck(Number)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'SIN': Blockly.Msg.MATH_TRIG_TOOLTIP_SIN,
'COS': Blockly.Msg.MATH_TRIG_TOOLTIP_COS,
'TAN': Blockly.Msg.MATH_TRIG_TOOLTIP_TAN,
'ASIN': Blockly.Msg.MATH_TRIG_TOOLTIP_ASIN,
'ACOS': Blockly.Msg.MATH_TRIG_TOOLTIP_ACOS,
'ATAN': Blockly.Msg.MATH_TRIG_TOOLTIP_ATAN,
'LN': Blockly.Msg.MATH_SINGLE_TOOLTIP_LN
};
return TOOLTIPS[mode];
});
}
};
//取整等
export const math_to_int = {
init: function () {
var OPERATORS = [
[Blockly.Msg.LANG_MATH_TO_ROUND, 'round'],
[Blockly.Msg.LANG_MATH_TO_CEIL, 'ceil'],
[Blockly.Msg.LANG_MATH_TO_FLOOR, 'floor'],
[Blockly.Msg.MATH_ABS, 'fabs'],
// [Blockly.Msg.MATH_SQ, 'pow'],
[Blockly.Msg.MATH_SQRT, 'sqrt']
];
this.setColour(MATH_HUE);
this.appendValueInput('A')
.setCheck(Number)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setOutput(true, Number);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'sqrt': Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT,
'fabs': Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS,
'sq': Blockly.Msg.MATH_SINGLE_TOOLTIP_SQ,
'round': Blockly.Msg.MATH_SINGLE_TOOLTIP_ROUND,
'ceil': Blockly.Msg.MATH_SINGLE_TOOLTIP_CEIL,
'floor': Blockly.Msg.MATH_SINGLE_TOOLTIP_FLOOR
};
return TOOLTIPS[mode];
});
}
};
//最大最小值
export const math_max_min = {
init: function () {
var OPERATORS = [
[Blockly.Msg.MIXLY_MAX, 'max'],
[Blockly.Msg.MIXLY_MIN, 'min'],
];
this.setColour(MATH_HUE);
this.appendValueInput('A')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP')
.appendField('(');
this.appendValueInput('B')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(',');
this.appendDummyInput('')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(')');
this.setInputsInline(true);
this.setOutput(true, Number);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'max': Blockly.Msg.MIXLY_TOOLTIP_MATH_MAX,
'min': Blockly.Msg.MIXLY_TOOLTIP_MATH_MIN
};
return TOOLTIPS[mode];
});
}
};
//最大最小值
export const math_max_min1 = {
init: function () {
var OPERATORS = [
[Blockly.Msg.MIXLY_MAX, 'max'],
[Blockly.Msg.MIXLY_MIN, 'min'],
];
this.setColour(MATH_HUE);
this.appendValueInput('LIST')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP')
this.setOutput(true, Number);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'max': Blockly.Msg.MIXLY_TOOLTIP_MATH_MAX,
'min': Blockly.Msg.MIXLY_TOOLTIP_MATH_MIN
};
return TOOLTIPS[mode];
});
}
};
export const math_number_base_conversion = {
init: function () {
var OPERATORS = [
[Blockly.Msg.MATH_TWO, 'two'],
[Blockly.Msg.MATH_EIGHT, 'eight'],
[Blockly.Msg.MATH_TEN, 'ten'],
[Blockly.Msg.MATH_SIXTEEN, 'sixteen']
];
this.setColour(MATH_HUE);
this.appendDummyInput('')
.appendField(Blockly.Msg.MATH_BA)
this.appendValueInput("NUM")
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP')
.appendField(Blockly.Msg.MATH_JinZhi)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MATH_ZHW)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP2')
.appendField(Blockly.Msg.MATH_JinZhi);
this.setFieldValue('ten', 'OP2')
// this.setPreviousStatement(true, null);
// this.setNextStatement(true, null);
this.setOutput(true)
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'two': Blockly.Msg.MATH_Before_two,
'eight': Blockly.Msg.MATH_Before_eight,
'ten': Blockly.Msg.MATH_Before_ten,
'sixteen': Blockly.Msg.MATH_Before_sixteen,
};
var mode2 = thisBlock.getFieldValue('OP2');
var TOOLTIPS2 = {
'two': Blockly.Msg.MATH_Behind_two,
'eight': Blockly.Msg.MATH_Behind_eight,
'ten': Blockly.Msg.MATH_Behind_ten,
'sixteen': Blockly.Msg.MATH_Behind_sixteen,
};
return TOOLTIPS[mode] + TOOLTIPS2[mode2];
});
}
};
export const math_random = {
init: function () {
var INT_FLOAT = [[Blockly.Msg.LANG_MATH_INT, 'int'], [Blockly.Msg.LANG_MATH_FLOAT, 'float']];
this.setColour(MATH_HUE);
this.setOutput(true, Number);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_RANDOM)
.appendField(new Blockly.FieldDropdown(INT_FLOAT), 'TYPE');
this.appendValueInput('FROM')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_CONTROLS_FOR_INPUT_FROM);
this.appendValueInput('TO')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.LANG_MATH_RANDOM_INT_INPUT_TO);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('TYPE');
var TOOLTIPS = {
'int': Blockly.Msg.LANG_MATH_INT,
'float': Blockly.Msg.LANG_MATH_FLOAT_RANDOM
};
return Blockly.Msg.MATH_RANDOM_INT_TOOLTIP + TOOLTIPS[mode];
});
}
};
export const math_constrain = {
/**
* Block for constraining a number between two limits.
* @this Blockly.Block
*/
init: function () {
this.setColour(MATH_HUE);
this.setOutput(true, Number);
this.appendValueInput('VALUE')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_MATH_CONSTRAIN_INPUT_CONSTRAIN);
this.appendValueInput('LOW')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_MATH_CONSTRAIN_INPUT_LOW);
this.appendValueInput('HIGH')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_MATH_CONSTRAIN_INPUT_HIGH);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MATH_CONSTRAIN_TOOLTIP);
}
};
export const math_map = {
init: function () {
this.setColour(MATH_HUE);
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_MAP)
.setCheck(Number);
this.appendValueInput("fromLow", Number)
.appendField(Blockly.Msg.MIXLY_MAP_FROM)
.setCheck(Number);
this.appendValueInput("fromHigh", Number)
.appendField(",")
.setCheck(Number);
this.appendValueInput("toLow", Number)
.appendField(Blockly.Msg.MIXLY_MAP_TO)
.setCheck(Number);
this.appendValueInput("toHigh", Number)
.appendField(",")
.setCheck(Number);
this.appendDummyInput("")
.appendField("]");
this.setInputsInline(true);
this.setOutput(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_MATH_MAP);
}
};
export const math_indexer_number = {
/**
* Block for numeric value.
* @this Blockly.Block
*/
init: function () {
this.setColour(MATH_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.math_number_validator_include_blank), 'NUM');
this.setOutput(true);
this.setTooltip(Blockly.Msg.MATH_NUMBER_TOOLTIP);
}
};
export const math_random_seed = {
init: function () {
this.setColour(MATH_HUE);
this.appendValueInput('NUM')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_MATH_RANDOM_SEED);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_MATH_RANDOM_SEED);
}
};
export const base_map = math_map

View File

@@ -0,0 +1,72 @@
import * as Blockly from 'blockly/core';
const GAME_HUE = '#2E9883';
export const nes_joystick_init = {
init: function () {
this.setColour(GAME_HUE);
this.appendDummyInput()
.appendField("NES 初始化");
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("PS2手柄");
this.appendValueInput("miso_pin", Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("DAT#")
.setCheck(Number);
this.appendValueInput("mosi_pin", Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("CMD#")
.setCheck(Number);
this.appendValueInput("cs_pin", Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("SEL#")
.setCheck(Number);
this.appendValueInput("clk_pin", Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("CLK#")
.setCheck(Number);
this.appendValueInput('vol')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("音量")
.setCheck(Number);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("初始化NES,使用PS2手柄控制");
}
};
export const nes_keyboard_init = {
init: function () {
this.setColour(GAME_HUE);
this.appendDummyInput()
.appendField("NES 初始化");
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("UART键盘");
this.appendValueInput('vol')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("音量")
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("初始化NES,使用串口键盘控制");
}
};
export const nes_run = {
init: function () {
this.setColour(GAME_HUE);
this.appendDummyInput()
.appendField("NES 运行游戏");
this.appendValueInput('path')
.appendField("路径")
.setCheck(String);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("运行NES游戏ROM");
}
};

View File

@@ -0,0 +1,249 @@
import * as Blockly from 'blockly/core';
const NETWORK_HUE = '#5B6DA5';
export const network_init = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendDummyInput()
.appendField("ESP-AT 初始化");
this.appendValueInput("RX", Number)
.appendField("RX#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("TX", Number)
.appendField("TX#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("使用串口连接ESP-AT设备并初始化配置");
}
};
export const network_scan = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendDummyInput()
.appendField("WiFi扫描");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("扫描附近可用的WiFi信息-返回多信息列表");
}
};
export const network_connect = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendDummyInput("")
.appendField("WiFi连接");
this.appendValueInput('account')
.appendField("名称")
.setCheck(String);
this.appendValueInput('password')
.appendField("密码")
.setCheck(String);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("配置WiFi名称及密码连接WiFi上网");
}
};
export const network_ifconfig = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendDummyInput()
.appendField("WiFi")
.appendField(new Blockly.FieldDropdown([
['连接信息', "1"],
['连接状态', "2"]
]), "mode");
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("查看wifi连接信息或者连接状态");
}
};
export const network_disconnect = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendDummyInput()
.appendField("WiFi断开连接");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("断开wifi连接");
}
};
export const network_enable_ap = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("打开热点");
this.appendValueInput('account')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("名称")
.setCheck(String);
this.appendValueInput('password')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("密码")
.setCheck(String);
this.appendValueInput('chl')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("通道")
.setCheck(Number);
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("加密")
.appendField(new Blockly.FieldDropdown([
['WPA2_PSK', "WPA2_PSK"],
['OPEN', "OPEN"],
['WPA_PSK', "WPA_PSK"],
['WPA_WPA2_PSK', "WPA_WPA2_PSK"]
]), "mode");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("打开WiFi热点并配置");
}
};
export const network_disable_ap = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendDummyInput()
.appendField("关闭热点");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("关闭热点");
}
};
//ok
export const network_socket_init = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendValueInput('VAR')
.appendField('')
.setCheck("var");
this.appendDummyInput()
.appendField("套接字 初始化");
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("套接字初始化");
}
};
//ok
export const network_socket_getaddrinfo = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendValueInput('VAR')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("获取地址");
this.appendValueInput('addr')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("域名")
.setCheck(String);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("套接字根据域名解析地址IP信息");
}
};
//ok
export const network_socket_connect = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendValueInput('VAR')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("创建连接");
this.appendValueInput('address')
.appendField("地址");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip("套接字创建目标IP地址连接");
}
};
//ok
export const network_socket_settimeout = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendValueInput('VAR')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("超时时间");
this.appendValueInput('time')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("")
.setCheck(Number);
this.appendDummyInput()
.appendField("s");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip("设置阻塞套接字超时时间");
}
};
//ok
export const network_socket_send = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendValueInput('VAR')
.appendField("")
.setCheck("var");
this.appendValueInput('content')
.appendField("发送数据")
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip("套接发送数据");
}
};
//ok
export const network_socket_receive = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendValueInput('VAR')
.appendField("")
.setCheck("var");
this.appendDummyInput()
.appendField("接收数据");
this.appendValueInput('size')
.appendField("字节")
.setCheck(Number);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip("套接接收数据,返回接收到的数据对象");
}
};
export const network_socket_close = {
init: function () {
this.setColour(NETWORK_HUE);
this.appendValueInput('VAR')
.setCheck("var")
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_SOCKET_CLOSE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_NETWORK_SOCKET_CLOSE_TOOLTIP);
}
};

View File

@@ -0,0 +1,220 @@
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);
}
};
export const pins_digital_pin = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.digital_pin), '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);
}
};
export const pins_analog_pin = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.analog_pin), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_dac = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.dac), 'PIN');
this.setOutput(true);
}
};
export const pins_dac_pin = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.dac_pin), '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);
}
};
export const pins_pwm_pin = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.pwm_pin), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_touch_pin = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.touch_pin), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_touch = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.touch), 'PIN');
this.setOutput(true);
}
};
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, "esp32_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_playlist = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.playlist), 'PIN');
this.setOutput(true);
}
};
export const pins_exlcdh = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.exlcdh), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_exlcdv = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.exlcdv), 'PIN');
this.setOutput(true, Number);
}
};
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);
}
};
export const pins_one_more = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.one_more), 'PIN');
this.setOutput(true);
}
};
export const pins_digital_dot = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.digital_dot), 'PIN');
this.setOutput(true, Number);
}
};

View File

@@ -0,0 +1,322 @@
import * as Blockly from 'blockly/core';
const SENSOR_HUE = 40; //'#9e77c9'//40;
export const KEY_SELET = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
["A", "17"],
["B", "16"]
]), "KEY");
this.setOutput(true);
this.setTooltip();
}
};
export const sensor_button_init = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField("初始化");
this.appendValueInput('key')
.appendField("按键");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip("初始化按键");
}
};
export const sensor_button_read = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('key')
.appendField("按键");
this.appendDummyInput()
.appendField("被按下?")
this.setInputsInline(true);
this.setOutput(true, [Boolean, Number]);
this.setTooltip("获取按键值");
}
};
export const sensor_dht11 = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput()
.appendField("DHT11");
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_PIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField("获取")
.appendField(new Blockly.FieldDropdown([
["温度-℃", "0"],
["湿度-%", "1"],
["温湿度", "2"]
]), "TYPE")
this.setInputsInline(true);
this.setOutput(true, Number);
this.setTooltip("dht11,获取温湿度");
}
};
export const HCSR04 = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_CHAOSHENGBO);
this.appendValueInput("PIN1", Number)
.appendField('Trig #')
.setCheck(Number);
this.appendValueInput("PIN2", Number)
.appendField('Echo #')
.setCheck(Number);
this.setInputsInline(true);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_CHAOSHENGBO);
}
};
export const sensor_mpu9250_get_acceleration = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('SUB')
.appendField("MPU9250")
.setCheck("var");
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_use_i2c_init = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('I2CSUB')
.appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH + "I2C")
.setCheck("var");
this.appendValueInput('SUB')
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_SOCKET_MAKE)
.setCheck("var");
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_SETUP + Blockly.Msg.LISTS_SET_INDEX_INPUT_TO)
.appendField(new Blockly.FieldDropdown([
["MPU9250", "MPU9250"],
["BMP280", "BMP280"],
["SHT20", "SHT20"],
["ADXL345", "ADXL345"]
]), "key");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setFieldValue("MPU9250", "key");
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('key');
var mode0 = Blockly.Msg.MIXLY_ESP32_SENSOR_USE_I2C_TOOLTIP;
var TOOLTIPS = {
"MPU9250": "MPU9250",
"SHT20": "SHT20",
"BMP280": "BMP280",
"ADXL345": "ADXL345"
};
return mode0 + TOOLTIPS[mode]
});
}
};
export const sensor_bmp = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('SUB')
.appendField("BMP280")
.setCheck("var");
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_GETTEMPERATUE, "get_BMP_temperature()"],
[Blockly.Msg.MIXLY_GETPRESSURE, "get_BMP_pressure()"]
]), "key");
this.setOutput(true, Number);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('key');
var TOOLTIPS = {
"get_BMP_temperature()": Blockly.Msg.MIXLY_MICROBIT_SENSOR_BMP_temperature_TOOLTIP,
"get_BMP_pressure()": Blockly.Msg.MIXLY_MICROBIT_SENSOR_BMP_press_TOOLTIP,
};
return TOOLTIPS[mode]
});
}
};
export const sensor_sht = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('SUB')
.appendField("SHT20")
.setCheck("var");
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_GETTEMPERATUE, "get_SHT_temperature()"],
[Blockly.Msg.MIXLY_GETHUMIDITY, "get_SHT_relative_humidity()"]
]), "key");
this.setOutput(true, Number);
this.setInputsInline(true);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('key');
var TOOLTIPS = {
"get_SHT_temperature()": Blockly.Msg.MIXLY_MICROBIT_SENSOR_SHT_temperature_TOOLTIP,
"get_SHT_relative_humidity()": Blockly.Msg.MIXLY_MICROBIT_SENSOR_SHT_HUM_TOOLTIP,
};
return TOOLTIPS[mode]
});
}
};
export const sensor_mpu9250_get_magnetic = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('SUB')
.appendField("MPU9250")
.setCheck("var");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_GET + Blockly.Msg.MIXLY_MICROBIT_JS_FIELD_STRENGTH)
.appendField(new Blockly.FieldDropdown([
["x", "x"],
["y", "y"],
["z", "z"],
["(x,y,z)", "values"]
]), "key");
this.setOutput(true, Number);
this.setInputsInline(true);
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_FIELD_STRENGTH;
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_mpu9250_get_gyro = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('SUB')
.appendField("MPU9250")
.setCheck("var");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET + Blockly.Msg.MIXLY_ESP32_SENOR_GYRO)
.appendField(new Blockly.FieldDropdown([
["x", "x"],
["y", "y"],
["z", "z"],
["(x,y,z)", "values"]
]), "key");
this.setOutput(true, Number);
this.setInputsInline(true);
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_ESP32_SENOR_GYRO;
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_mpu9250_temperature = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('SUB')
.appendField("MPU9250")
.setCheck("var");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_GETTEMPERATUE)
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_GETTEMPERATUE);
}
};
export const sensor_adxl345_get_acceleration = {
init: function () {
this.setColour(SENSOR_HUE);
this.appendValueInput('SUB')
.appendField("ADXL345")
.setCheck("var");
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;
});
}
};

View File

@@ -0,0 +1,341 @@
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")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
//this.setFieldValue('1','mode')
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")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
//this.setFieldValue('1','mode')
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.appendDummyInput()
.appendField("Serial")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
this.appendValueInput("CONTENT", Number)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MATH_BIN, "bin"], [Blockly.Msg.MATH_OCT, "oct"], [Blockly.Msg.MATH_DEC, "int"], [Blockly.Msg.MATH_HEX, "hex"]]), "STAT")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setFieldValue('hex', 'STAT')
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")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_SERIAL_READSTR);
//this.setFieldValue('1','mode')
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")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_SERIAL_AVAILABLE);
//this.setFieldValue('1','mode')
this.setOutput(true, Boolean);
this.setTooltip(Blockly.Msg.MIXLY_SERIAL_AVAILABLE1);
}
};
export const serial_readline = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField("Serial")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_ESP32_READ_LINE);
//this.setFieldValue('1','mode')
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_softserial1 = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("RX", Number)
.appendField(Blockly.Msg.MIXLY_SETUP)
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.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'], ['37400', '38400'], ['31250', '31250'], ['28800', '28800'], ['19200', '19200'], ['14400', '14400'], ['9600', '9600'], ['4800', '4800'], ['2400', '2400'], ['1200', '1200'], ['300', '300']]), 'baudrate');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_SERIAL_softserial);
}
};
export const system_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 system_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 system_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);
}
};
export const system_print_end = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("VAR")
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
this.appendValueInput("END")
.appendField(Blockly.Msg.MIXLY_ENDSWITH);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_PYTHON_INOUT_PRINT_END_TOOLTIP);
}
};
export const system_print_many = {
init: function () {
this.setColour(SERIAL_HUE);
this.itemCount_ = 2;
this.updateShape_();
this.setPreviousStatement(false);
this.setNextStatement(false);
this.setInputsInline(true);
this.setMutator(new Blockly.icons.MutatorIcon(['system_print_item'], this));
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_TOOLTIP);
},
mutationToDom: function () {
var container = document.createElement('mutation');
container.setAttribute('items', this.itemCount_);
return container;
},
domToMutation: function (xmlElement) {
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
this.updateShape_();
},
decompose: function (workspace) {
var containerBlock =
workspace.newBlock('system_print_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('system_print_item');
itemBlock.initSvg();
connection.connect(itemBlock.previousConnection);
connection = itemBlock.nextConnection;
}
return containerBlock;
},
compose: function (containerBlock) {
var itemBlock = containerBlock.getInputTargetBlock('STACK');
// Count number of inputs.
var connections = [];
var i = 0;
while (itemBlock) {
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) {
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 () {
// 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.
if (this.itemCount_ == 0) {
this.appendDummyInput('EMPTY')
.appendField(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_EMPTY);
} else {
for (var i = 0; i < this.itemCount_; i++) {
var input = this.appendValueInput('ADD' + i);
if (i == 0) {
input.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
}
}
}
}
};
export const system_print_container = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
this.appendStatementInput('STACK');
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_CONTAINER_TOOLTIP);
this.contextMenu = false;
}
};
export const system_print_item = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_ITEM_TOOLTIP);
this.contextMenu = false;
}
};
export const serial_send_to_mixgoce = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT")
.appendField("Serial")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH);
this.appendDummyInput()
.appendField(Blockly.Msg.LANG_CONTROLS_FOR_INPUT_TO + 'MixGo CE')
.appendField(Blockly.Msg.LANG_CONTROLS_WHILEUNTIL_TITLE_REPEAT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, '1'], [Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, '0']]), 'STAT')
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
};
export const serial_read_from_mixgoce = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField("Serial")
.appendField(new Blockly.FieldDropdown([['uart1', '1'], ['uart2', '2'], ['uart3', '3']]), 'mode')
.appendField(Blockly.Msg.MIXLY_ESP32_READ + 'MixGo CE' + Blockly.Msg.MIXLY_SD_DATA);
this.setOutput(true, Boolean);
}
};

View File

@@ -0,0 +1,199 @@
import * as Blockly from 'blockly/core';
const SYSTEM_HUE = 120//'#EB8045';
export const TIM_SELET = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([
["tim0", "0"],
["tim1", "1"],
["tim2", "2"],
["tim3", "3"],
["tim4", "4"],
["tim5", "5"],
["tim6", "6"],
["tim7", "7"],
["tim8", "8"],
["tim9", "9"],
["tim10", "10"],
["tim11", "11"]
]), "TIM");
this.setOutput(true);
this.setTooltip();
}
};
export const controls_delay = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_DELAY)
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_SECOND, "s"], [Blockly.Msg.MIXLY_mSecond, "ms"], [Blockly.Msg.MIXLY_uSecond, "us"]]), 'Time');
this.appendValueInput("DELAY_TIME", Number)
.setCheck(Number);
this.setFieldValue('ms', 'Time')
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
}
};
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 controls_millis = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_RUNTIME);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_mSecond, "ms"], [Blockly.Msg.MIXLY_uSecond, "us"]]), 'Time');
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_CONTROLS_MILLIS_TOOLTIP);
}
};
export const raw_block = {
// Container.
init: function () {
this.setColour(SYSTEM_HUE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField('Code Block:');
this.appendDummyInput()
.appendField(new Blockly.FieldMultilineInput('12345'), 'TEXT');
}
};
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);
}
};
//////-----------------------------/-------------
export const system_timer = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput("")
.appendField("Timer")
this.appendValueInput('SUB')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("初始化");
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_MODE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_PYTHON_ONE_SHOT, "ONE_SHOT"], [Blockly.Msg.MIXLY_PYTHON_PERIODIC, "PERIODIC"]]), "mode");
this.appendValueInput("period")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("周期ms")
.setCheck(Number);
this.appendValueInput('callback')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_DO);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SYSTEM_TIMER_TOOLTIP);
}
};
export const system_reset = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput("")
.appendField("机器复位");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("硬件复位");
}
};
export const system_gc_collect = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
["自动", "gc.enable()"],
["运行", "gc.collect()"]
]), "gc");
this.appendDummyInput("")
.appendField("垃圾回收");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip("启用自动垃圾回收");
}
};
export const system_ticks_diff = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendValueInput('END')
// .setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_ESP32_TIME_TICKS_DIFF);
this.appendValueInput('START')
// .setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_ESP32_TIME_MINUS);
this.setInputsInline(true);
this.setOutput(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SYSTEM_TICKS_DIFF_TOOLTIP);
}
};
export const system_timer_init = {
init: function () {
this.setColour(SYSTEM_HUE);
this.appendDummyInput("")
.appendField("Timer")
this.appendValueInput('SUB')
.appendField("初始化");
this.appendDummyInput()
.appendField("模式")
.appendField(new Blockly.FieldTextInput('PWM触发'), 'PIN_OBJ');
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_SYSTEM_TIMER_INIT_TOOLTIP);
}
};
export const Timer_init = system_timer_init;
export const timer2 = system_timer;
export const time_ticks_diff = system_ticks_diff;
export const base_delay = controls_delay;

View File

@@ -0,0 +1,59 @@
import * as Blockly from 'blockly/core';
const LISTS_HUE = 260; //'#70b234'//260;
const TUPLE_HUE = 195; //'#5ec73d'//195;
const MATH_HUE = 230; //'#e49f16';
const FIELD_COLOUR_CONFIG = {
colourOptions: [
'#ffffff', '#cccccc', '#c0c0c0', '#999999', '#666666', '#333333', '#000000',
'#ffcccc', '#ff6666', '#ff0000', '#cc0000', '#990000', '#660000', '#330000',
'#ffcc99', '#ff9966', '#ff9900', '#ff6600', '#cc6600', '#993300', '#663300',
'#ffff99', '#ffff66', '#ffcc66', '#ffcc33', '#cc9933', '#996633', '#663333',
'#ffffcc', '#ffff33', '#ffff00', '#ffcc00', '#999900', '#666600', '#333300',
'#99ff99', '#66ff99', '#33ff33', '#00ff00', '#33cc00', '#009900', '#006600',
'#99ffff', '#33ffff', '#66cccc', '#00cccc', '#339999', '#336666', '#003333',
'#ccffff', '#66ffff', '#33ccff', '#3366ff', '#0000ff', '#000099', '#000066',
'#ccccff', '#9999ff', '#6666cc', '#6633ff', '#6600cc', '#333399', '#330099',
'#ffccff', '#ff99ff', '#cc66cc', '#cc33cc', '#993399', '#663366', '#330033'
],
columns: 7
};
export const lists_create_with_text1 = {
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("")
.appendField('[')
.appendField(new Blockly.FieldTextInput('0,0,0'), 'TEXT')
.appendField(']');
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_LISTS_CREATE_WITH_TEXT2);
}
};
export const tuple_create_with_text3 = {
init: function () {
this.setColour(TUPLE_HUE);
this.appendDummyInput("")
.appendField('(')
.appendField(new Blockly.FieldTextInput('0,0,0'), 'TEXT')
.appendField(')');
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXPY_TOOLTIP_TUPLE_CREATE_WITH_TEXT);
}
};
export const LCD_color_seclet = {
init: function () {
this.setColour(MATH_HUE);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldColour("33ccff", null, FIELD_COLOUR_CONFIG), "COLOR");
this.setInputsInline(true);
this.setOutput(true);
this.setTooltip("颜色");
}
};