From 490a3816363100d16945373ebb5b0b67c40f3961 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anian=20B=C3=BChler?=
 <anian.buehler@reutlingen-university.de>
Date: Fri, 14 Jan 2022 11:30:11 +0100
Subject: [PATCH] added SimTypeLong and changed millis() to SimTypeLong

---
 .../simcode/datatypes/SimTypeInt.java         | 21 +++++--
 .../simcode/datatypes/SimTypeLong.java        | 56 +++++++++++++++++++
 .../simulator/simcode/vars/CodeMillis.java    | 10 ++--
 3 files changed, 77 insertions(+), 10 deletions(-)
 create mode 100644 src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeLong.java

diff --git a/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeInt.java b/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeInt.java
index d7581e0..cef6cb1 100644
--- a/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeInt.java
+++ b/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeInt.java
@@ -7,9 +7,9 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino;
 import tec.letsgoing.ardublock.simulator.simcode.SimCode;
 
 /**
- * Klasse für einen Int-Datentyp
+ * Klasse für einen int16-Datentyp
  * 
- * @author Lucas
+ * @author Lucas, Anian
  * 
  */
 public class SimTypeInt extends SimCode {
@@ -26,12 +26,21 @@ public class SimTypeInt extends SimCode {
 
 	@Override
 	public SimTypeInt run(Arduino _arduino, SimCode functionHead) {
-		if (followBlock instanceof SimCode) {
-			SimTypeInt ret = (SimTypeInt) followBlock.run(_arduino, functionHead);
-			value = (short) ret.getValue();
+		if (followBlock instanceof SimCode) {		
+				try {
+					SimTypeInt ret = (SimTypeInt) followBlock.run(_arduino, functionHead);
+					value = (short) ret.getValue();
+				} catch (Exception e) {
+					//if a none-SimTypeInt Block is attached 
+					if(e.toString().contains("SimTypeLong")) {
+						SimTypeLong ret = (SimTypeLong) followBlock.run(_arduino, functionHead);
+						value = (short) ret.getValue();
+					}else {
+						e.printStackTrace();
+					}
+				}	
 		}
 		return new SimTypeInt(value);
-
 	}
 
 	@Override
diff --git a/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeLong.java b/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeLong.java
new file mode 100644
index 0000000..4b5f6a3
--- /dev/null
+++ b/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeLong.java
@@ -0,0 +1,56 @@
+/**
+ * 
+ */
+package tec.letsgoing.ardublock.simulator.simcode.datatypes;
+
+import tec.letsgoing.ardublock.simulator.arduino.Arduino;
+import tec.letsgoing.ardublock.simulator.simcode.SimCode;
+
+/**
+ * Klasse für einen Int32-Datentyp (long)
+ * 
+ * @author Anian
+ * 
+ */
+public class SimTypeLong extends SimCode {
+	private int value = 0;
+	private SimCode followBlock;
+
+	public SimTypeLong(int _value) {
+		value = (int) _value;
+	}
+
+	public SimTypeLong(SimCode block) {
+		followBlock = block;
+	}
+
+	@Override
+	public SimTypeLong run(Arduino _arduino, SimCode functionHead) {
+		if (followBlock instanceof SimCode) {
+			try {
+				SimTypeLong ret = (SimTypeLong) followBlock.run(_arduino, functionHead);
+				value = (int) ret.getValue();
+			} catch (Exception e) {
+				//if a none-SimTypeLong Block is attached 
+				if(e.toString().contains("SimTypeInt")) {
+					SimTypeInt ret = (SimTypeInt) followBlock.run(_arduino, functionHead);
+					value = (short) ret.getValue();
+				}else {
+					e.printStackTrace();
+				}
+			}	
+		}
+		return new SimTypeLong(value);
+
+	}
+
+	@Override
+	public String toString() {
+		return String.valueOf(value);
+	}
+
+	public int getValue() {
+		return (int) value;
+	}
+
+}
diff --git a/src/tec/letsgoing/ardublock/simulator/simcode/vars/CodeMillis.java b/src/tec/letsgoing/ardublock/simulator/simcode/vars/CodeMillis.java
index 0be20c8..5ffc535 100644
--- a/src/tec/letsgoing/ardublock/simulator/simcode/vars/CodeMillis.java
+++ b/src/tec/letsgoing/ardublock/simulator/simcode/vars/CodeMillis.java
@@ -5,19 +5,21 @@ package tec.letsgoing.ardublock.simulator.simcode.vars;
 
 import tec.letsgoing.ardublock.simulator.arduino.Arduino;
 import tec.letsgoing.ardublock.simulator.simcode.SimCode;
-import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeInt;
+import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeLong;
 
 /**
  * Gibt die Zeit seit Programmstart in Millisekunden an
  * 
- * @author Lucas
+ * @author Lucas, Anian
  *
  */
+
+//changed Datatype to SimTypeLong (int32)
 public class CodeMillis extends SimCode {
 
 	@Override
-	public SimTypeInt run(Arduino _arduino, SimCode functionHead) {
-		return new SimTypeInt(_arduino.getMillis());
+	public SimTypeLong run(Arduino _arduino, SimCode functionHead) {
+		return new SimTypeLong(_arduino.getMillis());
 	}
 
 	@Override
-- 
GitLab