Weerstation.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. int currentScreen;
  11. boolean wait;
  12. boolean graph;
  13. public Weerstation(){
  14. weerstation1 = new WeerstationConnector();
  15. meting1 = weerstation1.getMostRecentMeasurement();
  16. meting2 = weerstation1.getAllMeasurementsLast24h();
  17. currentScreen = 0;
  18. wait = true;
  19. graph = false;
  20. IO.init();
  21. Timer timer = new Timer();
  22. //All the different screen classes
  23. final List<Grootheid> lstScreens = new ArrayList<Grootheid>();
  24. lstScreens.add(new AvgWindSpeed(meting1, meting2));
  25. lstScreens.add(new RainRate(meting1, meting2));
  26. lstScreens.add(new OutsideTemp(meting1, meting2));
  27. lstScreens.add(new InsideTemp(meting1, meting2));
  28. lstScreens.add(new OutsideHum(meting1, meting2));
  29. lstScreens.add(new InsideHum(meting1, meting2));
  30. lstScreens.add(new CloudHeight(meting1, meting2));
  31. lstScreens.add(new WindChill(meting1, meting2));
  32. lstScreens.add(new UVLevel(meting1, meting2));
  33. //Screen switcher
  34. timer.scheduleAtFixedRate(new TimerTask() {
  35. public void run() {
  36. if(!wait){
  37. currentScreen++;
  38. }
  39. if(currentScreen == lstScreens.size()){
  40. currentScreen = 0;
  41. }
  42. Grootheid obj = lstScreens.get(currentScreen);
  43. if(graph)
  44. {
  45. obj.displayGraph();
  46. }
  47. else
  48. {
  49. obj.display();
  50. }
  51. }
  52. }, 0, 5*1000);
  53. //Update recent measurement every 60 seconds
  54. timer.scheduleAtFixedRate(new TimerTask() {
  55. public void run() {
  56. meting1 = weerstation1.getMostRecentMeasurement();
  57. for(Grootheid obj : lstScreens){
  58. obj.updateRecent(meting1);
  59. }
  60. }
  61. }, 60*1000, 60*1000);
  62. //Update 24hours every 60 seconds
  63. timer.scheduleAtFixedRate(new TimerTask() {
  64. public void run() {
  65. meting2 = weerstation1.getAllMeasurementsLast24h();
  66. for(Grootheid obj : lstScreens){
  67. obj.update24Hour(meting2);
  68. }
  69. }
  70. }, 10*60*1000, 10*60*1000);
  71. //Button checker
  72. timer.scheduleAtFixedRate(new TimerTask() {
  73. public void run() {
  74. if(IO.readShort(0x100) == 1){
  75. if(IO.readShort(0x80) == 1){
  76. wait = true;
  77. graph = true;
  78. }else if(IO.readShort(0x80) == 0){
  79. wait = false;
  80. graph = false;
  81. }
  82. }else if(IO.readShort(0x100) == 0){
  83. wait = true;
  84. }
  85. }
  86. }, 0, 100);
  87. }
  88. }