diff --git a/README.md b/README.md
index 3409625..f70bc90 100644
--- a/README.md
+++ b/README.md
@@ -12,8 +12,10 @@ To be decided, but at this moment this code is open source and free to use for n
## Changelog
-### 0.2.10
+### 0.2.11
+* Added Delay element
+### 0.2.10
* New elements will now do overlap detection on placement
* Newly placed elements will now be selected
diff --git a/index.html b/index.html
index 38cbb20..3fe89fa 100644
--- a/index.html
+++ b/index.html
@@ -45,7 +45,8 @@
-
+
+
diff --git a/js/logicengine.js b/js/logicengine.js
index c750213..7689f98 100644
--- a/js/logicengine.js
+++ b/js/logicengine.js
@@ -642,6 +642,95 @@ class PulseElement extends Element {
}
}
+class DelayElement extends Element {
+ ClockTick() {
+ if (this.Output) {
+ this.Output = false;
+ this.Task.Enabled = false;
+ this.Task.LastCall = Date.now();
+ this.Task.Time = this.Period;
+ } else {
+ this.Output = true;
+ this.Task.Enabled = false;
+ if (this.InputEnd > 0) {
+ this.Task.Time = this.InputEnd - this.InputStart;
+ this.Task.Enabled = true;
+ }
+ this.Task.LastCall = Date.now();
+ }
+ for (let a = 0; a < this.OutputConnections.length; a++) {
+ this.LogicEngine.RecursionCount = 0;
+ this.OutputConnections[a].Element.setInput(this.OutputConnections[a].Input, this.getOutput());
+ }
+ }
+
+ Delete() {
+ super.Delete();
+ this.LogicEngine.Scheduler.deleteTask(this.Task);
+ }
+
+ getOutput() {
+ return this.Output;
+ }
+
+ setInput(Input, Value) {
+ if (Input > 0) return;
+ if (this.Inputs[Input] == Value) return;
+ //super.setInput(Input, Value);
+ this.Inputs[Input] = Value;
+ if (this.Inputs[0] && !this.Task.Enabled) {
+ this.InputStart = Date.now();
+ this.InputEnd = 0;
+ this.Output = false;
+ for (let a = 0; a < this.OutputConnections.length;a++) {
+ this.LogicEngine.RecursionCount = 0;
+ this.OutputConnections[a].Element.setInput(this.OutputConnections[a].Input,this.getOutput());
+ }
+ this.Task.LastCall = Date.now();
+ this.Task.Enabled = true;
+ } else {
+ this.InputEnd = Date.now();
+ if (!this.Task.Enabled) {
+ this.Task.LastCall = Date.now();
+ this.Task.Time = (this.InputEnd - this.InputStart) - (Date.now() - this.InputEnd);
+ this.Task.Enabled = true;
+ }
+ }
+ }
+
+ constructor(logicengine) {
+ super(logicengine,1);
+ this.removeProperty("Inputs");
+ this.Name = "Delay";
+ this.Period = 100;
+ this.Output = false;
+ this.Width = 100;
+ this.Task = new Task("DelayTask","CLOCK",0,this.Period,this.ClockTick.bind(this));
+ this.Task.Enabled = false;
+ this.removeProperty("Inputs");
+ let periodProperty = new ElementProperty("Period","int",{CBObject: this,CBFunction: "setPeriod"},100,false,false,4,999999);
+ this.Properties.push(periodProperty);
+ this.InputStart = 0;
+ this.InputEnd = 0;
+ this.Inputs[0] = false;
+ }
+
+ setPeriod(period) {
+ this.Period = parseInt(period);
+ this.Task.Time = parseInt(period);
+ this.getProperty("Period").CurrentValue = parseInt(period);
+ }
+
+ drawElement(x, y, ctx) {
+ this.drawBorderBox(ctx, x+10,y,this.Width-20,this.Height,1,"#000","#f7e979",this.LogicEngine.Settings.ShadowColor);
+ this.drawTextCentered(ctx,x,y+5,this.Width,12,this.Period + "ms","10px Console");
+ if (this.Task.Enabled) this.drawTextCentered(ctx,x,y+this.Height-16,this.Width,12,(this.Task.Time - (Date.now() - this.Task.LastCall)) + "ms","10px Console");
+ this.drawTextCentered(ctx,x,y,this.Width,this.Height,this.Designator,"12px Console","#000");
+ this.drawInputs(ctx,x,y);
+ this.drawOutputs(ctx,x,y);
+ }
+}
+
class inputElement extends Element {
constructor(logicengine) {
diff --git a/js/main.js b/js/main.js
index 74d4bdd..8001ceb 100644
--- a/js/main.js
+++ b/js/main.js
@@ -2,7 +2,7 @@
MatCat BrowserLogic Simulator
*/
-let Version = "0.2.10";
+let Version = "0.2.11";
let spanVersion = document.getElementById("version");
spanVersion.innerText = Version;
// get the canvas and get the engine object going
@@ -111,6 +111,12 @@ btn_AddPulse.addEventListener('click', function(evt) {
logicEngine.Scheduler.addTask(pulse.Task);
}, false);
+let btn_AddDelay = document.getElementById("btn_AddDELAY");
+btn_AddDelay.addEventListener('click', function(evt) {
+ let delay = addElement(DelayElement,[]);
+ logicEngine.Scheduler.addTask(delay.Task);
+}, false);
+
function CheckForWelcomeCookie() {
if (getCookie("hidewelcomescreen")) {
let WelcomeScreen = document.getElementById("WelcomeWindow");