add watchdog

This commit is contained in:
Mario Pesch 2022-01-26 09:52:50 +01:00
parent 3e3956b185
commit 0c8ae90124
5 changed files with 74 additions and 22 deletions

View File

@ -21,6 +21,7 @@ import "./procedures";
import "./time";
import "./variables";
import "./lists";
import "./watchdog";
import "./webserver";
import "../helpers/types";

View File

@ -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("");
},
};

View File

@ -22,4 +22,5 @@ import "./procedures";
import "./time";
import "./variables";
import "./lists";
import "./watchdog";
import "./webserver";

View File

@ -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 <Adafruit_SleepyDog.h>";
Blockly.Arduino.setupCode_["watchdog_enable"] = `Watchdog.enable(${time});`;
var code = "";
return code;
};
Blockly.Arduino.watchdog_reset = function () {
var code = "Watchdog.reset();";
return code;
};

View File

@ -608,28 +608,34 @@ class Toolbox extends React.Component {
custom="PROCEDURE"
></Category>
<sep></sep>
<Category name={Blockly.Msg.toolbox_io} colour={getColour().io}>
<Block type="io_digitalwrite"></Block>
<Block type="io_digitalread"></Block>
<Block type="io_builtin_led"></Block>
<Block type="io_analogwrite"></Block>
<Block type="io_analogread"></Block>
<Block type="io_highlow"></Block>
<Block type="io_pulsein">
<Value name="PULSETYPE">
<Shadow type="io_highlow"></Shadow>
</Value>
</Block>
<Block type="io_pulsetimeout">
<Value name="PULSETYPE">
<Shadow type="io_highlow"></Shadow>
</Value>
<Value name="TIMEOUT">
<Shadow type="math_number">
<Field name="NUM">100</Field>
</Shadow>
</Value>
</Block>
<Category name="Advanced" colour={getColour().io}>
<Category name={Blockly.Msg.toolbox_io} colour={getColour().io}>
<Block type="io_digitalwrite"></Block>
<Block type="io_digitalread"></Block>
<Block type="io_builtin_led"></Block>
<Block type="io_analogwrite"></Block>
<Block type="io_analogread"></Block>
<Block type="io_highlow"></Block>
<Block type="io_pulsein">
<Value name="PULSETYPE">
<Shadow type="io_highlow"></Shadow>
</Value>
</Block>
<Block type="io_pulsetimeout">
<Value name="PULSETYPE">
<Shadow type="io_highlow"></Shadow>
</Value>
<Value name="TIMEOUT">
<Shadow type="math_number">
<Field name="NUM">100</Field>
</Shadow>
</Value>
</Block>
</Category>
<Category name="Watchdog" colour={getColour().io}>
<Block type="watchdog_enable"></Block>
<Block type="watchdog_reset"></Block>
</Category>
</Category>
{/* this block is the initial block of the workspace; not necessary
to display, because it can only be used once anyway