From 8f6ab9ebce6e5a701dfebbab9a1490e38e659611 Mon Sep 17 00:00:00 2001 From: jancoow Date: Mon, 6 Oct 2014 13:10:49 +0200 Subject: [PATCH] Janco's klasse van de windspeed, nog geen grafiek & matrixscherm --- Main.java | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Main.java diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..ad3d12a --- /dev/null +++ b/Main.java @@ -0,0 +1,73 @@ +package weerstation; + + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +public class Main { + static Weerstation weerstation1; + static Measurement meting1; + static ArrayList meting2; + + public static void main(String[] args){ + weerstation1 = new Weerstation(); + meting1 = weerstation1.getMostRecentMeasurement(); + meting2 = weerstation1.getAllMeasurementsLast24h(); + IO.init(); + Timer timer = new Timer(); + + //All the different screen classes + + final List lstScreens = new ArrayList(); + lstScreens.add(new AvgWindspeed(meting1, meting2, 1)); + + //Screen switcher + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + + } + }, 0, 15*1000); + + //Update recent measurement every 60 seconds + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + + meting1 = weerstation1.getMostRecentMeasurement(); + for(Object obj : lstScreens){ + try { + obj.getClass().getMethod("updateRecent", Measurement.class).invoke(obj, meting1 ); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + } + } + }, 60*1000, 60*1000); + + + //Update 24hours every 60 seconds + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + meting2 = weerstation1.getAllMeasurementsLast24h(); + for(Object obj : lstScreens){ + try { + obj.getClass().getMethod("update24Hour", ArrayList.class).invoke(obj, meting2 ); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + } + } + }, 10*60*1000, 10*60*1000); + + + //Button checker + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + + } + }, 0, 60*1000); + + } +}