Guest User

Extender class for BrickletLCD20x4

a guest
Jan 2nd, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. /* This class extends the standard LCD20x4 class to add extra functionality,
  2.  * currently the only one writes text to the LCD not line by line.
  3.  * You can still use the LCD as you would if you used the standard class.
  4.  */
  5. public class BrickletLCD20x4Writer extends com.tinkerforge.BrickletLCD20x4
  6. {
  7.  
  8.     private boolean debug = false;
  9.    
  10.     public BrickletLCD20x4Writer(String uid) {
  11.         super(uid);
  12.     }
  13.  
  14.     public void writeText(String text)
  15.     {
  16.  
  17.         String regex_pattern = "(?<=\\G.{20})";
  18.         int chars = text.length();
  19.  
  20.         if (chars <= 20)
  21.         {
  22.             this.writeLine((short) 0, (short) 0, text);
  23.         } else
  24.         {
  25.             String[] lines;
  26.             lines = text.split(regex_pattern);
  27.  
  28.             for (int i = 0; i < lines.length; i++)
  29.             {
  30.                 if (i <= 3)
  31.                 {
  32.  
  33.                     this.writeLine((short) i, (short) 0, lines[i]);
  34.                 } else
  35.                 {
  36.                     if (debug = true)
  37.                     {
  38.                         System.out.println("Error: No more free lines to write to.");
  39.                         System.out.println("Data: " + lines[i]);
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.     }
  45.    
  46.     private void setDebugStatus(boolean status) {
  47.         debug = status;
  48.     }
  49.    
  50.     private boolean getDebugStatus() {
  51.         return debug;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment