Update(boards): 将arduino下函数和变量相关图形块定义移动到arduino目录下
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,97 +0,0 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import { Variables } from 'blockly/core';
|
||||
|
||||
|
||||
const VARIABLES_HUE = 330;
|
||||
|
||||
// ************************************************************************
|
||||
// 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(Variables.DATA_TYPE), "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);
|
||||
this.appendValueInput('MYVALUE')
|
||||
.appendField(new Blockly.FieldDropdown(Variables.DATA_TYPE), 'OP');
|
||||
// Assign 'this' to a variable for use in the tooltip closure below.
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_VARIABLES_CHANGE);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,14 +13,12 @@ import * as ArduinoAVRLogicBlocks from './blocks/logic';
|
||||
import * as ArduinoAVRMathBlocks from './blocks/math';
|
||||
import * as ArduinoAVRPinoutBlocks from './blocks/pinout';
|
||||
import * as ArduinoAVRPinsBlocks from './blocks/pins';
|
||||
import * as ArduinoAVRProceduresBlocks from './blocks/procedures';
|
||||
import * as ArduinoAVRScoopBlocks from './blocks/scoop';
|
||||
import * as ArduinoAVRSensorBlocks from './blocks/sensor';
|
||||
import * as ArduinoAVRSerialBlocks from './blocks/serial';
|
||||
import * as ArduinoAVRStorageBlocks from './blocks/storage';
|
||||
import * as ArduinoAVRTextBlocks from './blocks/text';
|
||||
import * as ArduinoAVRToolsBlocks from './blocks/tools';
|
||||
import * as ArduinoAVRVariablesBlocks from './blocks/variables';
|
||||
|
||||
import * as ArduinoAVRActuatorGenerators from './generators/actuator';
|
||||
import * as ArduinoAVRBlynkGenerators from './generators/blynk';
|
||||
@@ -35,14 +33,12 @@ import * as ArduinoAVRLogicGenerators from './generators/logic';
|
||||
import * as ArduinoAVRMathGenerators from './generators/math';
|
||||
import * as ArduinoAVRPinoutGenerators from './generators/pinout';
|
||||
import * as ArduinoAVRPinsGenerators from './generators/pins';
|
||||
import * as ArduinoAVRProceduresGenerators from './generators/procedures';
|
||||
import * as ArduinoAVRScoopGenerators from './generators/scoop';
|
||||
import * as ArduinoAVRSensorGenerators from './generators/sensor';
|
||||
import * as ArduinoAVRSerialGenerators from './generators/serial';
|
||||
import * as ArduinoAVRStorageGenerators from './generators/storage';
|
||||
import * as ArduinoAVRTextGenerators from './generators/text';
|
||||
import * as ArduinoAVRToolsGenerators from './generators/tools';
|
||||
import * as ArduinoAVRVariablesGenerators from './generators/variables';
|
||||
|
||||
export {
|
||||
ArduinoAVRPins,
|
||||
@@ -59,14 +55,12 @@ export {
|
||||
ArduinoAVRMathBlocks,
|
||||
ArduinoAVRPinoutBlocks,
|
||||
ArduinoAVRPinsBlocks,
|
||||
ArduinoAVRProceduresBlocks,
|
||||
ArduinoAVRScoopBlocks,
|
||||
ArduinoAVRSensorBlocks,
|
||||
ArduinoAVRSerialBlocks,
|
||||
ArduinoAVRStorageBlocks,
|
||||
ArduinoAVRTextBlocks,
|
||||
ArduinoAVRToolsBlocks,
|
||||
ArduinoAVRVariablesBlocks,
|
||||
ArduinoAVRActuatorGenerators,
|
||||
ArduinoAVRBlynkGenerators,
|
||||
ArduinoAVRCommunicateGenerators,
|
||||
@@ -80,12 +74,10 @@ export {
|
||||
ArduinoAVRMathGenerators,
|
||||
ArduinoAVRPinoutGenerators,
|
||||
ArduinoAVRPinsGenerators,
|
||||
ArduinoAVRProceduresGenerators,
|
||||
ArduinoAVRScoopGenerators,
|
||||
ArduinoAVRSensorGenerators,
|
||||
ArduinoAVRSerialGenerators,
|
||||
ArduinoAVRStorageGenerators,
|
||||
ArduinoAVRTextGenerators,
|
||||
ArduinoAVRToolsGenerators,
|
||||
ArduinoAVRVariablesGenerators
|
||||
ArduinoAVRToolsGenerators
|
||||
};
|
||||
@@ -1,107 +0,0 @@
|
||||
import { Variables, Procedures } from 'blockly/core';
|
||||
|
||||
export const procedures_defreturn = function (_, generator) {
|
||||
// Define a procedure with a return value.
|
||||
var funcName = generator.variableDB_.getName(this.getFieldValue('NAME'),
|
||||
Procedures.NAME_TYPE);
|
||||
var branch = (this.getInput('STACK') && generator.statementToCode(this, 'STACK'));
|
||||
if (generator.INFINITE_LOOP_TRAP) {
|
||||
branch = generator.INFINITE_LOOP_TRAP.replace(/%1/g,
|
||||
'\'' + this.id + '\'') + branch;
|
||||
}
|
||||
var returnValue = generator.valueToCode(this, 'RETURN',
|
||||
generator.ORDER_NONE) || '';
|
||||
var type = this.getFieldValue('TYPE');
|
||||
if (returnValue) {
|
||||
returnValue = ' return ' + returnValue + ';\n';
|
||||
}
|
||||
var returnType = type ? type : 'void';
|
||||
var args = [];
|
||||
for (var x = 0; x < this.arguments_.length; x++) {
|
||||
args[x] = this.argumentstype_[x] + ' ' + generator.variableDB_.getName(this.arguments_[x],
|
||||
Variables.NAME_TYPE);
|
||||
}
|
||||
var code = returnType + ' ' + funcName + '(' + args.join(', ') + ') {\n' +
|
||||
branch + returnValue + '}\n';
|
||||
code = generator.scrub_(this, code);
|
||||
generator.definitions_[funcName] = code;
|
||||
return null;
|
||||
}
|
||||
|
||||
export const procedures_defnoreturn = function (_, generator) {
|
||||
// Define a procedure with a return value.
|
||||
var funcName = generator.variableDB_.getName(this.getFieldValue('NAME'),
|
||||
Procedures.NAME_TYPE);
|
||||
var branch = (this.getInput('STACK') && generator.statementToCode(this, 'STACK'));
|
||||
if (generator.INFINITE_LOOP_TRAP) {
|
||||
branch = generator.INFINITE_LOOP_TRAP.replace(/%1/g,
|
||||
'\'' + this.id + '\'') + branch;
|
||||
}
|
||||
var returnType = 'void';
|
||||
var args = [];
|
||||
for (var x = 0; x < this.arguments_.length; x++) {
|
||||
args[x] = this.argumentstype_[x] + ' ' + generator.variableDB_.getName(this.arguments_[x],
|
||||
Variables.NAME_TYPE);
|
||||
}
|
||||
var code = returnType + ' ' + funcName + '(' + args.join(', ') + ') {\n' +
|
||||
branch + '}\n';
|
||||
code = generator.scrub_(this, code);
|
||||
generator.definitions_[funcName] = code;
|
||||
return null;
|
||||
}
|
||||
|
||||
export const procedures_callreturn = function (_, generator) {
|
||||
// Call a procedure with a return value.
|
||||
var funcName = generator.variableDB_.getName(this.getFieldValue('NAME'),
|
||||
Procedures.NAME_TYPE);
|
||||
var args = [];
|
||||
for (var x = 0; x < this.arguments_.length; x++) {
|
||||
args[x] = generator.valueToCode(this, 'ARG' + x,
|
||||
generator.ORDER_NONE) || 'null';
|
||||
}
|
||||
var code = funcName + '(' + args.join(', ') + ')';
|
||||
return [code, generator.ORDER_UNARY_POSTFIX];
|
||||
}
|
||||
|
||||
export const procedures_callnoreturn = function (_, generator) {
|
||||
// Call a procedure with no return value.
|
||||
var funcName = generator.variableDB_.getName(this.getFieldValue('NAME'),
|
||||
Procedures.NAME_TYPE);
|
||||
var args = [];
|
||||
for (var x = 0; x < this.arguments_.length; x++) {
|
||||
args[x] = generator.valueToCode(this, 'ARG' + x,
|
||||
generator.ORDER_NONE) || 'null';
|
||||
}
|
||||
var code = funcName + '(' + args.join(', ') + ');\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const procedures_ifreturn = function (_, generator) {
|
||||
// Conditionally return value from a procedure.
|
||||
var condition = generator.valueToCode(this, 'CONDITION',
|
||||
generator.ORDER_NONE) || 'false';
|
||||
var code = 'if (' + condition + ') {\n';
|
||||
if (this.hasReturnValue_) {
|
||||
var value = generator.valueToCode(this, 'VALUE',
|
||||
generator.ORDER_NONE) || '';
|
||||
code += ' return ' + value + ';\n';
|
||||
} else {
|
||||
code += ' return;\n';
|
||||
}
|
||||
code += '}\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const procedures_return = function (_, generator) {
|
||||
// Conditionally return value from a procedure.
|
||||
var code = ""
|
||||
if (this.hasReturnValue_) {
|
||||
var value = generator.valueToCode(this, 'VALUE',
|
||||
generator.ORDER_NONE) || 'None';
|
||||
code += 'return ' + value + ';\n';
|
||||
} else {
|
||||
code += 'return;\n';
|
||||
}
|
||||
code += '\n';
|
||||
return code;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
import { Variables } from 'blockly/core';
|
||||
|
||||
export const variables_get = function (_, generator) {
|
||||
// Variable getter.
|
||||
var code = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Variables.NAME_TYPE);
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const variables_declare = function (_, generator) {
|
||||
var dropdown_type = this.getFieldValue('TYPE');
|
||||
var dropdown_variables_type = this.getFieldValue('variables_type');
|
||||
var argument0;
|
||||
var code = '';
|
||||
//TODO: settype to variable
|
||||
if (dropdown_variables_type == 'global_variate') {
|
||||
if (dropdown_type == 'String') {
|
||||
argument0 = generator.valueToCode(this, 'VALUE', generator.ORDER_ASSIGNMENT) || '""';
|
||||
} else {
|
||||
argument0 = generator.valueToCode(this, 'VALUE', generator.ORDER_ASSIGNMENT) || '0';
|
||||
}
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Variables.NAME_TYPE);
|
||||
if (dropdown_type == 'String' || dropdown_type == 'char*')
|
||||
generator.definitions_['var_declare' + varName] = dropdown_type + ' ' + varName + ';';
|
||||
else
|
||||
generator.definitions_['var_declare' + varName] = 'volatile ' + dropdown_type + ' ' + varName + ';';
|
||||
|
||||
generator.setups_['setup_var' + varName] = varName + ' = ' + argument0 + ';';
|
||||
}
|
||||
else {
|
||||
if (dropdown_type == 'String') {
|
||||
argument0 = generator.valueToCode(this, 'VALUE', generator.ORDER_ASSIGNMENT) || '""';
|
||||
} else {
|
||||
argument0 = generator.valueToCode(this, 'VALUE', generator.ORDER_ASSIGNMENT) || '0';
|
||||
}
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Variables.NAME_TYPE);
|
||||
code = dropdown_type + ' ' + varName + ' = ' + argument0 + ';\n';
|
||||
}
|
||||
//generator.variableTypes_[varName] = dropdown_type;//处理变量类型
|
||||
return code;
|
||||
}
|
||||
|
||||
export const variables_set = function (_, generator) {
|
||||
// Variable setter.
|
||||
var argument0 = generator.valueToCode(this, 'VALUE',
|
||||
generator.ORDER_ASSIGNMENT) || '0';
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Variables.NAME_TYPE);
|
||||
return varName + ' = ' + argument0 + ';\n';
|
||||
}
|
||||
|
||||
export const variables_change = function (_, generator) {
|
||||
// Variable setter.
|
||||
var operator = this.getFieldValue('OP');
|
||||
var varName = generator.valueToCode(this, 'MYVALUE', generator.ORDER_ASSIGNMENT);
|
||||
//修复强制类型转换不正确的bug
|
||||
var code = '((' + operator + ')(' + varName + '))';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
@@ -3,9 +3,13 @@ import { Profile } from 'mixly';
|
||||
|
||||
import {
|
||||
ArduinoEthernetBlocks,
|
||||
ArduinoProceduresBlocks,
|
||||
ArduinoTextBlocks,
|
||||
ArduinoVariablesBlocks,
|
||||
ArduinoEthernetGenerators,
|
||||
ArduinoProceduresGenerators,
|
||||
ArduinoTextGenerators,
|
||||
ArduinoVariablesGenerators,
|
||||
Procedures,
|
||||
Variables,
|
||||
Arduino
|
||||
@@ -26,14 +30,12 @@ import {
|
||||
ArduinoAVRMathBlocks,
|
||||
ArduinoAVRPinoutBlocks,
|
||||
ArduinoAVRPinsBlocks,
|
||||
ArduinoAVRProceduresBlocks,
|
||||
ArduinoAVRScoopBlocks,
|
||||
ArduinoAVRSensorBlocks,
|
||||
ArduinoAVRSerialBlocks,
|
||||
ArduinoAVRStorageBlocks,
|
||||
ArduinoAVRTextBlocks,
|
||||
ArduinoAVRToolsBlocks,
|
||||
ArduinoAVRVariablesBlocks,
|
||||
ArduinoAVRActuatorGenerators,
|
||||
ArduinoAVRBlynkGenerators,
|
||||
ArduinoAVRCommunicateGenerators,
|
||||
@@ -47,14 +49,12 @@ import {
|
||||
ArduinoAVRMathGenerators,
|
||||
ArduinoAVRPinoutGenerators,
|
||||
ArduinoAVRPinsGenerators,
|
||||
ArduinoAVRProceduresGenerators,
|
||||
ArduinoAVRScoopGenerators,
|
||||
ArduinoAVRSensorGenerators,
|
||||
ArduinoAVRSerialGenerators,
|
||||
ArduinoAVRStorageGenerators,
|
||||
ArduinoAVRTextGenerators,
|
||||
ArduinoAVRToolsGenerators,
|
||||
ArduinoAVRVariablesGenerators
|
||||
ArduinoAVRToolsGenerators
|
||||
} from './';
|
||||
|
||||
import './css/color.css';
|
||||
@@ -72,7 +72,9 @@ Object.assign(Profile.default, ArduinoAVRPins.arduino_standard);
|
||||
Object.assign(
|
||||
Blockly.Blocks,
|
||||
ArduinoEthernetBlocks,
|
||||
ArduinoProceduresBlocks,
|
||||
ArduinoTextBlocks,
|
||||
ArduinoVariablesBlocks,
|
||||
ArduinoAVRActuatorBlocks,
|
||||
ArduinoAVRBlynkBlocks,
|
||||
ArduinoAVRCommunicateBlocks,
|
||||
@@ -86,20 +88,20 @@ Object.assign(
|
||||
ArduinoAVRMathBlocks,
|
||||
ArduinoAVRPinoutBlocks,
|
||||
ArduinoAVRPinsBlocks,
|
||||
ArduinoAVRProceduresBlocks,
|
||||
ArduinoAVRScoopBlocks,
|
||||
ArduinoAVRSensorBlocks,
|
||||
ArduinoAVRSerialBlocks,
|
||||
ArduinoAVRStorageBlocks,
|
||||
ArduinoAVRTextBlocks,
|
||||
ArduinoAVRToolsBlocks,
|
||||
ArduinoAVRVariablesBlocks
|
||||
ArduinoAVRToolsBlocks
|
||||
);
|
||||
|
||||
Object.assign(
|
||||
Blockly.Arduino.forBlock,
|
||||
ArduinoEthernetGenerators,
|
||||
ArduinoProceduresGenerators,
|
||||
ArduinoTextGenerators,
|
||||
ArduinoVariablesGenerators,
|
||||
ArduinoAVRActuatorGenerators,
|
||||
ArduinoAVRBlynkGenerators,
|
||||
ArduinoAVRCommunicateGenerators,
|
||||
@@ -113,12 +115,10 @@ Object.assign(
|
||||
ArduinoAVRMathGenerators,
|
||||
ArduinoAVRPinoutGenerators,
|
||||
ArduinoAVRPinsGenerators,
|
||||
ArduinoAVRProceduresGenerators,
|
||||
ArduinoAVRScoopGenerators,
|
||||
ArduinoAVRSensorGenerators,
|
||||
ArduinoAVRSerialGenerators,
|
||||
ArduinoAVRStorageGenerators,
|
||||
ArduinoAVRTextGenerators,
|
||||
ArduinoAVRToolsGenerators,
|
||||
ArduinoAVRVariablesGenerators
|
||||
ArduinoAVRToolsGenerators
|
||||
);
|
||||
Reference in New Issue
Block a user