private class Hygrometer.ReadTask
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
AUTO_RANGING_SLOPE
Legend for auto-ranging slope.
|
private java.lang.String |
AUTO_RANGING_ZERO
Legend for auto-ranging zero offset.
|
private double |
C1
Constant C1 for calculating dewpoint.
|
private double |
C2
Constant C2 for calculating dewpoint.
|
private double |
C3
Constant C3 for calculating dewpoint.
|
private double |
C4
Constant C4 for calculating dewpoint.
|
private double |
C5
Constant C5 for calculating dewpoint.
|
private double |
CK_OFFSET
Offset between Celsius and Kelvin.
|
private java.lang.String |
DEWPOINT_NAME
Data name.
|
private java.lang.String |
HUMIDITY_NAME
Data name.
|
private double[] |
hValues
Humidity values for RMS calculation.
|
private int |
hValuesIndex
Humidity values index.
|
private boolean |
initialize
Flag to initialize sensor.
|
private java.lang.String |
SOLAR_INTENSITY_NAME
Data name.
|
private byte[] |
state
1-Wire device state.
|
private double[] |
sValues
Solar values for RMS calculation.
|
private int |
sValuesIndex
Solar values index.
|
private double[] |
TC0
Zeroth order temperature compensation constants (for t > 0, t < 0).
|
private double[] |
TC1
First order temperature compensation constants (for t > 0, t < 0).
|
private double[] |
TC2
Second order temperature compensation constants (for t > 0, t < 0).
|
private java.lang.String |
TEMPERATURE_NAME
Data name.
|
private double[] |
tValues
Temperature values for RMS calculation.
|
private int |
tValuesIndex
Temperature values index.
|
private java.lang.String |
VALUE_ERROR_1
Value error message format for out of range exceptions.
|
private java.lang.String |
VALUE_ERROR_2
Value error message format for out of range exceptions.
|
Modifier | Constructor and Description |
---|---|
private |
ReadTask() |
Modifier and Type | Method and Description |
---|---|
private double |
calcDewpoint(double rh,
double tk)
Calculates the dewpoint based on the ambient temperature expressed in
Kelvin and humidity expressed as a simple ratio.
|
private double |
calculateDewpoint(double humidity,
double temp)
Calculates the dewpoint.
|
private double |
checkRange(double humidity)
Checks for humidity value in range and auto-ranges Slope and Vzero.
|
private double |
deviation(double value)
Calculates the maximum deviation in the sample history looking for
outliers due to an invalid response from the sensor.
|
private double |
getDeviceTemperature()
Reads the temperature from the device.
|
private double |
getDeviceVoltage(int channel)
Reads the current voltage on the specified channel.
|
private double |
getRmsHumidity(double temp)
Reads from the device until the vdd - vad RMS values are not greater
than 0.1 standard deviation.
|
private double |
getRmsSolarIntensity()
Reads the solar intensity from the device until the RMS values are
not greater than one standard deviation.
|
private double |
getRmsTemperature()
Spins reading the temperature until the RMS values are not greater
than a standard deviation of one degree Celsius.
|
private void |
initDevice()
Initializes the sensor for operation.
|
void |
run()
Initializes the DS2438 if necessary, then gets the humidity,
temperature and dew point values from the DS2438 and posts them to
the data exchange.
|
private double |
tCompHumidity(double humidity,
double temp)
Temperature-compensate humidity value.
|
private double |
vCompHumidity(double vdd,
double vad)
Voltage-compensate raw humidity value.
|
private final java.lang.String HUMIDITY_NAME
private final java.lang.String TEMPERATURE_NAME
private final java.lang.String DEWPOINT_NAME
private final java.lang.String SOLAR_INTENSITY_NAME
private final java.lang.String AUTO_RANGING_SLOPE
private final java.lang.String AUTO_RANGING_ZERO
private final java.lang.String VALUE_ERROR_1
private final java.lang.String VALUE_ERROR_2
private final double C1
private final double C2
private final double C3
private final double C4
private final double C5
private final double CK_OFFSET
private final double[] TC0
private final double[] TC1
private final double[] TC2
private boolean initialize
private byte[] state
private final double[] hValues
private int hValuesIndex
private final double[] sValues
private int sValuesIndex
private final double[] tValues
private int tValuesIndex
public void run()
run
in interface java.lang.Runnable
private void initDevice() throws com.dalsemi.onewire.OneWireException, ServiceException
com.dalsemi.onewire.OneWireException
- if 1-Wire communication fails.ServiceException
- if initialization fails.private double getRmsHumidity(double temp) throws com.dalsemi.onewire.OneWireException, ValueException
temp
- for temperature compensation.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ValueException
- if the value is out of range. The acceptable
range for Vdd is 3 volts to 5.8 volts. Other values suggest channel
crossover, or power supply problems. RMS deviation > 0.1 is more
than a 10% change, greater than any normally expected change due to
humidity from one minute to the next, or during retries.private double deviation(double value)
value
- to check.private double getRmsSolarIntensity() throws com.dalsemi.onewire.OneWireException, ValueException
com.dalsemi.onewire.OneWireException
- if access fails.ValueException
- if timeout occurs waiting for RMS readings to
converge.private double getDeviceVoltage(int channel) throws com.dalsemi.onewire.OneWireException
channel
- address.com.dalsemi.onewire.OneWireException
- if a communication error occurs.private double vCompHumidity(double vdd, double vad)
vdd
- sensor supply voltage from the A/D converter.vad
- sensor output voltage from the A/D converter.private double tCompHumidity(double humidity, double temp)
humidity
- voltage-compensated humidity value.temp
- sensor temperature degrees Celsius.private double checkRange(double humidity) throws ValueException
Offset errors use the following correction for humidity < 0:
Vzero = ((Slope * SensorRH) + Vzero) - (Slope * ReferenceRH)where ReferenceRH is zero in this case.
Range errors use the following correction for humidity > 100:
Slope = Slope * SensorRH / ReferenceRHwhere ReferenceRH is 100% in this case.
humidity
- to check.ValueException
- if humidity < 0 or humidity > 100.private double getRmsTemperature() throws com.dalsemi.onewire.OneWireException, ValueException
com.dalsemi.onewire.OneWireException
- if 1-Wire communication fails.ValueException
- if timeout occurs waiting for RMS readings to
converge.private double getDeviceTemperature() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if 1-Wire communication fails.private double calculateDewpoint(double humidity, double temp)
humidity
- relative humidity (percent).temp
- ambient temperature (Celsius).private double calcDewpoint(double rh, double tk)
saturation vapor pressure es
es = exp(C5 - C1*tk - C2/tk)vapor pressure ee
ee = RH*esintermediate variable bb
bb = C5 - ln(ee)dewpoint temperature tkd
tkd = (bb - sqrt(bb^2 - C3))/C4where
rh
- relative humidity (ratio).tk
- ambient temperature (Kelvin).