Преглед на файлове

Fixed the fucked up shit

Kenneth van Ewijk преди 11 години
родител
ревизия
d7375205ee
променени са 7 файла, в които са добавени 199 реда и са изтрити 86 реда
  1. 56 73
      Calculator.java
  2. 1 1
      Measurement.java
  3. 24 2
      Periode.java
  4. 12 0
      README.TXT
  5. 14 8
      Weerstation.java
  6. 1 2
      WeerstationConnector.java
  7. 91 0
      WindDirection.java

+ 56 - 73
Calculator.java

@@ -1,23 +1,23 @@
   
 
 public class Calculator {
-    
-    // Luchtdruk in hPa
-    // Malek&Tom
-    public static double luchtdruk(short mval)
+	
+	// Luchtdruk in hPa
+	// Malek&Tom
+	public static double luchtdruk(short mval)
     {
         double luchtdruk = (mval / 1000f) * 33.86389;
         return luchtdruk;
     }
-    
-    // Temperatuur in graden Celcius
+	
+	// Temperatuur in graden Celcius
     // Malek&Tom
     public static double temperatuur(short mval)
     {
         double temperatuur = (((double)mval / 10) -32) / 1.8;
         return temperatuur;
     }
-    
+	
     // Relatieve luchtvochtigheid in %
     // Malek&Tom
     public static double luchtVochtigheid(short mval)
@@ -27,15 +27,15 @@ public class Calculator {
     }
     
     // Windsnelheid in m/s
-    // Janco&Tim
-    public static double windSnelheid(short mval)
-    {
-        double windSpeed = mval * 0.44704;
-        return windSpeed;
-    }
-    
-    // Windrichting in noord, oost, zuid en west. 
-    // Kenneth&Daniël
+	// Janco&Tim
+	public static double windSnelheid(short mval)
+	{
+		double windSpeed = mval * 0.44704;
+		return windSpeed;
+	}
+	
+	// Windrichting in noord, oost, zuid en west. 
+	// Kenneth&Daniël
     public static String windRichting(short mval)
     {
         String direction = "Error";
@@ -111,16 +111,16 @@ public class Calculator {
         
         return direction;
     }
-    
+	
     // Regenmeter in mm
     // Kenneth&Daniël
     public static double regenmeter(short mval)
-    {
-        double rainAmount = (double)mval*0.2;
-        return rainAmount;
-    }
+	{
+    	double rainAmount = (double)mval*0.2;
+    	return rainAmount;
+	}
     
-    // uvIndex in index    
+	// uvIndex in index    
     // Kenneth&Daniël
     public static double uvIndex(short mval)
     {
@@ -131,37 +131,37 @@ public class Calculator {
     // BatterySpanning in Volt
     // Janco&Tim
     public static double batterySpanning(short mval){
-        double voltage = (((double)mval * 300)/512)/100;
-        return voltage; 
-    }
-    
+		double voltage = (((double)mval * 300)/512)/100;
+    	return voltage; 
+	}
+	
     // sunRise en Sunset in tijdformaat hh:mm
-    // Janco&Tim
+	// Janco&Tim
     public static String sunRise(short mval){
-        return sun(mval);
+    	return sun(mval);
     }
     public static String sunSet(short mval){
-        return sun(mval);
+    	return sun(mval);
     }
-    private static String sun(short sunRaw){
-        String tijd = "";
-        for(int i = 0; i <= 3; i++){
-            tijd = sunRaw % 10 + tijd;
-            sunRaw /= 10;
-            if(i == 1){             
-                tijd = ":" + tijd;
-            }
-        }
-        return tijd;
-    }
-    
-    public static double solarRad(short mval){
-        double zonSterkte = mval;
-        return zonSterkte;
+	private static String sun(short sunRaw){
+		String tijd = "";
+		for(int i = 0; i <= 3; i++){
+			tijd = sunRaw % 10 + tijd;
+			sunRaw /= 10;
+			if(i == 1){				
+				tijd = ":" + tijd;
+			}
+		}
+		return tijd;
+	}
+	
+	public static double solarRad(short mval){
+	    double zonSterkte = mval;
+    	return zonSterkte;
     }
 
     //windchill in graden Celcius
-    //Janco en Keneth
+	//Janco en Keneth
     public static double windChill(short grdnFh, short mph)
     {
         double gradenFahrenheit = grdnFh;
@@ -172,29 +172,12 @@ public class Calculator {
     }
     
     //Heatindex in celcius
-    //Tom met Malek
-    public static double heatIndex(short RH, short T2)
-    {        
-            double T = T2/10;
-            double HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH;
-                
-            if (RH < 13 && T < 112 && T > 80)
-            {
-                HI =- ((13-RH)/4)*Math.sqrt((17-Math.abs(T-95.))/17);
-            }
-            
-            if (RH > 85 && T < 87 && T > 80)
-            {
-                HI =+ ((RH-85)/10) * ((87-T)/5);
-            }
-            
-            if (T > 80)
-            {
-                HI = 0.5 * (T + 61.0 + ((T-68.0)*1.2) + (RH*0.094));
-            }
-            
-            double heatindex = Calculator.temperatuur( (short) (HI*10) );   
-            return heatindex;     
+	//Tom met Malek
+    public static double heatIndex(double RH, double T)
+    {
+        double HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH;
+        double heatindex = Calculator.temperatuur( (short) (HI*10) );
+        return heatindex;
     }
     
     //Dauwpunt in Celcius
@@ -205,11 +188,11 @@ public class Calculator {
        double dauwpunt = Math.pow( hm, (1/8f)) * (112 + 0.9*omgevingsTemp) + (0.1*omgevingsTemp) - 112;
        return dauwpunt;
     }
-    
+	
     public static double cloudHeight(double temp, short luchtVochtigheid ){
-        
-        double wolkhoogte = 125 * (temp-dewPoint(temp, luchtVochtigheid));
-        return wolkhoogte; 
-    }    
+    	
+    	double wolkhoogte = 125 * (temp-dewPoint(temp, luchtVochtigheid));
+    	return wolkhoogte; 
+	}    
 
 }

+ 1 - 1
Measurement.java

@@ -88,7 +88,7 @@ public class Measurement
     // solarRad
     public void setRawSolarRad (short val) { this.solarRad = val;};
     public short getRawSolarRad () { return solarRad; };
-    public double getSolarRad () {return Calculator.solarRad(solarRad);}
+    public double getSolarRad () { return Calculator.solarRad(solarRad); };
     
 
     // xmitBatt

+ 24 - 2
Periode.java

@@ -1,7 +1,29 @@
+import java.util.GregorianCalendar;
+
 public class Periode
 {
+    public GregorianCalendar beginPeriode;
+    public GregorianCalendar eindePeriode;
+    
     public Periode()
     {
-
     }
-}
+    
+    public Periode(int jaar, int maand, int dag, int eindjaar, int eindmaand, int einddag)
+    {
+        beginPeriode = new GregorianCalendar();
+        eindePeriode = new GregorianCalendar();
+        beginPeriode.set(jaar, maand, dag,0,0,0);
+        eindePeriode.set(eindjaar, eindmaand, einddag,23,59,59);
+    }
+    
+    public GregorianCalendar getBeginPeriode()
+    {
+        return beginPeriode;
+    }
+    
+    public GregorianCalendar getEindePeriode()
+    {
+        return eindePeriode;
+    }
+}

+ 12 - 0
README.TXT

@@ -0,0 +1,12 @@
+------------------------------------------------------------------------
+This is the project README file. Here, you should describe your project.
+Tell the reader (someone who does not know anything about this project)
+all he/she needs to know. The comments should usually include at least:
+------------------------------------------------------------------------
+
+PROJECT TITLE:
+PURPOSE OF PROJECT:
+VERSION or DATE:
+HOW TO START THIS PROJECT:
+AUTHORS:
+USER INSTRUCTIONS:

+ 14 - 8
Weerstation.java

@@ -4,10 +4,13 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.Calendar;
 
 public class Weerstation {
     WeerstationConnector weerstation1;
+    Calendar now;
     Measurement meting1;
+    Periode periodeDag;
     ArrayList<Measurement> meting2;
     Timer starter;
     int currentScreen;
@@ -17,13 +20,16 @@ public class Weerstation {
     
     public Weerstation(){
         weerstation1 = new WeerstationConnector();
+        now = Calendar.getInstance();
+        
+        periodeDag = new Periode(Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_MONTH,Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_MONTH);
         
         GUIboard.init();
         starter = new Timer();
         startAnimatie();
         
         meting1 = weerstation1.getMostRecentMeasurement();
-        meting2 = weerstation1.getAllMeasurementsLast24h();
+        meting2 = weerstation1.getAllMeasurementsBetween(periodeDag.getBeginPeriode(), periodeDag.getEindePeriode());
         
         stopAnimatie();
         while(startup)
@@ -46,14 +52,12 @@ public class Weerstation {
 
         //All the different screen classes
     
-        final List<Grootheid> lstScreens = new ArrayList<Grootheid>();        
-            
+        final List<Grootheid> lstScreens = new ArrayList<Grootheid>();
+        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 Voorspellingen(meting1));
         lstScreens.add(new AvgWindSpeed(meting1, meting2));
         lstScreens.add(new RainRate(meting1, meting2));
         lstScreens.add(new InsideTemp(meting1, meting2));
@@ -62,6 +66,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));
         
         
         
@@ -93,7 +98,7 @@ public class Weerstation {
                 
                 meting1 = weerstation1.getMostRecentMeasurement();
                 for(Grootheid obj : lstScreens){
-                    obj.updateRecent(meting1);                    
+                    obj.updateRecent(meting1);
                 }
             }
         }, 60*1000, 60*1000);
@@ -162,10 +167,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);
                     }
@@ -173,7 +179,7 @@ public class Weerstation {
                 
                 startup = false;
             }
-        }, 0, 64*2);
+        }, 0, 128*32);
     }
     
     public void stopAnimatie()

+ 1 - 2
WeerstationConnector.java

@@ -25,7 +25,6 @@ public class WeerstationConnector
     //Start connection with Databse
     public WeerstationConnector(String host, String port, String dbName, String userName, String password)
     {
-        System.out.println("Verbinding maken met de database...\n");
         try
         {
             String url = "jdbc:mysql://" + host + ":" + port + "/"+ dbName + "?user="
@@ -34,7 +33,7 @@ public class WeerstationConnector
             + password;
             Class.forName("com.mysql.jdbc.Driver").newInstance ();
             myConn = DriverManager.getConnection(url);
-            System.out.println("Verbonden met de database");
+            System.out.println("Database connection established");
         }
         catch( SQLException ex)
         {

+ 91 - 0
WindDirection.java

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