Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Blame | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * Date: 2004-sep-09
  3.  * Time: 19:39:30
  4. */
  5.  
  6. package Macbeth.Modules.modTempFetcher;
  7.  
  8. import Macbeth.Utilities.UByte;
  9.  
  10.  
  11. /**
  12.  * Represents a sensor on a node
  13.  * (a node can have several sensors)
  14.  * @author arune
  15.  */
  16. public class TempSensor {
  17.  
  18.     public String name;
  19.     public UByte identByte;
  20.     public String logPath;
  21.     private int nrOfSamples;
  22.  
  23.     public boolean printToDisplay;
  24.  
  25.     //data-arrays, build a mean with those
  26.     private double[] tempData;
  27.     private int tempPointer = 0;
  28.  
  29.     public TempSensor(String name, UByte identByte, String logPath, int nrOfSamples, boolean printToDisplay) {
  30.         this.name = name;
  31.         this.identByte = identByte;
  32.         this.logPath = logPath;
  33.         this.nrOfSamples = nrOfSamples;
  34.         this.printToDisplay = printToDisplay;
  35.         tempData = new double[nrOfSamples];
  36.     }
  37.  
  38.     /**
  39.      *
  40.      * @param tempValue the value to be stored
  41.      * @return true if a mean can be calculated
  42.      */
  43.     public boolean addValue(double tempValue){
  44.  
  45.        //spara varden i array
  46.         tempData[tempPointer] = tempValue;
  47.         //uppdatera pekare
  48.         tempPointer = tempPointer + 1;
  49.         if (tempPointer == nrOfSamples) {
  50.             tempPointer = 0;
  51.             return true;
  52.         }
  53.         return false;
  54.     }
  55.  
  56.     public double getMean() {
  57.         double dummyVar = 0;
  58.         for (int i = 0; i < nrOfSamples; i++) {
  59.             dummyVar = dummyVar + tempData[i];
  60.         }
  61.  
  62.         return dummyVar/nrOfSamples;
  63.     }
  64.  
  65. }
  66.