Parcourir la source

Added support for graphs

Also added small bits of code to center the name on the matrix display.
Kenneth van Ewijk il y a 11 ans
Parent
commit
eb3718cc0b
12 fichiers modifiés avec 311 ajouts et 171 suppressions
  1. 24 12
      AvgWindspeed.java
  2. 20 8
      CloudHeight.java
  3. 29 12
      GUIboard.java
  4. 4 0
      Grootheid.java
  5. 20 8
      InsideHum.java
  6. 20 8
      InsideTemp.java
  7. 20 8
      OutsideHum.java
  8. 20 8
      OutsideTemp.java
  9. 20 9
      RainRate.java
  10. 20 8
      UVLevel.java
  11. 93 81
      Weerstation.java
  12. 21 9
      WindChill.java

+ 24 - 12
AvgWindspeed.java

@@ -1,32 +1,44 @@
 import java.util.ArrayList;
 
-public class AvgWindspeed extends Grootheid{
+public class AvgWindSpeed extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
-    public AvgWindspeed(Measurement measurement1, ArrayList<Measurement> measurement2){
+    public AvgWindSpeed(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
+
     
     public void updateRecent(Measurement measurement1){
         setCurrent(measurement1.getAvgWindSpeed());
     }
-    
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getAvgWindSpeed());
+        }
+    }
 }

+ 20 - 8
CloudHeight.java

@@ -1,9 +1,11 @@
 import java.util.ArrayList;
 
 public class CloudHeight extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
     public CloudHeight(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,14 +15,7 @@ public class CloudHeight extends Grootheid{
         setCurrent(measurement1.getCloudHeight());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getCloudHeight());
+        }
+    }
 }

+ 29 - 12
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<centerLeft; i++)
+        {
+            IO.writeShort(0x40, ' ');
+        }
         for(char ch : regel1CharArray)
         {
             IO.writeShort(0x40, ch);
@@ -150,34 +158,43 @@ public class GUIboard {
     
     public static void writeGraphToMatrix(ArrayList<Double> 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<msList.size();i++)
         {
-            getal = msList.get(i);
-            x = ((i/1439)*127);
-            y = (int) ((getal - min)/(max-min))*31;
+            getal = msList.get((int)i);
+            x = (int)((i/msList.size())*127.0);
+            double temp = ((getal - min)/(max-min));
+            y = (int)(temp*31.0);
+            System.out.println(x + ", " + y + " <- " + getal + "/" + msList.size() + " " + 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 );

+ 4 - 0
Grootheid.java

@@ -83,4 +83,8 @@ public class Grootheid
         GUIboard.writeLeftDigits(getMax());
         GUIboard.writeRightDigits(getMin());
     }
+    
+    public void displayGraph()
+    {
+    }
 }

+ 20 - 8
InsideHum.java

@@ -1,9 +1,11 @@
 import java.util.ArrayList;
 
 public class InsideHum extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
     public InsideHum(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,14 +15,7 @@ public class InsideHum extends Grootheid{
         setCurrent(measurement1.getInsideHum());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getInsideHum());
+        }
+    }
 }

+ 20 - 8
InsideTemp.java

@@ -1,9 +1,11 @@
 import java.util.ArrayList;
 
 public class InsideTemp extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
     public InsideTemp(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,14 +15,7 @@ public class InsideTemp extends Grootheid{
         setCurrent(measurement1.getInsideTemp());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getInsideTemp());
+        }
+    }
 }

+ 20 - 8
OutsideHum.java

@@ -1,9 +1,11 @@
 import java.util.ArrayList;
 
 public class OutsideHum extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
     public OutsideHum(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,14 +15,7 @@ public class OutsideHum extends Grootheid{
         setCurrent(measurement1.getOutsideHum());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getOutsideHum());
+        }
+    }
 }

+ 20 - 8
OutsideTemp.java

@@ -1,9 +1,11 @@
 import java.util.ArrayList;
 
 public class OutsideTemp extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
     public OutsideTemp(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,14 +15,7 @@ public class OutsideTemp extends Grootheid{
         setCurrent(measurement1.getOutsideTemp());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getOutsideTemp());
+        }
+    }
 }

+ 20 - 9
RainRate.java

@@ -1,9 +1,10 @@
 import java.util.ArrayList;
 
 public class RainRate extends Grootheid{
-    
+    public ArrayList<Double> list;
     //constructor
     public RainRate(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,14 +14,7 @@ public class RainRate extends Grootheid{
         setCurrent(measurement1.getRainRate());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getRainRate());
+        }
+    }
 }

+ 20 - 8
UVLevel.java

@@ -1,9 +1,11 @@
 import java.util.ArrayList;
 
 public class UVLevel extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
     public UVLevel(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,14 +15,7 @@ public class UVLevel extends Grootheid{
         setCurrent(measurement1.getUVLevel());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getUVLevel());
+        }
+    }
 }

+ 93 - 81
Weerstation.java

@@ -6,86 +6,98 @@ import java.util.Timer;
 import java.util.TimerTask;
 
 public class Weerstation {
-	WeerstationConnector weerstation1;
-	Measurement meting1;
-	ArrayList<Measurement> 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<Measurement> 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<Grootheid> lstScreens = new ArrayList<Grootheid>();
-		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<Grootheid> lstScreens = new ArrayList<Grootheid>();
+        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);
+        
+    }
 }

+ 21 - 9
WindChill.java

@@ -1,9 +1,11 @@
 import java.util.ArrayList;
 
 public class WindChill extends Grootheid{
+    public ArrayList<Double> list;
     
     //constructor
     public WindChill(Measurement measurement1, ArrayList<Measurement> measurement2){
+        list = new ArrayList<Double>();
         updateRecent(measurement1);
         update24Hour(measurement2);
     }
@@ -13,20 +15,30 @@ public class WindChill extends Grootheid{
         setCurrent(measurement1.getWindChill());
     }
     public void update24Hour(ArrayList<Measurement> measurement2){
-        
-        ArrayList<Double> list = new ArrayList<Double>();
-        
-        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<Measurement> measurement2)
+    {
+        if(!list.isEmpty())
+        {
+            list.clear();
+        }
+        
+        for(Measurement ms : measurement2)
+        {
+            list.add(ms.getWindChill());
+        }
+    }
 }