update generated code

This commit is contained in:
Mario Pesch 2022-01-29 10:50:30 +01:00
parent 0c8ae90124
commit c711596285
3 changed files with 38 additions and 21 deletions

View File

@ -108,3 +108,14 @@ Blockly.Blocks["sensebox_ethernet"] = {
}
},
};
Blockly.Blocks["sensebox_ethernetIp"] = {
init: function () {
this.appendDummyInput().appendField(Blockly.Msg.senseBox_ethernet_ip);
this.setColour(getColour().sensebox);
this.setHelpUrl(Blockly.Msg.senseBox_ethernetIp_helpurl);
this.setTooltip(Blockly.Msg.senseBox_ethernet_ip_tooltip);
this.setOutput(true, null);
},
};

View File

@ -41,36 +41,41 @@ Blockly.Arduino.sensebox_ethernet = function () {
Blockly.Arduino.libraries_["library_ethernet"] = "#include <Ethernet.h>";
Blockly.Arduino.definitions_["ethernet_config"] = `
byte mac[] = { ${mac}};`;
byte mac[] = { ${mac}};`;
if (dhcp === "Manual") {
Blockly.Arduino.definitions_["ethernet_manual_config"] = `
//Configure static IP setup (only needed if DHCP is disabled)
IPAddress myIp(${ip.replaceAll(".", ", ")});
IPAddress myDns(${dns.replaceAll(".", ",")});
IPAddress myGateway(${gateway.replaceAll(".", ",")});
IPAddress mySubnet(${subnetmask.replaceAll(".", ",")});
//Configure static IP setup (only needed if DHCP is disabled)
IPAddress myIp(${ip.replaceAll(".", ", ")});
IPAddress myDns(${dns.replaceAll(".", ",")});
IPAddress myGateway(${gateway.replaceAll(".", ",")});
IPAddress mySubnet(${subnetmask.replaceAll(".", ",")});
`;
Blockly.Arduino.setupCode_["ethernet_setup"] = `
Ethernet.init(23);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, myIp);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Ethernet.init(23);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, myIp);
}
// give the Ethernet shield a second to initialize:
delay(1000);
`;
} else {
Blockly.Arduino.setupCode_["ethernet_setup"] = `
Ethernet.init(23);
// start the Ethernet connection:
Ethernet.begin(mac);
// give the Ethernet shield a second to initialize:
delay(1000);
Ethernet.init(23);
// start the Ethernet connection:
Ethernet.begin(mac);
// give the Ethernet shield a second to initialize:
delay(1000);
`;
}
var code = "";
return code;
};
Blockly.Arduino.sensebox_ethernetIp = function () {
var code = "Ethernet.localIP()";
return [code, Blockly.Arduino.ORDER_ATOMIC];
};

View File

@ -94,8 +94,9 @@ class Toolbox extends React.Component {
<Block type="sensebox_wifi" />
<Block type="sensebox_startap" />
</Category>
<Category name="Misc" colour={getColour().sensebox}>
<Category name="Ethernet" colour={getColour().sensebox}>
<Block type="sensebox_ethernet" />
<Block type="sensebox_ethernetIp" />
</Category>
<Category name="SD" colour={getColour().sensebox}>
<Block type="sensebox_sd_create_file" />