初始化提交

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,740 @@
import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';
const COMMUNICATE_HUE = 140;
//红外接收模块
export const ir_recv = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("PIN", Number)
.appendField(new Blockly.FieldTextInput('ir_item'), 'VAR')
.appendField(Blockly.Msg.MIXLY_IR_RECEIVE)
.setCheck(Number);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_IR_RECEIVE_YES);
this.appendStatementInput('DO2')
.appendField(Blockly.Msg.MIXLY_IR_RECEIVE_NO);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_IR_RECIEVE_TOOLTIP);
},
getVars: function () {
return [this.getFieldValue('VAR')];
},
renameVar: function (oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
this.setTitleValue(newName, 'VAR');
}
}
};
//红外发射模块NEC
export const ir_send_nec = {
init: function () {
var TYPE = [['RC5', 'RC5'], ['RC6', 'RC6'], ['NEC', 'NEC'], ['Sony', 'Sony'], ['Panasonic', 'Panasonic'], ['JVC', 'JVC'], ['SAMSUNG', 'SAMSUNG'], ['Whynter', 'Whynter'], ['AiwaRCT501', 'AiwaRCT501'], ['LG', 'LG'], ['Sanyo', 'Sanyo'], ['Mitsubishi', 'Mitsubishi'], ['DISH', 'DISH'], ['SharpRaw', 'SharpRaw'], ['Denon', 'Denon']];
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_IR_SEND_NEC1)
.appendField(new Blockly.FieldDropdown(TYPE), 'TYPE')
.appendField(Blockly.Msg.MIXLY_IR_SEND_NEC2)
.appendField(new Blockly.FieldDropdown(Profile.default.digital), "PIN");
this.appendValueInput('data')
.setCheck(Number)
.appendField(' ' + Blockly.Msg.MIXLY_DATA);
this.appendValueInput('bits')
.setCheck(Number)
.appendField(' ' + Blockly.Msg.MIXLY_BITS);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_IR_SEND_NEC_TOOLTIP);
}
}
//红外接收使能
export const ir_recv_enable = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_IR_RECEIVE_ENABLE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_IR_ENABLE);
}
};
//红外接收模块(raw)
export const ir_recv_raw = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_IR_RECEIVE_RAW)
.setCheck(Number);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_IR_RECIEVE_RAW_TOOLTIP);
}
};
//红外发射模块(raw)
export const ir_send_raw = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_IR_SEND_RAW)
.appendField(new Blockly.FieldDropdown(Profile.default.digital), "PIN");
this.appendDummyInput("")
.appendField(' ' + Blockly.Msg.MIXLY_I2C_SLAVE_WRITE_ARRAY_ARRAYNAME)
.appendField(new Blockly.FieldTextInput('0,0,0'), 'TEXT');
this.appendValueInput('length')
.setCheck(Number)
.appendField(' ' + Blockly.Msg.MIXLY_LIST_LENGTH);
this.appendValueInput('freq')
.setCheck(Number)
.appendField(' ' + Blockly.Msg.MIXLY_FREQUENCY);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_IR_SEND_RAW_TOOLTIP);
}
};
// IIC通信
// IIC初始化主机
export const i2c_master_Init = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SETUP + 'I2C' + Blockly.Msg.MIXLY_MASTER);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip();
this.setHelpUrl("");
}
};
// IIC初始化从机
export const i2c_slave_Init = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SETUP + 'I2C' + Blockly.Msg.MIXLY_SALVE + Blockly.Msg.MIXLY_LCD_ADDRESS);
this.appendValueInput("i2c_address")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip(Blockly.Msg.MIXLY_I2C_MASTER_INITHelp);
this.setHelpUrl("");
}
};
//IIC主机发送数据
export const i2c_begin_end_transmission = {
init: function () {
this.appendDummyInput()
.appendField("I2C" + Blockly.Msg.MIXLY_MASTER + Blockly.Msg.MIXLY_SEND_DATA);
this.appendValueInput("i2c_address")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_LCD_ADDRESS);
this.appendStatementInput("transmission_data")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//IIC写入主从机数据
export const i2c_write = {
init: function () {
this.appendValueInput("i2c_write_data")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("I2C" + Blockly.Msg.MIXLY_MICROPYTHON_SOCKET_SEND);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
}
};
// IIC写入数线数据
export const i2c_slave_write_array = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('array')
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_WRITE_ARRAY)
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_WRITE_ARRAY_ARRAYNAME);
this.appendValueInput('length')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_LIST_LEN);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_SLAVE_WRITE_ARRAY);
}
};
// IIC从机读取字节数
export const i2c_howmany = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_I2C_HOWMANY);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_HOWMANY);
}
};
// IIC主机或从机读取成功吗
export const i2c_available = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_I2C_AVAILABLE);
this.setOutput(true, Boolean);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_AVAILABLE);
}
};
// IIC主机或从机读取的数据
export const i2c_read = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_I2C_MASTER_READ2);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_MASTER_READ2);
}
};
//写入寄存器地址
export const i2c_master_writerReg = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('device')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_MASTER_WRITE);
this.appendValueInput('regadd')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_REGADD);
this.appendValueInput('value')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_I2C_VALUE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
}
};
//读取寄存器地址
export const i2c_master_readerReg = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('device')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_MASTER_READ);
this.appendValueInput('regadd')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_REGADD);
this.appendValueInput('bytes')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_BYTES);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
}
};
export const i2c_slave_onrequest = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_ONREQUEST);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_SLAVE_ONREQUEST);
}
};
export const i2c_master_writer = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('device')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_MASTER_WRITE);
this.appendValueInput('value')
.setCheck([String, Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.HTML_VALUE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_MASTER_WRITE);
}
};
export const i2c_master_reader = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('device')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_MASTER_READ);
this.appendValueInput('bytes')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_BYTES);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_MASTER_READ);
}
};
export const i2c_master_reader2 = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_I2C_MASTER_READ2);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_MASTER_READ2);
}
};
export const i2c_slave_onreceive = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_ONRECEIVE);
this.appendValueInput("onReceive_length")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_I2C_BYTES);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_SLAVE_ONRECEIVE);
}
};
export const i2c_slave_write = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('value')
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_WRITE)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.HTML_VALUE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_I2C_SLAVE_WRITE);
}
};
//SPI
export const spi_transfer = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput('pin')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.TO_SPI_SLAVE_PIN);
this.appendValueInput('value')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.SPI_TRANSFER);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SPI_TRANSFER.replace('%1', Blockly.Arduino.valueToCode(this, 'pin', Blockly.Arduino.ORDER_ATOMIC)));
}
}
//RFID
export const RFID_init = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_RFID_INITIAL);
this.appendDummyInput("")
.appendField("SDA")
.appendField(new Blockly.FieldDropdown(Profile.default.digital), "SDA");
this.appendDummyInput("")
.appendField("SCK")
.appendField(new Blockly.FieldDropdown(Profile.default.SCK), "SCK");
this.appendDummyInput("")
.appendField("MOSI")
.appendField(new Blockly.FieldDropdown(Profile.default.MOSI), "MOSI");
this.appendDummyInput("")
.appendField("MISO")
.appendField(new Blockly.FieldDropdown(Profile.default.MISO), "MISO");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RFID_INIT);
// this.setFieldValue("10", "SDA");
}
};
export const RFID_on = {
init: function () {
this.appendDummyInput("")
.appendField("RFID")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_RFID_ON_DETECTED);
this.appendStatementInput("do_");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(COMMUNICATE_HUE);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RFID_ON);
}
};
//读卡号
export const RFID_readcardnum = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_RFID_READ_CARDNUM)
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RFID_READ);
}
};
//串口打印卡号
/* export const RFID_serialprintcardnum = {
init: function() {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField('打印RFID卡号');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
}; */
export const RFID_in = {
init: function () {
this.appendValueInput("uid_")
.appendField(Blockly.Msg.CONTROLS_IF_MSG_IF)
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_RFID_READ_CARDNUM_IS);
this.appendStatementInput("do_")
.appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip('');
this.setColour(COMMUNICATE_HUE);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RFID_IN);
}
};
//写数据块
export const RFID_writecarddata = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("address1")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_RFID_WRITE)
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_DATA_BLOCK)
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_WRITE_NUM)
.appendField(new Blockly.FieldTextInput('mylist'), 'data1')
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RFID_WRITEBLOCK);
}
};
//读数据块的内容
export const RFID_readcarddata = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("address")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_RFID_READ)
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_DATA_BLOCK)
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_DATA_FROM)
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RFID_READBLOCK);
}
};
/* //串口打印数据内容
export const RFID_serialprintcarddata = {
init: function() {
this.setColour(COMMUNICATE_HUE);
this.appendValueInput("address")
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField("打印RFID数据块");
this.appendDummyInput("")
.appendField("内容")
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
}
}; */
//关闭RFID
export const RFID_off = {
init: function () {
this.setColour(COMMUNICATE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_RFID_OFF);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_RFID_OFF);
}
};
//初始化RFID
export const MFRC522_init = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SETUP + " RFID")
.appendField(new Blockly.FieldTextInput("rfid"), "rfid_name");
this.appendValueInput("PIN_SDA")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(" SDA");
this.appendValueInput("PIN_SCK")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("SCK");
this.appendValueInput("PIN_MOSI")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("MOSI");
this.appendValueInput("PIN_MISO")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("MISO");
this.appendValueInput("PIN_RST")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("RST");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//RFID侦测到信号
export const MFRC522_IsNewCard = {
init: function () {
this.appendDummyInput()
.appendField("RFID")
.appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
.appendField(" " + Blockly.Msg.MIXLY_COMMUNICATION_RFID_ON_DETECTED);
this.appendStatementInput("DO")
.setCheck(null);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//RFID读取卡号
export const MFRC522_ReadCardUID = {
init: function () {
this.appendDummyInput()
.appendField("RFID")
.appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
.appendField(" " + Blockly.Msg.MIXLY_RFID_READ_CARD_UID);
this.setInputsInline(false);
this.setOutput(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//RFID写卡
export const MFRC522_WriteCard = {
init: function () {
this.appendDummyInput()
.appendField("RFID")
.appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
.appendField(" " + Blockly.Msg.MIXLY_RFID_WRITE_CARD);
this.appendValueInput("block")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_DATA_BLOCK);
this.appendValueInput("buffer")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RFID_BYTE_ARRAY);
this.appendValueInput("length")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_WRITE_ARRAY_ARRAYLENGTH);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//RFID读卡
export const MFRC522_ReadCard = {
init: function () {
this.appendDummyInput()
.appendField("RFID")
.appendField(new Blockly.FieldTextInput("rfid"), "rfid_name")
.appendField(" " + Blockly.Msg.MIXLY_RFID_READ_CARD);
this.appendValueInput("block")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_COMMUNICATION_DATA_BLOCK);
this.appendValueInput("buffer")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.SAVETO + " " + Blockly.Msg.MIXLY_RFID_BYTE_ARRAY);
this.appendValueInput("length")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_I2C_SLAVE_WRITE_ARRAY_ARRAYLENGTH);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//SPI 初始化从机
export const spi_begin_slave = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SETUP + "SPI" + Blockly.Msg.MIXLY_DEVICE + Blockly.Msg.MIXLY_AS + Blockly.Msg.MIXLY_SALVE);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const spi_begin_master = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SETUP + "SPI" + Blockly.Msg.MIXLY_DEVICE + Blockly.Msg.MIXLY_AS + Blockly.Msg.MIXLY_MASTER);
this.appendValueInput("spi_slave_pin")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_SALVE + Blockly.Msg.MIXLY_PIN);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const spi_transfer_Init = {
init: function () {
this.appendValueInput("slave_pin")
.setCheck(null)
.appendField("SPI" + Blockly.Msg.MIXLY_SEND_DATA + Blockly.Msg.MIXLY_SALVE + Blockly.Msg.MIXLY_PIN);
this.appendStatementInput("transfer_data")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const spi_transfer_1 = {
init: function () {
this.appendValueInput("transfer_data")
.setCheck(null)
.appendField("SPI" + Blockly.Msg.MIXLY_MICROPYTHON_SOCKET_SEND);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const spi_transfer_2 = {
init: function () {
this.appendValueInput("transfer_data")
.setCheck(null)
.appendField("SPI" + Blockly.Msg.MIXLY_MICROPYTHON_SOCKET_SEND);
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_RETURN_DATA);
this.setInputsInline(true);
this.setOutput(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const spi_slave_interrupt = {
init: function () {
this.appendValueInput("slave_interrupt_input")
.setCheck(null)
.appendField("SPI " + Blockly.Msg.MIXLY_STM32_I2C_SLAVE_RECEIVE_EVENT + " " + Blockly.Msg.MIXLY_STM32_SPI_GET_REGISTER_DATA);
this.appendStatementInput("slave_interrupt_data")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_MSTIMER2_DO);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const spi_slave_receive = {
init: function () {
this.appendValueInput("slave_receive_data")
.setCheck(null)
.appendField("SPI " + Blockly.Msg.MIXLY_SALVE + " " + Blockly.Msg.MIXLY_STM32_SPI_GET_REGISTER_DATA);
this.setInputsInline(true);
this.setOutput(true, null);
this.setColour(COMMUNICATE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,861 @@
import * as Blockly from 'blockly/core';
const ETHERNET_HUE = 0;
export const ethernet_init_begin = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_BEGIN)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ETHERNET, 'Ethernet'], [Blockly.Msg.MIXLY_ETHERNET2, 'Ethernet2']]), "Ethernet");
this.appendValueInput('MAC')
.setCheck(Array)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_ETHERNET_MAC_ADDRESS);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_INIT);
}
};
export const ethernet_mac_address = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldTextInput('DE'), 'VAR1')
.appendField('-')
.appendField(new Blockly.FieldTextInput('AD'), 'VAR2')
.appendField('-')
.appendField(new Blockly.FieldTextInput('BE'), 'VAR3')
.appendField('-')
.appendField(new Blockly.FieldTextInput('EF'), 'VAR4')
.appendField('-')
.appendField(new Blockly.FieldTextInput('FE'), 'VAR5')
.appendField('-')
.appendField(new Blockly.FieldTextInput('ED'), 'VAR6');
this.setOutput(true, Array);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_MACADDRESS);
}
}
export const ethernet_init_local_ip = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_LOCALIP);
this.setOutput(true, 'IPAddress');
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_LOCALIP);
}
};
export const ethernet_client_connect_server = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_CONNECT_SERVER)
.appendField(this.newQuote_(true))
.appendField(new Blockly.FieldTextInput('mixly.org'), 'SERVER')
.appendField(this.newQuote_(false));
this.appendValueInput('PORT')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_PORT);
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_CONNECT);
},
newQuote_: function (open) {
if (open == this.RTL) {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
} else {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
}
return new Blockly.FieldImage(file, 12, 12, '"');
}
}
export const ethernet_client_stop = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_STOP);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_STOP);
}
};
export const ethernet_client_connected = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_CONNECTED);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_CONNECTED);
}
};
export const ethernet_client_available = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_AVAILABLE);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_CLIENT_AVAILABLE);
}
};
export const ethernet_client_print = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendValueInput('TEXT')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_PRINT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_CLIENT_PRINT);
}
};
export const ethernet_client_println = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendValueInput('TEXT')
.setCheck(String)
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_PRINTLN);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_CLIENT_PRINTLN);
}
};
export const ethernet_client_read = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_READ);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_CLIENT_READ);
}
};
export const ethernet_client_get_request = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_GET_REQUEST);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_URL)
.appendField(this.newQuote_(true))
.appendField(new Blockly.FieldTextInput(''), 'URL')
.appendField(this.newQuote_(false));
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_SERVER)
.appendField(this.newQuote_(true))
.appendField(new Blockly.FieldTextInput(''), 'SERVER')
.appendField(this.newQuote_(false));
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_ETHERNET_GET_REQUEST);
},
newQuote_: function (open) {
if (open == this.RTL) {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
} else {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
}
return new Blockly.FieldImage(file, 12, 12, '"');
}
}
export const NTP_server = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.NTP_SERVER);
this.appendValueInput("server_add")
.appendField(Blockly.Msg.blynk_SERVER_ADD)
.setCheck(String);
this.appendValueInput("timeZone")
.appendField(Blockly.Msg.MIXLY_TimeZone)
.setCheck(Number);
this.appendValueInput("Interval")
.appendField(Blockly.Msg.blynk_WidgetRTC_setSyncInterval)
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
//传感器-实时时钟块_时间变量
var NTP_TIME_TYPE = [
[Blockly.Msg.MIXLY_YEAR, "NTP.getDateYear()"],
[Blockly.Msg.MIXLY_MONTH, "NTP.getDateMonth()"],
[Blockly.Msg.MIXLY_DAY, "NTP.getDateDay()"],
[Blockly.Msg.MIXLY_HOUR, "NTP.getTimeHour24()"],
[Blockly.Msg.MIXLY_MINUTE, "NTP.getTimeMinute()"],
[Blockly.Msg.MIXLY_SECOND, "NTP.getTimeSecond()"],
[Blockly.Msg.MIXLY_WEEK, "NTP.getDateWeekday()"]
];
//传感器-实时时钟块_获取时间
export const NTP_server_get_time = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.NTP_server_get_time);
this.appendDummyInput("")
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldDropdown(NTP_TIME_TYPE), "TIME_TYPE");
this.setInputsInline(true);
this.setOutput(true, Number);
}
};
export const MQTT_server = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldImage(require('../../../../common/media/blynk/iot.png'), 20, 20))
.appendField(Blockly.Msg.MQTT_SERVER);
this.appendValueInput("server_add")
.appendField(Blockly.Msg.MQTT_SERVER_ADD)
.setCheck(String);
this.appendValueInput("server_port")
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_PORT)
.setCheck(Number);
this.appendValueInput("IOT_ID")
.appendField(Blockly.Msg.MIXLY_EMQX_USERNAME)
.setCheck(String);
this.appendValueInput("IOT_PWD", String)
.appendField(Blockly.Msg.HTML_PASSWORD)
.setCheck([String, Number]);
this.appendValueInput("Client_ID")
.appendField(Blockly.Msg.MQTT_Client_ID)
.setCheck(String);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl();
}
};
//WIFI信息
export const WIFI_info = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldImage(require('../../../../common/media/blynk/iot.png'), 20, 20))
.appendField(Blockly.Msg.MIXLY_NETWORK_INIT);
this.appendValueInput("SSID")
.appendField(Blockly.Msg.HTML_NAME);
this.appendValueInput("PWD")
.appendField(Blockly.Msg.HTML_PASSWORD);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(" ");
this.setHelpUrl();
}
};
export const network_connect = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_ESP32_NETWORK_CONNECT);
this.appendValueInput('id')
.setCheck(String)
.appendField(Blockly.Msg.HTML_NAME);
this.appendValueInput('password')
.setCheck(String)
.appendField(Blockly.Msg.HTML_PASSWORD);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_NETWORK_CONNECT_TOOLTIP);
}
};
export const network_wifi_connect = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_NETWORK_WIFI_CONNECT);
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_ESP32_NETWORK_WIFI_CONNECT_TOOLTIP);
}
};
export const network_get_connect = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_GET + Blockly.Msg.MIXLY_DEVICE)
.appendField(new Blockly.FieldDropdown([["MAC", "MAC"], ["IP", "IP"]]), "mode")
.appendField(Blockly.Msg.MQTT_SERVER_ADD);
this.setOutput(true);
this.setInputsInline(true);
}
};
export const MQTT_connect = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MQTT_connect);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip();
}
};
var Topic_validator = function (newValue) {
return newValue.replace(/\//g, '');
};
//MQTT-发送消息到topic
export const MQTT_publish = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldImage(require('../../../../common/media/blynk/iot.png'), 20, 20))
.appendField(Blockly.Msg.MQTT_publish);
this.appendValueInput("data");
this.appendDummyInput("")
.appendField(Blockly.Msg.LANG_MATH_RANDOM_INT_INPUT_TO);
this.appendDummyInput()
.appendField(Blockly.Msg.MQTT_Topic)
.appendField(new Blockly.FieldTextInput('Topic', Topic_validator), "Topic");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(" ");
this.setHelpUrl();
}
};
export const MQTT_subscribe_value = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MQTT_Topic)
.appendField(new Blockly.FieldTextInput('Topic_0', Topic_validator), "Topic_0");
this.appendDummyInput("")
.appendField(Blockly.Msg.HTML_VALUE)
this.setInputsInline(true);
this.setOutput(true, String);
}
};
export const MQTT_add_subscribe_topic = {
/**
* Mutator bolck for else-if condition.
* @this Blockly.Block
*/
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MQTT_Topic);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP);
this.contextMenu = false;
}
};
export const MQTT_subscribe = {
/**
* Block for if/elseif/else condition.
* @this Blockly.Block
*/
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT)
.appendField(Blockly.Msg.MQTT_Topic + Blockly.Msg.MQTT_subscribe2)
.appendField(new Blockly.FieldTextInput('Topic_0', Topic_validator), "Topic_0");
this.appendStatementInput('DO0')
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
this.setPreviousStatement(false);
this.setNextStatement(false);
this.setMutator(new Blockly.icons.MutatorIcon(['MQTT_add_subscribe_topic'], this));
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function () {
if (!thisBlock.elseifCount_) {
return Blockly.Msg.CONTROLS_IF_TOOLTIP_1;
} else if (thisBlock.elseifCount_) {
return Blockly.Msg.CONTROLS_IF_TOOLTIP_3;
}
});
this.elseifCount_ = 0;
},
/**
* Create XML to represent the number of else-if and else inputs.
* @return {Element} XML storage element.
* @this Blockly.Block
*/
mutationToDom: function () {
if (!this.elseifCount_ && !this.elseCount_) {
return null;
}
var container = document.createElement('mutation');
if (this.elseifCount_) {
container.setAttribute('elseif', this.elseifCount_);
}
return container;
},
/**
* Parse XML to restore the else-if and else inputs.
* @param {!Element} xmlElement XML storage element.
* @this Blockly.Block
*/
domToMutation: function (xmlElement) {
var containerBlock = this;
var statementConnections = [];
for (var i = this.elseifCount_; i > 0; i--) {
this.removeInput('DummyInput' + i);
if (containerBlock.getInputTargetBlock('DO' + i) && containerBlock.getInputTargetBlock('DO' + i).previousConnection)
statementConnections[i] = (containerBlock.getInputTargetBlock('DO' + i).previousConnection);
else
statementConnections[i] = null;
this.removeInput('DO' + i);
}
this.elseifCount_ = parseInt(xmlElement.getAttribute('elseif'), 10);
//this.compose(containerBlock);
for (var i = 1; i <= this.elseifCount_; i++) {
this.appendDummyInput('DummyInput' + i)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT)
.appendField(Blockly.Msg.MQTT_Topic + Blockly.Msg.MQTT_subscribe2)
.appendField(new Blockly.FieldTextInput('Topic_' + i, Topic_validator), "Topic_" + i);
this.appendStatementInput('DO' + i)
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
}
for (var i = statementConnections.length - 2; i > 0; i--) {
if (statementConnections[i])
statementConnections[i] && statementConnections[i].reconnect(this, 'DO' + i);
}
},
/**
* 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('mqtt_topics_set');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 1; i <= this.elseifCount_; i++) {
var elseifBlock = workspace.newBlock('MQTT_add_subscribe_topic');
elseifBlock.initSvg();
connection.connect(elseifBlock.previousConnection);
connection = elseifBlock.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) {
// Disconnect all the elseif input blocks and remove the inputs.
for (var i = this.elseifCount_; i > 0; i--) {
this.removeInput('DummyInput' + i);
this.removeInput('DO' + i);
}
this.elseifCount_ = 0;
// Rebuild the block's optional inputs.
var clauseBlock = containerBlock.getInputTargetBlock('STACK');
var statementConnections = [null];
while (clauseBlock) {
switch (clauseBlock.type) {
case 'MQTT_add_subscribe_topic':
this.elseifCount_++;
statementConnections.push(clauseBlock.statementConnection_);
break;
default:
throw Error('Unknown block type: ' + clauseBlock.type);
}
clauseBlock = clauseBlock.nextConnection &&
clauseBlock.nextConnection.targetBlock();
}
this.updateShape_();
// Reconnect any child blocks.
this.reconnectChildBlocks_(statementConnections);
},
/**
* Store pointers to any connected child blocks.
* @param {!Blockly.Block} containerBlock Root block in mutator.
* @this Blockly.Block
*/
saveConnections: function (containerBlock) {
var clauseBlock = containerBlock.getInputTargetBlock('STACK');
var i = 1;
while (clauseBlock) {
switch (clauseBlock.type) {
case 'MQTT_add_subscribe_topic':
var inputDo = this.getInput('DO' + i);
clauseBlock.statementConnection_ =
inputDo && inputDo.connection.targetConnection;
i++;
break;
default:
throw 'Unknown block type.';
}
clauseBlock = clauseBlock.nextConnection &&
clauseBlock.nextConnection.targetBlock();
}
},
/**
* Reconstructs the block with all child blocks attached.
*/
rebuildShape_: function () {
var statementConnections = [null];
var i = 1;
while (this.getInput('DummyInput' + i)) {
var inputDo = this.getInput('DO' + i);
statementConnections.push(inputDo.connection.targetConnection);
i++;
}
this.updateShape_();
this.reconnectChildBlocks_(statementConnections);
},
/**
* Modify this block to have the correct number of inputs.
* @this Blockly.Block
* @private
*/
updateShape_: function () {
var i = 1;
while (this.getInput('DummyInput' + i)) {
this.removeInput('DummyInput' + i);
this.removeInput('DO' + i);
i++;
}
// Rebuild block.
for (var i = 1; i <= this.elseifCount_; i++) {
this.appendDummyInput("DummyInput" + i)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_CURRENT)
.appendField(Blockly.Msg.MQTT_Topic + Blockly.Msg.MQTT_subscribe2)
.appendField(new Blockly.FieldTextInput('Topic_' + i, Topic_validator), "Topic_" + i);
this.appendStatementInput('DO' + i)
.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
}
},
/**
* Reconnects child blocks.
* @param {!Array<?Blockly.RenderedConnection>} valueConnections List of value
* connectsions for if input.
* @param {!Array<?Blockly.RenderedConnection>} statementConnections List of
* statement connections for do input.
* @param {?Blockly.RenderedConnection} elseStatementConnection Statement
* connection for else input.
*/
reconnectChildBlocks_: function (statementConnections) {
for (var i = 1; i <= this.elseifCount_; i++) {
//valueConnections[i] && valueConnections[i].reconnect(this, 'IF' + i);
statementConnections[i] && statementConnections[i].reconnect(this, 'DO' + i);
}
}
};
export const mqtt_topics_set = {
/**
* Mutator block for if container.
* @this Blockly.Block
*/
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_EMQX_SUBSCRIBE + Blockly.Msg.MQTT_Topic);
this.appendStatementInput('STACK');
this.contextMenu = false;
}
};
//GET请求
export const http_get = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_GET_REQUEST);
this.appendValueInput("api")
.setCheck(null)
.appendField(Blockly.Msg.blynk_SERVER_ADD);
this.appendStatementInput("success")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_SUCCESS);
this.appendStatementInput("failure")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_FAILED);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(ETHERNET_HUE);
this.setTooltip("");
}
};
//自动配网
export const WIFI_smartConfig = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.blynk_smartconfig)
.appendField(new Blockly.FieldDropdown([["SmartConfig", 'SmartConfig'], ["AP", 'AP']]), "MODE");
this.setInputsInline(true);
this.setPreviousStatement(true, null);//可上下连接
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MQTT_TEST_TOOLTIP);
}
};
export const WIFI_ap_or_sta = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/blynk/wifi_udp.png'), 25, 25, "*"))
.appendField(Blockly.Msg.MIXLY_SETUP + " UDP WIFI");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_MODE + ":")
.appendField(new Blockly.FieldDropdown([["STA", "STA"], ["AP", "AP"]]), "mode");
this.appendValueInput("SSID")
.setCheck(null)
.appendField("WIFI " + Blockly.Msg.HTML_NAME);
this.appendValueInput("PSK")
.setCheck(null)
.appendField("WIFI " + Blockly.Msg.HTML_PASSWORD);
this.appendValueInput("IP1")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_WIFI_LINK_DEVICE + " IP1");
this.appendValueInput("IP2")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_WIFI_LINK_DEVICE + " IP2");
this.appendValueInput("IP")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_ESP32_BLUETOOTH_FLAG + " IP");
this.appendValueInput("duankou")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_PORT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(ETHERNET_HUE);
this.setHelpUrl("");
}
};
export const WIFI_ap_and_sta = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/blynk/wifi_udp.png'), 25, 25, "*"))
.appendField(Blockly.Msg.MIXLY_SETUP + " UDP WIFI");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_MODE + ": AP+STA");
this.appendValueInput("SSID1")
.setCheck(null)
.appendField("WIFI " + Blockly.Msg.HTML_NAME + "(STA)");
this.appendValueInput("SSID2")
.setCheck(null)
.appendField("WIFI " + Blockly.Msg.HTML_NAME + "(AP)");
this.appendValueInput("PSK1")
.setCheck(null)
.appendField("WIFI " + Blockly.Msg.HTML_PASSWORD + "(STA)");
this.appendValueInput("PSK2")
.setCheck(null)
.appendField("WIFI " + Blockly.Msg.HTML_PASSWORD + "(AP)");
this.appendValueInput("IP1")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_WIFI_LINK_DEVICE + " IP1");
this.appendValueInput("IP2")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_WIFI_LINK_DEVICE + " IP2");
this.appendValueInput("IP")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_ESP32_BLUETOOTH_FLAG + " IP");
this.appendValueInput("duankou")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_ETHERNET_CLINET_PORT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(ETHERNET_HUE);
this.setHelpUrl("");
}
};
export const WIFI_incomingPacket = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/blynk/wifi_udp.png'), 25, 25, "*"))
.appendField(Blockly.Msg.CONTROLS_IF_MSG_IF + " WIFI UDP " + Blockly.Msg.MIXLY_STM32_SPI_DATA_RECEIVED + "")
this.appendValueInput("input_data")
.setCheck(null)
.appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS);
this.appendDummyInput()
.appendField("(" + Blockly.Msg.LANG_MATH_STRING + ")");
this.appendStatementInput("do")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(ETHERNET_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const WIFI_send_data = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/blynk/wifi_udp.png'), 25, 25, "*"))
.appendField("WIFI UDP " + Blockly.Msg.MIXLY_SEND_DATA);
this.appendValueInput("data")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(ETHERNET_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//天气GET
export const WeatherGet = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.WeatherGet)
.appendField(new Blockly.FieldTextInput('北京'), 'data')
.appendField("1", "check");
this.setOutput(true, Boolean);
this.setTooltip("输入正确的城市名(不用带“市”字)如:深圳 北京 广州,如果错误会显示'error'刷新成功则返回true\n天气接口优化注意\n1. 接口每 8 小时更新一次,机制是 CDN 缓存 8 小时更新一次。注意:自己做缓存。\n2. 接口采用城市 ID 来精准查询请求,省份不能直接查询天气。\n3.每分钟阈值为 300 次,如果超过会禁用一天。请谨慎使用。");
}
};
//获取当天天气
export const WeatherGetToday = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.WeatherGetToday)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_Humidity, "0"], ['PM2.5', "1"], ['PM1.0', "2"], [Blockly.Msg.TodayQuality, "3"], [Blockly.Msg.MIXLY_TEMPERATURE, "4"]]), "type");
this.setOutput(true, Number);
this.setTooltip("返回对应数据 字符串型。");
}
};
//获取当天天气
export const WeatherGetForecast = {
init: function () {
this.setColour(ETHERNET_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.WeatherGetForecast)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_GPS_DATE, "ForecastDate"], [Blockly.Msg.ForecastHigh, "ForecastHigh"], [Blockly.Msg.ForecastLow, "ForecastLow"], [Blockly.Msg.ForecastYmd, "ForecastYmd"], [Blockly.Msg.MIXLY_WEEK, "ForecastWeek"], [Blockly.Msg.ForecastAqi, "ForecastAqi"], [Blockly.Msg.ForecastFx, "ForecastFx"], [Blockly.Msg.ForecastFl, "ForecastFl"], [Blockly.Msg.ForecastType, "ForecastType"]]), "type");
this.appendValueInput('date', Number)
.appendField(Blockly.Msg.MIXLY_GPS_DATE + '(0~14)');
this.setOutput(true, Number);
this.setTooltip("返回预报天气内容0表示当天最大为14字符串型。");
this.setInputsInline(true);
}
};
export const mixio_mqtt_subscribe = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
this.appendValueInput("server")
.setCheck(null)
.appendField(Blockly.Msg.blynk_SERVER_ADD);
this.appendValueInput("port")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_EMQX_PORT);
this.appendValueInput("mqtt_username")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_WIFI_USERNAME);
this.appendValueInput("mqtt_password")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_WIFI_PASSWORD);
this.appendValueInput("project")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_EMQX_PROJECT);
//this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(170);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const mixio_mqtt_subscribe_key = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.USE_MIXLY_KEY)
.appendField(new Blockly.FieldTextInput("1RFOH08C"), "key")
.appendField(Blockly.Msg.CONNECT_TO_MIXIO)
.appendField(Blockly.Msg.blynk_SERVER_ADD)
.appendField(new Blockly.FieldTextInput("mixio.mixly.cn"), "server");
this.setNextStatement(true, null);
this.setColour(170);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const mixio_mqtt_publish = {
init: function () {
this.appendValueInput("data")
.setCheck(null)
.appendField(Blockly.Msg.MQTT_SEND_MESSAGE);
this.appendValueInput("topic")
.setCheck(null)
.appendField(Blockly.Msg.TO_TOPIC);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([["MixIO", "1"], ["Mixly Key", "2"]]), "mode");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(170);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const mixio_mqtt_received_the_news = {
init: function () {
this.appendValueInput("topic")
.setCheck(null)
.appendField(Blockly.Msg.WHEN_THE_SUBJECT_IS_RECEIVED);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MICROBIT_MSG)
.appendField(new Blockly.FieldDropdown([["MixIO", "1"], ["Mixly Key", "2"]]), "mode");
this.appendStatementInput("function")
.setCheck(null);
this.setPreviousStatement(false, null);
this.setNextStatement(false, null);
this.setColour(170);
this.setTooltip("");
this.setHelpUrl("");
}
};
//OTA
export const asyncelegantota = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/blocks_icons/loop.png'), 15, 15, { alt: "*", flipRtl: "FALSE" }))
.appendField("ElegantOTA");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(120);
this.setTooltip("http://ip/update");
this.setHelpUrl("");
}
};

View File

@@ -0,0 +1,321 @@
import * as Blockly from 'blockly/core';
const FACTORY_HUE = "#777777";
export const factory_include = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField("#include <")
.appendField(new Blockly.FieldTextInput('Test'), 'INCLUDE')
.appendField(".h>");
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('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('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'), 'TYPE')
.appendField(" ")
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
.appendField(";");
this.setPreviousStatement(true);
this.setNextStatement(true);
}
}
export const factory_declare2 = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldMultilineInput('//define user code;'), 'VALUE');
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const factory_define = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('#define'), 'TYPE')
.appendField(" ")
.appendField(new Blockly.FieldTextInput('MYDEFINE 11'), 'NAME')
this.setPreviousStatement(true);
this.setNextStatement(true);
}
}
export const factory_static_method_noreturn = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('Test'), 'TYPE')
.appendField("::")
.appendField(new Blockly.FieldTextInput('staticMethod'), '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: 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_static_method_return = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('Test'), 'TYPE')
.appendField("::")
.appendField(new Blockly.FieldTextInput('staticMethod'), '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_callMethod_noreturn = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
.appendField('.')
.appendField(new Blockly.FieldTextInput('callMetod'), '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('callMetod'), '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('Serial.println("hello");'), '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('Serial.println("Hello");\nSerial.println("Mixly");'), 'VALUE');
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const factory_block_return_with_textarea = {
init: function () {
this.setColour(FACTORY_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldMultilineInput('Hello\nMixly'), 'VALUE');
this.setOutput(true);
}
};

View File

@@ -0,0 +1,420 @@
import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';
const BASE_HUE = 20;//'#ae3838';//40;
export const inout_highlow = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_HIGH, "HIGH"], [Blockly.Msg.MIXLY_LOW, "LOW"]]), 'BOOL')
this.setOutput(true, Boolean);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_HIGHLOW);
}
};
export const inout_pinMode = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_PINMODE)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_STAT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_PINMODEIN, "INPUT"], [Blockly.Msg.MIXLY_PINMODEOUT, "OUTPUT"], [Blockly.Msg.MIXLY_PINMODEPULLUP, "INPUT_PULLUP"]]), "MODE")
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_pinMode);
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '管脚模式']
}
};
}
};
export const inout_digital_write2 = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_DIGITALWRITE_PIN)
.setCheck(Number);
this.appendValueInput("STAT")
.appendField(Blockly.Msg.MIXLY_STAT)
.setCheck([Number, Boolean]);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.LANG_INOUT_DIGITAL_WRITE_TOOLTIP);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id2");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '数字输出']
}
};
}
};
export const inout_digital_read = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_DIGITALREAD_PIN)
.appendField(new Blockly.FieldDropdown(Profile.default.digital), "PIN");
this.setOutput(true, [Boolean, Number]);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_DIGITAL_READ);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id7");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '数字输入']
}
};
}
};
export const inout_digital_read2 = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_DIGITALREAD_PIN)
.setCheck(Number);
this.setInputsInline(true);
this.setOutput(true, [Boolean, Number]);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_DIGITAL_READ);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id19");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '数字输入']
}
};
}
};
export const inout_analog_write = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_ANALOGWRITE_PIN)
.setCheck(Number);
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_VALUE2)
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_WRITE);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id13");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '模拟输出']
}
};
}
};
export const inout_analog_read = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_ANALOGREAD_PIN)
.setCheck(Number);
this.setInputsInline(true);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_READ);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id13");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '模拟输入']
}
};
}
};
export const inout_buildin_led = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_BUILDIN_LED)
.appendField(Blockly.Msg.MIXLY_STAT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_ON, "HIGH"], [Blockly.Msg.MIXLY_OFF, "LOW"]]), "STAT");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('light or off the build-in LED');
}
};
export const OneButton_interrupt = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.ONEBUTTON + " " + Blockly.Msg.MIXLY_PIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_CLICK, "attachClick"], [Blockly.Msg.MIXLY_DOUBLE_CLICK, "attachDoubleClick"], [Blockly.Msg.MIXLY_LONG_PRESS_START, "attachLongPressStart"], [Blockly.Msg.MIXLY_DURING_LONG_PRESS, "attachDuringLongPress"], [Blockly.Msg.MIXLY_LONG_PRESS_END, "attachLongPressStop"]]), "mode");
this.appendValueInput("STAT")
.appendField(Blockly.Msg.MIXLY_ELECLEVEL);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ATTACHINTERRUPT);
this.setHelpUrl();
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '多功能按键']
}
};
}
};
export const controls_attachInterrupt = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_ATTACHINTERRUPT_PIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MODE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_RISING, "RISING"], [Blockly.Msg.MIXLY_FALLING, "FALLING"], [Blockly.Msg.MIXLY_CHANGE, "CHANGE"]]), "mode");
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ATTACHINTERRUPT);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id25");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '硬件中断'],
scrollPos: '硬件中断'
}
};
}
};
export const controls_detachInterrupt = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_DETACHINTERRUPT_PIN)
.setCheck(Number);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_DETACHINTERRUPT);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id30");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '硬件中断'],
scrollPos: '取消硬件中断'
}
};
}
};
export const controls_attachPinInterrupt = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_ATTACHPININTERRUPT_PIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MODE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_RISING, "RISING"], [Blockly.Msg.MIXLY_FALLING, "FALLING"], [Blockly.Msg.MIXLY_CHANGE, "CHANGE"]]), "mode");
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ATTACHINTERRUPT);
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '软件中断'],
scrollPos: '软件中断'
}
};
}
};
export const controls_detachPinInterrupt = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_DETACHPININTERRUPT_PIN)
.setCheck(Number);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_DETACHINTERRUPT);
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '软件中断'],
scrollPos: '取消软件中断'
}
};
}
};
export const inout_pulseIn = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_PULSEIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_PULSEIN_STAT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_HIGH, "HIGH"], [Blockly.Msg.MIXLY_LOW, "LOW"]]), "STAT");
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_pulseIn);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id33");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '脉冲长度']
}
};
}
};
export const inout_pulseIn2 = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_PULSEIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_PULSEIN_STAT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_HIGH, "HIGH"], [Blockly.Msg.MIXLY_LOW, "LOW"]]), "STAT");
this.appendValueInput("TIMEOUT", Number)
.appendField(Blockly.Msg.MIXLY_PULSEIN_TIMEOUT)
.setCheck(Number);
this.setInputsInline(true);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_pulseIn2);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#id33");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', '脉冲长度']
}
};
}
};
export const inout_shiftout = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("")
.appendField("ShiftOut");
this.appendValueInput("PIN1", Number)
.appendField(Blockly.Msg.MIXLY_DATAPIN)
.setCheck(Number);
this.appendValueInput("PIN2", Number)
.appendField(Blockly.Msg.MIXLY_CLOCKPIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_BITORDER)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_MSBFIRST, "MSBFIRST"], [Blockly.Msg.MIXLY_LSBFIRST, "LSBFIRST"]]), "ORDER");
this.appendValueInput("DATA", Number)
.appendField(Blockly.Msg.MIXLY_DATA)
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_shiftout);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/02.Input-Output.html#shiftout");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '输入输出', 'ShiftOut']
}
};
}
};
export const ESP32touchButton = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField("ESP32" + Blockly.Msg.MIXLY_ESP32_TOUCH + Blockly.Msg.ONEBUTTON + " " + Blockly.Msg.MIXLY_PIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MODE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_CLICK, "attachClick"], [Blockly.Msg.MIXLY_DOUBLE_CLICK, "attachDoubleClick"], [Blockly.Msg.MIXLY_LONG_PRESS_START, "attachLongPressStart"], [Blockly.Msg.MIXLY_DURING_LONG_PRESS, "attachDuringLongPress"], [Blockly.Msg.MIXLY_LONG_PRESS_END, "attachLongPressStop"]]), "mode");
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setTooltip();
this.setHelpUrl();
}
};
export const inout_soft_analog_write = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_SOFT_ANALOGWRITE_PIN)
.setCheck(Number);
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_VALUE2)
.setCheck(Number);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_WRITE);
this.setHelpUrl("");
}
};
export const inout_cancel_soft_analog_write = {
init: function () {
this.setColour(BASE_HUE);
this.appendValueInput("PIN", Number)
.appendField(Blockly.Msg.MIXLY_CANCEL_SOFT_ANALOGWRITE_PIN)
.setCheck(Number);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CANCEL_SOFT_ANALOGWRITE_PIN);
this.setHelpUrl("");
}
};
//ADS1015模拟数字转换模块-获取数据
var ADS1015_setGain_type = [
["±6.144V 3mv/bit", "GAIN_TWOTHIRDS"],
["±4.096V 2mv/bit", "GAIN_ONE"],
["±2.048V 1mv/bit", "GAIN_TWO"],
["±1.024V 0.5mv/bit", "GAIN_FOUR"],
["±0.512V 0.25mv/bit", "GAIN_EIGHT"],
["±0.256V 0.125mv/bit", "GAIN_SIXTEEN"],
];
//ADS1015模拟数字转换模块-增益设置
export const ADS1015_setGain = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("").appendField(Blockly.Msg.MIXLY_SETTING).appendField(Blockly.Msg.ADS1015_setGain);
this.appendDummyInput("").setAlign(Blockly.inputs.Align.RIGHT).appendField(new Blockly.FieldDropdown(ADS1015_setGain_type), "ADS1015_setGain");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
}
};
//ADS1015模拟数字转换模块 数值获取
export const ADS1015_Get_Value = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("").appendField("ADS1015" + Blockly.Msg.ADS1015_Get_Value);
this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["AIN0", "ads.readADC_SingleEnded(0)"], ["AIN1", "ads.readADC_SingleEnded(1)"], ["AIN2", "ads.readADC_SingleEnded(2)"], ["AIN3", "ads.readADC_SingleEnded(3)"]]), "ADS1015_AIN");
this.setInputsInline(true);
this.setOutput(true);
}
};
//PCF8591T模拟数字转换模块 数值获取
export const PCF8591T = {
init: function () {
this.setColour(BASE_HUE);
this.appendDummyInput("").appendField("PCF8591T" + Blockly.Msg.ADS1015_Get_Value);
this.appendDummyInput("").appendField(new Blockly.FieldDropdown([["AIN0", "pcf8591.analogRead(AIN0)"], ["AIN1", "pcf8591.analogRead(AIN1)"], ["AIN2", "pcf8591.analogRead(AIN2)"], ["AIN3", "pcf8591.analogRead(AIN3)"]]), "PCF8591T_AIN");
this.setInputsInline(true);
this.setOutput(true);
}
};

View File

@@ -0,0 +1,749 @@
import * as Blockly from 'blockly/core';
const LISTS_HUE = 260;
const DATATYPES = [
[Blockly.Msg.LANG_MATH_INT, 'int'],
[Blockly.Msg.LANG_MATH_UNSIGNED_INT, 'unsigned int'],
[Blockly.Msg.LANG_MATH_WORD, 'word'],
[Blockly.Msg.LANG_MATH_LONG, 'long'],
[Blockly.Msg.LANG_MATH_UNSIGNED_LONG, 'unsigned long'],
[Blockly.Msg.LANG_MATH_FLOAT, 'float'],
[Blockly.Msg.LANG_MATH_DOUBLE, 'double'],
[Blockly.Msg.LANG_MATH_BOOLEAN, 'boolean'],
[Blockly.Msg.LANG_MATH_BYTE, 'byte'],
[Blockly.Msg.LANG_MATH_CHAR, 'char'],
[Blockly.Msg.LANG_MATH_UNSIGNED_CHAR, 'unsigned char'],
[Blockly.Msg.LANG_MATH_STRING, 'String']
];
export const lists_create_with = {
/**
* Block for creating a list with any number of elements of any type.
* @this Blockly.Block
*/
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(DATATYPES), "TYPE")
.appendField(' ')
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField('[')
.appendField(new Blockly.FieldTextInput('3', Blockly.FieldTextInput.math_number_validator), 'SIZE')
.appendField(']');
this.itemCount_ = 3;
this.updateShape_();
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setMutator(new Blockly.icons.MutatorIcon(['lists_create_with_item'], this));
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_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('lists_create_with_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('lists_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');
} 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.LISTS_CREATE_EMPTY_TITLE);
} else {
for (var i = 0; i < this.itemCount_; i++) {
var input = this.appendValueInput('ADD' + i);
if (i == 0) {
input.appendField(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH);
}
}
}
}
};
export const lists_create_with_text = {
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(DATATYPES), "TYPE")
.appendField(' ')
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField('[')
.appendField(new Blockly.FieldTextInput('3', Blockly.FieldTextInput.math_number_validator), 'SIZE')
.appendField(']')
.appendField(Blockly.Msg.MIXLY_MAKELISTFROM)
.appendField(this.newQuote_(true))
.appendField(new Blockly.FieldTextInput('0,0,0'), 'TEXT')
.appendField(this.newQuote_(false))
.appendField(Blockly.Msg.MIXLY_SPLITBYDOU);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_LISTS_CREATE_WITH_TEXT);
},
newQuote_: function (open) {
if (open == this.RTL) {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
} else {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
}
return new Blockly.FieldImage(file, 12, 12, '"');
}
}
export const lists_create_with2 = {
/**
* Block for creating a list with any number of elements of any type.
* @this Blockly.Block
*/
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(DATATYPES), "TYPE")
.appendField(' ')
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField('[')
//.appendField(new Blockly.FieldTextInput('3',Blockly.FieldTextInput.math_number_validator), 'SIZE')
.appendField(']');
this.itemCount_ = 3;
this.updateShape_();
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setMutator(new Blockly.icons.MutatorIcon(['lists_create_with_item'], this));
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_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('lists_create_with_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('lists_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');
} 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.LISTS_CREATE_EMPTY_TITLE);
} else {
for (var i = 0; i < this.itemCount_; i++) {
var input = this.appendValueInput('ADD' + i);
if (i == 0) {
input.appendField(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH);
}
}
}
}
};
export const lists_create_with_text2 = {
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(DATATYPES), "TYPE")
.appendField(' ')
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField('[')
.appendField(new Blockly.FieldTextInput("3"), "SIZE")
.appendField(']')
.appendField(Blockly.Msg.MIXLY_MAKELISTFROM)
.appendField(this.newQuote_(true))
.appendField(new Blockly.FieldTextInput('0,0,0'), 'TEXT')
.appendField(this.newQuote_(false))
.appendField(Blockly.Msg.MIXLY_SPLITBYDOU);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_LISTS_CREATE_WITH_TEXT);
},
newQuote_: function (open) {
if (open == this.RTL) {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
} else {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
}
return new Blockly.FieldImage(file, 12, 12, '"');
}
}
export const lists_create_with_container = {
/**
* Mutator block for list container.
* @this Blockly.Block
*/
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD);
this.appendStatementInput('STACK');
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TOOLTIP);
this.contextMenu = false;
}
};
export const lists_create_with_item = {
/**
* Mutator bolck for adding items.
* @this Blockly.Block
*/
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TOOLTIP);
this.contextMenu = false;
}
};
export const lists_getIndex = {
init: function () {
this.setColour(LISTS_HUE);
this.setOutput(true, Number);
this.appendValueInput('AT')
.setCheck(Number)
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField(Blockly.Msg.LANG_LISTS_GET_INDEX1);
this.appendDummyInput("")
.appendField(Blockly.Msg.LANG_LISTS_GET_INDEX2);
this.appendDummyInput()
.appendField('(' + Blockly.Msg.MIXLY_DEPRECATED + ')');
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.LANG_LISTS_GET_INDEX_TOOLTIP);
this.setWarningText(Blockly.Msg.MIXLY_DEPRECATED_WARNING_TEXT);
}
};
export const lists_setIndex = {
init: function () {
this.setColour(LISTS_HUE);
this.appendValueInput('AT')
.setCheck(Number)
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField(Blockly.Msg.LANG_LISTS_SET_INDEX1);
this.appendValueInput('TO')
.appendField(Blockly.Msg.LANG_LISTS_SET_INDEX2);
this.appendDummyInput()
.appendField('(' + Blockly.Msg.MIXLY_DEPRECATED + ')');
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.LANG_LISTS_SET_INDEX_TOOLTIP);
this.setWarningText(Blockly.Msg.MIXLY_DEPRECATED_WARNING_TEXT);
}
};
export const listsGetValueByIndex = {
init: function () {
this.setColour(LISTS_HUE);
this.setOutput(true, Number);
this.appendValueInput('AT')
.setCheck(Number)
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField(Blockly.Msg.LANG_LISTS_GET_INDEX1);
this.appendDummyInput("")
.appendField(Blockly.Msg.LANG_LISTS_GET_INDEX2);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.LANG_LISTS_GET_VALUE_BY_INDEX_TOOLTIP);
}
};
export const listsSetValueByIndex = {
init: function () {
this.setColour(LISTS_HUE);
this.appendValueInput('AT')
.setCheck(Number)
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField(Blockly.Msg.LANG_LISTS_SET_INDEX1);
this.appendValueInput('TO')
.appendField(Blockly.Msg.LANG_LISTS_SET_INDEX2);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.LANG_LISTS_SET_VALUE_BY_INDEX_TOOLTIP);
}
};
export const lists_length = {
/**
* Block for list length.
* @this Blockly.Block
*/
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_LENGTH)
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR');
this.setTooltip(Blockly.Msg.LISTS_LENGTH_TOOLTIP);
this.setOutput(true, Number);
}
};
//创建二维数组
export const create_array2_with_text = {
init: function () {
this.setColour(LISTS_HUE);
this.appendValueInput("name")
.setCheck(null)
.appendField(new Blockly.FieldDropdown(DATATYPES), "TYPE")
.appendField(Blockly.Msg.MIXLY_ARRAY2);
this.appendValueInput("line")
.setCheck(null)
.appendField(Blockly.Msg.array2_rows);
this.appendValueInput("list")
.setCheck(null)
.appendField(Blockly.Msg.array2_cols);
this.appendValueInput("String")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_MAKELISTFROM);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ESP32_SET);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setHelpUrl("");
}
};
//二维数组赋值
export const array2_assignment = {
init: function () {
this.setColour(LISTS_HUE);
this.appendValueInput("name")
.setCheck(null)
.appendField(Blockly.Msg.array2_assignment);
this.appendValueInput("line")
.appendField(Blockly.Msg.DATAFRAME_RAW)
this.appendValueInput("list")
.appendField(Blockly.Msg.DATAFRAME_COLUMN);
this.appendValueInput("assignment")
.appendField(Blockly.Msg.MIXLY_VALUE2);
this.appendDummyInput()
.appendField('(' + Blockly.Msg.MIXLY_DEPRECATED + ')');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setHelpUrl("");
this.setWarningText(Blockly.Msg.MIXLY_DEPRECATED_WARNING_TEXT);
}
};
//获取二维数组值
export const get_array2_value = {
init: function () {
this.setColour(LISTS_HUE);
this.appendValueInput("name")
.setCheck(null)
.appendField(Blockly.Msg.get_array2_value);
this.appendValueInput("line")
.appendField(Blockly.Msg.DATAFRAME_RAW);
this.appendValueInput("list")
.appendField(Blockly.Msg.DATAFRAME_COLUMN);
this.appendDummyInput()
.appendField('(' + Blockly.Msg.MIXLY_DEPRECATED + ')');
this.setInputsInline(true);
this.setOutput(true, null);
this.setHelpUrl("");
this.setWarningText(Blockly.Msg.MIXLY_DEPRECATED_WARNING_TEXT);
}
};
//二维数组赋值
export const lists2SetValueByIndex = {
init: function () {
this.setColour(LISTS_HUE);
this.appendValueInput("name")
.setCheck(null)
.appendField(Blockly.Msg.array2_assignment);
this.appendValueInput("line")
.appendField(Blockly.Msg.DATAFRAME_RAW)
this.appendValueInput("list")
.appendField(Blockly.Msg.DATAFRAME_COLUMN);
this.appendValueInput("assignment")
.appendField(Blockly.Msg.MIXLY_VALUE2);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setHelpUrl("");
this.setTooltip(Blockly.Msg.LANG_LISTS_SET_VALUE_BY_INDEX_TOOLTIP);
}
};
//二维数组取值
export const lists2GetValueByIndex = {
init: function () {
this.setColour(LISTS_HUE);
this.appendValueInput("name")
.setCheck(null)
.appendField(Blockly.Msg.get_array2_value);
this.appendValueInput("line")
.appendField(Blockly.Msg.DATAFRAME_RAW);
this.appendValueInput("list")
.appendField(Blockly.Msg.DATAFRAME_COLUMN);
this.setInputsInline(true);
this.setOutput(true, null);
this.setHelpUrl("");
this.setTooltip(Blockly.Msg.LANG_LISTS_GET_VALUE_BY_INDEX_TOOLTIP);
}
};
export const lists_array2_setup = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SETUP + Blockly.Msg.MIXLY_ARRAY2);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(DATATYPES), "lists_create_type")
.appendField(new Blockly.FieldTextInput("mylist"), "lists_create_name")
.appendField("[ ][ ]");
this.appendStatementInput("lists_with_2_1_data")
.setCheck(null)
.appendField(Blockly.Msg.VARIABLES_SET_TITLE);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(LISTS_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const lists_array2_setup_get_data = {
/**
* Block for creating a list with any number of elements of any type.
* @this Blockly.Block
*/
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("");
this.itemCount_ = 3;
this.updateShape_();
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setMutator(new Blockly.icons.MutatorIcon(['lists_create_with_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('lists_create_with_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('lists_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');
} else {
var i = 0;
while (this.getInput('ADD' + i)) {
this.removeInput('ADD' + i);
i++;
}
}
// Rebuild block.
if (this.itemCount_ == 0) {
this.appendDummyInput('EMPTY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("");
} else {
for (var i = 0; i <= this.itemCount_; i++) {
if (i > 0 && i < this.itemCount_) {
var input = this.appendValueInput('ADD' + i);
input.setAlign(Blockly.inputs.Align.RIGHT)
input.appendField(",");
}
if (i == 0) {
var input = this.appendValueInput('ADD' + i);
input.setAlign(Blockly.inputs.Align.RIGHT);
input.appendField("{");
}
else if (i == this.itemCount_) {
var input = this.appendDummyInput('ADD' + i);
input.setAlign(Blockly.inputs.Align.RIGHT);
input.appendField("}");
}
}
}
}
};
//一维数组循环
export const loop_array = {
init: function () {
this.appendValueInput("name")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_CONTORL_GET_TYPE).appendField(new Blockly.FieldDropdown(DATATYPES), "TYPE")
.appendField(Blockly.Msg.MIXLY_LIST_NAME);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.LEFT_CYCLE, "0"], [Blockly.Msg.RIGHT_CYCLE, "1"]]), "mode");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(LISTS_HUE);
this.setTooltip(Blockly.Msg.LEFT_CYCLE + Blockly.Msg.LEFT_CYCLE1 + Blockly.Msg.RIGHT_CYCLE + Blockly.Msg.RIGHT_CYCLE1);
this.setHelpUrl("");
}
};
//获取二维数组的行数与列数
export const lists_array2_get_length = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_ARRAY2)
.appendField(new Blockly.FieldTextInput("mylist"), "list_name")
.appendField(" " + Blockly.Msg.MIXLY_GET)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.array2_rows, "row"], [Blockly.Msg.array2_cols, "col"]]), "type");
this.setInputsInline(true);
this.setOutput(true, null);
this.setColour(LISTS_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};

View File

@@ -0,0 +1,149 @@
import * as Blockly from 'blockly/core';
const LOGIC_HUE = 210;
export const logic_compare = {
/**
* Block for comparison operator.
* @this Blockly.Block
*/
init: function () {
var OPERATORS = Blockly.RTL ? [
['=', 'EQ'],
['\u2260', 'NEQ'],
['>', 'LT'],
['\u2265', 'LTE'],
['<', 'GT'],
['\u2264', 'GTE']
] : [
['=', 'EQ'],
['\u2260', 'NEQ'],
['<', 'LT'],
['\u2264', 'LTE'],
['>', 'GT'],
['\u2265', 'GTE']
];
//this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL);
this.setColour(LOGIC_HUE);
this.setOutput(true, Boolean);
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 op = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'EQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,
'NEQ': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,
'LT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,
'LTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,
'GT': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,
'GTE': Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE
};
return TOOLTIPS[op];
});
this.prevBlocks_ = [null, null];
}
};
export const logic_operation = {
/**
* Block for logical operations: 'and', 'or'.
* @this Blockly.Block
*/
init: function () {
var OPERATORS = [
[Blockly.Msg.LOGIC_OPERATION_AND, 'AND'],
[Blockly.Msg.LOGIC_OPERATION_OR, 'OR']
];
//this.setHelpUrl(Blockly.Msg.LOGIC_OPERATION_HELPURL);
this.setColour(LOGIC_HUE);
this.setOutput(true, Boolean);
this.appendValueInput('A')
.setCheck([Boolean, Number]);
this.appendValueInput('B')
.setCheck([Boolean, Number])
.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 op = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'AND': Blockly.Msg.LOGIC_OPERATION_TOOLTIP_AND,
'OR': Blockly.Msg.LOGIC_OPERATION_TOOLTIP_OR
};
return TOOLTIPS[op];
});
}
};
export const logic_negate = {
/**
* Block for negation.
* @this Blockly.Block
*/
init: function () {
//this.setHelpUrl(Blockly.Msg.LOGIC_NEGATE_HELPURL);
this.setColour(LOGIC_HUE);
this.setOutput(true, Boolean);
this.appendValueInput('BOOL')
.setCheck([Number, Boolean])
.appendField(Blockly.Msg.LOGIC_NEGATE_TITLE);
//this.interpolateMsg(Blockly.Msg.LOGIC_NEGATE_TITLE,
// ['BOOL', Boolean, Blockly.inputs.Align.RIGHT],
// Blockly.inputs.Align.RIGHT);
this.setTooltip(Blockly.Msg.LOGIC_NEGATE_TOOLTIP);
}
};
export const logic_boolean = {
/**
* Block for boolean data type: true and false.
* @this Blockly.Block
*/
init: function () {
var BOOLEANS = [
[Blockly.Msg.LOGIC_BOOLEAN_TRUE, 'TRUE'],
[Blockly.Msg.LOGIC_BOOLEAN_FALSE, 'FALSE']
];
//this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);
this.setColour(LOGIC_HUE);
this.setOutput(true, Boolean);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(BOOLEANS), 'BOOL');
this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP);
}
};
export const logic_null = {
/**
* Block for null data type.
* @this Blockly.Block
*/
init: function () {
//this.setHelpUrl(Blockly.Msg.LOGIC_NULL_HELPURL);
this.setColour(LOGIC_HUE);
this.setOutput(true);
this.appendDummyInput()
.appendField(Blockly.Msg.LOGIC_NULL);
this.setTooltip(Blockly.Msg.LOGIC_NULL_TOOLTIP);
}
};
export const logic_true_or_false = {
init: function () {
this.setColour(LOGIC_HUE);
this.appendValueInput('A');
this.appendValueInput('B')
.appendField(Blockly.Msg.LOGIC_TERNARY_IF_TRUE);
this.appendValueInput('C')
.appendField(Blockly.Msg.LOGIC_TERNARY_IF_FALSE);
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_LOGIT_TRUEORFALSE);
}
};

View File

@@ -0,0 +1,360 @@
import * as Blockly from 'blockly/core';
const MATH_HUE = 230;
Blockly.FieldTextInput.math_number_validator = function (text) {
//return window.isNaN(text) ? null : String(text);
return String(text);//不再校验
};
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);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#id2");
}
};
export const math_arithmetic = {
/**
* Block for basic arithmetic operator.
* @this Blockly.Block
*/
init: function () {
var OPERATORS = [
[Blockly.Msg.MATH_ADDITION_SYMBOL, 'ADD'],
[Blockly.Msg.MATH_SUBTRACTION_SYMBOL, 'MINUS'],
[Blockly.Msg.MATH_MULTIPLICATION_SYMBOL, 'MULTIPLY'],
[Blockly.Msg.MATH_DIVISION_SYMBOL, 'DIVIDE'],
[Blockly.Msg.MATH_QUYU_SYMBOL, 'QUYU'],
[Blockly.Msg.MATH_POWER_SYMBOL, 'POWER']
];
//this.setHelpUrl(Blockly.Msg.MATH_ARITHMETIC_HELPURL);
this.setColour(MATH_HUE);
this.setOutput(true, Number);
this.appendValueInput('A')
.setCheck(null);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#id4");
this.appendValueInput('B')
.setCheck(null)
.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,
'POWER': Blockly.Msg.MATH_ARITHMETIC_TOOLTIP_POWER
};
return TOOLTIPS[mode];
});
}
};
export const math_bit = {
init: function () {
var OPERATORS = [
['&', '&'],
['|', '|'],
['xor', '^'],
['>>', '>>'],
['<<', '<<']
];
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("");
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#id8");
}
};
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.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#id17");
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
};
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, 'abs'],
[Blockly.Msg.MATH_SQ, 'sq'],
[Blockly.Msg.MATH_SQRT, 'sqrt']
];
this.setColour(MATH_HUE);
this.appendValueInput('A')
.setCheck(Number)
.appendField(new Blockly.FieldDropdown(OPERATORS), 'OP');
this.setOutput(true, Number);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#id18");
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('OP');
var TOOLTIPS = {
'sqrt': Blockly.Msg.MATH_SINGLE_TOOLTIP_ROOT,
'abs': Blockly.Msg.MATH_SINGLE_TOOLTIP_ABS,
'sq': Blockly.Msg.MATH_SINGLE_TOOLTIP_SQ,
'log': Blockly.Msg.MATH_SINGLE_TOOLTIP_LN,
'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 arduino_variate_type = {
init: function () {
var DATATYPES = [
[Blockly.Msg.LANG_MATH_INT, 'int'],
[Blockly.Msg.LANG_MATH_UNSIGNED_INT, 'unsigned int'],
[Blockly.Msg.LANG_MATH_WORD, 'word'],
[Blockly.Msg.LANG_MATH_LONG, 'long'],
[Blockly.Msg.LANG_MATH_UNSIGNED_LONG, 'unsigned long'],
[Blockly.Msg.LANG_MATH_FLOAT, 'float'],
[Blockly.Msg.LANG_MATH_DOUBLE, 'double'],
[Blockly.Msg.LANG_MATH_BOOLEAN, 'boolean'],
[Blockly.Msg.LANG_MATH_BYTE, 'byte'],
[Blockly.Msg.LANG_MATH_CHAR, 'char'],
[Blockly.Msg.LANG_MATH_UNSIGNED_CHAR, 'unsigned char'],
[Blockly.Msg.LANG_MATH_STRING, 'String'],
["uint8_t", "uint8_t"],
["uint16_t", "uint16_t"],
["uint32_t", "uint32_t"],
["uint64_t", "uint64_t"]
];
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(DATATYPES), "variate_type");
this.setOutput(true, null);
this.setColour(MATH_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//获取某个变量在内存中所占用的字节数
export const math_SizeOf = {
init: function () {
this.appendValueInput("data")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_GET + " " + Blockly.Msg.MIXLY_I2C_BYTES);
this.setInputsInline(false);
this.setOutput(true, null);
this.setColour(MATH_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
//最大最小值
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.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#min-max");
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_random_seed = {
init: function () {
this.setColour(MATH_HUE);
// this.appendDummyInput()
// .appendField(Blockly.Msg.LANG_MATH_RANDOM_SEED);
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);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#randomseed");
}
};
export const math_random_int = {
/**
* Block for random integer between [X] and [Y].
* @this Blockly.Block
*/
init: function () {
this.setColour(MATH_HUE);
this.setOutput(true, Number);
this.appendValueInput('FROM')
.setCheck(Number)
.appendField(Blockly.Msg.LANG_MATH_RANDOM_INT_INPUT_FROM);
this.appendValueInput('TO')
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.LANG_MATH_RANDOM_INT_INPUT_TO);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MATH_RANDOM_INT_TOOLTIP);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#random");
}
};
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);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#constrain");
}
};
export const base_map = {
init: function () {
this.setColour(MATH_HUE);
this.appendValueInput("NUM", Number)
.appendField(Blockly.Msg.MIXLY_MAP)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.LANG_MATH_INT, "map_int"], [Blockly.Msg.LANG_MATH_FLOAT, "map_float"]]), "maptype")
.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);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/04.Mathematics.html#map");
}
};
export const variables_operation = {
init: function () {
this.setColour(MATH_HUE);
this.appendValueInput("variables")
.setCheck(null);
this.appendValueInput("data")
.setCheck(null)
.appendField(new Blockly.FieldDropdown([["+=", "+"], ["-=", "-"], ["*=", "*"], ["/=", "/"]]), "type");
this.appendDummyInput();
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip();
this.setHelpUrl("");
}
};
export const math_auto_add_or_minus = {
init: function () {
this.appendValueInput("math_auto_add_minus_output")
.setCheck(null);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([["++", "++"], ["--", "--"]]), "math_auto_add_minus_type");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(MATH_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};

View File

@@ -0,0 +1,80 @@
import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';
const PINS_HUE = 230;
export const pins_digital = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.digital), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_analog = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.analog), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_pwm = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.pwm), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_interrupt = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.interrupt), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_MOSI = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.MOSI), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_MISO = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.MISO), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_SCK = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.SCK), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_SCL = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.SCL), 'PIN');
this.setOutput(true, Number);
}
};
export const pins_SDA = {
init: function () {
this.setColour(PINS_HUE);
this.appendDummyInput("")
.appendField(new Blockly.FieldDropdown(Profile.default.SDA), 'PIN');
this.setOutput(true, Number);
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,63 @@
import * as Blockly from 'blockly/core';
const SCOOP_HUE = 120;
export const SCoopTask = {
init: function () {
var _tasknum = [["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"]];
this.appendDummyInput()
.appendField("Scoop Task")
.appendField(new Blockly.FieldDropdown(_tasknum), "_tasknum");
this.appendStatementInput("setup")
.appendField(Blockly.Msg.MIXLY_SETUP)
.setCheck(null);
this.appendStatementInput("loop")
.appendField(Blockly.Msg.MIXLY_CONTROL_SCoop_loop)
.setCheck(null);
this.setColour(SCOOP_HUE);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SCOOP);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/03.Control.html#scoop-task");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '控制', 'SCoop Task']
}
};
}
};
export const SCoop_yield = {
init: function () {
this.setColour(SCOOP_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_CONTROL_SCoop_yield);
this.setPreviousStatement(false, null);
this.setNextStatement(false, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SCOOP_YIELD);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/03.Control.html#scoop-task");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '控制', 'SCoop Task']
}
};
}
};
export const SCoop_sleep = {
init: function () {
this.setColour(SCOOP_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_CONTROL_SCoop_sleep);
this.appendValueInput("sleeplength", Number)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_MILLIS);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SCOOP_SLEEP);
this.setHelpUrl("https://mixly.readthedocs.io/zh_CN/latest/arduino/03.Control.html#scoop-task");
this.wiki = {
'zh-hans': {
page: ['Arduino AVR', '控制', 'SCoop Task']
}
};
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,179 @@
import * as Blockly from 'blockly/core';
import { Profile } from 'mixly';
const SERIAL_HUE = 65;
export const serial_begin = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT", Number)
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_BEGIN)
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SERIAL_BEGIN);
}
};
export const serial_write = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT", String)
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_WRITE);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.TEXT_WRITE_TOOLTIP);
}
};
export const serial_print = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT", String)
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_PRINT_INLINE, "print"], [Blockly.Msg.TEXT_PRINT_Huanhang_TOOLTIP, "println"]]), "new_line");
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(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.TEXT_PRINT_Huanhang_TOOLTIP, "println"], [Blockly.Msg.MIXLY_PRINT_INLINE, "print"]]), "new_line");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);
}
};
export const serial_print_num = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_PRINT_INLINE, "print"], [Blockly.Msg.TEXT_PRINT_Huanhang_TOOLTIP, "println"]]), "new_line")
.appendField(Blockly.Msg.MIXLY_NUMBER);
this.appendValueInput("CONTENT", Number)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MATH_HEX, "HEX"], [Blockly.Msg.MATH_BIN, "BIN"], [Blockly.Msg.MATH_OCT, "OCT"], [Blockly.Msg.MATH_DEC, "DEC"]]), "STAT")
.setCheck(Number);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.TEXT_PRINT_HEX_TOOLTIP);
}
};
export const serial_print_hex = serial_print_num;
export const serial_available = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_AVAILABLE);
this.setOutput(true, Boolean);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_SERIAL_AVAILABLE);
}
};
export const serial_readstr = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_READSTR);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_SERIAL_READ_STR);
}
};
export const serial_readstr_until = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendValueInput("CONTENT", Number)
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_READSTR_UNTIL)
.setCheck(Number);
this.setInputsInline(true);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SERIAL_READSTRUNITL.replace('%1', Blockly.Arduino.valueToCode(this, 'CONTENT', Blockly.Arduino.ORDER_ATOMIC)));
}
};
export const serial_parseInt_Float = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
//.appendField(Blockly.Msg.MIXLY_SERIAL_READ)
.appendField(new Blockly.FieldDropdown([["read", "read"], ["peek", "peek"], ["parseInt", "parseInt"], ["parseFloat", "parseFloat"]]), "STAT");
this.setOutput(true, Number);
var thisBlock = this;
this.setTooltip(function () {
var op = thisBlock.getFieldValue('STAT');
var TOOLTIPS = {
'parseInt': Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_SERIAL_READ_INT,
'parseFloat': Blockly.Msg.MIXLY_TOOLTIP_BLOCKGROUP_SERIAL_READ_FLOAT
};
return TOOLTIPS[op];
});
}
};
export const serial_flush = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_FLUSH);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SERIAL_FLUSH);
}
};
export const serial_softserial = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_SETUP)
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select");
this.appendValueInput("RX", Number)
.setCheck(Number)
.appendField("RX#")
.setAlign(Blockly.inputs.Align.RIGHT);
this.appendValueInput("TX", Number)
.appendField("TX#")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SOFTSERIAL.replace('%1', Blockly.Arduino.valueToCode(this, 'RX', Blockly.Arduino.ORDER_ATOMIC))
.replace('%2', Blockly.Arduino.valueToCode(this, 'TX', Blockly.Arduino.ORDER_ATOMIC)));
}
};
export const serial_event = {
init: function () {
this.setColour(SERIAL_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(Profile.default.serial_select), "serial_select")
.appendField(Blockly.Msg.MIXLY_SERIAL_EVENT);
this.appendStatementInput('DO')
.appendField(Blockly.Msg.MIXLY_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SERIALEVENT);
}
};

View File

@@ -0,0 +1,313 @@
import * as Blockly from 'blockly/core';
const STORAGE_HUE = 0;
export const store_sd_init = {
init: function () {
this.appendDummyInput("")
.appendField("SD")
.appendField(Blockly.Msg.MIXLY_SETUP);
this.appendValueInput("PIN_MOSI")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("MOSI")
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("PIN_MISO")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("MISO")
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("PIN_SCK")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("CLK")
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("PIN_CS")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("CS")
.appendField(Blockly.Msg.MIXLY_PIN);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(STORAGE_HUE);
this.setInputsInline(false);
this.setTooltip();
this.setHelpUrl('');
}
};
export const store_sd_init_32 = {
init: function () {
this.appendDummyInput("")
.appendField("SD")
.appendField(Blockly.Msg.MIXLY_SETUP);
this.appendValueInput("PIN_MOSI")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("MOSI")
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("PIN_MISO")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("MISO")
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("PIN_SCK")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("CLK")
.appendField(Blockly.Msg.MIXLY_PIN);
this.appendValueInput("PIN_CS")
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField("CS")
.appendField(Blockly.Msg.MIXLY_PIN);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(STORAGE_HUE);
this.setInputsInline(false);
this.setTooltip();
this.setHelpUrl('');
}
};
export const sd_card_type = {
init: function () {
this.appendDummyInput()
.appendField("SD" + Blockly.Msg.MIXLY_TYPE);
this.setOutput(true, null);
this.setColour(STORAGE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const sd_card_root_files = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SD_LIST_FILES);
this.setOutput(false, null);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(STORAGE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
var volume_TYPE = [
[Blockly.Msg.MIXLY_SD_clusterCount, 'volume.clusterCount()'],
[Blockly.Msg.MIXLY_SD_blocksPerCluster, 'volume.blocksPerCluster()'],
[Blockly.Msg.MIXLY_SD_TOTAL_blocks, 'volume.blocksPerCluster() * volume.clusterCount()'],
["FAT" + Blockly.Msg.MIXLY_TYPE, 'volume.fatType()'],
[Blockly.Msg.MIXLY_volume + "(KB)", 'volume.blocksPerCluster()*volume.clusterCount()/2'],
[Blockly.Msg.MIXLY_volume + "(MB)", 'volume.blocksPerCluster()*volume.clusterCount()/2/1024'],
[Blockly.Msg.MIXLY_volume + "(GB)", 'volume.blocksPerCluster()*volume.clusterCount()/2/1024/1024.0'],
];
export const sd_volume = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendDummyInput()
.appendField("SD")
.appendField(new Blockly.FieldDropdown(volume_TYPE), 'volume_TYPE');
this.setOutput(true, Number);
this.setTooltip();
}
};
export const sd_exist = {
init: function () {
this.appendValueInput("FileName");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_SD_FILE_Exist);
this.setOutput(true, null);
this.setColour(STORAGE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const sd_DelFile = {
init: function () {
this.appendValueInput("FileName")
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_DELETE_VAR);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(STORAGE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const sd_read = {
init: function () {
this.appendValueInput("FileName")
.appendField(Blockly.Msg.MIXLY_SERIAL_READ);
this.setOutput(true, null);
this.setColour(STORAGE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const store_sd_write = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("FILE")
.appendField(Blockly.Msg.MIXLY_WRITE_SD_FILE);
this.appendValueInput("DATA", String)
.setCheck([String, Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_SD_DATA);
this.appendValueInput("NEWLINE", Boolean)
.setCheck(Boolean)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_SD_NEWLINE);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_SDWRITE);
}
};
export const store_eeprom_write_long = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("ADDRESS", Number)
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_EEPROM_WRITE_LONG);
this.appendValueInput("DATA", Number)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_DATA);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_EEPROM_WRITELONG);
}
};
export const store_eeprom_read_long = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("ADDRESS", Number)
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_EEPROM_READ_LONG);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_EEPROM_READLONG);
}
};
export const store_eeprom_write_byte = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("ADDRESS", Number)
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_EEPROM_WRITE_BYTE);
this.appendValueInput("DATA", Number)
.setCheck(Number)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_DATA);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_EEPROM_WRITEBYTE);
}
};
export const store_eeprom_read_byte = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("ADDRESS", Number)
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_EEPROM_READ_BYTE);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_EEPROM_READBYTE);
}
};
export const store_eeprom_put = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("ADDRESS")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_ESP32_WRITE)
//.appendField(new Blockly.FieldDropdown([[Blockly.Msg.LANG_MATH_INT,"int"],[Blockly.Msg.LANG_MATH_LONG,"long"],[Blockly.Msg.LANG_MATH_FLOAT,"float"],[Blockly.Msg.LANG_MATH_BYTE,"byte"],["字节数组","byte_array"],["字符数组","char_array"]]), "type")
.appendField("EEPROM")
.appendField(Blockly.Msg.MQTT_SERVER_ADD);
this.appendValueInput("DATA")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_SD_DATA);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_EEPROM_PUT);
}
};
export const store_eeprom_get = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("ADDRESS")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_SERIAL_READ)
//.appendField(new Blockly.FieldDropdown([[Blockly.Msg.LANG_MATH_INT,"int"],[Blockly.Msg.LANG_MATH_LONG,"long"],[Blockly.Msg.LANG_MATH_FLOAT,"float"],[Blockly.Msg.LANG_MATH_BYTE,"byte"],["字节数组","byte_array"],["字符数组","char_array"]]), "type")
.appendField("EEPROM")
.appendField(Blockly.Msg.MQTT_SERVER_ADD);
this.appendValueInput("DATA")
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.SAVETO + ' ' + Blockly.Msg.MSG["catVar"]);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_EEPROM_GET);
}
};
//ESP32简化SPIFFS
var OPEN_MODE1 = [
[Blockly.Msg.TEXT_WRITE_TEXT, '1'],
[Blockly.Msg.TEXT_APPEND_APPENDTEXT, '2']]
export const simple_spiffs_read = {
init: function () {
this.appendValueInput("FileName")
.appendField(Blockly.Msg.MIXLY_SERIAL_READ);
this.setOutput(true, null);
this.setColour(STORAGE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const simple_spiffs_store_spiffs_write = {
init: function () {
this.setColour(STORAGE_HUE);
this.appendValueInput("FILE")
.appendField(Blockly.Msg.MIXLY_WRITE_SPIFFS_FILE);
this.appendValueInput("DATA", String)
.setCheck([String, Number])
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_SD_DATA);
this.appendValueInput("NEWLINE", Boolean)
.setCheck(Boolean)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_SD_NEWLINE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_MODE)
.appendField(new Blockly.FieldDropdown(OPEN_MODE1), 'MODE');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_STORE_SDWRITE);
}
};
export const simple_spiffs_DelFile = {
init: function () {
this.appendValueInput("FileName")
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_DELETE_VAR);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(STORAGE_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};

View File

@@ -0,0 +1,568 @@
import * as Blockly from 'blockly/core';
const TEXTS_HUE = 160;
export const text = {
/**
* Block for text value.
* @this Blockly.Block
*/
init: function () {
//this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);
this.setColour(TEXTS_HUE);
this.appendDummyInput()
.appendField(this.newQuote_(true))
.appendField(new Blockly.FieldTextInput(''), 'TEXT')
.appendField(this.newQuote_(false));
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.TEXT_TEXT_TOOLTIP);
},
/**
* Create an image of an open or closed quote.
* @param {boolean} open True if open quote, false if closed.
* @return {!Blockly.FieldImage} The field image of the quote.
* @private
*/
newQuote_: function (open) {
if (open == this.RTL) {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
} else {
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
}
return new Blockly.FieldImage(file, 12, 12, '"');
}
};
Blockly.FieldTextInput.char_validator = function (text) {
if (text.length > 1) {
if (text.charAt(0) === "\\") {
var charAtOne = text.charAt(1);
if (charAtOne === "0" ||
charAtOne === "b" ||
charAtOne === "f" ||
charAtOne === "n" ||
charAtOne === "r" ||
charAtOne === "t" ||
charAtOne === "\\" ||
charAtOne === "'") {
return String(text).substring(0, 2);
} else if (charAtOne === "x" && text.charAt(2) === "0" && text.charAt(3) === "B") {
return String(text).substring(0, 4);
}
}
}
return String(text).substring(0, 1);
};
export const text_char = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendDummyInput()
.appendField(this.newQuote_(true))
.appendField(new Blockly.FieldTextInput('', Blockly.FieldTextInput.char_validator), 'TEXT')
.appendField(this.newQuote_(false));
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.TEXT_CHAR_TOOLTIP);
},
newQuote_: function (open) {
if (open == true) {
var file = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAkBAMAAAB/KNeuAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAP///////////////////////////////+tNPsIAAAAIdFJOUwAe1q4KRGaFPS0VAQAAAKlJREFUGNNVkD0LwkAMhlNsnUvBH+DmKnXoeODgWgXBsaOj+AGuVfTys8318l7OTA/hTe7JEWmVNwekA/fAHfNSsVoxew0/mfkbeSvo6wkLSbx0tJH2XdPS/pClsfxs7TA5WOQNl5M9X3bMF8RlS608z+JhFOZNMowybftw4GDvjHmTsc84PJJ4iPbgWcZVxuEUMHXKvS2dZHVgxJHpV4qr4Brei+Oe/usHT1JfDpNGeM0AAAAASUVORK5CYII=";
} else {
var file = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAkBAMAAAB/KNeuAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAP///////////////////////////////+tNPsIAAAAIdFJOUwAe1q4KRGaFPS0VAQAAAKpJREFUGNNV0bEKAjEMBuActOd6KIKrg+h4cII3Cg6u5yA6Ot4DONxcUfPYJmnaxn/6KEmaUoD/LK+XxAUibhuhR85bvBLjQHR99DqXIL7ItTo0xdyQ3RrvjWlQZQyT8cnYjcXgbl2XzBmNe5kv4WUfar6kUc9o56N6nh4Zy1NrHZ8iuSN+lB5LCR0HnXIuy/hd7qymUs3bf7WajsNQrn9CHr7Jn+IOaUH4ATxJW2wDnL5kAAAAAElFTkSuQmCC";
}
return new Blockly.FieldImage(file, 7, 12, '"');
}
};
export const text_join = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendValueInput('A')
.setCheck([String, Number]);
this.appendValueInput('B')
.setCheck([String, Number])
.appendField(Blockly.Msg.MIXLY_TEXT_JOIN);
this.setInputsInline(true);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TEXT_JOIN);
}
};
export const text_to_number = {
init: function () {
var TO_INT_FLOAT = [
[Blockly.Msg.MIXLY_TO_INT, 'toInt'],
[Blockly.Msg.MIXLY_TO_FLOAT, 'toFloat']
];
this.setColour(TEXTS_HUE);
this.appendValueInput('VAR')
.setCheck([String, Number])
.appendField(new Blockly.FieldDropdown(TO_INT_FLOAT), 'TOWHAT');
this.setOutput(true, Number);
var thisBlock = this;
this.setTooltip(function () {
var mode = thisBlock.getFieldValue('TOWHAT');
var TOOLTIPS = {
'toInt': Blockly.Msg.MIXLY_TOOLTIP_TEXT_TOINT,
'toFloat': Blockly.Msg.MIXLY_TOOLTIP_TEXT_TOFLOAT
};
return TOOLTIPS[mode];
});
}
};
export const ascii_to_char = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendValueInput('VAR')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_TOCHAR);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TEXT_TOCHAR);
}
};
export const char_to_ascii = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_TOASCII)
.appendField("'")
.appendField(new Blockly.FieldTextInput('', Blockly.FieldTextInput.char_validator), 'TEXT')
.appendField("'");
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TEXT_TOASCII);
}
};
export const number_to_text = {
init: function () {
var TO_INT_FLOAT = [
[Blockly.Msg.MATH_BIN, 'BIN'],
[Blockly.Msg.MATH_OCT, 'OCT'],
[Blockly.Msg.MATH_DEC, 'DEC'],
[Blockly.Msg.MATH_HEX, 'HEX']
];
this.setColour(TEXTS_HUE);
this.appendValueInput('VAR')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_TOSTRING)
.appendField(new Blockly.FieldDropdown(TO_INT_FLOAT), 'TOWHAT');
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TEXT_TOTEXT);
}
};
export const number_to_text_ = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendValueInput('VAR')
.setCheck(Number)
.appendField(Blockly.Msg.MIXLY_TOSTRING);
this.setOutput(true, String);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TEXT_TOTEXT);
}
};
export const text_length = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendValueInput("VAR")
.appendField(Blockly.Msg.MIXLY_LENGTH)
.setCheck(String);
this.setOutput(true, Number);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TEXT_LENGTH);
}
}
export const text_char_at = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendValueInput("VAR")
.setCheck(String);
this.appendValueInput("AT")
.appendField(Blockly.Msg.TEXT_CHARAT)
.setCheck(Number);
this.appendDummyInput()
.appendField(Blockly.Msg.TEXT_CHARAT2);
this.setOutput(true, Number);
this.setInputsInline(true);
var self = this;
this.setTooltip(function () {
return Blockly.Msg.MIXLY_TOOLTIP_TEXT_FIND_CHAR_AT.replace('%1', Blockly.Arduino.valueToCode(self, 'VAR', Blockly.Arduino.ORDER_ATOMIC));
});
}
}
export const text_equals_starts_ends = {
init: function () {
var TEXT_DOWHAT = [
[Blockly.Msg.MIXLY_EQUALS, 'equals'],
[Blockly.Msg.MIXLY_STARTSWITH, 'startsWith'],
[Blockly.Msg.MIXLY_ENDSWITH, 'endsWith']
];
this.setColour(TEXTS_HUE);
this.appendValueInput("STR1")
.setCheck([String, Number]);
this.appendValueInput("STR2")
.appendField(new Blockly.FieldDropdown(TEXT_DOWHAT), 'DOWHAT')
.setCheck([String, Number]);
this.setOutput(true, [Boolean, Number]);
this.setInputsInline(true);
var self = this;
this.setTooltip(function () {
var op = self.getFieldValue('DOWHAT');
var TOOLTIPS = {
'equals': Blockly.Msg.MIXLY_EQUALS,
'startsWith': Blockly.Msg.MIXLY_STARTSWITH,
'endsWith': Blockly.Msg.MIXLY_ENDSWITH
};
return Blockly.Msg.MIXLY_TOOLTIP_TEXT_EQUALS_STARTS_ENDS.replace('%1', TOOLTIPS[op]).replace('%2', Blockly.Arduino.valueToCode(self, 'STR2', Blockly.Arduino.ORDER_ATOMIC));
});
}
}
export const text_compareTo = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendValueInput("STR1")
.setCheck([String, Number]);
this.appendValueInput("STR2")
.appendField(Blockly.Msg.MIXLY_COMPARETO)
.setCheck([String, Number]);
this.setOutput(true, Number);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_COMPARETO_HELP);
}
}
//小数获取有效位
export const decimal_places = {
init: function () {
this.setColour(TEXTS_HUE);
this.appendValueInput("numeral")
.setCheck(null)
.appendField(Blockly.Msg.LANG_MATH_FLOAT);
this.appendValueInput("decimal_places")
.setCheck(null)
.appendField(Blockly.Msg.TEXT_KEEP);
this.appendDummyInput()
.appendField(Blockly.Msg.TEXT_DECIMAL);
this.setOutput(true, null);
this.setTooltip(Blockly.Msg.DECIMAL_PLACES_HELP);
this.setHelpUrl("");
}
};
//截取字符串
export const substring = {
init: function () {
this.appendValueInput("name")
.setCheck(null);
this.appendValueInput("Start")
.setCheck(null)
.appendField(Blockly.Msg.LISTS_GET_INDEX_GET);
this.appendValueInput("end")
.setCheck(null)
.appendField(Blockly.Msg.TEXT_TO);
this.appendDummyInput()
.appendField(Blockly.Msg.LANG_MATH_STRING);
this.setOutput(true, null);
this.setColour(TEXTS_HUE);
this.setTooltip(Blockly.Msg.SUBSTRING_HELP);
this.setHelpUrl("");
}
};
//字符串转化为大小写
export const letter_conversion = {
init: function () {
this.appendValueInput("String")
.setCheck(null)
.appendField(Blockly.Msg.STRING_VARIABLE);
this.appendDummyInput()
.appendField(Blockly.Msg.LETTERS_ARE_CONVERTED_TO)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.CAPITAL, ".toUpperCase()"], [Blockly.Msg.LOWER_CASE, ".toLowerCase()"]]), "type");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(TEXTS_HUE);
this.setTooltip(Blockly.Msg.LETTER_CONVERSION_HELP);
this.setHelpUrl("");
}
};
//字符串变量替换
export const data_replacement = {
init: function () {
this.appendValueInput("String")
.setCheck(null)
.appendField(Blockly.Msg.STRING_VARIABLE);
this.appendValueInput("source_data")
.setCheck(null)
.appendField(Blockly.Msg.LANG_MATH_STRING);
this.appendValueInput("replace")
.setCheck(null)
.appendField(Blockly.Msg.REPLACE_WITH);
this.appendDummyInput();
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(TEXTS_HUE);
this.setTooltip(Blockly.Msg.DATA_REPLACEMENT_HELP);
this.setHelpUrl("");
}
};
//消除非可视字符
export const eliminate = {
init: function () {
this.appendValueInput("String")
.setCheck(null)
.appendField(Blockly.Msg.STRING_VARIABLE);
this.appendDummyInput()
.appendField(Blockly.Msg.ELIMINATE_NON_VISUAL_CHARACTERS);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(TEXTS_HUE);
this.setTooltip(Blockly.Msg.ELIMINATE_HELP);
this.setHelpUrl("");
}
};
//检测是否以特定字符串开头或结尾
export const first_and_last = {
init: function () {
this.appendValueInput("String")
.setCheck(null)
.appendField(Blockly.Msg.LANG_MATH_STRING);
this.appendValueInput("String1")
.setCheck(null)
.appendField(Blockly.Msg.AS_A_STRING);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.STARTSWITH, ".startsWith"], [Blockly.Msg.ENDSWITH, ".endsWith"]]), "type");
this.setOutput(true, null);
this.setColour(TEXTS_HUE);
this.setTooltip(Blockly.Msg.FIRST_AND_LAST_HELP);
this.setHelpUrl("");
}
};
//数据类型转换
export const type_conversion = {
init: function () {
this.appendValueInput("variable")
.setCheck(null)
.appendField(Blockly.Msg.DATA_TYPE_CONVERSION)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.LANG_MATH_STRING, "String"], [Blockly.Msg.LANG_MATH_CHAR, "char"], [Blockly.Msg.LANG_MATH_BYTE, "byte"], [Blockly.Msg.LANG_MATH_INT, "int"], [Blockly.Msg.LANG_MATH_LONG, "long"], [Blockly.Msg.LANG_MATH_FLOAT, "float"], [Blockly.Msg.LANG_MATH_WORD, "word"]]), "type");
this.setOutput(true, null);
this.setColour(TEXTS_HUE);
this.setTooltip(Blockly.Msg.TYPE_CONVERSION_HELP);
this.setHelpUrl("");
}
};
export const create_with_item = {
/**
* Mutator bolck for adding items.
* @this Blockly.Block
*/
init: function () {
this.setColour(TEXTS_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TOOLTIP);
this.contextMenu = false;
}
};
export const create_with_container = {
/**
* Mutator block for list container.
* @this Blockly.Block
*/
init: function () {
this.setColour(TEXTS_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.HTML_TEXT);
this.appendStatementInput('STACK');
this.setTooltip("");
this.contextMenu = false;
}
};
export const String_indexOf = {
init: function () {
this.appendValueInput("str1")
.setCheck(null);
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.PROCEDURES_DEFRETURN_RETURN);
this.appendValueInput("str2")
.setCheck(null);
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.SERIES_INDEX);
this.setInputsInline(true);
this.setOutput(true, null);
this.setColour(160);
this.setTooltip();
this.setHelpUrl("");
}
};
export const text_join2 = {
/**
* Block for creating a list with any number of elements of any type.
* @this Blockly.Block
*/
init: function () {
this.setColour(TEXTS_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_TEXT_JOIN + Blockly.Msg.MIXLY_MICROBIT_TYPE_STRING);
this.itemCount_ = 3;
this.updateShape_();
this.setInputsInline(true);
this.setOutput(true, null);
this.setMutator(new Blockly.icons.MutatorIcon(['create_with_item'], this));
this.setTooltip("");
},
/**
* Create XML to represent list inputs.
* @return {Element} XML storage element.
* @this Blockly.Block
*/
mutationToDom: function () {
var container = Blockly.utils.xml.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('create_with_container');
containerBlock.initSvg();
var connection = containerBlock.getInput('STACK').connection;
for (var i = 0; i < this.itemCount_; i++) {
var itemBlock = workspace.newBlock('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');
} else {
var i = 0;
while (this.getInput('ADD' + i)) {
this.removeInput('ADD' + i);
i++;
}
}
// Rebuild block.
if (this.itemCount_ == 0) {
this.appendDummyInput('EMPTY')
.appendField("无需要连接的字符串");
} else {
for (var i = 0; i < this.itemCount_; i++) {
var input = this.appendValueInput('ADD' + i);
if (i > 0) {
input.setAlign(Blockly.inputs.Align.RIGHT)
input.appendField("+");
}
}
}
}
};
//Arduinojson数据解析
export const Arduinojson = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.ARDUINOJSON_STRING_PARSING);
this.appendDummyInput("")
.appendField(new Blockly.FieldMultilineInput('const size_t capacity = JSON_ARRAY_SIZE(3) + 10;\nDynamicJsonBuffer jsonBuffer(capacity);\nconst char* json = "[\\"0\\",\\"74\\",\\"134\\"]";\nJsonArray& root = jsonBuffer.parseArray(json);\nconst char* root_0 = root[0]; // "0"\nconst char* root_1 = root[1]; // "74"\nconst char* root_2 = root[2]; // "134"'), 'VALUE');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(120);
this.setTooltip(Blockly.Msg.ARDUINOJSON_STRING_PARSING1);
this.setHelpUrl("https://arduinojson.org/v5/assistant/");
}
};
//字符串转长整数
export const String_to_Long_Integer = {
init: function () {
this.appendValueInput("data")
.setCheck(null)
.appendField(Blockly.Msg.MIXLY_MICROBIT_TYPE_STRING + Blockly.Msg.A_TO_B + Blockly.Msg.LANG_MATH_LONG)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MATH_HEX, "16"], [Blockly.Msg.MATH_DEC, "10"], [Blockly.Msg.MATH_OCT, "8"], [Blockly.Msg.MATH_BIN, "2"], [Blockly.Msg.blynk_IOT_AUTO, "0"]]), "type");
this.setOutput(true, null);
this.setColour(TEXTS_HUE);
this.setTooltip("");
this.setHelpUrl("https://blog.csdn.net/lizhengze1117/article/details/103318662?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-10.base&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-10.base");
}
};

View File

@@ -0,0 +1,281 @@
import * as Blockly from 'blockly/core';
const TOOLS_HUE = "#555555";
const LISTS_HUE = 260;
export const factory_notes = {
init: function () {
this.setColour(TOOLS_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_CONTROL_NOTES)
.appendField(new Blockly.FieldMultilineInput(''), 'VALUE');
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const folding_block = {
init: function () {
this.setColour(TOOLS_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldTextInput(Blockly.Msg.FOLDING_BLOCK), "peien");
this.appendStatementInput('DO')
.appendField('');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.FOLDING_BLOCK_HELP);
}
};
//IIC地址查找
export const IICSCAN = {
init: function () {
this.setColour(TOOLS_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.IICSCAN);
this.setInputsInline(true);
this.setTooltip('');
}
};
//取模工具显示数据部分
export const tool_modulus_show = {
init: function () {
this.setColour(LISTS_HUE);
this.appendDummyInput("")
.appendField(Blockly.Msg.OLED_BITMAP_NAME)
.appendField(new Blockly.FieldTextInput('mylist'), 'VAR')
.appendField('[')
.appendField(new Blockly.FieldTextInput('3'), 'x')
.appendField(']');
this.appendDummyInput("")
.appendField(Blockly.Msg.SAVETO + " flash")
.appendField(new Blockly.FieldCheckbox("true"), "save_hz");
this.appendValueInput("input_data");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip("");
}
};
//取模工具设置部分
export const tool_modulus = {
init: function () {
this.appendDummyInput()
.appendField("点阵格式")
.appendField(new Blockly.FieldDropdown([["阴码", "1"], ["阳码", "2"]]), "bitmap_formats")
.appendField(" 取模方式")
.appendField(new Blockly.FieldDropdown([["逐列式", "1"], ["逐行式", "2"], ["列行式", "3"], ["行列式", "4"]]), "modulus_way")
.appendField(" 取模走向")
.appendField(new Blockly.FieldDropdown([["顺向(高位在前)", "1"], ["逆向(低位在前)", "2"]]), "modulus_direction");
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME)
.appendField(new Blockly.FieldDropdown([["华文黑体", "STHeiti"], ["华文楷体", "STKaiti"], ["华文细黑", "STXihei"], ["华文宋体", "STSong"], ["华文中宋", "STZhongsong"], ["华文仿宋", "STFangsong"], ["华文彩云", "STCaiyun"], ["华文琥珀", "STHupo"], ["华文隶书", "STLiti"], ["华文行楷", "STXingkai"], ["华文新魏", "STXinwei"], ["黑体", "simHei"], ["宋体", "simSun"], ["新宋体", "NSimSun"], ["仿宋", "FangSong"], ["楷体", "KaiTi"], ["仿宋_GB2312", "FangSong_GB2312"], ["楷体_GB2312", "KaiTi_GB2312"], ["隶书", "LiSu"], ["幼圆", "YouYuan"], ["新细明体", "PMingLiU"], ["细明体", "MingLiU"], ["标楷体", "DFKai-SB"], ["微软正黑体", "Microsoft JhengHei"], ["微软雅黑体", "Microsoft YaHei"]]), "hz_sharp")
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM)
.appendField(new Blockly.FieldTextInput("16"), "hz_line_height")
.appendField("px")
//.appendField("px "+Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_FILE_SEEK_OFFSET+":")
//.appendField(new Blockly.FieldDropdown([["上移","hz_up"],["下移","hz_down"]]), "hz_up_down")
//.appendField(new Blockly.FieldTextInput("0"), "hz_up_down_data")
//.appendField("px ")
// .appendField(new Blockly.FieldDropdown([["左移","hz_left"],["右移","hz_right"]]), "hz_left_right")
//.appendField(new Blockly.FieldTextInput("0"), "hz_left_right_data")
//.appendField("px");
// this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WIDTH)
.appendField(new Blockly.FieldTextInput("16"), "bitmap_width")
.appendField("px " + Blockly.Msg.MIXLY_HEIGHT)
.appendField(new Blockly.FieldTextInput("16"), "bitmap_height")
.appendField("px");
// .appendField(new Blockly.FieldCheckbox("true"), "show_hz");
this.appendDummyInput()
.appendField("输入数据")
.appendField(new Blockly.FieldTextInput(""), "input_data");
this.setInputsInline(false);
this.setOutput(true, null);
//this.setColour("#cc66cc");
this.setColour(180);
this.setTooltip("");
this.setHelpUrl("");
}
};
export const uno_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/uno.png'), 525, 372, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const nano_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/nano.png'), 525, 368, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const mega_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/mega.png'), 525, 736, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const promini_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/ProMini.png'), 525, 371, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const leonardo_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/leonardo.png'), 525, 371, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const esp32s2_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/ESP32s2.jpg'), 525, 376, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const esp32c3_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/ESP32c3.jpg'), 525, 376, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const core_esp32c3_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/core_esp32c3_pin.png'), 500, 376, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const esp32s3_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/ESP32s3.jpg'), 500, 350, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const esp8266_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/ESP8266-NodeMCU.png'), 525, 346, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const wemos_d1_mini_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/ESP8266-WeMos-D1-Mini.png'), 525, 264, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl();
}
};
export const stm32f103c8t6_pin = {
init: function () {
this.appendDummyInput()
.appendField(new Blockly.FieldImage(require('../../../../common/media/board_pin/STM32F103C8T6.png'), 525, 376, "*"));
this.setColour(TOOLS_HUE);
this.setTooltip();
this.setHelpUrl("https://blog.csdn.net/xatsoft/article/details/90687016?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-6.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-6.nonecase");
}
};
//获取两个日期差值
export const get_the_number_of_days_between_the_two_dates = {
init: function () {
this.appendDummyInput()
.appendField(Blockly.Msg.GET_THE_DIFFERENCE_BETWEEN_TWO_DATES);
this.appendValueInput("year_start")
.setCheck(null)
.appendField(Blockly.Msg.START + Blockly.Msg.MIXLY_GPS_DATE_YEAR);
this.appendValueInput("month_start")
.setCheck(null)
.appendField(Blockly.Msg.START + Blockly.Msg.MIXLY_GPS_DATE_MONTH);
this.appendValueInput("day_start")
.setCheck(null)
.appendField(Blockly.Msg.START + Blockly.Msg.MIXLY_GPS_DATE_DAY);
this.appendValueInput("year_end")
.setCheck(null)
.appendField(Blockly.Msg.END + Blockly.Msg.MIXLY_GPS_DATE_YEAR);
this.appendValueInput("month_end")
.setCheck(null)
.appendField(Blockly.Msg.END + Blockly.Msg.MIXLY_GPS_DATE_MONTH);
this.appendValueInput("day_end")
.setCheck(null)
.appendField(Blockly.Msg.END + Blockly.Msg.MIXLY_GPS_DATE_DAY);
this.setOutput(true, null);
this.setColour(TOOLS_HUE);
this.setTooltip("");
this.setHelpUrl("https://blog.csdn.net/a_ran/article/details/43601699?utm_source=distribute.pc_relevant.none-task");
}
};
var esp8266_board_pin_type = [
["D0", "16"],
["D1", "5"],
["D2", "4"],
["D3", "0"],
["D4", "2"],
["D5", "14"],
["D6", "12"],
["D7", "13"],
["D8", "15"],
["RX", "3"],
["TX", "1"],
["A0", "A0"],
["SD3", "10"],
["SD2", "9"]
];
export const esp8266_board_pin = {
init: function () {
this.appendDummyInput()
.appendField("ESP8266 GPIO")
.appendField(new Blockly.FieldDropdown(esp8266_board_pin_type), "pin");
this.setOutput(true, null);
this.setColour(TOOLS_HUE);
this.setTooltip("");
this.setHelpUrl("");
}
};

View File

@@ -0,0 +1,128 @@
import * as Blockly from 'blockly/core';
const VARIABLES_HUE = 330;
var DATATYPES = [
[Blockly.Msg.LANG_MATH_INT, 'int'],
[Blockly.Msg.LANG_MATH_UNSIGNED_INT, 'unsigned int'],
[Blockly.Msg.LANG_MATH_WORD, 'word'],
[Blockly.Msg.LANG_MATH_LONG, 'long'],
[Blockly.Msg.LANG_MATH_UNSIGNED_LONG, 'unsigned long'],
[Blockly.Msg.LANG_MATH_FLOAT, 'float'],
[Blockly.Msg.LANG_MATH_DOUBLE, 'double'],
[Blockly.Msg.LANG_MATH_BOOLEAN, 'boolean'],
[Blockly.Msg.LANG_MATH_BYTE, 'byte'],
[Blockly.Msg.LANG_MATH_CHAR, 'char'],
[Blockly.Msg.LANG_MATH_UNSIGNED_CHAR, 'unsigned char'],
[Blockly.Msg.LANG_MATH_STRING, 'String'],
["char*", "char*"],
["uint8_t", "uint8_t"],
["uint16_t", "uint16_t"],
["uint32_t", "uint32_t"],
["uint64_t", "uint64_t"]
];
// ************************************************************************
// THIS SECTION IS INSERTED INTO BLOCKLY BY BLOCKLYDUINO.
export const variables_declare = {
// Variable setter.
init: function () {
this.setColour(VARIABLES_HUE);
this.appendValueInput('VALUE', null)
.appendField(Blockly.Msg.MIXLY_DECLARE)
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_GLOBAL_VARIABLE, "global_variate"], [Blockly.Msg.MIXLY_LOCAL_VARIABLE, "local_variate"]]), "variables_type")
.appendField(new Blockly.FieldTextInput('item'), 'VAR')
.appendField(Blockly.Msg.MIXLY_AS)
.appendField(new Blockly.FieldDropdown(DATATYPES), "TYPE")
.appendField(Blockly.Msg.MIXLY_VALUE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_VARIABLES_DECLARE);
},
getVars: function () {
return [this.getFieldValue('VAR')];
},
renameVar: function (oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
this.setFieldValue(newName, 'VAR');
}
}
};
// ************************************************************************
export const variables_get = {
init: function () {
this.setColour(VARIABLES_HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldTextInput('item'), 'VAR')
this.setOutput(true);
this.setTooltip(Blockly.Msg.VARIABLES_GET_TOOLTIP);
},
getVars: function () {
return [this.getFieldValue('VAR')];
},
renameVar: function (oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
this.setFieldValue(newName, 'VAR');
}
}/*,
onchange: function() {
var varName = Blockly.Arduino.variableDB_.getName(this.getFieldValue('VAR'),Blockly.Variables.NAME_TYPE);
if(Blockly.Arduino.definitions_['var_declare'+varName]){
this.setWarningText(null);
}else{
this.setWarningText(Blockly.Msg.MIXLY_WARNING_NOT_DECLARE);
}
}*/
};
export const variables_set = {
init: function () {
this.setColour(VARIABLES_HUE);
this.appendValueInput('VALUE')
.appendField(new Blockly.FieldTextInput('item'), 'VAR')
.appendField(Blockly.Msg.MIXLY_VALUE2);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP);
},
getVars: function () {
return [this.getFieldValue('VAR')];
},
renameVar: function (oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
this.setFieldValue(newName, 'VAR');
}
}
};
/**
* Block for basic data type change.
* @this Blockly.Block
*/
export const variables_change = {
init: function () {
this.setColour(VARIABLES_HUE);
var DATATYPES = [
[Blockly.Msg.LANG_MATH_INT, 'int'],
[Blockly.Msg.LANG_MATH_UNSIGNED_INT, 'unsigned int'],
[Blockly.Msg.LANG_MATH_WORD, 'word'],
[Blockly.Msg.LANG_MATH_LONG, 'long'],
[Blockly.Msg.LANG_MATH_UNSIGNED_LONG, 'unsigned long'],
[Blockly.Msg.LANG_MATH_FLOAT, 'float'],
[Blockly.Msg.LANG_MATH_DOUBLE, 'double'],
[Blockly.Msg.LANG_MATH_BOOLEAN, 'boolean'],
[Blockly.Msg.LANG_MATH_BYTE, 'byte'],
[Blockly.Msg.LANG_MATH_CHAR, 'char'],
[Blockly.Msg.LANG_MATH_UNSIGNED_CHAR, 'unsigned char'],
[Blockly.Msg.LANG_MATH_STRING, 'String']
];
this.appendValueInput('MYVALUE')
.appendField(new Blockly.FieldDropdown(DATATYPES), 'OP');
// Assign 'this' to a variable for use in the tooltip closure below.
this.setOutput(true);
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_VARIABLES_CHANGE);
}
};