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

Merge branch 'dev_SimTypeFloat' into 'master'

Dev sim type float

See merge request !1
parents c41a99e9 8c845c64
No related branches found
No related tags found
1 merge request!1Dev sim type float
...@@ -6,6 +6,8 @@ package tec.letsgoing.ardublock.simulator; ...@@ -6,6 +6,8 @@ package tec.letsgoing.ardublock.simulator;
import java.awt.Point; import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector; import java.util.Vector;
import javax.swing.UIManager; import javax.swing.UIManager;
...@@ -104,6 +106,15 @@ public class Simulator implements Runnable, ActionListener{ ...@@ -104,6 +106,15 @@ public class Simulator implements Runnable, ActionListener{
guiThread = new Thread(gui); guiThread = new Thread(gui);
guiThread.start(); guiThread.start();
//override close operation
//TODO: TEST
gui.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
instance.stopSimu();
gui.stopThread();
}
});
return true; return true;
} }
......
...@@ -11,7 +11,7 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeString; ...@@ -11,7 +11,7 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeString;
/** /**
* Sende Nachricht via Serial * Sende Nachricht via Serial
* *
* @author Lucas * @author Lucas, Anian
* *
* *
*/ */
...@@ -19,6 +19,21 @@ public class CodeSerialPrint extends SimCode { ...@@ -19,6 +19,21 @@ public class CodeSerialPrint extends SimCode {
private SimTypeString stringBlock; private SimTypeString stringBlock;
private SimTypeBool boolBlock; private SimTypeBool boolBlock;
private String replaceEscapeCodes(String str) {
int indexNL = str.indexOf("\\n");
int indexTab = str.indexOf("\\t");
while(indexNL > -1) {
str = str.substring(0, indexNL) + "\n" + str.substring(indexNL+2);
indexNL = str.indexOf("\\n");
}
while(indexTab > -1) {
str = str.substring(0, indexTab) + "\t" + str.substring(indexTab+2);
indexTab = str.indexOf("\\t");
}
return str;
}
public CodeSerialPrint(SimTypeString _stringBlock, SimTypeBool _boolBlock) { public CodeSerialPrint(SimTypeString _stringBlock, SimTypeBool _boolBlock) {
stringBlock = _stringBlock; stringBlock = _stringBlock;
boolBlock = _boolBlock; boolBlock = _boolBlock;
...@@ -26,7 +41,10 @@ public class CodeSerialPrint extends SimCode { ...@@ -26,7 +41,10 @@ public class CodeSerialPrint extends SimCode {
public SimCode run(Arduino _arduino, SimCode functionHead) { public SimCode run(Arduino _arduino, SimCode functionHead) {
String content; String content;
content = stringBlock.run(_arduino, functionHead).toString(); content = stringBlock.run(_arduino, functionHead).toString();
content = replaceEscapeCodes(content);
if (boolBlock.run(_arduino, functionHead).getValue()) { if (boolBlock.run(_arduino, functionHead).getValue()) {
content += "\n"; content += "\n";
} }
......
...@@ -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 {
...@@ -27,11 +27,21 @@ public class SimTypeInt extends SimCode { ...@@ -27,11 +27,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) {
try {
SimTypeInt ret = (SimTypeInt) followBlock.run(_arduino, functionHead); SimTypeInt ret = (SimTypeInt) followBlock.run(_arduino, functionHead);
value = (short) ret.getValue(); value = (short) ret.getValue();
} catch (Exception e) {
//if a none-SimTypeInt Block is attached
try {
SimTypeLong ret = (SimTypeLong) followBlock.run(_arduino, functionHead);
value = (short) ret.getValue();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.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
try {
SimTypeInt ret = (SimTypeInt) followBlock.run(_arduino, functionHead);
value = (short) ret.getValue();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.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
......
...@@ -428,16 +428,13 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -428,16 +428,13 @@ public class GUI extends JFrame implements Runnable, ActionListener {
while (!stopFlag) { while (!stopFlag) {
try { try {
//Thread.sleep(7); // 144 Hz //Thread.sleep(7); // 144 Hz
Thread.sleep(17); //60 Hz //Thread.sleep(17); //60 Hz
Thread.sleep(50); //20 Hz
} catch (InterruptedException e) { } catch (InterruptedException e) {
// e.printStackTrace(); // e.printStackTrace();
} }
super.repaint(); super.repaint();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment