Implemented measure motor
[des2015.git] / dsl / runtime / src / nl / ru / des / LCDPrinter.java
index ea39f52..fdfcd60 100644 (file)
@@ -11,8 +11,18 @@ import lejos.utility.Delay;
 
 public class LCDPrinter{
        public static final int PRINTDELAY = 50;
+       
+       private static class Message{
+               public String msg;
+               public boolean nl;
+               
+               public Message(String msg, boolean nl){
+                       this.msg = msg;
+                       this.nl = nl;
+               }
+       }
 
-       private static Deque<String> buffer = new LinkedList<String>();
+       private static Deque<Message> buffer = new LinkedList<Message>();
 
        public static void startLCDPrinter(final TextLCD glcd) {
                new Thread(new Runnable(){
@@ -20,13 +30,17 @@ public class LCDPrinter{
                        public void run() {
                                while (true) {
                                        if (!buffer.isEmpty()) {
-                                               String c = buffer.remove();
-                                               if(c.length() > glcd.getTextWidth()){
-                                                       buffer.addFirst(c.substring(glcd.getTextWidth(), c.length()));
-                                                       c = c.substring(0, glcd.getTextWidth());
+                                               Message c = buffer.remove();
+                                               if(c.msg.length() > glcd.getTextWidth()){
+                                                       buffer.addFirst(new Message(c.msg.substring(glcd.getTextWidth(), c.msg.length()), c.nl));
+                                                       c.msg = c.msg.substring(0, glcd.getTextWidth());
+                                               }
+                                               if(c.nl){
+                                                       glcd.scroll();
+                                               } else {
+                                                       glcd.clear(glcd.getTextHeight()-1);
                                                }
-                                               glcd.scroll();
-                                               glcd.drawString(c, 0, glcd.getTextHeight()-1);
+                                               glcd.drawString(c.msg, 0, glcd.getTextHeight()-1);
                                        }
                                        Delay.msDelay(PRINTDELAY);
                                }
@@ -36,7 +50,11 @@ public class LCDPrinter{
        }
        
        public static void print(String s){
-               buffer.addLast(s);
+               print(s, true);
+       }
+       
+       public static void print(String s, boolean nl){
+               buffer.addLast(new Message(s, nl));
        }
        
        public static PrintStream getPrefixedPrintstream(final String prefix, final TextLCD glcd){