Commit 154d9f12 authored by carlosperate's avatar carlosperate

Create built version of Arduino blocks and generator.

parent 6cd98de1
// Do not edit this file; automatically generated by build.py.
'use strict';
/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
Based on work of Fred Lin (gasolin@gmail.com) for Blocklyduino.
@fileoverview Helper functions for generating Arduino language (C++) for
blocks.
*/
Blockly.Arduino=new Blockly.Generator("Arduino");Blockly.Arduino.addReservedWords("Blockly,setup,loop,if,else,for,switch,case,while,do,break,continue,return,goto,define,include,HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false,integer,constants,floating,point,void,boolean,char,unsigned,byte,int,word,long,float,double,string,String,array,static,volatile,const,sizeof,pinMode,digitalWrite,digitalRead,analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn,pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain,map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead,bitWrite,bitSet,bitClear,bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts");
Blockly.Arduino.ORDER_ATOMIC=0;Blockly.Arduino.ORDER_UNARY_POSTFIX=1;Blockly.Arduino.ORDER_UNARY_PREFIX=2;Blockly.Arduino.ORDER_MULTIPLICATIVE=3;Blockly.Arduino.ORDER_ADDITIVE=4;Blockly.Arduino.ORDER_SHIFT=5;Blockly.Arduino.ORDER_RELATIONAL=6;Blockly.Arduino.ORDER_EQUALITY=7;Blockly.Arduino.ORDER_BITWISE_AND=8;Blockly.Arduino.ORDER_BITWISE_XOR=9;Blockly.Arduino.ORDER_BITWISE_OR=10;Blockly.Arduino.ORDER_LOGICAL_AND=11;Blockly.Arduino.ORDER_LOGICAL_OR=12;Blockly.Arduino.ORDER_CONDITIONAL=13;
Blockly.Arduino.ORDER_ASSIGNMENT=14;Blockly.Arduino.ORDER_NONE=99;Blockly.Arduino.PinTypes={INPUT:"INPUT",OUTPUT:"OUTPUT",PWM:"PWM",SERVO:"SERVO",STEPPER:"STEPPER",SERIAL:"SERIAL",I2C:"I2C/TWI",SPI:"SPI"};Blockly.Arduino.DEF_FUNC_NAME=Blockly.Arduino.FUNCTION_NAME_PLACEHOLDER_;
Blockly.Arduino.init=function(a){Blockly.Arduino.includes_=Object.create(null);Blockly.Arduino.definitions_=Object.create(null);Blockly.Arduino.codeFunctions_=Object.create(null);Blockly.Arduino.userFunctions_=Object.create(null);Blockly.Arduino.functionNames_=Object.create(null);Blockly.Arduino.setups_=Object.create(null);Blockly.Arduino.pins_=Object.create(null);Blockly.Arduino.variableDB_?Blockly.Arduino.variableDB_.reset():Blockly.Arduino.variableDB_=new Blockly.Names(Blockly.Arduino.RESERVED_WORDS_);
var b=Blockly.StaticTyping.getAllVarsWithTypes(a);Blockly.StaticTyping.setProcedureArgs(a,b);a=[];for(var c in b)a.push(Blockly.Arduino.getArduinoType_(b[c])+" "+c+";");Blockly.Arduino.definitions_.variables=a.join("\n")};
Blockly.Arduino.finish=function(a){var b=[],c=[],d=[],e;for(e in Blockly.Arduino.includes_)b.push(Blockly.Arduino.includes_[e]);b.length&&b.push("\n");for(e in Blockly.Arduino.definitions_)c.push(Blockly.Arduino.definitions_[e]);c.length&&c.push("\n");for(e in Blockly.Arduino.codeFunctions_)d.push(Blockly.Arduino.codeFunctions_[e]);for(e in Blockly.Arduino.userFunctions_)d.push(Blockly.Arduino.userFunctions_[e]);d.length&&d.push("\n");var f=[""],g="";void 0!==Blockly.Arduino.setups_.userSetupCode&&
(g="\n"+Blockly.Arduino.setups_.userSetupCode,delete Blockly.Arduino.setups_.userSetupCode);for(e in Blockly.Arduino.setups_)f.push(Blockly.Arduino.setups_[e]);g&&f.push(g);delete Blockly.Arduino.includes_;delete Blockly.Arduino.definitions_;delete Blockly.Arduino.codeFunctions_;delete Blockly.Arduino.userFunctions_;delete Blockly.Arduino.functionNames_;delete Blockly.Arduino.setups_;delete Blockly.Arduino.pins_;Blockly.Arduino.variableDB_.reset();b=b.join("\n")+c.join("\n")+d.join("\n\n");f="void setup() {"+
f.join("\n ")+"\n}\n\n";a="void loop() {\n "+a.replace(/\n/g,"\n ")+"\n}";return b+f+a};Blockly.Arduino.addInclude=function(a,b){void 0===Blockly.Arduino.includes_[a]&&(Blockly.Arduino.includes_[a]=b)};Blockly.Arduino.addDeclaration=function(a,b){void 0===Blockly.Arduino.definitions_[a]&&(Blockly.Arduino.definitions_[a]=b)};Blockly.Arduino.addSetup=function(a,b,c){c?Blockly.Arduino.setups_[a]=b:void 0===Blockly.Arduino.setups_[a]&&(Blockly.Arduino.setups_[a]=b)};
Blockly.Arduino.addFunction=function(a,b){if(void 0===Blockly.Arduino.codeFunctions_[a]){var c=Blockly.Arduino.variableDB_.getDistinctName(a,Blockly.Generator.NAME_TYPE);Blockly.Arduino.codeFunctions_[a]=b.replace(Blockly.Arduino.DEF_FUNC_NAME,c);Blockly.Arduino.functionNames_[a]=c}return Blockly.Arduino.functionNames_[a]};
Blockly.Arduino.reservePin=function(a,b,c,d){void 0!==Blockly.Arduino.pins_[b]?Blockly.Arduino.pins_[b]!=c?a.setWarningText("Pin "+b+" is needed for "+d+" as pin "+c+". Already used as "+Blockly.Arduino.pins_[b]+".",d):a.setWarningText(null,d):(Blockly.Arduino.pins_[b]=c,a.setWarningText(null,d))};Blockly.Arduino.scrubNakedValue=function(a){return a+";\n"};Blockly.Arduino.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/\$/g,"\\$").replace(/'/g,"\\'");return'"'+a+'"'};
Blockly.Arduino.scrub_=function(a,b){if(null===b)return"";var c="";if(!a.outputConnection||!a.outputConnection.targetConnection){var d=a.getCommentText();d&&(c+=this.prefixLines(d,"// ")+"\n");for(var e=0;e<a.inputList.length;e++)a.inputList[e].type==Blockly.INPUT_VALUE&&(d=a.inputList[e].connection.targetBlock())&&(d=this.allNestedComments(d))&&(c+=this.prefixLines(d,"// "))}e=a.nextConnection&&a.nextConnection.targetBlock();e=this.blockToCode(e);return c+b+e};
Blockly.Arduino.getArduinoType_=function(a){switch(a.typeName){case Blockly.StaticTyping.BlocklyTypes.NUMBER.typeName:return"int";case Blockly.StaticTyping.BlocklyTypes.DECIMAL.typeName:return"float";case Blockly.StaticTyping.BlocklyTypes.TEXT.typeName:return"String";case Blockly.StaticTyping.BlocklyTypes.CHARACTER.typeName:return"char";case Blockly.StaticTyping.BlocklyTypes.BOOLEAN.typeName:return"boolean";case Blockly.StaticTyping.BlocklyTypes.NULL.typeName:return"void";case Blockly.StaticTyping.BlocklyTypes.UNDEF.typeName:return"undefined";
case Blockly.StaticTyping.BlocklyTypes.CHILD_BLOCK_MISSING.typeName:return"ChildBlockMissing";default:return"Invalid Blockly Type"}};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Generating Arduino code for the logic blocks.
*/
Blockly.Arduino.Boards={};Blockly.Arduino.Boards.generateDigitalIo=function(a,b){for(var c=[],d=a;d<b+1;d++)c.push([d.toString(),d.toString()]);return c};Blockly.Arduino.Boards.generateAnalogIo=function(a,b){for(var c=[],d=a;d<b+1;d++)c.push(["A"+d.toString(),"A"+d.toString()]);return c};
Blockly.Arduino.Boards.uno={name:"Arduino Uno",description:"Arduino Uno standard-compatible board",analogPins:Blockly.Arduino.Boards.generateAnalogIo(0,5),digitalPins:Blockly.Arduino.Boards.generateDigitalIo(0,13).concat(Blockly.Arduino.Boards.generateAnalogIo(0,5)),pwmPins:[["3","3"],["5","5"],["6","6"],["9","9"],["10","10"],["11","11"]],serial:[["serial","Serial"]],serialPins:{serial:[["RX","0"],["TX","1"]]},serialSpeed:[["300","300"],["600","600"],["1200","1200"],["2400","2400"],["4800","4800"],
["9600","9600"],["14400","14400"],["19200","19200"],["28800","28800"],["31250","31250"],["38400","38400"],["57600","57600"],["115200","115200"]],spi:[["SPI","SPI"]],spiPins:{spi:[["MOSI","11"],["MISO","12"],["SCK","13"]]},spiClockDivide:[["2 (8MHz)","SPI_CLOCK_DIV2"],["4 (4MHz)","SPI_CLOCK_DIV4"],["8 (2MHz)","SPI_CLOCK_DIV8"],["16 (1MHz)","SPI_CLOCK_DIV16"],["32 (500KHz)","SPI_CLOCK_DIV32"],["64 (250KHz)","SPI_CLOCK_DIV64"],["128 (125KHz)","SPI_CLOCK_DIV128"]],i2c:[["I2C","Wire"]],i2cPins:{I2C:[["SDA",
"A4"],["SCL","A5"]]},i2cSpeed:[["100kHz","100000L"],["400kHz","400000L"]],builtinLed:[["BUILTIN_1","13"]],interrupt:[["interrupt0","2"],["interrupt1","3"]]};
Blockly.Arduino.Boards.duemilanove={name:"Arduino Duemilanove",description:"Arduino Duemilanove with ATmega168p or ATmega328p board",analogPins:Blockly.Arduino.Boards.uno.analogPins,digitalPins:Blockly.Arduino.Boards.uno.digitalPins,pwmPins:Blockly.Arduino.Boards.uno.pwmPins,serial:Blockly.Arduino.Boards.uno.serial,serialPins:Blockly.Arduino.Boards.uno.serialPins,serialSpeed:Blockly.Arduino.Boards.uno.serialSpeed,spi:Blockly.Arduino.Boards.uno.spi,spiPins:Blockly.Arduino.Boards.uno.spiPins,spiClockDivide:Blockly.Arduino.Boards.uno.spiClockDivide,
i2c:Blockly.Arduino.Boards.uno.i2c,i2cPins:Blockly.Arduino.Boards.uno.i2cPins,i2cSpeed:Blockly.Arduino.Boards.uno.i2cSpeed,builtinLed:Blockly.Arduino.Boards.uno.builtinLed,interrupt:Blockly.Arduino.Boards.uno.interrupt};Blockly.Arduino.Boards.duemilanove_168p=Blockly.Arduino.Boards.duemilanove;Blockly.Arduino.Boards.duemilanove_328p=Blockly.Arduino.Boards.duemilanove;
Blockly.Arduino.Boards.mega={name:"Arduino Mega",description:"Arduino Mega-compatible board",analogPins:Blockly.Arduino.Boards.generateAnalogIo(0,15),digitalPins:Blockly.Arduino.Boards.generateDigitalIo(0,53),pwmPins:Blockly.Arduino.Boards.generateDigitalIo(2,13).concat(Blockly.Arduino.Boards.generateDigitalIo(44,46)),serial:[["serial","Serial"],["serial_1","Serial1"],["serial_2","Serial2"],["serial_3","Serial3"]],serialPins:{serial:[["TX","0"],["RX","1"]],serial1:[["TX","18"],["TX","19"]],serial2:[["TX",
"16"],["TX","17"]],serial3:[["TX","14"],["TX","15"]]},serialSpeed:Blockly.Arduino.Boards.uno.serialSpeed,spi:[["SPI","SPI"]],spiPins:{SPI:[["MOSI","51"],["MISO","50"],["SCK","52"]]},spiClockDivide:Blockly.Arduino.Boards.uno.spiClockDivide,i2c:[["I2C","Wire"]],i2cPins:{I2C:[["SDA","20"],["SCL","21"]]},i2cSpeed:[["100kHz","100000L"],["400kHz","400000L"]],builtinLed:Blockly.Arduino.Boards.uno.builtinLed,interrupt:[["interrupt0","2"],["interrupt1","3"],["interrupt2","21"],["interrupt3","20"],["interrupt4",
"19"],["interrupt5","18"]]};
Blockly.Arduino.Boards.leonardo={description:"Arduino Leonardo-compatible board",analogPins:Blockly.Arduino.Boards.generateAnalogIo(0,5).concat([["A6","4"],["A7","6"],["A8","8"],["A9","9"],["A10","10"],["A11","12"]]),digitalPins:Blockly.Arduino.Boards.generateDigitalIo(0,13).concat(Blockly.Arduino.Boards.generateAnalogIo(0,5)),pwmPins:Blockly.Arduino.Boards.uno.pwmPins.concat([["13","13"]]),serial:Blockly.Arduino.Boards.uno.serial,serialPins:Blockly.Arduino.Boards.uno.serialPins,serialSpeed:Blockly.Arduino.Boards.uno.serialSpeed,
spi:[["SPI","SPI"]],spiPins:{SPI:[["MOSI","ICSP-4"],["MISO","ICSP-1"],["SCK","ICSP-3"]]},spiClockDivide:Blockly.Arduino.Boards.uno.spiClockDivide,i2c:[["I2C","Wire"]],i2cPins:{I2C:[["SDA","2"],["SCL","3"]]},i2cSpeed:Blockly.Arduino.Boards.uno.i2cSpeed,builtinLed:Blockly.Arduino.Boards.uno.builtinLed,interrupt:[["interrupt0","3"],["interrupt1","2"],["interrupt2","0"],["interrupt3","1"],["interrupt4","17"]]};Blockly.Arduino.Boards.yun=Blockly.Arduino.Boards.leonardo;
Blockly.Arduino.Boards.selected=Blockly.Arduino.Boards.uno;Blockly.Arduino.Boards.changeBoard=function(a,b){if(void 0===Blockly.Arduino.Boards[b])console.log("Tried to set non-existing Arduino board: "+b);else{Blockly.Arduino.Boards.selected=Blockly.Arduino.Boards[b];for(var c=a.getAllBlocks(),d=0;d<c.length;d++){var e=c[d].updateFields;e&&e.call(c[d])}}};
Blockly.Arduino.Boards.refreshBlockFieldDropdown=function(a,b,c){var d=a.getField(b);b=d.getValue();c=Blockly.Arduino.Boards.selected[c];d.menuGenerator_=c;for(var d=!1,e=0;e<c.length;e++)b==c[e][1]&&(d=!0);d?a.setWarningText(null,"bPin"):a.setWarningText("The old pin value "+b+" is no longer available.","bPin")};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Generating Arduino code for colour blocks.
Based on the javascript generator
TODO: These blocks do not really serve a purpose for Arduino code.
*/
Blockly.Arduino.colour={};Blockly.Arduino.colour_picker=function(){return["'"+block.getFieldValue("COLOUR")+"'",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.colour_random=function(a){return[Blockly.Arduino.provideFunction_("colour_random",["function "+Blockly.Arduino.FUNCTION_NAME_PLACEHOLDER_+"() {"," var num = Math.floor(Math.random() * Math.pow(2, 24));"," return '#' + ('00000' + num.toString(16)).substr(-6);","}"])+"()",Blockly.Arduino.ORDER_FUNCTION_CALL]};
Blockly.Arduino.colour_rgb=function(a){var b=Blockly.Arduino.valueToCode(a,"RED",Blockly.Arduino.ORDER_NONE)||0,c=Blockly.Arduino.valueToCode(a,"GREEN",Blockly.Arduino.ORDER_NONE)||0;a=Blockly.Arduino.valueToCode(a,"BLUE",Blockly.Arduino.ORDER_NONE)||0;if(!Blockly.Arduino.definitions_.colour_rgb){Blockly.Arduino.definitions_.import_arduino_math="import 'arduino:math' as Math;";var d=Blockly.Arduino.variableDB_.getDistinctName("colour_rgb",Blockly.Generator.NAME_TYPE);Blockly.Arduino.colour_rgb.functionName=
d;var e=[];e.push("String "+d+"(r, g, b) {");e.push(" String rs = (Math.max(Math.min(r, 1), 0) * 255).round().toRadixString(16);");e.push(" String gs = (Math.max(Math.min(g, 1), 0) * 255).round().toRadixString(16);");e.push(" String bs = (Math.max(Math.min(b, 1), 0) * 255).round().toRadixString(16);");e.push(" rs = '0$rs';");e.push(" rs = rs.substring(rs.length - 2);");e.push(" gs = '0$gs';");e.push(" gs = gs.substring(gs.length - 2);");e.push(" bs = '0$bs';");e.push(" bs = bs.substring(bs.length - 2);");
e.push(" return '#$rs$gs$bs';");e.push("}");Blockly.Arduino.definitions_.colour_rgb=e.join("\n")}return[Blockly.Arduino.colour_rgb.functionName+"("+b+", "+c+", "+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.colour_blend=function(a){var b=Blockly.Arduino.valueToCode(a,"COLOUR1",Blockly.Arduino.ORDER_NONE)||"'#000000'",c=Blockly.Arduino.valueToCode(a,"COLOUR2",Blockly.Arduino.ORDER_NONE)||"'#000000'";a=Blockly.Arduino.valueToCode(a,"RATIO",Blockly.Arduino.ORDER_NONE)||.5;if(!Blockly.Arduino.definitions_.colour_blend){Blockly.Arduino.definitions_.import_arduino_math="import 'arduino:math' as Math;";var d=Blockly.Arduino.variableDB_.getDistinctName("colour_blend",Blockly.Generator.NAME_TYPE);
Blockly.Arduino.colour_blend.functionName=d;var e=[];e.push("String "+d+"(c1, c2, ratio) {");e.push(" ratio = Math.max(Math.min(ratio, 1), 0);");e.push(" int r1 = parseInt('0x${c1.substring(1, 3)}');");e.push(" int g1 = parseInt('0x${c1.substring(3, 5)}');");e.push(" int b1 = parseInt('0x${c1.substring(5, 7)}');");e.push(" int r2 = parseInt('0x${c2.substring(1, 3)}');");e.push(" int g2 = parseInt('0x${c2.substring(3, 5)}');");e.push(" int b2 = parseInt('0x${c2.substring(5, 7)}');");e.push(" String rs = (r1 * (1 - ratio) + r2 * ratio).round().toRadixString(16);");
e.push(" String gs = (g1 * (1 - ratio) + g2 * ratio).round().toRadixString(16);");e.push(" String bs = (b1 * (1 - ratio) + b2 * ratio).round().toRadixString(16);");e.push(" rs = '0$rs';");e.push(" rs = rs.substring(rs.length - 2);");e.push(" gs = '0$gs';");e.push(" gs = gs.substring(gs.length - 2);");e.push(" bs = '0$bs';");e.push(" bs = bs.substring(bs.length - 2);");e.push(" return '#$rs$gs$bs';");e.push("}");Blockly.Arduino.definitions_.colour_blend=e.join("\n")}return[Blockly.Arduino.colour_blend.functionName+
"("+b+", "+c+", "+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Code generator Arduino Digital and Analogue input/output
blocks. The Arduino built in functions syntax can be found at:
http://arduino.cc/en/Reference/HomePage
*/
Blockly.Arduino.IO={};Blockly.Arduino.io_digitalwrite=function(a){var b=a.getFieldValue("PIN"),c=Blockly.Arduino.valueToCode(a,"STATE",Blockly.Arduino.ORDER_ATOMIC)||"0";Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.OUTPUT,"Digital Write");Blockly.Arduino.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);return"digitalWrite("+b+", "+c+");\n"};
Blockly.Arduino.io_digitalread=function(a){var b=a.getFieldValue("PIN");Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.INPUT,"Digital Read");Blockly.Arduino.addSetup("io_"+b,"pinMode("+b+", INPUT);",!1);return["digitalRead("+b+")",Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.io_builtin_led=function(a){var b=a.getFieldValue("BUILT_IN_LED"),c=Blockly.Arduino.valueToCode(a,"STATE",Blockly.Arduino.ORDER_ATOMIC)||"0";Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.OUTPUT,"Set LED");Blockly.Arduino.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);return"digitalWrite("+b+", "+c+");\n"};
Blockly.Arduino.io_analogwrite=function(a){var b=a.getFieldValue("PIN"),c=Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_ATOMIC)||"0";Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.OUTPUT,"Analogue Write");Blockly.Arduino.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);0>c||255<c?a.setWarningText("The analogue value set must be between 0 and 255","pwm_value"):a.setWarningText(null,"pwm_value");return"analogWrite("+b+", "+c+");\n"};
Blockly.Arduino.io_analogread=function(a){var b=a.getFieldValue("PIN");Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.INPUT,"Analogue Read");Blockly.Arduino.addSetup("io_"+b,"pinMode("+b+", INPUT);",!1);return["analogRead("+b+")",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.io_highlow=function(a){return[a.getFieldValue("STATE"),Blockly.Arduino.ORDER_ATOMIC]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Generating Arduino code for list blocks.
Based on the Dart list code generator.
TODO: A lot of this can be converted to arrays code by creating functions to
replicate this kind of behavior.
*/
Blockly.Arduino.lists={};Blockly.Arduino.lists_create_empty=function(a){return["[]",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.lists_create_with=function(a){for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++)b[c]=Blockly.Arduino.valueToCode(a,"ADD"+c,Blockly.Arduino.ORDER_NONE)||"null";b="["+b.join(", ")+"]";return[b,Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.lists_repeat=function(a){if(!Blockly.Arduino.definitions_.lists_repeat){var b=Blockly.Arduino.variableDB_.getDistinctName("lists_repeat",Blockly.Generator.NAME_TYPE);Blockly.Arduino.lists_repeat.repeat=b;var c=[];c.push("List "+b+"(value, n) {");c.push(" var array = new List(n);");c.push(" for (int i = 0; i < n; i++) {");c.push(" array[i] = value;");c.push(" }");c.push(" return array;");c.push("}");Blockly.Arduino.definitions_.lists_repeat=c.join("\n")}b=Blockly.Arduino.valueToCode(a,
"ITEM",!0)||"null";a=Blockly.Arduino.valueToCode(a,"NUM")||"0";return[Blockly.Arduino.lists_repeat.repeat+"("+b+", "+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.lists_length=function(a){return Blockly.Arduino.text_length.call(a)};Blockly.Arduino.lists_isEmpty=function(a){return Blockly.Arduino.text_isEmpty.call(a)};Blockly.Arduino.lists_indexOf=function(a){return Blockly.Arduino.text_indexOf.call(a)};Blockly.Arduino.lists_getIndex=function(a){return Blockly.Arduino.text_charAt.call(a)};
Blockly.Arduino.lists_setIndex=function(a){var b=Blockly.Arduino.valueToCode(a,"AT",Blockly.Arduino.ORDER_ADDITIVE)||"1",c=Blockly.Arduino.valueToCode(a,"LIST",Blockly.Arduino.ORDER_UNARY_POSTFIX)||"[]";a=Blockly.Arduino.valueToCode(a,"TO",Blockly.Arduino.ORDER_ASSIGNMENT)||"null";b=b.match(/^\d+$/)?parseInt(b,10)-1:b+" - 1";return c+"["+b+"] = "+a+";\n"};Blockly.Arduino.logic={};Blockly.Arduino.controls_if=function(a){for(var b=0,c=Blockly.Arduino.valueToCode(a,"IF"+b,Blockly.Arduino.ORDER_NONE)||"false",d=Blockly.Arduino.statementToCode(a,"DO"+b),e="if ("+c+") {\n"+d+"}",b=1;b<=a.elseifCount_;b++)c=Blockly.Arduino.valueToCode(a,"IF"+b,Blockly.Arduino.ORDER_NONE)||"false",d=Blockly.Arduino.statementToCode(a,"DO"+b),e+=" else if ("+c+") {\n"+d+"}";a.elseCount_&&(d=Blockly.Arduino.statementToCode(a,"ELSE"),e+=" else {\n"+d+"}");return e+"\n"};
Blockly.Arduino.logic_compare=function(a){var b={EQ:"==",NEQ:"!=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")],c="=="==b||"!="==b?Blockly.Arduino.ORDER_EQUALITY:Blockly.Arduino.ORDER_RELATIONAL,d=Blockly.Arduino.valueToCode(a,"A",c)||"0";a=Blockly.Arduino.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]};
Blockly.Arduino.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"&&":"||",c="&&"==b?Blockly.Arduino.ORDER_LOGICAL_AND:Blockly.Arduino.ORDER_LOGICAL_OR,d=Blockly.Arduino.valueToCode(a,"A",c)||"false";a=Blockly.Arduino.valueToCode(a,"B",c)||"false";if(d||a){var e="&&"==b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+" "+b+" "+a,c]};
Blockly.Arduino.logic_negate=function(a){var b=Blockly.Arduino.ORDER_UNARY_PREFIX;return["!"+(Blockly.Arduino.valueToCode(a,"BOOL",b)||"false"),b]};Blockly.Arduino.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"true":"false",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.logic_null=function(a){return["NULL",Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.logic_ternary=function(a){var b=Blockly.Arduino.valueToCode(a,"IF",Blockly.Arduino.ORDER_CONDITIONAL)||"false",c=Blockly.Arduino.valueToCode(a,"THEN",Blockly.Arduino.ORDER_CONDITIONAL)||"null";a=Blockly.Arduino.valueToCode(a,"ELSE",Blockly.Arduino.ORDER_CONDITIONAL)||"null";return[b+" ? "+c+" : "+a,Blockly.Arduino.ORDER_CONDITIONAL]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Generating Arduino code for the loop blocks.
TODO: 'For each' block needs to have lists implemented.
*/
Blockly.Arduino.loops={};Blockly.Arduino.controls_repeat=function(a){var b=+a.getFieldValue("TIMES"),c=Blockly.Arduino.statementToCode(a,"DO"),c=Blockly.Arduino.addLoopTrap(c,a.id);a=Blockly.Arduino.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE);return"for (int "+a+" = 0; "+a+" < "+b+"; "+a+"++) {\n"+c+"}\n"};
Blockly.Arduino.controls_repeat_ext=function(a){var b=Blockly.Arduino.valueToCode(a,"TIMES",Blockly.Arduino.ORDER_ADDITIVE)||"0",c=Blockly.Arduino.statementToCode(a,"DO"),c=Blockly.Arduino.addLoopTrap(c,a.id);a="";var d=Blockly.Arduino.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.Arduino.variableDB_.getDistinctName("repeat_end",Blockly.Variables.NAME_TYPE),a+="int "+e+" = "+b+";\n");return a+("for (int "+d+" = 0; "+d+" < "+
e+"; "+d+"++) {\n"+c+"}\n")};Blockly.Arduino.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Arduino.valueToCode(a,"BOOL",b?Blockly.Arduino.ORDER_LOGICAL_OR:Blockly.Arduino.ORDER_NONE)||"false",d=Blockly.Arduino.statementToCode(a,"DO"),d=Blockly.Arduino.addLoopTrap(d,a.id);b&&(c.match(/^\w+$/)||(c="("+c+")"),c="!"+c);return"while ("+c+") {\n"+d+"}\n"};
Blockly.Arduino.controls_for=function(a){var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Arduino.valueToCode(a,"FROM",Blockly.Arduino.ORDER_ASSIGNMENT)||"0",d=Blockly.Arduino.valueToCode(a,"TO",Blockly.Arduino.ORDER_ASSIGNMENT)||"0",e=Blockly.Arduino.valueToCode(a,"BY",Blockly.Arduino.ORDER_ASSIGNMENT)||"1",f=Blockly.Arduino.statementToCode(a,"DO"),f=Blockly.Arduino.addLoopTrap(f,a.id);if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&Blockly.isNumber(e)){var g=
parseFloat(c)<=parseFloat(d);a="for ("+b+" = "+c+"; "+b+(g?" <= ":" >= ")+d+"; "+b;b=Math.abs(parseFloat(e));a=(1==b?a+(g?"++":"--"):a+((g?" += ":" -= ")+b))+(") {\n"+f+"}\n")}else a="",g=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(g=Blockly.Arduino.variableDB_.getDistinctName(b+"_start",Blockly.Variables.NAME_TYPE),a+="int "+g+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.Arduino.variableDB_.getDistinctName(b+"_end",Blockly.Variables.NAME_TYPE),a+="int "+c+" = "+d+";\n"),d=Blockly.Arduino.variableDB_.getDistinctName(b+
"_inc",Blockly.Variables.NAME_TYPE),a+="int "+d+" = ",a=Blockly.isNumber(e)?a+(Math.abs(e)+";\n"):a+("abs("+e+");\n"),a+="if ("+g+" > "+c+") {\n",a+=Blockly.Arduino.INDENT+d+" = -"+d+";\n",a+="}\n",a+="for ("+b+" = "+g+";\n "+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+";\n "+b+" += "+d+") {\n"+f+"}\n";return a};
Blockly.Arduino.controls_forEach=function(a){var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Arduino.valueToCode(a,"LIST",Blockly.Arduino.ORDER_ASSIGNMENT)||"[]",d=Blockly.Arduino.statementToCode(a,"DO"),d=Blockly.Arduino.addLoopTrap(d,a.id);a=Blockly.Arduino.variableDB_.getDistinctName(b+"_index",Blockly.Variables.NAME_TYPE);d=Blockly.Arduino.INDENT+b+" = "+c+"["+a+"];\n"+d;return"for (int "+a+" in "+c+") {\n"+d+"}\n"};
Blockly.Arduino.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw"Unknown flow statement.";};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Code generator for the Arduino map functionality.
The Arduino built in functions syntax can be found at:
http://arduino.cc/en/Reference/HomePage
*/
Blockly.Arduino.map={};Blockly.Arduino.base_map=function(a){var b=Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_NONE)||"0";a=Blockly.Arduino.valueToCode(a,"DMAX",Blockly.Arduino.ORDER_ATOMIC)||"0";return["map("+b+", 0, 1024, 0, "+a+")",Blockly.Arduino.ORDER_NONE]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Generating Arduino code for the math blocks.
TODO: Math on list needs lists to be implemented.
math_constant and math_change needs to be tested in compiler.
*/
Blockly.Arduino.math={};Blockly.Arduino.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));Infinity==a?a="INFINITY":-Infinity==a&&(a="-INFINITY");return[a,Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.Arduino.ORDER_ADDITIVE],MINUS:[" - ",Blockly.Arduino.ORDER_ADDITIVE],MULTIPLY:[" * ",Blockly.Arduino.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",Blockly.Arduino.ORDER_MULTIPLICATIVE],POWER:[null,Blockly.Arduino.ORDER_NONE]}[a.getFieldValue("OP")],c=b[0],b=b[1],d=Blockly.Arduino.valueToCode(a,"A",b)||"0";a=Blockly.Arduino.valueToCode(a,"B",b)||"0";return c?[d+c+a,b]:["Math.pow("+d+", "+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.math_single=function(a){var b=a.getFieldValue("OP"),c;if("NEG"==b)return a=Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_UNARY_PREFIX)||"0","-"==a[0]&&(a=" "+a),["-"+a,Blockly.Arduino.ORDER_UNARY_PREFIX];a="ABS"==b||"ROUND"==b.substring(0,5)?Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_UNARY_POSTFIX)||"0":"SIN"==b||"COS"==b||"TAN"==b?Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0":Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_NONE)||
"0";switch(b){case "ABS":c="abs("+a+")";break;case "ROOT":c="sqrt("+a+")";break;case "LN":c="log("+a+")";break;case "EXP":c="exp("+a+")";break;case "POW10":c="pow(10,"+a+")";break;case "ROUND":c="round("+a+")";break;case "ROUNDUP":c="ceil("+a+")";break;case "ROUNDDOWN":c="floor("+a+")";break;case "SIN":c="sin("+a+" / 180 * Math.PI)";break;case "COS":c="cos("+a+" / 180 * Math.PI)";break;case "TAN":c="tan("+a+" / 180 * Math.PI)"}if(c)return[c,Blockly.Arduino.ORDER_UNARY_POSTFIX];switch(b){case "LOG10":c=
"log("+a+") / log(10)";break;case "ASIN":c="asin("+a+") / M_PI * 180";break;case "ACOS":c="acos("+a+") / M_PI * 180";break;case "ATAN":c="atan("+a+") / M_PI * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.Arduino.ORDER_MULTIPLICATIVE]};
Blockly.Arduino.math_constant=function(a){return{PI:["M_PI",Blockly.Arduino.ORDER_UNARY_POSTFIX],E:["M_E",Blockly.Arduino.ORDER_UNARY_POSTFIX],GOLDEN_RATIO:["(1 + sqrt(5)) / 2",Blockly.Arduino.ORDER_MULTIPLICATIVE],SQRT2:["M_SQRT2",Blockly.Arduino.ORDER_UNARY_POSTFIX],SQRT1_2:["M_SQRT1_2",Blockly.Arduino.ORDER_UNARY_POSTFIX],INFINITY:["INFINITY",Blockly.Arduino.ORDER_ATOMIC]}[a.getFieldValue("CONSTANT")]};
Blockly.Arduino.math_number_property=function(a){var b=Blockly.Arduino.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0",c=a.getFieldValue("PROPERTY"),d;if("PRIME"==c)return a=Blockly.Arduino.addFunction("mathIsPrime",["boolean "+Blockly.Arduino.DEF_FUNC_NAME+"(int n) {"," // https://en.wikipedia.org/wiki/Primality_test#Naive_methods\n if (n == 2 || n == 3) {\n return true;\n }\n // False if n is NaN, negative, is 1.\n // And false if n is divisible by 2 or 3.\n if (isnan(n) || (n <= 1) || (n == 1) || (n % 2 == 0) || (n % 3 == 0)) {\n return false;\n }\n // Check all the numbers of form 6k +/- 1, up to sqrt(n).\n for (int x = 6; x <= sqrt(n) + 1; x += 6) {\n if (n % (x - 1) == 0 || n % (x + 1) == 0) {\n return false;\n }\n }\n return true;\n}"].join("\n")),
Blockly.Arduino.addInclude("math","#include <math.h>"),[a+"("+b+")",Blockly.Arduino.ORDER_UNARY_POSTFIX];switch(c){case "EVEN":d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":Blockly.Arduino.addInclude("math","#include <math.h>");d="(floor("+b+") == "+b+")";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.Arduino.valueToCode(a,"DIVISOR",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0",d=b+" % "+a+" == 0"}return[d,Blockly.Arduino.ORDER_EQUALITY]};
Blockly.Arduino.math_change=function(a){var b=Blockly.Arduino.valueToCode(a,"DELTA",Blockly.Arduino.ORDER_ADDITIVE)||"0";return Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" += "+b+";\n"};Blockly.Arduino.math_round=Blockly.Arduino.math_single;Blockly.Arduino.math_trig=Blockly.Arduino.math_single;
Blockly.Arduino.math_on_list=function(a){var b=a.getFieldValue("OP");a=Blockly.Arduino.valueToCode(a,"LIST",Blockly.Arduino.ORDER_NONE)||"[]";switch(b){case "SUM":var b=["num "+Blockly.Arduino.DEF_FUNC_NAME+"(List myList) {"," num sumVal = 0;"," myList.forEach((num entry) {sumVal += entry;});"," return sumVal;","}"],c=Blockly.Arduino.addFunction("mathListSum",b.join("\n")),b=c+"("+a+")";break;case "MIN":Blockly.Arduino.definitions_.math_min||(c=Blockly.Arduino.variableDB_.getDistinctName("math_min",
Blockly.Generator.NAME_TYPE),Blockly.Arduino.math_on_list.math_min=c,b=[],b.push("num "+c+"(List myList) {"),b.push(" if (myList.isEmpty()) return null;"),b.push(" num minVal = myList[0];"),b.push(" myList.forEach((num entry) {minVal = Math.min(minVal, entry);});"),b.push(" return minVal;"),b.push("}"),Blockly.Arduino.definitions_.math_min=b.join("\n"));b=Blockly.Arduino.math_on_list.math_min+"("+a+")";break;case "MAX":Blockly.Arduino.definitions_.math_max||(c=Blockly.Arduino.variableDB_.getDistinctName("math_max",
Blockly.Generator.NAME_TYPE),Blockly.Arduino.math_on_list.math_max=c,b=[],b.push("num "+c+"(List myList) {"),b.push(" if (myList.isEmpty()) return null;"),b.push(" num maxVal = myList[0];"),b.push(" myList.forEach((num entry) {maxVal = Math.max(maxVal, entry);});"),b.push(" return maxVal;"),b.push("}"),Blockly.Arduino.definitions_.math_max=b.join("\n"));b=Blockly.Arduino.math_on_list.math_max+"("+a+")";break;case "AVERAGE":Blockly.Arduino.definitions_.math_average||(c=Blockly.Arduino.variableDB_.getDistinctName("math_average",
Blockly.Generator.NAME_TYPE),Blockly.Arduino.math_on_list.math_average=c,b=[],b.push("num "+c+"(List myList) {"),b.push(" // First filter list for numbers only."),b.push(" List localList = myList.filter((a) => a is num);"),b.push(" if (localList.isEmpty()) return null;"),b.push(" num sumVal = 0;"),b.push(" localList.forEach((num entry) {sumVal += entry;});"),b.push(" return sumVal / localList.length;"),b.push("}"),Blockly.Arduino.definitions_.math_average=b.join("\n"));b=Blockly.Arduino.math_on_list.math_average+
"("+a+")";break;case "MEDIAN":Blockly.Arduino.definitions_.math_median||(c=Blockly.Arduino.variableDB_.getDistinctName("math_median",Blockly.Generator.NAME_TYPE),Blockly.Arduino.math_on_list.math_median=c,b=[],b.push("num "+c+"(List myList) {"),b.push(" // First filter list for numbers only, then sort, then return middle value"),b.push(" // or the average of two middle values if list has an even number of elements."),b.push(" List localList = myList.filter((a) => a is num);"),b.push(" if (localList.isEmpty()) return null;"),
b.push(" localList.sort((a, b) => (a - b));"),b.push(" int index = (localList.length / 2).toInt();"),b.push(" if (localList.length % 2 == 1) {"),b.push(" return localList[index];"),b.push(" } else {"),b.push(" return (localList[index - 1] + localList[index]) / 2;"),b.push(" }"),b.push("}"),Blockly.Arduino.definitions_.math_median=b.join("\n"));b=Blockly.Arduino.math_on_list.math_median+"("+a+")";break;case "MODE":Blockly.Arduino.definitions_.math_modes||(c=Blockly.Arduino.variableDB_.getDistinctName("math_modes",
Blockly.Generator.NAME_TYPE),Blockly.Arduino.math_on_list.math_modes=c,b=[],b.push("List "+c+"(values) {"),b.push(" List modes = [];"),b.push(" List counts = [];"),b.push(" int maxCount = 0;"),b.push(" for (int i = 0; i < values.length; i++) {"),b.push(" var value = values[i];"),b.push(" bool found = false;"),b.push(" int thisCount;"),b.push(" for (int j = 0; j < counts.length; j++) {"),b.push(" if (counts[j][0] === value) {"),b.push(" thisCount = ++counts[j][1];"),b.push(" found = true;"),
b.push(" break;"),b.push(" }"),b.push(" }"),b.push(" if (!found) {"),b.push(" counts.add([value, 1]);"),b.push(" thisCount = 1;"),b.push(" }"),b.push(" maxCount = Math.max(thisCount, maxCount);"),b.push(" }"),b.push(" for (int j = 0; j < counts.length; j++) {"),b.push(" if (counts[j][1] == maxCount) {"),b.push(" modes.add(counts[j][0]);"),b.push(" }"),b.push(" }"),b.push(" return modes;"),b.push("}"),Blockly.Arduino.definitions_.math_modes=b.join("\n"));
b=Blockly.Arduino.math_on_list.math_modes+"("+a+")";break;case "STD_DEV":Blockly.Arduino.definitions_.math_standard_deviation||(c=Blockly.Arduino.variableDB_.getDistinctName("math_standard_deviation",Blockly.Generator.NAME_TYPE),Blockly.Arduino.math_on_list.math_standard_deviation=c,b=[],b.push("num "+c+"(myList) {"),b.push(" // First filter list for numbers only."),b.push(" List numbers = myList.filter((a) => a is num);"),b.push(" if (numbers.isEmpty()) return null;"),b.push(" num n = numbers.length;"),
b.push(" num sum = 0;"),b.push(" numbers.forEach((x) => sum += x);"),b.push(" num mean = sum / n;"),b.push(" num sumSquare = 0;"),b.push(" numbers.forEach((x) => sumSquare += Math.pow(x - mean, 2));"),b.push(" return Math.sqrt(sumSquare / n);"),b.push("}"),Blockly.Arduino.definitions_.math_standard_deviation=b.join("\n"));b=Blockly.Arduino.math_on_list.math_standard_deviation+"("+a+")";break;case "RANDOM":Blockly.Arduino.definitions_.math_random_item||(c=Blockly.Arduino.variableDB_.getDistinctName("math_random_item",
Blockly.Generator.NAME_TYPE),Blockly.Arduino.math_on_list.math_random_item=c,b=[],b.push("Dynamic "+c+"(List myList) {"),b.push(" int x = (Math.random() * myList.length).floor().toInt();"),b.push(" return myList[x];"),b.push("}"),Blockly.Arduino.definitions_.math_random_item=b.join("\n"));b=Blockly.Arduino.math_on_list.math_random_item+"("+a+")";break;default:throw"Unknown operator: "+b;}return[b,Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.math_modulo=function(a){var b=Blockly.Arduino.valueToCode(a,"DIVIDEND",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Arduino.valueToCode(a,"DIVISOR",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,Blockly.Arduino.ORDER_MULTIPLICATIVE]};
Blockly.Arduino.math_constrain=function(a){var b=Blockly.Arduino.valueToCode(a,"VALUE",Blockly.Arduino.ORDER_NONE)||"0",c=Blockly.Arduino.valueToCode(a,"LOW",Blockly.Arduino.ORDER_NONE)||"0";a=Blockly.Arduino.valueToCode(a,"HIGH",Blockly.Arduino.ORDER_NONE)||"0";return["("+b+" < "+c+" ? "+c+" : ( "+b+" > "+a+" ? "+a+" : "+b+"))",Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.math_random_int=function(a){var b=Blockly.Arduino.valueToCode(a,"FROM",Blockly.Arduino.ORDER_NONE)||"0";a=Blockly.Arduino.valueToCode(a,"TO",Blockly.Arduino.ORDER_NONE)||"0";var c=Blockly.Arduino.variableDB_.getDistinctName("math_random_int",Blockly.Generator.NAME_TYPE);Blockly.Arduino.math_random_int.random_function=c;return[Blockly.Arduino.addFunction("mathRandomInt",["int "+Blockly.Arduino.DEF_FUNC_NAME+"(int min, int max) {"," if (min > max) {\n // Swap min and max to ensure min is smaller.\n int temp = min;\n min = max;\n max = temp;\n }\n return min + (rand() % (max - min + 1));\n}"].join("\n"))+
"("+b+", "+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.math_random_float=function(a){return["(rand() / RAND_MAX)",Blockly.Arduino.ORDER_UNARY_POSTFIX]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Generating Arduino code for procedure (function) blocks.
Based on the code generator for Dart
TODO: For now all variables will stay at "int". Once type is implemented
it needs to be captured on the functions with return.
*/
Blockly.Arduino.procedures={};
Blockly.Arduino.procedures_defreturn=function(a){var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=Blockly.Arduino.statementToCode(a,"STACK");Blockly.Arduino.STATEMENT_PREFIX&&(c=Blockly.Arduino.prefixLines(Blockly.Arduino.STATEMENT_PREFIX.replace(/%1/g,"'"+a.id+"'"),Blockly.Arduino.INDENT)+c);Blockly.Arduino.INFINITE_LOOP_TRAP&&(c=Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+c);var d=Blockly.Arduino.valueToCode(a,"RETURN",Blockly.Arduino.ORDER_NONE)||
"";d&&(d=" return "+d+";\n");for(var e=[],f=0;f<a.arguments_.length;f++)e[f]=Blockly.Arduino.getArduinoType_(a.getArgType(a.arguments_[f]))+" "+Blockly.Arduino.variableDB_.getName(a.arguments_[f],Blockly.Variables.NAME_TYPE);f=Blockly.StaticTyping.BlocklyTypes.NULL;a.getReturnType&&(f=a.getReturnType());f=Blockly.Arduino.getArduinoType_(f);c=f+" "+b+"("+e.join(", ")+") {\n"+c+d+"}";c=Blockly.Arduino.scrub_(a,c);Blockly.Arduino.userFunctions_[b]=c;return null};
Blockly.Arduino.procedures_defnoreturn=Blockly.Arduino.procedures_defreturn;Blockly.Arduino.procedures_callreturn=function(a){for(var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Arduino.valueToCode(a,"ARG"+d,Blockly.Arduino.ORDER_NONE)||"null";return[b+"("+c.join(", ")+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.procedures_callnoreturn=function(a){for(var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Arduino.valueToCode(a,"ARG"+d,Blockly.Arduino.ORDER_NONE)||"null";return b+"("+c.join(", ")+");\n"};
Blockly.Arduino.procedures_ifreturn=function(a){var b="if ("+(Blockly.Arduino.valueToCode(a,"CONDITION",Blockly.Arduino.ORDER_NONE)||"false")+") {\n";a.hasReturnValue_?(a=Blockly.Arduino.valueToCode(a,"VALUE",Blockly.Arduino.ORDER_NONE)||"null",b+=" return "+a+";\n"):b+=" return;\n";return b+"}\n"};
Blockly.Arduino.arduino_functions=function(a){var b=Blockly.Arduino.statementToCode(a,"SETUP_FUNC");b&&Blockly.Arduino.addSetup("userSetupCode",b,!0);a=a.getInputTargetBlock("LOOP_FUNC");b=Blockly.Arduino.blockToCode(a);if(!goog.isString(b))throw'Expecting code from statement block "'+a.type+'".';return b};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Code generator for the Arduino serial blocks.
The Arduino built in functions syntax can be found at:
http://arduino.cc/en/Reference/HomePage
TODO: There are more functions that can be added:
http://arduino.cc/en/Reference/Serial
*/
Blockly.Arduino.serial={};Blockly.Arduino.serial_print=function(a){var b=a.getFieldValue("SERIAL_ID"),c=Blockly.Arduino.valueToCode(a,"CONTENT",Blockly.Arduino.ORDER_ATOMIC)||"0";return"TRUE"==a.getFieldValue("NEW_LINE")?b+".println("+c+");\n":b+".print("+c+");\n"};Blockly.Arduino.serial_setup=function(a){var b=a.getFieldValue("SERIAL_ID");a=a.getFieldValue("SPEED");Blockly.Arduino.addSetup("serial_"+b,b+".begin("+a+");",!0);return""};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Arduino code generator for the Servo library blocks.
The Arduino Servo functions syntax can be found in
http://arduino.cc/en/reference/servo
TODO: If angle selector added to blocks edit code here.
*/
Blockly.Arduino.servo={};Blockly.Arduino.servo_write=function(a){var b=a.getFieldValue("SERVO_PIN"),c=Blockly.Arduino.valueToCode(a,"SERVO_ANGLE",Blockly.Arduino.ORDER_ATOMIC)||"90",d="myServo"+b;Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.SERVO,"Servo Write");Blockly.Arduino.addInclude("servo","#include <Servo.h>");Blockly.Arduino.addDeclaration("servo_"+b,"Servo "+d+";");Blockly.Arduino.addSetup("servo_"+b,d+".attach("+b+");",!0);return d+".write("+c+");\n"};
Blockly.Arduino.servo_read=function(a){var b=a.getFieldValue("SERVO_PIN"),c="myServo"+b;Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.SERVO,"Servo Read");Blockly.Arduino.addInclude("servo","#include <Servo.h>");Blockly.Arduino.addDeclaration("servo_"+b,"Servo "+c+";");Blockly.Arduino.addSetup("servo_"+b,c+".attach("+b+");",!0);return[c+".read()",Blockly.Arduino.ORDER_ATOMIC]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Arduino ode generator for SPI library blocks.
The Arduino SPI functions syntax can be found in:
http://arduino.cc/en/Reference/SPI
*/
Blockly.Arduino.spi={};
Blockly.Arduino.spi_setup=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SHIFT_ORDER"),d=a.getFieldValue("SPI_CLOCK_DIVIDE");a=a.getFieldValue("SPI_MODE");Blockly.Arduino.addInclude("spi","#include <SPI.h>");Blockly.Arduino.addSetup("spi_order",b+".setBitOrder("+c+");",!0);Blockly.Arduino.addSetup("spi_mode",b+".setDataMode("+a+");",!0);Blockly.Arduino.addSetup("spi_div",b+".setClockDivider("+d+");",!0);Blockly.Arduino.addSetup("spi_begin",b+".begin();",!0);return""};
Blockly.Arduino.spi_transfer=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SS"),d=Blockly.Arduino.valueToCode(a,"SPI_DATA",Blockly.Arduino.ORDER_ATOMIC)||"0";Blockly.Arduino.addInclude("spi","#include <SPI.h>");Blockly.Arduino.addSetup("spi_begin",b+".begin();",!1);for(var e=0;e<Blockly.Arduino.Boards.selected.spiPins.length;e++)Blockly.Arduino.reservePin(a,Blockly.Arduino.Boards.selected.spiPins[e][1],Blockly.Arduino.PinTypes.SPI,"SPI "+Blockly.Arduino.Boards.selected.spiPins[e][0]);
"none"!==c&&(Blockly.Arduino.reservePin(a,c,Blockly.Arduino.PinTypes.OUTPUT,"SPI Slave pin"),Blockly.Arduino.addSetup("io_"+c,"pinMode("+c+", OUTPUT);",!1));a=[];"none"!==c&&a.push("digitalWrite("+c+", HIGH);");a.push(b+".transfer("+d+");");"none"!==c&&a.push("digitalWrite("+c+", LOW);");return a.join("\n")+"\n"};
Blockly.Arduino.spi_transfer_return=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SS"),d=Blockly.Arduino.valueToCode(a,"SPI_DATA",Blockly.Arduino.ORDER_ATOMIC)||"0";Blockly.Arduino.spi_transfer(a);return["none"===c?b+".transfer("+d+")":Blockly.Arduino.addFunction("spiReturnSlave"+c,["int "+Blockly.Arduino.DEF_FUNC_NAME+"() {"," int spiReturn = 0;"," digitalWrite("+c+", HIGH);"," spiReturn = "+b+".transfer("+d+");"," digitalWrite("+c+", LOW);"," return spiReturn;\n}"].join("\n"))+
"()",Blockly.Arduino.ORDER_UNARY_POSTFIX]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Arduino code generator for the Stepper library blocks.
The Arduino Servo functions syntax can be found in the
following URL: http://arduino.cc/en/Reference/Stepper
*/
Blockly.Arduino.stepper={};
Blockly.Arduino.stepper_config=function(a){var b=a.getFieldValue("STEPPER_PIN1"),c=a.getFieldValue("STEPPER_PIN2"),d=Blockly.Arduino.PinTypes.STEPPER,e=a.getStepperSetupInstance(),f=Blockly.Arduino.valueToCode(a,"STEPPER_STEPS",Blockly.Arduino.ORDER_ATOMIC)||"360",g=Blockly.Arduino.valueToCode(a,"STEPPER_SPEED",Blockly.Arduino.ORDER_ATOMIC)||"90";Blockly.Arduino.reservePin(a,b,d,"Stepper");Blockly.Arduino.reservePin(a,c,d,"Stepper");Blockly.Arduino.addInclude("stepper","#include <Stepper.h>");Blockly.Arduino.addDeclaration("stepper_"+
e,"Stepper "+e+"("+f+", "+b+", "+c+");");Blockly.Arduino.addSetup("stepper_"+e,e+".setSpeed("+g+");",!0);return""};Blockly.Arduino.stepper_step=function(a){var b=a.getFieldValue("STEPPER_NAME");a=Blockly.Arduino.valueToCode(a,"STEPPER_STEPS",Blockly.Arduino.ORDER_ATOMIC)||"0";return b+".step("+a+");\n"};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Arduino code generator for the text blocks.
Partially implements the Serial interface in Arduino:
http://arduino.cc/en/Reference/Serial
TODO: Too many calls to String constructor, which consumes a lot of
resources. Once type identification is implemented this will need an
update.
TODO: Trim generator is not correct.
*/
Blockly.Arduino.text={};Blockly.Arduino.text=function(a){return[Blockly.Arduino.quote_(a.getFieldValue("TEXT")),Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.text_join=function(a){var b;if(0==a.itemCount_)return['""',Blockly.Arduino.ORDER_ATOMIC];if(1==a.itemCount_)b="String("+(Blockly.Arduino.valueToCode(a,"ADD0",Blockly.Arduino.ORDER_UNARY_POSTFIX)||'""')+")";else{var c;b=[];for(var d=0;d<a.itemCount_;d++)c=Blockly.Arduino.valueToCode(a,"ADD"+d,Blockly.Arduino.ORDER_NONE),b[d]=""==c?'""':"String("+c+")";b=b.join(" + ")}return[b,Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.text_append=function(a){var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);a=Blockly.Arduino.valueToCode(a,"TEXT",Blockly.Arduino.ORDER_UNARY_POSTFIX);return b+" += "+(""==a?'""':"String("+a+")")+";\n"};Blockly.Arduino.text_length=function(a){return["String("+(Blockly.Arduino.valueToCode(a,"VALUE",Blockly.Arduino.ORDER_UNARY_POSTFIX)||'""')+").length()",Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.text_isEmpty=function(a){var b=[];b.push("boolean "+Blockly.Arduino.DEF_FUNC_NAME+"(String msg) {");b.push(" if (msg.length() == 0) {");b.push(" return true;");b.push(" } else {");b.push(" return false;");b.push(" }");b.push("}");b=Blockly.Arduino.addFunction("isStringEmpty",b.join("\n"));a=Blockly.Arduino.valueToCode(a,"VALUE",Blockly.Arduino.ORDER_UNARY_POSTFIX);return[b+"("+(""==a?'""':"String("+a+")")+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.text_trim=function(a){Blockly.Arduino.text_trim.OPERATORS={LEFT:".trim()",RIGHT:".trim()",BOTH:".trim()"};var b=a.getFieldValue("MODE"),b=Blockly.Arduino.text_trim.OPERATORS[b];a=Blockly.Arduino.valueToCode(a,"TEXT",Blockly.Arduino.ORDER_UNARY_POSTFIX);return[(""==a?'""':"String("+a+")")+b,Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.text_print=function(a){var b=Blockly.Arduino.Boards.selected.serial[0][1];Blockly.Arduino.addSetup("serial_"+b,b+".begin(9600);",!1);a=Blockly.Arduino.valueToCode(a,"TEXT",Blockly.Arduino.ORDER_NONE);return b+".print("+(""==a?'""':"String("+a+")")+");\n"};
Blockly.Arduino.text_prompt_ext=function(a){var b=Blockly.Arduino.Boards.selected.serial[0][1],c=a.getFieldValue("TYPE"),d=[],e=c==Blockly.StaticTyping.BlocklyTypes.NUMBER.languageKeyword;e?d.push("int "+Blockly.Arduino.DEF_FUNC_NAME+"(String msg) {"):d.push("String "+Blockly.Arduino.DEF_FUNC_NAME+"(String msg) {");d.push(" "+b+".println(msg);");d.push(" boolean stringComplete = false;");e?d.push(" int content = 0;"):d.push(' String content = "";');d.push(" while (stringComplete == false) {");
d.push(" if ("+b+".available()) {");e?(d.push(" content = "+b+".parseInt();"),d.push(" stringComplete = true;")):(d.push(" char readChar = (char)"+b+".read();"),d.push(" if (readChar == '\\n' || readChar == '\\r') {"),d.push(" stringComplete = true;"),d.push(" } else {"),d.push(" content += readChar;"),d.push(" }"));d.push(" }");d.push(" }");d.push(" // Empty incoming serial buffer");d.push(" while(Serial.available()) { Serial.read(); };");d.push(" return content;");
d.push("}");c=Blockly.Arduino.addFunction("getUserInputPrompt"+c,d.join("\n"));Blockly.Arduino.addSetup("serial_"+b,b+".begin(9600);",!1);a=Blockly.Arduino.valueToCode(a,"TEXT",Blockly.Arduino.ORDER_NONE)||'""';return[c+"("+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.text_endString=function(a){return["",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.text_indexOf=function(a){return["",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.text_charAt=function(a){return["",Blockly.Arduino.ORDER_UNARY_POSTFIX]};
Blockly.Arduino.text_getSubstring=function(a){return["",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.text_changeCase=function(a){return["",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.text_prompt=function(a){return["",Blockly.Arduino.ORDER_UNARY_POSTFIX]};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Arduino code generator for the Time blocks.
The arduino built in functions syntax can be found in
http://arduino.cc/en/Reference/HomePage
*/
Blockly.Arduino.time={};Blockly.Arduino.time_delay=function(a){return"delay("+(Blockly.Arduino.valueToCode(a,"DELAY_TIME_MILI",Blockly.Arduino.ORDER_ATOMIC)||"0")+");\n"};Blockly.Arduino.time_delaymicros=function(a){return"delayMicroseconds("+(Blockly.Arduino.valueToCode(a,"DELAY_TIME_MICRO",Blockly.Arduino.ORDER_ATOMIC)||"0")+");\n"};Blockly.Arduino.time_millis=function(a){return["millis()",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.time_micros=function(a){return["micros()",Blockly.Arduino.ORDER_ATOMIC]};
Blockly.Arduino.infinite_loop=function(a){return"while(true);\n"};/*
Licensed under the Apache License, Version 2.0 (the "License"):
http://www.apache.org/licenses/LICENSE-2.0
@fileoverview Generating Arduino code for variables blocks.
*/
Blockly.Arduino.variables={};Blockly.Arduino.variables_get=function(a){return[Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.variables_set=function(a){var b=Blockly.Arduino.valueToCode(a,"VALUE",Blockly.Arduino.ORDER_ASSIGNMENT)||"0";return Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" = "+b+";\n"};
Blockly.Arduino.variables_set_type=function(a){var b=Blockly.Arduino.valueToCode(a,"VARIABLE_SETTYPE_INPUT",Blockly.Arduino.ORDER_ASSIGNMENT)||"0";return["("+Blockly.Arduino.getArduinoType_(Blockly.StaticTyping.BlocklyTypes[a.getFieldValue("VARIABLE_SETTYPE_TYPE")])+")("+b+")",Blockly.Arduino.ORDER_ATOMIC]};
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -10,13 +10,13 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.io');
goog.provide('Blockly.Blocks.io');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.io.HUE = 250;
Blockly.Blocks.io.HUE = 250;
Blockly.Blocks['io_digitalwrite'] = {
/**
......@@ -25,7 +25,7 @@ Blockly.Blocks['io_digitalwrite'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('STATE')
.appendField('set digital pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -54,7 +54,7 @@ Blockly.Blocks['io_digitalread'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalRead');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField('read digital pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -83,7 +83,7 @@ Blockly.Blocks['io_builtin_led'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('STATE')
.appendField('set LED')
.appendField(new Blockly.FieldDropdown(
......@@ -116,7 +116,7 @@ Blockly.Blocks['io_analogwrite'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogWrite');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('NUM')
.appendField('set analogue pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -148,7 +148,7 @@ Blockly.Blocks['io_analogread'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogRead');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField('read analogue pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -176,7 +176,7 @@ Blockly.Blocks['io_highlow'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Constants');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField(
new Blockly.FieldDropdown([['HIGH', 'HIGH'], ['LOW', 'LOW']]),
......
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
/*
* @fileoverview Blocks use for the Ardublockly logo creation.
* These are not mean to used at all.
*
* Generator:
* var noCode = function(block) { return ''; };
* Blockly.Arduino['ardublockly_name_bottom'] = noCode;
* Blockly.Arduino['ardublockly_plus_top_large'] = noCode;
* Blockly.Arduino['ardublockly_plus_top_small'] = noCode;
* Blockly.Arduino['ardublockly_plus_bottom_large'] = noCode;
* Blockly.Arduino['ardublockly_plus_bottom_small'] = noCode;
* Blockly.Arduino['ardublockly_plus_both_small'] = noCode;
* Blockly.Arduino['ardublockly_plus_both_large'] = noCode;
* Blockly.Arduino['ardublockly_minus_large'] = noCode;
* Blockly.Arduino['ardublockly_minus_small'] = noCode;
*
* Toolbox:
* <sep></sep>
* <category name="Logo">
......@@ -20,15 +34,12 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.logo');
goog.provide('Blockly.Blocks.logo');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
var noCode = function(block) { return ''; };
Blockly.Blocks.Arduino.variables.HUE = 180;
Blockly.Blocks.logo.HUE = 180;
/* Ardublockly block */
Blockly.Blocks['ardublockly_name_top'] = {
......@@ -36,22 +47,19 @@ Blockly.Blocks['ardublockly_name_top'] = {
this.appendDummyInput()
.appendField("Ardublockly");
this.setPreviousStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_name_top'] = noCode;
Blockly.Blocks['ardublockly_name_bottom'] = {
init: function() {
this.appendDummyInput()
.appendField("Ardublockly");
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
this.setTooltip('');
}
};
Blockly.Arduino['ardublockly_name_bottom'] = noCode;
/* Plus block */
Blockly.Blocks['ardublockly_plus_top_large'] = {
......@@ -59,40 +67,36 @@ Blockly.Blocks['ardublockly_plus_top_large'] = {
this.appendValueInput("NAME")
.appendField(" +");
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_top_large'] = noCode;
Blockly.Blocks['ardublockly_plus_top_small'] = {
init: function() {
this.appendValueInput("NAME")
.appendField(" +");
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_top_small'] = noCode;
Blockly.Blocks['ardublockly_plus_bottom_large'] = {
init: function() {
this.appendValueInput("NAME")
.appendField(" +");
this.setPreviousStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_bottom_large'] = noCode;
Blockly.Blocks['ardublockly_plus_bottom_small'] = {
init: function() {
this.appendValueInput("NAME")
.appendField(" +");
this.setPreviousStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_bottom_small'] = noCode;
Blockly.Blocks['ardublockly_plus_both_small'] = {
init: function() {
......@@ -100,10 +104,9 @@ Blockly.Blocks['ardublockly_plus_both_small'] = {
.appendField(" +");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_both_small'] = noCode;
Blockly.Blocks['ardublockly_plus_both_large'] = {
init: function() {
......@@ -111,11 +114,9 @@ Blockly.Blocks['ardublockly_plus_both_large'] = {
.appendField(" +");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_both_large'] = noCode;
/* Minus block */
Blockly.Blocks['ardublockly_minus_large'] = {
......@@ -124,10 +125,9 @@ Blockly.Blocks['ardublockly_minus_large'] = {
.appendField("- ");
this.setInputsInline(false);
this.setOutput(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_minus_large'] = noCode;
Blockly.Blocks['ardublockly_minus_small'] = {
init: function() {
......@@ -135,7 +135,6 @@ Blockly.Blocks['ardublockly_minus_small'] = {
.appendField("- ");
this.setInputsInline(false);
this.setOutput(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_minus_small'] = noCode;
......@@ -10,14 +10,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.map');
goog.provide('Blockly.Blocks.map');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.map.HUE = 230;
Blockly.Blocks.map.HUE = 230;
Blockly.Blocks['base_map'] = {
/**
......@@ -26,7 +26,7 @@ Blockly.Blocks['base_map'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/map');
this.setColour(Blockly.Blocks.Arduino.map.HUE);
this.setColour(Blockly.Blocks.map.HUE);
this.appendValueInput('NUM')
.appendField('Map ')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles());
......
......@@ -10,13 +10,11 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.procedures');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.procedures.HUE = 290;
Blockly.Blocks.procedures.HUE = 290;
Blockly.Blocks['arduino_functions'] = {
/**
......@@ -31,7 +29,7 @@ Blockly.Blocks['arduino_functions'] = {
.appendField('Arduino loop forever:');
this.appendStatementInput('LOOP_FUNC');
this.setInputsInline(false);
this.setColour(Blockly.Blocks.Arduino.procedures.HUE);
this.setColour(Blockly.Blocks.procedures.HUE);
this.setTooltip('Defines the Arduino setup() and loop() functions.');
this.setHelpUrl('https://arduino.cc/en/Reference/Loop');
this.contextMenu = false;
......
......@@ -11,14 +11,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.serial');
goog.provide('Blockly.Blocks.serial');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.serial.HUE = 160;
Blockly.Blocks.serial.HUE = 160;
Blockly.Blocks['serial_setup'] = {
/**
......@@ -27,7 +27,7 @@ Blockly.Blocks['serial_setup'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Serial/Begin');
this.setColour(Blockly.Blocks.Arduino.serial.HUE);
this.setColour(Blockly.Blocks.serial.HUE);
this.appendDummyInput()
.appendField('Setup')
.appendField(
......@@ -68,7 +68,7 @@ Blockly.Blocks['serial_print'] = {
*/
init: function() {
this.setHelpUrl('http://www.arduino.cc/en/Serial/Print');
this.setColour(Blockly.Blocks.Arduino.serial.HUE);
this.setColour(Blockly.Blocks.serial.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.serial), 'SERIAL_ID')
......
......@@ -10,14 +10,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.servo');
goog.provide('Blockly.Blocks.servo');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.servo.HUE = 60;
Blockly.Blocks.servo.HUE = 60;
Blockly.Blocks['servo_write'] = {
/**
......@@ -26,7 +26,7 @@ Blockly.Blocks['servo_write'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/ServoWrite');
this.setColour(Blockly.Blocks.Arduino.servo.HUE);
this.setColour(Blockly.Blocks.servo.HUE);
this.appendDummyInput()
.appendField('Set SERVO from Pin')
.appendField(new Blockly.FieldDropdown(
......@@ -59,7 +59,7 @@ Blockly.Blocks['servo_read'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/ServoRead');
this.setColour(Blockly.Blocks.Arduino.servo.HUE);
this.setColour(Blockly.Blocks.servo.HUE);
this.appendDummyInput()
.appendField('Read SERVO from PIN#')
.appendField(new Blockly.FieldDropdown(
......
......@@ -8,14 +8,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.spi');
goog.provide('Blockly.Blocks.spi');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.spi.HUE = 170;
Blockly.Blocks.spi.HUE = 170;
Blockly.Blocks['spi_setup'] = {
/**
......@@ -24,7 +24,7 @@ Blockly.Blocks['spi_setup'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/SPI');
this.setColour(Blockly.Blocks.Arduino.spi.HUE);
this.setColour(Blockly.Blocks.spi.HUE);
this.appendDummyInput()
.appendField('Setup')
.appendField(new Blockly.FieldDropdown(
......@@ -85,7 +85,7 @@ Blockly.Blocks['spi_transfer'] = {
Blockly.Arduino.Boards.selected.digitalPins);
this.setHelpUrl('http://arduino.cc/en/Reference/SPITransfer');
this.setColour(Blockly.Blocks.Arduino.spi.HUE);
this.setColour(Blockly.Blocks.spi.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.spi), 'SPI_ID');
......@@ -182,7 +182,7 @@ Blockly.Blocks['spi_transfer_return'] = {
Blockly.Arduino.Boards.selected.digitalPins);
this.setHelpUrl('http://arduino.cc/en/Reference/SPITransfer');
this.setColour(Blockly.Blocks.Arduino.spi.HUE);
this.setColour(Blockly.Blocks.spi.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.spi), 'SPI_ID');
......
......@@ -8,34 +8,33 @@
* Additional functions apart from the normal generators have
* been added to be able to generate the 'set' drop down menu
* with all current instances of the Stepper class:
* Blockly.Blocks.Arduino.stepper.stepperInstances
* Blockly.Blocks.Arduino.stepper.FieldStepperInstance
* Blockly.Blocks.Arduino.stepper.stepperDropdownList
* Blockly.Blocks.stepper.stepperInstances
* Blockly.Blocks.stepper.FieldStepperInstance
* Blockly.Blocks.stepper.stepperDropdownList
*
* TODO: Still need to had some kind of handler to refresh the "set" drop down
* menu values if an instance in a 'configure' block is renamed.
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.stepper');
goog.provide('Blockly.Blocks.stepper');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
goog.require('Blockly.FieldDropdown');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.stepper.HUE = 80;
Blockly.Blocks.stepper.HUE = 80;
/** Strings for easy reference. */
Blockly.Blocks.Arduino.stepper.noInstance = 'No_Instances';
Blockly.Blocks.Arduino.stepper.noName = 'Empty_input_name';
Blockly.Blocks.stepper.noInstance = 'No_Instances';
Blockly.Blocks.stepper.noName = 'Empty_input_name';
/**
* Finds all user-created instances of the Stepper block config.
* @return {!Array.<string>} Array of instance names.
*/
Blockly.Blocks.Arduino.stepper.stepperInstances = function() {
Blockly.Blocks.stepper.stepperInstances = function() {
var stepperList = [];
var blocks = Blockly.mainWorkspace.getTopBlocks();
for (var x = 0; x < blocks.length; x++) {
......@@ -54,8 +53,8 @@ Blockly.Blocks.Arduino.stepper.stepperInstances = function() {
* Return a sorted list of instances names for set dropdown menu.
* @return {!Array.<string>} Array of stepper instances names.
*/
Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
var stepperList = Blockly.Blocks.Arduino.stepper.stepperInstances();
Blockly.Blocks.stepper.stepperDropdownList = function() {
var stepperList = Blockly.Blocks.stepper.stepperInstances();
var options = [];
if (stepperList.length > 0) {
stepperList.sort(goog.string.caseInsensitiveCompare);
......@@ -66,8 +65,8 @@ Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
}
} else {
// There are no config blocks in the work area
options[0] = [Blockly.Blocks.Arduino.stepper.noInstance,
Blockly.Blocks.Arduino.stepper.noInstance];
options[0] = [Blockly.Blocks.stepper.noInstance,
Blockly.Blocks.stepper.noInstance];
}
return options;
};
......@@ -77,12 +76,12 @@ Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
* @extends {Blockly.FieldDropdown}
* @constructor
*/
Blockly.Blocks.Arduino.stepper.FieldStepperInstance = function() {
Blockly.Blocks.Arduino.stepper.FieldStepperInstance.superClass_.constructor
.call(this, Blockly.Blocks.Arduino.stepper.stepperDropdownList);
Blockly.Blocks.stepper.FieldStepperInstance = function() {
Blockly.Blocks.stepper.FieldStepperInstance.superClass_.constructor
.call(this, Blockly.Blocks.stepper.stepperDropdownList);
};
goog.inherits(
Blockly.Blocks.Arduino.stepper.FieldStepperInstance, Blockly.FieldDropdown);
Blockly.Blocks.stepper.FieldStepperInstance, Blockly.FieldDropdown);
Blockly.Blocks['stepper_config'] = {
......@@ -93,7 +92,7 @@ Blockly.Blocks['stepper_config'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperConstructor');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.setColour(Blockly.Blocks.stepper.HUE);
this.appendDummyInput()
.appendField('Setup')
.appendField(new Blockly.FieldTextInput('MyStepper'), 'STEPPER_NAME')
......@@ -125,7 +124,7 @@ Blockly.Blocks['stepper_config'] = {
getStepperSetupInstance: function() {
var InstanceName = this.getFieldValue('STEPPER_NAME');
if (!InstanceName) {
InstanceName = Blockly.Blocks.Arduino.stepper.noName;
InstanceName = Blockly.Blocks.stepper.noName;
}
// Replace all spaces with underscores
return InstanceName.replace(/ /g, '_');
......@@ -135,9 +134,9 @@ Blockly.Blocks['stepper_config'] = {
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
Blockly.Boards.refreshBlockFieldDropdown(
this, 'STEPPER_PIN1', 'digitalPins');
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
Blockly.Boards.refreshBlockFieldDropdown(
this, 'STEPPER_PIN2', 'digitalPins');
}
};
......@@ -149,10 +148,10 @@ Blockly.Blocks['stepper_step'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperStep');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.setColour(Blockly.Blocks.stepper.HUE);
this.appendDummyInput()
.appendField('move stepper')
.appendField(new Blockly.Blocks.Arduino.stepper.FieldStepperInstance(),
.appendField(new Blockly.Blocks.stepper.FieldStepperInstance(),
'STEPPER_NAME');
this.appendValueInput('STEPPER_STEPS')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles());
......@@ -170,7 +169,7 @@ Blockly.Blocks['stepper_step'] = {
{
"type": "field_dropdown",
"name": "STEPPER_NAME",
"options": Blockly.Blocks.Arduino.stepper.stepperDropdownList()
"options": Blockly.Blocks.stepper.stepperDropdownList()
},
{
"type": "input_value",
......@@ -181,7 +180,7 @@ Blockly.Blocks['stepper_step'] = {
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Blocks.Arduino.stepper.HUE,
"colour": Blockly.Blocks.stepper.HUE,
"tooltip": "Turns the stepper motor a specific number of steps.",
"helpUrl": "http://arduino.cc/en/Reference/StepperStep"
});*/
......@@ -196,14 +195,13 @@ Blockly.Blocks['stepper_step'] = {
if (!this.workspace) { return; } // Block has been deleted.
var currentDropdown = this.getFieldValue('STEPPER_NAME');
var instances = Blockly.Blocks.Arduino.stepper.stepperDropdownList();
var instances = Blockly.Blocks.stepper.stepperDropdownList();
// Check for configuration block presence
if (instances[0][0] === Blockly.Blocks.Arduino.stepper.noInstance) {
if (instances[0][0] === Blockly.Blocks.stepper.noInstance) {
// Ensure dropdown menu says there is no config block
if (currentDropdown !== Blockly.Blocks.Arduino.stepper.noInstance) {
this.setFieldValue(
Blockly.Blocks.Arduino.stepper.noInstance, 'STEPPER_NAME');
if (currentDropdown !== Blockly.Blocks.stepper.noInstance) {
this.setFieldValue(Blockly.Blocks.stepper.noInstance, 'STEPPER_NAME');
}
this.setWarningText(
'A STEPPER configuration block must be added to use this block!');
......@@ -212,9 +210,9 @@ Blockly.Blocks['stepper_step'] = {
var existingConfigSelected = false;
for (var x = 0; x < instances.length; x++) {
// Check if any of the config blocks does not have a name
if (instances[x][0] === Blockly.Blocks.Arduino.stepper.noName) {
if (instances[x][0] === Blockly.Blocks.stepper.noName) {
// If selected config has no name either, set warning and exit func
if (currentDropdown === Blockly.Blocks.Arduino.stepper.noName) {
if (currentDropdown === Blockly.Blocks.stepper.noName) {
this.setWarningText('A Name input must be added to the Stepper ' +
'configuration block!');
return;
......@@ -229,8 +227,8 @@ Blockly.Blocks['stepper_step'] = {
// All good, just remove any warnings and exit the function
this.setWarningText(null);
} else {
if ((currentDropdown === Blockly.Blocks.Arduino.stepper.noName) ||
(currentDropdown === Blockly.Blocks.Arduino.stepper.noInstance)) {
if ((currentDropdown === Blockly.Blocks.stepper.noName) ||
(currentDropdown === Blockly.Blocks.stepper.noInstance)) {
// Just pick the first config block
this.setFieldValue(instances[0][0], 'STEPPER_NAME');
this.setWarningText(null);
......
......@@ -8,14 +8,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.time');
goog.provide('Blockly.Blocks.time');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.time.HUE = 140;
Blockly.Blocks.time.HUE = 140;
Blockly.Blocks['time_delay'] = {
/**
......@@ -24,7 +24,7 @@ Blockly.Blocks['time_delay'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Delay');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendValueInput('DELAY_TIME_MILI')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles())
.appendField('wait');
......@@ -44,7 +44,7 @@ Blockly.Blocks['time_delaymicros'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DelayMicroseconds');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendValueInput('DELAY_TIME_MICRO')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles())
.appendField('wait');
......@@ -64,7 +64,7 @@ Blockly.Blocks['time_millis'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Millis');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField('current elapsed Time (milliseconds)');
this.setOutput(true, Blockly.StaticTyping.BlocklyTypes.NUMBER.basicType);
......@@ -84,7 +84,7 @@ Blockly.Blocks['time_micros'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Micros');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField('current elapsed Time (microseconds)');
this.setOutput(true, Blockly.StaticTyping.BlocklyTypes.NUMBER.basicType);
......@@ -107,7 +107,7 @@ Blockly.Blocks['infinite_loop'] = {
*/
init: function() {
this.setHelpUrl('');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField('wait forever (end program)');
this.setInputsInline(true);
......
......@@ -10,14 +10,12 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.variables');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.variables.HUE = 330;
Blockly.Blocks.variables.HUE = 330;
Blockly.Blocks['variables_set_type'] = {
/**
......@@ -26,7 +24,7 @@ Blockly.Blocks['variables_set_type'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/HomePage');
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.variables.HUE);
this.appendValueInput('VARIABLE_SETTYPE_INPUT');
this.appendDummyInput()
.appendField('as')
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -30,6 +30,7 @@
#
# This script also generates:
# blocks_compressed.js: The compressed Blockly language blocks.
# arduino_compressed.js: The compressed Arduino generator.
# javascript_compressed.js: The compressed Javascript generator.
# python_compressed.js: The compressed Python generator.
# dart_compressed.js: The compressed Dart generator.
......@@ -40,7 +41,7 @@ if sys.version_info[0] != 2:
raise Exception("Blockly build only compatible with Python 2.x.\n"
"You are using: " + sys.version)
import errno, glob, httplib, json, os, re, subprocess, threading, urllib
import errno, glob, fnmatch, httplib, json, os, re, subprocess, threading, urllib
def import_path(fullpath):
......@@ -173,6 +174,7 @@ class Gen_compressed(threading.Thread):
def run(self):
self.gen_core()
self.gen_blocks()
self.gen_generator("arduino")
self.gen_generator("javascript")
self.gen_generator("python")
self.gen_generator("php")
......@@ -202,7 +204,7 @@ class Gen_compressed(threading.Thread):
params.append(("js_code", "".join(f.readlines())))
f.close()
self.do_compile(params, target_filename, filenames, "")
self.do_compile(params, target_filename, filenames, [])
def gen_blocks(self):
target_filename = "blocks_compressed.js"
......@@ -219,14 +221,18 @@ class Gen_compressed(threading.Thread):
# Read in all the source files.
# Add Blockly.Blocks to be compatible with the compiler.
params.append(("js_code", "goog.provide('Blockly.Blocks');"))
filenames = glob.glob(os.path.join("blocks", "*.js"))
params.append(("js_code", "goog.provide('Blockly.StaticTyping');"))
filenames = []
for root, folders, files in os.walk("blocks"):
for filename in fnmatch.filter(files, "*.js"):
filenames.append(os.path.join(root, filename))
for filename in filenames:
f = open(filename)
params.append(("js_code", "".join(f.readlines())))
f.close()
# Remove Blockly.Blocks to be compatible with Blockly.
remove = "var Blockly={Blocks:{}};"
remove = ["var Blockly={Blocks:{}};", "Blockly.StaticTyping={};"]
self.do_compile(params, target_filename, filenames, remove)
def gen_generator(self, language):
......@@ -254,7 +260,7 @@ class Gen_compressed(threading.Thread):
filenames.insert(0, "[goog.provide]")
# Remove Blockly.Generator to be compatible with Blockly.
remove = "var Blockly={Generator:{}};"
remove = ["var Blockly={Generator:{}};"]
self.do_compile(params, target_filename, filenames, remove)
def do_compile(self, params, target_filename, filenames, remove):
......@@ -309,7 +315,8 @@ class Gen_compressed(threading.Thread):
sys.exit(1)
code = HEADER + "\n" + json_data["compiledCode"]
code = code.replace(remove, "")
for code_statement in remove:
code = code.replace(code_statement, "")
# Trim down Google's Apache licences.
# The Closure Compiler used to preserve these until August 2015.
......
......@@ -40,6 +40,7 @@ goog.require('Blockly.FieldTextInput');
goog.require('Blockly.FieldVariable');
goog.require('Blockly.Generator');
goog.require('Blockly.Msg');
goog.require('Blockly.StaticTyping');
goog.require('Blockly.Procedures');
goog.require('Blockly.Toolbox');
goog.require('Blockly.WidgetDiv');
......
......@@ -14,12 +14,6 @@ goog.require('Blockly.Block');
goog.require('Blockly.Workspace');
/**
* Class for StaticTyping.
* @constructor
*/
Blockly.StaticTyping = function() {};
/**
* "Enum-like" object to create blockly variable types.
* The number type is used to set a general number from the number block, the
......@@ -354,8 +348,8 @@ Blockly.StaticTyping.manageTypeWarning = function(block, bType, vName, vType) {
* Iterates through the list of top level blocks and sets the function arguments
* types.
* @param {Blockly.Workspace} workspace Blockly Workspace to collect variables.
* @param {Array<Blockly.StaticTyping.Type>} Associative array with the variable
* names as the keys and the type as the values.
* @param {Array<Blockly.StaticTyping.Type>} varsWithTypes Associative array
* with the variable names as the keys and the type as the values.
*/
Blockly.StaticTyping.setProcedureArgs = function(workspace, varsWithTypes) {
var blocks = workspace.getTopBlocks();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment