diff --git a/src/components/Blockly/blocks/index.js b/src/components/Blockly/blocks/index.js index b4bf8fa..307c4f4 100644 --- a/src/components/Blockly/blocks/index.js +++ b/src/components/Blockly/blocks/index.js @@ -21,6 +21,7 @@ import "./procedures"; import "./time"; import "./variables"; import "./lists"; +import "./watchdog"; import "./webserver"; import "../helpers/types"; diff --git a/src/components/Blockly/blocks/watchdog.js b/src/components/Blockly/blocks/watchdog.js new file mode 100644 index 0000000..09ce26d --- /dev/null +++ b/src/components/Blockly/blocks/watchdog.js @@ -0,0 +1,28 @@ +import Blockly from "blockly/core"; +import { getColour } from "../helpers/colour"; + +Blockly.Blocks["watchdog_enable"] = { + init: function () { + this.appendDummyInput() + .appendField("Watchdog aktivieren") + .appendField(new Blockly.FieldTextInput("10000"), "TIME") + .appendField("ms"); + + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(getColour().io); + this.setTooltip(""); + this.setHelpUrl(""); + }, +}; + +Blockly.Blocks["watchdog_reset"] = { + init: function () { + this.appendDummyInput().appendField("Watchdog zurücksetzen"); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(getColour().io); + this.setTooltip(""); + this.setHelpUrl(""); + }, +}; diff --git a/src/components/Blockly/generator/index.js b/src/components/Blockly/generator/index.js index d2cb21e..f913c5a 100644 --- a/src/components/Blockly/generator/index.js +++ b/src/components/Blockly/generator/index.js @@ -22,4 +22,5 @@ import "./procedures"; import "./time"; import "./variables"; import "./lists"; +import "./watchdog"; import "./webserver"; diff --git a/src/components/Blockly/generator/watchdog.js b/src/components/Blockly/generator/watchdog.js new file mode 100644 index 0000000..0f51766 --- /dev/null +++ b/src/components/Blockly/generator/watchdog.js @@ -0,0 +1,16 @@ +import * as Blockly from "blockly/core"; + +Blockly.Arduino.watchdog_enable = function () { + var time = this.getFieldValue("TIME"); + + Blockly.Arduino.libraries_["Adafruit_sleepydog"] = + "#include "; + Blockly.Arduino.setupCode_["watchdog_enable"] = `Watchdog.enable(${time});`; + var code = ""; + return code; +}; + +Blockly.Arduino.watchdog_reset = function () { + var code = "Watchdog.reset();"; + return code; +}; diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 39e2095..8f71bbc 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -608,28 +608,34 @@ class Toolbox extends React.Component { custom="PROCEDURE" > - - - - - - - - - - - - - - - - - - - 100 - - - + + + + + + + + + + + + + + + + + + + + 100 + + + + + + + + {/* this block is the initial block of the workspace; not necessary to display, because it can only be used once anyway