// Do not edit this file; automatically generated by build.py.
'use strict';


Blockly.Python=new Blockly.Generator("Python");Blockly.Python.addReservedWords("and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is,lambda,not,or,pass,print,raise,return,try,while,with,yield,True,False,None,NotImplemented,Ellipsis,__debug__,quit,exit,copyright,license,credits,abs,divmod,input,open,staticmethod,all,enumerate,int,ord,str,any,eval,isinstance,pow,sum,basestring,execfile,issubclass,print,super,bin,file,iter,property,tuple,bool,filter,len,range,type,bytearray,float,list,raw_input,unichr,callable,format,locals,reduce,unicode,chr,frozenset,long,reload,vars,classmethod,getattr,map,repr,xrange,cmp,globals,max,reversed,zip,compile,hasattr,memoryview,round,__import__,complex,hash,min,set,apply,delattr,help,next,setattr,buffer,dict,hex,object,slice,coerce,dir,id,oct,sorted,intern");
Blockly.Python.ORDER_ATOMIC=0;Blockly.Python.ORDER_COLLECTION=1;Blockly.Python.ORDER_STRING_CONVERSION=1;Blockly.Python.ORDER_MEMBER=2;Blockly.Python.ORDER_FUNCTION_CALL=2;Blockly.Python.ORDER_EXPONENTIATION=3;Blockly.Python.ORDER_UNARY_SIGN=4;Blockly.Python.ORDER_BITWISE_NOT=4;Blockly.Python.ORDER_MULTIPLICATIVE=5;Blockly.Python.ORDER_ADDITIVE=6;Blockly.Python.ORDER_BITWISE_SHIFT=7;Blockly.Python.ORDER_BITWISE_AND=8;Blockly.Python.ORDER_BITWISE_XOR=9;Blockly.Python.ORDER_BITWISE_OR=10;
Blockly.Python.ORDER_RELATIONAL=11;Blockly.Python.ORDER_LOGICAL_NOT=12;Blockly.Python.ORDER_LOGICAL_AND=13;Blockly.Python.ORDER_LOGICAL_OR=14;Blockly.Python.ORDER_CONDITIONAL=15;Blockly.Python.ORDER_LAMBDA=16;Blockly.Python.ORDER_NONE=99;
Blockly.Python.init=function(a){Blockly.Python.PASS=this.INDENT+"pass\n";Blockly.Python.definitions_=Object.create(null);Blockly.Python.functionNames_=Object.create(null);Blockly.Python.variableDB_?Blockly.Python.variableDB_.reset():Blockly.Python.variableDB_=new Blockly.Names(Blockly.Python.RESERVED_WORDS_);var b=[];a=Blockly.Variables.allVariables(a);for(var c=0;c<a.length;c++)b[c]=Blockly.Python.variableDB_.getName(a[c],Blockly.Variables.NAME_TYPE)+" = None";Blockly.Python.definitions_.variables=
b.join("\n")};Blockly.Python.finish=function(a){var b=[],c=[],d;for(d in Blockly.Python.definitions_){var e=Blockly.Python.definitions_[d];e.match(/^(from\s+\S+\s+)?import\s+\S+/)?b.push(e):c.push(e)}delete Blockly.Python.definitions_;delete Blockly.Python.functionNames_;Blockly.Python.variableDB_.reset();return(b.join("\n")+"\n\n"+c.join("\n\n")).replace(/\n\n+/g,"\n\n").replace(/\n*$/,"\n\n\n")+a};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){var c="";if(!a.outputConnection||!a.outputConnection.targetConnection){var d=a.getCommentText();d&&(c+=Blockly.Python.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=Blockly.Python.allNestedComments(d))&&(c+=Blockly.Python.prefixLines(d,"# "))}e=a.nextConnection&&a.nextConnection.targetBlock();e=Blockly.Python.blockToCode(e);return c+b+e};Blockly.Python.AIYBoard={};Blockly.Python.AIYBoard_from=function(a){return"from aiy.board "+(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_NONE)||"__")+"\n"};Blockly.Python.AIYBoard_import=function(a){return["import "+a.getFieldValue("BOARD"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.AIYBoard_Board=function(a){return["Board()",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.AIYBoard_LED_state=function(a){return[(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__")+".led.state",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.AIYBoard_LED_status=function(a){return[(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__")+".led.status",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.AIYBoard_LED_setting=function(a){return["Led."+a.getFieldValue("SETTING"),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.AIYBoard_board=function(a){return["board",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.AIYBoard_button=function(a){return["button",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.AIYBoard_button_press=function(a){return"def _on_button_pressed(self):\n"+Blockly.Python.statementToCode(a,"STACK")};Blockly.Python.AIYBoard_board_led_status=function(a){return"self._board.led.status = "+Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)+"\n"};
Blockly.Python.AIYBoard_board_led_state=function(a){return"self._board.led.state = "+Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)+"\n"};/*
 Licensed under the Apache License, Version 2.0 (the "License"):
          http://www.apache.org/licenses/LICENSE-2.0
*/
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.camera={};Blockly.Python.camera_import=function(a){return"from picamera import PiCamera\n"};Blockly.Python.camera_use=function(a){var b=a.getFieldValue("CAMERA"),c=a.getFieldValue("SENSOR"),d=a.getFieldValue("X"),e=a.getFieldValue("Y"),f=a.getFieldValue("FPS");a=Blockly.Python.statementToCode(a,"STACK");return"with PiCamera(sensor_mode="+c+", resolution=("+d+", "+e+"),\nframerate="+f+") as "+b+":\n"+a};
Blockly.Python.camera_enable=function(a){return"camera."+a.getFieldValue("MODE")+"_preview()\n"};Blockly.Python.camera_set_bounding=function(a){var b=a.getFieldValue("X"),c=a.getFieldValue("Y"),d=a.getFieldValue("WIDTH");a=a.getFieldValue("HEIGHT");return b+", "+c+", "+d+", "+a+" = bounding_box\n"};Blockly.Python["class"]={};Blockly.Python.class_creation=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("CLASS"),Blockly.Variables.NAME_TYPE)||"___";a=Blockly.Python.statementToCode(a,"BODY")||Blockly.Python.PASS;return"class "+b+":\n"+a};
Blockly.Blocks.attribute_access={init:function(){this.appendValueInput("MODULE").setCheck(null);this.appendValueInput("NAME").setCheck(null).appendField(".");this.setInputsInline(!0);this.setOutput(!0,null);this.setColour(230);this.setTooltip("");this.setHelpUrl("")}};Blockly.Python.attribute_access=function(a){var b=Blockly.Python.valueToCode(a,"MODULE",Blockly.Python.ORDER_MEMBER);a=Blockly.Python.valueToCode(a,"NAME",Blockly.Python.ORDER_MEMBER);return[b+"."+a,Blockly.Python.ORDER_NONE]};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=function(a){return["'"+a.getFieldValue("COLOUR")+"'",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.colour_random=function(a){Blockly.Python.definitions_.import_random="import random";return["'#%06x' % random.randint(0, 2**24 - 1)",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.colour_rgb=function(a){var b=Blockly.Python.provideFunction_("colour_rgb",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(r, g, b):","  r = round(min(100, max(0, r)) * 2.55)","  g = round(min(100, max(0, g)) * 2.55)","  b = round(min(100, max(0, b)) * 2.55)","  return '#%02x%02x%02x' % (r, g, b)"]),c=Blockly.Python.valueToCode(a,"RED",Blockly.Python.ORDER_NONE)||0,d=Blockly.Python.valueToCode(a,"GREEN",Blockly.Python.ORDER_NONE)||0;a=Blockly.Python.valueToCode(a,"BLUE",Blockly.Python.ORDER_NONE)||
0;return[b+"("+c+", "+d+", "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.colour_blend=function(a){var b=Blockly.Python.provideFunction_("colour_blend",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(colour1, colour2, ratio):","  r1, r2 = int(colour1[1:3], 16), int(colour2[1:3], 16)","  g1, g2 = int(colour1[3:5], 16), int(colour2[3:5], 16)","  b1, b2 = int(colour1[5:7], 16), int(colour2[5:7], 16)","  ratio = min(1, max(0, ratio))","  r = round(r1 * (1 - ratio) + r2 * ratio)","  g = round(g1 * (1 - ratio) + g2 * ratio)","  b = round(b1 * (1 - ratio) + b2 * ratio)",
"  return '#%02x%02x%02x' % (r, g, b)"]),c=Blockly.Python.valueToCode(a,"COLOUR1",Blockly.Python.ORDER_NONE)||"'#000000'",d=Blockly.Python.valueToCode(a,"COLOUR2",Blockly.Python.ORDER_NONE)||"'#000000'";a=Blockly.Python.valueToCode(a,"RATIO",Blockly.Python.ORDER_NONE)||0;return[b+"("+c+", "+d+", "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};Blockly.Python.comment={};Blockly.Python.comment_single=function(a){return"# "+a.getFieldValue("BODY")+"\n"};Blockly.Python.string_multiline=function(a){return['"""'+a.getFieldValue("TEXT")+'"""\n',Blockly.Python.ORDER_ATOMIC]};Blockly.Python.comprehensions={};Blockly.Python.list_comprehension=function(a){var b=Blockly.Python.valueToCode(a,"body",Blockly.Python.ORDER_ATOMIC)||"___",c=Blockly.Python.valueToCode(a,"var",Blockly.Python.ORDER_ATOMIC)||"___";a=Blockly.Python.valueToCode(a,"list",Blockly.Python.ORDER_ATOMIC)||"___";return["["+b+" for "+c+" in "+a+"]",Blockly.Python.ORDER_NONE]};Blockly.Python.corgis={};
Blockly.Python.weather_temperature_get=function(a){Blockly.Python.definitions_.get_temperatures="__temperatures = [{'Min Temp': 32, 'Max Temp': 46, 'Avg Temp': 39}, {'Min Temp': 31, 'Max Temp': 47, 'Avg Temp': 39}, {'Min Temp': 41, 'Max Temp': 51, 'Avg Temp': 46}, {'Min Temp': 38, 'Max Temp': 52, 'Avg Temp': 45}, {'Min Temp': 29, 'Max Temp': 38, 'Avg Temp': 34}, {'Min Temp': 31, 'Max Temp': 44, 'Avg Temp': 38}, {'Min Temp': 24, 'Max Temp': 36, 'Avg Temp': 30}, {'Min Temp': 9, 'Max Temp': 32, 'Avg Temp': 22}, {'Min Temp': 31, 'Max Temp': 36, 'Avg Temp': 34}, {'Min Temp': 33, 'Max Temp': 43, 'Avg Temp': 38}, {'Min Temp': 23, 'Max Temp': 39, 'Avg Temp': 31}, {'Min Temp': 4, 'Max Temp': 30, 'Avg Temp': 14}, {'Min Temp': 19, 'Max Temp': 34, 'Avg Temp': 27}, {'Min Temp': 35, 'Max Temp': 42, 'Avg Temp': 39}, {'Min Temp': 37, 'Max Temp': 42, 'Avg Temp': 40}, {'Min Temp': 31, 'Max Temp': 40, 'Avg Temp': 36}, {'Min Temp': 30, 'Max Temp': 37, 'Avg Temp': 34}, {'Min Temp': 33, 'Max Temp': 41, 'Avg Temp': 37}, {'Min Temp': 35, 'Max Temp': 42, 'Avg Temp': 39}, {'Min Temp': 36, 'Max Temp': 42, 'Avg Temp': 40}, {'Min Temp': 20, 'Max Temp': 33, 'Avg Temp': 27}, {'Min Temp': 20, 'Max Temp': 39, 'Avg Temp': 30}, {'Min Temp': 25, 'Max Temp': 32, 'Avg Temp': 29}, {'Min Temp': -9, 'Max Temp': 8, 'Avg Temp': 0}, {'Min Temp': 32, 'Max Temp': 42, 'Avg Temp': 37}, {'Min Temp': 60, 'Max Temp': 60, 'Avg Temp': 60}, {'Min Temp': 60, 'Max Temp': 60, 'Avg Temp': 60}, {'Min Temp': 60, 'Max Temp': 60, 'Avg Temp': 60}, {'Min Temp': 39, 'Max Temp': 46, 'Avg Temp': 43}, {'Min Temp': 33, 'Max Temp': 42, 'Avg Temp': 38}, {'Min Temp': 29, 'Max Temp': 35, 'Avg Temp': 32}, {'Min Temp': 23, 'Max Temp': 39, 'Avg Temp': 32}, {'Min Temp': 13, 'Max Temp': 29, 'Avg Temp': 21}, {'Min Temp': 2, 'Max Temp': 9, 'Avg Temp': 6}, {'Min Temp': 32, 'Max Temp': 40, 'Avg Temp': 36}, {'Min Temp': 24, 'Max Temp': 57, 'Avg Temp': 41}, {'Min Temp': 25, 'Max Temp': 54, 'Avg Temp': 40}, {'Min Temp': 45, 'Max Temp': 69, 'Avg Temp': 58}, {'Min Temp': 43, 'Max Temp': 69, 'Avg Temp': 56}, {'Min Temp': 15, 'Max Temp': 42, 'Avg Temp': 29}, {'Min Temp': 27, 'Max Temp': 51, 'Avg Temp': 39}, {'Min Temp': 27, 'Max Temp': 48, 'Avg Temp': 38}, {'Min Temp': 34, 'Max Temp': 49, 'Avg Temp': 42}, {'Min Temp': 33, 'Max Temp': 60, 'Avg Temp': 47}, {'Min Temp': 12, 'Max Temp': 42, 'Avg Temp': 27}, {'Min Temp': 21, 'Max Temp': 49, 'Avg Temp': 35}, {'Min Temp': 37, 'Max Temp': 51, 'Avg Temp': 44}, {'Min Temp': 33, 'Max Temp': 53, 'Avg Temp': 44}, {'Min Temp': 36, 'Max Temp': 55, 'Avg Temp': 46}, {'Min Temp': 41, 'Max Temp': 53, 'Avg Temp': 47}, {'Min Temp': 43, 'Max Temp': 65, 'Avg Temp': 54}, {'Min Temp': 45, 'Max Temp': 63, 'Avg Temp': 55}, {'Min Temp': 36, 'Max Temp': 50, 'Avg Temp': 44}, {'Min Temp': 38, 'Max Temp': 51, 'Avg Temp': 45}, {'Min Temp': 34, 'Max Temp': 52, 'Avg Temp': 44}, {'Min Temp': 41, 'Max Temp': 57, 'Avg Temp': 49}, {'Min Temp': 45, 'Max Temp': 64, 'Avg Temp': 55}, {'Min Temp': 41, 'Max Temp': 51, 'Avg Temp': 46}, {'Min Temp': 33, 'Max Temp': 44, 'Avg Temp': 39}, {'Min Temp': 39, 'Max Temp': 62, 'Avg Temp': 51}, {'Min Temp': 37, 'Max Temp': 63, 'Avg Temp': 51}, {'Min Temp': 33, 'Max Temp': 51, 'Avg Temp': 42}, {'Min Temp': -5, 'Max Temp': 33, 'Avg Temp': 14}, {'Min Temp': 9, 'Max Temp': 45, 'Avg Temp': 28}, {'Min Temp': -23, 'Max Temp': 3, 'Avg Temp': -10}, {'Min Temp': 12, 'Max Temp': 40, 'Avg Temp': 27}, {'Min Temp': 4, 'Max Temp': 24, 'Avg Temp': 14}, {'Min Temp': 4, 'Max Temp': 47, 'Avg Temp': 26}, {'Min Temp': 32, 'Max Temp': 43, 'Avg Temp': 38}, {'Min Temp': 27, 'Max Temp': 40, 'Avg Temp': 34}, {'Min Temp': 27, 'Max Temp': 46, 'Avg Temp': 37}, {'Min Temp': 27, 'Max Temp': 46, 'Avg Temp': 37}, {'Min Temp': 58, 'Max Temp': 68, 'Avg Temp': 63}, {'Min Temp': 70, 'Max Temp': 82, 'Avg Temp': 76}, {'Min Temp': 51, 'Max Temp': 62, 'Avg Temp': 56}, {'Min Temp': 50, 'Max Temp': 61, 'Avg Temp': 56}, {'Min Temp': 74, 'Max Temp': 82, 'Avg Temp': 79}, {'Min Temp': 70, 'Max Temp': 82, 'Avg Temp': 76}, {'Min Temp': 57, 'Max Temp': 72, 'Avg Temp': 65}, {'Min Temp': 44, 'Max Temp': 52, 'Avg Temp': 48}, {'Min Temp': 48, 'Max Temp': 57, 'Avg Temp': 53}, {'Min Temp': 59, 'Max Temp': 71, 'Avg Temp': 66}, {'Min Temp': 62, 'Max Temp': 74, 'Avg Temp': 69}, {'Min Temp': 67, 'Max Temp': 80, 'Avg Temp': 74}, {'Min Temp': 47, 'Max Temp': 58, 'Avg Temp': 51}, {'Min Temp': 36, 'Max Temp': 54, 'Avg Temp': 45}, {'Min Temp': 36, 'Max Temp': 48, 'Avg Temp': 42}, {'Min Temp': 41, 'Max Temp': 56, 'Avg Temp': 48}, {'Min Temp': 40, 'Max Temp': 53, 'Avg Temp': 47}, {'Min Temp': 49, 'Max Temp': 62, 'Avg Temp': 56}, {'Min Temp': 65, 'Max Temp': 81, 'Avg Temp': 73}, {'Min Temp': 64, 'Max Temp': 81, 'Avg Temp': 73}, {'Min Temp': 60, 'Max Temp': 80, 'Avg Temp': 71}, {'Min Temp': 64, 'Max Temp': 79, 'Avg Temp': 72}, {'Min Temp': 60, 'Max Temp': 79, 'Avg Temp': 70}, {'Min Temp': 7, 'Max Temp': 23, 'Avg Temp': 15}, {'Min Temp': 12, 'Max Temp': 29, 'Avg Temp': 21}, {'Min Temp': -4, 'Max Temp': 21, 'Avg Temp': 8}, {'Min Temp': 20, 'Max Temp': 30, 'Avg Temp': 25}, {'Min Temp': 19, 'Max Temp': 31, 'Avg Temp': 25}]";return["__temperatures",
Blockly.Python.ORDER_ATOMIC]};Blockly.Python.weather_temperature=function(a){Blockly.Python.definitions_.import_weather="import weather";return["weather.get_temperature("+(Blockly.Python.quote_(a.getFieldValue("CITY"))+")"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.weather_forecasts=function(a){Blockly.Python.definitions_.import_weather="import weather";return["weather.get_forecasts("+(Blockly.Python.quote_(a.getFieldValue("CITY"))+")"),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.weather_highs_lows=function(a){Blockly.Python.definitions_.import_weather="import weather";return["weather.get_highs_lows("+(Blockly.Python.quote_(a.getFieldValue("CITY"))+")"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.weather_report=function(a){Blockly.Python.definitions_.import_weather="import weather";return["weather.get_report("+(Blockly.Python.quote_(a.getFieldValue("CITY"))+")"),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.weather_report_forecasts=function(a){Blockly.Python.definitions_.import_weather="import weather";return["weather.get_forecasted_reports("+(Blockly.Python.quote_(a.getFieldValue("CITY"))+")"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.weather_all_forecasts=function(a){Blockly.Python.definitions_.import_weather="import weather";return["weather.get_all_forecasted_temperatures()",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.stocks_current=function(a){Blockly.Python.definitions_.import_stocks="import stocks";return["stocks.get_current("+(Blockly.Python.quote_(a.getFieldValue("TICKER"))+")"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.stocks_past=function(a){Blockly.Python.definitions_.import_stocks="import stocks";return["stocks.get_past("+(Blockly.Python.quote_(a.getFieldValue("TICKER"))+")"),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.earthquake_get=function(a){Blockly.Python.definitions_.import_earthquakes="import earthquakes";return["earthquakes.get("+(Blockly.Python.quote_(a.getFieldValue("PROPERTY"))+")"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.earthquake_both=function(a){Blockly.Python.definitions_.import_earthquakes="import earthquakes";return["earthquakes.get_both()",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.earthquake_all=function(a){Blockly.Python.definitions_.import_earthquakes="import earthquakes";return["earthquakes.get_all()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.crime_state=function(a){Blockly.Python.definitions_.import_crime="import crime";var b="crime.get_"+a.getFieldValue("TYPE")+"_crimes(";a=Blockly.Python.quote_(a.getFieldValue("STATE"));return[b+(a+")"),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.crime_year=function(a){Blockly.Python.definitions_.import_crime="import crime";return["crime.get_by_year("+(Blockly.Python.quote_(a.getFieldValue("YEAR"))+")"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.crime_all=function(a){Blockly.Python.definitions_.import_crime="import crime";return["crime.get_all()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.books_get=function(a){Blockly.Python.definitions_.import_books="import books";return["books.get_all()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.decorator={};Blockly.Python.decorator=function(a){return"@"+(Blockly.Python.valueToCode(a,"BODY",Blockly.Python.ORDER_ATOMIC)||"___")+"\n"};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.dict={};Blockly.Python.dicts_create_with=function(a){Blockly.Python.valueToCode(a,"keys",Blockly.Python.ORDER_ATOMIC);for(var b=Array(a.itemCount_),c=1;c<=a.itemCount_;c++){var d=Blockly.Python.quote_(a.getFieldValue("KEY"+c)),e=Blockly.Python.valueToCode(a,"VALUE"+c,Blockly.Python.ORDER_NONE)||"___";b[c-1]=d+": "+e}b="{"+b.join(", ")+"}";return[b,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.dicts={};Blockly.Python.dict_get=function(a){var b=Blockly.Python.valueToCode(a,"DICT",Blockly.Python.ORDER_MEMBER)||"___";a=Blockly.Python.valueToCode(a,"ITEM",Blockly.Python.ORDER_NONE)||"___";return[b+"["+a+"]",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.dict_get_literal=function(a){var b=Blockly.Python.valueToCode(a,"DICT",Blockly.Python.ORDER_MEMBER)||"___";a=Blockly.Python.quote_(a.getFieldValue("ITEM"));return[b+"["+a+"]",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.dicts_create_with=function(a){Blockly.Python.valueToCode(a,"keys",Blockly.Python.ORDER_ATOMIC);for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++){var d=Blockly.Python.quote_(a.getFieldValue("KEY"+c)),e=Blockly.Python.valueToCode(a,"VALUE"+c,Blockly.Python.ORDER_NONE)||"___";b[c]=d+": "+e}b="{"+b.join(", ")+"}";return[b,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.dict_keys=function(a){return[(Blockly.Python.valueToCode(a,"DICT",Blockly.Python.ORDER_MEMBER)||"___")+".keys()",Blockly.Python.ORDER_ATOMIC]};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["if"]={};Blockly.Python.controls_if_better=function(a){var b=0,c="";do{var d=Blockly.Python.valueToCode(a,"IF"+b,Blockly.Python.ORDER_NONE)||"___";var e=Blockly.Python.statementToCode(a,"DO"+b)||Blockly.Python.PASS;c+=(0==b?"if ":"elif ")+d+":\n"+e;++b}while(a.getInput("IF"+b));a.getInput("ELSE")&&(e=Blockly.Python.statementToCode(a,"ELSE")||Blockly.Python.PASS,c+="else:\n"+e);return c};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.text_input=function(a){a=a.getFieldValue("MESSAGE");return["input("+Blockly.Python.quote_(a)+")",Blockly.JavaScript.ORDER_NONE]};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_empty=function(a){return["[]",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.lists_create_with=function(a){for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++)b[c]=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_NONE)||"___";return["["+b.join(", ")+"]",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.lists_repeat=function(a){var b=Blockly.Python.valueToCode(a,"ITEM",Blockly.Python.ORDER_NONE)||"___";a=Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_MULTIPLICATIVE)||"___";return["["+b+"] * "+a,Blockly.Python.ORDER_MULTIPLICATIVE]};Blockly.Python.lists_length=function(a){return["len("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___")+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.lists_isEmpty=function(a){return["not len("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___")+")",Blockly.Python.ORDER_LOGICAL_NOT]};
Blockly.Python.lists_indexOf=function(a){var b=Blockly.Python.valueToCode(a,"FIND",Blockly.Python.ORDER_NONE)||"___",c=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___";if(a.workspace.options.oneBasedIndex)var d=" 0",e=" + 1",f="";else d=" -1",e="",f=" - 1";if("FIRST"==a.getFieldValue("END"))return a=Blockly.Python.provideFunction_("first_index",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(my_list, elem):","  try: index = my_list.index(elem)"+e,"  except: index ="+d,"  return index"]),
[a+"("+c+", "+b+")",Blockly.Python.ORDER_FUNCTION_CALL];a=Blockly.Python.provideFunction_("last_index",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(my_list, elem):","  try: index = len(my_list) - my_list[::-1].index(elem)"+f,"  except: index ="+d,"  return index"]);return[a+"("+c+", "+b+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.lists_index=function(a){var b=Blockly.Python.valueToCode(a,"ITEM",Blockly.Python.ORDER_UNARY_SIGN)||"___";return[(Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_MEMBER)||"___")+"["+b+"]",Blockly.Python.ORDER_MEMBER]};
Blockly.Python.lists_getIndex=function(a){var b=a.getFieldValue("MODE")||"GET",c=a.getFieldValue("WHERE")||"FROM_START",d=Blockly.Python.valueToCode(a,"VALUE","RANDOM"==c?Blockly.Python.ORDER_NONE:Blockly.Python.ORDER_MEMBER)||"___";switch(c){case "FIRST":if("GET"==b)return[d+"[0]",Blockly.Python.ORDER_MEMBER];if("GET_REMOVE"==b)return[d+".pop(0)",Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+".pop(0)\n";break;case "LAST":if("GET"==b)return[d+"[-1]",Blockly.Python.ORDER_MEMBER];if("GET_REMOVE"==
b)return[d+".pop()",Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+".pop()\n";break;case "FROM_START":a=Blockly.Python.getAdjustedInt(a,"AT");if("GET"==b)return[d+"["+a+"]",Blockly.Python.ORDER_MEMBER];if("GET_REMOVE"==b)return[d+".pop("+a+")",Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+".pop("+a+")\n";break;case "FROM_END":a=Blockly.Python.getAdjustedInt(a,"AT",1,!0);if("GET"==b)return[d+"["+a+"]",Blockly.Python.ORDER_MEMBER];if("GET_REMOVE"==b)return[d+".pop("+a+")",
Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+".pop("+a+")\n";break;case "RANDOM":Blockly.Python.definitions_.import_random="import random";if("GET"==b)return["random.choice("+d+")",Blockly.Python.ORDER_FUNCTION_CALL];d=Blockly.Python.provideFunction_("lists_remove_random_item",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(myList):","  x = int(random.random() * len(myList))","  return myList.pop(x)"])+"("+d+")";if("GET_REMOVE"==b)return[d,Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==
b)return d+"\n"}throw"Unhandled combination (lists_getIndex).";};
Blockly.Python.lists_setIndex=function(a){var b=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_MEMBER)||"___",c=a.getFieldValue("MODE")||"GET",d=a.getFieldValue("WHERE")||"FROM_START",e=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"___";switch(d){case "FIRST":if("SET"==c)return b+"[0] = "+e+"\n";if("INSERT"==c)return b+".insert(0, "+e+")\n";break;case "LAST":if("SET"==c)return b+"[-1] = "+e+"\n";if("INSERT"==c)return b+".append("+e+")\n";break;case "FROM_START":a=Blockly.Python.getAdjustedInt(a,
"AT");if("SET"==c)return b+"["+a+"] = "+e+"\n";if("INSERT"==c)return b+".insert("+a+", "+e+")\n";break;case "FROM_END":a=Blockly.Python.getAdjustedInt(a,"AT",1,!0);if("SET"==c)return b+"["+a+"] = "+e+"\n";if("INSERT"==c)return b+".insert("+a+", "+e+")\n";break;case "RANDOM":Blockly.Python.definitions_.import_random="import random";b.match(/^\w+$/)?a="":(a=Blockly.Python.variableDB_.getDistinctName("tmp_list",Blockly.Variables.NAME_TYPE),d=a+" = "+b+"\n",b=a,a=d);d=Blockly.Python.variableDB_.getDistinctName("tmp_x",
Blockly.Variables.NAME_TYPE);a+=d+" = int(random.random() * len("+b+"))\n";if("SET"==c)return a+(b+"["+d+"] = "+e+"\n");if("INSERT"==c)return a+(b+".insert("+d+", "+e+")\n")}throw"Unhandled combination (lists_setIndex).";};
Blockly.Python.lists_getSublist=function(a){var b=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_MEMBER)||"___",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");switch(c){case "FROM_START":c=Blockly.Python.getAdjustedInt(a,"AT1");"0"==c&&(c="");break;case "FROM_END":c=Blockly.Python.getAdjustedInt(a,"AT1",1,!0);break;case "FIRST":c="";break;default:throw"Unhandled option (lists_getSublist)";}switch(d){case "FROM_START":a=Blockly.Python.getAdjustedInt(a,"AT2",1);break;case "FROM_END":a=
Blockly.Python.getAdjustedInt(a,"AT2",0,!0);Blockly.isNumber(String(a))?"0"==a&&(a=""):(Blockly.Python.definitions_.import_sys="import sys",a+=" or sys.maxsize");break;case "LAST":a="";break;default:throw"Unhandled option (lists_getSublist)";}return[b+"["+c+" : "+a+"]",Blockly.Python.ORDER_MEMBER]};
Blockly.Python.lists_sort=function(a){var b=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_NONE)||"[]",c=a.getFieldValue("TYPE");a="1"===a.getFieldValue("DIRECTION")?"False":"True";return[Blockly.Python.provideFunction_("lists_sort",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(my_list, type, reverse):","  def try_float(s):","    try:","      return float(s)","    except:","      return 0","  key_funcs = {",'    "NUMERIC": try_float,','    "TEXT": str,','    "IGNORE_CASE": lambda s: str(s).lower()',
"  }","  key_func = key_funcs[type]","  list_cpy = list(my_list)","  return sorted(list_cpy, key=key_func, reverse=reverse)"])+"("+b+', "'+c+'", '+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.lists_split=function(a){var b=a.getFieldValue("MODE");if("SPLIT"==b)b=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_MEMBER)||"___",a=Blockly.Python.valueToCode(a,"DELIM",Blockly.Python.ORDER_NONE),a=b+".split("+a+")";else if("JOIN"==b)b=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_NONE)||"___",a=Blockly.Python.valueToCode(a,"DELIM",Blockly.Python.ORDER_MEMBER)||"___",a=a+".join("+b+")";else throw"Unknown mode: "+b;return[a,Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.lists_append=function(a){var b=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_MEMBER)||"___";a=Blockly.Python.valueToCode(a,"ITEM",Blockly.Python.ORDER_NONE)||"___";return b+".append("+a+")\n"};Blockly.Python.log={};Blockly.Python.log_setup=function(a){return"import logging\n"};Blockly.Python.log_conf=function(a){return'logging.basicConfig(\n  level=logging.INFO,\n  format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s"\n)\n'};Blockly.Python.log_import=function(a){return"import logging\n"};Blockly.Python.log_info=function(a){return"logging.info("+(Blockly.Python.valueToCode(a,"LOG_INPUT",Blockly.Python.ORDER_NONE)||"___")+")\n"};
Blockly.Python.log_config=function(a){return"logging.basicConfig(level="+a.getFieldValue("LEVEL")+")\n"};Blockly.Python.logic={};Blockly.Python.controls_if=function(a){var b=0,c="";do{var d=Blockly.Python.valueToCode(a,"IF"+b,Blockly.Python.ORDER_NONE)||"___";var e=Blockly.Python.statementToCode(a,"DO"+b)||Blockly.Python.PASS;c+=(0==b?"if ":"elif ")+d+":\n"+e;++b}while(a.getInput("IF"+b));a.getInput("ELSE")&&(e=Blockly.Python.statementToCode(a,"ELSE")||Blockly.Python.PASS,c+="else:\n"+e);return c};
Blockly.Python.logic_compare=function(a){var b={EQ:"==",NEQ:"!=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")],c=Blockly.Python.ORDER_RELATIONAL,d=Blockly.Python.valueToCode(a,"A",c)||"___";a=Blockly.Python.valueToCode(a,"B",c)||"___";return[d+" "+b+" "+a,c]};
Blockly.Python.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"and":"or",c="and"==b?Blockly.Python.ORDER_LOGICAL_AND:Blockly.Python.ORDER_LOGICAL_OR,d=Blockly.Python.valueToCode(a,"A",c);a=Blockly.Python.valueToCode(a,"B",c);d||a?(d||(d="___"),a||(a="___")):a=d="___";return[d+" "+b+" "+a,c]};Blockly.Python.logic_negate=function(a){return["not "+(Blockly.Python.valueToCode(a,"BOOL",Blockly.Python.ORDER_LOGICAL_NOT)||"___"),Blockly.Python.ORDER_LOGICAL_NOT]};
Blockly.Python.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"True":"False",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.logic_null=function(a){return["None",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.logic_ternary=function(a){var b=Blockly.Python.valueToCode(a,"IF",Blockly.Python.ORDER_CONDITIONAL)||"___",c=Blockly.Python.valueToCode(a,"THEN",Blockly.Python.ORDER_CONDITIONAL)||"___";a=Blockly.Python.valueToCode(a,"ELSE",Blockly.Python.ORDER_CONDITIONAL)||"___";return[c+" if "+b+" else "+a,Blockly.Python.ORDER_CONDITIONAL]};
Blockly.Python.logic_isIn=function(a){var b="IN"==a.getFieldValue("OP")?"in":"not in",c=Blockly.Python.ORDER_RELATIONAL,d=Blockly.Python.valueToCode(a,"ITEM",c)||"___";a=Blockly.Python.valueToCode(a,"LIST",c)||"___";return[d+" "+b+" "+a,c]};Blockly.Python.logic_none=function(a){return["None",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.loops={};Blockly.Python.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(parseInt(a.getFieldValue("TIMES"),10)):Blockly.Python.valueToCode(a,"TIMES",Blockly.Python.ORDER_NONE)||"___";b=Blockly.isNumber(b)?parseInt(b,10):"int("+b+")";var c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a.id)||Blockly.Python.PASS;return"for "+Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE)+" in range("+b+"):\n"+c};
Blockly.Python.controls_repeat=Blockly.Python.controls_repeat_ext;Blockly.Python.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Python.valueToCode(a,"BOOL",b?Blockly.Python.ORDER_LOGICAL_NOT:Blockly.Python.ORDER_NONE)||"___",d=Blockly.Python.statementToCode(a,"DO");d=Blockly.Python.addLoopTrap(d,a.id)||Blockly.Python.PASS;b&&(c="not "+c);return"while "+c+":\n"+d};
Blockly.Python.controls_while=function(a){var b=Blockly.Python.valueToCode(a,"BOOL",Blockly.Python.ORDER_NONE)||"___",c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a.id)||Blockly.Python.PASS;return"while "+b+":\n"+c};
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_NONE)||"___",d=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"___",e=Blockly.Python.valueToCode(a,"BY",Blockly.Python.ORDER_NONE)||"___",f=Blockly.Python.statementToCode(a,"DO");f=Blockly.Python.addLoopTrap(f,a.id)||Blockly.Python.PASS;var g="",h=function(){return Blockly.Python.provideFunction_("upRange",
["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):","  while start <= stop:","    yield start","    start += abs(step)"])},l=function(){return Blockly.Python.provideFunction_("downRange",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):","  while start >= stop:","    yield start","    start -= abs(step)"])};a=function(a,b,c){return"("+a+" <= "+b+") and "+h()+"("+a+", "+b+", "+c+") or "+l()+"("+a+", "+b+", "+c+")"};if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&
Blockly.isNumber(e))c=parseFloat(c),d=parseFloat(d),e=Math.abs(parseFloat(e)),0===c%1&&0===d%1&&0===e%1?(c<=d?(d++,a=0==c&&1==e?d:c+", "+d,1!=e&&(a+=", "+e)):(d--,a=c+", "+d+", -"+e),a="range("+a+")"):(a=c<d?h():l(),a+="("+c+", "+d+", "+e+")");else{var k=function(a,c){if(Blockly.isNumber(a))a=parseFloat(a);else if(a.match(/^\w+$/))a="float("+a+")";else{var d=Blockly.Python.variableDB_.getDistinctName(b+c,Blockly.Variables.NAME_TYPE);g+=d+" = float("+a+")\n";a=d}return a};c=k(c,"_start");d=k(d,"_end");
k(e,"_inc");a="number"==typeof c&&"number"==typeof d?c<d?h(c,d,e):l(c,d,e):a(c,d,e)}return g+="for "+b+" in "+a+":\n"+f};Blockly.Python.controls_forEach=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_RELATIONAL)||"___",d=Blockly.Python.statementToCode(a,"DO");d=Blockly.Python.addLoopTrap(d,a.id)||Blockly.Python.PASS;return"for "+b+" in "+c+":\n"+d};
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.controls_pass=function(a){return"pass\n"};Blockly.Python.loop_forEach=function(a){var b=Blockly.Python.valueToCode(a,"ITEM",Blockly.Python.ORDER_ATOMIC)||"";a=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_ATOMIC)||"";return["for "+b+" in "+a,Blockly.Python.ORDER_ATOMIC]};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.addReservedWords("math,random,Number");Blockly.Python.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));if(Infinity==a){a='float("inf")';var b=Blockly.Python.ORDER_FUNCTION_CALL}else-Infinity==a?(a='-float("inf")',b=Blockly.Python.ORDER_UNARY_SIGN):b=0>a?Blockly.Python.ORDER_UNARY_SIGN:Blockly.Python.ORDER_ATOMIC;return[a,b]};
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:[" ** ",Blockly.Python.ORDER_EXPONENTIATION],MODULO:[" % ",Blockly.Python.ORDER_MULTIPLICATIVE]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=Blockly.Python.valueToCode(a,"A",b)||"___";a=Blockly.Python.valueToCode(a,"B",b)||"___";return[d+c+a,b]};
Blockly.Python.math_single=function(a){var b=a.getFieldValue("OP");if("NEG"==b){var c=Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_UNARY_SIGN)||"___";return["-"+c,Blockly.Python.ORDER_UNARY_SIGN]}"ABS"!=b&&"POW"!=b&&"ROUND"!=b&&(Blockly.Python.definitions_.import_math="import math");a="SIN"==b||"COS"==b||"TAN"==b?Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_MULTIPLICATIVE)||"___":Blockly.Python.valueToCode(a,"NUM",Blockly.Python.ORDER_NONE)||"___";switch(b){case "ABS":c="abs("+
a+")";break;case "ROOT":c="math.sqrt("+a+")";break;case "LN":c="math.log("+a+")";break;case "LOG10":c="math.log10("+a+")";break;case "EXP":c="math.exp("+a+")";break;case "POW10":c="pow(10,"+a+")";break;case "ROUND":c="round("+a+")";break;case "ROUNDUP":c="math.ceil("+a+")";break;case "ROUNDDOWN":c="math.floor("+a+")";break;case "SIN":c="math.sin("+a+" / 180.0 * math.pi)";break;case "COS":c="math.cos("+a+" / 180.0 * math.pi)";break;case "TAN":c="math.tan("+a+" / 180.0 * math.pi)"}if(c)return[c,Blockly.Python.ORDER_FUNCTION_CALL];
switch(b){case "ASIN":c="math.asin("+a+") / math.pi * 180";break;case "ACOS":c="math.acos("+a+") / math.pi * 180";break;case "ATAN":c="math.atan("+a+") / math.pi * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.Python.ORDER_MULTIPLICATIVE]};
Blockly.Python.math_constant=function(a){var b={PI:["math.pi",Blockly.Python.ORDER_MEMBER],E:["math.e",Blockly.Python.ORDER_MEMBER],GOLDEN_RATIO:["(1 + math.sqrt(5)) / 2",Blockly.Python.ORDER_MULTIPLICATIVE],SQRT2:["math.sqrt(2)",Blockly.Python.ORDER_MEMBER],SQRT1_2:["math.sqrt(1.0 / 2)",Blockly.Python.ORDER_MEMBER],INFINITY:["float('inf')",Blockly.Python.ORDER_ATOMIC]};a=a.getFieldValue("CONSTANT");"INFINITY"!=a&&(Blockly.Python.definitions_.import_math="import math");return b[a]};
Blockly.Python.math_number_property=function(a){var b=Blockly.Python.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Python.ORDER_MULTIPLICATIVE)||"___",c=a.getFieldValue("PROPERTY");if("PRIME"==c)return Blockly.Python.definitions_.import_math="import math",Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number",[Blockly.Python.provideFunction_("math_isPrime",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(n):","  # https://en.wikipedia.org/wiki/Primality_test#Naive_methods",
"  # If n is not a number but a string, try parsing it.","  if not isinstance(n, Number):","    try:","      n = float(n)","    except:","      return False","  if n == 2 or n == 3:","    return True","  # False if n is negative, is 1, or not whole, or if n is divisible by 2 or 3.","  if n <= 1 or n % 1 != 0 or n % 2 == 0 or n % 3 == 0:","    return False","  # Check all the numbers of form 6k +/- 1, up to sqrt(n).","  for x in range(6, int(math.sqrt(n)) + 2, 6):","    if n % (x - 1) == 0 or n % (x + 1) == 0:",
"      return False","  return True"])+"("+b+")",Blockly.Python.ORDER_FUNCTION_CALL];switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";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);if(!a||"0"==a)return["False",Blockly.Python.ORDER_ATOMIC];d=b+" % "+a+" == 0"}return[d,Blockly.Python.ORDER_RELATIONAL]};
Blockly.Python.math_change=function(a){var b=Blockly.Python.valueToCode(a,"DELTA",Blockly.Python.ORDER_ADDITIVE)||"___";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=function(a){var b=a.getFieldValue("OP");a=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_NONE)||"___";switch(b){case "SUM":b="sum("+a+")";break;case "MIN":b="min("+a+")";break;case "MAX":b="max("+a+")";break;case "AVERAGE":Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number";b=Blockly.Python.provideFunction_("math_mean",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(myList):","  localList = [e for e in myList if isinstance(e, Number)]",
"  if not localList: return","  return float(sum(localList)) / len(localList)"]);b=b+"("+a+")";break;case "MEDIAN":Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number";b=Blockly.Python.provideFunction_("math_median",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(myList):","  localList = sorted([e for e in myList if isinstance(e, Number)])","  if not localList: return","  if len(localList) % 2 == 0:","    return (localList[len(localList) // 2 - 1] + localList[len(localList) // 2]) / 2.0",
"  else:","    return localList[(len(localList) - 1) // 2]"]);b=b+"("+a+")";break;case "MODE":b=Blockly.Python.provideFunction_("math_modes",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(some_list):","  modes = []","  # Using a lists of [item, count] to keep count rather than dict",'  # to avoid "unhashable" errors when the counted item is itself a list or dict.',"  counts = []","  maxCount = 1","  for item in some_list:","    found = False","    for count in counts:","      if count[0] == item:",
"        count[1] += 1","        maxCount = max(maxCount, count[1])","        found = True","    if not found:","      counts.append([item, 1])","  for counted_item, item_count in counts:","    if item_count == maxCount:","      modes.append(counted_item)","  return modes"]);b=b+"("+a+")";break;case "STD_DEV":Blockly.Python.definitions_.import_math="import math";b=Blockly.Python.provideFunction_("math_standard_deviation",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(numbers):","  n = len(numbers)",
"  if n == 0: return","  mean = float(sum(numbers)) / n","  variance = sum((x - mean) ** 2 for x in numbers) / n","  return math.sqrt(variance)"]);b=b+"("+a+")";break;case "RANDOM":Blockly.Python.definitions_.import_random="import random";b="random.choice("+a+")";break;default:throw"Unknown operator: "+b;}return[b,Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.math_modulo=function(a){var b=Blockly.Python.valueToCode(a,"DIVIDEND",Blockly.Python.ORDER_MULTIPLICATIVE)||"___";a=Blockly.Python.valueToCode(a,"DIVISOR",Blockly.Python.ORDER_MULTIPLICATIVE)||"___";return[b+" % "+a,Blockly.Python.ORDER_MULTIPLICATIVE]};
Blockly.Python.math_constrain=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___",c=Blockly.Python.valueToCode(a,"LOW",Blockly.Python.ORDER_NONE)||"___";a=Blockly.Python.valueToCode(a,"HIGH",Blockly.Python.ORDER_NONE)||"___";return["min(max("+b+", "+c+"), "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.math_random_int=function(a){Blockly.Python.definitions_.import_random="import random";var b=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"___";a=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"___";return["random.randint("+b+", "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};Blockly.Python.math_random_float=function(a){Blockly.Python.definitions_.import_random="import random";return["random.random()",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.math_sum_values=function(a){var b=Blockly.Python.valueToCode(a,"SUM1",Blockly.Python.ORDER_ATOMIC)||"";a=Blockly.Python.valueToCode(a,"SUM2",Blockly.Python.ORDER_ATOMIC)||"";return["sum("+b+" "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};Blockly.Python.math_sum_common=function(a){return["sum("+(Blockly.Python.valueToCode(a,"SUM1",Blockly.Python.ORDER_ATOMIC)||"")+")",Blockly.Python.ORDER_FUNCTION_CALL]};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.parking={};
PythonToBlocks.KNOWN_MODULES.parking={today:["datetime_day",["DAY","TODAY"]],day_compare:["datetime_check_day","OP",{type:"variable",mode:"value",name:"LEFT"},{type:"mapper",name:"VALUE",method:convertDate}],Day:["datetime_day",{type:"mapper",name:"DAY",method:convertDate}],now:["datetime_time",["HOUR","NOW"]],Time:["datetime_time",{type:"integer",name:"HOUR",add_mutation:{name:"@isnow",value:"false"}},{type:"integer_mapper",name:"MINUTE",method:convertMinute},"MERIDIAN"],time_compare:["datetime_check_time",
"OP",{type:"variable",mode:"value",name:"LEFT"},{type:"integer",name:"HOURS"},{type:"integer_mapper",name:"MINUTES",method:convertMinute},"MERIDIANS"]};Blockly.Python.datetime_day=function(a){Blockly.Python.definitions_.import_parking="import parking";return[DAYS_MAP[a.getFieldValue("DAY").slice(0,3).toLowerCase()],Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.datetime_check_time=function(a){Blockly.Python.definitions_.import_parking="import parking";var b=parseInt(a.getFieldValue("HOURS")),c=parseInt(a.getFieldValue("MINUTES")),d=Blockly.Python.quote_(a.getFieldValue("MERIDIANS")),e=Blockly.Python.quote_(a.getFieldValue("OP"));a=Blockly.Python.valueToCode(a,"LEFT",Blockly.Python.ORDER_ATOMIC);return["parking.time_compare("+e+", "+a+","+b+","+c+","+d+")",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.datetime_check_day=function(a){Blockly.Python.definitions_.import_parking="import parking";var b=Blockly.Python.quote_(a.getFieldValue("VALUE")),c=Blockly.Python.quote_(a.getFieldValue("OP"));a=Blockly.Python.valueToCode(a,"LEFT",Blockly.Python.ORDER_ATOMIC)||"___";return["parking.day_compare("+c+", "+a+", "+b+")",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.datetime_time=function(a){Blockly.Python.definitions_.import_parking="import parking";var b=a.getFieldValue("HOUR");if("NOW"==b)b="parking.now()";else{var c=parseInt(a.getFieldValue("MINUTE"));a=Blockly.Python.quote_(a.getFieldValue("MERIDIAN"));b="parking.Time("+b+","+c+","+a+")"}return[b,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.Platform={};Blockly.Python.Platform_import=function(a){return"import platform\n"};Blockly.Python.plot={};Blockly.Python.plot_title=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";return"plt.title("+Blockly.Python.quote_(a.getFieldValue("TEXT"))+")\n"};Blockly.Python.plot_xlabel=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";return"plt.xlabel("+Blockly.Python.quote_(a.getFieldValue("TEXT"))+")\n"};
Blockly.Python.plot_ylabel=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";return"plt.ylabel("+Blockly.Python.quote_(a.getFieldValue("TEXT"))+")\n"};Blockly.Python.plot_line=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";return"plt.plot("+((Blockly.Python.valueToCode(a,"y_values",Blockly.Python.ORDER_NONE)||"___")+")\n")};
Blockly.Python.plot_hist=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";return"plt.hist("+((Blockly.Python.valueToCode(a,"values",Blockly.Python.ORDER_NONE)||"___")+")\n")};
Blockly.Python.plot_lineXY=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";var b=Blockly.Python.valueToCode(a,"x_values",Blockly.Python.ORDER_NONE)||"___";a=Blockly.Python.valueToCode(a,"y_values",Blockly.Python.ORDER_NONE)||"___";return"plt.line("+(b+","+a+")\n")};
Blockly.Python.plot_scatter=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";var b=Blockly.Python.valueToCode(a,"x_values",Blockly.Python.ORDER_NONE)||"___";a=Blockly.Python.valueToCode(a,"y_values",Blockly.Python.ORDER_NONE)||"___";return"plt.scatter("+(b+","+a+")\n")};Blockly.Python.plot_show=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";return"plt.show()\n"};Blockly.Python.plots={};Blockly.Python.plot_legend=function(a){Blockly.Python.definitions_.import_matplotlib="import matplotlib.pyplot as plt";return"plt.legend()\n"};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":c||(c=Blockly.Python.PASS);for(var e=[],f=0;f<a.arguments_.length;f++)e[f]=Blockly.Python.variableDB_.getName(a.arguments_[f],Blockly.Variables.NAME_TYPE);return"def "+b+"("+e.join(", ")+"):\n"+c+d};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)||"___";b=b+"("+c.join(", ")+")";return a.outputConnection?[b,Blockly.Python.ORDER_FUNCTION_CALL]:b};
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)||"___";b=b+"("+c.join(", ")+")\n";return a.outputConnection?[b,Blockly.Python.ORDER_FUNCTION_CALL]:b};
Blockly.Python.procedures_ifreturn=function(a){var b="if "+(Blockly.Python.valueToCode(a,"CONDITION",Blockly.Python.ORDER_NONE)||"___")+":\n";a.hasReturnValue_?(a=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___",b+="  return "+a+"\n"):b+="  return\n";return b};Blockly.Python.procedures_return=function(a){var b="return";a.hasReturnValue_?(a=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___",b+=" "+a+"\n"):b+="\n";return b};
Blockly.Python.procedures_main=function(a){return"def main():\n"+(Blockly.Python.statementToCode(a,"STACK")+"\nif __name__ == '__main__':\n    main()\n")};Blockly.Python.request={};Blockly.Python.request_import=function(a){return"import requests\n"};Blockly.Python.request_post=function(a){var b=a.getFieldValue("URL");a=Blockly.Python.valueToCode(a,"DATA",Blockly.Python.ORDER_ATOMIC)||"";return"response = requests.post('"+b+'\', json={"data": ['+a+"]})\nprint(response.status_code)\n"};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.sets={};Blockly.Python.set_create=function(a){var b=Array(a.itemCount_);console.log(a.itemCount_);for(var c=0;c<a.itemCount_;c++)b[c]=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_NONE)||"___";return["{"+b.join(", ")+"}",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.System={};Blockly.Python.System_import=function(a){return"import sys\n"};Blockly.Python.System_exit=function(a){return"sys.exit("+a.getFieldValue("TEXT_INPUT")+")\n"};Blockly.Python.System_dot=function(a){var b=Blockly.Python.valueToCode(a,"INPUT1",Blockly.Python.ORDER_ATOMIC)||"__";a=Blockly.Python.valueToCode(a,"INPUT2",Blockly.Python.ORDER_ATOMIC)||"__";return[b+"."+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.texts={};Blockly.Python.text=function(a){return[Blockly.Python.quote_(a.getFieldValue("TEXT")),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.text_join=function(a){switch(a.itemCount_){case 0:return["''",Blockly.Python.ORDER_ATOMIC];case 1:return["str("+(Blockly.Python.valueToCode(a,"ADD0",Blockly.Python.ORDER_NONE)||"''")+")",Blockly.Python.ORDER_FUNCTION_CALL];case 2:var b=Blockly.Python.valueToCode(a,"ADD0",Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.valueToCode(a,"ADD1",Blockly.Python.ORDER_NONE)||"''";return["str("+b+") + str("+a+")",Blockly.Python.ORDER_ADDITIVE];default:b=[];for(var c=0;c<a.itemCount_;c++)b[c]=
Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.variableDB_.getDistinctName("x",Blockly.Variables.NAME_TYPE);a="''.join([str("+a+") for "+a+" in ["+b.join(", ")+"]])";return[a,Blockly.Python.ORDER_FUNCTION_CALL]}};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_NONE)||"___";return b+" = str("+b+") + str("+a+")\n"};
Blockly.Python.text_length=function(a){return["len("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___")+")",Blockly.Python.ORDER_FUNCTION_CALL]};Blockly.Python.text_isEmpty=function(a){return["not len("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"___")+")",Blockly.Python.ORDER_LOGICAL_NOT]};
Blockly.Python.text_indexOf=function(a){var b="FIRST"==a.getFieldValue("END")?"find":"rfind",c=Blockly.Python.valueToCode(a,"FIND",Blockly.Python.ORDER_NONE)||"___";return[(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_MEMBER)||"___")+"."+b+"("+c+") + 1",Blockly.Python.ORDER_ADDITIVE]};
Blockly.Python.text_charAt=function(a){var b=a.getFieldValue("WHERE")||"FROM_START",c=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_MEMBER)||"___";switch(b){case "FIRST":return[c+"[0]",Blockly.Python.ORDER_MEMBER];case "LAST":return[c+"[-1]",Blockly.Python.ORDER_MEMBER];case "FROM_START":return a=Blockly.Python.getAdjustedInt(a,"AT"),[c+"["+a+"]",Blockly.Python.ORDER_MEMBER];case "FROM_END":return a=Blockly.Python.getAdjustedInt(a,"AT",1,!0),[c+"["+a+"]",Blockly.Python.ORDER_MEMBER];case "RANDOM":return Blockly.Python.definitions_.import_random=
"import random",[Blockly.Python.provideFunction_("text_random_letter",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(text):","  x = int(random.random() * len(text))","  return text[x];"])+"("+c+")",Blockly.Python.ORDER_FUNCTION_CALL]}throw"Unhandled option (text_charAt).";};
Blockly.Python.text_getSubstring=function(a){var b=Blockly.Python.valueToCode(a,"STRING",Blockly.Python.ORDER_MEMBER)||"___",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");switch(c){case "FROM_START":c=Blockly.Python.getAdjustedInt(a,"AT1");"0"==c&&(c="");break;case "FROM_END":c=Blockly.Python.getAdjustedInt(a,"AT1",1,!0);break;case "FIRST":c="";break;default:throw"Unhandled option (text_getSubstring)";}switch(d){case "FROM_START":a=Blockly.Python.getAdjustedInt(a,"AT2",1);break;case "FROM_END":a=
Blockly.Python.getAdjustedInt(a,"AT2",0,!0);Blockly.isNumber(String(a))?"0"==a&&(a=""):(Blockly.Python.definitions_.import_sys="import sys",a+=" or sys.maxsize");break;case "LAST":a="";break;default:throw"Unhandled option (text_getSubstring)";}return[b+"["+c+" : "+a+"]",Blockly.Python.ORDER_MEMBER]};
Blockly.Python.text_changeCase=function(a){var b={UPPERCASE:".upper()",LOWERCASE:".lower()",TITLECASE:".title()"}[a.getFieldValue("CASE")];return[(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_MEMBER)||"___")+b,Blockly.Python.ORDER_MEMBER]};Blockly.Python.text_trim=function(a){var b={LEFT:".lstrip()",RIGHT:".rstrip()",BOTH:".strip()"}[a.getFieldValue("MODE")];return[(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_MEMBER)||"___")+b,Blockly.Python.ORDER_MEMBER]};
Blockly.Python.text_print=function(a){return"print("+(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE)||"___")+")\n"};
Blockly.Python.text_prompt_ext=function(a){var b=Blockly.Python.provideFunction_("text_prompt",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(msg):","  try:","    return raw_input(msg)","  except NameError:","    return input(msg)"]),c=a.getField("TEXT")?Blockly.Python.quote_(a.getFieldValue("TEXT")):Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE)||"___";b=b+"("+c+")";"NUMBER"==a.getFieldValue("TYPE")&&(b="float("+b+")");return[b,Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.text_print_multiple=function(a){for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++)b[c]=Blockly.Python.valueToCode(a,"PRINT"+c,Blockly.Python.ORDER_NONE)||"___";return"print("+b.join(", ")+")\n"};Blockly.Python.text_prompt=Blockly.Python.text_prompt_ext;Blockly.Python.text_lower=function(a){return[(Blockly.Python.valueToCode(a,"TEXT_INPUT",Blockly.Python.ORDER_ATOMIC)||"")+".lower()",Blockly.Python.ORDER_ATOMIC]};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.Thread={};Blockly.Python.Thread_import=function(a){return"import threading\n"};Blockly.Python.Thread_start_output=function(a){return[(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__")+".start()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.Thread_start_preNext=function(a){return(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__")+".start()\n"};
Blockly.Python.Thread_set_target=function(a){return["threading.Thread(target="+(Blockly.Python.valueToCode(a,"TARGET",Blockly.Python.ORDER_ATOMIC)||"__")+")",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.tuple={};Blockly.Python.tuple_create=function(a){for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++)b[c]=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_NONE)||"___";b=b.join(", ");b=1==a.itemCount_?"("+b+",)":"("+b+")";return[b,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.turtles={};Blockly.Python.turtle_create=function(a){return"import turtle \nturtle = turtle.Turtle()\n"};Blockly.Python.turtle_color=function(a){return"turtle.color("+Blockly.Python.valueToCode(a,"COLOR",Blockly.Python.ORDER_ATOMIC)+")\n"};PythonToBlocks.KNOWN_ATTR_FUNCTIONS.color=function(a,b,c,d,e,f){if(1>b.length||2<b.length)throw Error("Incorrect number of arguments to turtle.color!");return[block("turtle_color",a.lineno,{},{COLOR:this.convert(b[0])},{inline:"true"})]};
Blockly.Python.turtle_forward=function(a){return"turtle.forward("+Blockly.Python.valueToCode(a,"DISTANCE",Blockly.Python.ORDER_ATOMIC)+")\n"};PythonToBlocks.KNOWN_ATTR_FUNCTIONS.forward=function(a,b,c,d,e,f){if(1!=b.length)throw Error("Incorrect number of arguments to turtle.forward!");return[block("turtle_forward",a.lineno,{},{DISTANCE:this.convert(b[0])},{inline:"true"})]};
Blockly.Python.turtle_backward=function(a){return"turtle.backward("+Blockly.Python.valueToCode(a,"DISTANCE",Blockly.Python.ORDER_ATOMIC)+")\n"};PythonToBlocks.KNOWN_ATTR_FUNCTIONS.backward=function(a,b,c,d,e,f){if(1!=b.length)throw Error("Incorrect number of arguments to turtle.backward!");return[block("turtle_backward",a.lineno,{},{DISTANCE:this.convert(b[0])},{inline:"true"})]};
Blockly.Python.turtle_left=function(a){return"turtle.left("+Blockly.Python.valueToCode(a,"ANGLE",Blockly.Python.ORDER_ATOMIC)+")\n"};PythonToBlocks.KNOWN_ATTR_FUNCTIONS.left=function(a,b,c,d,e,f){if(1!=b.length)throw Error("Incorrect number of arguments to turtle.left!");return[block("turtle_left",a.lineno,{},{ANGLE:this.convert(b[0])},{inline:"true"})]};Blockly.Python.turtle_right=function(a){return"turtle.right("+Blockly.Python.valueToCode(a,"ANGLE",Blockly.Python.ORDER_ATOMIC)+")\n"};
PythonToBlocks.KNOWN_ATTR_FUNCTIONS.right=function(a,b,c,d,e,f){if(1!=b.length)throw Error("Incorrect number of arguments to turtle.right!");return[block("turtle_right",a.lineno,{},{ANGLE:this.convert(b[0])},{inline:"true"})]};Blockly.Python.turtle_shape=function(a){return'turtle.shape("'+a.getFieldValue("Shape")+'")\n'};
PythonToBlocks.KNOWN_ATTR_FUNCTIONS.shape=function(a,b,c,d,e,f){if(1!=b.length)throw Error("Incorrect number of arguments to turtle.shape!");b=b[0].s.v;if(!["turtle","circle","classic","square","triangle"].includes(b))throw Error("The shape is not supported!");return[block("turtle_shape",a.lineno,{Shape:b},{},{inline:"true"})]};Blockly.Python.turtle_pen=function(a){return"turtle.pen"+a.getFieldValue("Pen")+"()\n"};
PythonToBlocks.KNOWN_ATTR_FUNCTIONS.penup=function(a,b,c,d,e,f){if(0!=b.length)throw Error("Incorrect number of arguments to turtle.shape!");return[block("turtle_pen",a.lineno,{Pen:"up"},{},{inline:"true"})]};PythonToBlocks.KNOWN_ATTR_FUNCTIONS.pendown=function(a,b,c,d,e,f){if(0!=b.length)throw Error("Incorrect number of arguments to turtle.shape!");return[block("turtle_pen",a.lineno,{Pen:"down"},{},{inline:"true"})]};
Blockly.Python.turtle_circle=function(a){return"turtle.circle("+Blockly.Python.valueToCode(a,"RADIUS",Blockly.Python.ORDER_ATOMIC)+")\n"};PythonToBlocks.KNOWN_ATTR_FUNCTIONS.circle=function(a,b,c,d,e,f){if(1!=b.length)throw Error("Incorrect number of arguments to turtle.circle!");return[block("turtle_circle",a.lineno,{},{RADIUS:this.convert(b[0])},{inline:"true"})]};
Blockly.Python.turtle_goto=function(a){var b=Blockly.Python.valueToCode(a,"X",Blockly.Python.ORDER_ATOMIC);a=Blockly.Python.valueToCode(a,"Y",Blockly.Python.ORDER_ATOMIC);return"turtle.goto("+b+","+a+")\n"};PythonToBlocks.KNOWN_ATTR_FUNCTIONS["goto"]=function(a,b,c,d,e,f){if(2!=b.length)throw Error("Incorrect number of arguments to turtle.goto!");return[block("turtle_goto",a.lineno,{},{X:this.convert(b[0]),Y:this.convert(b[1])},{inline:"true"})]};
Blockly.Python.turtle_pos=function(a){return["turtle.pos()",Blockly.Python.ORDER_ATOMIC]};PythonToBlocks.KNOWN_MODULES.turtle={pos:["turtle_pos"]};Blockly.Python.turtle_stamp=function(a){return"turtle.stamp()\n"};PythonToBlocks.KNOWN_ATTR_FUNCTIONS.stamp=function(a,b,c,d,e,f){if(0!=b.length)throw Error("Incorrect number of arguments to turtle.goto!");return[block("turtle_stamp",a.lineno,{},{},{inline:"true"})]};Blockly.Python.turtle_begin_fill=function(a){return"turtle.begin_fill()\n"};
PythonToBlocks.KNOWN_ATTR_FUNCTIONS.begin_fill=function(a,b,c,d,e,f){if(0!=b.length)throw Error("Incorrect number of arguments to turtle.begin_fill!");return[block("turtle_begin_fill",a.lineno,{},{},{inline:"true"})]};Blockly.Python.turtle_end_fill=function(a){Blockly.Python.valueToCode(a,"TURTLE",Blockly.Python.ORDER_ATOMIC);return"turtle.end_fill()\n"};
PythonToBlocks.KNOWN_ATTR_FUNCTIONS.end_fill=function(a,b,c,d,e,f){if(0!=b.length)throw Error("Incorrect number of arguments to turtle.end_fill!");return[block("turtle_end_fill",a.lineno,{},{},{inline:"true"})]};Blockly.Python.turtle_speed=function(a){return"turtle.speed("+Blockly.Python.valueToCode(a,"SPEED",Blockly.Python.ORDER_ATOMIC)+")\n"};
PythonToBlocks.KNOWN_ATTR_FUNCTIONS.speed=function(a,b,c,d,e,f){if(1!=b.length)throw Error("Incorrect number of arguments to turtle.speed!");return[block("turtle_speed",a.lineno,{},{SPEED:this.convert(b[0])},{inline:"true"})]};Blockly.Python.utility={};Blockly.Python.raw_block=function(a){return a.getFieldValue("TEXT")+"\n"};Blockly.Python.raw_expression=function(a){return[a.getFieldValue("TEXT"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.raw_empty=function(a){return(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_MEMBER)||"")+"\n"};Blockly.Python.raw_table=function(a){return""};
Blockly.Python.type_check=function(a){return["type("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_MEMBER)||"___")+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.function_call=function(a){for(var b=a.getFieldValue("NAME"),c=a.hasReturn_,d=Array(a.itemCount_),e=0;e<a.itemCount_;e++)d[e]=Blockly.Python.valueToCode(a,"ARGUMENT"+e,Blockly.Python.ORDER_NONE)||"___";a=b+"("+d.join(", ")+")";return c?[a,Blockly.Python.ORDER_ATOMIC]:a+"\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_NONE)||"___";return Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" = "+b+"\n"};
Blockly.Python.variables_getself=function(a){return["self."+(Blockly.Python.valueToCode(a,"VAR",Blockly.Python.ORDER_NONE)||"___"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.variables_setself=function(a){var b=Blockly.Python.valueToCode(a,"VAR",Blockly.Python.ORDER_NONE)||"___";a=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"___";return"self."+b+" = "+a+"\n"};Blockly.Python.visionkit={};Blockly.Python.visionkit_import=function(a){var b=Blockly.Python.valueToCode(a,"IMPORT",Blockly.Python.ORDER_NONE)||0;return"from "+a.getFieldValue("FROM")+" "+b+"\n"};Blockly.Python.visionkit_import_annotator=function(a){return["import "+a.getFieldValue("IMPORT")||"Annotator",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.visionkit_import_models=function(a){return["import "+a.getFieldValue("IMPORT")||"face_detection",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.visionkit_import_inference=function(a){return["import "+a.getFieldValue("IMPORT")||"CameraInference",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.visionkit_cameraInference=function(a){var b=a.getFieldValue("INFERENCE"),c=a.getFieldValue("USEMODEL");a=Blockly.Python.statementToCode(a,"STACK");return"with CameraInference("+c+") as "+b+":\n"+a+"\n"};
Blockly.Python.visionkit_runInference=function(a){return["inference.run("+(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_NONE)||"")+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.visionkit_GetInference=function(a){return["inference."+a.getFieldValue("INFERENCE"),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.visionkit_faceDetection_operation=function(a){var b=a.getFieldValue("MODEL"),c=a.getFieldValue("OPERATION");a=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_NONE)||"";return[b+"."+c+"("+a+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.visionkit_model_get=function(a){var b=a.getFieldValue("MODEL");return[(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_NONE)||"")+"."+b,Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.visionkit_Use_Annotator=function(a){var b=a.getFieldValue("ANNOTATOR"),c=a.getFieldValue("X-DIMEN");a=a.getFieldValue("Y-DIMEN");return"Annotator("+b+", dimensions = ("+c+","+a+"))\n"};Blockly.Python.visionkit_Use_Annotator_output=function(a){var b=a.getFieldValue("ANNOTATOR"),c=a.getFieldValue("X-DIMEN");a=a.getFieldValue("Y-DIMEN");return["Annotator("+b+", dimensions = ("+c+","+a+"))",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.visionkit_Annotator_operation=function(a){return"annotator."+a.getFieldValue("OPERATION")+"()\n"};Blockly.Python.visionkit_Annotator_Bounding=function(a){var b=a.getFieldValue("FILL");return"annotator.bounding_box(transform("+(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_NONE)||"")+"),fill="+b+")\n"};Blockly.Python.visionkit_myAssistant=function(a){return["MyAssistant()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.visionkit_import_aiy=function(a){return"from aiy.vision.inference import CameraInference\nfrom aiy.vision.models import face_detection\nfrom aiy.vision.annotator import Annotator\n"};
Blockly.Python.visionkit_avg_joy_score=function(a){return"def avg_joy_score(faces):\n    if faces:\n        return sum(face.joy_score for face in faces) / len(faces)\n    return 0\n"};Blockly.Python.visionkit_annotator_camera=function(a){var b=a.getFieldValue("X"),c=a.getFieldValue("Y"),d=a.getFieldValue("SCALE_X");a=a.getFieldValue("SCALE_Y");return"annotator = Annotator(camera, dimensions=("+b+", "+c+"))\nscale_x = "+b+" / "+d+"\nscale_y = "+c+" / "+a+"\n"};
Blockly.Python.visionkit_transform_boundingBox=function(a){return"def transform(bounding_box):\n    x, y, width, height = bounding_box\n    return (scale_x * x, scale_y * y, scale_x * (x + width), scale_y * (y + height))\n"};
Blockly.Python.visionkit_CameraInference=function(a){a.getFieldValue("SETTING");a=Blockly.Python.statementToCode(a,"STACK");return"with CameraInference(face_detection.model()) as inference:\n    for result in inference.run(num_frames):\n        faces = face_detection.get_faces(result)\n        annotator.clear()\n        for face in faces:\n            annotator.bounding_box(transform(face.bounding_box), fill=0)\n        annotator.update()\n"+Blockly.Python.prefixLines(a,Blockly.Python.INDENT)};
Blockly.Python.visionkit_avg_joy_score_num=function(a){return["avg_joy_score("+a.getFieldValue("FACE")+")",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.visionkit_face=function(a){return["faces",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit={};Blockly.Python.voicekit_from=function(a){var b=a.getFieldValue("FROM");a=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__";return"from "+b+" "+a+"\n"};Blockly.Python.voicekit_import=function(a){return["import auth_helpers",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_import_tts=function(a){return"from aiy.voice import tts"};
Blockly.Python.voicekit_tts_say=function(a){return"tts.say("+(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_ATOMIC)||"_")+", lang='en-US', volume=60, pitch=130, speed=100, device='default')\n"};Blockly.Python.voicekit_set_credential=function(a){var b=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__",c=Blockly.Python.statementToCode(a,"STACK");a=a.getFieldValue("ASSISTANT");return"with Assistant("+b+") as "+a+":\n"+c+"\n"};
Blockly.Python.voicekit_get_credential=function(a){return["auth_helpers.get_assistant_credentials()",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_import_assistant=function(a){return["import Assistant",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_assistant_preNext=function(a){var b=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__";a=a.getFieldValue("OPERATION");return b+"."+a+"\n"};
Blockly.Python.voicekit_assistant_output=function(a){var b=Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__";a=a.getFieldValue("OPERATION");return[b+"."+a,Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_EventType_import=function(a){return["import EventType",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_EventType_assistant=function(a){return["EventType."+a.getFieldValue("TYPE"),Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.voicekit_event_of=function(a){return[(Blockly.Python.valueToCode(a,"INPUT",Blockly.Python.ORDER_ATOMIC)||"__")+".type",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_run_task=function(a){return["self._run_task",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_process_event=function(a){return"self._process_event(event)\n"};Blockly.Python.voicekit_assistant_start_conversation=function(a){return"self._assistant.start_conversation()\n"};
Blockly.Python.voicekit_send_instructions=function(a){return"self.send_instructions("+(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_ATOMIC)||"__")+")\n"};Blockly.Python.voicekit_on_button_pressed=function(a){return["self._on_button_pressed",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_import_aiy=function(a){return"from google.assistant.library.event import EventType\nfrom aiy.assistant import auth_helpers\nfrom aiy.assistant.library import Assistant\nfrom aiy.voice import tts\n"};
Blockly.Python.voicekit_init=function(a){for(var b="def __init__(self):\n",c=0;c<a.itemCount_;c++)switch(Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_ATOMIC)||"\n"){case "button":b+="    self._board.button.when_pressed = self._on_button_pressed\n";break;case "board":b+="    self._board = Board()\n";break;case "task":b+="    self._task = threading.Thread(target=self._run_task)\n";break;case "can_start":b+="    self._can_start_conversation = False\n";break;case "assistant":b+="    self._assistant = None\n"}return b};
Blockly.Python.voicekit_task=function(a){return["task",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_can_start=function(a){return["can_start",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_asssistant=function(a){return["assistant",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_start_thread=function(a){return"def start(self):\n    self._task.start()\n"};Blockly.Python.voicekit_runTask=function(a){return"def _run_task(self):\n    credentials = auth_helpers.get_assistant_credentials()\n    with Assistant(credentials) as assistant:\n        self._assistant = assistant\n        for event in assistant.start():\n            self._process_event(event)\n"};
Blockly.Python.voicekit_logging_config=function(a){return"logging.basicConfig(level=logging.INFO)\n"};Blockly.Python.voicekit_myassistant_start=function(a){return a.getFieldValue("INPUT")+"().start()"};Blockly.Python.voicekit_process_event=function(a){return"def _process_event(self, event):\n    logging.info(event)\n"+Blockly.Python.statementToCode(a,"STACK")};Blockly.Python.voicekit_process_eventType=function(a){return["event.type",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.voicekit_EventType_select=function(a){return["EventType."+a.getFieldValue("TYPE"),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_can_start_conversation_self=function(a){return["self._can_start_conversation",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_can_start_conversation=function(a){return"self._can_start_conversation = "+a.getFieldValue("SETTING")+"\n"};
Blockly.Python.voicekit_assistant_conversation=function(a){return"self._assistant."+a.getFieldValue("SETTING")+"\n"};Blockly.Python.voicekit_event_args=function(a){return["event.args",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.voicekit_event_args_of=function(a){return["event.args['"+a.getFieldValue("TEXT")+"']",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]};