Package com.dalsemi.onewire.container
Interface TemperatureContainer
-
- All Superinterfaces:
OneWireSensor
- All Known Implementing Classes:
OneWireContainer10
,OneWireContainer21
,OneWireContainer22
,OneWireContainer26
,OneWireContainer28
,OneWireContainer30
,OneWireContainer41
,OneWireContainer42
public interface TemperatureContainer extends OneWireSensor
1-Wire temperature interface class for basic temperature measuring operations. This class should be implemented for each temperature type 1-Wire device.The TemperatureContainer methods can be organized into the following categories:
- Information
- Options
- I/O
Usage
-
Example 1
Display some features of TemperatureContainer instance 'tc
':// Read High and Low Alarms if (!tc.hasTemperatureAlarms()) System.out.println("Temperature alarms not supported"); else { byte[] state = tc.readDevice(); double alarmLow = tc.getTemperatureAlarm(TemperatureContainer.ALARM_LOW, state); double alarmHigh = tc.getTemperatureAlarm(TemperatureContainer.ALARM_HIGH, state); System.out.println("Alarm: High = " + alarmHigh + ", Low = " + alarmLow); } }
Example 2
Gets temperature reading from a TemperatureContainer instance 'tc
':double lastTemperature; // get the current resolution and other settings of the device (done only once) byte[] state = tc.readDevice(); do // loop to read the temp { // perform a temperature conversion tc.doTemperatureConvert(state); // read the result of the conversion state = tc.readDevice(); // extract the result out of state lastTemperature = tc.getTemperature(state); ... }while (!done);
// get the current resolution of the device byte [] state = tc.readDevice(); // set the trips tc.setTemperatureAlarm(TemperatureContainer.ALARM_HIGH, 50, state); tc.setTemperatureAlarm(TemperatureContainer.ALARM_LOW, 20, state); tc.writeDevice(state); do // loop on conversions until an alarm occurs { tc.doTemperatureConvert(state); } while (!tc.isAlarming());
Example 3
Sets the temperature resolution of a TemperatureContainer instance 'tc
':byte[] state = tc.readDevice(); if (tc.hasSelectableTemperatureResolution()) { double[] resolution = tc.getTemperatureResolutions(); tc.setTemperatureResolution(resolution [resolution.length - 1], state); tc.writeDevice(state); }
-
-
Field Summary
Fields Modifier and Type Field Description static int
ALARM_HIGH
high temperature alarmstatic int
ALARM_LOW
low temperature alarm
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
doTemperatureConvert(byte[] state)
Performs a temperature conversion.double
getMaxTemperature()
Gets the maximum temperature in Celsius.double
getMinTemperature()
Gets the minimum temperature in Celsius.double
getTemperature(byte[] state)
Gets the temperature value in Celsius from thestate
data retrieved from thereadDevice()
method.double
getTemperatureAlarm(int alarmType, byte[] state)
Gets the specified temperature alarm value in Celsius from thestate
data retrieved from thereadDevice()
method.double
getTemperatureAlarmResolution()
Gets the temperature alarm resolution in Celsius.double
getTemperatureResolution(byte[] state)
Gets the current temperature resolution in Celsius from thestate
data retrieved from thereadDevice()
method.double[]
getTemperatureResolutions()
Get an array of available temperature resolutions in Celsius.boolean
hasSelectableTemperatureResolution()
Checks to see if this device has selectable temperature resolution.boolean
hasTemperatureAlarms()
Checks to see if this temperature measuring device has high/low trip alarms.void
setTemperatureAlarm(int alarmType, double alarmValue, byte[] state)
Sets the temperature alarm value in Celsius in the providedstate
data.void
setTemperatureResolution(double resolution, byte[] state)
Sets the current temperature resolution in Celsius in the providedstate
data.-
Methods inherited from interface com.dalsemi.onewire.container.OneWireSensor
readDevice, writeDevice
-
-
-
-
Field Detail
-
ALARM_HIGH
static final int ALARM_HIGH
high temperature alarm- See Also:
- Constant Field Values
-
ALARM_LOW
static final int ALARM_LOW
low temperature alarm- See Also:
- Constant Field Values
-
-
Method Detail
-
hasTemperatureAlarms
boolean hasTemperatureAlarms()
Checks to see if this temperature measuring device has high/low trip alarms.- Returns:
true
if thisTemperatureContainer
has high/low trip alarms- See Also:
getTemperatureAlarm(int, byte[])
,setTemperatureAlarm(int, double, byte[])
-
hasSelectableTemperatureResolution
boolean hasSelectableTemperatureResolution()
Checks to see if this device has selectable temperature resolution.- Returns:
true
if thisTemperatureContainer
has selectable temperature resolution- See Also:
getTemperatureResolution(byte[])
,getTemperatureResolutions()
,setTemperatureResolution(double, byte[])
-
getTemperatureResolutions
double[] getTemperatureResolutions()
Get an array of available temperature resolutions in Celsius.- Returns:
- byte array of available temperature resolutions in Celsius with minimum resolution as the first element and maximum resolution as the last element.
- See Also:
hasSelectableTemperatureResolution()
,getTemperatureResolution(byte[])
,setTemperatureResolution(double, byte[])
-
getTemperatureAlarmResolution
double getTemperatureAlarmResolution() throws OneWireException
Gets the temperature alarm resolution in Celsius.- Returns:
- temperature alarm resolution in Celsius for this 1-wire device
- Throws:
OneWireException
- Device does not support temperature alarms- See Also:
hasTemperatureAlarms()
,getTemperatureAlarm(int, byte[])
,setTemperatureAlarm(int, double, byte[])
-
getMaxTemperature
double getMaxTemperature()
Gets the maximum temperature in Celsius.- Returns:
- maximum temperature in Celsius for this 1-wire device
-
getMinTemperature
double getMinTemperature()
Gets the minimum temperature in Celsius.- Returns:
- minimum temperature in Celsius for this 1-wire device
-
doTemperatureConvert
void doTemperatureConvert(byte[] state) throws OneWireIOException, OneWireException
Performs a temperature conversion.- Parameters:
state
- byte array with device state information- Throws:
OneWireException
- Part could not be found [ fatal ]OneWireIOException
- Data wasn't transferred properly [ recoverable ]
-
getTemperature
double getTemperature(byte[] state) throws OneWireIOException
Gets the temperature value in Celsius from thestate
data retrieved from thereadDevice()
method.- Parameters:
state
- byte array with device state information- Returns:
- temperature in Celsius from the last
doTemperatureConvert()
- Throws:
OneWireIOException
- In the case of invalid temperature data
-
getTemperatureAlarm
double getTemperatureAlarm(int alarmType, byte[] state) throws OneWireException
Gets the specified temperature alarm value in Celsius from thestate
data retrieved from thereadDevice()
method.- Parameters:
alarmType
- valid value:ALARM_HIGH
orALARM_LOW
state
- byte array with device state information- Returns:
- temperature alarm trip values in Celsius for this 1-wire device
- Throws:
OneWireException
- Device does not support temperature alarms- See Also:
hasTemperatureAlarms()
,setTemperatureAlarm(int, double, byte[])
-
getTemperatureResolution
double getTemperatureResolution(byte[] state)
Gets the current temperature resolution in Celsius from thestate
data retrieved from thereadDevice()
method.- Parameters:
state
- byte array with device state information- Returns:
- temperature resolution in Celsius for this 1-wire device
- See Also:
hasSelectableTemperatureResolution()
,getTemperatureResolutions()
,setTemperatureResolution(double, byte[])
-
setTemperatureAlarm
void setTemperatureAlarm(int alarmType, double alarmValue, byte[] state) throws OneWireException
Sets the temperature alarm value in Celsius in the providedstate
data. Use the methodwriteDevice()
with this data to finalize the change to the device.- Parameters:
alarmType
- valid value:ALARM_HIGH
orALARM_LOW
alarmValue
- alarm trip value in Celsiusstate
- byte array with device state information- Throws:
OneWireException
- Device does not support temperature alarms- See Also:
hasTemperatureAlarms()
,getTemperatureAlarm(int, byte[])
-
setTemperatureResolution
void setTemperatureResolution(double resolution, byte[] state) throws OneWireException
Sets the current temperature resolution in Celsius in the providedstate
data. Use the methodwriteDevice()
with this data to finalize the change to the device.- Parameters:
resolution
- temperature resolution in Celsiusstate
- byte array with device state information- Throws:
OneWireException
- Device does not support selectable temperature resolution- See Also:
hasSelectableTemperatureResolution()
,getTemperatureResolution(byte[])
,getTemperatureResolutions()
-
-