From 29e2ec4f40cfaee4d7d692b3e644bcf1df3e85b9 Mon Sep 17 00:00:00 2001 From: Greg Corbett Date: Wed, 27 Jul 2016 11:25:16 +0100 Subject: [PATCH 1/8] Fix loop variable declaration bug --- .../ardublock/translator/block/RepeatBlock.java | 8 +++----- .../translator/block/RepeatControlBlock.java | 15 +++++++++++---- .../translator/block/RepeatTimesBlock.java | 5 ++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ardublock/translator/block/RepeatBlock.java b/src/main/java/com/ardublock/translator/block/RepeatBlock.java index 28f49c90..bec50cff 100644 --- a/src/main/java/com/ardublock/translator/block/RepeatBlock.java +++ b/src/main/java/com/ardublock/translator/block/RepeatBlock.java @@ -20,17 +20,15 @@ public RepeatBlock(Long blockId, Translator translator, String codePrefix, Strin @Override public String toCode() throws SocketNullException, SubroutineNotDeclaredException { - String varName="";//this.getRequiredTranslatorBlockAtSocket(0); TranslatorBlock teste = this.getRequiredTranslatorBlockAtSocket(0); if (!(teste instanceof VariableNumberBlock || teste instanceof VariableNumberUnsignedLongBlock || teste instanceof VariableNumberDoubleBlock)) { throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.number_var_slot")); } - varName=varName+teste.toCode(); - //translator.addDefinitionCommand("int " + varName + "; //teste"); - String ret = "for (" + varName + "= 1; " + varName + "<= ( "; + String varName=teste.toCode(); + String ret = "for(int " + varName + "=1; " + varName + " <= "; TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(1); ret = ret + translatorBlock.toCode(); - ret = ret + " ); " + varName + "++ )\n{\n"; + ret = ret + "; " + varName + "++)\n{\n"; translatorBlock = getTranslatorBlockAtSocket(2); diff --git a/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java b/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java index 2d78253b..aed2b88d 100644 --- a/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java +++ b/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java @@ -37,11 +37,18 @@ public String toCode() throws SocketNullException, SubroutineNotDeclaredExceptio tb = this.getRequiredTranslatorBlockAtSocket(3); String incVal = tb.toCode(); - String ret = ""; + String ret = "for(int " + varName + " = " + startVal + "; "; - ret = ret + "for(" + varName + " = " + startVal + "; \n" + - startVal + "<=" + stopVal + "?" + varName + " <= " + stopVal + ":" + varName + " >= " + stopVal + "; \n" + - startVal + "<=" + stopVal + "?" + varName + " = " + varName + " + " + incVal + ":" + varName + " = " + varName + " - " + incVal + ")\n{"; + if (Integer.parseInt(startVal) <= Integer.parseInt(stopVal)) { + ret = ret + varName + " <= " + stopVal+"; "; + ret = ret + varName + " + " + incVal+";)\n"; + } + else { + ret = ret + varName + " > " + stopVal+"; "; + ret = ret + varName + " - " + incVal+";)\n"; + } + + ret = ret +"{"; TranslatorBlock translatorBlock = getTranslatorBlockAtSocket(4); while (translatorBlock != null) diff --git a/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java b/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java index ea2b9d97..4eca561c 100644 --- a/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java +++ b/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java @@ -16,11 +16,10 @@ public RepeatTimesBlock(Long blockId, Translator translator, String codePrefix, public String toCode() throws SocketNullException, SubroutineNotDeclaredException { String varName = translator.buildVariableName(); - translator.addDefinitionCommand("int " + varName + "a;"); - String ret = "for (" + varName + "a=1; " + varName + "a<= ( "; + String ret = "for(int " + varName + "i=1; " + varName + "i <= "; TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(0); ret = ret + translatorBlock.toCode(); - ret = ret + " ); ++" + varName + "a )\n{\n"; + ret = ret + "; " + varName + "i++)\n{\n"; translatorBlock = getTranslatorBlockAtSocket(1); From ccc88914b1793ac10436c863a5fcb530d9bda321 Mon Sep 17 00:00:00 2001 From: Greg Corbett Date: Wed, 27 Jul 2016 15:27:12 +0100 Subject: [PATCH 2/8] Alter loop counters to be more pythonic --- .../java/com/ardublock/translator/block/RepeatBlock.java | 2 +- .../com/ardublock/translator/block/RepeatControlBlock.java | 6 +++--- .../com/ardublock/translator/block/RepeatTimesBlock.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ardublock/translator/block/RepeatBlock.java b/src/main/java/com/ardublock/translator/block/RepeatBlock.java index bec50cff..7706b950 100644 --- a/src/main/java/com/ardublock/translator/block/RepeatBlock.java +++ b/src/main/java/com/ardublock/translator/block/RepeatBlock.java @@ -25,7 +25,7 @@ public String toCode() throws SocketNullException, SubroutineNotDeclaredExceptio throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.number_var_slot")); } String varName=teste.toCode(); - String ret = "for(int " + varName + "=1; " + varName + " <= "; + String ret = "for(int " + varName + "=0; " + varName + " < "; TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(1); ret = ret + translatorBlock.toCode(); ret = ret + "; " + varName + "++)\n{\n"; diff --git a/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java b/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java index aed2b88d..370d2a72 100644 --- a/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java +++ b/src/main/java/com/ardublock/translator/block/RepeatControlBlock.java @@ -40,12 +40,12 @@ public String toCode() throws SocketNullException, SubroutineNotDeclaredExceptio String ret = "for(int " + varName + " = " + startVal + "; "; if (Integer.parseInt(startVal) <= Integer.parseInt(stopVal)) { - ret = ret + varName + " <= " + stopVal+"; "; - ret = ret + varName + " + " + incVal+";)\n"; + ret = ret + varName + " < " + stopVal+"; "; + ret = ret + varName + " = " + varName + " + " + incVal+")\n"; } else { ret = ret + varName + " > " + stopVal+"; "; - ret = ret + varName + " - " + incVal+";)\n"; + ret = ret + varName + " = " + varName + " - " + incVal+")\n"; } ret = ret +"{"; diff --git a/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java b/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java index 4eca561c..f5d71a6f 100644 --- a/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java +++ b/src/main/java/com/ardublock/translator/block/RepeatTimesBlock.java @@ -16,7 +16,7 @@ public RepeatTimesBlock(Long blockId, Translator translator, String codePrefix, public String toCode() throws SocketNullException, SubroutineNotDeclaredException { String varName = translator.buildVariableName(); - String ret = "for(int " + varName + "i=1; " + varName + "i <= "; + String ret = "for(int " + varName + "i=0; " + varName + "i < "; TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(0); ret = ret + translatorBlock.toCode(); ret = ret + "; " + varName + "i++)\n{\n"; From 200c6f0ad4b098b8889e3b3dc2095d320ffbdf0b Mon Sep 17 00:00:00 2001 From: Greg Corbett Date: Wed, 27 Jul 2016 15:27:57 +0100 Subject: [PATCH 3/8] Update ChangeLog.txt --- ChangeLog.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 3bb1c394..7c5197e0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,14 @@ Changelog + +========== Version 2.0.0 ========== + +Major Changes: +Alter loop counters to be more pythonic (starting at 0) + +Minor Changes: +Defines loop counters in the loop + ========== Version 1.1.0 ========== Major Changes: From 2c479f95a548465f8214ea8a7c601b3a0c11978b Mon Sep 17 00:00:00 2001 From: Greg Corbett Date: Wed, 27 Jul 2016 15:40:32 +0100 Subject: [PATCH 4/8] Replace the Tinker function with digitalWrite --- .../AbstractTinkerWriteDigitalBlock.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ardublock/translator/block/tinker/AbstractTinkerWriteDigitalBlock.java b/src/main/java/com/ardublock/translator/block/tinker/AbstractTinkerWriteDigitalBlock.java index 374041ba..210f4757 100644 --- a/src/main/java/com/ardublock/translator/block/tinker/AbstractTinkerWriteDigitalBlock.java +++ b/src/main/java/com/ardublock/translator/block/tinker/AbstractTinkerWriteDigitalBlock.java @@ -22,22 +22,16 @@ public String toCode() throws SocketNullException, SubroutineNotDeclaredExceptio TranslatorBlock translatorBlock = this.getRequiredTranslatorBlockAtSocket(0); String ret = ""; - if (translatorBlock instanceof NumberBlock || translatorBlock instanceof TinkerOutputPortBlock) + String number = translatorBlock.toCode(); + + if (translatorBlock instanceof NumberBlock) { - String number = translatorBlock.toCode(); String setupCode = "pinMode( " + number + " , OUTPUT);"; translator.addSetupCommand(setupCode); - - ret = "digitalWrite( "; - ret = ret + number; - } - else - { - translator.addDefinitionCommand(DigitalOutputBlock.ARDUBLOCK_DIGITAL_WRITE_DEFINE); - ret = "__ardublockDigitalWrite("; - - ret = ret + translatorBlock.toCode(); } + + ret = "digitalWrite( "; + ret = ret + number; ret = ret + " , "; translatorBlock = this.getRequiredTranslatorBlockAtSocket(1); From 6d535a6163e095aa3b6dd1f92fc24e9ceceb5636 Mon Sep 17 00:00:00 2001 From: Greg Corbett Date: Wed, 27 Jul 2016 15:44:01 +0100 Subject: [PATCH 5/8] Update ChangeLog.txt --- ChangeLog.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 3bb1c394..c283420a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,11 @@ Changelog + +========== Version 1.1.1 ========== + +Patches and Bug Fixes: +Tinker blocks in loops no longer generate functions + ========== Version 1.1.0 ========== Major Changes: From a0d30dfdcbdd2fbb0a2d9159f7c4d802e434e3d6 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 27 Jul 2016 19:19:55 +0100 Subject: [PATCH 6/8] Version bump to 2.0.0-1.beta --- ChangeLog.txt | 2 +- pom.xml | 2 +- src/main/resources/com/ardublock/block/ardublock.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 7c5197e0..c96088e1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,7 @@ Changelog -========== Version 2.0.0 ========== +========== Version 2.0.0-1.beta ========== Major Changes: Alter loop counters to be more pythonic (starting at 0) diff --git a/pom.xml b/pom.xml index 4e859de7..88d252c5 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.ardublock ardublock jar - 1.1.0-SNAPSHOT + 2.0.0-1.beta-SNAPSHOT ArduBlock A Block Programming Language for Arduino diff --git a/src/main/resources/com/ardublock/block/ardublock.properties b/src/main/resources/com/ardublock/block/ardublock.properties index 698fa2ba..626e3651 100644 --- a/src/main/resources/com/ardublock/block/ardublock.properties +++ b/src/main/resources/com/ardublock/block/ardublock.properties @@ -437,7 +437,7 @@ ardublock.ui.create_refer=create reference ardublock.ui.website=Go to Web Site ardublock.ui.serialMonitor=Serial Monitor ardublock.ui.saveImage=Save as image... -ardublock.ui.version=1.1.0 +ardublock.ui.version=2.0.0-1.beta ardublock.error_msg.digital_var_slot=Digital variable slot must take a 'digital variable' name.\nHint: Look at the 'variable' socket on the highlighted block ardublock.error_msg.number_var_slot=Standard variable slot must take a standard 'numeric' variable name.\nHint: Look at the 'variable' socket on the highlighted block From fe13141c946c9a2b48ea467e527e0aefc34bdf90 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 27 Jul 2016 19:21:45 +0100 Subject: [PATCH 7/8] Version Bump to 1.1.1-1.beta --- ChangeLog.txt | 2 +- pom.xml | 2 +- src/main/resources/com/ardublock/block/ardublock.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c283420a..ae671dcb 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,7 @@ Changelog -========== Version 1.1.1 ========== +========== Version 1.1.1-1.beta ========== Patches and Bug Fixes: Tinker blocks in loops no longer generate functions diff --git a/pom.xml b/pom.xml index 4e859de7..c1e26e79 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.ardublock ardublock jar - 1.1.0-SNAPSHOT + 1.1.1-1.beta-SNAPSHOT ArduBlock A Block Programming Language for Arduino diff --git a/src/main/resources/com/ardublock/block/ardublock.properties b/src/main/resources/com/ardublock/block/ardublock.properties index 698fa2ba..eb895cb2 100644 --- a/src/main/resources/com/ardublock/block/ardublock.properties +++ b/src/main/resources/com/ardublock/block/ardublock.properties @@ -437,7 +437,7 @@ ardublock.ui.create_refer=create reference ardublock.ui.website=Go to Web Site ardublock.ui.serialMonitor=Serial Monitor ardublock.ui.saveImage=Save as image... -ardublock.ui.version=1.1.0 +ardublock.ui.version=1.1.1.beta ardublock.error_msg.digital_var_slot=Digital variable slot must take a 'digital variable' name.\nHint: Look at the 'variable' socket on the highlighted block ardublock.error_msg.number_var_slot=Standard variable slot must take a standard 'numeric' variable name.\nHint: Look at the 'variable' socket on the highlighted block From bfe2701e3608ed25ce0699b5d33dfb9bca4c6e5b Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 27 Jul 2016 19:28:07 +0100 Subject: [PATCH 8/8] Version bump to 2.0.0 --- ChangeLog.txt | 2 +- pom.xml | 2 +- src/main/resources/com/ardublock/block/ardublock.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d5fa557e..94f43137 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,7 @@ Changelog -========== Version 2.0.0-1.beta ========== +========== Version 2.0.0 ========== Major Changes: Alter loop counters to be more pythonic (starting at 0) diff --git a/pom.xml b/pom.xml index 88d252c5..08ad4ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.ardublock ardublock jar - 2.0.0-1.beta-SNAPSHOT + 2.0.0-SNAPSHOT ArduBlock A Block Programming Language for Arduino diff --git a/src/main/resources/com/ardublock/block/ardublock.properties b/src/main/resources/com/ardublock/block/ardublock.properties index dc33ee5a..09561fc0 100644 --- a/src/main/resources/com/ardublock/block/ardublock.properties +++ b/src/main/resources/com/ardublock/block/ardublock.properties @@ -437,7 +437,7 @@ ardublock.ui.create_refer=create reference ardublock.ui.website=Go to Web Site ardublock.ui.serialMonitor=Serial Monitor ardublock.ui.saveImage=Save as image... -ardublock.ui.version=2.0.0-1.beta +ardublock.ui.version=2.0.0 ardublock.error_msg.digital_var_slot=Digital variable slot must take a 'digital variable' name.\nHint: Look at the 'variable' socket on the highlighted block ardublock.error_msg.number_var_slot=Standard variable slot must take a standard 'numeric' variable name.\nHint: Look at the 'variable' socket on the highlighted block