working robot
[des2015.git] / mart / ev3 / ex1 / nl / ru / des / LCDPrinter.java
1 package nl.ru.des;
2
3 import java.util.LinkedList;
4 import java.util.Queue;
5
6 import lejos.hardware.lcd.LCD;
7 import lejos.utility.Delay;
8
9 public class LCDPrinter extends Thread{
10 public static final int PRINTDELAY = 250;
11
12 private static Queue<String> buffer = new LinkedList<String>();
13 private static boolean shutdown = false;
14
15 public static void print(String s){
16 buffer.add(s);
17 }
18
19 public void run(){
20 int y = 0;
21 while(!shutdown || (shutdown && !buffer.isEmpty())){
22 if(!buffer.isEmpty()){
23 LCD.clear(y);
24 LCD.clear(Math.max(0, y+1));
25 LCD.drawString(buffer.remove(), 0, y);
26 y = y < LCD.DISPLAY_CHAR_DEPTH-1 ? y + 1 : 0;
27 }
28 Delay.msDelay(PRINTDELAY);
29 }
30 }
31
32 public static void shutdown(String s) {
33 buffer.add(s);
34 shutdown = true;
35 while(!buffer.isEmpty()){
36 Delay.msDelay(200);
37 }
38 }
39 }