From 0252061bc69c9a964c7d91f68cd80d4d99568362 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Fri, 17 Oct 2014 12:27:16 +0200 Subject: [PATCH] Added winddirection --- Weerstation.java | 10 +++-- WindDirection.java | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 WindDirection.java diff --git a/Weerstation.java b/Weerstation.java index 9c0dd72..948f64b 100644 --- a/Weerstation.java +++ b/Weerstation.java @@ -47,9 +47,9 @@ public class Weerstation { //All the different screen classes final List lstScreens = new ArrayList(); + lstScreens.add(new WindDirection(meting1, meting2)); lstScreens.add(new OutsideTemp(meting1, meting2)); lstScreens.add(new WindChill(meting1, meting2)); - lstScreens.add(new HeatIndex(meting1, meting2)); lstScreens.add(new OutsideHum(meting1, meting2)); lstScreens.add(new Barometer(meting1, meting2)); lstScreens.add(new AvgWindSpeed(meting1, meting2)); @@ -60,6 +60,7 @@ public class Weerstation { lstScreens.add(new UVLevel(meting1, meting2)); lstScreens.add(new Zonsterkte(meting1, meting2)); lstScreens.add(new DewPoint(meting1, meting2)); + lstScreens.add(new Sun(meting1)); @@ -91,7 +92,7 @@ public class Weerstation { meting1 = weerstation1.getMostRecentMeasurement(); for(Grootheid obj : lstScreens){ - obj.updateRecent(meting1); + obj.updateRecent(meting1); } } }, 60*1000, 60*1000); @@ -160,10 +161,11 @@ public class Weerstation { GUIboard.clearBottom(); - for(int i=0; i<128;i++) + for(int i=1; i<128;i+=2) { for(int n=0; n<32;n++) { + IO.writeShort(0x42, 1 << 12 | i-1 << 5 | n); IO.writeShort(0x42, 1 << 12 | i << 5 | n); IO.delay(1); } @@ -171,7 +173,7 @@ public class Weerstation { startup = false; } - }, 0, 64*2); + }, 0, 128*32); } public void stopAnimatie() diff --git a/WindDirection.java b/WindDirection.java new file mode 100644 index 0000000..2519259 --- /dev/null +++ b/WindDirection.java @@ -0,0 +1,91 @@ +import java.util.ArrayList; + +public class WindDirection extends Grootheid{ + public ArrayList list; + + //constructor + public WindDirection(Measurement measurement1, ArrayList measurement2){ + list = new ArrayList(); + updateRecent(measurement1); + update24Hour(measurement2); + } + + + public void updateRecent(Measurement measurement1){ + setCurrent(measurement1.getRawWindDir()); + } + public void update24Hour(ArrayList measurement2){ + createList(measurement2); + calculateMaxMinAvg(list); + } + + public void display(){ + super.display(); + GUIboard.writePageToMatrix("Windrichting", "Gemiddelde: " + getAvg(), ""); + } + + public void displayGraph() + { + GUIboard.writePageToMatrix("", "West East", ""); + + int x,y; + int radius = 15; + double degree= getCurrent(); + int x2 = 0; + int y2 = 0; + + degree -= 90; + + if( degree < 0){ + degree += 360; + } + + for(double i = 0; i< 360; i+= 1) + { + x = (int)(64 + (radius*Math.cos(i * Math.PI / 180))); + y = (int)(16 + radius*Math.sin(i * Math.PI / 180)); + System.out.println("x: " + x + " Y: " + y); + if(i == degree){ + x2 = x; + y2 = y; + } + IO.writeShort(0x42, 1 << 12 | x << 5 | y); + } + line(64, 16, x2, y2); + } + + public static void line(int x1,int y1,int x2, int y2) { + + if(x1 > x2) + { + int x3 = x1; + x1 = x2; + x2 = x3; + int y3 = y1; + y1 = y2; + y2 = y3; + } + + + int x,y; + int deltax = x2 - x1 ; + int deltay = y2 - y1 ; + for (x=x1; x<=x2; x++) { + y = y1 + deltay * (x - x1) / deltax; + IO.writeShort(0x42, 1 << 12 | x << 5 | y); + } + } + + private void createList(ArrayList measurement2) + { + if(!list.isEmpty()) + { + list.clear(); + } + + for(Measurement ms : measurement2) + { + list.add( (double)ms.getRawWindDir()); + } + } +}