private class Barometer2438.ReadTask
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
private boolean |
initialize
Flag to initialize sensor.
|
private java.lang.String |
PRESSURE_NAME
Data name for pressure.
|
private double[] |
pValues
History of recent vdd - vad for RMS calculation.
|
private int |
pValuesIndex
History index.
|
private byte[] |
state
1-Wire device state.
|
private java.lang.String |
TEMPERATURE_NAME
Data name for temperature.
|
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 |
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 |
getRmsPressure()
Reads from the device until the vdd - vad RMS values are not greater
than 0.1 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 pressure and
temperature values from the DS2438 and posts them to the data
exchange.
|
private double |
toPressure(double vad)
Converts raw voltage to atmospheric pressure in millibars.
|
private final java.lang.String PRESSURE_NAME
private final java.lang.String TEMPERATURE_NAME
private final java.lang.String VALUE_ERROR_1
private final java.lang.String VALUE_ERROR_2
private boolean initialize
private final double[] pValues
private int pValuesIndex
private final double[] tValues
private int tValuesIndex
private byte[] state
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 getRmsPressure() throws com.dalsemi.onewire.OneWireException, ValueException
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
atmospheric pressure from one minute to the next, or during retries,
suggesting a channel crossover problem.private double deviation(double value)
value
- to evaluate.private double toPressure(double vad) throws ValueException
vad
- pressure sensor voltage.ValueException
- if the calculated value is not within 800 to
1100 millibars.
Based on
Atmospheric pressure From Wikipedia, the free encyclopedia:
The highest recorded atmospheric pressure, 108.6 kPa (1086 mbar or 32.06 inches of mercury), occurred at Tosontsengel, Mongolia, 19 December 2001.
The lowest recorded non-tornadic atmospheric pressure, 87.0 kPa (870 mbar or 25.69 inHg), occurred in the Western Pacific during Typhoon Tip on 12 October 1979. The record for the Atlantic ocean was 88.2 kPa (882 mbar or 26.04 inHg) during Hurricane Wilma on 19 October 2005.
private double getDeviceVoltage(int channel) throws com.dalsemi.onewire.OneWireException
channel
- address.com.dalsemi.onewire.OneWireException
- if a communication error occurs.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.