Browse Source

add setup wait until

zeedee
Thorsten Riess 4 years ago
parent
commit
0a301b124d
5 changed files with 55 additions and 2 deletions
  1. +1
    -0
      blockly/apps/blocklyduino/index.html
  2. +2
    -1
      blockly/arduino_compressed.js
  3. +31
    -0
      blockly/blocks/zeedee.js
  4. +3
    -1
      blockly/blocks_compressed.js
  5. +18
    -0
      blockly/generators/arduino/zeedee.js

+ 1
- 0
blockly/apps/blocklyduino/index.html View File

@ -424,6 +424,7 @@ function init() {
</value>
</block>
<block type="zeedee_dist"></block>
<block type="zeedee_waitsetup"></block>
</category>
<category name="Servo">
<block type="servo_move">


+ 2
- 1
blockly/arduino_compressed.js View File

@ -51,7 +51,8 @@ Blockly.Arduino.zeedee_left=function(){var a=this.getFieldValue("PINLEFT"),b=thi
Blockly.Arduino.setups_["setup_zeedee_servo_"+b]="zeedee_servo_"+b+".attach("+b+");\n";a="zeedee_servo_"+a+".write("+Math.max(Math.min(Math.floor(90+.9*c),180),0)+");\n";return a=a+"zeedee_servo_"+b+".write("+Math.max(Math.min(Math.floor(90+.9*c),180),0)+");\n"};
Blockly.Arduino.zeedee_right=function(){var a=this.getFieldValue("PINLEFT"),b=this.getFieldValue("PINRIGHT"),c=Blockly.Arduino.valueToCode(this,"PERCENTAGE",Blockly.Arduino.ORDER_ATOMIC);Blockly.Arduino.definitions_.define_zeedee_move="#include <Servo.h>\n";Blockly.Arduino.definitions_["var_zeedee_servo"+a]="Servo zeedee_servo_"+a+";\n";Blockly.Arduino.definitions_["var_zeedee_servo"+b]="Servo zeedee_servo_"+b+";\n";Blockly.Arduino.setups_["setup_zeedee_servo_"+a]="zeedee_servo_"+a+".attach("+a+");\n";
Blockly.Arduino.setups_["setup_zeedee_servo_"+b]="zeedee_servo_"+b+".attach("+b+");\n";a="zeedee_servo_"+a+".write("+Math.max(Math.min(Math.floor(90-.9*c),180),0)+");\n";return a=a+"zeedee_servo_"+b+".write("+Math.max(Math.min(Math.floor(90-.9*c),180),0)+");\n"};
Blockly.Arduino.zeedee_dist=function(){var a=this.getFieldValue("PINTRIGGER"),b=this.getFieldValue("PINECHO"),c=this.getFieldValue("MEDIAN"),d=this.getFieldValue("ITERATIONS");Blockly.Arduino.definitions_.define_zeedee_ping="#include <NewPing.h>\n";Blockly.Arduino.definitions_["var_zeedee_ping_"+a+"_"+b]="NewPing zeedee_ping_"+a+"_"+b+"("+a+","+b+");\n";a="zeedee_ping_"+a+"_"+b;return["TRUE"==c?"("+a+".ping_median("+d+") / US_ROUNDTRIP_CM)":a+".ping_cm()",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.procedures={};
Blockly.Arduino.zeedee_dist=function(){var a=this.getFieldValue("PINTRIGGER"),b=this.getFieldValue("PINECHO"),c=this.getFieldValue("MEDIAN"),d=this.getFieldValue("ITERATIONS");Blockly.Arduino.definitions_.define_zeedee_ping="#include <NewPing.h>\n";Blockly.Arduino.definitions_["var_zeedee_ping_"+a+"_"+b]="NewPing zeedee_ping_"+a+"_"+b+"("+a+","+b+");\n";a="zeedee_ping_"+a+"_"+b;return["TRUE"==c?"("+a+".ping_median("+d+") / US_ROUNDTRIP_CM)":a+".ping_cm()",Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.zeedee_waitsetup=function(){var a="UNTIL"==this.getFieldValue("MODE"),b=Blockly.Arduino.valueToCode(this,"BOOL",a?Blockly.Arduino.ORDER_LOGICAL_NOT:Blockly.Arduino.ORDER_NONE)||"false",c=Blockly.Arduino.statementToCode(this,"DO");Blockly.Arduino.INFINITE_LOOP_TRAP&&(c=Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+this.id+"'")+c);a&&(b="!"+b);Blockly.Arduino.setups_.setup_zeedee_waitsetup="while ("+b+") {\n"+c+"}\n";return""};Blockly.Arduino.procedures={};
Blockly.Arduino.procedures_defreturn=function(){var a=Blockly.Arduino.variableDB_.getName(this.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),b=Blockly.Arduino.statementToCode(this,"STACK");Blockly.Arduino.INFINITE_LOOP_TRAP&&(b=Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+this.id+"'")+b);var c=Blockly.Arduino.valueToCode(this,"RETURN",Blockly.Arduino.ORDER_NONE)||"";c&&(c=" return "+c+";\n");for(var d=c?"int":"void",e=[],f=0;f<this.arguments_.length;f++)e[f]="int "+Blockly.Arduino.variableDB_.getName(this.arguments_[f],
Blockly.Variables.NAME_TYPE);b=d+" "+a+"("+e.join(", ")+") {\n"+b+c+"}\n";b=Blockly.Arduino.scrub_(this,b);Blockly.Arduino.definitions_[a]=b;return null};Blockly.Arduino.procedures_defnoreturn=Blockly.Arduino.procedures_defreturn;
Blockly.Arduino.procedures_callreturn=function(){for(var a=Blockly.Arduino.variableDB_.getName(this.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),b=[],c=0;c<this.arguments_.length;c++)b[c]=Blockly.Arduino.valueToCode(this,"ARG"+c,Blockly.Arduino.ORDER_NONE)||"null";return[a+"("+b.join(", ")+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};


+ 31
- 0
blockly/blocks/zeedee.js View File

@ -128,3 +128,34 @@ Blockly.Blocks['zeedee_dist'] = {
this.setOutput(true, 'Number');
}
};
Blockly.Blocks['zeedee_waitsetup'] = {
/**
* Block for 'do while/until' loop in the setup routine.
* @this Blockly.Block
*/
init: function() {
var OPERATORS =
[[Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_WHILE, 'WHILE'],
[Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_UNTIL, 'UNTIL']];
this.setHelpUrl(Blockly.Msg.CONTROLS_WHILEUNTIL_HELPURL);
this.setColour(Blockly.Blocks.loops.HUE);
this.appendValueInput('BOOL')
.setCheck('Boolean')
.appendField(new Blockly.FieldDropdown(OPERATORS), 'MODE');
this.appendStatementInput('DO')
.appendField(Blockly.Msg.CONTROLS_WHILEUNTIL_INPUT_DO);
this.setPreviousStatement(true);
this.setNextStatement(true);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function() {
var op = thisBlock.getFieldValue('MODE');
var TOOLTIPS = {
'WHILE': Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_WHILE,
'UNTIL': Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL
};
return TOOLTIPS[op];
});
}
};

+ 3
- 1
blockly/blocks_compressed.js View File

@ -156,7 +156,9 @@ null);this.setNextStatement(!0,null);this.setTooltip("turn left with given perce
Blockly.Blocks.zeedee_right={helpUrl:"https://www.hacknology.de/projekt/2016/zeedee/",init:function(){this.setColour(190);this.appendDummyInput().appendField("ZeeDee R").appendField("PINL#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PINLEFT").appendField("PINR#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PINRIGHT");this.appendValueInput("PERCENTAGE","Number").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField("PERCENTAGE (0~100)");this.setPreviousStatement(!0,
null);this.setNextStatement(!0,null);this.setTooltip("turn right with given percentage")}};
Blockly.Blocks.zeedee_dist={helpUrl:"https://www.hacknology.de/projekt/2016/zeedee/",init:function(){this.setColour(190);this.appendDummyInput().appendField("ZeeDee Dist").appendField("PINT#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PINTRIGGER").appendField("PINE#").appendField(new Blockly.FieldDropdown(profile["default"].digital),"PINECHO").appendField("median:").appendField(new Blockly.FieldCheckbox("TRUE"),"MEDIAN").appendField("iterations:").appendField(new Blockly.FieldDropdown([["5",
"5"],["3","3"],["7","7"]]),"ITERATIONS");this.setTooltip("read the current distance");this.setOutput(!0,"Number")}};Blockly.Blocks.procedures={};Blockly.Blocks.procedures.HUE=290;
"5"],["3","3"],["7","7"]]),"ITERATIONS");this.setTooltip("read the current distance");this.setOutput(!0,"Number")}};
Blockly.Blocks.zeedee_waitsetup={init:function(){var a=[[Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_WHILE,"WHILE"],[Blockly.Msg.CONTROLS_WHILEUNTIL_OPERATOR_UNTIL,"UNTIL"]];this.setHelpUrl(Blockly.Msg.CONTROLS_WHILEUNTIL_HELPURL);this.setColour(Blockly.Blocks.loops.HUE);this.appendValueInput("BOOL").setCheck("Boolean").appendField(new Blockly.FieldDropdown(a),"MODE");this.appendStatementInput("DO").appendField(Blockly.Msg.CONTROLS_WHILEUNTIL_INPUT_DO);this.setPreviousStatement(!0);this.setNextStatement(!0);
var b=this;this.setTooltip(function(){var a=b.getFieldValue("MODE");return{WHILE:Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_WHILE,UNTIL:Blockly.Msg.CONTROLS_WHILEUNTIL_TOOLTIP_UNTIL}[a]})}};Blockly.Blocks.procedures={};Blockly.Blocks.procedures.HUE=290;
Blockly.Blocks.procedures_defnoreturn={init:function(){this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL);this.setColour(Blockly.Blocks.procedures.HUE);var a=Blockly.Procedures.findLegalName(Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE,this),a=new Blockly.FieldTextInput(a,Blockly.Procedures.rename);a.setSpellcheck(!1);this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_TITLE).appendField(a,"NAME").appendField("","PARAMS");this.setMutator(new Blockly.Mutator(["procedures_mutatorarg"]));
this.setTooltip(Blockly.Msg.PROCEDURES_DEFNORETURN_TOOLTIP);this.arguments_=[];this.setStatements_(!0);this.statementConnection_=null},setStatements_:function(a){this.hasStatements_!==a&&(a?(this.appendStatementInput("STACK").appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_DO),this.getInput("RETURN")&&this.moveInputBefore("STACK","RETURN")):this.removeInput("STACK",!0),this.hasStatements_=a)},updateParams_:function(){for(var a=!1,b={},c=0;c<this.arguments_.length;c++){if(b["arg_"+this.arguments_[c].toLowerCase()]){a=
!0;break}b["arg_"+this.arguments_[c].toLowerCase()]=!0}a?this.setWarningText(Blockly.Msg.PROCEDURES_DEF_DUPLICATE_WARNING):this.setWarningText(null);a="";this.arguments_.length&&(a=Blockly.Msg.PROCEDURES_BEFORE_PARAMS+" "+this.arguments_.join(", "));this.setFieldValue(a,"PARAMS")},mutationToDom:function(){for(var a=document.createElement("mutation"),b=0;b<this.arguments_.length;b++){var c=document.createElement("arg");c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}this.hasStatements_||


+ 18
- 0
blockly/generators/arduino/zeedee.js View File

@ -108,3 +108,21 @@ Blockly.Arduino.zeedee_dist = function() {
}
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
Blockly.Arduino.zeedee_waitsetup = function() {
// Do while/until loop.
var until = this.getFieldValue('MODE') == 'UNTIL';
var argument0 = Blockly.Arduino.valueToCode(this, 'BOOL',
until ? Blockly.Arduino.ORDER_LOGICAL_NOT :
Blockly.Arduino.ORDER_NONE) || 'false';
var branch = Blockly.Arduino.statementToCode(this, 'DO');
if (Blockly.Arduino.INFINITE_LOOP_TRAP) {
branch = Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g,
'\'' + this.id + '\'') + branch;
}
if (until) {
argument0 = '!' + argument0;
}
Blockly.Arduino.setups_['setup_zeedee_waitsetup'] = 'while (' + argument0 + ') {\n' + branch + '}\n';
return '';
};

Loading…
Cancel
Save