/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 */
package org.thingml.compilers.c.arduino;

import org.thingml.compilers.Context;
import org.thingml.compilers.c.CThingActionCompiler;
import org.thingml.xtext.helpers.AnnotatedElementHelper;
import org.thingml.xtext.thingML.ErrorAction;
import org.thingml.xtext.thingML.PrintAction;

/**
 * Created by ffl on 11.06.15.
 */
public class CThingActionCompilerArduino extends CThingActionCompiler {

    @Override
    public void generate(ErrorAction action, StringBuilder builder, Context ctx) {
        final StringBuilder b = new StringBuilder();
        generate(action.getMsg(), b, ctx);

        builder.append("// PRINT ERROR: " + b.toString() + "\n");
    }

    @Override
    public void generate(PrintAction action, StringBuilder builder, Context ctx) {
        final StringBuilder b = new StringBuilder();
        generate(action.getMsg(), b, ctx);
        if (AnnotatedElementHelper.hasAnnotation(ctx.getCurrentConfiguration(), "arduino_stdout")) {
            builder.append(AnnotatedElementHelper.annotation(ctx.getCurrentConfiguration(), "arduino_stdout").iterator().next() + ".print(" + b.toString() + ");\n");
        } else {
            builder.append("// PRINT: " + b.toString() + "\n");
        }
    }

}

@@ -907,16 +907,61 @@
 Action;%0A
+import org.thingml.xtext.thingML.Expression;%0A
 import o
@@ -998,16 +998,16 @@
 Action;%0A
-
 %0A/**%0A * 
@@ -1467,32 +1467,82 @@
  Context ctx) %7B%0A
+        for(Expression e : action.getMsg()) %7B%0A    
         final St
@@ -1578,32 +1578,36 @@
 lder();%0A        
+    
 generate(action.
@@ -1595,39 +1595,25 @@
    generate(
-action.getMsg()
+e
 , b, ctx);%0A 
@@ -1619,16 +1619,17 @@
         
+%09
 if (Anno
@@ -1709,24 +1709,28 @@
 stdout%22)) %7B%0A
+    
             
@@ -1891,16 +1891,20 @@
         
+    
 %7D else %7B
@@ -1908,32 +1908,36 @@
 e %7B%0A            
+  
+  
 builder.append(%22
@@ -1968,24 +1968,444 @@
 () + %22%5Cn%22);%0A
+            %7D        %09        %09%0A        %7D%0A        if (action.isLine()) %7B%0A        %09if (AnnotatedElementHelper.hasAnnotation(ctx.getCurrentConfiguration(), %22arduino_stdout%22)) %7B%0A                builder.append(AnnotatedElementHelper.annotation(ctx.getCurrentConfiguration(), %22arduino_stdout%22).iterator().next() + %22.print(%5C%22%5C%5Cn%5C%22);%5Cn%22);%0A            %7D else %7B%0A                builder.append(%22// PRINT: %5C%22%5C%5Cn%5C%22%22);%0A            %7D%0A
         %7D%0A  

fix print in arduino compiler