Weerstation.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import java.lang.reflect.InvocationTargetException;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Timer;
  5. import java.util.TimerTask;
  6. public class Weerstation {
  7. WeerstationConnector weerstation1;
  8. Measurement meting1;
  9. ArrayList<Measurement> meting2;
  10. Timer starter;
  11. int currentScreen;
  12. boolean wait;
  13. boolean graph;
  14. boolean startup;
  15. public Weerstation(){
  16. weerstation1 = new WeerstationConnector();
  17. GUIboard.init();
  18. starter = new Timer();
  19. startAnimatie();
  20. meting1 = weerstation1.getMostRecentMeasurement();
  21. meting2 = weerstation1.getAllMeasurementsLast24h();
  22. stopAnimatie();
  23. while(startup)
  24. {
  25. try
  26. {
  27. Thread.sleep(1);
  28. }
  29. catch(InterruptedException e)
  30. {
  31. e.printStackTrace();
  32. }
  33. }
  34. currentScreen = 0;
  35. wait = true;
  36. graph = false;
  37. Timer timer = new Timer();
  38. //All the different screen classes
  39. final List<Grootheid> lstScreens = new ArrayList<Grootheid>();
  40. lstScreens.add(new OutsideTemp(meting1, meting2));
  41. lstScreens.add(new WindChill(meting1, meting2));
  42. lstScreens.add(new OutsideHum(meting1, meting2));
  43. lstScreens.add(new Barometer(meting1, meting2));
  44. lstScreens.add(new AvgWindSpeed(meting1, meting2));
  45. lstScreens.add(new RainRate(meting1, meting2));
  46. lstScreens.add(new InsideTemp(meting1, meting2));
  47. lstScreens.add(new InsideHum(meting1, meting2));
  48. lstScreens.add(new CloudHeight(meting1, meting2));
  49. lstScreens.add(new UVLevel(meting1, meting2));
  50. lstScreens.add(new Zonsterkte(meting1, meting2));
  51. lstScreens.add(new DewPoint(meting1, meting2));
  52. //Screen switcher
  53. timer.scheduleAtFixedRate(new TimerTask() {
  54. public void run() {
  55. if(!wait){
  56. currentScreen++;
  57. }
  58. if(currentScreen == lstScreens.size()){
  59. currentScreen = 0;
  60. }
  61. Grootheid obj = lstScreens.get(currentScreen);
  62. if(graph)
  63. {
  64. obj.displayGraph();
  65. }
  66. else
  67. {
  68. obj.display();
  69. }
  70. }
  71. }, 0, 5*1000);
  72. //Update recent measurement every 60 seconds
  73. timer.scheduleAtFixedRate(new TimerTask() {
  74. public void run() {
  75. meting1 = weerstation1.getMostRecentMeasurement();
  76. for(Grootheid obj : lstScreens){
  77. obj.updateRecent(meting1);
  78. }
  79. }
  80. }, 60*1000, 60*1000);
  81. //Update 24hours every 60 seconds
  82. timer.scheduleAtFixedRate(new TimerTask() {
  83. public void run() {
  84. meting2 = weerstation1.getAllMeasurementsLast24h();
  85. for(Grootheid obj : lstScreens){
  86. obj.update24Hour(meting2);
  87. }
  88. }
  89. }, 10*60*1000, 10*60*1000);
  90. //Button checker
  91. timer.scheduleAtFixedRate(new TimerTask() {
  92. public void run() {
  93. if(IO.readShort(0x100) == 1){
  94. if(IO.readShort(0x80) == 1){
  95. wait = true;
  96. if(!graph)
  97. {
  98. Grootheid obj = lstScreens.get(currentScreen);
  99. obj.displayGraph();
  100. }
  101. graph = true;
  102. }else if(IO.readShort(0x80) == 0){
  103. wait = false;
  104. if(graph)
  105. {
  106. Grootheid obj = lstScreens.get(currentScreen);
  107. obj.display();
  108. }
  109. graph = false;
  110. }
  111. }else if(IO.readShort(0x100) == 0){
  112. if(IO.readShort(0x80) == 1){
  113. if(!graph)
  114. {
  115. Grootheid obj = lstScreens.get(currentScreen);
  116. obj.displayGraph();
  117. }
  118. graph = true;
  119. }else if(IO.readShort(0x80) == 0){
  120. if(graph)
  121. {
  122. Grootheid obj = lstScreens.get(currentScreen);
  123. obj.display();
  124. }
  125. graph = false;
  126. }
  127. wait = true;
  128. }
  129. }
  130. }, 0, 100);
  131. }
  132. public void startAnimatie()
  133. {
  134. starter.scheduleAtFixedRate(new TimerTask() {
  135. public void run() {
  136. startup = true;
  137. GUIboard.clearBottom();
  138. for(int i=0; i<128;i++)
  139. {
  140. for(int n=0; n<32;n++)
  141. {
  142. IO.writeShort(0x42, 1 << 12 | i << 5 | n);
  143. IO.delay(1);
  144. }
  145. }
  146. startup = false;
  147. }
  148. }, 0, 64*2);
  149. }
  150. public void stopAnimatie()
  151. {
  152. starter.cancel();
  153. }
  154. }