Skip to content
Snippets Groups Projects
Commit 490a3816 authored by Anian Bühler's avatar Anian Bühler
Browse files

added SimTypeLong and changed millis() to SimTypeLong

parent c41a99e9
No related branches found
No related tags found
1 merge request!1Dev sim type float
...@@ -7,9 +7,9 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino; ...@@ -7,9 +7,9 @@ import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.simcode.SimCode; 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 { public class SimTypeInt extends SimCode {
...@@ -26,12 +26,21 @@ public class SimTypeInt extends SimCode { ...@@ -26,12 +26,21 @@ public class SimTypeInt extends SimCode {
@Override @Override
public SimTypeInt run(Arduino _arduino, SimCode functionHead) { public SimTypeInt run(Arduino _arduino, SimCode functionHead) {
if (followBlock instanceof SimCode) { if (followBlock instanceof SimCode) {
SimTypeInt ret = (SimTypeInt) followBlock.run(_arduino, functionHead); try {
value = (short) ret.getValue(); 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); return new SimTypeInt(value);
} }
@Override @Override
......
/**
*
*/
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;
}
}
...@@ -5,19 +5,21 @@ package tec.letsgoing.ardublock.simulator.simcode.vars; ...@@ -5,19 +5,21 @@ package tec.letsgoing.ardublock.simulator.simcode.vars;
import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Arduino;
import tec.letsgoing.ardublock.simulator.simcode.SimCode; 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 * Gibt die Zeit seit Programmstart in Millisekunden an
* *
* @author Lucas * @author Lucas, Anian
* *
*/ */
//changed Datatype to SimTypeLong (int32)
public class CodeMillis extends SimCode { public class CodeMillis extends SimCode {
@Override @Override
public SimTypeInt run(Arduino _arduino, SimCode functionHead) { public SimTypeLong run(Arduino _arduino, SimCode functionHead) {
return new SimTypeInt(_arduino.getMillis()); return new SimTypeLong(_arduino.getMillis());
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment