def define(self, **kwargs): name = self.get_name() self.add_parameter("variable_name", "booleano") boolean = str(self.get_parameter("variable_name").get_value()) self.meta = { Arduino: { "code": ("void @@name@@(){\n" "\t@@name@@_outBool = @@param@@variable_name@@;\n" "}\n"), "declarations": "bool @@name@@_outBool;\n", "setup": "", "loop": "\t@@name@@();\n", "inputs": {}, "outputs": { "outBool_@@name@@": "@@name@@_outBool" }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("outBool", OutBoolPort(self, "outBool", "outBool_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.add_parameter("variable_name", "stringa") self.meta = { Arduino: { "code": ("void @@name@@(){\n" "\t@@name@@_outStr = @@param@@variable_name@@;\n" "}\n"), "declarations":"char* @@name@@_outStr;\n", "setup": "", "loop": "\t@@name@@();\n", "inputs": {}, "outputs": { "outStr_@@name@@": "@@name@@_outStr" }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("outStr", OutStringPort(self, "outStr", "outStr_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.add_parameter("variable_name", "numero") self.meta = { Arduino: { "code": ("void @@name@@(){\n" "\t@@param@@variable_name@@ = <<inInt_@@name@@>>;\n" "}\n"), "declarations": "int @@param@@variable_name@@ = 0;\n", "setup": "", "loop": "\t@@name@@();\n", "inputs": { "inInt_@@name@@": None, }, "outputs": {}, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("inInt", InIntPort(self, "inInt", "inInt_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.meta = { Arduino: { "code": ("void @@name@@(){\n" "\t@@name@@_bitcounter = 0;\n" "\twhile(Serial.available()){\n" "\t\tif(@@name@@_bitcounter < @@name@@_receivedLength){\n" "\t\t\t@@name@@_received[@@name@@_bitcounter] = tolower(Serial.read());\n" "\t\t\t@@name@@_bitcounter++;\n" "\t\t\t@@name@@_came = true;\n" "\t\t\tdelay(10);\n" "\t\t}\n" "\t\telse{\n" "\t\t\t@@name@@_received = (char*)realloc(@@name@@_received, @@name@@_receivedLength*2);\n" "\t\t\t@@name@@_receivedLength = @@name@@_receivedLength*2;\n" "\t\t}\n" "\t}\n" "}\n"), "declarations": ("void @@name@@();\n" "char* @@name@@_received;\n" "int @@name@@_receivedLength = 32;\n" "int @@name@@_bitcounter = 0;\n" "char @@name@@_prefix[4];\n" "bool @@name@@_came = false;\n"), "setup": ("Serial.begin(9600);\n" "@@name@@_received = (char*)calloc(32, sizeof(char));\n"), "loop": "@@name@@();\n", "inputs": { "inBaudRate_@@name@@": None }, "outputs": { "receivedString_@@name@@": "@@name@@_received", "hasReceivedString_@@name@@": "@@name@@_came", }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface( "received", OutSerialPort(self, "received_out", "receivedString_@@name@@")) self.add_interface( "came", OutBoolPort(self, "came", "hasReceivedString_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.meta = { Arduino: { "code": ("void @@name@@(){\n" "\tif(<<hasReceivedSerial_@@name@@>>){\n" "\t\tif(strcmp(<<motorInstruction_@@name@@>>, \"go\") == 0){\n" "\t\t\t@@name@@_left.write(0);\n" "\t\t\t@@name@@_right.write(180);\n" "\t\t}\n" "\t\telse if(strcmp(<<motorInstruction_@@name@@>>, \"stop\") == 0){\n" "\t\t\t@@name@@_left.write(90);\n" "\t\t\t@@name@@_right.write(90);\n" "\t\t}\n" "\t\tfor(int i = 0; <<motorInstruction_@@name@@>>[i] != 0; i++){\n" "\t\t\t<<motorInstruction_@@name@@>>[i] = 0;\n" "\t\t}\n" "\t}\n" "}\n"), "declarations": ("#include <Servo.h>\n" "Servo @@name@@_right;\n" "Servo @@name@@_left;\n"), "setup": ("\t@@name@@_left.attach(5);\n" "\t@@name@@_right.attach(4);\n"), "loop": "@@name@@();\n", "inputs": { "motorInstruction_@@name@@": None, "hasReceivedSerial_@@name@@": None, }, "outputs": {}, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface( "motorString", InStringPort(self, "motorString", "motorInstruction_@@name@@")) self.add_interface( "motorCame", InBoolPort(self, "motorCame", "hasReceivedSerial_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.add_parameter("compareString", "Go") cmpString = str(self.get_parameter("compareString").get_value()) self.meta = { Arduino: { "code": ("void @@name@@(){{\n" "\tif(<<hasReceivedSerial_@@name@@>>){{\n" "\t\tif(strcmp(<<inString_@@name@@>>, \"{0}\") == 0){{\n" "\t\t\t@@name@@_isMatch = 1;\n" "\t\t}}\n" "\t}}\n" "}}\n").format(cmpString), "declarations": "bool @@name@@_isMatch = 0;\n", "setup": "", "loop": "\t@@name@@();\n", "inputs": { "inString_@@name@@": None, "hasReceivedSerial_@@name@@": None, }, "outputs": { "isMatch_@@name@@": "@@name@@_isMatch" }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("inString", InStringPort(self, "inString", "inString_@@name@@")) self.add_interface( "inDetected", InBoolPort(self, "inDetected", "hasReceivedSerial_@@name@@")) self.add_interface("isMatch", OutBoolPort(self, "isMatch", "isMatch_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): self.add_parameter("num", 0, is_symbol=False) self.meta = { Arduino: { "code": "", "inputs": {}, "outputs": { "num@@name@@": "@@param@@num@@", }, "declarations": "", "setup": ("\n"), "loop": ("\n"), "needs": set() }, } self.add_interface("num", OutIntPort(self, "num", "num@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): self.meta = { Arduino: { "code": "", "inputs": {}, "outputs": { "tog@@name@@": "@@name@@item", }, "declarations": (), "setup": "@@name@@item = (int)(0);\n", "loop": (" @@name@@item = (int)(!@@name@@item);\n" " \n"), "needs": set() }, } self.add_interface("tog", OutIntPort(self, "tog", "tog@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): self.meta = { Cpp: { "code": "", "inputs": { }, "outputs": { "str@@name@@": "\"Hello World!\\n\"" }, "declarations": "", "needs": set() }, Arduino: { "code": "", "declarations": "", "setup": "", "loop": "", "inputs": {}, "outputs": { "str@@name@@": "\"Hello World!\\n\"" }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("outStr", OutStringPort(self, "outStr", "str@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): self.meta = { Cpp: { "code": "", "inputs": { "inSort_@@name@@": None }, "outputs": { "sorted_@@name@@": "std::sort(<<inSort_@@name@@>>)" }, "declarations": "", "needs": set() } } self.add_interface("inStr", InStringPort(self, "inStr", "inSort_@@name@@")) self.add_interface("outStr", OutStringPort(self, "sorted", "sorted_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.meta = { Arduino: { "code": ("void @@name@@(){\n" "\tif(<<hasReceivedSerial_@@name@@>>){\n" "\t\t@@name@@_receivedString = (char*)<<receivedSerial_@@name@@>>;\n" "\t\t@@name@@_cameOut = true;\n" "\t}\n" "}\n"), "declarations": ("void @@name@@();\n" "char* @@name@@_receivedString;\n" "bool @@name@@_cameOut = false;\n"), "setup": "", "loop": "@@name@@();\n", "inputs": { "receivedSerial_@@name@@": None, "hasReceivedSerial_@@name@@": None, }, "outputs": { "receivedString_@@name@@": "@@name@@_receivedString", "hasReceivedString_@@name@@": "@@name@@_cameOut", }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("received", InSerialPort(self, "received", "receivedSerial_@@name@@")) self.add_interface("came", InBoolPort(self, "came", "hasReceivedSerial_@@name@@")) self.add_interface("receivedString", OutStringPort(self, "receivedString_out", "receivedString_@@name@@")) self.add_interface("cameOut", OutBoolPort(self, "cameOut", "hasReceivedString_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.add_parameter("buttonValue", "UP") self.meta = { Web: { "script": ("function @@name@@Send(val) {\n" "\tvar timeStr = new Date().toLocaleTimeString();\n" "\tvar text = \"(\" + timeStr + \") : TX = #\" + val + \"<br>\";\n" "\ttxLog(text);\n" "\n" "\tconsole.log('Button pressed, sending #'+val); \n" "\tconnection.send('#'+val);\n" "}\n" "\n" "function @@name@@Release() {\n" "\tvar timeStr = new Date().toLocaleTimeString();\n" "\tvar text = \"(\" + timeStr + \") : TX = #0<br>\";\n" "\ttxLog(text);\n" "\tconsole.log('Button released'); \n" "\tconnection.send('#0');\n" "}\n" "\n"), "declarations": "\t<td><button id=\"@@name@@\" name=\"@@name@@\" value=\"@@param@@buttonValue@@\" class=\"smbutton\">@@param@@buttonValue@@</button></td>\n", "functions": ("var btns = document.getElementsByName(\"@@name@@\");\n" "for (var i = 0; i < btns.length; i++) {\n" "\t\tbtns[i].ontouchstart = function(e) {@@name@@Send(this.value); e.stopPropagation(); e.preventDefault();};\n" "\t\tbtns[i].onmousedown = function(e) {@@name@@Send(this.value); e.stopPropagation(); e.preventDefault();};\n" "\t\tbtns[i].ontouchend = function() {@@name@@Release(); e.stopPropagation(); e.preventDefault();}\n" "\t\tbtns[i].onmouseup = function() {@@name@@Release(); e.stopPropagation(); e.preventDefault();}\n" "}\n"), "inputs": {}, "outputs": {"sentValue_@@name@@": "@@name@@_receivedString", }, "needs": set(), } } CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.meta = { Arduino: { "code": ("void webSocketEvent(uint8_t id, WStype_t type, uint8_t * payload, size_t length) {\n" "\n" "\t\tswitch(type) {\n" "\t\t\t\tcase WStype_DISCONNECTED:\n" "\t\t\t\t\t\tDEBUG(\"Web socket disconnected, id = \", id);\n" "\t\t\t\t\t\tbreak;\n" "\t\t\t\tcase WStype_CONNECTED: \n" "\t\t\t\t{\n" "\t\t\t\t\t\t// IPAddress ip = webSocket.remoteIP(id);\n" "\t\t\t\t\t\t// Serial.printf(\"[%u] Connected from %d.%d.%d.%d url: %s\\n\", id, ip[0], ip[1], ip[2], ip[3], payload);\n" "\t\t\t\t\t\tDEBUG(\"Web socket connected, id = \", id);\n" "\n" "\t\t\t\t\t\t// send message to client\n" "\t\t\t\t\t\twsSend(id, \"Connected to \");\n" "\t\t\t\t\t\twsSend(id, ap_ssid);\n" "\t\t\t\t\t\tbreak;\n" "\t\t\t\t}\n" "\t\t\t\tcase WStype_BIN:\n" "\t\t\t\t\t\tDEBUG(\"On connection #\", id)\n" "\t\t\t\t\t\tDEBUG(\" got binary of length \", length);\n" "\t\t\t\t\t\tfor (int i = 0; i < length; i++)\n" "\t\t\t\t\t\t\tDEBUG(\" char : \", payload[i]);\n" "\n" "\t\t\t\tcase WStype_TEXT:\n" "\t\t\t\t\t\tDEBUG(\"On connection #\", id)\n" "\t\t\t\t\t\tDEBUG(\" got text: \", (char *)payload);\n" "\n" "\t\t\t\t\t\t@@name@@_payload = (char*) &payload;\n" "\t\t\t\t\t\t@@name@@_isReceived = true;" "\t\t\t\t\t\tbreak;\n" "\t\t}\n" "}\n"), "declarations": ("#include <Hash.h>\n" "#include <FS.h>\n" "#include <ESP8266WiFi.h>\n" "#include <WiFiClient.h>\n" "#include <ESP8266WebServer.h>\n" "#include <WebSocketsServer.h>\n" "#include <ESP8266mDNS.h>\n" "#include \"debug.h\"\n" "#include \"file.h\"\n" "#include \"server.h\"\n" "// WiFi AP parameters\n" "char ap_ssid[13];\n" "char* ap_password = \"\";\n" "\n" "// WiFi STA parameters\n" "char* sta_ssid = \n" "\t\"...\";\n" "char* sta_password = \n" "\t\"...\";\n" "\n" "char* mDNS_name = \"paperbot\";\n" "\n" "String html;\n" "String css;\n" "char* @@name@@_payload;\n" "bool @@name@@_isReceived = false;\n" "void webSocketEvent(uint8_t id, WStype_t type, uint8_t * payload, size_t length);\n" ), "setup": ("\n" "\t\tsprintf(ap_ssid, \"ESP_%08X\", ESP.getChipId());\n" "\n" "\t\tfor(uint8_t t = 4; t > 0; t--) {\n" "\t\t\t\tSerial.printf(\"[SETUP] BOOT WAIT %d...\\n\", t);\n" "\t\t\t\tSerial.flush();\n" "\t\t\t\tLED_ON;\n" "\t\t\t\tdelay(500);\n" "\t\t\t\tLED_OFF;\n" "\t\t\t\tdelay(500);\n" "\t\t}\n" "\t\tLED_ON;\n" "\t\t//setupSTA(sta_ssid, sta_password);\n" "\t\tsetupAP(ap_ssid, ap_password);\n" "\t\tLED_OFF;\n" "\n" "\t\tsetupFile();\n" "\t\thtml = loadFile(\"/controls.html\");\n" "\t\tcss = loadFile(\"/style.css\");\n" "\t\tregisterPage(\"/\", \"text/html\", html);\n" "\t\tregisterPage(\"/style.css\", \"text/css\", css);\n" "\n" "\t\tsetupHTTP();\n" "\t\tsetupWS(webSocketEvent);\n" "\t\t//setupMDNS(mDNS_name);\n" "\n"), "loop": ("\n" "\t\twsLoop();\n" "\t\thttpLoop();\n"), "inputs": {}, "outputs": { "output_@@name@@": "@@name@@_payload" }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("payload", OutStringPort(self, "payload", "payload_@@name@@")) self.add_interface( "isReceived", OutBoolPort(self, "isReceived", "isReceived_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.meta = { Arduino: { "code": ("void @@name@@(){\n" "\tif(<<switchOne_@@name@@>>)\n" "\t{\n" "\t\t@@name@@_output = <<inputOne_@@name@@>>;\n" "\t}\n" "\telse if(<<switchTwo_@@name@@>>)\n" "\t{\n" "\t\t@@name@@_output = <<inputTwo_@@name@@>>;\n" "\t}\n" "\telse if(<<switchThree_@@name@@>>)\n" "\t{\n" "\t\t@@name@@_output = <<inputThree_@@name@@>>;\n" "\t}\n" "\telse if(<<switchFour_@@name@@>>)\n" "\t{\n" "\t\t@@name@@_output = <<inputFour_@@name@@>>;\n" "\t}\n" "}\n"), "declarations": "int @@name@@_output;\n", "setup": "", "loop": "\t@@name@@();\n", "inputs": { "inputOne_@@name@@": None, "inputTwo_@@name@@": None, "inputThree_@@name@@": None, "inputFour_@@name@@": None, "switchOne_@@name@@": None, "switchTwo_@@name@@": None, "switchThree_@@name@@": None, "switchFour_@@name@@": None, }, "outputs": { "output_@@name@@": "@@name@@_output" }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("inputOne", InIntPort(self, "inputOne", "inputOne_@@name@@")) self.add_interface("inputTwo", InIntPort(self, "inputTwo", "inputTwo_@@name@@")) self.add_interface("inputThree", InIntPort(self, "inputThree", "inputThree_@@name@@")) self.add_interface("inputFour", InIntPort(self, "inputFour", "inputFour_@@name@@")) self.add_interface("switchOne", InBoolPort(self, "switchOne", "switchOne_@@name@@")) self.add_interface("switchTwo", InBoolPort(self, "switchTwo", "switchTwo_@@name@@")) self.add_interface("switchThree", InBoolPort(self, "switchThree", "switchThree_@@name@@")) self.add_interface("switchFour", InBoolPort(self, "switchFour", "switchFour_@@name@@")) self.add_interface("output", OutIntPort(self, "output", "output_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.meta = { Cpp: { "code": "std::string @@name@@(std::string str)\n" + \ "{\n" + \ " size_t len = str.length();\n\n" + \ " for (int i = 0;i < len / 2;++i)\n" + \ " {\n" + \ " char c = str[i];\n" + \ " str[i] = str[len - i - 1];\n" + \ " str[len - i - 1] = c;\n" + \ " }\n\n" + \ " return str;\n" + \ "}\n", "inputs": { "inReverse_@@name@@": None }, "outputs": { "reversed_@@name@@": "@@name@@(<<inReverse_@@name@@>>)" }, "declarations": "@@name@@(std::string str);\n", "needs": set() }, Arduino: { "code": "std::string @@name@@(std::string str)\n" + \ "{\n" + \ " size_t len = str.length();\n\n" + \ " for (int i = 0;i < len / 2;++i)\n" + \ " {\n" + \ " char c = str[i];\n" + \ " str[i] = str[len - i - 1];\n" + \ " str[len - i - 1] = c;\n" + \ " }\n\n" + \ " return str;\n" + \ "}\n", "declarations": "@@name@@(std::string str);\n", "setup": "", "loop": "", "inputs": { "inReverse_@@name@@": None }, "outputs": { "reversed_@@name@@": "@@name@@(<<inReverse_@@name@@>>)" }, "needs": set(), "interface": { "html": "", "style": "", "js": "", "event": "", } } } self.add_interface("inStr", InStringPort(self, "inStr", "inReverse_@@name@@")) self.add_interface("outStr", OutStringPort(self, "reversed", "reversed_@@name@@")) CodeComponent.define(self, **kwargs)
def define(self, **kwargs): name = self.get_name() self.meta = { # Each key is the kind of output you support, in this case this module # supports only Arduino output. Arduino: { # "code" is a string containing any generic code you want. It will # be in the global scope, below all declarations. Generally, it # contains functions that will be used elsewhere in the code. "code": ("void @@name@@(){\n" "\t@@name@@_bitcounter = 0;\n" "\twhile(Serial.available()){\n" "\t\tif(@@name@@_bitcounter < @@name@@_receivedLength){" "\t\t\t@@name@@_received[@@name@@_bitcounter] = tolower(Serial.read());\n" "\t\t\t@@name@@_bitcounter++;\n" "\t\t\t@@name@@_came = true;\n" "\t\t\tdelay(10);\n" "\t\t}\n" "\t\telse{\n" "\t\t\t@@name@@_received = realloc(@@name@@_received, @@name@@_receivedLength*2);\n" "\t\t\t@@name@@_receivedLength = @@name@@_receivedLength*2;\n" "\t\t}\n" "\t}\n" "}\n"), # "declarations" contains all declarations for global variables # and functions used in the code. "declarations": ("void @@name@@();\n" "char* @@name@@_received;\n" "int @@name@@_receivedLength = 32;\n" "int @@name@@_bitcounter = 0;\n" "char @@name@@_prefix[4];\n" "bool @@name@@_came = false;\n"), # "setup" contains all the code you want to be in setup. The # indentation is sketchy but it shouldn't matter. "setup": ("Serial.begin(<<inBaudRate_@@name@@>>);\n" "@@name@@_received = calloc(32, sizeof(char));\n"), # "loop" contains all the code you want to be in the loop function. "loop": "@@name@@();\n", # "inputs" is a dictionary containing all the inputs to the component. # The key is the name you want to refer to the input by in the code. # Use it in the code as a variable as long as the type matches. # Wherever its used in the code, surround it with << and >> # I think the value is always None, but I have to double check "inputs": { "inBaudRate_@@name@@": None }, # "outputs" is a dictionary containing all the outputs to the component. # The key is an arbitrary tag you call it by but it should be the same # lable in the definition of the ports below. The values are the # names of the variables that contain the value of the outputs. "outputs": { "receivedString_@@name@@": "@@name@@_received", "hasReceivedString_@@name@@": "@@name@@_came", }, # "needs" is an array of any dependencies (libraries) that the # may use. "needs": set(), # "interface" is used to create UI stuff, I have no idea how it works # Don't screw with it "interface": { "html": "", "style": "", "js": "", "event": "", } } } # This is where you add ports to the component. The first argument is the name # of the port. Keep this simple and not scary because its what the users # will see in the blockly interface. The second argument is a port object. # Look at the port documentation to see how to create one. self.add_interface("baudRate", InIntPort(self, "baudRate", "inBaudRate_@@name@@")) self.add_interface( "received", OutSerialPort(self, "received", "receivedString_@@name@@")) self.add_interface( "came", OutBoolPort(self, "came", "hasReceivedString_@@name@@")) CodeComponent.define(self, **kwargs)