GUIboard.java 4.5 KB

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