GUIboard.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package weerstation;
  2. import java.util.ArrayList;
  3. public class GUIboard {
  4. public static void writeUpperDigits(double number){
  5. clearTop();
  6. writeDigits(number, 0x10, 0x18);
  7. }
  8. public static void writeLeftDigits(double number){
  9. clearLeft();
  10. writeDigits(number, 0x20, 0x24);
  11. }
  12. public static void writeRightDigits(double number){
  13. clearRight();
  14. writeDigits(number, 0x30, 0x34);
  15. }
  16. private static void writeDigits(double number, int firstSegment, int lastSegment){
  17. number = Math.round(number * 100.0) / 100.0;
  18. //Segments
  19. int segA = 0x01;
  20. int segB = 0x02;
  21. int segC = 0x04;
  22. int segD = 0x08;
  23. int segE = 0x10;
  24. int segF = 0x20;
  25. int segG = 0x40;
  26. int segDP = 0x80;
  27. //Digits
  28. int[] digits = {
  29. segA | segB | segC | segD | segE | segF, //0
  30. segB | segC, //1
  31. segA | segB | segG | segE | segD, //2
  32. segA | segB | segC | segG | segD, //3
  33. segB | segC | segF | segG | segC, //4
  34. segA | segF | segG | segC | segD, //5
  35. segA | segF | segG | segC | segD | segE, //6
  36. segA | segB | segC, //7
  37. segDP - 1, //8
  38. segA | segF | segG | segC | segD | segB, //9
  39. };
  40. int digit = firstSegment;
  41. String numberString = String.valueOf(number);;
  42. char numberSplit[] = numberString.toCharArray();
  43. for(int i = numberSplit.length-1; i >= 0; i--){
  44. if(numberSplit[i] == '.'){
  45. IO.writeShort(digit, digits[(Character.getNumericValue(numberSplit[i - 1]))]|0x180); //display a . with the next number
  46. i--;
  47. }else if(numberSplit[i] == '-'){
  48. IO.writeShort(digit, 0x140); //will display a -
  49. }else{
  50. IO.writeShort(digit, Character.getNumericValue(numberSplit[i]));
  51. }
  52. digit += 2; //Next digits screen
  53. if(digit > lastSegment){ //If there are more then max digits needed, it will stop.
  54. break;
  55. }
  56. }
  57. }
  58. public static boolean writePageToMatrix(String regel1, String regel2, String regel3)
  59. {
  60. clearBottom();
  61. if(regel1.length() > 20 && regel2.length() > 20 && regel3.length() > 11) //check if the length is not to long
  62. {
  63. return false;
  64. }
  65. String nav = "< > S"; //creates the navigation and will center it out to the right
  66. for(int i=0; i < (12-regel3.length()); i++){
  67. nav = " " + nav;
  68. }
  69. char[] regel1CharArray = regel1.toCharArray();
  70. char[] regel2CharArray = regel2.toCharArray();
  71. char[] regel3CharArray = (regel3 + nav).toCharArray();
  72. for(char ch : regel1CharArray)
  73. {
  74. IO.writeShort(0x40, ch);
  75. }
  76. IO.writeShort(0x40, '\n');
  77. for(char ch : regel2CharArray)
  78. {
  79. IO.writeShort(0x40, ch);
  80. }
  81. IO.writeShort(0x40, '\n');
  82. for(char ch : regel3CharArray)
  83. {
  84. IO.writeShort(0x40, ch);
  85. }
  86. return true;
  87. }
  88. public static void writeGraphToMatrix(ArrayList<Measurement> msList, int axisx, int axisy)
  89. {
  90. clearBottom();
  91. createAxis(axisx,axisy);
  92. int x,y;
  93. for(x = 0; x < 128; x++ )
  94. {
  95. y = (int) (Math.sin(x)*2f) + 10;
  96. y = 31-y;
  97. IO.writeShort(0x42, 1 << 12 | x << 5 | y);
  98. IO.delay(10);
  99. }
  100. }
  101. //Private functions
  102. private static void createAxis(int x, int y)
  103. {
  104. y = 31-y;
  105. for(int x2 = 0; x2 < 128; x2++)
  106. {
  107. IO.writeShort(0x42, 1 << 12 | x2 << 5 | y );
  108. }
  109. for(int y2 = 0; y2 < 32; y2++)
  110. {
  111. IO.writeShort(0x42, 1 << 12 | x << 5 | y2 );
  112. }
  113. }
  114. private static void clearTop()
  115. {
  116. IO.writeShort(0x10, 0x100 | 0x0);
  117. IO.writeShort(0x12, 0x100 | 0x0);
  118. IO.writeShort(0x14, 0x100 | 0x0);
  119. IO.writeShort(0x16, 0x100 | 0x0);
  120. IO.writeShort(0x18, 0x100 | 0x0);
  121. }
  122. private static void clearLeft()
  123. {
  124. IO.writeShort(0x24, 0x100 | 0x0);
  125. IO.writeShort(0x22, 0x100 | 0x0);
  126. IO.writeShort(0x20, 0x100 | 0x0);
  127. }
  128. private static void clearRight()
  129. {
  130. IO.writeShort(0x34, 0x100 | 0x0);
  131. IO.writeShort(0x32, 0x100 | 0x0);
  132. IO.writeShort(0x30, 0x100 | 0x0);
  133. }
  134. private static void clearBottom()
  135. {
  136. IO.writeShort(0x40, 0xFE);
  137. IO.writeShort(0x40, 0x01);
  138. IO.writeShort(0x42, 3 << 12);
  139. }
  140. }