diff --git a/src/tec/letsgoing/ardublock/simulator/simcode/comm/CodeSerialPrint.java b/src/tec/letsgoing/ardublock/simulator/simcode/comm/CodeSerialPrint.java index 5547e7a72ac408256f704e160e66bfc88fb68ced..074596441ccbbada47c3327fb38be2994ce6e835 100644 --- a/src/tec/letsgoing/ardublock/simulator/simcode/comm/CodeSerialPrint.java +++ b/src/tec/letsgoing/ardublock/simulator/simcode/comm/CodeSerialPrint.java @@ -11,13 +11,28 @@ import tec.letsgoing.ardublock.simulator.simcode.datatypes.SimTypeString; /** * Sende Nachricht via Serial * - * @author Lucas + * @author Lucas, Anian * * */ public class CodeSerialPrint extends SimCode { private SimTypeString stringBlock; 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) { stringBlock = _stringBlock; @@ -26,7 +41,10 @@ public class CodeSerialPrint extends SimCode { public SimCode run(Arduino _arduino, SimCode functionHead) { String content; + content = stringBlock.run(_arduino, functionHead).toString(); + content = replaceEscapeCodes(content); + if (boolBlock.run(_arduino, functionHead).getValue()) { content += "\n"; }