Weerstation.java 5.7 KB

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