ea39f52e9d9fc0eec02f960aa11c6afd73c11194
3 import java
.io
.IOException
;
4 import java
.io
.OutputStream
;
5 import java
.io
.PrintStream
;
6 import java
.util
.Deque
;
7 import java
.util
.LinkedList
;
9 import lejos
.hardware
.lcd
.TextLCD
;
10 import lejos
.utility
.Delay
;
12 public class LCDPrinter
{
13 public static final int PRINTDELAY
= 50;
15 private static Deque
<String
> buffer
= new LinkedList
<String
>();
17 public static void startLCDPrinter(final TextLCD glcd
) {
18 new Thread(new Runnable(){
22 if (!buffer
.isEmpty()) {
23 String c
= buffer
.remove();
24 if(c
.length() > glcd
.getTextWidth()){
25 buffer
.addFirst(c
.substring(glcd
.getTextWidth(), c
.length()));
26 c
= c
.substring(0, glcd
.getTextWidth());
29 glcd
.drawString(c
, 0, glcd
.getTextHeight()-1);
31 Delay
.msDelay(PRINTDELAY
);
35 LCDPrinter
.print("LCDThread started");
38 public static void print(String s
){
42 public static PrintStream
getPrefixedPrintstream(final String prefix
, final TextLCD glcd
){
43 return new PrintStream(new OutputStream(){
44 private char[] line
= new char[glcd
.getTextWidth()];
45 private int index
= 0;
48 public void write(int b
) throws IOException
{
49 if(index
== line
.length
-prefix
.length() || b
== '\n'){
50 LCDPrinter
.print(prefix
+ String
.valueOf(line
, 0, index
));
53 line
[index
++] = (char)b
;