diff --git a/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeInt.java b/src/tec/letsgoing/ardublock/simulator/simcode/datatypes/SimTypeInt.java index d7581e02148e541e106ba7d46a69c4d72c20da9f..cef6cb18d0a8f9774844615beff9587a62e8a8cd 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 0000000000000000000000000000000000000000..4b5f6a380d3d0bb68c581e8e4c7741c7fdbdd5ac --- /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 0be20c824a643d5d10fa0468fbeb3d8dd33b5a50..5ffc535de2539ba97a3d38de4f9363ef7adbf03a 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