diff --git a/AvgWindspeed.java b/AvgWindspeed.java index 690a985..aa765df 100644 --- a/AvgWindspeed.java +++ b/AvgWindspeed.java @@ -1,32 +1,44 @@ import java.util.ArrayList; -public class AvgWindspeed extends Grootheid{ +public class AvgWindSpeed extends Grootheid{ + public ArrayList list; //constructor - public AvgWindspeed(Measurement measurement1, ArrayList measurement2){ + public AvgWindSpeed(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } + public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getAvgWindSpeed()); } - public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getAvgWindSpeed()); - } - + createList(measurement2); calculateMaxMinAvg(list); } public void display(){ super.display(); - GUIboard.writePageToMatrix("Windsnelheid in m/s", "Gemiddelde: " + getAvg(), ""); + GUIboard.writePageToMatrix("Gem. Windsnelheid", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getAvgWindSpeed()); + } + } } diff --git a/CloudHeight.java b/CloudHeight.java index 08d1ad8..7fd8a3b 100644 --- a/CloudHeight.java +++ b/CloudHeight.java @@ -1,9 +1,11 @@ import java.util.ArrayList; public class CloudHeight extends Grootheid{ + public ArrayList list; //constructor public CloudHeight(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,14 +15,7 @@ public class CloudHeight extends Grootheid{ setCurrent(measurement1.getCloudHeight()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getCloudHeight()); - } - + createList(measurement2); calculateMaxMinAvg(list); } @@ -29,4 +24,21 @@ public class CloudHeight extends Grootheid{ GUIboard.writePageToMatrix("Wolkhoogte", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getCloudHeight()); + } + } } diff --git a/GUIboard.java b/GUIboard.java index 383024e..0d66eb6 100644 --- a/GUIboard.java +++ b/GUIboard.java @@ -125,7 +125,15 @@ public class GUIboard { char[] regel1CharArray = regel1.toCharArray(); char[] regel2CharArray = regel2.toCharArray(); char[] regel3CharArray = (regel3 + nav).toCharArray(); - + + double centerMargins = 20-regel1CharArray.length; + int centerLeft = (int) Math.floor(centerMargins/2.0); + + + for(int i=0; i msList, double min, double max) { - IO.init(); clearBottom(); createAxis(min,max); int x,y; double getal; - for(int i=0;i<1440;i++) + for(double i=0;i " + temp); + y = 31 - y; IO.writeShort(0x42, 1 << 12 | x << 5 | y ); } } //Private functions - private static void createAxis(double min, double max) + public static void createAxis(double min, double max) { + //temp + int x,y; double diff = max-min; double valpix = diff/32; if(min<=0){ - y = (int) ( (diff-max) / valpix); - System.out.println(y); - y = 32 - y; - System.out.println(y); - + if(min==0) + { + y = 31; + } + else + { + y = (int) ( (diff-max) / valpix); + y = 31 - y; + System.out.println("Y: " + y); + } for(int x2 = 0; x2 < 128; x2++) { IO.writeShort(0x42, 1 << 12 | x2 << 5 | y ); diff --git a/Grootheid.java b/Grootheid.java index 05b504f..8e84335 100644 --- a/Grootheid.java +++ b/Grootheid.java @@ -83,4 +83,8 @@ public class Grootheid GUIboard.writeLeftDigits(getMax()); GUIboard.writeRightDigits(getMin()); } + + public void displayGraph() + { + } } diff --git a/InsideHum.java b/InsideHum.java index d57bc78..5bcea59 100644 --- a/InsideHum.java +++ b/InsideHum.java @@ -1,9 +1,11 @@ import java.util.ArrayList; public class InsideHum extends Grootheid{ + public ArrayList list; //constructor public InsideHum(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,14 +15,7 @@ public class InsideHum extends Grootheid{ setCurrent(measurement1.getInsideHum()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getInsideHum()); - } - + createList(measurement2); calculateMaxMinAvg(list); } @@ -29,4 +24,21 @@ public class InsideHum extends Grootheid{ GUIboard.writePageToMatrix("Luchtv. Binnen", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getInsideHum()); + } + } } diff --git a/InsideTemp.java b/InsideTemp.java index 85a1fd7..2e4310e 100644 --- a/InsideTemp.java +++ b/InsideTemp.java @@ -1,9 +1,11 @@ import java.util.ArrayList; public class InsideTemp extends Grootheid{ + public ArrayList list; //constructor public InsideTemp(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,14 +15,7 @@ public class InsideTemp extends Grootheid{ setCurrent(measurement1.getInsideTemp()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getInsideTemp()); - } - + createList(measurement2); calculateMaxMinAvg(list); } @@ -29,4 +24,21 @@ public class InsideTemp extends Grootheid{ GUIboard.writePageToMatrix("Binnentemperatuur", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getInsideTemp()); + } + } } diff --git a/OutsideHum.java b/OutsideHum.java index ea0b4b0..5642eb5 100644 --- a/OutsideHum.java +++ b/OutsideHum.java @@ -1,9 +1,11 @@ import java.util.ArrayList; public class OutsideHum extends Grootheid{ + public ArrayList list; //constructor public OutsideHum(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,14 +15,7 @@ public class OutsideHum extends Grootheid{ setCurrent(measurement1.getOutsideHum()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getOutsideHum()); - } - + createList(measurement2); calculateMaxMinAvg(list); } @@ -29,4 +24,21 @@ public class OutsideHum extends Grootheid{ GUIboard.writePageToMatrix("Luchtv. Buiten", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getOutsideHum()); + } + } } diff --git a/OutsideTemp.java b/OutsideTemp.java index f99570f..100a161 100644 --- a/OutsideTemp.java +++ b/OutsideTemp.java @@ -1,9 +1,11 @@ import java.util.ArrayList; public class OutsideTemp extends Grootheid{ + public ArrayList list; //constructor public OutsideTemp(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,14 +15,7 @@ public class OutsideTemp extends Grootheid{ setCurrent(measurement1.getOutsideTemp()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getOutsideTemp()); - } - + createList(measurement2); calculateMaxMinAvg(list); } @@ -29,4 +24,21 @@ public class OutsideTemp extends Grootheid{ GUIboard.writePageToMatrix("Buitentemperatuur", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getOutsideTemp()); + } + } } diff --git a/RainRate.java b/RainRate.java index fbee199..34badd1 100644 --- a/RainRate.java +++ b/RainRate.java @@ -1,9 +1,10 @@ import java.util.ArrayList; public class RainRate extends Grootheid{ - + public ArrayList list; //constructor public RainRate(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,14 +14,7 @@ public class RainRate extends Grootheid{ setCurrent(measurement1.getRainRate()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getRainRate()); - } - + createList(measurement2); calculateMaxMinAvg(list); } @@ -29,4 +23,21 @@ public class RainRate extends Grootheid{ GUIboard.writePageToMatrix("Regenval in mm/h", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getRainRate()); + } + } } diff --git a/UVLevel.java b/UVLevel.java index a2728d9..a0340b2 100644 --- a/UVLevel.java +++ b/UVLevel.java @@ -1,9 +1,11 @@ import java.util.ArrayList; public class UVLevel extends Grootheid{ + public ArrayList list; //constructor public UVLevel(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,14 +15,7 @@ public class UVLevel extends Grootheid{ setCurrent(measurement1.getUVLevel()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getUVLevel()); - } - + createList(measurement2); calculateMaxMinAvg(list); } @@ -29,4 +24,21 @@ public class UVLevel extends Grootheid{ GUIboard.writePageToMatrix("UV Level", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getUVLevel()); + } + } } diff --git a/Weerstation.java b/Weerstation.java index 00798c3..6d209d7 100644 --- a/Weerstation.java +++ b/Weerstation.java @@ -6,86 +6,98 @@ import java.util.Timer; import java.util.TimerTask; public class Weerstation { - WeerstationConnector weerstation1; - Measurement meting1; - ArrayList meting2; - int currentScreen; - boolean wait; - - public Weerstation(){ - weerstation1 = new WeerstationConnector(); - meting1 = weerstation1.getMostRecentMeasurement(); - meting2 = weerstation1.getAllMeasurementsLast24h(); - currentScreen = 0; - wait = true; - IO.init(); - Timer timer = new Timer(); + WeerstationConnector weerstation1; + Measurement meting1; + ArrayList meting2; + int currentScreen; + boolean wait; + boolean graph; + + public Weerstation(){ + weerstation1 = new WeerstationConnector(); + meting1 = weerstation1.getMostRecentMeasurement(); + meting2 = weerstation1.getAllMeasurementsLast24h(); + currentScreen = 0; + wait = true; + graph = false; + IO.init(); + Timer timer = new Timer(); - //All the different screen classes - - final List lstScreens = new ArrayList(); - lstScreens.add(new AvgWindspeed(meting1, meting2)); - lstScreens.add(new RainRate(meting1, meting2)); - lstScreens.add(new OutsideTemp(meting1, meting2)); - lstScreens.add(new InsideTemp(meting1, meting2)); - lstScreens.add(new OutsideHum(meting1, meting2)); - lstScreens.add(new InsideHum(meting1, meting2)); - lstScreens.add(new CloudHeight(meting1, meting2)); - lstScreens.add(new WindChill(meting1, meting2)); - lstScreens.add(new UVLevel(meting1, meting2)); - - - //Screen switcher - timer.scheduleAtFixedRate(new TimerTask() { - public void run() { - if(wait == false){ - currentScreen++; - } - if(currentScreen == lstScreens.size()){ - currentScreen = 0; - } - Grootheid obj = lstScreens.get(currentScreen); - obj.display(); - } - }, 0, 5*1000); - - //Update recent measurement every 60 seconds - timer.scheduleAtFixedRate(new TimerTask() { - public void run() { - - meting1 = weerstation1.getMostRecentMeasurement(); - for(Grootheid obj : lstScreens){ - obj.updateRecent(meting1); - } - } - }, 60*1000, 60*1000); - - - //Update 24hours every 60 seconds - timer.scheduleAtFixedRate(new TimerTask() { - public void run() { - meting2 = weerstation1.getAllMeasurementsLast24h(); - for(Grootheid obj : lstScreens){ - obj.update24Hour(meting2); - } - } - }, 10*60*1000, 10*60*1000); - - - //Button checker - timer.scheduleAtFixedRate(new TimerTask() { - public void run() { - if(IO.readShort(0x100) == 1){ - if(IO.readShort(0x80) == 1){ - wait = true; - }else if(IO.readShort(0x80) == 0){ - wait = false; - } - }else if(IO.readShort(0x100) == 0){ - wait = true; - } - } - }, 0, 100); - - } + //All the different screen classes + + final List lstScreens = new ArrayList(); + lstScreens.add(new AvgWindSpeed(meting1, meting2)); + lstScreens.add(new RainRate(meting1, meting2)); + lstScreens.add(new OutsideTemp(meting1, meting2)); + lstScreens.add(new InsideTemp(meting1, meting2)); + lstScreens.add(new OutsideHum(meting1, meting2)); + lstScreens.add(new InsideHum(meting1, meting2)); + lstScreens.add(new CloudHeight(meting1, meting2)); + lstScreens.add(new WindChill(meting1, meting2)); + lstScreens.add(new UVLevel(meting1, meting2)); + + + //Screen switcher + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + if(!wait){ + currentScreen++; + } + if(currentScreen == lstScreens.size()){ + currentScreen = 0; + } + + Grootheid obj = lstScreens.get(currentScreen); + if(graph) + { + obj.displayGraph(); + } + else + { + obj.display(); + } + } + }, 0, 5*1000); + + //Update recent measurement every 60 seconds + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + + meting1 = weerstation1.getMostRecentMeasurement(); + for(Grootheid obj : lstScreens){ + obj.updateRecent(meting1); + } + } + }, 60*1000, 60*1000); + + + //Update 24hours every 60 seconds + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + meting2 = weerstation1.getAllMeasurementsLast24h(); + for(Grootheid obj : lstScreens){ + obj.update24Hour(meting2); + } + } + }, 10*60*1000, 10*60*1000); + + + //Button checker + timer.scheduleAtFixedRate(new TimerTask() { + public void run() { + if(IO.readShort(0x100) == 1){ + if(IO.readShort(0x80) == 1){ + wait = true; + graph = true; + }else if(IO.readShort(0x80) == 0){ + wait = false; + graph = false; + } + }else if(IO.readShort(0x100) == 0){ + wait = true; + } + } + }, 0, 100); + + } } diff --git a/WindChill.java b/WindChill.java index e6b0e56..a52c63b 100644 --- a/WindChill.java +++ b/WindChill.java @@ -1,9 +1,11 @@ import java.util.ArrayList; public class WindChill extends Grootheid{ + public ArrayList list; //constructor public WindChill(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); updateRecent(measurement1); update24Hour(measurement2); } @@ -13,20 +15,30 @@ public class WindChill extends Grootheid{ setCurrent(measurement1.getWindChill()); } public void update24Hour(ArrayList measurement2){ - - ArrayList list = new ArrayList(); - - for(Measurement ms : measurement2) - { - list.add(ms.getWindChill()); - } - + createList(measurement2); calculateMaxMinAvg(list); } public void display(){ super.display(); - GUIboard.writePageToMatrix("Gevoelstemperatuur", "Gemiddelde: " + getAvg(), ""); + GUIboard.writePageToMatrix("Gevoelstemp", "Gemiddelde: " + getAvg(), ""); } + public void displayGraph() + { + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add(ms.getWindChill()); + } + } }