Weerstation.java 2.5 KB

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