예제 #1
0
  public void run() {
    try {
      while (rhSensor.isOpened()) {
        byte[] data = null;
        data = rhSensor.readData();

        this.oldTemperature = this.temperature;

        setHumidity(Math.round(rhSensor.getHumidity(data) * 1e-4 * 100));
        setTemperature(Math.round(rhSensor.getTemperature(data) * 1e-2 - 273.15));

        if (this.first) {
          System.out.println("Première température :" + this.temperature);
          this.first = false;
        }

        if ((this.oldTemperature < 30) && (this.temperature >= 30)) {
          fireTemperatureEvent();
        }
        if ((this.oldTemperature > 27) && (this.temperature <= 27)) {
          fireTemperatureEvent();
        }

        Thread.sleep(time);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #2
0
 public TempHumSensor(int t, OakUsbRH rhSensor) {
   this.time = t;
   this.rhSensor = rhSensor;
   this.vectTempListener = new Vector<TemperatureListener>();
   this.first = true;
   try {
     rhSensor.openSensor();
     rhSensor.setReportMode(OakReportMode.REPORT_MODE_FIXED_RATE, OakMemoryMode.RAM);
     rhSensor.setReportRate(500, OakMemoryMode.RAM);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }