Weerstation.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. lstScreens.add(new Sun(meting1));
  53. //Screen switcher
  54. timer.scheduleAtFixedRate(new TimerTask() {
  55. public void run() {
  56. if(!wait){
  57. currentScreen++;
  58. }
  59. if(currentScreen == lstScreens.size()){
  60. currentScreen = 0;
  61. }
  62. Grootheid obj = lstScreens.get(currentScreen);
  63. if(graph)
  64. {
  65. obj.displayGraph();
  66. }
  67. else
  68. {
  69. obj.display();
  70. }
  71. }
  72. }, 0, 5*1000);
  73. //Update recent measurement every 60 seconds
  74. timer.scheduleAtFixedRate(new TimerTask() {
  75. public void run() {
  76. meting1 = weerstation1.getMostRecentMeasurement();
  77. for(Grootheid obj : lstScreens){
  78. obj.updateRecent(meting1);
  79. }
  80. }
  81. }, 60*1000, 60*1000);
  82. //Update 24hours every 60 seconds
  83. timer.scheduleAtFixedRate(new TimerTask() {
  84. public void run() {
  85. meting2 = weerstation1.getAllMeasurementsLast24h();
  86. for(Grootheid obj : lstScreens){
  87. obj.update24Hour(meting2);
  88. }
  89. }
  90. }, 10*60*1000, 10*60*1000);
  91. //Button checker
  92. timer.scheduleAtFixedRate(new TimerTask() {
  93. public void run() {
  94. if(IO.readShort(0x100) == 1){
  95. if(IO.readShort(0x80) == 1){
  96. wait = true;
  97. if(!graph)
  98. {
  99. Grootheid obj = lstScreens.get(currentScreen);
  100. obj.displayGraph();
  101. }
  102. graph = true;
  103. }else if(IO.readShort(0x80) == 0){
  104. wait = false;
  105. if(graph)
  106. {
  107. Grootheid obj = lstScreens.get(currentScreen);
  108. obj.display();
  109. }
  110. graph = false;
  111. }
  112. }else if(IO.readShort(0x100) == 0){
  113. if(IO.readShort(0x80) == 1){
  114. if(!graph)
  115. {
  116. Grootheid obj = lstScreens.get(currentScreen);
  117. obj.displayGraph();
  118. }
  119. graph = true;
  120. }else if(IO.readShort(0x80) == 0){
  121. if(graph)
  122. {
  123. Grootheid obj = lstScreens.get(currentScreen);
  124. obj.display();
  125. }
  126. graph = false;
  127. }
  128. wait = true;
  129. }
  130. }
  131. }, 0, 100);
  132. }
  133. public void startAnimatie()
  134. {
  135. starter.scheduleAtFixedRate(new TimerTask() {
  136. public void run() {
  137. startup = true;
  138. GUIboard.clearBottom();
  139. for(int i=1; i<128;i+=2)
  140. {
  141. for(int n=0; n<32;n++)
  142. {
  143. IO.writeShort(0x42, 1 << 12 | i-1 << 5 | n);
  144. IO.writeShort(0x42, 1 << 12 | i << 5 | n);
  145. IO.delay(1);
  146. }
  147. }
  148. startup = false;
  149. }
  150. }, 0, 128*32);
  151. }
  152. public void stopAnimatie()
  153. {
  154. starter.cancel();
  155. }
  156. }