private class WindVane.ReadTask
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Integer,java.lang.Integer> |
CARDINAL_POINTS
Map of encoded channels to cardinal points.
|
private boolean[] |
CHANNELS
DS2450 A/D channels (0 - 3, A - D respectively) to convert.
|
private java.lang.String |
DATA_NAME
Data name.
|
private int |
EIGHT_BITS_INDEX
Index into resolutions array for eight bit resolution.
|
private int |
FIVE_VOLTS_INDEX
Index into range array for five volt range.
|
private boolean |
initialize
Flag to initialize sensor.
|
private int[] |
LEVELS_A
Channel A x 3^0 weighted key levels indexed by voltage.
|
private int[] |
LEVELS_B
Channel B x 3^1 weighted key levels indexed by voltage.
|
private int[] |
LEVELS_C
Channel C x 3^2 weighted key levels indexed by voltage.
|
private int[] |
LEVELS_D
Channel D x 3^3 weighted key levels indexed by voltage.
|
private byte[] |
state
1-Wire device state.
|
Modifier | Constructor and Description |
---|---|
private |
ReadTask() |
Modifier and Type | Method and Description |
---|---|
private double[] |
getDeviceVoltage()
Reads the windvane A/D converters.
|
private int |
getDirection()
Reads the current wind direction.
|
private void |
initDevice()
Initializes the sensor for operation.
|
void |
run()
Initializes the DS2450 wind vane if necessary, then gets the wind
direction value from the DS2450 wind vane and posts it to the data
exchange.
|
private int |
toPoint(double[] values)
Converts A/D output voltage level patterns to cardinal points.
|
private final java.lang.String DATA_NAME
private final boolean[] CHANNELS
private final int[] LEVELS_A
private final int[] LEVELS_B
private final int[] LEVELS_C
private final int[] LEVELS_D
private final int FIVE_VOLTS_INDEX
private final int EIGHT_BITS_INDEX
private boolean initialize
private byte[] state
private final java.util.Map<java.lang.Integer,java.lang.Integer> CARDINAL_POINTS
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 int getDirection() throws com.dalsemi.onewire.OneWireException, ValueException
com.dalsemi.onewire.OneWireException
- if access fails.ValueException
- if invalid data pattern is detected.private double[] getDeviceVoltage() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if a comm error occurs.private int toPoint(double[] values) throws ValueException
CARDINAL_POINTS.put(Integer.parseInt("0200", 3), 0); // N CARDINAL_POINTS.put(Integer.parseInt("0220", 3), 1); // NNE CARDINAL_POINTS.put(Integer.parseInt("0020", 3), 2); // NE CARDINAL_POINTS.put(Integer.parseInt("0022", 3), 3); // ENE CARDINAL_POINTS.put(Integer.parseInt("0002", 3), 4); // E CARDINAL_POINTS.put(Integer.parseInt("1002", 3), 5); // ESE CARDINAL_POINTS.put(Integer.parseInt("1000", 3), 6); // SE CARDINAL_POINTS.put(Integer.parseInt("1100", 3), 7); // SSE CARDINAL_POINTS.put(Integer.parseInt("0100", 3), 8); // S CARDINAL_POINTS.put(Integer.parseInt("0110", 3), 9); // SSW CARDINAL_POINTS.put(Integer.parseInt("0010", 3), 10); // SW CARDINAL_POINTS.put(Integer.parseInt("0011", 3), 11); // WSW CARDINAL_POINTS.put(Integer.parseInt("0001", 3), 12); // W CARDINAL_POINTS.put(Integer.parseInt("2001", 3), 13); // WNW CARDINAL_POINTS.put(Integer.parseInt("2000", 3), 14); // NW CARDINAL_POINTS.put(Integer.parseInt("2200", 3), 15); // NNWThis encoding scheme minimizes the dead space in the map. Referring to the schematic diagram for the "classic" Dallas 1-Wire Weather Station, '0' corresponds to an open (inactive) switch. '2' corresponds to switches S3, S2, S1 or S8 closed (active). '1' corresponds to S7, S6, S5 or S4 closed (active).
values
- raw A/D voltage output.ValueException
- if the the CARDINAL_POINTS map doesn't contain
the generated key.