add language selection
This commit is contained in:
@@ -17,5 +17,6 @@ import './audio';
|
||||
import './procedures';
|
||||
import './time';
|
||||
import './variables';
|
||||
import './lists';
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
|
||||
Blockly.Arduino['lists_create_empty'] = function () {
|
||||
var code = '';
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
Blockly.Arduino['array_getIndex'] = function () {
|
||||
var code = '';
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
|
||||
Blockly.Arduino['lists_length'] = function () {
|
||||
var array = Blockly.Arduino.valueToCode(this, 'ARRAY', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var code = `${array}.length`;
|
||||
return [code, Blockly.Arduino.ORDER_ATOMIC];
|
||||
}
|
||||
@@ -31,6 +31,42 @@ Blockly.Arduino.sensebox_display_printDisplay = function () {
|
||||
return code;
|
||||
};
|
||||
|
||||
|
||||
Blockly.Arduino.sensebox_display_fastPrint = function () {
|
||||
var title1 = Blockly.Arduino.valueToCode(this, 'Title1', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var value1 = Blockly.Arduino.valueToCode(this, 'Value1', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var dimension1 = Blockly.Arduino.valueToCode(this, 'Dimension1', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var title2 = Blockly.Arduino.valueToCode(this, 'Title2', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
var value2 = Blockly.Arduino.valueToCode(this, 'Value2', Blockly.Arduino.ORDER_ATOMIC);
|
||||
var dimension2 = Blockly.Arduino.valueToCode(this, 'Dimension2', Blockly.Arduino.ORDER_ATOMIC) || '0'
|
||||
Blockly.Arduino.codeFunctions_['sensebox_fastPrint'] = `
|
||||
void printOnDisplay(String title1, String measurement1, String unit1, String title2, String measurement2, String unit2) {
|
||||
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE, BLACK);
|
||||
display.println(title1);
|
||||
display.setCursor(0, 10);
|
||||
display.setTextSize(2);
|
||||
display.print(measurement1);
|
||||
display.print(" ");
|
||||
display.setTextSize(1);
|
||||
display.println(unit1);
|
||||
display.setCursor(0, 30);
|
||||
display.setTextSize(1);
|
||||
display.println(title2);
|
||||
display.setCursor(0, 40);
|
||||
display.setTextSize(2);
|
||||
display.print(measurement2);
|
||||
display.print(" ");
|
||||
display.setTextSize(1);
|
||||
display.println(unit2);
|
||||
}
|
||||
`
|
||||
var code = ` printOnDisplay(${title1}, String(${value1}), ${dimension1}, ${title2}, String(${value2}), ${dimension2});\n`;
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Arduino.sensebox_display_show = function (block) {
|
||||
var show = Blockly.Arduino.statementToCode(block, 'SHOW');
|
||||
var code = '';
|
||||
|
||||
@@ -14,9 +14,28 @@ const setVariableFunction = function (defaultValue) {
|
||||
|
||||
const allVars = Blockly.getMainWorkspace().getVariableMap().getAllVariables();
|
||||
const myVar = allVars.filter(v => v.name === variableName)[0]
|
||||
var code = ''
|
||||
|
||||
Blockly.Arduino.variables_[myVar + myVar.type] = myVar.type + " " + myVar.name + ';\n';
|
||||
return variableName + ' = ' + (variableValue || defaultValue) + ';\n';
|
||||
switch (myVar.type) {
|
||||
default:
|
||||
Blockly.Arduino.variables_[myVar + myVar.type] = myVar.type + " " + myVar.name + ';\n';
|
||||
code = variableName + ' = ' + (variableValue || defaultValue) + ';\n';
|
||||
break;
|
||||
case 'Array':
|
||||
var arrayType;
|
||||
var number;
|
||||
|
||||
if (this.getChildren().length > 0) {
|
||||
if (this.getChildren()[0].type === 'lists_create_empty') {
|
||||
|
||||
arrayType = this.getChildren()[0].getFieldValue('type');
|
||||
number = Blockly.Arduino.valueToCode(this.getChildren()[0], 'NUMBER', Blockly['Arduino'].ORDER_ATOMIC);
|
||||
Blockly.Arduino.variables_[myVar + myVar.type] = `${arrayType} ${myVar.name} [${number}];\n`;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return code;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -25,8 +44,8 @@ const getVariableFunction = function (block) {
|
||||
block.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE
|
||||
);
|
||||
|
||||
return [variableName, Blockly['Arduino'].ORDER_ATOMIC];
|
||||
var code = variableName;
|
||||
return [code, Blockly['Arduino'].ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly['Arduino']['variables_set_dynamic'] = setVariableFunction()
|
||||
|
||||
Reference in New Issue
Block a user