123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- // 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
- */
- Blockly.Python=new Blockly.Generator("Arduino");Blockly.Python.StaticTyping=new Blockly.StaticTyping;Blockly.Python.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.Python.ORDER_ATOMIC=0;Blockly.Python.ORDER_UNARY_POSTFIX=1;Blockly.Python.ORDER_UNARY_PREFIX=2;Blockly.Python.ORDER_MULTIPLICATIVE=3;Blockly.Python.ORDER_ADDITIVE=4;Blockly.Python.ORDER_SHIFT=5;Blockly.Python.ORDER_RELATIONAL=6;Blockly.Python.ORDER_EQUALITY=7;Blockly.Python.ORDER_BITWISE_AND=8;Blockly.Python.ORDER_BITWISE_XOR=9;Blockly.Python.ORDER_BITWISE_OR=10;Blockly.Python.ORDER_LOGICAL_AND=11;Blockly.Python.ORDER_LOGICAL_OR=12;Blockly.Python.ORDER_CONDITIONAL=13;
- Blockly.Python.ORDER_ASSIGNMENT=14;Blockly.Python.ORDER_NONE=99;Blockly.Python.PinTypes={INPUT:"INPUT",OUTPUT:"OUTPUT",PWM:"PWM",SERVO:"SERVO",STEPPER:"STEPPER",SERIAL:"SERIAL",I2C:"I2C/TWI",SPI:"SPI",FASTLED:"FASTLED",DHT:"DHT"};Blockly.Python.DEF_FUNC_NAME=Blockly.Python.FUNCTION_NAME_PLACEHOLDER_;
- Blockly.Python.init=function(a){Blockly.Python.includes_=Object.create(null);Blockly.Python.definitions_=Object.create(null);Blockly.Python.variables_=Object.create(null);Blockly.Python.codeFunctions_=Object.create(null);Blockly.Python.userFunctions_=Object.create(null);Blockly.Python.functionNames_=Object.create(null);Blockly.Python.setups_=Object.create(null);Blockly.Python.pins_=Object.create(null);Blockly.Python.variableDB_?Blockly.Python.variableDB_.reset():Blockly.Python.variableDB_=new Blockly.Names(Blockly.Python.RESERVED_WORDS_);
- var b=Blockly.Python.StaticTyping.collectVarsWithTypes(a);Blockly.Python.StaticTyping.setProcedureArgs(a,b);for(var c in b)"array"!=Blockly.Python.getArduinoType_(b[c])&&Blockly.Python.addVariable(c,Blockly.Python.getArduinoType_(b[c])+" "+Blockly.Python.variableDB_.getName(c,Blockly.Variables.NAME_TYPE)+";")};
- Blockly.Python.finish=function(a){var b=[],c=[],d=[],e=[],f;for(f in Blockly.Python.includes_)b.push(Blockly.Python.includes_[f]);b.length&&b.push("\n");for(f in Blockly.Python.variables_)d.push(Blockly.Python.variables_[f]);d.length&&d.push("\n");for(f in Blockly.Python.definitions_)c.push(Blockly.Python.definitions_[f]);c.length&&c.push("\n");for(f in Blockly.Python.codeFunctions_)e.push(Blockly.Python.codeFunctions_[f]);for(f in Blockly.Python.userFunctions_)e.push(Blockly.Python.userFunctions_[f]);
- e.length&&e.push("\n");var g=[""],h="";void 0!==Blockly.Python.setups_.userSetupCode&&(h="\n"+Blockly.Python.setups_.userSetupCode,delete Blockly.Python.setups_.userSetupCode);for(f in Blockly.Python.setups_)g.push(Blockly.Python.setups_[f]);h&&g.push(h);delete Blockly.Python.includes_;delete Blockly.Python.definitions_;delete Blockly.Python.codeFunctions_;delete Blockly.Python.userFunctions_;delete Blockly.Python.functionNames_;delete Blockly.Python.setups_;delete Blockly.Python.pins_;Blockly.Python.variableDB_.reset();
- b=b.join("\n")+d.join("\n")+c.join("\n");g="void setup() {"+g.join("\n ")+"\n}\n\n";a="void loop() {\n "+a.replace(/\n/g,"\n ")+"\n}\n\n";return b+g+a+e.join("\n")};Blockly.Python.addInclude=function(a,b){void 0===Blockly.Python.includes_[a]&&(Blockly.Python.includes_[a]=b)};Blockly.Python.addDeclaration=function(a,b){void 0===Blockly.Python.definitions_[a]&&(Blockly.Python.definitions_[a]=b)};
- Blockly.Python.addVariable=function(a,b,c){var d=!1;if(c||void 0===Blockly.Python.variables_[a])Blockly.Python.variables_[a]=b,d=!0;return d};Blockly.Python.addSetup=function(a,b,c){var d=!1;if(c||void 0===Blockly.Python.setups_[a])Blockly.Python.setups_[a]=b,d=!0;return d};
- Blockly.Python.addFunction=function(a,b){if(void 0===Blockly.Python.codeFunctions_[a]){var c=Blockly.Python.variableDB_.getDistinctName(a,Blockly.Generator.NAME_TYPE);Blockly.Python.codeFunctions_[a]=b.replace(Blockly.Python.DEF_FUNC_NAME,c);Blockly.Python.functionNames_[a]=c}return Blockly.Python.functionNames_[a]};
- Blockly.Python.reservePin=function(a,b,c,d){void 0!==Blockly.Python.pins_[b]?Blockly.Python.pins_[b]!=c?a.setWarningText(Blockly.Msg.ARD_PIN_WARN1.replace("%1",b).replace("%2",d).replace("%3",c).replace("%4",Blockly.Python.pins_[b]),d):a.setWarningText(null,d):(Blockly.Python.pins_[b]=c,a.setWarningText(null,d))};Blockly.Python.scrubNakedValue=function(a){return a+";\n"};
- Blockly.Python.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/\$/g,"\\$").replace(/'/g,"\\'");return'"'+a+'"'};
- Blockly.Python.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.Python.getArduinoType_=function(a){switch(a.typeId){case Blockly.Types.SHORT_NUMBER.typeId:return"short";case Blockly.Types.NUMBER.typeId:return"int";case Blockly.Types.LARGE_NUMBER.typeId:return"long";case Blockly.Types.DECIMAL.typeId:return"float";case Blockly.Types.TEXT.typeId:return"String";case Blockly.Types.CHARACTER.typeId:return"char";case Blockly.Types.BOOLEAN.typeId:return"boolean";case Blockly.Types.NULL.typeId:return"void";case Blockly.Types.UNDEF.typeId:return"undefined";case Blockly.Types.CHILD_BLOCK_MISSING.typeId:return"int";
- case Blockly.Types.ARRAY.typeId:return"array";default:return"Invalid Blockly Type"}};Blockly.Python.noGeneratorCodeInline=function(){return["",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.noGeneratorCodeLine=function(){return""};Blockly.Python.basic101={};Blockly.Python.read_button=function(a){a=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("basic101_setup_button"+a,"pinMode("+a+", INPUT);");return["digitalRead("+a+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.basic101_dropdown_button=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.read_knob=function(a){a=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("basic101_setup_knob"+a,"pinMode("+a+", INPUT);");return["analogRead("+a+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.basic101_dropdown_knob=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.analog_light=function(a){var b=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BRIGHTNESS",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("basic101_setup_led"+b,"pinMode("+b+", OUTPUT);\n",!1);return"analogWrite("+b+", "+a+");\n"};Blockly.Python.basic101_dropdown_analog_light=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.digital_light=function(a){a=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("basic101_setup_led"+a,"pinMode("+a+", OUTPUT);\n",!1);return"digitalWrite("+a+", HIGH);\n"};Blockly.Python.basic101_dropdown_digital_light=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.nolight=function(a){a=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("basic101_setup_led"+a,"pinMode("+a+", OUTPUT);\n",!1);return"digitalWrite("+a+", LOW);\n"};Blockly.Python.basic101_dropdown_nolight=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.tone=function(a){var b=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"FREQUENCY",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("basic101_setup_tone"+b,"pinMode("+b+", OUTPUT);\n",!1);return"tone("+b+","+a+");\n"};Blockly.Python.basic101_dropdown_tone=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.notone=function(a){a=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("io_"+a,"pinMode("+a+", OUTPUT);\n",!1);return"noTone("+a+");\n"};Blockly.Python.basic101_dropdown_notone=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.io_dropdown_digital=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.io_dropdown_analog=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.io_dropdown_pwm=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.counter_button_setup=function(a){a=a.getFieldValue("PINSNUM");Blockly.Python.addSetup("basic101_setup_button"+a,"pinMode("+a+", INPUT);");Blockly.Python.addDeclaration("basic101_declaration_counter","int counter = 0;\n int triggle = 0;\n");return" int signal = digitalRead("+a+");\n if ((triggle == 0) && (signal==1)) {\n counter++;\n triggle=1;\n }\n if ((triggle == 1) && (signal==0)) {\n triggle=0;\n }\n"};
- Blockly.Python.read_counter=function(a){a=Blockly.Python.valueToCode(a,"PINSNUM",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("basic101_setup_button"+a,"pinMode("+a+", INPUT);");return["counter",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.basic101_counter_dropdown_button=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.bluetooth={};
- Blockly.Python.bluetooth_setup=function(a){var b=a.getFieldValue("BAUD");Blockly.Python.addSetup("bluetooth_serial_begin","Serial1.begin("+b+");",!1);b=Blockly.Python.statementToCode(a,"RECEIVED_DO");var c=a.getFieldValue("OPTIONS"),d=Blockly.Python.variableDB_.getName(a.getFieldValue("CMDVAR"),Blockly.Variables.NAME_TYPE),e="";if("string"===c)e="while (Serial1.available()) {\n delay(10);\n char c = Serial1.read();\n "+d+" += c;\n}\n"+b+"\n"+d+' = "";\n';else if("number"===c)e="if (Serial1.available() > 0) {\n "+
- d+" = Serial1.read();\n}\n"+b;else if("array"===c){a=a.getFieldValue("LENGTH");c="{";for(e=0;e<a-1;e++)c+="0,";Blockly.Python.addDeclaration("bluetooth_list","int "+d+"["+a+"] = "+(c+"0};\n"));e="int n = sizeof("+d+")/sizeof("+d+"[0]);\nwhile (Serial1.available() < n) { }\nfor (int b_n = 0; b_n < n; b_n++) {\n "+d+"[b_n] = Serial1.read();\n}\n"+b}return e};
- Blockly.Python.bluetooth_text_getCommand=function(a){return[Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.bluetooth_number_getCommand=function(a){return[Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.bluetooth_list_getCommand=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);a=a.getFieldValue("INDEX");return[b+"["+a+"]",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.bluetooth_intercomms_send=function(a){a=a.getFieldValue("BAUD");Blockly.Python.addDeclaration("BT_Serial_sendState","int BTserialSendState = 0;");Blockly.Python.addSetup("serial1","Serial1.begin("+a+");");Blockly.Python.addFunction("BTSerialSendData","void BTserialSendData() {\n int BTserialDataLength = BTserialDataPackage().length() + 1;\n char BTserialDataBuf[BTserialDataLength];\n BTserialDataPackage().toCharArray(BTserialDataBuf, BTserialDataLength);\n if ( BTserialSendState == 0 ) {\n Serial1.write(BTserialDataBuf);\n }\n if ( (millis() / 100) % 4 == 3 && BTserialSendState == 0) {\n Serial1.write(BTserialDataBuf);\n BTserialSendState = 1;\n } else if ( (millis() / 100) % 4 == 1) {\n BTserialSendState = 0;\n }\n}\n");for(var b=
- 'String BTserialDataPackage() { \n String data = "";\n data += "SOF";\n',c=0;c<this.itemCount_;c++)a=Blockly.Python.valueToCode(this,"ADD"+c,Blockly.Python.ORDER_NONE)||"0",b+=' data += "|";\n data += '+a+";\n";Blockly.Python.addFunction("BTSerialDataPackage",b+' data += "|";\n data += "\\r\\n";\n return data;\n}\n');return"BTserialSendData();\n"};
- Blockly.Python.bluetooth_intercomms_receive=function(a){var b=a.getFieldValue("BAUD");a=a.getFieldValue("TIMEOUT");Blockly.Python.addSetup("serial1_trans","Serial1.begin("+b+");\n Serial1.setTimeout("+a+");");Blockly.Python.addDeclaration("BTserialDataReceived","String BTserialDataReceived;\n");Blockly.Python.addFunction("BTserialDataFilter",'int BTserialDataFilter() {\n if (Serial1.available() > 0) {\n BTserialDataReceived = Serial1.readStringUntil("\\r\\n");\n }\n if (BTgetSerialDataValue(BTserialDataReceived, \'|\', 0) == "SOF") {\n return 1;\n } else {\n return 0;\n }\n}\n');
- Blockly.Python.addFunction("BTgetSerialDataValue",'String BTgetSerialDataValue(String data, char separator, int index)\n{\n int found = 0;\n int strIndex[] = {0, -1};\n int maxIndex = data.length() - 1;\n for (int i = 0; i <= maxIndex && found <= index; i++) {\n if (data.charAt(i) == separator || i == maxIndex) {\n found++;\n strIndex[0] = strIndex[1] + 1;\n strIndex[1] = (i == maxIndex) ? i + 1 : i;\n }\n }\n return found > index ? data.substring(strIndex[0], strIndex[1]) : "";\n}\n');
- return'boolean BTserialReceiveCheck_ = BTserialDataFilter();\nif (!BTserialReceiveCheck_) {\n Serial.println("Error receiving data from Bluetooth Module.");\n return;\n }\n'};Blockly.Python.bluetooth_intercomms_receive_getData=function(a){var b=parseInt(a.getFieldValue("INDEX"))+1;a=a.getFieldValue("TYPE");return["BTgetSerialDataValue(BTserialDataReceived, '|', "+b+")"+a,Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.bluetooth_intercomms_send_old=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");var b=a.getFieldValue("BAUD");Blockly.Python.addSetup("mainwifi_setup","Serial1.begin("+b+");");b=a.itemCount_;for(var c=b+"+2",d="unsigned char DataOut_["+c+"];\nDataOut_[0] = SOP;\n",e=1;e<b+1;e++){var f=Blockly.Python.valueToCode(a,"ADD"+(e-1),Blockly.Python.ORDER_ATOMIC)||0;d+="DataOut_["+e+"] = "+f+";\n"}return d+("DataOut_["+b+"+1] = EOP;\nSerial1.write(DataOut_, "+
- c+");\ndelay(50);\n")};
- Blockly.Python.bluetooth_intercomms_receive_old=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");var b=a.getFieldValue("LENGTH");a=a.getFieldValue("BAUD");Blockly.Python.addSetup("mainwifi_setup","Serial1.begin("+a+");");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");Blockly.Python.addDeclaration("BT_interCommms_receive","int BTIC_receive["+b+"] = {0};");Blockly.Python.addFunction("mainwifi_dataIn_function",
- "int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+b+")&&started&&(!ended)) {\n BTIC_receive[index_i] = inChar;\n index_i++;\n }\n }\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");return"boolean receiveMsgsuccess_ = handleDataIn();\n"};
- Blockly.Python.bluetooth_intercomms_receive_getData_old=function(a){return["BTIC_receive["+a.getFieldValue("INDEX")+"]",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.bluetooth_at_slave=function(a){a=a.getFieldValue("BAUD");Blockly.Python.addDeclaration("BT_at_slave_decl","int bluetoothATModeserialSendState = 0;\nchar c = ' ';\n");Blockly.Python.addSetup("BT_at_slave_setup"," Serial.begin("+a+");\n Serial1.begin(38400);\n");Blockly.Python.addFunction("BT_at_slave_func","void bluetoothATModeInteractive() {\n while (Serial1.available() > 0) {\n c = Serial1.read();\n Serial.write(c);\n }\n while (Serial.available() > 0) {\n c = Serial.read();\n Serial1.write(c);\n }\n}\n");return' bluetoothATModeInteractive();\n // Slave\n if ( (millis() / 1000) % 50 == 5 && bluetoothATModeserialSendState == 0) {\n Serial.println(" ____ _ _ _ _ ");\n Serial.println(" | __ ) | | _ _ ___ | |_ ___ ___ | |_ | |__ ");\n Serial.println(" | _ \\ | | | | | | / _ \\ | __| / _ \\ / _ \\ | __| | \'_ \\ ");\n Serial.println(" | |_) | | | | |_| | | __/ | |_ | (_) | | (_) | | |_ | | | |");\n Serial.println(" |____/ |_| \\__,_| \\___| \\__| \\___/ \\___/ \\__| |_| |_|");\n Serial.println("");\n Serial.println(" ____ _ ");\n Serial.println(" / ___| | | __ _ __ __ ___ ");\n Serial.println(" \\___ \\ | | / _` | \\ \\ / / / _ ");\n Serial.println(" ___) | | | | (_| | \\ V / | __/");\n Serial.println(" |____/ |_| \\__,_| \\_/ \\___|");\n Serial.println("");\n Serial.println("");\n Serial.println("1. Testing communication:");\n Serial.print("- ");\n Serial1.write("AT\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 6) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 7 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("2. Reset previous configuration:");\n Serial.print("- ");\n Serial1.write("AT+ORGL\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 8) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 10 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("3. Set up UART configuration: AT+UART='+
- a+',0,0");\n Serial.print("- ");\n Serial1.write("AT+UART='+a+',0,0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 11) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 13 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("4. Set up pairing mode, prevent outside connection: AT+CMODE=0");\n Serial.print("- ");\n Serial1.write("AT+CMODE=0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 14) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 16 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("5. Set up pairing mode, set as Slave Mode: AT+ROLE=0");\n Serial.print("- ");\n Serial1.write("AT+ROLE=0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 17) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 18 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("6. Getting MAC address:");\n Serial.print("- ");\n Serial1.write("AT+ADDR\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 19) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 21 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("7. Done, reset bluetooth module to normal state.");\n Serial.print("- ");\n Serial1.write("AT+RESET\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 22) {\n bluetoothATModeserialSendState = 0;\n }\n'};
- Blockly.Python.bluetooth_at_master=function(a){var b=a.getFieldValue("BAUD");a=a.getFieldValue("ADDR").replace(/:/g,",");Blockly.Python.addDeclaration("BT_at_master_decl","int bluetoothATModeserialSendState = 0;\nchar c = ' ';\n");Blockly.Python.addSetup("BT_at_master_setup"," Serial.begin("+b+");\n Serial1.begin(38400);\n");Blockly.Python.addFunction("BT_at_master_fun","void bluetoothATModeInteractive() {\n while (Serial1.available() > 0) {\n c = Serial1.read();\n Serial.write(c);\n }\n while (Serial.available() > 0) {\n c = Serial.read();\n Serial1.write(c);\n }\n}\n");
- return' bluetoothATModeInteractive();\n // Master\n if ( (millis() / 1000) % 50 == 5 && bluetoothATModeserialSendState == 0) {\n Serial.println(" ____ _ _ _ _ ");\n Serial.println(" | __ ) | | _ _ ___ | |_ ___ ___ | |_ | |__ ");\n Serial.println(" | _ \\ | | | | | | / _ \\ | __| / _ \\ / _ \\ | __| | \'_ \\ ");\n Serial.println(" | |_) | | | | |_| | | __/ | |_ | (_) | | (_) | | |_ | | | |");\n Serial.println(" |____/ |_| \\__,_| \\___| \\__| \\___/ \\___/ \\__| |_| |_|");\n Serial.println("");\n Serial.println(" __ __ _ ");\n Serial.println(" | \\/ | __ _ ___ | |_ ___ _ __ ");\n Serial.println(" | |\\/| | / _` | / __| | __| / _ \\ | \'__|");\n Serial.println(" | | | | | (_| | \\__ \\ | |_ | __/ | | ");\n Serial.println(" |_| |_| \\__,_| |___/ \\__| \\___| |_| ");\n Serial.println("");\n Serial.println("");\n Serial.println("1. Testing communication:");\n Serial.print("- ");\n Serial1.write("AT\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 6) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 7 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("2. Reset previous configuration:");\n Serial.print("- ");\n Serial1.write("AT+ORGL\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 8) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 10 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("3. Set up UART configuration: AT+UART='+
- b+',0,0");\n Serial.print("- ");\n Serial1.write("AT+UART='+b+',0,0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 11) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 13 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("4. Set up pairing mode, prevent outside connection: AT+CMODE=0");\n Serial.print("- ");\n Serial1.write("AT+CMODE=0\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 14) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 16 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("5. Set up pairing mode, set as Master Mode: AT+ROLE=1");\n Serial.print("- ");\n Serial1.write("AT+ROLE=1\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 17) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 18 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("6. Binding slave device:");\n Serial.print("- ");\n Serial1.write("AT+BIND='+
- a+'\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 19) {\n bluetoothATModeserialSendState = 0;\n }\n if ( (millis() / 1000) % 50 == 21 && bluetoothATModeserialSendState == 0) {\n Serial.println("");\n Serial.println("7. Done, reset bluetooth module to normal state.");\n Serial.print("- ");\n Serial1.write("AT+RESET\\r\\n");\n bluetoothATModeserialSendState = 1;\n } else if ( (millis() / 1000) % 50 == 22) {\n bluetoothATModeserialSendState = 0;\n }\n'};
- Blockly.Python.bluetooth_at_interaction=function(a){a=a.getFieldValue("bluetooth_at_interaction_baud");Blockly.Python.addDeclaration("bluetooth_at_interaction_declare","char c = ' ';\n");Blockly.Python.addSetup("bluetooth_at_interaction_setup","Serial.begin("+a+");\nSerial1.begin("+a+");\n");Blockly.Python.addFunction("bluetooth_at_interaction_function","void _bluetoothATmode() {\n if (Serial1.available())\n Serial.write(Serial1.read());\n if (Serial.available())\n Serial1.write(Serial.read());\n}\n");
- return"_bluetoothATmode();\n"};Blockly.Python.blynk={};
- Blockly.Python.blynk_setup=function(a){var b=a.getFieldValue("AUTH"),c=a.getFieldValue("SSID");a=a.getFieldValue("PW");Blockly.Python.addDeclaration("blynk_define","#define BLYNK_PRINT Serial\n");Blockly.Python.addInclude("blynk_setup","#include <ESP8266WiFi.h>\n#include <BlynkSimpleEsp8266.h>\n");Blockly.Python.addDeclaration("Blynk_init",'char auth[] = "'+b+'";\nchar ssid[] = "'+c+'";\nchar pass[] = "'+a+'";\n');Blockly.Python.addSetup("Blynk_begin","Blynk.begin(auth,ssid,pass);\n");return"Blynk.run();\n"};
- Blockly.Python.blynk_write=function(a){var b=a.getFieldValue("PIN");a.getFieldValue("MOD");var c="BLYNK_WRITE("+b+")\n{\n";a=Blockly.Python.statementToCode(a,"STATEMENT");Blockly.Python.addFunction("Blynk_Write"+b,c+(a+"\n}\n"));return""};Blockly.Python.blynk_write_getData=function(a){var b=a.getFieldValue("MOD");return["zeRGBa"==b||"Joystick"==b?"param["+a.getFieldValue("SELINDEX")+"].asInt()":"param.asInt()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.blynk_write_getData_joystick=function(a){var b=a.getFieldValue("MOD");return["zeRGBa"==b||"Joystick"==b?"param["+a.getFieldValue("SELINDEX")+"].asInt()":"param.asInt()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.blynk_write_getData_zeRGBa=function(a){var b=a.getFieldValue("MOD");return["zeRGBa"==b||"Joystick"==b?"param["+a.getFieldValue("SELINDEX")+"].asInt()":"param.asInt()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.blynk_write_getData_GraOrAcc=function(a){return["param["+a.getFieldValue("SELINDEX")+"].asFloat()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.blynk_write_getData_GPS=function(a){return["param["+a.getFieldValue("SELINDEX")+"].asFloat()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.blynk_read=function(a){for(var b=a.getFieldValue("PIN"),c="BLYNK_READ("+b+")\n{\n",d=0;d<this.itemCount_;d++){var e=Blockly.Python.valueToCode(this,"ADD"+d,Blockly.Python.ORDER_NONE)||"0";1==a.itemCount_?c+=" Blynk.virtualWrite("+b+","+e+");\n":(c=0==d?c+(" Blynk.virtualWrite("+b+","+e):c+(","+e),d==a.itemCount_-1&&(c+=");\n"))}Blockly.Python.addFunction("Blynk_Read"+b,c+"\n}\n");return""};
- Blockly.Python.blynk_virtualWrite=function(a){for(var b=a.getFieldValue("PIN"),c="",d=0;d<this.itemCount_;d++){var e=Blockly.Python.valueToCode(this,"ADD"+d,Blockly.Python.ORDER_NONE)||"0";1==a.itemCount_?c+="Blynk.virtualWrite("+b+","+e+");\n":(c=0==d?c+("Blynk.virtualWrite("+b+","+e):c+(","+e),d==a.itemCount_-1&&(c+=");\n"))}return c};
- Blockly.Python.blynk_timer=function(a){var b=a.getFieldValue("TIME");a=Blockly.Python.statementToCode(a,"DO");Blockly.Python.addDeclaration("Blynk_timer_dec","BlynkTimer timer;\n");Blockly.Python.addFunction("Blynk_timer_func"+b,"void BF_T"+b+"() {\n"+a+"}\n");Blockly.Python.addSetup("Blynk_timer_setup_"+b,"timer.setInterval("+b+"L, BF_T"+b+");\n");return"timer.run();\n"};
- Blockly.Python.blynk_connect=function(a){a=Blockly.Python.valueToCode(a,"STATEMENT",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addFunction("Blynk_Connect","BLYNK_CONNECT() {\n"+a+"\n}\n");return""};Blockly.Python.blynk_log=function(a){return"BLYNK_LOG() {\n"+Blockly.Python.valueToCode(a,"STATEMENT",Blockly.Python.ORDER_ATOMIC)+"\n}\n"};Blockly.Python.Boards={};Blockly.Python.Boards.generateDigitalIo=function(a,b){for(var c=[],d=a;d<b+1;d++)c.push([d.toString(),d.toString()]);return c};Blockly.Python.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.Python.Boards.duplicateBoardProfile=function(a,b,c,d){return{name:b,description:c||a.description,compilerFlag:d||a.compilerFlag,analogPins:a.analogPins,digitalPins:a.digitalPins,pwmPins:a.pwmPins,serial:a.serial,serialPins:a.serialPins,serialSpeed:a.serialSpeed,spi:a.spi,spiPins:a.spiPins,spiClockDivide:a.spiClockDivide,i2c:a.i2c,i2cPins:a.i2cPins,i2cSpeed:a.i2cSpeed,builtinLed:a.builtinLed,interrupt:a.interrupt}};Blockly.Python.Boards.profiles={};
- Blockly.Python.Boards.profiles.uno={name:"Arduino Uno",description:"Arduino Uno standard compatible board",compilerFlag:"arduino:avr:uno",analogPins:Blockly.Python.Boards.generateAnalogIo(0,5),digitalPins:Blockly.Python.Boards.generateDigitalIo(0,13).concat(Blockly.Python.Boards.generateAnalogIo(0,5)),pwmPins:[["3","3"],["5","5"],["6","6"],["9","9"],["10","10"],["11","11"],["13","13"]],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:{Wire:[["SDA","A4"],["SCL","A5"]]},i2cSpeed:[["100kHz","100000L"],["400kHz","400000L"]],builtinLed:[["BUILTIN_1","13"]],interrupt:[["interrupt0","2"],["interrupt1","3"]]};
- Blockly.Python.Boards.profiles.nano_328={name:"Arduino Nano 328",description:"Arduino Nano with ATmega328 board",compilerFlag:"arduino:avr:nano:cpu=atmega328",analogPins:Blockly.Python.Boards.generateAnalogIo(0,7),digitalPins:Blockly.Python.Boards.generateDigitalIo(0,13).concat(Blockly.Python.Boards.generateAnalogIo(0,7)),pwmPins:Blockly.Python.Boards.profiles.uno.pwmPins,serial:Blockly.Python.Boards.profiles.uno.serial,serialPins:Blockly.Python.Boards.profiles.uno.serialPins,serialSpeed:Blockly.Python.Boards.profiles.uno.serialSpeed,
- spi:Blockly.Python.Boards.profiles.uno.spi,spiPins:Blockly.Python.Boards.profiles.uno.spiPins,spiClockDivide:Blockly.Python.Boards.profiles.uno.spiClockDivide,i2c:Blockly.Python.Boards.profiles.uno.i2c,i2cPins:Blockly.Python.Boards.profiles.uno.i2cPins,i2cSpeed:Blockly.Python.Boards.profiles.uno.i2cSpeed,builtinLed:Blockly.Python.Boards.profiles.uno.builtinLed,interrupt:Blockly.Python.Boards.profiles.uno.interrupt};
- Blockly.Python.Boards.profiles.nano_168=Blockly.Python.Boards.duplicateBoardProfile(Blockly.Python.Boards.profiles.nano_328,"Arduino Nano 168","Arduino Nano with ATmega168 compatible board","arduino:avr:nano:cpu=atmega168");
- Blockly.Python.Boards.profiles.duemilanove_168p={name:"Arduino Nano 168p",description:"Arduino Duemilanove with ATmega168p compatible board",compilerFlag:"arduino:avr:diecimila:cpu=atmega168",analogPins:Blockly.Python.Boards.profiles.uno.analogPins,digitalPins:Blockly.Python.Boards.profiles.uno.digitalPins,pwmPins:Blockly.Python.Boards.profiles.uno.pwmPins,serial:Blockly.Python.Boards.profiles.uno.serial,serialPins:Blockly.Python.Boards.profiles.uno.serialPins,serialSpeed:Blockly.Python.Boards.profiles.uno.serialSpeed,
- spi:Blockly.Python.Boards.profiles.uno.spi,spiPins:Blockly.Python.Boards.profiles.uno.spiPins,spiClockDivide:Blockly.Python.Boards.profiles.uno.spiClockDivide,i2c:Blockly.Python.Boards.profiles.uno.i2c,i2cPins:Blockly.Python.Boards.profiles.uno.i2cPins,i2cSpeed:Blockly.Python.Boards.profiles.uno.i2cSpeed,builtinLed:Blockly.Python.Boards.profiles.uno.builtinLed,interrupt:Blockly.Python.Boards.profiles.uno.interrupt};
- Blockly.Python.Boards.profiles.duemilanove_328p=Blockly.Python.Boards.duplicateBoardProfile(Blockly.Python.Boards.profiles.duemilanove_168p,"Arduino Duemilanove 328p","Arduino Duemilanove with ATmega328p compatible board","arduino:avr:diecimila");
- Blockly.Python.Boards.profiles.mega={name:"Arduino Mega",description:"Arduino Mega-compatible board",compilerFlag:"arduino:avr:mega",analogPins:Blockly.Python.Boards.generateAnalogIo(0,15),digitalPins:Blockly.Python.Boards.generateDigitalIo(0,53),pwmPins:Blockly.Python.Boards.generateDigitalIo(2,13).concat(Blockly.Python.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.Python.Boards.profiles.uno.serialSpeed,spi:[["SPI","SPI"]],spiPins:{SPI:[["MOSI","51"],["MISO","50"],["SCK","52"]]},spiClockDivide:Blockly.Python.Boards.profiles.uno.spiClockDivide,i2c:[["I2C","Wire"]],i2cPins:{Wire:[["SDA","20"],["SCL","21"]]},i2cSpeed:[["100kHz","100000L"],["400kHz","400000L"]],builtinLed:Blockly.Python.Boards.profiles.uno.builtinLed,interrupt:[["interrupt0","2"],["interrupt1",
- "3"],["interrupt2","21"],["interrupt3","20"],["interrupt4","19"],["interrupt5","18"]]};
- Blockly.Python.Boards.profiles.leonardo={name:"Arduino Leonardo",description:"Arduino Leonardo-compatible board",compilerFlag:"arduino:avr:leonardo",analogPins:Blockly.Python.Boards.generateAnalogIo(0,7),digitalPins:Blockly.Python.Boards.generateDigitalIo(0,13),pwmPins:Blockly.Python.Boards.profiles.uno.pwmPins,serial:Blockly.Python.Boards.profiles.uno.serial,serialPins:Blockly.Python.Boards.profiles.uno.serialPins,serialSpeed:Blockly.Python.Boards.profiles.uno.serialSpeed,spi:[["SPI","SPI"]],spiPins:{SPI:[["MOSI",
- "ICSP-4"],["MISO","ICSP-1"],["SCK","ICSP-3"]]},spiClockDivide:Blockly.Python.Boards.profiles.uno.spiClockDivide,i2c:[["I2C","Wire"]],i2cPins:{Wire:[["SDA","2"],["SCL","3"]]},i2cSpeed:Blockly.Python.Boards.profiles.uno.i2cSpeed,builtinLed:Blockly.Python.Boards.profiles.uno.builtinLed,interrupt:[["interrupt0","3"],["interrupt1","2"],["interrupt2","0"],["interrupt3","1"],["interrupt4","17"]]};
- Blockly.Python.Boards.profiles.yun=Blockly.Python.Boards.duplicateBoardProfile(Blockly.Python.Boards.profiles.leonardo,"Arduino Yun","Arduino Yun compatible board");
- Blockly.Python.Boards.profiles.atmel_atmega328p_xplained_mini={name:"Atmel atmega328p Xplained mini",description:"Atmel Xplained mini board with atmega328p (Uno compatible)",compilerFlag:"atmel:avr:atmega328p_xplained_mini",analogPins:Blockly.Python.Boards.profiles.uno.analogPins,digitalPins:Blockly.Python.Boards.profiles.uno.digitalPins.concat([["20","20"]]),pwmPins:Blockly.Python.Boards.profiles.uno.pwmPins,serial:Blockly.Python.Boards.profiles.uno.serial,serialPins:Blockly.Python.Boards.profiles.uno.serialPins,
- serialSpeed:Blockly.Python.Boards.profiles.uno.serialSpeed,spi:Blockly.Python.Boards.profiles.uno.spi,spiPins:Blockly.Python.Boards.profiles.uno.spiPins,spiClockDivide:Blockly.Python.Boards.profiles.uno.spiClockDivide,i2c:Blockly.Python.Boards.profiles.uno.i2c,i2cPins:Blockly.Python.Boards.profiles.uno.i2cPins,i2cSpeed:Blockly.Python.Boards.profiles.uno.i2cSpeed,builtinLed:[["BUILTIN_LED","13"]],interrupt:Blockly.Python.Boards.profiles.uno.interrupt,builtinButton:[["BUILTIN_BUTTON","20"]]};
- Blockly.Python.Boards.profiles.atmel_atmega328pb_xplained_mini=Blockly.Python.Boards.duplicateBoardProfile(Blockly.Python.Boards.profiles.atmel_atmega328p_xplained_mini,"Atmel atmega328pb Xplained mini","Atmel Xplained mini board with atmega328pb (Arduino Uno compatible)","atmel:avr:atmega328pb_xplained_mini");
- Blockly.Python.Boards.profiles.atmel_atmega168pb_xplained_mini=Blockly.Python.Boards.duplicateBoardProfile(Blockly.Python.Boards.profiles.atmel_atmega328p_xplained_mini,"Atmel atmega168pb Xplained mini","Atmel Xplained mini board with atmega168pb (Arduino Uno compatible)","atmel:avr:atmega168pb_xplained_mini");
- Blockly.Python.Boards.profiles.esp8266_huzzah={name:"Adafruit Feather HUZZAH",description:"Adafruit HUZZAH ESP8266 compatible board",compilerFlag:"esp8266:esp8266:generic",analogPins:[["A0","A0"]],digitalPins:[["0","0"],["2","2"],["4","4"],["5","5"],["12","12"],["13","13"],["14","14"],["15","15"],["16","16"]],pwmPins:[["2","2"]],serial:[["serial","Serial"]],serialPins:{Serial:[["RX","RX"],["TX","TX"]]},serialSpeed:Blockly.Python.Boards.profiles.uno.serial,spi:[["SPI","SPI"]],spiPins:{SPI:[["MOSI",
- "13"],["MISO","12"],["SCK","14"]]},spiClockDivide:Blockly.Python.Boards.profiles.uno.spiClockDivide,i2c:[["I2C","Wire"]],i2cPins:{Wire:[["SDA","4"],["SCL","5"]]},i2cSpeed:Blockly.Python.Boards.profiles.uno.i2cSpeed,builtinLed:[["BUILTIN_1","0"]],interrupt:[["interrupt0","2"],["interrupt1","3"]]};
- Blockly.Python.Boards.profiles.esp8266_wemos_d1={name:"Wemos D1",description:"Wemos D1 R2 compatible board",compilerFlag:"esp8266:esp8266:generic",analogPins:[["A0","A0"]],digitalPins:[["D0","D0"],["D1","D1"],["D2","D2"],["D3","D3"],["D4","D4"],["D5","D5"],["D6","D7"],["D8","D8"]],pwmPins:[["D1","D1"],["D2","D2"],["D3","D3"],["D4","D4"],["D5","D5"],["D6","D7"],["D8","D8"]],serial:[["serial","Serial"]],serialPins:{Serial:[["RX","RX"],["TX","TX"]]},serialSpeed:Blockly.Python.Boards.profiles.uno.serialSpeed,
- spi:[["SPI","SPI"]],spiPins:{SPI:[["MOSI","D7"],["MISO","D6"],["SCK","D5"]]},spiClockDivide:Blockly.Python.Boards.profiles.uno.spiClockDivide,i2c:[["I2C","Wire"]],i2cPins:{Wire:[["SDA","D2"],["SCL","D1"]]},i2cSpeed:Blockly.Python.Boards.profiles.uno.i2cSpeed,builtinLed:[["BUILTIN_1","D4"]],interrupt:[["D0","D0"],["D1","D1"],["D2","D2"],["D3","D3"],["D4","D4"],["D5","D5"],["D6","D7"],["D8","D8"]]};Blockly.Python.Boards.selected=Blockly.Python.Boards.profiles.leonardo;
- Blockly.Python.Boards.changeBoard=function(a,b){if(void 0===Blockly.Python.Boards.profiles[b])console.log("Tried to set non-existing Arduino board: "+b);else{Blockly.Python.Boards.selected=Blockly.Python.Boards.profiles[b];for(var c=a.getAllBlocks(),d=0;d<c.length;d++){var e=c[d].updateFields;e&&e.call(c[d])}}};
- Blockly.Python.Boards.refreshBlockFieldDropdown=function(a,b,c){var d=a.getField(b);b=d.getValue();c=Blockly.Python.Boards.selected[c];d.menuGenerator_=c;d=!1;for(var 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")};Blockly.Python.color={};function hexToRgb(a){a=(a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a))?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:null;return"("+a.r+", "+a.g+", "+a.b+")"}function sharpTo0x(a){return(a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a))?"0x"+a[1]+a[2]+a[3]:null}
- function sharpTo565(a){var b="#"==a[0]?(a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a))?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:null:(a=/([0-9]{0,3}),([0-9]{0,3}),([0-9]{0,3})/g.exec(a))?{r:a[1],g:a[2],b:a[3]}:null;b=2048*(b.r>>3)+32*(b.g>>2)+(b.b>>3);b=b.toString(16);if(4>b.length)for(;4>b.length;)b="0"+b;return a?"0x"+b:null}
- Blockly.Python.color_analyzer_setup=function(a){Blockly.Python.addInclude("wire.h","#include <Wire.h>\n");Blockly.Python.addInclude("colorAnalyzeDef",'#include "Adafruit_TCS34725.h"\n\nAdafruit_TCS34725 tcs = Adafruit_TCS34725();\n');Blockly.Python.addSetup("colorAnalyzeSetup","tcs.begin();\n");Blockly.Python.addDeclaration("Color_analyzer_colors","uint16_t red, green, blue, c;\n");return"tcs.getRawData(&red, &green, &blue, &c);\nred = red*256/c;\ngreen = green*256/c;\nblue = blue*256/c;\nif (red > 255) red = 255;\nif (green > 255) green = 255;\nif (blue > 255) blue = 255;\n"};
- Blockly.Python.set_color=function(a){return[a.getFieldValue("COLOR"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.read_r=function(a){return["red",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.read_g=function(a){return["green",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.read_b=function(a){return["blue",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.set_colorRGB=function(a){var b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return["("+b+","+c+","+a+")",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.isColorRGB=function(a){a=a.getFieldValue("COLOR")||"r";var b="int isColorRGB_"+a+"() {\n";switch(a){case "r":b+=" if (red >= 200 && green <= 50 && blue <= 50)\n return 1;\n else\n return 0;\n";break;case "g":b+=" if (green >= 200 && red <= 50 && blue <= 50)\n return 1;\n else\n return 0;\n";break;case "b":b+=" if (blue >= 200 && green <= 50 && red <= 50)\n return 1;\n else\n return 0;\n"}Blockly.Python.addFunction("isColor_"+a,b+"}\n");return["isColorRGB_"+
- a+"()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.colour={};Blockly.Python.colour_picker=Blockly.Python.noGeneratorCodeInline;Blockly.Python.colour_random=Blockly.Python.noGeneratorCodeInline;Blockly.Python.colour_rgb=Blockly.Python.noGeneratorCodeInline;Blockly.Python.colour_blend=Blockly.Python.noGeneratorCodeInline;Blockly.Python.define={};Blockly.Python.define=function(a){var b=Blockly.Python.valueToCode(a,"define_init",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"define_variable",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("define_init","#define\t"+b+"\t"+a,!1);return""};Blockly.Python.define_var=function(a){Blockly.Python.valueToCode(a,"define_variable",Blockly.Python.ORDER_ATOMIC);return["",Blockly.Python.ORDER_NONE]};Blockly.Python.env={};Blockly.Python.env_init=function(a){Blockly.Python.addDeclaration("env_init_",'#include "DHT.h"\n #define DHTTYPE DHT11\n');Blockly.Python.addSetup("env_init_2",'Serial.println("DHTxx test!"); \n');return""};
- Blockly.Python.iot_read_val=function(a){a=a.getFieldValue("val_type");"mic"==a?(Blockly.Python.addDeclaration("iot_mic_decl","#define PIN_MIC A2\n"),Blockly.Python.addSetup("iot_mic_setup","pinMode(PIN_MIC, INPUT);"),a="analogRead(PIN_MIC)"):"light"==a?(Blockly.Python.addDeclaration("iot_light_decl","#define PIN_LIGHT A1\n"),Blockly.Python.addSetup("iot_light_setup","pinMode(PIN_LIGHT, INPUT);"),a="analogRead(PIN_LIGHT)"):a="dht.readHumidity()";return[a,Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.iot_read_mic=function(a){a=a.getFieldValue("env_sensor_mic");Blockly.Python.addDeclaration("iot_mic_decl","#define PIN_MIC "+a);Blockly.Python.addSetup("iot_mic_setup","pinMode(PIN_MIC, INPUT);");return["analogRead(PIN_MIC)",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.iot_read_light=function(a){a=a.getFieldValue("env_sensor_light");Blockly.Python.addDeclaration("iot_light_decl","#define PIN_LIGHT "+a);Blockly.Python.addSetup("iot_light_setup","pinMode(PIN_LIGHT, INPUT);");return["analogRead(PIN_LIGHT)",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.iot_read_humid=function(a){a=a.getFieldValue("env_sensor_humid");Blockly.Python.addDeclaration("humid_temp_init","#define DHTPIN "+a+"\nDHT dht(DHTPIN, DHTTYPE);\n");Blockly.Python.addSetup("humid_temp_setup","dht.begin();\n");return["dht.readHumidity()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.iot_read_temp=function(a){var b=a.getFieldValue("env_sensor_temp");Blockly.Python.addDeclaration("humid_temp_init","#define DHTPIN "+b+"\nDHT dht(DHTPIN, DHTTYPE);\n");Blockly.Python.addSetup("humid_temp_setup","dht.begin();\n");b="dht.readTemperature(";b="c"==a.getFieldValue("temp_unit")?b+")":b+"true)";return[b,Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.iot_buzzer=function(a){var b=a.getFieldValue("PINSNUM");a=Blockly.Python.valueToCode(a,"FREQUENCY",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addSetup("iot_buzzer_"+b,"pinMode("+b+", OUTPUT);\n",!1);return"tone("+b+","+a+");\n"};Blockly.Python.iot_nobuzzer=function(a){a=a.getFieldValue("PINSNUM");Blockly.Python.addSetup("iot_buzzer_"+a,"pinMode("+a+", OUTPUT);\n",!1);return"noTone("+a+");\n"};
- Blockly.Python.iot_set_rgb=function(a){var b=a.getFieldValue("env_sensor_rgbPin_r"),c=a.getFieldValue("env_sensor_rgbPin_g"),d=a.getFieldValue("env_sensor_rgbPin_b");Blockly.Python.addDeclaration("pin_rgb","int redPin = "+b+";\n int greenPin = "+c+";\n int bluePin = "+d+";");Blockly.Python.addSetup("setup_rgb","pinMode(redPin, OUTPUT);\npinMode(greenPin, OUTPUT);\n pinMode(bluePin, OUTPUT);\nsetColor(0,0,0);\n");Blockly.Python.addFunction("setcolor_rgb","void setColor(int red, int green, int blue)\n{\n red = 255 - red;\n green = 255 - green;\n blue = 255 - blue;\n analogWrite(redPin, red);\n analogWrite(greenPin, green);\n analogWrite(bluePin, blue);\n}\n");
- b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC);c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return"setColor("+b+","+c+","+a+");"};Blockly.Python.hci={};Blockly.Python.HID_setup=function(a){Blockly.Python.addInclude("keyboard",'#include "Keyboard.h"');Blockly.Python.addInclude("Mouse",'#include "Mouse.h"');Blockly.Python.addSetup("HID","Mouse.begin();\nKeyboard.begin();\n");return""};
- Blockly.Python.HID_mouse_move=function(a){var b="",c=a.getFieldValue("mouse_towards");a=a.getFieldValue("mouse_distance");switch(c){case "KEYPAD_UP":b="Mouse.move(0, -"+a+");\n";break;case "KEYPAD_DOWN":b="Mouse.move(0, "+a+");\n";break;case "KEYPAD_LEFT":b="Mouse.move(-"+a+", 0);\n";break;case "KEYPAD_RIGHT":b="Mouse.move("+a+", 0);\n"}return b};Blockly.Python.HID_mouse_click=function(a){return"Mouse.click("+a.getFieldValue("CLICK")+");\n"};
- Blockly.Python.HID_mouse_press=function(a){return"Mouse.press("+a.getFieldValue("CLICK")+");\n"};Blockly.Python.HID_mouse_release=function(a){return"Mouse.release("+a.getFieldValue("CLICK")+");\n"};Blockly.Python.HID_keyboard_press=function(a){return"Keyboard.press("+a.getFieldValue("keyboard_press")+");\n"};Blockly.Python.HID_keyboard_release=function(a){return"Keyboard.release("+a.getFieldValue("keyboard_press")+");\n"};Blockly.Python.HID_keyboard_releaseAll=function(a){return"Keyboard.releaseAll();\n"};Blockly.Python.IO={};Blockly.Python.io_digitalwrite=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"1",c=Blockly.Python.valueToCode(a,"STATE",Blockly.Python.ORDER_ATOMIC)||"LOW";Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"Digital Write");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);return"digitalWrite("+b+", "+c+");\n"};
- Blockly.Python.io_digitalread=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"1";Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.INPUT,"Digital Read");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", INPUT);",!1);return["digitalRead("+b+")",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.io_builtin_led=function(a){var b=a.getFieldValue("BUILT_IN_LED"),c=Blockly.Python.valueToCode(a,"STATE",Blockly.Python.ORDER_ATOMIC)||"LOW";Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"Set LED");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);return"digitalWrite("+b+", "+c+");\n"};
- Blockly.Python.io_analogwrite=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"0",c=Blockly.Python.valueToCode(a,"ANALOGNUM",Blockly.Python.ORDER_ATOMIC)||"0";var d=/A[0-9]/g.test(b);var e="";d?(Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"Analogue Write"),Blockly.Python.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1)):(Blockly.Python.addDeclaration("io_analogPinList","const int analogPIN[8]={A0,A1,A2,A3,A4,A5,A6,A7};"),Blockly.Python.addSetup("io_A0",
- "pinMode(A0, OUTPUT);"),Blockly.Python.addSetup("io_A1","pinMode(A1, OUTPUT);"),Blockly.Python.addSetup("io_A2","pinMode(A2, OUTPUT);"),Blockly.Python.addSetup("io_A3","pinMode(A3, OUTPUT);"),Blockly.Python.addSetup("io_A4","pinMode(A4, OUTPUT);"),Blockly.Python.addSetup("io_A5","pinMode(A5, OUTPUT);"),Blockly.Python.addSetup("io_A6","pinMode(A6, OUTPUT);"),Blockly.Python.addSetup("io_A7","pinMode(A7, OUTPUT);"),e="analogPIN["+b+"]");0>c||255<c?a.setWarningText("The analogue value set must be between 0 and 255",
- "pwm_value"):a.setWarningText(null,"pwm_value");return d?"analogWrite("+b+", "+c+");\n":"analogWrite("+e+", "+c+");\n"};Blockly.Python.io_analogread=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"0";Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.INPUT,"Analogue Read");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", INPUT);",!1);return["analogRead("+b+")",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.io_pwmwrite=function(a){var b=Blockly.Python.valueToCode(a,"PIN",Blockly.Python.ORDER_ATOMIC)||"0",c=Blockly.Python.valueToCode(a,"PWMVALUE",Blockly.Python.ORDER_ATOMIC)||"0";/[0-9]/g.test(b);Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"PWM Write");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", OUTPUT);",!1);return"analogWrite("+b+", "+c+");\n"};Blockly.Python.io_highlow=function(a){return[a.getFieldValue("STATE"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.io_pulsein=function(a){var b=a.getFieldValue("PULSEPIN"),c=Blockly.Python.valueToCode(a,"PULSETYPE",Blockly.Python.ORDER_ATOMIC);Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.INPUT,"Pulse Pin");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", INPUT);\n",!1);return["pulseIn("+b+", "+c+")",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.io_pulsetimeout=function(a){var b=a.getFieldValue("PULSEPIN"),c=Blockly.Python.valueToCode(a,"PULSETYPE",Blockly.Python.ORDER_ATOMIC),d=Blockly.Python.valueToCode(a,"TIMEOUT",Blockly.Python.ORDER_ATOMIC);Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.INPUT,"Pulse Pin");Blockly.Python.addSetup("io_"+b,"pinMode("+b+", INPUT);\n",!1);return["pulseIn("+b+", "+c+", "+d+")",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.io_dropdown_digital=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.io_dropdown_analog=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.io_dropdown_pwm=function(a){return[a.getFieldValue("SELECTPIN"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.led={};var globalBrightness;
- Blockly.Python.led_neopixel_setup=function(a){Blockly.Python.addInclude("Aadafruit_GFX","#include <Adafruit_GFX.h>");Blockly.Python.addInclude("Adafruit_NeoMatrix","#include <Adafruit_NeoMatrix.h>");Blockly.Python.addInclude("Adafruit_NeoPixel","#include <Adafruit_NeoPixel.h>");var b=a.getFieldValue("neopixel_initpin"),c=a.getFieldValue("neopixel_initheight"),d=a.getFieldValue("neopixel_initwidth");a=a.getFieldValue("neopixel_initbright");Blockly.Python.addDeclaration("ledDeclA"+b,"#ifndef PSTR\n #define PSTR\n#endif\n",
- !1);Blockly.Python.addDeclaration("ledDeclB"+b,"#define\tPIN\t"+b,!1);Blockly.Python.addDeclaration("ledDeclC"+b,"Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(5,5,"+d+","+c+", PIN,NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_COLUMNS + NEO_TILE_PROGRESSIVE + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,NEO_GRB + NEO_KHZ800);");Blockly.Python.addSetup("ledSetup"+b,"matrix.begin();\n matrix.setBrightness("+a+");\n");globalBrightness=a;return""};
- Blockly.Python.led_setrotation=function(a){return"matrix.setRotation("+a.getFieldValue("led_setrotation_option")+");\n"};Blockly.Python.led_setbright=function(a){return"matrix.setBrightness("+Blockly.Python.valueToCode(a,"BRIGHTNESS",Blockly.Python.ORDER_ATOMIC)+");\n"};Blockly.Python.led_set_width_height=function(a){var b=Blockly.Python.valueToCode(a,"WIDTH",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"HEIGHT",Blockly.Python.ORDER_ATOMIC);return[b+", "+a,Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.led_set_position=function(a){var b=Blockly.Python.valueToCode(a,"POSX",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSY",Blockly.Python.ORDER_ATOMIC);return[b+", "+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.led_drawpixel=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;return"matrix.drawPixel("+Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC)+",matrix.Color"+b+");\n"};
- Blockly.Python.led_drawrect=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;var c=Blockly.Python.valueToCode(a,"SIZE",Blockly.Python.ORDER_ATOMIC),d=a.getFieldValue("rect_type");a=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);return"matrix."+d+"Rect("+a+","+c+",matrix.Color"+b+");\n"};
- Blockly.Python.led_drawline=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;Blockly.Python.valueToCode(a,"TYPE",Blockly.Python.ORDER_ATOMIC);var c=Blockly.Python.valueToCode(a,"POSA",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSB",Blockly.Python.ORDER_ATOMIC);return"matrix.drawLine("+c+","+a+",matrix.Color"+b+");\n"};
- Blockly.Python.led_showall=function(a){return"matrix.show();\ndelayMicroseconds(500);\nmatrix.setBrightness("+globalBrightness+");\n"};
- Blockly.Python.led_text=function(a){var b=Number(a.getFieldValue("x_val")),c=Number(a.getFieldValue("y_val")),d=hexToRgb(Blockly.Python.valueToCode(a,"text_color",Blockly.Python.ORDER_ATOMIC)),e=hexToRgb(Blockly.Python.valueToCode(a,"back_color",Blockly.Python.ORDER_ATOMIC));a=a.getFieldValue("text_size");return"matrix.setCursor("+b+", "+c+");\nmatrix.setTextColor(matrix.Color"+d+", matrix.Color"+e+");\nmatrix.setTextSize("+a+");\nmatrix.setTextWrap(false);\n"};
- Blockly.Python.led_clear=function(a){Blockly.Python.addFunction("led_clear","void ledClear() {\n matrix.fillScreen(0);\n matrix.show();\n delay(1);\n}\n");return"ledClear();\n"};
- Blockly.Python.led_scrolling_text=function(a){var b=a.getFieldValue("led_scrolling_speed");a=hexToRgb(Blockly.Python.valueToCode(a,"led_scrolling_color",Blockly.Python.ORDER_ATOMIC));Blockly.Python.addDeclarataddDion("led_scrolling_decl","int x = tiledMatrix.width() ;");return"matrix.setTextWrap(false);\nmatrix.setTextColor(matrix.Color"+a+");\nmatrix.setCursor(x, 0);\nint len = text.length()*6;\nlen *= (-1);\n//every word takes about 6 pixel wide\nif(--x < len) {\nx = matrix.width();\n}\nmatrix.show();\ndelay("+
- b+");\n"};
- Blockly.Python.led_pattern_5x5=function(a){Blockly.Python.addFunction("pattern_5x5","void setPattern(uint16_t patternMatrix[5][5]) {\n for (int row=0; row<5; row++) {\n for (int col=0; col<5; col++) {\n matrix.drawPixel(row, col, patternMatrix[col][row]);\n }\n }\n}\n");Blockly.Python.addDeclaration("pattern_5x5_dec","uint16_t pattern[5][5] =\n{\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), }\n};\n");for(var b=
- "",c=0;5>c;c++){for(var d=0;5>d;d++){var e="matrix.Color"+hexToRgb(a.getFieldValue(c+"_"+d));"matrix.Color(59, 85, 135)"===e&&(e="matrix.Color(0, 0, 0)");b+="pattern[4-"+c+"][4-"+d+"] = "+e+"; "}b+="\n"}return b+"setPattern(pattern);\n"};
- Blockly.Python.led_drawWord_5x5=function(a){var b=Blockly.Python.valueToCode(a,"WORD",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);a="#"==a[0]?hexToRgb(a):a;Blockly.Python.addInclude("myfont_5x5","#include <Fonts/MyFont5pt7b.h>");Blockly.Python.addSetup("setTextWrap_false","matrix.setTextWrap(false);");Blockly.Python.addSetup("font_5x5","matrix.setFont(&MyFont5pt7b);\n");return"matrix.setTextColor(matrix.Color"+a+");\nmatrix.setCursor(0, 4);\nmatrix.print(F("+
- b+"));\n"};
- Blockly.Python.led_text_input=function(a){var b=a.getFieldValue("scroll"),c=a.getFieldValue("font"),d=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_ATOMIC),e=/"/g.test(d);var f=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);f="#"==f[0]?hexToRgb(f):f;var g=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);a=parseInt(g.split(",")[0]);g=parseInt(g.split(",")[1]);f="matrix.setTextColor(matrix.Color"+f+");\n";Blockly.Python.addSetup("setTextWrap_false","matrix.setTextWrap(false);");
- "1"==c?(Blockly.Python.addInclude("myfont_5x5","#include <Fonts/MyFont5pt7b.h>"),Blockly.Python.addSetup("myfont_setup","matrix.setFont(&MyFont5pt7b);\n"),g+=4,Blockly.Python.addDeclaration("pixelPerChar_5","int pixelPerChar = 5;")):"3"==c?(Blockly.Python.addInclude("FreeSansBold9pt7b","#include <Fonts/FreeSansBold9pt7b.h>"),Blockly.Python.addSetup("FreeSansBold9pt7b","matrix.setFont(&FreeSansBold9pt7b);\n"),g+=12,Blockly.Python.addDeclaration("pixelPerChar_9","int pixelPerChar = 9;")):Blockly.Python.addDeclaration("pixelPerChar_5",
- "int pixelPerChar = 5;");"1"==b?(Blockly.Python.addDeclaration("scroll_"+a+"_"+g,"int scroll_"+a+"_"+g+" = matrix.width();"),Blockly.Python.addDeclaration("maxDisplacement_"+a+"_"+g,"int maxDisplacement_"+a+"_"+g+";"),f+="matrix.fillScreen(0);\nmatrix.setRotation(2);\nmatrix.setCursor(scroll_"+a+"_"+g+"+"+a+", "+g+");\n ",f=(e?f+("matrix.print(F("+d+"));\nmaxDisplacement_"+a+"_"+g+" = strlen("+d+")* pixelPerChar + matrix.width();\n"):f+("matrix.print("+d+");\nmaxDisplacement_"+a+"_"+g+" = "+d+".length()* pixelPerChar + matrix.width();\n"))+
- ("if(--scroll_"+a+"_"+g+" < -maxDisplacement_"+a+"_"+g+") {\nscroll_"+a+"_"+g+" = matrix.width();\n}\n")):(f+="matrix.setCursor("+a+","+g+");\n",f=e?f+("matrix.print(F("+d+"));\n"):f+("matrix.print("+d+");\n"));return f};
- Blockly.Python.led_draw_emotion=function(a){Blockly.Python.addFunction("pattern_5x5","void setPattern(uint16_t patternMatrix[5][5]) {\n for (int row=0; row<5; row++) {\n for (int col=0; col<5; col++) {\n matrix.drawPixel(row, col, patternMatrix[col][row]);\n }\n }\n}\n");Blockly.Python.addDeclaration("pattern_5x5_dec","uint16_t pattern[5][5] =\n{\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), }\n};\n");
- var b=a.getFieldValue("face");a.updateImage_();a=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);a="#"==a[0]?hexToRgb(a):a;var c="";switch(b){case "1":c="pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\npattern[1][0] = matrix.Color(0, 0, 0); pattern[1][1] = matrix.Color"+a+"; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color"+
- a+"; pattern[1][4] = matrix.Color(0, 0, 0);\npattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\npattern[3][0] = matrix.Color"+a+"; pattern[3][1] = matrix.Color(0, 0, 0); pattern[3][2] = matrix.Color(0, 0, 0); pattern[3][3] = matrix.Color(0, 0, 0); pattern[3][4] = matrix.Color"+a+";\npattern[4][0] = matrix.Color(0, 0, 0); pattern[4][1] = matrix.Color"+a+"; pattern[4][2] = matrix.Color"+
- a+"; pattern[4][3] = matrix.Color"+a+"; pattern[4][4] = matrix.Color(0, 0, 0);\nsetPattern(pattern);\n";break;case "2":c="pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\npattern[1][0] = matrix.Color"+a+"; pattern[1][1] = matrix.Color"+a+"; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color"+a+"; pattern[1][4] = matrix.Color"+a+";\npattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\npattern[3][0] = matrix.Color(0, 0, 0); pattern[3][1] = matrix.Color"+
- a+"; pattern[3][2] = matrix.Color"+a+"; pattern[3][3] = matrix.Color"+a+"; pattern[3][4] = matrix.Color(0, 0, 0);\npattern[4][0] = matrix.Color(0, 0, 0); pattern[4][1] = matrix.Color(0, 0, 0); pattern[4][2] = matrix.Color(0, 0, 0); pattern[4][3] = matrix.Color(0, 0, 0); pattern[4][4] = matrix.Color(0, 0, 0);\nsetPattern(pattern);\n";break;case "3":c="pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\npattern[1][0] = matrix.Color(0, 0, 0); pattern[1][1] = matrix.Color"+
- a+"; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color"+a+"; pattern[1][4] = matrix.Color(0, 0, 0);\npattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\npattern[3][0] = matrix.Color(0, 0, 0); pattern[3][1] = matrix.Color"+a+"; pattern[3][2] = matrix.Color"+a+"; pattern[3][3] = matrix.Color"+a+"; pattern[3][4] = matrix.Color(0, 0, 0);\npattern[4][0] = matrix.Color"+
- a+"; pattern[4][1] = matrix.Color(0, 0, 0); pattern[4][2] = matrix.Color(0, 0, 0); pattern[4][3] = matrix.Color(0, 0, 0); pattern[4][4] = matrix.Color"+a+";\nsetPattern(pattern);\n"}return c};Blockly.Python.led_draw_strip=function(a){var b=Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC);b="#"==b[0]?hexToRgb(b):b;a=Blockly.Python.valueToCode(a,"LOC",Blockly.Python.ORDER_ATOMIC);return"matrix.drawPixel("+(a+" % 5 , "+a+" / 5,matrix.Color")+b+");\n"};
- Blockly.Python.led_set_color=function(a){return[a.getFieldValue("COLOR"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.led_set_colorRGB=function(a){var b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return["("+b+","+c+","+a+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.lists={};Blockly.Python.lists_create_with=function(a){a=Array(this.itemCount_);for(var b=0;b<this.itemCount_;b++)a[b]=Blockly.Python.valueToCode(this,"ADD"+b,Blockly.Python.ORDER_NONE)||"0";return["{"+a.join(", ")+"}",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.lists_create_with2=function(a){a=Array(this.itemCount_);for(var b=0;b<this.itemCount_;b++)a[b]=Blockly.Python.valueToCode(this,"ADD"+b,Blockly.Python.ORDER_NONE)||'"string"';return["{"+a.join(", ")+"}",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.lists_length=function(a){a=Blockly.Python.valueToCode(this,"VAR",Blockly.Python.ORDER_ATOMIC)||"list";return["sizeof("+a+")/sizeof("+a+"[0])",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.lists_getIndex=function(a){a=Blockly.Python.valueToCode(this,"VAR",Blockly.Python.ORDER_ATOMIC)||"list";var b=Blockly.Python.valueToCode(this,"AT",Blockly.Python.ORDER_ADDITIVE)||"0";b.match(/^\d+$/)&&(b=parseInt(b,10));return[a+"[(int)("+b+")]",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.lists_setIndex=function(a){a=Blockly.Python.valueToCode(this,"VAR",Blockly.Python.ORDER_ATOMIC)||"list";var b=Blockly.Python.valueToCode(this,"AT",Blockly.Python.ORDER_ADDITIVE)||"1",c=Blockly.Python.valueToCode(this,"TO",Blockly.Python.ORDER_ASSIGNMENT)||"0";b.match(/^\d+$/)&&(b=parseInt(b,10));return a+"[(int)("+b+")] = "+c+";\n"};Blockly.Python.lists_variable_get=function(a){return[Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.lists_variable_set=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_ASSIGNMENT)||"{}";if(a.childBlocks_.length){if("lists_create_with"==a.childBlocks_[0].type){var c=a.getFieldValue("VAR");a="create_int_list_"+c;b="int "+c+"["+this.getChildren()[0].itemCount_+"] = "+b+";\n";Blockly.Python.addDeclaration(a,b);return""}if("lists_create_with2"==a.childBlocks_[0].type)return c=a.getFieldValue("VAR"),a="create_int_list_"+c,b="String "+c+"["+this.getChildren()[0].itemCount_+
- "] = "+b+";\n",Blockly.Python.addDeclaration(a,b),""}c=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);Blockly.Python.addDeclaration("create_string_list","String "+c+"[] = "+b+";\n");return""};Blockly.Python.logic={};Blockly.Python.controls_if=function(a){var b=0,c=Blockly.Python.valueToCode(a,"IF"+b,Blockly.Python.ORDER_NONE)||"false",d=Blockly.Python.statementToCode(a,"DO"+b),e="if ("+c+") {\n"+d+"}";for(b=1;b<=a.elseifCount_;b++)c=Blockly.Python.valueToCode(a,"IF"+b,Blockly.Python.ORDER_NONE)||"false",d=Blockly.Python.statementToCode(a,"DO"+b),e+=" else if ("+c+") {\n"+d+"}";a.elseCount_&&(d=Blockly.Python.statementToCode(a,"ELSE"),e+=" else {\n"+d+"}");return e+"\n"};
- Blockly.Python.switch_statement=function(a){for(var b="switch ("+Blockly.Python.variableDB_.getName(a.getFieldValue("switch_var"),Blockly.Variables.NAME_TYPE)+") {\n",c,d,e=0;e<=a.caseCount_;e++)c=Blockly.Python.valueToCode(a,"CASE"+e,Blockly.Python.ORDER_NONE)||e,d=Blockly.Python.statementToCode(a,"DO"+e),b+=" case "+c+":\n"+d+" break;\n";a.defaultCount_&&(d=Blockly.Python.statementToCode(a,"DEFAULT"),b+=" default:\n"+d+" break;\n");return b+"}\n"};
- Blockly.Python.logic_compare=function(a){var b={EQ:"==",NEQ:"!=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")],c="=="==b||"!="==b?Blockly.Python.ORDER_EQUALITY:Blockly.Python.ORDER_RELATIONAL,d=Blockly.Python.valueToCode(a,"A",c)||"0";a=Blockly.Python.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]};
- Blockly.Python.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"&&":"||",c="&&"==b?Blockly.Python.ORDER_LOGICAL_AND:Blockly.Python.ORDER_LOGICAL_OR,d=Blockly.Python.valueToCode(a,"A",c)||"false";a=Blockly.Python.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.Python.logic_negate=function(a){var b=Blockly.Python.ORDER_UNARY_PREFIX;return["!"+(Blockly.Python.valueToCode(a,"BOOL",b)||"false"),b]};
- Blockly.Python.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"true":"false",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.logic_null=function(a){return["NULL",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.logic_ternary=function(a){var b=Blockly.Python.valueToCode(a,"IF",Blockly.Python.ORDER_CONDITIONAL)||"false",c=Blockly.Python.valueToCode(a,"THEN",Blockly.Python.ORDER_CONDITIONAL)||"null";a=Blockly.Python.valueToCode(a,"ELSE",Blockly.Python.ORDER_CONDITIONAL)||"null";return[b+" ? "+c+" : "+a,Blockly.Python.ORDER_CONDITIONAL]};Blockly.Python.loops={};Blockly.Python.controls_repeat=function(a){var b=Number(a.getFieldValue("TIMES")),c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a.id);a=Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE);return"for (int "+a+" = 0; "+a+" < "+b+"; "+a+"++) {\n"+c+"}\n"};
- Blockly.Python.controls_repeat_ext=function(a){var b=Blockly.Python.valueToCode(a,"TIMES",Blockly.Python.ORDER_ADDITIVE)||"0",c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a.id);a="";var d=Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.Python.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.Python.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Python.valueToCode(a,"BOOL",b?Blockly.Python.ORDER_LOGICAL_OR:Blockly.Python.ORDER_NONE)||"false",d=Blockly.Python.statementToCode(a,"DO");d=Blockly.Python.addLoopTrap(d,a.id);b&&(c.match(/^\w+$/)||(c="("+c+")"),c="!"+c);return"while ("+c+") {\n"+d+"}\n"};
- Blockly.Python.controls_for=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_ASSIGNMENT)||"0",d=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_ASSIGNMENT)||"0",e=Blockly.Python.valueToCode(a,"BY",Blockly.Python.ORDER_ASSIGNMENT)||"1",f=Blockly.Python.statementToCode(a,"DO");f=Blockly.Python.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.Python.variableDB_.getDistinctName(b+"_start",Blockly.Variables.NAME_TYPE),a+="int "+g+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.Python.variableDB_.getDistinctName(b+"_end",Blockly.Variables.NAME_TYPE),a+="int "+c+" = "+d+";\n"),d=Blockly.Python.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=a+("if ("+g+" > "+c+") {\n")+(Blockly.Python.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.Python.controls_forEach=Blockly.Python.noGeneratorCodeLine;
- Blockly.Python.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw"Unknown flow statement.";};Blockly.Python.mainwifi={};Blockly.Python.mainwifi_setup=function(a){Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");return""};
- Blockly.Python.mainwifi_sendMsg=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");a=Blockly.Python.variableDB_.getName(a.getFieldValue("dataVar"),Blockly.Variables.NAME_TYPE);var b="sizeof("+a+")/sizeof("+a+"[0])",c=b+"+2";return"unsigned char DataOut_["+c+"];\nDataOut_[0]= SOP;\nDataOut_["+b+"+1]= EOP;\nfor (int i=0; i<"+b+";i++) {\n DataOut_[i+1]="+a+"[i];\n}\nSerial1.write(DataOut_, "+c+");\n"};
- Blockly.Python.mainwifi_receiveMsg=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");a=Blockly.Python.variableDB_.getName(a.getFieldValue("dataVar"),Blockly.Variables.NAME_TYPE);Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+
- ("sizeof("+a+")/sizeof("+a+"[0])"||1)+")&&started&&(!ended)) {\n "+a+"[index_i] = inChar;\n index_i++;\n }\n }\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");return"boolean receiveMsgsuccess_ = handleDataIn();\n"};Blockly.Python.mainwifi_receiveMsg_isSuccessed=function(a){return["receiveMsgsuccess_",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.MainEasymode_transfer_send=function(a){a=Blockly.Python.variableDB_.getName(a.getFieldValue("DATAMAIN"),Blockly.Variables.NAME_TYPE);Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");var b="sizeof("+a+")/sizeof("+a+"[0])",c=b+"+2";return"unsigned char DataOut_["+c+"];\nDataOut_[0]= SOP;\nDataOut_["+b+"+1]= EOP;\nfor (int i=0; i<"+b+";i++) {\n DataOut_[i+1]="+a+"[i];\n}\nSerial1.write(DataOut_, "+
- c+");\n"};
- Blockly.Python.MainEasymode_transfer_receive=function(a){a=Blockly.Python.variableDB_.getName(a.getFieldValue("DATAMAIN"),Blockly.Variables.NAME_TYPE);Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+("sizeof("+
- a+")/sizeof("+a+"[0])"||1)+")&&started&&(!ended)) {\n "+a+"[index_i] = inChar;\n index_i++;\n }\n }\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");return"boolean receiveMsgsuccess_ = handleDataIn();\n"};
- Blockly.Python.MainEasymode_transfer2_send_old=function(a){a=a.getFieldValue("DATAMAIN");for(var b="int "+a+"["+this.itemCount_+"] = {0",c=1;c<this.itemCount_;c++)b+=",0";Blockly.Python.addDeclaration("dataMain_list",b+"};\n");Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");b="sizeof("+a+")/sizeof("+a+"[0])";c=b+"+2";for(var d="",e,f=0;f<this.itemCount_;f++)e=Blockly.Python.valueToCode(this,
- "ADD"+f,Blockly.Python.ORDER_NONE)||"0",d+=a+"["+f+"] = "+e+";\n";return d+("unsigned char DataOut_["+c+"];\nDataOut_[0]= SOP;\nDataOut_["+b+"+1]= EOP;\nfor (int i=0; i<"+b+";i++) {\n DataOut_[i+1]="+a+"[i];\n}\nSerial1.write(DataOut_, "+c+");\n")};
- Blockly.Python.MainEasymode_transfer2_receive_old=function(a){var b=a.getFieldValue("DATAMAIN")||"_main_transfer";a=a.getFieldValue("LENGTH");for(var c="int "+b+"["+a+"] = {0",d=1;d<a;d++)c+=",0";Blockly.Python.addDeclaration("dataMain_list",c+"};\n");Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");
- Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial1.available() > 0) {\n int inChar = Serial1.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+("sizeof("+b+")/sizeof("+b+"[0])"||1)+")&&started&&(!ended)) {\n "+b+"[index_i] = inChar;\n index_i++;\n }\n }\n delay(10);\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");
- return'boolean receiveMsgsuccess_ = handleDataIn();\nif (!receiveMsgsuccess_) {\n Serial.println("Error: Fail to receive data!");\n return;\n}\n'};Blockly.Python.MainEasymode_transfer2_receive_getValue_old=function(a){var b=a.getFieldValue("DATAMAIN")||"_main_transfer";a=a.getFieldValue("INDEX");return[""+b+"["+a+"]",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.MainEasymode_transfer2_send=function(a){Blockly.Python.addDeclaration("Serial_sendState","int serialSendState = 0;");Blockly.Python.addSetup("serial1","Serial1.begin(9600);");Blockly.Python.addFunction("SerialSendData","void serialSendData() {\n int serialDataLength = serialDataPackage().length() + 1;\n char serialDataBuf[serialDataLength];\n serialDataPackage().toCharArray(serialDataBuf, serialDataLength);\n if ( serialSendState == 0 ) {\n Serial1.write(serialDataBuf);\n }\n if ( (millis() / 100) % 4 == 3 && serialSendState == 0) {\n Serial1.write(serialDataBuf);\n serialSendState = 1;\n } else if ( (millis() / 100) % 4 == 1) {\n serialSendState = 0;\n }\n}\n");
- for(var b='String serialDataPackage() { \n String data = "";\n data += "SOF";\n',c=0;c<this.itemCount_;c++)a=Blockly.Python.valueToCode(this,"ADD"+c,Blockly.Python.ORDER_NONE)||"0",b+=' data += "|";\n data += '+a+";\n";Blockly.Python.addFunction("SerialDataPackage",b+' data += "|";\n data += "\\r\\n";\n return data;\n}\n');return"serialSendData();\n"};
- Blockly.Python.MainEasymode_transfer2_receive=function(a){Blockly.Python.addSetup("serial1_trans","Serial1.begin(9600);\n Serial1.setTimeout(20);");Blockly.Python.addDeclaration("serialDataReceived","String serialDataReceived;\n");Blockly.Python.addFunction("serialDataFilter",'int serialDataFilter() {\n if (Serial1.available() > 0) {\n serialDataReceived = Serial1.readStringUntil("\\r\\n");\n }\n if (getSerialDataValue(serialDataReceived, \'|\', 0) == "SOF") {\n return 1;\n } else {\n return 0;\n }\n}\n');
- Blockly.Python.addFunction("getSerialDataValue",'String getSerialDataValue(String data, char separator, int index)\n{\n int found = 0;\n int strIndex[] = {0, -1};\n int maxIndex = data.length() - 1;\n for (int i = 0; i <= maxIndex && found <= index; i++) {\n if (data.charAt(i) == separator || i == maxIndex) {\n found++;\n strIndex[0] = strIndex[1] + 1;\n strIndex[1] = (i == maxIndex) ? i + 1 : i;\n }\n }\n return found > index ? data.substring(strIndex[0], strIndex[1]) : "";\n}\n');
- return'boolean serialReceiveCheck_ = serialDataFilter();\nif (!serialReceiveCheck_) {\n Serial.println("Error receiving data from WiFi Module.");\n return;\n }\n'};Blockly.Python.MainEasymode_transfer2_receive_getValue=function(a){var b=parseInt(a.getFieldValue("INDEX"))+1;a=a.getFieldValue("TYPE");return["getSerialDataValue(serialDataReceived, '|', "+b+")"+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.map={};Blockly.Python.base_map=function(a){var b=Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"DMAX",Blockly.Python.ORDER_ATOMIC)||"0";return["map("+b+", 0, 1024, 0, "+a+")",Blockly.Python.ORDER_NONE]};Blockly.Python.math={};Blockly.Python.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));Infinity==a?a="INFINITY":-Infinity==a&&(a="-INFINITY");return[a,Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.Python.ORDER_ADDITIVE],MINUS:[" - ",Blockly.Python.ORDER_ADDITIVE],MULTIPLY:[" * ",Blockly.Python.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",Blockly.Python.ORDER_MULTIPLICATIVE],POWER:[null,Blockly.Python.ORDER_NONE]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=Blockly.Python.valueToCode(a,"A",b)||"0";a=Blockly.Python.valueToCode(a,"B",b)||"0";return c?[d+c+a,b]:["Math.pow("+d+", "+a+")",Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.math_single=function(a){var b=a.getFieldValue("OP");if("NEG"==b)return a=Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_UNARY_PREFIX)||"0","-"==a[0]&&(a=" "+a),["-"+a,Blockly.Python.ORDER_UNARY_PREFIX];a="ABS"==b||"ROUND"==b.substring(0,5)?Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_UNARY_POSTFIX)||"0":"SIN"==b||"COS"==b||"TAN"==b?Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_MULTIPLICATIVE)||"0":Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_NONE)||
- "0";switch(b){case "ABS":var 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.Python.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.Python.ORDER_MULTIPLICATIVE]};
- Blockly.Python.math_constant=function(a){return{PI:["M_PI",Blockly.Python.ORDER_UNARY_POSTFIX],E:["M_E",Blockly.Python.ORDER_UNARY_POSTFIX],GOLDEN_RATIO:["(1 + sqrt(5)) / 2",Blockly.Python.ORDER_MULTIPLICATIVE],SQRT2:["M_SQRT2",Blockly.Python.ORDER_UNARY_POSTFIX],SQRT1_2:["M_SQRT1_2",Blockly.Python.ORDER_UNARY_POSTFIX],INFINITY:["INFINITY",Blockly.Python.ORDER_ATOMIC]}[a.getFieldValue("CONSTANT")]};
- Blockly.Python.math_number_property=function(a){var b=Blockly.Python.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Python.ORDER_MULTIPLICATIVE)||"0",c=a.getFieldValue("PROPERTY");if("PRIME"==c)return a=Blockly.Python.addFunction("mathIsPrime",["boolean "+Blockly.Python.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.Python.addInclude("math","#include <math.h>"),[a+"("+b+")",Blockly.Python.ORDER_UNARY_POSTFIX];switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":Blockly.Python.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.Python.valueToCode(a,"DIVISOR",Blockly.Python.ORDER_MULTIPLICATIVE)||"0",d=b+" % "+a+" == 0"}return[d,Blockly.Python.ORDER_EQUALITY]};
- Blockly.Python.math_change=function(a){var b=Blockly.Python.valueToCode(a,"DELTA",Blockly.Python.ORDER_ADDITIVE)||"0";return Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" += "+b+";\n"};Blockly.Python.math_round=Blockly.Python.math_single;Blockly.Python.math_trig=Blockly.Python.math_single;Blockly.Python.math_on_list=Blockly.Python.noGeneratorCodeInline;
- Blockly.Python.math_modulo=function(a){var b=Blockly.Python.valueToCode(a,"DIVIDEND",Blockly.Python.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Python.valueToCode(a,"DIVISOR",Blockly.Python.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,Blockly.Python.ORDER_MULTIPLICATIVE]};
- Blockly.Python.math_constrain=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"0",c=Blockly.Python.valueToCode(a,"LOW",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"HIGH",Blockly.Python.ORDER_NONE)||"0";return["("+b+" < "+c+" ? "+c+" : ( "+b+" > "+a+" ? "+a+" : "+b+"))",Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.math_random_int=function(a){var b=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"0";var c=Blockly.Python.variableDB_.getDistinctName("math_random_int",Blockly.Generator.NAME_TYPE);Blockly.Python.math_random_int.random_function=c;return[Blockly.Python.addFunction("mathRandomInt",["int "+Blockly.Python.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.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.math_random_float=function(a){return["(rand() / RAND_MAX)",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.motion={};
- Blockly.Python.motion_setup=function(a){Blockly.Python.addInclude("motion_include",'#include "I2Cdev.h"\n#include "MPU6050_6Axis_MotionApps20.h"\n#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE\n#include "Wire.h"\n#endif\n');Blockly.Python.addDeclaration("motion_declaration","MPU6050 mpu;\n\n#define _INTERRUPT_PIN 2\n#define _LED_PIN 13\nbool _blinkState = false;\n\nbool dmpReady = false; // set true if DMP init was successful\nuint8_t mpuIntStatus; // holds actual interrupt status byte from MPU\nuint8_t devStatus; // return status after each device operation (0 = success, !0 = error)\nuint16_t packetSize; // expected DMP packet size (default is 42 bytes)\nuint16_t fifoCount; // count of all bytes currently in FIFO\nuint8_t fifoBuffer[64]; // FIFO storage buffer\n\nQuaternion q; // [w, x, y, z] quaternion container\nVectorInt16 aa; // [x, y, z] accel sensor measurements\nVectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements\nVectorFloat gravity; // [x, y, z] gravity vector\nfloat ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector\n\nvolatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high\n\nfloat _motionGetYaw, _motionGetPitch, _motionGetRoll;\nint _directionState = 0;\nfloat _directionValue = 0.00;\nvoid dmpDataReady() {\nmpuInterrupt = true;\n}\n");Blockly.Python.addFunction("motion_SetupFunc",
- 'void _motionSensorSetup() {\n#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE\nWire.begin();\nWire.setClock(400000);\n#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE\nFastwire::setup(400, true);\n#endif\nSerial.begin(115200);\n// while (!Serial);\nSerial.println(F("Initializing I2C devices..."));\nmpu.initialize();\npinMode(_INTERRUPT_PIN, INPUT);\nSerial.println(F("Testing device connections..."));\nSerial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));\nSerial.println("Waiting for calibrating... 2s");\ndelay(1000);\nSerial.println("Waiting for calibrating... 1s");\ndelay(1000);\nSerial.println(F("Initializing DMP..."));\ndevStatus = mpu.dmpInitialize();\nmpu.setXGyroOffset(220);\nmpu.setYGyroOffset(76);\nmpu.setZGyroOffset(-85);\nmpu.setZAccelOffset(1788);\nif (devStatus == 0) {\nmpu.CalibrateAccel(6);\nmpu.CalibrateGyro(6);\nmpu.PrintActiveOffsets();\nSerial.println(F("Enabling DMP..."));\nmpu.setDMPEnabled(true);\nSerial.print(F("Enabling interrupt detection (Arduino external interrupt "));\nSerial.print(digitalPinToInterrupt(_INTERRUPT_PIN));\nSerial.println(F(")..."));\nattachInterrupt(digitalPinToInterrupt(_INTERRUPT_PIN), dmpDataReady, RISING);\nmpuIntStatus = mpu.getIntStatus();\nSerial.println(F("DMP ready! Waiting for first interrupt..."));\ndmpReady = true;\npacketSize = mpu.dmpGetFIFOPacketSize();\n} else {\nSerial.print(F("DMP Initialization failed (code "));\nSerial.print(devStatus);\nSerial.println(F(")"));\n}\npinMode(_LED_PIN, OUTPUT);\n}\n');
- Blockly.Python.addFunction("motion_LoopFunc",'void _motionSensorMain() {\nif (!dmpReady) return;\nwhile (!mpuInterrupt && fifoCount < packetSize) {\nif (mpuInterrupt && fifoCount < packetSize) {\nfifoCount = mpu.getFIFOCount();\n}\n}\nmpuInterrupt = false;\nmpuIntStatus = mpu.getIntStatus();\nfifoCount = mpu.getFIFOCount();\nif (fifoCount < packetSize) {\n}\nelse if ((mpuIntStatus & _BV(MPU6050_INTERRUPT_FIFO_OFLOW_BIT)) || fifoCount >= 1024) {\n mpu.resetFIFO();\nSerial.println(F("FIFO overflow!"));\n} else if (mpuIntStatus & _BV(MPU6050_INTERRUPT_DMP_INT_BIT)) {\nwhile (fifoCount >= packetSize) {\nmpu.getFIFOBytes(fifoBuffer, packetSize);\nfifoCount -= packetSize;\n}\nmpu.dmpGetQuaternion(&q, fifoBuffer);\nmpu.dmpGetGravity(&gravity, &q);\nmpu.dmpGetYawPitchRoll(ypr, &q, &gravity);\n_motionGetYaw = ypr[0] * 180 / M_PI;\n_motionGetPitch = ypr[1] * 180 / M_PI;\n_motionGetRoll = ypr[2] * 180 / M_PI;\nmpu.dmpGetQuaternion(&q, fifoBuffer);\nmpu.dmpGetAccel(&aa, fifoBuffer);\nmpu.dmpGetGravity(&gravity, &q);\nmpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);\n_blinkState = !_blinkState;\ndigitalWrite(_LED_PIN, _blinkState);\n}\n}\n');
- Blockly.Python.addSetup("motion_setup","_motionSensorSetup();\n");return"_motionSensorMain();\n"};Blockly.Python.motion_onshake=function(a){Blockly.Python.addFunction("onShake_function","boolean _motionOnShake() {\nif (aaReal.x < -5000 || aaReal.x > 5000 || aaReal.y < -5000 || aaReal.y > 5000 || aaReal.z < -5000 || aaReal.z > 5000) {\nreturn true;\n} else {\nreturn false;\n}\n}\n");return["_motionOnShake()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.motion_onDirection=function(a){a=a.getFieldValue("DIRECTION");Blockly.Python.addFunction("onDirection_function","int _motionOnTilting(int direction) {\n _directionState = 0;\n switch (direction) {\n case 1:\n if (ypr[2] * 180 / M_PI < -20) {\n _directionState = 1;\n }\n break;\n case 2:\n if (ypr[2] * 180 / M_PI > 20) {\n _directionState = 1;\n }\n break;\n case 3:\n if (ypr[1] * 180 / M_PI < -20) {\n _directionState = 1;\n }\n break;\n case 4:\n if (ypr[1] * 180 / M_PI > 20) {\n _directionState = 1;\n }\n break;\n case 5:\n if (ypr[0] * 180 / M_PI +180 - _directionValue > 0) {\n _directionState = 1;\n }\n break;\n case 6:\n if (ypr[0] * 180 / M_PI +180 - _directionValue < 0) {\n _directionState = 1;\n }\n break;\n default:\n break;\n }\n _directionValue = ypr[0] * 180 / M_PI +180;\n return _directionState;\n}\n");
- switch(a){case "left":var b=1;break;case "right":b=2;break;case "front":b=3;break;case "back":b=4;break;case "clockwise":b=5;break;case "counterClockwise":b=6}return["_motionOnTilting("+b+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.motion_getRotation_ypr=function(a){return["ypr["+a.getFieldValue("Rotation")+"] * 180 / M_PI",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.motion_getAcceleration=function(a){return["aaReal."+a.getFieldValue("Acceleration"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.motor={};
- Blockly.Python.motor_setup=function(){Blockly.Python.addDeclaration("STBY_define","int STBY = A5;");Blockly.Python.addDeclaration("motor_A_define","// Motor A Definition\nint PWMA = 5; // Speed control\nint AIN1 = 9; // Direction\nint AIN2 = 10; // Direction");Blockly.Python.addDeclaration("motor_B_define","// Motor B Definition\nint PWMB = 6; // Speed control\nint BIN1 = 4; // Direction\nint BIN2 = 8; // Direction\n");Blockly.Python.addSetup("stby_setup","pinMode(STBY, OUTPUT);");Blockly.Python.addSetup("motor_A_setup",
- "// Motor A Setup\n pinMode(PWMA, OUTPUT);\n pinMode(AIN1, OUTPUT);\n pinMode(AIN2, OUTPUT);");Blockly.Python.addSetup("motor_B_setup","// Motor B Setup\n pinMode(PWMB, OUTPUT);\n pinMode(BIN1, OUTPUT);\n pinMode(BIN2, OUTPUT);");Blockly.Python.addFunction("motor_move_function","void move(int motor, int speed, int direction) {\n //Move specific motor at speed and direction\n //motor: 0 for B 1 for A\n //speed: 0 is off, and 255 is full speed\n //direction: 0 clockwise, 1 counter-clockwise\n digitalWrite(STBY, HIGH); //disable standby\n boolean inPin1 = LOW;\n boolean inPin2 = HIGH;\n if (direction == 1) {\n inPin1 = HIGH;\n inPin2 = LOW;\n }\n if (motor == 1) {\n digitalWrite(AIN1, inPin1);\n digitalWrite(AIN2, inPin2);\n analogWrite(PWMA, speed);\n } else {\n digitalWrite(BIN1, inPin1);\n digitalWrite(BIN2, inPin2);\n analogWrite(PWMB, speed);\n }\n}");
- Blockly.Python.addFunction("motor_stop_function","void stop() {\n //enable standby\n digitalWrite(STBY, LOW);\n}");return""};Blockly.Python.motor_speed=function(a){return[a.getFieldValue("SPEED"),Blockly.Python.ORDER_NONE]};Blockly.Python.motorA_move_clockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"};
- Blockly.Python.motorA_move_anticlockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"};Blockly.Python.motorB_move_clockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"};
- Blockly.Python.motorB_move_anticlockwise=function(a){var b=a.getFieldValue("MOTOR"),c=Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("DIRECTION");return"move("+b+","+c+","+a+");\n"};Blockly.Python.motor_stop=function(a){return"stop();\n"};Blockly.Python.music={};Blockly.Python.MusicMidiSetup=function(a){Blockly.Python.addInclude("SPI","#include <SPI.h>");Blockly.Python.addInclude("SD","#include <SD.h>");Blockly.Python.addInclude("MusicPlayer","#include <MusicPlayer.h>\n");a="player.beginInMidiFmt();\n player.midiSetInit("+a.getFieldValue("INSTRUMENT")+", "+a.getFieldValue("VOLUME")+");\n";Blockly.Python.addSetup("music_setup",a);return""};
- Blockly.Python.MusicSetVolume=function(a){return"player.setVolume("+a.getFieldValue("VOLUME")+");\n"};Blockly.Python.MusicSetInstrument=function(a){return"player.midiSetInstrument("+a.getFieldValue("INSTRUMENT")+");\n"};Blockly.Python.MusicNote=function(a){return[a.getFieldValue("NOTE"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.MusicBeat=function(a){return[a.getFieldValue("BEAT"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.MusicPlayTone=function(a){var b=Blockly.Python.valueToCode(a,"NOTE",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"DURATION",Blockly.Python.ORDER_ATOMIC);return"player.midiPlay("+b+", "+a+");\n"};Blockly.Python.MusicRest=function(a){return"delay("+Blockly.Python.valueToCode(a,"BEAT",Blockly.Python.ORDER_ATOMIC)+");\n"};
- Blockly.Python.Music_mp3_setup=function(a){Blockly.Python.addInclude("SPI","#include <SPI.h>");Blockly.Python.addInclude("SD","#include <SD.h>");Blockly.Python.addInclude("MusicPlayer","#include <MusicPlayer.h>\n");a=a.getFieldValue("SETVOL")||50;Blockly.Python.addDeclaration("mp3_dec","int _musicPlayerVolume = "+a+";\nint _musicVolumeMappingRead, _musicVolumeMappingSet;\n");Blockly.Python.addSetup("mp3_setup"," Serial.begin(9600);\n delay(2000);\n player.keyDisable(); //keys disable first;\n player.begin(); //will initialize the hardware and set default mode to be normal.\n player.setVolume(_musicPlayerVolume);\n");
- Blockly.Python.addFunction("func_musicPlaySong","/*\n* Music Function: Music Set Play Song\n*/\nvoid _musicPlaySong(String songname) {\n int songNameLength = songname.length() + 1;\n char songNameBuf[songNameLength];\n songname.toCharArray(songNameBuf, songNameLength);\n\n delay(50);\n player.opPause();\n player.setPlayMode(PM_REPEAT_ONE);\n player.playOne(songNameBuf);\n player.play();\n delay(50);\n}");Blockly.Python.addFunction("func__musicOperation","/* \n * Music Function: Music Operation\n */\n\nvoid _musicOperation(int operation) {\n _musicVolumeMappingRead = map(_musicPlayerVolume, 110, 10, 0, 10);\n\n if (operation == 0) { // 0: Play song\n delay(100);\n player.opResume();\n } else if (operation == 1) { // 1: Pause song\n delay(100);\n player.opPause();\n } else if (operation == 2) { // 2: Previous song\n delay(100);\n for (int a = 0; a < 1; a++) {\n player.opPreviousSong();\n player.play();\n }\n } else if (operation == 3) { // 3: Next song\n delay(100);\n for (int a = 0; a < 1; a++) {\n player.opNextSong();\n player.play();\n }\n } else if (operation == 4) { // 4: Volume Up\n\n _musicPlayerVolume = _musicPlayerVolume - 10;\n if ( _musicPlayerVolume <= 10 ) {\n _musicPlayerVolume = 10;\n }\n delay(100);\n player.setVolume(_musicPlayerVolume);\n } else if (operation == 5) { // 5: Volume Down\n\n _musicPlayerVolume = _musicPlayerVolume + 10;\n if ( _musicPlayerVolume >= 110 ) {\n _musicPlayerVolume = 110;\n }\n delay(100);\n player.setVolume(_musicPlayerVolume);\n } else if (operation == 6) { // 6: Play all song\n delay(100);\n player.setPlayMode(PM_REPEAT_LIST);\n player.scanAndPlayAll();\n player.play();\n delay(100);\n player.play();\n }\n}\n");
- Blockly.Python.addFunction("func_musicSetVolume","/* \n * Music Function: Music Set Volume\n */\n\nvoid _musicSetVolume(int volume) {\n _musicVolumeMappingSet = map(volume, 0, 10, 110, 10);\n player.setVolume(_musicVolumeMappingSet);\n\n _musicPlayerVolume = _musicVolumeMappingSet;\n}\n");return""};Blockly.Python.Music_mp3_playOneWithName=function(a){return'_musicPlaySong("'+a.getFieldValue("MUSIC_NAME")+'");\n'};
- Blockly.Python.Music_mp3_playAllMusic=function(a){Blockly.Python.addSetup("playMode","player.setPlayMode(PM_NORMAL_PLAY);\n ");return"player.scanAndPlayAll();\nplayer.play();\n"};Blockly.Python.Music_mp3_playSetting=function(a){return"_musicOperation("+a.getFieldValue("SETTING")+");\n"};Blockly.Python.Music_mp3_getCurrentVolume=function(a){return["_musicVolumeMappingRead",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.Music_mp3_setCurrentVolume=function(a){return"_musicSetVolume("+a.getFieldValue("VOLLEVEL")+");\n"};Blockly.Python.nbiot={};Blockly.Python.NBIoT_setup=function(a){Blockly.Python.addDeclaration("NBIoT_Dec","#define nbiotSerial Serial1\nint nbiotperiodicallyExecutionState = 0;\nint nbiotperiodicallyExecutionGap = 8;\nint serialSendState = 0;\n");Blockly.Python.addSetup("NBIoT_Setup",'nbiotSerial.begin(115200);\nnbiotSerial.write("AT+CSQ\\r\\n");\n');return""};
- Blockly.Python.NBIoT_http=function(a){var b=a.getFieldValue("APIKEY");Blockly.Python.addFunction("nbiotHttprequestPOST",'void nbiotHttprequestPOST() {\n int nbiotDataLength = nbiotHTTPJSONDataSet().length() + 1;\n char nbiotDataBuf[nbiotDataLength];\n nbiotHTTPJSONDataSet().toCharArray(nbiotDataBuf, nbiotDataLength);\n if ((millis() / 1000) % 10 == 1 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCLOSE=0\\r\\n");\n serialSendState= 1;\n; } else if ((millis() / 1000) % 10 == 2) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 3 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCREATE=\\"http://api.cocorobo.cn/\\"\\r\\n");\n nbiotSerial.write("AT+HTTPHEADER=0,\\"Content-Type: application/json\\\\r\\\\n\\"\\r\\n");\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 4) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 5 && serialSendState == 0) {\n nbiotSerial.write(nbiotDataBuf);\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 6) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 7 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPSEND=0,1,\\"/iot/data/eventAPIKey/'+b+
- '\\"\\r\\n");\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 8) {\n serialSendState = 0;\n } }\n');b='String nbiotHTTPJSONDataSet() {\n String data = "AT+HTTPCONTENT=0,\\"{";\n';for(var c=0;c<a.itemCount_;c++){var d=a.getFieldValue("DATA_DEFAULT"+c)||"default",e=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_ATOMIC)||0;0<c&&(b+=' data += ",";\n');b+=' data += "\\"";\n data += "'+d+'";\n data += "\\":";\n data += '+e+";\n"}Blockly.Python.addFunction("nbiotHTTPJSONDataSet",
- b+' data += "}\\"\\r\\n";\n return data;\n}\n');return"nbiotHttprequestPOST();\n"};
- Blockly.Python.NBIoT_enable=function(a){Blockly.Python.addDeclaration("nbiotEnable_var",'const char EOPmarker = \'\\r\\n\'; //This is the end of packet marker\nchar serialbuf[200]; //This gives the incoming serial some room. Change it if you want a longer incoming.\nchar c = " ";\n\nString nbiot_btstring;\nString nbiot_var;\nString nbiot_str;\n\nint _stateADDR = 0;\nint _stateNbiotIsOn = 0;\nString _IPADDR = "";\n');Blockly.Python.addFunction("interactiveNBIoTSerial","void interactiveNBIoTSerial(){\n while (nbiotSerial.available() > 0) { //makes sure something is ready to be read\n\n static int bufpos = 0; //starts the buffer back at the first position in the incoming serial.read\n char inchar = nbiotSerial.read(); //assigns one byte (as serial.read()'s only input one byte at a time\n if (inchar != EOPmarker) { //if the incoming character is not the byte that is the incoming package ender\n serialbuf[bufpos] = inchar; //the buffer position in the array get assigned to the current read\n bufpos++; //once that has happend the buffer advances, doing this over and over again until the end of package marker is read.\n }\n else { //once the end of package marker has been read\n serialbuf[bufpos] = 0; //restart the buff\n bufpos = 0; //restart the position of the buff\n\n Serial.println(serialbuf);\n nbiot_str = serialbuf;\n\n if (nbiot_str.charAt(1) == 'I' && nbiot_str.charAt(2) == 'P') {\n nbiot_var = midString(nbiot_str, \"+IP:\", \"\\r\");\n _IPADDR = nbiot_var;\n int i = 0;\n while (i < nbiot_var.length()) {\n if (nbiot_var.charAt(i) == '.') \n nbiot_var.setCharAt(i, ',');\n i++;\n }\n Serial.println(nbiot_var);\n _stateADDR = 1;\n }\nif (nbiot_str.charAt(1) == 'C' && nbiot_str.charAt(2) == 'P' && nbiot_str.charAt(3) == 'I' && nbiot_str.charAt(4) == 'N' && nbiot_str.charAt(7) == 'R' && nbiot_str.charAt(8) == 'E' && nbiot_str.charAt(9) == 'A' && nbiot_str.charAt(10) == 'D' && nbiot_str.charAt(11) == 'Y') {\n_stateNbiotIsOn = 1;\nSerial.println(\"NBIoT initiated.\");\ndelay(100);\nnbiotSerial.write(\"AT+CMSYSCTRL=0,2,50,300,100,800\\r\\n\");\n}\n\n }\n }\n while (Serial.available() > 0) {\n char cmd = Serial.read();\n nbiotSerial.write(cmd);\n }\n}\n");
- Blockly.Python.addFunction("NBIoT_midString",'String midString(String str, String start, String finish) {\n int locStart = str.indexOf(start);\n if (locStart == -1) return "";\n locStart += start.length();\n int locFinish = str.indexOf(finish, locStart);\n if (locFinish == -1) return "";\n return str.substring(locStart, locFinish);\n}\n');return"interactiveNBIoTSerial();\n"};
- Blockly.Python.NBIoT_http_thingspeak=function(a){for(var b="update?api_key="+a.getFieldValue("APIKEY")+"&",c=0;c<a.itemCount_;c++){var d=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_ATOMIC);b+="field"+(c+1)+'="+String('+d+')+"';c!=a.itemCount_-1&&(b+="&")}Blockly.Python.addFunction("nbiotThingspeakRequest",'void nbiotThingspeakRequest() {\n if ((millis() / 1000) % 10 == 1 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCLOSE=0\\r\\n");\n serialSendState= 1;\n; } else if ((millis() / 1000) % 10 == 2) {\n serialSendState = 0;\n }\n if ((millis() / 1000) % 10 == 3 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCREATE=\\"http://api.thingspeak.com/\\"\\r\\n");\n nbiotSerial.write("AT+HTTPHEADER=0,\\"User-Agent: Unknown\\\\r\\\\n\\"\\r\\n");\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 4) {\n serialSendState = 0;\n }\n if ((millis() / 1000) % 10 == 5 && serialSendState == 0 ){\n String myString = "AT+HTTPSEND=0,0,\\"'+
- b+'\\"\\r\\n";\n char* buf = (char*) malloc(sizeof(char)*myString.length()+1);\n myString.toCharArray(buf, myString.length()+1);\n nbiotSerial.write(buf);\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 6) {\n serialSendState = 0;\n }\n}\n');return"nbiotThingspeakRequest();\n"};
- Blockly.Python.NBIoT_http_IFTTT=function(a){for(var b=a.getFieldValue("APIKEY"),c=a.getFieldValue("EVENT"),d=0;d<a.itemCount_;d++)Blockly.Python.valueToCode(a,"ADD"+d,Blockly.Python.ORDER_ATOMIC);Blockly.Python.addFunction("nbiotIFTTTRequest",'void nbiotIFTTTRequest() {\n int nbiotDataLength = nbiotHTTPJSONDataSet().length() + 1;\n char nbiotDataBuf[nbiotDataLength];\n nbiotHTTPJSONDataSet().toCharArray(nbiotDataBuf, nbiotDataLength);\nif ((millis() / 1000) % 10 == 1 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCLOSE=0\\r\\n");\n serialSendState= 1;\n;} else if ((millis() / 1000) % 10 == 2) {\n serialSendState = 0;\n }if ((millis() / 1000) % 10 == 3 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCREATE=\\"http://maker.ifttt.com/\\"\\r\\n");\n nbiotSerial.write("AT+HTTPHEADER=0,\\"Content-Type: application/json\\\\r\\\\n\\"\\r\\n");\n serialSendState= 1;\n} else if ((millis() / 1000) % 10 == 4) {\n serialSendState = 0;\n }if ((millis() / 1000) % 10 == 5 && serialSendState == 0) {\n nbiotSerial.write(nbiotDataBuf);\n serialSendState= 1;\n} else if ((millis() / 1000) % 10 == 6) {\n serialSendState = 0;\n }if ((millis() / 1000) % 10 == 7 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPSEND=0,1,\\"/trigger/'+
- c+"/with/key/"+b+'\\"\\r\\n");\n serialSendState= 1;\n} else if ((millis() / 1000) % 10 == 8) {\n serialSendState = 0;\n }}\n');b='String nbiotHTTPJSONDataSet() {\n String data = "AT+HTTPCONTENT=0,\\"{";\n';for(c=0;c<a.itemCount_&&3>c;c++){d="value"+(c+1);var e=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_ATOMIC)||0;0<c&&(b+=' data += ",";\n');b+=' data += "\\"";\n data += "'+d+'";\n data += "\\":";\n data += '+e+";\n"}Blockly.Python.addFunction("nbiotHTTPJSONDataSet",b+' data += "}\\"\\r\\n";\n return data;\n}\n');
- return"nbiotIFTTTRequest();\n"};Blockly.Python.NBIoT_network_connected=function(a){return["_stateADDR",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.NBIoT_powered_on=function(a){return["_stateNbiotIsOn",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.NBIoT_network_IP=function(a){return["_IPADDR",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.NBIoT_http_cococloud_get=function(a){a=a.getFieldValue("APIKEY")||"";Blockly.Python.addFunction("nbiotHttprequestGet",'void nbiotHttprequestGet() {\n char nbiotDataBuf[nbiotDataLength];\n if ((millis() / 1000) % 10 == 1 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCLOSE=0\\r\\n");\n serialSendState= 1;\n; } else if ((millis() / 1000) % 10 == 2) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 3 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPCREATE=\\"http://api.cocorobo.cn/\\"\\r\\n");\n nbiotSerial.write("AT+HTTPHEADER=0,\\"User-Agent: Unknown\\r\\n\\"\\r\\n");\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 4) {\n serialSendState = 0;\n } if ((millis() / 1000) % 10 == 5 && serialSendState == 0) {\n nbiotSerial.write("AT+HTTPSEND=0,0,\\"/iot/data/eventAPIKey/'+a+
- '\\"\\r\\n");\n serialSendState= 1;\n } else if ((millis() / 1000) % 10 == 6) {\n serialSendState = 0;\n } }\n');return""};Blockly.Python.procedures={};
- Blockly.Python.procedures_defreturn=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=Blockly.Python.statementToCode(a,"STACK");Blockly.Python.STATEMENT_PREFIX&&(c=Blockly.Python.prefixLines(Blockly.Python.STATEMENT_PREFIX.replace(/%1/g,"'"+a.id+"'"),Blockly.Python.INDENT)+c);Blockly.Python.INFINITE_LOOP_TRAP&&(c=Blockly.Python.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+c);var d=Blockly.Python.valueToCode(a,"RETURN",Blockly.Python.ORDER_NONE)||
- "";d&&(d=" return "+d+";\n");for(var e=[],f=0;f<a.arguments_.length;f++)e[f]=Blockly.Python.getArduinoType_(a.getArgType(a.arguments_[f]))+" "+Blockly.Python.variableDB_.getName(a.arguments_[f],Blockly.Variables.NAME_TYPE);f=Blockly.Types.NULL;a.getReturnType&&(f=a.getReturnType());f=Blockly.Python.getArduinoType_(f);c=f+" "+b+"("+e.join(", ")+") {\n"+c+d+"}";c=Blockly.Python.scrub_(a,c);Blockly.Python.userFunctions_[b]=c;return null};Blockly.Python.procedures_defnoreturn=Blockly.Python.procedures_defreturn;
- Blockly.Python.procedures_callreturn=function(a){for(var b=Blockly.Python.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Python.valueToCode(a,"ARG"+d,Blockly.Python.ORDER_NONE)||"null";return[b+"("+c.join(", ")+")",Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.procedures_callnoreturn=function(a){for(var b=Blockly.Python.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Python.valueToCode(a,"ARG"+d,Blockly.Python.ORDER_NONE)||"null";return b+"("+c.join(", ")+");\n"};
- Blockly.Python.procedures_ifreturn=function(a){var b="if ("+(Blockly.Python.valueToCode(a,"CONDITION",Blockly.Python.ORDER_NONE)||"false")+") {\n";a.hasReturnValue_?(a=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"null",b+=" return "+a+";\n"):b+=" return;\n";return b+"}\n"};
- Blockly.Python.arduino_functions=function(a){var b=Blockly.Python.statementToCode(a,"SETUP_FUNC");b&&Blockly.Python.addSetup("userSetupCode",b,!0);a=a.getInputTargetBlock("LOOP_FUNC");b=Blockly.Python.blockToCode(a);if(!goog.isString(b))throw'Expecting code from statement block "'+a.type+'".';return b};Blockly.Python.robot={};Blockly.Python.screen={};
- Blockly.Python.lcd_setup=function(a){Blockly.Python.addInclude("Aadafruit_GFX","#include <Adafruit_GFX.h>");Blockly.Python.addInclude("Adafruit_SSD1351","#include <Adafruit_SSD1351.h>");Blockly.Python.addInclude("SPI","#include <SPI.h>");Blockly.Python.addDeclaration("SSD1351_CS","#define CS 8");Blockly.Python.addDeclaration("SSD1351_DC","#define DC 5");Blockly.Python.addDeclaration("SSD1351_RST","#define RST 6");Blockly.Python.addDeclaration("SSD1351_decl","Adafruit_SSD1351 tft = Adafruit_SSD1351(CS, DC, RST);");Blockly.Python.addSetup("SSD1351_begin",
- "tft.begin();\n tft.fillScreen(0x0000);\n",!1);return""};Blockly.Python.lcd_set_width_height=function(a){var b=Blockly.Python.valueToCode(a,"WIDTH",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"HEIGHT",Blockly.Python.ORDER_ATOMIC);return[b+", "+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.lcd_set_position=function(a){var b=Blockly.Python.valueToCode(a,"POSX",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSY",Blockly.Python.ORDER_ATOMIC);return[posConvert(b,a),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.lcd_drawline=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=Blockly.Python.valueToCode(a,"POSA",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSB",Blockly.Python.ORDER_ATOMIC);return"tft.drawLine("+c+", "+a+", "+b+");\n"};
- Blockly.Python.lcd_drawrect=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=Blockly.Python.valueToCode(a,"SIZE",Blockly.Python.ORDER_ATOMIC),d=a.getFieldValue("rect_type");a=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);return"tft."+d+"Rect("+a+", "+c+", "+b+");\n"};
- Blockly.Python.lcd_drawcircle=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=a.getFieldValue("circle_type"),d=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"RADIUS",Blockly.Python.ORDER_ATOMIC);return"tft."+c+"Circle("+d+", "+a+", "+b+");\n"};
- Blockly.Python.lcd_drawtriangle=function(a){var b=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),c=a.getFieldValue("triangle_type"),d=Blockly.Python.valueToCode(a,"POSA",Blockly.Python.ORDER_ATOMIC),e=Blockly.Python.valueToCode(a,"POSB",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"POSC",Blockly.Python.ORDER_ATOMIC);return"tft."+c+"Triangle("+d+", "+e+", "+a+","+b+");\n"};
- Blockly.Python.lcd_text=function(a){var b=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"POS",Blockly.Python.ORDER_ATOMIC),d=sharpTo565(Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)),e=Blockly.Python.valueToCode(a,"SIZE",Blockly.Python.ORDER_ATOMIC);a=a.getFieldValue("print_type");return"tft.setCursor("+c+");\ntft.setTextColor("+d+");\ntft.setTextSize("+e+");\ntft."+a+"("+b+");\n"};Blockly.Python.lcd_clear=function(a){return"tft.fillScreen(0x0000);\n"};
- Blockly.Python.lcd_rotation=function(a){return"tft.fillScreen(0x0000);\ntft.setRotation("+a.getFieldValue("DEGREE")+");\n"};Blockly.Python.lcd_set_color=function(a){return[a.getFieldValue("COLOR"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.lcd_set_colorRGB=function(a){var b=Blockly.Python.valueToCode(a,"RED_VAL",Blockly.Python.ORDER_ATOMIC),c=Blockly.Python.valueToCode(a,"GREEN_VAL",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"BLUE_VAL",Blockly.Python.ORDER_ATOMIC);return["("+b+","+c+","+a+")",Blockly.Python.ORDER_ATOMIC]};function posConvert(a,b){return a+", 128 - "+b};Blockly.Python.serial={};Blockly.Python.serial_print=function(a){for(var b=a.getFieldValue("SERIAL_ID"),c=Blockly.Python.valueToCode(a,"CONTENT",Blockly.Python.ORDER_ATOMIC)||"0",d="TRUE"==a.getFieldValue("NEW_LINE"),e=Blockly.Python.Boards.selected.serialPins[b],f=0;f<e.length;f++)Blockly.Python.reservePin(a,e[f][1],Blockly.Python.PinTypes.SERIAL,"SERIAL "+e[f][0]);return d?b+".println("+c+");\n":b+".print("+c+");\n"};
- Blockly.Python.serial_setup=function(a){var b=a.getFieldValue("SERIAL_ID");a=a.getFieldValue("SPEED");Blockly.Python.addSetup("serial_"+b,b+".begin("+a+");",!0);return""};Blockly.Python.serial1_write=function(a){var b=a.getFieldValue("SERIAL_ID");a=Blockly.Python.valueToCode(a,"CONTENT",Blockly.Python.ORDER_ATOMIC)||"0";return b+".write("+a+");\n"};Blockly.Python.serial1_read=function(a){return a.getFieldValue("SERIAL_ID")+".read();\n"};
- Blockly.Python.serial1_available=function(a){return[a.getFieldValue("SERIAL_ID")+".available();\n",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.servo={};Blockly.Python.servo_setup=function(a){Blockly.Python.addInclude("servo","#include <Servo.h>");return""};
- Blockly.Python.servo_write=function(a){var b=a.getFieldValue("SERVO_PIN"),c=Blockly.Python.valueToCode(a,"SERVO_ANGLE",Blockly.Python.ORDER_ATOMIC)||"90",d="myServo"+b;Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.SERVO,"Servo Write");Blockly.Python.addDeclaration("servo_"+b,"Servo "+d+";");Blockly.Python.addSetup("servo_"+b,d+".attach("+b+");",!0);return d+".write("+c+");\n"};
- Blockly.Python.servo_read=function(a){var b=a.getFieldValue("SERVO_PIN"),c="myServo"+b;Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.SERVO,"Servo Read");Blockly.Python.addDeclaration("servo_"+b,"Servo "+c+";");Blockly.Python.addSetup("servo_"+b,c+".attach("+b+");",!0);return[c+".read()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.robot_setup=function(a){var b=a.getFieldValue("YR_PIN"),c=a.getFieldValue("YL_PIN"),d=a.getFieldValue("RR_PIN"),e=a.getFieldValue("RL_PIN");Blockly.Python.reservePin(a,b,Blockly.Python.PinTypes.OUTPUT,"YR_pin");Blockly.Python.reservePin(a,c,Blockly.Python.PinTypes.OUTPUT,"YL_pin");Blockly.Python.reservePin(a,d,Blockly.Python.PinTypes.OUTPUT,"RR_pin");Blockly.Python.reservePin(a,e,Blockly.Python.PinTypes.OUTPUT,"RL_pin");Blockly.Python.addInclude("servo","#include <Servo.h>");Blockly.Python.addInclude("oscillator",
- "#include <Oscillator.h>");Blockly.Python.addInclude("EEPROM","#include <EEPROM.h>");Blockly.Python.addInclude("SERVO_QUANT_AMOUNTS","#define N_SERVOS 4");Blockly.Python.addInclude("EEPROM_TRIM","#define EEPROM_TRIM false");Blockly.Python.addInclude("SERVO_TRIMRR","#define TRIM_RR 7");Blockly.Python.addInclude("SERVO_TRIMRL","#define TRIM_RL 4");Blockly.Python.addInclude("SERVO_TRIMYR","#define TRIM_YR 4");Blockly.Python.addInclude("SERVO_TRIMYL","#define TRIM_YL 7\n");Blockly.Python.addDeclaration("robot_def",
- "#define PIN_YR "+b+"\n#define PIN_YL "+c+"\n#define PIN_RR "+d+"\n#define PIN_RL "+e+"\n#define INTERVALTIME 10.0\n\nOscillator servo[N_SERVOS];\n\nvoid goingUp(int tempo);\nvoid drunk (int tempo);\nvoid noGravity(int tempo);\nvoid kickLeft(int tempo);\nvoid kickRight(int tempo);\nvoid run(int steps, int T = 500);\nvoid walk(int steps, int T = 1000);\nvoid backyard(int steps, int T = 3000);\nvoid backyardSlow(int steps, int T = 5000);\nvoid turnLeft(int steps, int T = 3000);\nvoid turnRight(int steps, int T = 3000);\nvoid moonWalkLeft(int steps, int T = 1000);\nvoid moonWalkRight(int steps, int T = 1000);\nvoid crusaito(int steps, int T = 1000);\nvoid swing(int steps, int T = 1000);\nvoid upDown(int steps, int T = 1000);\nvoid flapping(int steps, int T = 1000);\n");
- Blockly.Python.addSetup("servo_setup","servo[0].attach(PIN_RR);\n servo[1].attach(PIN_RL);\n servo[2].attach(PIN_YR);\n servo[3].attach(PIN_YL);");Blockly.Python.addSetup("trim_setup","int trim;");Blockly.Python.addSetup("eeprom_setup",'if (EEPROM_TRIM) {\n for (int x = 0; x < 4; x++) {\n trim = EEPROM.read(x);\n if (trim > 128)trim = trim - 256;\n Serial.print("TRIM ");\n Serial.print(x);\n Serial.print(" en ");\n Serial.println(trim);\n servo[x].SetTrim(trim);\n }\n }\n else {\n servo[0].SetTrim(TRIM_RR);\n servo[1].SetTrim(TRIM_RL);\n servo[2].SetTrim(TRIM_YR);\n servo[3].SetTrim(TRIM_YL);\n }');
- Blockly.Python.addFunction("dance","void dance() {\n for ( int i = 0; i < 4; i++ ) {\n servo[i].SetPosition(90);\n }\n primera_parte();\n segunda_parte();\n moonWalkLeft(4, t * 2);\n moonWalkRight(4, t * 2);\n moonWalkLeft(4, t * 2);\n moonWalkRight(4, t * 2);\n primera_parte();\n crusaito(1, t * 8);\n crusaito(1, t * 7);\n for (int i = 0; i < 16; i++) {\n flapping(1, t / 4);\n delay(3 * t / 4);\n }\n moonWalkRight(4, t * 2);\n moonWalkLeft(4, t * 2);\n moonWalkRight(4, t * 2);\n moonWalkLeft(4, t * 2);\n drunk(t * 4);\n drunk(t * 4);\n kickLeft(t);\n kickRight(t);\n delay(t * 4);\n drunk(t / 2);\n delay(t * 4);\n walk(2, t * 2);\n backyard(2, t * 2);\n goingUp(t * 2);\n goingUp(t * 1);\n noGravity(t * 2);\n crusaito(1, t * 2);\n crusaito(1, t * 8);\n crusaito(1, t * 2);\n crusaito(1, t * 8);\n crusaito(1, t * 2);\n crusaito(1, t * 3);\n delay(t);\n primera_parte();\n for (int i = 0; i < 32; i++) {\n flapping(1, t / 2);\n delay(t / 2);\n }\n for ( int i = 0; i < 4; i++ ) {\n servo[i].SetPosition(90);\n }\n}\n");
- Blockly.Python.addFunction("oscillate","void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]) {\n for (int i = 0; i < 4; i++) {\n servo[i].SetO(O[i]);\n servo[i].SetA(A[i]);\n servo[i].SetT(T);\n servo[i].SetPh(phase_diff[i]);\n }\n double ref = millis();\n for (double x = ref; x < T + ref; x = millis()) {\n for (int i = 0; i < 4; i++) {\n servo[i].refresh();\n }\n }\n}");Blockly.Python.addFunction("moveNServos","unsigned long final_time;\nunsigned long interval_time;\nint oneTime;\nint iteration;\nfloat increment[N_SERVOS];\nint oldPosition[] = {90, 90, 90, 90};\n\nvoid moveNServos(int time, int newPosition[]) {\n for (int i = 0; i < N_SERVOS; i++) increment[i] = ((newPosition[i]) - oldPosition[i]) / (time / INTERVALTIME);\n final_time = millis() + time;\n iteration = 1;\n while (millis() < final_time) { //Javi del futuro cambia esto\n interval_time = millis() + INTERVALTIME;\n oneTime = 0;\n while (millis() < interval_time) {\n if (oneTime < 1) {\n for (int i = 0; i < N_SERVOS; i++) {\n servo[i].SetPosition(oldPosition[i] + (iteration * increment[i]));\n }\n iteration++;\n oneTime++;\n }\n }\n }\n for (int i = 0; i < N_SERVOS; i++) {\n oldPosition[i] = newPosition[i];\n }\n}");
- Blockly.Python.addFunction("goingUp","void goingUp(int tempo) {\n pause = millis();\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n delay(tempo);\n servo[0].SetPosition(80);\n servo[1].SetPosition(100);\n delay(tempo);\n servo[0].SetPosition(70);\n servo[1].SetPosition(110);\n delay(tempo);\n servo[0].SetPosition(60);\n servo[1].SetPosition(120);\n delay(tempo);\n servo[0].SetPosition(50);\n servo[1].SetPosition(130);\n delay(tempo);\n servo[0].SetPosition(40);\n servo[1].SetPosition(140);\n delay(tempo);\n servo[0].SetPosition(30);\n servo[1].SetPosition(150);\n delay(tempo);\n servo[0].SetPosition(20);\n servo[1].SetPosition(160);\n delay(tempo);\n while (millis() < pause + 8 * t);\n}");
- Blockly.Python.addFunction("primera_parte","void primera_parte() {\n int move1[4] = {60, 120, 90, 90};\n int move2[4] = {90, 90, 90, 90};\n int move3[4] = {40, 140, 90, 90};\n for (int x = 0; x < 3; x++) {\n for (int i = 0; i < 3; i++) {\n lateral_fuerte(1, t / 2);\n lateral_fuerte(0, t / 4);\n lateral_fuerte(1, t / 4);\n delay(t);\n }\n pause = millis();\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n moveNServos(t * 0.4, move1);\n moveNServos(t * 0.4, move2);\n while (millis() < (pause + t * 2));\n }\n for (int i = 0; i < 2; i++) {\n lateral_fuerte(1, t / 2);\n lateral_fuerte(0, t / 4);\n lateral_fuerte(1, t / 4);\n delay(t);\n }\n pause = millis();\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n crusaito(1, t * 1.4);\n moveNServos(t * 1, move3);\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n while (millis() < (pause + t * 4));\n}");
- Blockly.Python.addFunction("segunda_parte","void segunda_parte() {\n int move1[4] = {90, 90, 80, 100};\n int move2[4] = {90, 90, 100, 80};\n int move3[4] = {90, 90, 80, 100};\n int move4[4] = {90, 90, 100, 80};\n int move5[4] = {40, 140, 80, 100};\n int move6[4] = {40, 140, 100, 80};\n int move7[4] = {90, 90, 80, 100};\n int move8[4] = {90, 90, 100, 80};\n int move9[4] = {40, 140, 80, 100};\n int move10[4] = {40, 140, 100, 80};\n int move11[4] = {90, 90, 80, 100};\n int move12[4] = {90, 90, 100, 80};\n for (int x = 0; x < 7; x++) {\n for (int i = 0; i < 3; i++) {\n pause = millis();\n moveNServos(t * 0.15, move1);\n moveNServos(t * 0.15, move2);\n moveNServos(t * 0.15, move3);\n moveNServos(t * 0.15, move4);\n while (millis() < (pause + t));\n }\n pause = millis();\n moveNServos(t * 0.15, move5);\n moveNServos(t * 0.15, move6);\n moveNServos(t * 0.15, move7);\n moveNServos(t * 0.15, move8);\n while (millis() < (pause + t));\n }\n for (int i = 0; i < 3; i++) {\n pause = millis();\n moveNServos(t * 0.15, move9);\n moveNServos(t * 0.15, move10);\n moveNServos(t * 0.15, move11);\n moveNServos(t * 0.15, move12);\n while (millis() < (pause + t));\n }\n}");
- Blockly.Python.addFunction("lateral_fuerte","void lateral_fuerte(boolean side, int tempo) {\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n if (side) servo[0].SetPosition(40);\n else servo[1].SetPosition(140);\n delay(tempo / 2);\n servo[0].SetPosition(90);\n servo[1].SetPosition(90);\n delay(tempo / 2);\n}");Blockly.Python.addFunction("drunk","void drunk (int tempo) {\n pause = millis();\n int move1[] = {60, 70, 90, 90};\n int move2[] = {110, 120, 90, 90};\n int move3[] = {60, 70, 90, 90};\n int move4[] = {110, 120, 90, 90};\n moveNServos(tempo * 0.235, move1);\n moveNServos(tempo * 0.235, move2);\n moveNServos(tempo * 0.235, move3);\n moveNServos(tempo * 0.235, move4);\n while (millis() < (pause + tempo));\n}");
- Blockly.Python.addFunction("noGravity","void noGravity(int tempo) {\n int move1[4] = {120, 140, 90, 90};\n int move2[4] = {140, 140, 90, 90};\n int move3[4] = {120, 140, 90, 90};\n int move4[4] = {90, 90, 90, 90};\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n for (int i = 0; i < N_SERVOS; i++) oldPosition[i] = 90;\n moveNServos(tempo * 2, move1);\n moveNServos(tempo * 2, move2);\n delay(tempo * 2);\n moveNServos(tempo * 2, move3);\n moveNServos(tempo * 2, move4);\n}");Blockly.Python.addFunction("kickLeft",
- "void kickLeft(int tempo) {\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n delay(tempo);\n servo[0].SetPosition(50);\n servo[1].SetPosition(70);\n delay(tempo);\n servo[0].SetPosition(80);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(30);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(80);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(30);\n servo[1].SetPosition(70);\n delay(tempo / 4);\n servo[0].SetPosition(80);\n servo[1].SetPosition(70);\n delay(tempo);\n}");
- Blockly.Python.addFunction("kickRight","void kickRight(int tempo) {\n for (int i = 0; i < 4; i++) servo[i].SetPosition(90);\n delay(tempo);\n servo[0].SetPosition(110);\n servo[1].SetPosition(130);\n delay(tempo);\n servo[0].SetPosition(110);\n servo[1].SetPosition(100);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(150);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(80);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(150);\n delay(tempo / 4);\n servo[0].SetPosition(110);\n servo[1].SetPosition(100);\n delay(tempo);\n}");
- Blockly.Python.addFunction("walk","void walk(int steps, int T) {\n int A[4] = {15, 15, 30, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("run","void run(int steps, int T) {\n int A[4] = {10, 10, 10, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");
- Blockly.Python.addFunction("backyard","void backyard(int steps, int T) {\n int A[4] = {15, 15, 30, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("backyardSlow","void backyardSlow(int steps, int T) {\n int A[4] = {15, 15, 30, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");
- Blockly.Python.addFunction("turnLeft","void turnLeft(int steps, int T) {\n int A[4] = {20, 20, 10, 30};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("turnRight","void turnRight(int steps, int T) {\n int A[4] = {20, 20, 30, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");
- Blockly.Python.addFunction("turnRight","void turnRight(int steps, int T) {\n int A[4] = {20, 20, 30, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("turnRight","void turnRight(int steps, int T) {\n int A[4] = {20, 20, 30, 10};\n int O[4] = {0, 0, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");
- Blockly.Python.addFunction("crusaito","void crusaito(int steps, int T) {\n int A[4] = {25, 25, 30, 30};\n int O[4] = { - 15, 15, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("swing","void swing(int steps, int T) {\n int A[4] = {25, 25, 0, 0};\n int O[4] = { -15, 15, 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");
- Blockly.Python.addFunction("upDown","void upDown(int steps, int T) {\n int A[4] = {25, 25, 0, 0};\n int O[4] = { -15, 15, 0, 0};\n double phase_diff[4] = {DEG2RAD(180), DEG2RAD(0), DEG2RAD(270), DEG2RAD(270)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}");Blockly.Python.addFunction("flapping","void flapping(int steps, int T) {\n int A[4] = {15, 15, 8, 8};\n int O[4] = { -A[0], A[1], 0, 0};\n double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};\n for (int i = 0; i < steps; i++)oscillate(A, O, T, phase_diff);\n}")};
- Blockly.Python.robot_set_movement=function(a){var b=Blockly.Python.valueToCode(a,"MOVEMENT",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"TEMPO",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("robot_setmovement_def","int t = "+a+";\ndouble pause = 0;\n");switch(b){case "goingUp":case "drunk":case "kickLeft":case "kickRight":a="(";break;default:a="(1, "}return b+a+" 2*t);\n"};Blockly.Python.robot_movement=function(a){return[a.getFieldValue("MOVEMENT"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.robot_tempo=function(a){return[a.getFieldValue("TEMPO"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.spi={};Blockly.Python.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.Python.addInclude("spi","#include <SPI.h>");Blockly.Python.addSetup("spi_order",b+".setBitOrder("+c+");",!0);Blockly.Python.addSetup("spi_mode",b+".setDataMode("+a+");",!0);Blockly.Python.addSetup("spi_div",b+".setClockDivider("+d+");",!0);Blockly.Python.addSetup("spi_begin",b+".begin();",!0);return""};
- Blockly.Python.spi_transfer=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SS"),d=Blockly.Python.valueToCode(a,"SPI_DATA",Blockly.Python.ORDER_ATOMIC)||"0";Blockly.Python.addInclude("spi","#include <SPI.h>");Blockly.Python.addSetup("spi_begin",b+".begin();",!1);for(var e=Blockly.Python.Boards.selected.spiPins[b],f=0;f<e.length;f++)Blockly.Python.reservePin(a,e[f][1],Blockly.Python.PinTypes.SPI,"SPI "+e[f][0]);"none"!==c&&(Blockly.Python.reservePin(a,c,Blockly.Python.PinTypes.OUTPUT,
- "SPI Slave pin"),Blockly.Python.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.Python.spi_transfer_return=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SS"),d=Blockly.Python.valueToCode(a,"SPI_DATA",Blockly.Python.ORDER_ATOMIC)||"0";Blockly.Python.spi_transfer(a);return["none"===c?b+".transfer("+d+")":Blockly.Python.addFunction("spiReturnSlave"+c,["int "+Blockly.Python.DEF_FUNC_NAME+"() {"," int spiReturn = 0;"," digitalWrite("+c+", HIGH);"," spiReturn = "+b+".transfer("+d+");"," digitalWrite("+c+", LOW);"," return spiReturn;\n}"].join("\n"))+
- "()",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.stepper={};
- Blockly.Python.stepper_config=function(a){var b=a.getFieldValue("STEPPER_PIN1"),c=a.getFieldValue("STEPPER_PIN2"),d=Blockly.Python.PinTypes.STEPPER,e=a.getFieldValue("STEPPER_NAME"),f=Blockly.Python.valueToCode(a,"STEPPER_STEPS",Blockly.Python.ORDER_ATOMIC)||"360",g=Blockly.Python.valueToCode(a,"STEPPER_SPEED",Blockly.Python.ORDER_ATOMIC)||"90";Blockly.Python.addVariable(e,"int "+e+"[2] = {"+b+", "+c+"};",!0);e="stepper_"+e;Blockly.Python.reservePin(a,b,d,"Stepper");Blockly.Python.reservePin(a,c,
- d,"Stepper");Blockly.Python.addInclude("stepper","#include <Stepper.h>");Blockly.Python.addDeclaration(e,"Stepper "+e+"("+f+", "+b+", "+c+");");Blockly.Python.addSetup(e,e+".setSpeed("+g+");",!0);return""};Blockly.Python.stepper_step=function(a){var b="stepper_"+a.getFieldValue("STEPPER_NAME");a=Blockly.Python.valueToCode(a,"STEPPER_STEPS",Blockly.Python.ORDER_ATOMIC)||"0";return b+".step("+a+");\n"};Blockly.Python.text={};Blockly.Python.text=function(a){return[Blockly.Python.quote_(a.getFieldValue("TEXT")),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.text_join=function(a){if(0==a.itemCount_)return['""',Blockly.Python.ORDER_ATOMIC];if(1==a.itemCount_)return["String("+(Blockly.Python.valueToCode(a,"ADD0",Blockly.Python.ORDER_UNARY_POSTFIX)||'""')+")",Blockly.Python.ORDER_UNARY_POSTFIX];var b=[];for(var c=0;c<a.itemCount_;c++){var d=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_NONE);b[c]=""==d?'""':"String("+d+")"}b=b.join(" + ");return[b,Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.text_append=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);a=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_UNARY_POSTFIX);return b+" += "+(""==a?'""':"String("+a+")")+";\n"};Blockly.Python.text_length=function(a){return["String("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_UNARY_POSTFIX)||'""')+").length()",Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.text_isEmpty=function(a){var b=[];b.push("boolean "+Blockly.Python.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.Python.addFunction("isStringEmpty",b.join("\n"));a=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_UNARY_POSTFIX);return[b+"("+(""==a?'""':"String("+a+")")+")",Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.text_trim=function(a){Blockly.Python.text_trim.OPERATORS={LEFT:".trim()",RIGHT:".trim()",BOTH:".trim()"};var b=a.getFieldValue("MODE");b=Blockly.Python.text_trim.OPERATORS[b];a=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_UNARY_POSTFIX);return[(""==a?'""':"String("+a+")")+b,Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.text_print=function(a){var b=Blockly.Python.Boards.selected.serial[0][1];Blockly.Python.addSetup("serial_"+b,b+".begin(9600);",!1);a=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE);return b+".print("+(""==a?'""':"String("+a+")")+");\n"};
- Blockly.Python.text_prompt_ext=function(a){var b=Blockly.Python.Boards.selected.serial[0][1],c=a.getFieldValue("TYPE"),d=[],e=c==Blockly.Types.NUMBER.output;e?d.push("int "+Blockly.Python.DEF_FUNC_NAME+"(String msg) {"):d.push("String "+Blockly.Python.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.Python.addFunction("getUserInputPrompt"+
- c,d.join("\n"));Blockly.Python.addSetup("serial_"+b,b+".begin(9600);",!1);a=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE)||'""';return[c+"("+a+")",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.text_endString=function(a){return["",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.text_indexOf=function(a){return["",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.text_charAt=function(a){return["",Blockly.Python.ORDER_UNARY_POSTFIX]};
- Blockly.Python.text_getSubstring=function(a){return["",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.text_changeCase=function(a){return["",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.text_prompt=function(a){return["",Blockly.Python.ORDER_UNARY_POSTFIX]};Blockly.Python.third_party={};
- Blockly.Python.sonar_setup=function(a){Blockly.Python.addInclude("NewPing","#include <NewPing.h>");var b="sonar"+a.getFieldValue("NUMBER"),c=a.getFieldValue("TRIG_PIN"),d=a.getFieldValue("ECHO_PIN");Blockly.Python.reservePin(a,c,Blockly.Python.PinTypes.OUTPUT,"Sonar_Trig_Pin"+c);Blockly.Python.reservePin(a,d,Blockly.Python.PinTypes.OUTPUT,"Sonar_Echo_Pin"+d);a=a.getFieldValue("MAXDIST");var e="TRIG_"+c,f="ECHO_"+d,g="MAXDIST_"+c+"_"+d;Blockly.Python.addDeclaration("define_"+b,"#define "+e+" "+
- c+"\n#define "+f+" "+d+"\n#define "+g+" "+a+"\nNewPing "+b+"("+e+", "+f+", "+g+");\n");return""};Blockly.Python.sonar_read_dist=function(a){return["sonar"+a.getFieldValue("NUMBER")+".ping_cm()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.infraredRay_setup=function(a){Blockly.Python.addInclude("IRLib","#include <IRLibDecodeBase.h>\n#include <IRLib_P01_NEC.h>\n#include <IRLibCombo.h>\nIRdecode myDecoder;\n#include <IRLibRecv.h>\nIRrecv myReceiver(A2);\n");Blockly.Python.addDeclaration("IR_keys_def","#define KEYPAD_UP 0xFF18E7\n#define KEYPAD_DOWN 0xFF4AB5\n#define KEYPAD_LEFT 0xFF10EF\n#define KEYPAD_RIGHT 0xFF5AA5\n#define KEYPAD_OK 0xFF38C7\n#define KEYPAD_1 0xFFA25D\n#define KEYPAD_2 0xFF629D\n#define KEYPAD_3 0xFFE21D\n#define KEYPAD_4 0xFF22DD\n#define KEYPAD_5 0xFF02FD\n#define KEYPAD_6 0xFFC23D\n#define KEYPAD_7 0xFFE01F\n#define KEYPAD_8 0xFFA857\n#define KEYPAD_9 0xFF906F\n#define KEYPAD_0 0xFF9867\n#define KEYPAD_STAR 0xFF6897\n#define KEYPAD_NUMSIGN 0xFFB04F\n");
- Blockly.Python.addSetup("IR_setup","Serial.begin(9600);\ndelay(2000);\nmyReceiver.enableIRIn();",!1);return"if (myReceiver.getResults()) {\nmyDecoder.decode(); \n// myDecoder.dumpResults(true);\nmyReceiver.enableIRIn();\n}\n"};Blockly.Python.infraredRay_receive_val=function(a){return["myDecoder.value",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.infraredRay_send_val=function(a){return[a.getFieldValue("VALTYPE"),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.RTC_setup=function(a){Blockly.Python.addInclude("RTC_include",'#include <Wire.h> //include Wire.h library \n#include "RTClib.h" //include Adafruit RTC library');Blockly.Python.addDeclaration("RTC_declaration",'RTC_DS3231 rtc; //Make a RTC DS3231 object\n //Set the names of days\nchar daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};');Blockly.Python.addSetup("RTC_setup",' Serial.begin(9600);\n if (! rtc.begin()) {\n Serial.println("Couldn\'t find RTC");\n while (1);\n }\n //Setup of time if RTC lost power or time is not set\n if (rtc.lostPower()) {\n //Sets the code compilation time to RTC DS3231\n rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\n }\n');
- return"DateTime now = rtc.now();\n"};Blockly.Python.RTC_setDateTime=function(a){var b=a.getFieldValue("hour"),c=a.getFieldValue("minute"),d=a.getFieldValue("second"),e=a.getFieldValue("year"),f=a.getFieldValue("month");a=a.getFieldValue("day");Blockly.Python.addSetup("RTC_set","rtc.adjust(DateTime("+e+","+f+","+a+","+b+","+c+","+d+"));");return""};
- Blockly.Python.RTC_getDate=function(a){var b="";switch(a.getFieldValue("date_detail")){case "year":b="now.year()";break;case "month":b="now.month()";break;case "day":b="now.day()"}return[b,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.RTC_getTime=function(a){var b="";switch(a.getFieldValue("time_detail")){case "hour":b="now.hour()";break;case "minute":b="now.minute()";break;case "second":b="now.second()"}return[b,Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.RTC_getWeek=function(a){return["daysOfTheWeek[now.dayOfTheWeek()]",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.PulseSensor_setup=function(a){a=a.getFieldValue("PIN");Blockly.Python.addInclude("PulseSensor_inc","#define USE_ARDUINO_INTERRUPTS true\n#include <PulseSensorPlayground.h>");Blockly.Python.addDeclaration("PulseSensor_dec","const int OUTPUT_TYPE = SERIAL_PLOTTER;\nconst int PIN_INPUT = "+a+";\nconst int THRESHOLD = 550;\nPulseSensorPlayground pulseSensor;");Blockly.Python.addSetup("PulseSensor_setup","pulseSensor.analogInput(PIN_INPUT);\n pulseSensor.setSerial(Serial);\n pulseSensor.setOutputType(OUTPUT_TYPE);\n pulseSensor.setThreshold(THRESHOLD);\n if (!pulseSensor.begin())\n {\n for (;;) {}\n }");
- return""};Blockly.Python.PulseSensor_getBPM=function(a){return["pulseSensor.getBeatsPerMinute()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.PulseSensor_Heart_Beats=function(a){return["pulseSensor.sawStartOfBeat()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.PulseSensor_Heart_noBeats=function(a){return["pulseSensor.isInsideBeat() == false",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.PulseSensor_print=function(a){return"pulseSensor.outputSample();\n"};
- Blockly.Python.Encoder_Setup=function(a){a=a.getFieldValue("PIN");Blockly.Python.addDeclaration("Encoder_dec","int encoderCounter = 0;\nunsigned long encoderTime = 0, old_encoderTime = 0;\nunsigned long encoderTime1 = 0;\nfloat encoderSpeed;\n");Blockly.Python.addSetup("Encoder_setup","Serial.begin(9600);\nattachInterrupt("+a+", encoderCount_CallBack, FALLING);\n");Blockly.Python.addFunction("Encoder_func","bool SpeedDetection()\n{\n encoderTime = millis();\n if (abs(encoderTime - old_encoderTime) >= 1000)\n {\n detachInterrupt("+
- a+");\n encoderSpeed = (float)encoderCounter * 60 / 20;\n encoderCounter = 0;\n old_encoderTime = millis();\n attachInterrupt("+a+", encoderCount_CallBack, FALLING); \n return 1;\n }\n else\n return 0;\n}\n\nvoid encoderCount_CallBack()\n{\n encoderCounter++;\n}");return"SpeedDetection();\n"};Blockly.Python.Encoder_getRotationSpeed=function(a){return["encoderSpeed",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.RFID_Setup=function(a){Blockly.Python.addInclude("RFID_include","#include <SPI.h>\n#include <MFRC522.h>");Blockly.Python.addDeclaration("RFID_dec",'#define SS_PIN SS\nMFRC522 rfid(SS_PIN); // Instance of the class\nMFRC522::MIFARE_Key key;\nbyte nuidPICC[4];\nchar NUID[4];\nString nuid_str="null";');Blockly.Python.addSetup("RFID_setup",'Serial.begin(9600);\nSPI.begin(); // Init SPI bus\nrfid.PCD_Init(); // Init MFRC522\nfor (byte i = 0; i < 6; i++) {\n key.keyByte[i] = 0xFF;\n}\nSerial.println(F("This code scan the MIFARE Classsic NUID."));\nSerial.print(F("Using the following key:"));\nprintHex(key.keyByte, MFRC522::MF_KEY_SIZE);\n');
- Blockly.Python.addFunction("RFID_printHex","void printHex(byte *buffer, byte bufferSize) {\n for (byte i = 0; i < bufferSize; i++) {\n Serial.print(buffer[i], HEX);\n }\n}");Blockly.Python.addFunction("RFID_tohex","String tohex(int n) {\n if (n == 0) {\n return \"00\"; //n\u4e3a0\n }\n String result = \"\";\n char _16[] = {'0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F'};\n const int radix = 16;\n while (n) {\n int i = n % radix;\n result = _16[i] + result;\n n /= radix;\n }\n if (result.length() < 2) {\n result = '0' + result;\n }\n return result;\n}");
- return'// Look for new cards\nif (!rfid.PICC_IsNewCardPresent())\n return;\nif (!rfid.PICC_ReadCardSerial())\n return;\nMFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);\n// Check is the PICC of Classic MIFARE type\nif (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&\n piccType != MFRC522::PICC_TYPE_MIFARE_1K &&\n piccType != MFRC522::PICC_TYPE_MIFARE_4K) {\n Serial.println(F("Your tag is not supported"));\n return;\n}\n// Store NUID into nuidPICC array\nfor (byte i = 0; i < 4; i++) {\n nuidPICC[i] = rfid.uid.uidByte[i];\n}\n//Store NUID into nuid_str\nnuid_str="";\nfor (byte i = 0; i < 4; i++) {\n nuid_str += tohex(rfid.uid.uidByte[i]);\n}\n// Halt PICC\nrfid.PICC_HaltA();\n// Stop encryption on PCD\nrfid.PCD_StopCrypto1();\n'};
- Blockly.Python.RFID_ReadID=function(a){return["nuid_str",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.GPS_setup=function(a){Blockly.Python.addInclude("GPS_include","#include <SoftwareSerial.h>\nSoftwareSerial gpsSerial(11,10);// MOSI");Blockly.Python.addDeclaration("GPS_Dec","struct\n{\n char GPS_Buffer[80];\n bool isGetData;\n bool isParseData;\n char UTCTime[11];\n char latitude[11];\n char N_S[2];\n char longitude[12];\n char E_W[2];\n bool isUsefull;\n} Save_Data;\nconst unsigned int gpsRxBufferLength = 600;\nchar gpsRxBuffer[gpsRxBufferLength];\nunsigned int ii = 0;\nString GPSMODULEstringLat, GPSMODULEstringLong, GPSMODULEgpsLatitude, GPSMODULEgpsLongitude;\nfloat GPSMODULEfloatLat, GPSMODULEfloatLon;\n");Blockly.Python.addSetup("GPS_Setup",
- "gpsSerial.begin(9600);\n Save_Data.isGetData = false;\n Save_Data.isParseData = false;\n Save_Data.isUsefull = false;\n");Blockly.Python.addFunction("gpsMoudle","void gpsModule() {\n gpsRead();\n parseGpsBuffer();\n convertRealCoordinate();\n}\n");Blockly.Python.addFunction("convertRealCoordinate","void convertRealCoordinate() {\n String GPSMODULEstringLat = Save_Data.latitude;\n String GPSMODULEstringLon = Save_Data.longitude;\n float GPSMODULEfloatLat = GPSMODULEstringLat.toFloat();\n float GPSMODULEfloatLon = GPSMODULEstringLon.toFloat();\n GPSMODULEgpsLatitude = String(convertDegMinToDecDeg(GPSMODULEfloatLat), 7);\n GPSMODULEgpsLongitude = String(convertDegMinToDecDeg(GPSMODULEfloatLon), 7);\n}\n");
- Blockly.Python.addFunction("convertDegMinToDecDeg","double convertDegMinToDecDeg (float degMin) {\n double min = 0.0;\n double decDeg = 0.0;\n //get the minutes, fmod() requires double\n min = fmod((double)degMin, 100.0);\n //rebuild coordinates in decimal degrees\n degMin = (int) ( degMin / 100 );\n decDeg = degMin + ( min / 60 );\n return decDeg;\n}\n");Blockly.Python.addFunction("errorLog",'void errorLog(int num)\n{\n Serial.print("ERROR");\n Serial.println(num);\n while (1)\n {\n Serial.flush();\n }\n}\n');
- Blockly.Python.addFunction("printGpsBuffer",'void printGpsBuffer()\n{\n if (Save_Data.isParseData)\n {\n Save_Data.isParseData = false;\n Serial.print("Save_Data.UTCTime = ");\n Serial.println(Save_Data.UTCTime);\n if (Save_Data.isUsefull)\n {\n Save_Data.isUsefull = false;\n Serial.print("Save_Data.latitude = ");\n Serial.println(Save_Data.latitude);\n Serial.print("Save_Data.N_S = ");\n Serial.println(Save_Data.N_S);\n Serial.print("Save_Data.longitude = ");\n Serial.println(Save_Data.longitude);\n Serial.print("Save_Data.E_W = ");\n Serial.println(Save_Data.E_W);\n } else {\n Serial.println("GPS DATA is not usefull!");\n }\n }\n}\n');
- Blockly.Python.addFunction("parseGpsBuffer",'void parseGpsBuffer()\n{\n char *subString;\n char *subStringNext;\n if (Save_Data.isGetData)\n {\n Save_Data.isGetData = false;\n Serial.println("**************");\n Serial.println(Save_Data.GPS_Buffer);\n for (int i = 0 ; i <= 6 ; i++)\n {\n if (i == 0)\n {\n if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)\n errorLog(1); // Parse error\n }\n else\n {\n subString++;\n if ((subStringNext = strstr(subString, ",")) != NULL)\n {\n char usefullBuffer[2];\n switch (i)\n {\n case 1: memcpy(Save_Data.UTCTime, subString, subStringNext - subString); break;\n case 2: memcpy(usefullBuffer, subString, subStringNext - subString); break;\n case 3: memcpy(Save_Data.latitude, subString, subStringNext - subString); break;\n case 4: memcpy(Save_Data.N_S, subString, subStringNext - subString); break;\n case 5: memcpy(Save_Data.longitude, subString, subStringNext - subString); break;\n case 6: memcpy(Save_Data.E_W, subString, subStringNext - subString); break;\n default: break;\n }\n subString = subStringNext;\n Save_Data.isParseData = true;\n if (usefullBuffer[0] == \'A\')\n Save_Data.isUsefull = true;\n else if (usefullBuffer[0] == \'V\')\n Save_Data.isUsefull = false;\n }\n else\n {\n errorLog(2);\n }\n }\n }\n }\n}\n');
- Blockly.Python.addFunction("gpsRead",'void gpsRead() {\n while (gpsSerial.available())\n {\n gpsRxBuffer[ii++] = gpsSerial.read();\n if (ii == gpsRxBufferLength)clrGpsRxBuffer();\n }\n char* GPS_BufferHead;\n char* GPS_BufferTail;\n if ((GPS_BufferHead = strstr(gpsRxBuffer, "$GPRMC,")) != NULL || (GPS_BufferHead = strstr(gpsRxBuffer, "$GNRMC,")) != NULL )\n {\n if (((GPS_BufferTail = strstr(GPS_BufferHead, "\\r\\n")) != NULL) && (GPS_BufferTail > GPS_BufferHead))\n {\n memcpy(Save_Data.GPS_Buffer, GPS_BufferHead, GPS_BufferTail - GPS_BufferHead);\n Save_Data.isGetData = true;\n clrGpsRxBuffer();\n }\n }\n}\n');
- Blockly.Python.addFunction("clrGpsRxBuffer","void clrGpsRxBuffer(void) {\n memset(gpsRxBuffer, 0, gpsRxBufferLength);\n ii = 0;\n}\n");return["gpsModule();\n",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.GPS_getLatitude=function(a){return["GPSMODULEgpsLatitude",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.GPS_getLongitude=function(a){return["GPSMODULEgpsLongitude",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.water_temp_sensor_setup=function(a){a.getFieldValue("water_temp_sensor_setup_dropdown");a=a.getFieldValue("water_temp_sensor_setup_pin");Blockly.Python.addDeclaration("water_temp_sensor_setup_DECLARATION","#include <OneWire.h>\nint DS18S20_Pin = "+a+";\nOneWire ds(DS18S20_Pin);\n");Blockly.Python.addFunction("water_temp_sensor_setup_FUNCTION",'float getDS18S20WaterTemp() {\nbyte data[12];\nbyte addr[8];\nif ( !ds.search(addr)) {\n ds.reset_search();\n return -1000;\n}\nif ( OneWire::crc8( addr, 7) != addr[7]) {\n Serial.println("CRC is not valid!");\n return -1000;\n}\nif ( addr[0] != 0x10 && addr[0] != 0x28) {\n Serial.print("Device is not recognized");\n return -1000;\n}\nds.reset(); \nds.select(addr); \nds.write(0x44, 1); \nbyte present = ds.reset(); \nds.select(addr); \nds.write(0xBE); \nfor (int i = 0; i < 9; i++) { \n data[i] = ds.read(); \n} \nds.reset_search();\nbyte MSB = data[1];\nbyte LSB = data[0];\nfloat tempRead = ((MSB << 8) | LSB);\nfloat TemperatureSum = tempRead / 16;\nreturn TemperatureSum;\n}\n');
- return["float getWaterTempValue = getDS18S20WaterTemp();\n",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.water_temp_sensor_get_value=function(a){return["getWaterTempValue",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.thirdparty_co2_sensor_setup=function(a){a.getFieldValue("thirdparty_co2_sensor_setup_sdapin");a.getFieldValue("thirdparty_co2_sensor_setup_sclpin");Blockly.Python.addInclude("thirdparty_co2_sensor_setup_include",'#include "Adafruit_CCS811.h"\n');Blockly.Python.addDeclaration("thirdparty_co2_sensor_setup_declaration","Adafruit_CCS811 ccs;\nuint16_t _ccs811getCO2, _ccs811getTVOC;\n");Blockly.Python.addFunction("thirdparty_co2_sensor_setup_function",'void _ccs811Setup() {\n Serial.begin(9600);\n Serial.println("CCS811 test");\n if (!ccs.begin()) {\n Serial.println("Failed to start sensor! Please check your wiring.");\n while (1);\n }\n while (!ccs.available());\n}\n\nvoid _ccs811Main() {\n if (ccs.available()) {\n if (!ccs.readData()) {\n _ccs811getCO2 = ccs.geteCO2();\n _ccs811getTVOC = ccs.getTVOC();\n }\n else {\n Serial.println("ERROR!");\n while (1);\n }\n }\n delay(100);\n}\n');
- Blockly.Python.addSetup("thirdparty_co2_sensor_setup_setup","_ccs811Setup();\n");return["_ccs811Main();\n",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.thirdparty_co2_sensor_get_co2=function(a){return["_ccs811getCO2",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.thirdparty_co2_sensor_get_tvoc=function(a){return["_ccs811getTVOC",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.thirdparty_nrf24l01_setup=function(a){a.getFieldValue("thirdparty_nrf24l01_setup_dropdown_cepin");a.getFieldValue("thirdparty_nrf24l01_setup_dropdown_csnpin");a=a.getFieldValue("thirdparty_nrf24l01_setup_addr");Blockly.Python.addInclude("thirdparty_nrf24l01_setup_include","#include <SPI.h>\n#include <nRF24L01.h>\n#include <RF24.h>)\n");Blockly.Python.addDeclaration("thirdparty_nrf24l01_setup_declaration",'RF24 radio(7, 5);\nconst byte address[6] = "'+a+'";\n');Blockly.Python.addSetup("thirdparty_nrf24l01_setup_setup",
- "radio.begin();\n");return""};Blockly.Python.thirdparty_nrf24l01_send_data=function(a){a=a.getFieldValue("thirdparty_nrf24l01_send_data_data");Blockly.Python.addSetup("thirdparty_nrf24l01_send_data_setup","radio.openWritingPipe(address);\nradio.setPALevel(RF24_PA_MIN);\nradio.stopListening();\n");return'const char text[] = "'+a+'";\nradio.write(&text, sizeof(text));\n'};
- Blockly.Python.thirdparty_nrf24l01_receive_data=function(a){Blockly.Python.addDeclaration("thirdparty_nrf24l01_receive_data_declare",'char _nrfText[32] = "";\n');Blockly.Python.addSetup("thirdparty_nrf24l01_receive_data_setup","radio.openReadingPipe(0, address);\nradio.setPALevel(RF24_PA_MIN);\nradio.startListening();\n");Blockly.Python.addFunction("thirdparty_nrf24l01_receive_data_function","void _nrfReceiveDataSet() {\n if (radio.available()) {\n radio.read(&_nrfText, sizeof(_nrfText));\n }\n}\n");
- return"_nrfReceiveDataSet();\n"};Blockly.Python.thirdparty_nrf24l01_data_received=function(a){return["_nrfText",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.time={};Blockly.Python.time_delay=function(a){return"delay("+(Blockly.Python.valueToCode(a,"DELAY_TIME_MILI",Blockly.Python.ORDER_ATOMIC)||"0")+");\n"};Blockly.Python.time_delaymicros=function(a){return"delayMicroseconds("+(Blockly.Python.valueToCode(a,"DELAY_TIME_MICRO",Blockly.Python.ORDER_ATOMIC)||"0")+");\n"};Blockly.Python.time_millis=function(a){return["millis()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.time_micros=function(a){return["micros()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.infinite_loop=function(a){return"while(true);\n"};Blockly.Python.time_chrono_setup=function(a){Blockly.Python.addInclude("chrono.h","#include <Chrono.h>\n");Blockly.Python.addDeclaration("chrono_dec","Chrono myChrono;\n")};Blockly.Python.time_chrono_reset=function(a){return"myChrono.restart();\n"};Blockly.Python.time_chrono_elapsed=function(a){return["myChrono.elapsed()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.time_chrono_timeCheck=function(a){return["myChrono.hasPassed("+Blockly.Python.valueToCode(this,"TIME",Blockly.Python.ORDER_ATOMIC)+")",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.time_everySecond=function(a){var b=Blockly.Python.valueToCode(this,"TIME",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("everySecondState_"+b,"int everySecondState_"+b+" = 0;");a=Blockly.Python.statementToCode(a,"STACK",Blockly.Python.ORDER_ATOMIC);return 2<=b?"if ((millis() / 1000) % "+b+" == "+(b-2)+" && everySecondState_"+b+" == 0) {\n "+a+"\n everySecondState_"+b+" = 1;\n} else if ((millis() / 1000) % "+b+" == "+(b-1)+") {\n everySecondState_"+b+" = 0;\n}\n":"if ((millis() / 100) % 10 == 1 && everySecondState_"+
- b+" == 0) {\n "+a+"\n everySecondState_"+b+" = 1;\n} else if ((millis() / 100) % 10 == 2 && everySecondState_"+b+" == 1) {\n everySecondState_"+b+" = 0;\n}\n"};
- Blockly.Python.time_everyMilliSecond=function(a){var b=Blockly.Python.valueToCode(this,"TIME",Blockly.Python.ORDER_ATOMIC);Blockly.Python.addDeclaration("timePeriodExecutionState_"+b,"int timePeriodExecutionState_"+b+" = 0;");a=Blockly.Python.statementToCode(a,"STACK",Blockly.Python.ORDER_ATOMIC);return"if ((millis()) % "+b+" == "+(b-1)+" && timePeriodExecutionState_"+b+" == 0) {\n "+a+"\n timePeriodExecutionState_"+b+" = 1;\n} else if ((millis()) % "+b+" == 0) {\n timePeriodExecutionState_"+b+
- " = 0;\n}\n"};Blockly.Python.touch={};
- Blockly.Python.touch_setup=function(a){Blockly.Python.addDeclaration("wire.h","#include <Wire.h>\n");Blockly.Python.addDeclaration("touch_sensor_decl",'#include "Adafruit_MPR121.h"\nAdafruit_MPR121 cap = Adafruit_MPR121();\nuint16_t lasttouched = 0;\nuint16_t currtouched = 0;\n');Blockly.Python.addSetup("music_keyboard_setup",'Serial.begin(9600);\nSerial.println("Adafruit MPR121 Capacitive Touch sensor test");\n if (!cap.begin(0x5A)) {\n Serial.println("MPR121 not found, check wiring?");\n while (1);\n }\n Serial.println("MPR121 found!");\n');return""};
- Blockly.Python.touch_keyboardset=function(a){for(var b=" switch (i_) {\n",c,d,e=0;e<=a.caseCount_;e++)c=a.getFieldValue("keyboard"+e)||e,d=Blockly.Python.statementToCode(a,"DO"+e),b+=" case "+c+":\n "+d+" break;\n";return"currtouched = cap.touched();\nfor (uint8_t i_=0; i_<12; i_++) {\n if ((currtouched & _BV(i_)) && !(lasttouched & _BV(i_)) ) {\n"+b+" }\nlasttouched = currtouched;\n }\n}\n"};
- Blockly.Python.touch_keyboardset_loose=function(a){for(var b=" switch (i_) {\n",c,d,e=0;e<=a.caseCount_;e++)c=a.getFieldValue("keyboard"+e)||e,d=Blockly.Python.statementToCode(a,"DO"+e),b+=" case "+c+":\n "+d+" break;\n";return"for (uint8_t i_=0; i_<12; i_++) {\n if (!(currtouched & _BV(i_)) && (lasttouched & _BV(i_)) ) {\n"+b+" }\nlasttouched = 0;\n }\n}\n"};
- Blockly.Python.touch_setup_1=function(a){Blockly.Python.addDeclaration("wire.h","#include <Wire.h>\n");Blockly.Python.addDeclaration("touch_sensor_decl",'#include "Adafruit_MPR121.h"\nAdafruit_MPR121 cap = Adafruit_MPR121();\nuint16_t lasttouched = 0;\nuint16_t currtouched = 0;\n');Blockly.Python.addSetup("music_keyboard_setup",'Serial.println("Adafruit MPR121 Capacitive Touch sensor test");\n if (!cap.begin(0x5A)) {\n Serial.println("MPR121 not found, check wiring?");\n while (1);\n }\n Serial.println("MPR121 found!");\n');
- return"currtouched = cap.touched();\n"};Blockly.Python.touch_each=function(a){var b=a.getFieldValue("keyboard"),c=Blockly.Python.statementToCode(a,"DO0");a=Blockly.Python.statementToCode(a,"DO1");return"if ((currtouched & _BV("+b+"))&& !(lasttouched & _BV("+b+"))){\n"+c+" lasttouched = currtouched;\n}\nif ((lasttouched & _BV("+b+")) && !(currtouched & _BV("+b+")) ) {\n"+a+" lasttouched = 0;\n}\n"};Blockly.Python.variables={};Blockly.Python.variables_get=function(a){return[Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.variables_set=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_ASSIGNMENT)||"0";if(a.childBlocks_.length){if("lists_create_with"==a.childBlocks_[0].type)return a=a.getFieldValue("VAR"),Blockly.Python.addDeclaration("create_int_list","int "+a+"[] = "+b+";\n"),"";if("lists_create_with2"==a.childBlocks_[0].type)return a=a.getFieldValue("VAR"),Blockly.Python.addDeclaration("create_string_list","String "+a+"[] = "+b+";\n"),"";a=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),
- Blockly.Variables.NAME_TYPE);return a+" = "+b+";\n"}a=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);return a+" = "+b+";\n"};Blockly.Python.variables_set_type=function(a){var b=Blockly.Python.valueToCode(a,"VARIABLE_SETTYPE_INPUT",Blockly.Python.ORDER_ASSIGNMENT)||"0";return["("+Blockly.Python.getArduinoType_(Blockly.Types[a.getFieldValue("VARIABLE_SETTYPE_TYPE")])+")("+b+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.webpage={};
- Blockly.Python.webpage_label=function(a){var b='server.send(200, "text/html","<!DOCTYPE HTML><html><head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1, user-scalable=no\\"> <meta http-equiv=\\"refresh\\" content=\\"1\\"> </head><style>body { font-family:Arial;padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; /* updated */ } .row { margin-left: auto; margin-right: auto; margin-bottom: 20px; text-align: center; } .label { font-size: 20px; line-height: 28px; } .value { font-weight: bolder !important; margin-left: 2px; padding: 5px 8px; border-radius: 5px; background-color: rgba(0,0,0,.025); border: 1px solid rgba(0,0,0,.15); } .header { padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto; } .content { padding: 20px 20px 20px 20px; } h1,h2,h3,h4,h5,h6 {font-weight: 500;line-height: 1.1;z-index: 1001;}p {margin-bottom: 10px;text-align: center;z-index: 1001;} </style> <body> <div> <div class=\'row\'> <h1> CocoRobo IoT Project </h1> </div> <div class=\'row header\'> <h2> Web Dashboard </h2></div><div class=\'content\'>';for(var c=
- 0;c<a.itemCount_;c++){var d=a.getFieldValue("LABLE"+c),e=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_ATOMIC);b+=" <div class='row label'>"+d+": <span class='value'>\"+String("+e+')+"</span> </div>'}return b+' </div></body></html>");\n'};
- Blockly.Python.webpage_button=function(a){var b='server.send(200, "text/html","<!DOCTYPE HTML><html><head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1, user-scalable=no\\"></head><style>body { font-family:Arial;padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; /* updated */ } .row { margin-left: auto; margin-right: auto; font-weight: bolder !important; margin-bottom: 20px; text-align: center; z-index: 1001; } .header { padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto; } .content { padding: 20px 20px 20px 20px; } h1,h2,h3,h4,h5,h6 {font-weight: 500;line-height: 1.1;z-index: 1001;}p {margin-bottom: 10px;text-align: center;z-index: 1001;} .btn { font-weight: bolder; /* added */ border-radius: 5px; display: inline-block; height: 36px; line-height: 36px; padding: 0.5rem 2rem; text-decoration: none; color: #444; /* updated */ border: 1px solid rgba(0,0,0,.2); /* updated */ background-color: rgba(255, 255, 255, 0); /* updated */ text-align: center; text-transform: uppercase; vertical-align: middle; -webkit-tap-highlight-color: transparent; } .btn.disabled, .btn[disabled] { pointer-events: none; background-color: rgba(44, 79, 205, 1) !important; -webkit-box-shadow: none; box-shadow: none; color: #9F9F9F !important; cursor: default; } .btn:hover { background-color: rgba(44, 79, 205, 1); border-radius: 5px; border: 1px solid #2c4fcd; color: #fff; } .btn:before { border-radius: 0; }</style> <body> <div> <div class=\'row\'> <h1> CocoRobo IoT Project </h1> </div> <div class=\'row header\'> <h2> Web Dashboard </h2></div> <div class=\'content\'>';for(var c=
- 0;c<a.itemCount_;c++){var d=a.getFieldValue("URL"+c);d="http://192.168.4.1"+d;var e=a.getFieldValue("BUTTON"+c);b+=" <div class='row'><a class='btn' onclick=\\\"clickBtn('"+d+"', '"+e+"')\\\">"+e+"</a></div>"}return b+"</div> </body> <script> function clickBtn(url_ , btn) { var content = {'data':[ btn]};var contentTo_ = JSON.stringify(content);var xhr = new XMLHttpRequest();xhr.open('POST', url_);xhr.setRequestHeader('content-type','application/json'); xhr.send(contentTo_);}\x3c/script></html>\");\n"};
- Blockly.Python.webpage_colorpicker=function(a){a=a.getFieldValue("webpage_colorpicker_path");Blockly.Python.addFunction("webpage_colorpicker-string",'String htmlContent() {\n String data = "<!DOCTYPE HTML><html><head> <meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1, user-scalable=no\\"></head><style>.color-picker,.color-picker *,.color-picker ::after,.color-picker ::before,.color-picker::after,.color-picker::before{box-sizing: border-box}.color-picker{position: absolute; top: 0; left: 0; z-index: 9999; box-shadow: 1px 5px 10px rgba(0, 0, 0, .5)}.color-picker-container{direction: rtl; display: flex; height: 10em; border: 1px solid #000; color: #000}.color-picker-container *{border-color: inherit; color: inherit}.color-picker i{font: inherit; font-size: 12px}.color-picker-h,.color-picker-sv{direction: ltr; background-size: 100% 100%; position: relative}.color-picker-h{width: 1.5em; border-left: 1px solid; background: transparent url(color-picker-h.png) no-repeat 50% 50%; background-image: linear-gradient(to top, red 0, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%); cursor: ns-resize; overflow: hidden}.color-picker-h i{display: block; height: .5em; position: absolute; top: -.25em; right: 0; left: 0; z-index: 3}.color-picker-h i::before{display: block; content: \\"\\"; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border: .25em solid; border-top-color: transparent; border-bottom-color: transparent}.color-picker-sv{width: 10em; background: transparent url(color-picker-sv.png) no-repeat 50% 50%; background-image: linear-gradient(to top, #000, rgba(0, 0, 0, 0)), linear-gradient(to right, #fff, rgba(255, 255, 255, 0)); cursor: crosshair}.color-picker-sv i{display: block; width: .8em; height: .8em; position: absolute; top: -.4em; right: -.4em; z-index: 3}.color-picker-sv i::after,.color-picker-sv i::before{display: block; content: \\"\\"; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border: 1px solid; border-color: inherit; border-radius: 100%}.color-picker-sv i::before{top: -1px; right: -1px; bottom: -1px; left: -1px; border-color: #fff}.color-picker-h,.color-picker-sv{-webkit-touch-callout: none; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent}#color-picker-show{text-align:center; display: inline-block; margin: auto 27% 10px 26.5%; background-color: rgb(255,0,0); height:180px; width:47%; border: 1px solid rgba(0,0,0,.1); -webkit-box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.36); -moz-box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.36); box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.36);}#color-picker-header{font-size:18px; margin-bottom:-2px; font-weight: bolder;}input[type=\\"text\\"]{font-size: 18px; width: 185px; padding: 10px auto; margin-left: 10px; border: 1px solid rgba(0,0,0,.2); text-align:center;}</style><style>body{font-family: Arial; padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; /* updated */}.row{margin-left: auto; margin-right: auto; font-weight: bolder !important; margin-bottom: 20px; text-align: center; z-index: 1001;}.header{padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto;}.content{padding: 20px 20px 20px 20px;}h1,h2,h3,h4,h5,h6{font-weight: 500; line-height: 1.1; z-index: 1001;}p{margin-bottom: 10px; text-align: center; z-index: 1001;}.btn{font-weight: bolder; /* added */ border-radius: 5px; display: inline-block; height: 36px; line-height: 36px; padding: 0.5rem 2rem; text-decoration: none; color: #444; /* updated */ border: 1px solid rgba(0, 0, 0, .2); /* updated */ background-color: rgba(255, 255, 255, 0); /* updated */ text-align: center; text-transform: uppercase; vertical-align: middle; -webkit-tap-highlight-color: transparent;}.btn.disabled,.btn[disabled]{pointer-events: none; background-color: rgba(44, 79, 205, 1) !important; -webkit-box-shadow: none; box-shadow: none; color: #9F9F9F !important; cursor: default;}.btn:hover{background-color: rgba(44, 79, 205, 1); border-radius: 5px; border: 1px solid #2c4fcd; color: #fff;}.btn:before{border-radius: 0;}</style><body> <div> <div class=\'row navbar\'> <h1> CocoRobo IoT Project </h1> </div><div class=\'row header\'> <h2> Web Dashboard </h2> </div><div class=\'content\'> <div id=\\"color-picker-show\\"></div><p id=\\"color-picker-header\\">Pick a color below: (in RGB)</p><p> <input type=\\"text\\" readonly=\\"true\\"/> </p></div></body>";\n data += "<script>"; data += "\\r\\n";\n data += "! function(t, n, e) {"; data += "\\r\\n";\n data += " function r(t) { return void 0 !== t }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function i(t) { return \\"string\\" == typeof t }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function o(t) { return \\"object\\" == typeof t }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function u(t) { return Object.keys(t).length }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function c(t, n, e) { return n > t ? n : t > e ? e : t }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function s(t, n) { return parseInt(t, n || 10) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function a(t) { return Math.round(t) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function f(t) {"; data += "\\r\\n";\n data += " var n, e, r, i, o, u, c, s, f = +t[0],"; data += "\\r\\n";\n data += " l = +t[1],"; data += "\\r\\n";\n data += " h = +t[2];"; data += "\\r\\n";\n data += " switch (i = Math.floor(6 * f), o = 6 * f - i, u = h * (1 - l), c = h * (1 - o * l), s = h * (1 - (1 - o) * l), i = i || 0, c = c || 0, s = s || 0, i % 6) {"; data += "\\r\\n";\n data += " case 0:"; data += "\\r\\n";\n data += " n = h, e = s, r = u;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case 1:"; data += "\\r\\n";\n data += " n = c, e = h, r = u;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case 2:"; data += "\\r\\n";\n data += " n = u, e = h, r = s;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case 3:"; data += "\\r\\n";\n data += " n = u, e = c, r = h;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case 4:"; data += "\\r\\n";\n data += " n = s, e = u, r = h;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case 5:"; data += "\\r\\n";\n data += " n = h, e = u, r = c"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += " return [a(255 * n), a(255 * e), a(255 * r)]"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function l(t) { return p(f(t)) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function h(t) {"; data += "\\r\\n";\n data += " var n, e = +t[0],"; data += "\\r\\n";\n data += " r = +t[1],"; data += "\\r\\n";\n data += " i = +t[2],"; data += "\\r\\n";\n data += " o = Math.max(e, r, i),"; data += "\\r\\n";\n data += " u = Math.min(e, r, i),"; data += "\\r\\n";\n data += " c = o - u,"; data += "\\r\\n";\n data += " s = 0 === o ? 0 : c / o,"; data += "\\r\\n";\n data += " a = o / 255;"; data += "\\r\\n";\n data += " switch (o) {"; data += "\\r\\n";\n data += " case u:"; data += "\\r\\n";\n data += " n = 0;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case e:"; data += "\\r\\n";\n data += " n = r - i + c * (i > r ? 6 : 0), n /= 6 * c;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case r:"; data += "\\r\\n";\n data += " n = i - e + 2 * c, n /= 6 * c;"; data += "\\r\\n";\n data += " break;"; data += "\\r\\n";\n data += " case i:"; data += "\\r\\n";\n data += " n = e - r + 4 * c, n /= 6 * c"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += " return [n, s, a]"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function p(t) { var n = +t[2] | +t[1] << 8 | +t[0] << 16; return n = \\"000000\\" + n.toString(16), n.slice(-6) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function v(t) { return h(d(t)) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function d(t) { return 3 === t.length && (t = t.replace(/./g, \\"$&$&\\")), [s(t[0] + t[1], 16), s(t[2] + t[3], 16), s(t[4] + t[5], 16)] }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function g(t) { return [+t[0] / 360, +t[1] / 100, +t[2] / 100] }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function y(t) { return [a(360 * +t[0]), a(100 * +t[1]), a(100 * +t[2])] }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function x(t) { return [+t[0] / 255, +t[1] / 255, +t[2] / 255] }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function H(t) {"; data += "\\r\\n";\n data += " if (o(t)) return t;"; data += "\\r\\n";\n data += " var n = /\\\\s*rgb\\\\s*\\\\(\\\\s*(\\\\d+)\\\\s*,\\\\s*(\\\\d+)\\\\s*,\\\\s*(\\\\d+)\\\\s*\\\\)\\\\s*$/i.exec(t),"; data += "\\r\\n";\n data += " e = /\\\\s*hsv\\\\s*\\\\(\\\\s*(\\\\d+)\\\\s*,\\\\s*(\\\\d+)%\\\\s*,\\\\s*(\\\\d+)%\\\\s*\\\\)\\\\s*$/i.exec(t),"; data += "\\r\\n";\n data += " r = \\"#\\" === t[0] && t.match(/^#([\\\\da-f]{3}|[\\\\da-f]{6})$/i);"; data += "\\r\\n";\n data += " return r ? v(t.slice(1)) : e ? g([+e[1], +e[2], +e[3]]) : n ? h([+n[1], +n[2], +n[3]]) : [0, 1, 1]"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += " var b = \\"__instance__\\","; data += "\\r\\n";\n data += " m = \\"firstChild\\","; data += "\\r\\n";\n data += " k = setTimeout;"; data += "\\r\\n";\n data += " ! function(t) { t.version = \\"1.4.2\\", t[b] = {}, t.each = function(n, e) { return k(function() { var e, r = t[b]; for (e in r) n.call(r[e], e, r) }, 0 === e ? 0 : e || 1), t }, t.parse = H, t._HSV2RGB = f, t._HSV2HEX = l, t._RGB2HSV = h, t._HEX2HSV = v, t._HEX2RGB = function(t) { return x(d(t)) }, t.HSV2RGB = function(t) { return f(g(t)) }, t.HSV2HEX = function(t) { return l(g(t)) }, t.RGB2HSV = function(t) { return y(h(t)) }, t.RGB2HEX = p, t.HEX2HSV = function(t) { return y(v(t)) }, t.HEX2RGB = d }(t[e] = function(s, a, h) {"; data += "\\r\\n";\n data += " function p(t, n, e) { t = t.split(/\\\\s+/); for (var r = 0, i = t.length; i > r; ++r) n.addEventListener(t[r], e, !1) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function v(t, n, e) { t = t.split(/\\\\s+/); for (var r = 0, i = t.length; i > r; ++r) n.removeEventListener(t[r], e) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function d(t, n) {"; data += "\\r\\n";\n data += " var e = \\"touches\\","; data += "\\r\\n";\n data += " r = \\"clientX\\","; data += "\\r\\n";\n data += " i = \\"clientY\\","; data += "\\r\\n";\n data += " o = n[e] ? n[e][0][r] : n[r],"; data += "\\r\\n";\n data += " u = n[e] ? n[e][0][i] : n[i],"; data += "\\r\\n";\n data += " c = g(t);"; data += "\\r\\n";\n data += " return { x: o - c.l, y: u - c.t }"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function g(n) { var e, r, i; return n === t ? (e = t.pageXOffset || M.scrollLeft, r = t.pageYOffset || M.scrollTop) : (i = n.getBoundingClientRect(), e = i.left, r = i.top), { l: e, t: r } }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function y(t, n) {"; data += "\\r\\n";\n data += " for (;"; data += "\\r\\n";\n data += " (t = t.parentElement) && t !== n;);"; data += "\\r\\n";\n data += " return t"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function x(t) { t && t.preventDefault() }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function H(n) { return n === t ? { w: t.innerWidth, h: t.innerHeight } : { w: n.offsetWidth, h: n.offsetHeight } }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function w(t) { return j || (r(t) ? t : !1) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function E(t) { j = t }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function S(t, n, e) { return r(t) ? r(n) ? (r(O[t]) || (O[t] = {}), r(e) || (e = u(O[t])), O[t][e] = n, $) : O[t] : O }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function X(t, n) { return r(t) ? r(n) ? (delete O[t][n], $) : (O[t] = {}, $) : (O = {}, $) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function _(t, n, e) {"; data += "\\r\\n";\n data += " if (!r(O[t])) return $;"; data += "\\r\\n";\n data += " if (r(e)) r(O[t][e]) && O[t][e].apply($, n);"; data += "\\r\\n";\n data += " else"; data += "\\r\\n";\n data += " for (var i in O[t]) O[t][i].apply($, n);"; data += "\\r\\n";\n data += " return $"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function B(t, n) { t && \\"h\\" !== t || _(\\"change:h\\", n), t && \\"sv\\" !== t || _(\\"change:sv\\", n), _(\\"change\\", n) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function R() { return T.parentNode }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function V(e, r) {"; data += "\\r\\n";\n data += " function i(t) {"; data += "\\r\\n";\n data += " var n = t.target,"; data += "\\r\\n";\n data += " e = n === s || y(n, s) === s;"; data += "\\r\\n";\n data += " e ? !R() && (V(), _(\\"enter\\")) : $.exit()"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function o(t) {"; data += "\\r\\n";\n data += " var n = (f(I), f([I[0], 1, 1]));"; data += "\\r\\n";\n data += " q.style.backgroundColor = \\"rgb(\\" + n.join(\\",\\") + \\")\\", E(I), x(t)"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function u(t) {"; data += "\\r\\n";\n data += " var n = c(d(P, t).y, 0, L);"; data += "\\r\\n";\n data += " I[0] = (L - n) / L, F.style.top = n - D / 2 + \\"px\\", o(t)"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function g(t) {"; data += "\\r\\n";\n data += " var n = d(q, t),"; data += "\\r\\n";\n data += " e = c(n.x, 0, j),"; data += "\\r\\n";\n data += " r = c(n.y, 0, O);"; data += "\\r\\n";\n data += " I[1] = 1 - (j - e) / j, I[2] = (O - r) / O, J.style.right = j - e - tn / 2 + \\"px\\", J.style.top = r - nn / 2 + \\"px\\", o(t)"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function b(t) { U && (u(t), on = [l(I)], K || (_(\\"drag:h\\", on), _(\\"drag\\", on), B(\\"h\\", on))), Z && (g(t), on = [l(I)], Q || (_(\\"drag:sv\\", on), _(\\"drag\\", on), B(\\"sv\\", on))), K = 0, Q = 0 }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function m(t) {"; data += "\\r\\n";\n data += " var n = t.target,"; data += "\\r\\n";\n data += " e = U ? \\"h\\" : \\"sv\\","; data += "\\r\\n";\n data += " r = [l(I), $],"; data += "\\r\\n";\n data += " i = n === s || y(n, s) === s,"; data += "\\r\\n";\n data += " o = n === T || y(n, T) === T;"; data += "\\r\\n";\n data += " i || o ? o && (_(\\"stop:\\" + e, r), _(\\"stop\\", r), B(e, r)) : R() && a !== !1 && ($.exit(), B(0, r)), U = 0, Z = 0"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function k(t) { K = 1, U = 1, b(t), x(t), _(\\"start:h\\", on), _(\\"start\\", on), B(\\"h\\", on) }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function S(t) { Q = 1, Z = 1, b(t), x(t), _(\\"start:sv\\", on), _(\\"start\\", on), B(\\"sv\\", on) } e || ((h || r || C).appendChild(T), $.visible = !0), en = H(T).w, rn = H(T).h;"; data += "\\r\\n";\n data += " var X = H(q),"; data += "\\r\\n";\n data += " M = H(J),"; data += "\\r\\n";\n data += " L = H(P).h,"; data += "\\r\\n";\n data += " j = X.w,"; data += "\\r\\n";\n data += " O = X.h,"; data += "\\r\\n";\n data += " D = H(F).h,"; data += "\\r\\n";\n data += " tn = M.w,"; data += "\\r\\n";\n data += " nn = M.h;"; data += "\\r\\n";\n data += " e ? (T.style.left = T.style.top = \\"-9999px\\", a !== !1 && p(a, s, i), $.create = function() { return V(1), _(\\"create\\"), $ }, $.destroy = function() { return a !== !1 && v(a, s, i), $.exit(), E(!1), _(\\"destroy\\"), $ }) : G(), A = function() { I = w(I), o(), F.style.top = L - D / 2 - L * +I[0] + \\"px\\", J.style.right = j - tn / 2 - j * +I[1] + \\"px\\", J.style.top = O - nn / 2 - O * +I[2] + \\"px\\" }, $.exit = function() { var e = R(); return e && (e.removeChild(T), $.visible = !1), v(N, P, k), v(N, q, S), v(W, n, b), v(Y, n, m), v(z, t, G), _(\\"exit\\"), $ }, A(), e || (p(N, P, k), p(N, q, S), p(W, n, b), p(Y, n, m), p(z, t, G))"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += ""; data += "\\r\\n";\n data += " function G() { return $.fit() }"; data += "\\r\\n";\n data += " var C = n.body,"; data += "\\r\\n";\n data += " M = n.documentElement,"; data += "\\r\\n";\n data += " $ = this,"; data += "\\r\\n";\n data += " L = t[e],"; data += "\\r\\n";\n data += " j = !1,"; data += "\\r\\n";\n data += " O = {},"; data += "\\r\\n";\n data += " T = n.createElement(\\"div\\"),"; data += "\\r\\n";\n data += " N = \\"touchstart mousedown\\","; data += "\\r\\n";\n data += " W = \\"touchmove mousemove\\","; data += "\\r\\n";\n data += " Y = \\"touchend mouseup\\","; data += "\\r\\n";\n data += " z = \\"orientationchange resize\\";"; data += "\\r\\n";\n data += " if (!($ instanceof L)) return new L(s, a);"; data += "\\r\\n";\n data += " L[b][s.id || s.name || u(L[b])] = $, r(a) && a !== !0 || (a = N), E(L.parse(s.getAttribute(\\"data-color\\") || s.value || [0, 1, 1])), T.className = \\"color-picker\\", T.innerHTML = \'<div class=\\"color-picker-container\\"><span class=\\"color-picker-h\\"><i></i></span><span class=\\"color-picker-sv\\"><i></i></span></div>\';"; data += "\\r\\n";\n data += " var A, D = T[m].children,"; data += "\\r\\n";\n data += " I = w([0, 1, 1]),"; data += "\\r\\n";\n data += " P = D[0],"; data += "\\r\\n";\n data += " q = D[1],"; data += "\\r\\n";\n data += " F = P[m],"; data += "\\r\\n";\n data += " J = q[m],"; data += "\\r\\n";\n data += " K = 0,"; data += "\\r\\n";\n data += " Q = 0,"; data += "\\r\\n";\n data += " U = 0,"; data += "\\r\\n";\n data += " Z = 0,"; data += "\\r\\n";\n data += " tn = 0,"; data += "\\r\\n";\n data += " nn = 0,"; data += "\\r\\n";\n data += " en = 0,"; data += "\\r\\n";\n data += " rn = 0,"; data += "\\r\\n";\n data += " on = [l(I)];"; data += "\\r\\n";\n data += " return V(1), k(function() {"; data += "\\r\\n";\n data += " var t = [l(I)];"; data += "\\r\\n";\n data += " _(\\"create\\", t), B(0, t)"; data += "\\r\\n";\n data += " }, 0), $.fit = function(n) {"; data += "\\r\\n";\n data += " var e = H(t),"; data += "\\r\\n";\n data += " i = H(M),"; data += "\\r\\n";\n data += " u = e.w - i.w,"; data += "\\r\\n";\n data += " a = e.h - M.clientHeight,"; data += "\\r\\n";\n data += " f = g(t),"; data += "\\r\\n";\n data += " l = g(s);"; data += "\\r\\n";\n data += " if (tn = l.l + f.l, nn = l.t + f.t + H(s).h, o(n)) r(n[0]) && (tn = n[0]), r(n[1]) && (nn = n[1]);"; data += "\\r\\n";\n data += " else {"; data += "\\r\\n";\n data += " var h = f.l,"; data += "\\r\\n";\n data += " p = f.t,"; data += "\\r\\n";\n data += " v = f.l + e.w - en - u,"; data += "\\r\\n";\n data += " d = f.t + e.h - rn - a;"; data += "\\r\\n";\n data += " tn = c(tn, h, v) >> 0, nn = c(nn, p, d) >> 0"; data += "\\r\\n";\n data += " }"; data += "\\r\\n";\n data += " return T.style.left = tn + \\"px\\", T.style.top = nn + \\"px\\", _(\\"fit\\"), $"; data += "\\r\\n";\n data += " }, $.set = function(t) { return r(t) ? (i(t) && (t = L.parse(t)), E(t), A(), $) : w() }, $.get = function(t) { return w(t) }, $.source = s, $.self = T, $.visible = !1, $.on = S, $.off = X, $.fire = _, $.hooks = O, $.enter = function(t) { return V(0, t), _(\\"enter\\"), $ }, $"; data += "\\r\\n";\n data += " })"; data += "\\r\\n";\n data += "}(window, document, \\"CP\\");"; data += "\\r\\n";\n data += "\x3c/script>"; data += "\\r\\n";\n\n data += "<script>var picker=new CP(document.querySelector(\'input[type=\\"text\\"]\'), \\"click\\");var globalRed, globalGreen, globalBlue;picker.on(\\"change\\", function(color){/* console.log(CP.HEX2RGB(color)); */ this.source.value=CP.HEX2RGB(color); document.getElementById(\'color-picker-show\').style.backgroundColor=\'rgb(\' + CP.HEX2RGB(color) + \')\'; var colorString=\'rgb(\' + CP.HEX2RGB(color) + \')\', colorsOnly=colorString.substring(colorString.indexOf(\'(\') + 1, colorString.lastIndexOf(\')\')).split(/,s*/), colorStringRed=colorsOnly[0], colorStringGreen=colorsOnly[1], colorStringBlue=colorsOnly[2]; /*console.log(colorStringRed); console.log(colorStringGreen); console.log(colorStringBlue);*/ globalRed=colorStringRed; globalGreen=colorStringGreen; globalBlue=colorStringBlue;});setInterval(function(){var content={\'data\': [globalRed + \'|\' + globalGreen + \'|\' + globalBlue]}; var contentTo_=JSON.stringify(content); var xhr=new XMLHttpRequest(); xhr.open(\'POST\', \'http://192.168.4.1'+
- a+"'); xhr.setRequestHeader('content-type', 'application/json'); xhr.send(contentTo_); console.log(contentTo_);}, 500);\x3c/script></html>\";\n return data;\n}\n");return'server.send(200, "text/html", htmlContent());\n'};
- Blockly.Python.webpage_buttoncontroller=function(a){var b=a.getFieldValue("webpage_buttoncontroller_top"),c=a.getFieldValue("webpage_buttoncontroller_top_path"),d=a.getFieldValue("webpage_buttoncontroller_left"),e=a.getFieldValue("webpage_buttoncontroller_left_path"),f=a.getFieldValue("webpage_buttoncontroller_center"),g=a.getFieldValue("webpage_buttoncontroller_center_path"),h=a.getFieldValue("webpage_buttoncontroller_right"),l=a.getFieldValue("webpage_buttoncontroller_right_path"),k=a.getFieldValue("webpage_buttoncontroller_bottom");
- a=a.getFieldValue("webpage_buttoncontroller_bottom_path");return"server.send(200, \"text/html\",\" <!DOCTYPE HTML><html><head> <meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'></head><style>* { box-sizing: border-box;}body { font-family: Arial; padding-top: 10px; background-color: white; user-select: none; --webkit-user-select: none; overflow: hidden; margin: 0;}.row { margin-left: auto; margin-right: auto; font-weight: bolder !important; margin-bottom: 20px; text-align: center; z-index: 1001;}.header { padding: 5px 0; border-radius: 10px; background-color: rgba(0, 0, 0, .04); color: #111; border: 1px solid rgba(0,0,0,.1); width: 80%; margin-left: auto; margin-right: auto;}.content { width: 100%; padding-top: 10px; margin: auto 0px auto 9.5%;}.block { background-color: rgba(0, 0, 0, 0);}/* Create three equal columns that floats next to each other */.column { float: left; width: 27%; padding: 0px; /* Should be removed. Only for demonstration */}/* Clear floats after the columns */.row:after { content: ''; display: table; clear: both;}#btn { display: inline-block; display: inline-block; font-size: 20px; cursor: pointer; text-align: center; text-decoration: none; outline: none; color: #fff; background-color: rgba(44, 79, 205, .88); border-radius: 10px; border: none; box-shadow: 0 9px rgba(24, 61, 195, .99); width: 90%; height: 80px; margin: 5px 5% 0px 5%;} .blank { color: rgba(0,0,0,0); } /* .btn:hover {background-color: #3e8e41}*/#btn:active { background-color: rgba(24, 61, 195, .99); border: none; box-shadow: 0 5px rgba(24, 61, 195, .99); transform: translateY(4px); cursor: pointer;}button:focus { outline: 0;}h1,h2,h3,h4,h5,h6 { font-weight: 500; line-height: 1.1; z-index: 1001;}p { margin-bottom: 10px; text-align: center; z-index: 1001;}</style><body> <div> <div class='row navbar'> <h1> CocoRobo IoT Project </h1> </div> <div class='row header'> <h2> Web Dashboard </h2> </div> <div class='content'> <div class='row'> <div class='column block blank'> . </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+
- c+"', '"+b+"')\\\">"+b+"</button> </div> <div class='column block blank'> . </div> </div> <div class='row'> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+e+"', '"+d+"')\\\">"+d+"</button> </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+g+"', '"+f+
- "')\\\">"+f+"</button> </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+l+"', '"+h+"')\\\">"+h+"</button> </div> </div> <div class='row'> <div class='column block blank'> . </div> <div class='column block'> <button id='btn' onclick=\\\"clickBtn('http://192.168.4.1"+a+"', '"+k+"')\\\">"+k+
- "</button> </div> <div class='column block blank'> . </div> </div> </div></body><script>function clickBtn(url_, btn) { var content = { 'data': [btn] }; var contentTo_ = JSON.stringify(content); var xhr = new XMLHttpRequest(); xhr.open('POST', url_); xhr.setRequestHeader('content-type', 'application/json'); xhr.send(contentTo_); console.log(btn);}\x3c/script></html>\");\n"};Blockly.Python.wificlient={};Blockly.Python.wifiClient_http_setup=function(a){Blockly.Python.addInclude("wifi_httpclient","#include <ESP8266HTTPClient.h>");Blockly.Python.addDeclaration("HTTP_Response","String http_response;");Blockly.Python.addDeclaration("HTTP_code","int httpCode;");Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");Blockly.Python.addDeclaration("wifi_httpclient_setup","HTTPClient http;\n");return""};
- Blockly.Python.wifiClient_http_get=function(a){Blockly.Python.addInclude("json_declaration","#include <ArduinoJson.h>");var b=a.getFieldValue("VAR");return'if ((millis() % 1000) /100 % 5 == 0 ) {\n http.begin("http://192.168.4.1'+(a.getFieldValue("URL")||"")+'");\n httpCode = http.GET();\n // Serial.print("HTTP code: ");\n // Serial.println(httpCode);\n http_response = http.getString();\n http.end();\n}\nStaticJsonBuffer<800> jsonBuffer_'+(b+";\nJsonObject& parse_"+b+" = jsonBuffer_"+b+".parseObject(http_response);\n")};
- Blockly.Python.wifiClient_http_get_getValue=function(a){var b=a.getFieldValue("VAR")||"",c=a.getFieldValue("INDEX")||"";a=a.getFieldValue("TYPE")||"";b="parse_"+b+'["data"]['+c+"]";return["Int"==a?b+".as<int>()":b+".as<String>()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.wifiClient_http_post=function(a){Blockly.Python.addInclude("json_include","#include <ArduinoJson.h>");Blockly.Python.addDeclaration("jsontool_prettyPrint","char JSONmessageBuffer[240];\n");for(var b=a.getFieldValue("VAR")||"json",c="StaticJsonBuffer<800> JSONbuffer_"+b+";\nJsonObject& "+b+"_json_ = JSONbuffer_"+b+".createObject();\nJsonArray& data_json_C = "+b+'_json_.createNestedArray("data");\n',d,e="http://192.168.4.1"+(a.getFieldValue("URL")||""),f=0;f<a.itemCount_;f++)d=Blockly.Python.valueToCode(a,
- "ADD"+f),c+="data_json_C.add("+d+");\n";c=c+("String jsonString_"+b+";\n"+b+"_json_.printTo(jsonString_"+b+');\nif ((millis() % 1000) /100 % 5 == 0 ) {\n http.begin("')+(e+'");\n http.addHeader("Content-Type","application/json");\n');return c+(" httpCode = http.POST(jsonString_"+b+');\n Serial.print("HTTP code: ");\n Serial.println(httpCode);\n http_response = http.getString();\n http.end();\n}\n')};
- Blockly.Python.wifiClient_http_put=function(a){var b=Blockly.Python.valueToCode(a,"DATA",Blockly.Python.ORDER_ATOMIC)||"",c=Blockly.Python.valueToCode(a,"URL",Blockly.Python.ORDER_ATOMIC)||"";a=a.getFieldValue("TYPE");c="http.begin("+c+");\n";"Cloud Data"==a?c+='http.addHeader("Content-Type","application/json");\nhttpCode = http.sendRequest("PUT","'+b+'")\n':"String"==a&&(c+='httpCode = http.sendRequest("PUT",'+b+")\n");return c+'Serial.print("HTTP code: ");\nSerial.println(httpCode);\nhttp_response = http.getString();\nhttp.end();\n'};
- Blockly.Python.wifiClient_http_response=function(a){return["http_response",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.wificomms={};Blockly.Python.wificomms_setup=function(a){Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");return""};
- Blockly.Python.wificomms_sendMsg=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");a=Blockly.Python.variableDB_.getName(a.getFieldValue("dataVar"),Blockly.Variables.NAME_TYPE);var b="sizeof("+a+")/sizeof("+a+"[0])",c=b+"+2";return"unsigned char DataOut_["+c+"];\nDataOut_[0]= SOP;\nDataOut_["+b+"+1]= EOP;\nfor (int i=0; i<"+b+";i++) {\n DataOut_[i+1]="+a+"[i];\n}\nSerial.write(DataOut_, "+c+");\n"};
- Blockly.Python.wificomms_receiveMsg=function(a){Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");a=Blockly.Python.variableDB_.getName(a.getFieldValue("dataVar"),Blockly.Variables.NAME_TYPE);Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial.available() > 0) {\n int inChar = Serial.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+
- ("sizeof("+a+")/sizeof("+a+"[0])"||1)+")&&started&&(!ended)) {\n "+a+"[index_i] = inChar;\n index_i++;\n }\n }\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");return"boolean receiveMsgsuccess_ = handleDataIn();\n"};Blockly.Python.wificomms_receiveMsg_isSuccessed=function(a){return["receiveMsgsuccess_",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.wifiTransfer_send_old=function(a){Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");a=a.getFieldValue("DATAMAIN");for(var b="int "+a+"["+this.itemCount_+"] = {0",c=1;c<this.itemCount_;c++)b+=",0";Blockly.Python.addDeclaration("dataMain_list",b+"};\n");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");b="sizeof("+a+")/sizeof("+a+"[0])";c=b+"+2";for(var d="",e,f=0;f<this.itemCount_;f++)e=Blockly.Python.valueToCode(this,"ADD"+f,
- Blockly.Python.ORDER_NONE)||"0",d+=a+"["+f+"] = "+e+";\n";return d+("unsigned char DataOut_["+c+"];\nDataOut_[0]= SOP;\nDataOut_["+b+"+1]= EOP;\nfor (int i=0; i<"+b+";i++) {\n DataOut_[i+1]="+a+"[i];\n}\nSerial.write(DataOut_, "+c+");\n")};
- Blockly.Python.wifiTransfer_receive_old=function(a){Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");var b=a.getFieldValue("DATAMAIN")||"_wifi_transfer";a=a.getFieldValue("LENGTH");for(var c="int "+b+"["+a+"] = {0",d=1;d<a;d++)c+=",0";Blockly.Python.addDeclaration("dataMain_list",c+"};\n");Blockly.Python.addDeclaration("wifi_dataTransfer_checkbit","#define SOP '<'\n#define EOP '>'\n");Blockly.Python.addDeclaration("wifi_dataTransfer_MsgReceiveStatus","bool started = false;\nbool ended = false;\nint index_i;\n");
- Blockly.Python.addFunction("mainwifi_dataIn_function","int handleDataIn() {\n while (Serial.available() > 0) {\n int inChar = Serial.read();\n if(inChar == SOP) {\n index_i = 0;\n started = true;\n ended = false;\n } else if(inChar == EOP) {\n ended = true;\n break;\n }else if((index_i < "+("sizeof("+b+")/sizeof("+b+"[0])"||1)+")&&started&&(!ended)) {\n "+b+"[index_i] = inChar;\n index_i++;\n }\n }\n delay(10);\n if(started && ended) {\n return 1;\n } else {\n return 0;\n }\n}\n");
- return'boolean receiveMsgsuccess_ = handleDataIn();\nif (!receiveMsgsuccess_) {\n Serial.println("Error: Fail to receive data!");\n return;\n}\n'};Blockly.Python.wifiTransfer_receive_getValue_old=function(a){var b=a.getFieldValue("DATAMAIN")||"_wifi_transfer";a=a.getFieldValue("INDEX");return[""+b+"["+a+"]",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.wifiTransfer_send=function(a){Blockly.Python.addDeclaration("Serial_sendState","int serialSendState = 0;");Blockly.Python.addSetup("serial","Serial.begin(9600);");Blockly.Python.addFunction("SerialSendData","void serialSendData() {\n int serialDataLength = serialDataPackage().length() + 1;\n char serialDataBuf[serialDataLength];\n serialDataPackage().toCharArray(serialDataBuf, serialDataLength);\n if ( serialSendState == 0 ) {\n Serial.write(serialDataBuf);\n }\n if ( (millis() / 100) % 4 == 3 && serialSendState == 0) {\n Serial.write(serialDataBuf);\n serialSendState = 1;\n } else if ( (millis() / 100) % 4 == 1) {\n serialSendState = 0;\n }\n}\n");
- for(var b='String serialDataPackage() { \n String data = "";\n data += "SOF";\n',c=0;c<this.itemCount_;c++)a=Blockly.Python.valueToCode(this,"ADD"+c,Blockly.Python.ORDER_NONE)||"0",b+=' data += "|";\n data += '+a+";\n";Blockly.Python.addFunction("SerialDataPackage",b+' data += "|";\n data += "\\r\\n";\n return data;\n}\n');return" serialSendData();\n"};
- Blockly.Python.wifiTransfer_receive=function(a){Blockly.Python.addSetup("serial_trans","Serial.begin(9600);\n Serial.setTimeout(20);");Blockly.Python.addDeclaration("serialDataReceived","String serialDataReceived;\n");Blockly.Python.addFunction("serialDataFilter","int serialDataFilter() {\n if (Serial.available() > 0) {\n serialDataReceived = Serial.readStringUntil('\\r\\n');\n }\n if (getSerialDataValue(serialDataReceived, '|', 0) == \"SOF\") {\n return 1;\n } else {\n return 0;\n }\n}\n");
- Blockly.Python.addFunction("getSerialDataValue",'String getSerialDataValue(String data, char separator, int index)\n{\n int found = 0;\n int strIndex[] = {0, -1};\n int maxIndex = data.length() - 1;\n for (int i = 0; i <= maxIndex && found <= index; i++) {\n if (data.charAt(i) == separator || i == maxIndex) {\n found++;\n strIndex[0] = strIndex[1] + 1;\n strIndex[1] = (i == maxIndex) ? i + 1 : i;\n }\n }\n return found > index ? data.substring(strIndex[0], strIndex[1]) : "";\n}\n');
- return'boolean serialReceiveCheck_ = serialDataFilter();\n if (!serialReceiveCheck_) {\n Serial.println("Error receiving data from Main Module.");\n return;\n }\n'};Blockly.Python.wifiTransfer_receive_getValue=function(a){var b=parseInt(a.getFieldValue("INDEX"))+1;a=a.getFieldValue("TYPE");return["getSerialDataValue(serialDataReceived, '|', "+b+")"+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.wifinetwork={};
- Blockly.Python.wifinetwork_connect_setup=function(a){Blockly.Python.addInclude("wifi_esp8266_declaration","#include <ESP8266WiFi.h>\n");Blockly.Python.addInclude("wifi_wifimulti_include_declaration","#include <ESP8266WiFiMulti.h>");var b=Blockly.Python.valueToCode(a,"SSID",Blockly.Python.ORDER_ATOMIC)||"";a=Blockly.Python.valueToCode(a,"PW",Blockly.Python.ORDER_ATOMIC)||"";Blockly.Python.addDeclaration("wifiMulti_declaration","ESP8266WiFiMulti WiFiMulti;\n");Blockly.Python.addSetup("wifinetwork_connect"," delay(10);\n WiFiMulti.addAP("+
- b+","+a+');\n Serial.print("Wait for WiFi... ");\n while(WiFiMulti.run() != WL_CONNECTED) {\n Serial.print(".");\n delay(500);\n }\n Serial.println("");\n Serial.println("WiFi connected");');return""};Blockly.Python.wifinetwork_getMacAddr=function(a){return["WiFi.macAddress()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.wifinetwork_getGatewayIp=function(a){return["WiFi.gatewayIP()",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.wifinetwork_AP_setup=function(a){Blockly.Python.addInclude("wifi_esp8266_declaration","#include <ESP8266WiFi.h>\n");Blockly.Python.addInclude("wifi_client_declaration","#include <WiFiClient.h>\n");Blockly.Python.addInclude("wifi_esp8266_webserver_declaration","#include <ESP8266WebServer.h>\n");var b=Blockly.Python.valueToCode(a,"SSID",Blockly.Python.ORDER_ATOMIC)||"";a=Blockly.Python.valueToCode(a,"PW",Blockly.Python.ORDER_ATOMIC)||"";Blockly.Python.addSetup("AP_setup",'delay(1000);\nSerial.begin(9600);\nSerial.println();\nSerial.print("Configuring access point...");\nWiFi.softAP('+
- b+","+a+');\nIPAddress myIP = WiFi.softAPIP();\nSerial.print("AP IP address: ");\nSerial.println(myIP);\n');return""};
- Blockly.Python.wifiNetwork_network=function(a){Blockly.Python.addInclude("wifi_esp8266_declaration","#include <ESP8266WiFi.h>\n");Blockly.Python.addInclude("wifi_wifimulti_include_declaration","#include <ESP8266WiFiMulti.h>");var b=a.getFieldValue("wifi_ssid");a=a.getFieldValue("wifi_pw");Blockly.Python.addDeclaration("wifiMulti_declaration","ESP8266WiFiMulti WiFiMulti;\n");Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");Blockly.Python.addSetup("wifinetwork_connect",' WiFi.mode(WIFI_STA);\n delay(10);\n WiFiMulti.addAP("'+
- b+'","'+a+'");\n Serial.print("Wait for WiFi... ");\n while(WiFiMulti.run() != WL_CONNECTED) {\n Serial.print(".");\n delay(500);\n }\n Serial.println("");\n Serial.println("WiFi connected");');return""};
- Blockly.Python.wifiNetwork_AP=function(a){Blockly.Python.addInclude("wifi_esp8266_declaration","#include <ESP8266WiFi.h>\n");Blockly.Python.addInclude("wifi_client_declaration","#include <WiFiClient.h>\n");Blockly.Python.addInclude("wifi_esp8266_webserver_declaration","#include <ESP8266WebServer.h>\n");Blockly.Python.addSetup("serial_9600","Serial.begin(9600);");var b=a.getFieldValue("SSID")||"";a=a.getFieldValue("PW")||"";Blockly.Python.addSetup("AP_setup",'delay(1000);\nSerial.println();\nSerial.print("Configuring access point...");\nWiFi.softAP("'+
- b+'","'+a+'");\nIPAddress myAPIP = WiFi.softAPIP();\nSerial.print("AP IP address: ");\nSerial.println(myAPIP);\n');return""};Blockly.Python.wifiNetwork_getLocalIp=function(a){Blockly.Python.addDeclaration("myWiFiModuleIp","String myWiFiModuleIp;");Blockly.Python.addSetup("getlocalIP",'IPAddress myIP = WiFi.localIP();\n myWiFiModuleIp = String(myIP[0]) + "." + String(myIP[1]) + "." + String(myIP[2]) + "." + String(myIP[3]);\n');return["myWiFiModuleIp",Blockly.Python.ORDER_ATOMIC]};
- Blockly.Python.wifiNetwork_isConnected=function(a){return["(WiFiMulti.run() == WL_CONNECTED)",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.wifiNetwork_getStationNum=function(a){return["WiFi.softAPgetStationNum()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.wifiserver={};Blockly.Python.wifiServer_onNotFound=function(a){a=Blockly.Python.valueToCode(a,"VAR",Blockly.Python.ORDER_ATOMIC)||"";Blockly.Python.addSetup("setRouter_urlNotFound","server.onNotFound("+a+");");return""};
- Blockly.Python.wifiServer_serverSend=function(a){var b=Blockly.Python.valueToCode(a,"CODE",Blockly.Python.ORDER_ATOMIC)||"",c=Blockly.Python.valueToCode(a,"TYPE",Blockly.Python.ORDER_ATOMIC)||"";a=Blockly.Python.valueToCode(a,"CONTENT",Blockly.Python.ORDER_ATOMIC)||"";return["server.send("+b+","+c+","+a+");",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.wifiServer_handleClient=function(a){return"server.handleClient();\n"};Blockly.Python.wifiServer_waitConnection=function(a){return""};
- Blockly.Python.wifiServer_setup=function(a){Blockly.Python.addInclude("wifi_server","#include <ESP8266WebServer.h>");Blockly.Python.addInclude("json_include","#include <ArduinoJson.h>");Blockly.Python.addDeclaration("SetupWiFiServer_80","ESP8266WebServer server(80);");return""};
- Blockly.Python.wifiServer_setRouter=function(a){for(var b="",c=0;c<a.itemCount_;c++){var d=a.getFieldValue("URL"+c)||"/"+c,e=Blockly.Python.statementToCode(a,"STATEMENT"+c);b+='server.on("'+d+'",[]() {\n'+e+'\n server.send(200,"text/plain","200");\n});\n'}Blockly.Python.addSetup("setRouter",b);Blockly.Python.addSetup("setRouter_onNotFound",' server.onNotFound([]() {\n server.send(404,"text/plain","404:Not found");\n });');Blockly.Python.addSetup("ServerBegin","server.begin();\n");return"server.handleClient();\n"};
- Blockly.Python.wifiServer_setRootPage=function(a){a=Blockly.Python.statementToCode(a,"STATEMENT0");Blockly.Python.addSetup("setRootPage",'server.on("/",[]() {\n'+a+'\n server.send(200,"text/plain","200");\n});\n');Blockly.Python.addSetup("setRouter_onNotFound",' server.onNotFound([]() {\n server.send(404,"text/plain","404:Not found");\n });');Blockly.Python.addSetup("ServerBegin","server.begin();\n");return"server.handleClient();\n"};
- Blockly.Python.wifiServer_Send=function(a){Blockly.Python.addInclude("json_include","#include <ArduinoJson.h>");for(var b=a.getFieldValue("VAR")||"json",c="StaticJsonBuffer<800> Serverbuffer_"+b+";\nJsonObject& "+b+"_json_ = Serverbuffer_"+b+".createObject();\nJsonArray& data_json_S = "+b+'_json_.createNestedArray("data");\n',d,e=0;e<a.itemCount_;e++)d=Blockly.Python.valueToCode(a,"ADD"+e,Blockly.Python.ORDER_NONE)||"",c+="data_json_S.add("+d+");\n";return c+("String jsonString;\n"+b+'_json_.printTo(jsonString);\n server.send(200, "application/json", jsonString);\n')};
- Blockly.Python.wifiServer_Receive=function(a){Blockly.Python.addInclude("json_declaration","#include <ArduinoJson.h>");var b=a.getFieldValue("VAR")||"";a=a.getFieldValue("LENGTH")||"";Blockly.Python.addDeclaration("data_dec"+b,"String data_"+b+"["+a+"];\n");Blockly.Python.addFunction("Server_receiver_"+b,"void server_receiver_"+b+"(String data) { StaticJsonBuffer<800> ParseBuffer_"+b+";\n JsonObject& parse_"+b+" = ParseBuffer_"+b+".parseObject(data);\n for (int i = 0; i < "+a+"; i++) {\n data_"+
- b+"[i] = parse_"+b+'["data"][i].as<String>();\n }\n}\n');return' String data = server.arg("plain");\nserver_receiver_'+b+'(data);\nserver.send(200,"text/plain",data);\n'};Blockly.Python.wifiServer_Receive_getValue=function(a){var b=a.getFieldValue("VAR")||"",c=a.getFieldValue("INDEX")||"";a=a.getFieldValue("TYPE")||"";b="data_"+b+"["+c+"]";"Int"==a&&(b+=".toInt()");return[b,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.wifiwebservices={};var eventIdentifier="";
- Blockly.Python.wifiwebservices_ifttt_simple=function(a){var b=Blockly.Python.valueToCode(a,"KEY",Blockly.Python.ORDER_ATOMIC).replace(/"/g,"")||"",c=Blockly.Python.valueToCode(a,"EVENT",Blockly.Python.ORDER_ATOMIC).replace(/"/g,"")||"",d=Blockly.Python.valueToCode(a,"VALUE1",Blockly.Python.ORDER_ATOMIC)||"",e=Blockly.Python.valueToCode(a,"VALUE2",Blockly.Python.ORDER_ATOMIC)||"";a=Blockly.Python.valueToCode(a,"VALUE3",Blockly.Python.ORDER_ATOMIC)||"";Blockly.Python.addInclude("jsontool_declaration",
- "#include <ArduinoJson.h>");Blockly.Python.addInclude("wifi_httpclient","#include <ESP8266HTTPClient.h>");Blockly.Python.addDeclaration("httpclient","HTTPClient http;");Blockly.Python.addDeclaration("jsontool_prettyPrint","char JSONmessageBuffer[240];\n");return'StaticJsonBuffer<800> JSONbuffer;\nJsonObject& JSONencoder = JSONbuffer.createObject();\nJSONencoder["value1"] = String('+d+');\nJSONencoder["value2"] = String('+e+');\nJSONencoder["value3"] = String('+a+');\nJSONencoder.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));\nSerial.println(JSONmessageBuffer);\nif (WiFi.status() == WL_CONNECTED) {\n http.begin("http://maker.ifttt.com/trigger/'+
- (c+"/with/key/"+b)+'");\n http.addHeader("Content-Type", "application/json");\n int httpCode = http.POST(JSONmessageBuffer);\n String payload = http.getString();\n // Serial.println(httpCode);\n // Serial.println(payload);\n http.end();\n} else {\n Serial.println("Error in WiFi connection");\n}\n'};
- Blockly.Python.wifiwebservices_thinkspeak_simple=function(a){for(var b,c,d="http://api.thingspeak.com/update?api_key="+(Blockly.Python.valueToCode(a,"KEY",Blockly.Python.ORDER_ATOMIC).replace(/"/g,"")||""),e=0;e<this.itemCount_;e++)b=a.getFieldValue("FIELD"+e),c=Blockly.Python.valueToCode(this,"ADD"+e,Blockly.Python.ORDER_NONE)||"",d+="&"+b+'="+String('+c+')+"';Blockly.Python.addInclude("wifi_httpclient","#include <ESP8266HTTPClient.h>");Blockly.Python.addDeclaration("httpclient","HTTPClient http;");
- return'http.begin("'+d+'");\nhttp.GET();\nhttp.end();\ndelay(500);\n'};
- Blockly.Python.wifiServices_thingspeak=function(a){for(var b,c="http://api.thingspeak.com/update?api_key="+a.getFieldValue("API_KEY"),d=0;d<this.itemCount_;d++)a="field"+(d+1),b=Blockly.Python.valueToCode(this,"ADD"+d,Blockly.Python.ORDER_NONE)||"",c+="&"+a+'="+String('+b+')+"';Blockly.Python.addInclude("wifi_httpclient","#include <ESP8266HTTPClient.h>");Blockly.Python.addDeclaration("httpclient","HTTPClient http;");return'http.begin("'+c+'");\nhttp.GET();\nhttp.end();\ndelay(500);\n'};
- Blockly.Python.wifiServices_IFTTT=function(a){Blockly.Python.addInclude("jsontool_declaration","#include <ArduinoJson.h>");Blockly.Python.addInclude("wifi_httpclient","#include <ESP8266HTTPClient.h>");Blockly.Python.addDeclaration("httpclient","HTTPClient http;");Blockly.Python.addDeclaration("HTTP_code","int httpCode;");Blockly.Python.addDeclaration("payload","String payload;");Blockly.Python.addDeclaration("jsontool_prettyPrint","char JSONmessageBuffer[240];\n");var b=a.getFieldValue("IFTTT_KEY").replace(/"/g,
- "")||"";b="http://maker.ifttt.com/trigger/"+(a.getFieldValue("IFTTT_EVENT").replace(/"/g,"")||"")+"/with/key/"+b;var c=a.getType();a.onChange();if(2==c)var d='if (WiFi.status() == WL_CONNECTED) {\n if ((millis() % 1000) /100 % 5 == 0 ) {\n http.begin("'+b+'");\n httpCode = http.GET();\n payload = http.getString();\n // Serial.println(httpCode);\n // Serial.println(payload);\n http.end();\n }\n} else {\n Serial.println("Error in WiFi connection");\n}\n';else 1==c&&(d=Blockly.Python.valueToCode(a,
- "data0",Blockly.Python.ORDER_ATOMIC)||"",c=Blockly.Python.valueToCode(a,"data1",Blockly.Python.ORDER_ATOMIC)||"",a=Blockly.Python.valueToCode(a,"data2",Blockly.Python.ORDER_ATOMIC)||"",d=' StaticJsonBuffer<800> JSONbuffer_ifttt;\n JsonObject& JSONencoder = JSONbuffer_ifttt.createObject();\n JSONencoder["value1"] = String('+d+');\n JSONencoder["value2"] = String('+c+');\n JSONencoder["value3"] = String('+a+');\n JSONencoder.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));\n Serial.println(JSONmessageBuffer);\n if (WiFi.status() == WL_CONNECTED) {\n http.begin("'+
- b+'");\n http.addHeader("Content-Type", "application/json");\n httpCode = http.POST(JSONmessageBuffer);\n payload = http.getString();\n Serial.println(httpCode);\n Serial.println(payload);\n http.end();\n delay(500);\n } else {\n Serial.println("Error in WiFi connection");\n }\n');return d};
- Blockly.Python.wifiServices_cococloud_post=function(a){Blockly.Python.addInclude("wifi_httpclient","#include <ESP8266HTTPClient.h>");Blockly.Python.addDeclaration("HTTP_Response","String http_response;");Blockly.Python.addDeclaration("HTTP_code","int httpCode;");Blockly.Python.addSetup("serial_serial","Serial.begin(9600);");Blockly.Python.addDeclaration("httpclient","HTTPClient http;");Blockly.Python.addDeclaration("payload","String payload;");Blockly.Python.addInclude("json_declaration","#include <ArduinoJson.h>");
- Blockly.Python.addDeclaration("jsontool_prettyPrint","char JSONmessageBuffer[240];\n");var b="http://api.cocorobo.cn/iot/data/eventAPIKey/"+a.getFieldValue("event0");var c="StaticJsonBuffer<800> JSONbuffer_easymode;\nJsonObject& Json_easymode = JSONbuffer_easymode.createObject();\n";for(var d=0;d<this.itemCount_;d++){var e=a.getFieldValue("field"+d),f=Blockly.Python.valueToCode(this,"ADD"+d,Blockly.Python.ORDER_NONE)||"0";c+='Json_easymode["'+e+'"]='+f+";\n"}return c+('if ((millis() % 1000) /100 % 5 == 0 ) {\n Json_easymode.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));\n http.begin("'+
- b+'");\n http.addHeader("Content-Type", "application/json");\n httpCode = http.POST(JSONmessageBuffer);\n payload = http.getString();\n Serial.println(httpCode);\n Serial.println(payload);\n http.end();\n}\n')};
- Blockly.Python.wifiServices_cococloud_get=function(a){Blockly.Python.addInclude("wifi_httpclient","#include <ESP8266HTTPClient.h>");Blockly.Python.addDeclaration("HTTP_Response","String http_response;");Blockly.Python.addDeclaration("HTTP_code","int httpCode;");Blockly.Python.addSetup("serial_serial","Serial.begin(9600);");Blockly.Python.addDeclaration("httpclient","HTTPClient http;");Blockly.Python.addDeclaration("cococloud_Response","String cococloud_response;");Blockly.Python.addDeclaration("payload",
- "String payload;");Blockly.Python.addInclude("json_declaration","#include <ArduinoJson.h>");var b="",c="http://api.cocorobo.cn/iot/data/eventAPIKey/"+a.getFieldValue("event0");eventIdentifier=a.getFieldValue("event0").slice(0,5);b+='if ((millis() % 1000) /100 % 5 == 0 ) {\n http.begin("'+c+'");\n http.addHeader("Content-Type", "application/json");\n httpCode = http.GET();\n payload = http.getString();\n cococloud_response = payload;\n // Serial.println(httpCode);\n // Serial.println(payload);\n http.end();\n}\nStaticJsonBuffer<800> jsonBuffer_easymode_'+
- a.getFieldValue("event0").slice(0,5)+";\nJsonObject& cloud_data_"+a.getFieldValue("event0").slice(0,5)+" = jsonBuffer_easymode_"+a.getFieldValue("event0").slice(0,5)+".parseObject(cococloud_response);\n";for(var d=0;d<this.itemCount_;d++){c=Blockly.Python.variableDB_.getName(a.getFieldValue("DATA"+d),Blockly.Variables.NAME_TYPE);var e=Blockly.Python.valueToCode(this,"ADD"+d,Blockly.Python.ORDER_NONE)||'""';b+=""+c+"="+e+";\n"}return b};
- Blockly.Python.wifiServices_cococloud_get_data=function(a){var b=a.getFieldValue("KEY");a=a.getFieldValue("VAR_TYPE");"Text"==a?a="char*":"Number"==a&&(a="int");return["cloud_data_"+eventIdentifier+'["data"][0]["'+b+'"].as<'+a+">()",Blockly.Python.ORDER_ATOMIC]};
|