Package com.dalsemi.onewire.container
Interface ClockContainer
- All Superinterfaces:
OneWireSensor
- All Known Subinterfaces:
MissionContainer
- All Known Implementing Classes:
OneWireContainer04
,OneWireContainer21
,OneWireContainer24
,OneWireContainer26
,OneWireContainer27
,OneWireContainer41
Interface class for 1-Wire® devices that contain Real-Time clocks. This class should be implemented for each Clock type 1-Wire device.
Features
- Supports clock alarm enabling and setting on devices with clock alarms
- Supports enabling and disabling the clock on devices that can disable their oscillators
Usage
ClockContainer
extends
com.dalsemi.onewire.container.OneWireSensor
, so the general
usage model applies to any ClockContainer
:
- readDevice()
- perform operations on the
ClockContainer
- writeDevice(byte[])
Consider this interaction with a ClockContainer
that reads from
the Real-Time clock, then tries to set it to the system's current clock
setting before disabling the oscillator:
//clockcontainer is a com.dalsemi.onewire.container.ClockContainer
byte[] state = clockcontainer.readDevice();
long current_time = clockcontainer.getClock(state);
System.out.println("Current time is :"+(new Date(current_time)));
long system_time = System.currentTimeMillis();
clockcontainer.setClock(system_time,state);
clockcontainer.writeDevice(state);
//now try to disable to clock oscillator
if (clockcontainer.canDisableClock())
{
state = clockcontainer.readDevice();
clockcontainer.setClockRunEnable(false,state);
clockcontainer.writeDevice(state);
}
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks to see if the clock can be disabled.long
getClock
(byte[] state) Extracts the Real-Time clock value in milliseconds.long
getClockAlarm
(byte[] state) Extracts the clock alarm value for the Real-Time clock.long
Gets the clock resolution in milliseconds.boolean
Checks to see if the clock has an alarm feature.boolean
isClockAlarmEnabled
(byte[] state) Checks if the clock alarm is enabled.boolean
isClockAlarming
(byte[] state) Checks if the clock alarm flag has been set.boolean
isClockRunning
(byte[] state) Checks if the device's oscillator is enabled.void
setClock
(long time, byte[] state) Sets the Real-Time clock.void
setClockAlarm
(long time, byte[] state) Sets the clock alarm.void
setClockAlarmEnable
(boolean alarmEnable, byte[] state) Enables or disables the clock alarm.void
setClockRunEnable
(boolean runEnable, byte[] state) Enables or disables the oscillator, turning the clock 'on' and 'off'.Methods inherited from interface com.dalsemi.onewire.container.OneWireSensor
readDevice, writeDevice
-
Method Details
-
hasClockAlarm
boolean hasClockAlarm()Checks to see if the clock has an alarm feature.- Returns:
- true if the Real-Time clock has an alarm
- See Also:
-
canDisableClock
boolean canDisableClock()Checks to see if the clock can be disabled.- Returns:
- true if the clock can be enabled and disabled
- See Also:
-
getClockResolution
long getClockResolution()Gets the clock resolution in milliseconds.- Returns:
- the clock resolution in milliseconds
-
getClock
long getClock(byte[] state) Extracts the Real-Time clock value in milliseconds.- Parameters:
state
- current state of the device returned fromreadDevice()
- Returns:
- the time represented in this clock in milliseconds since 1970
- See Also:
-
getClockAlarm
Extracts the clock alarm value for the Real-Time clock.- Parameters:
state
- current state of the device returned fromreadDevice()
- Returns:
- the set value of the clock alarm in milliseconds since 1970
- Throws:
OneWireException
- if this device does not have clock alarms- See Also:
-
isClockAlarming
boolean isClockAlarming(byte[] state) Checks if the clock alarm flag has been set. This will occur when the value of the Real-Time clock equals the value of the clock alarm.- Parameters:
state
- current state of the device returned fromreadDevice()
- Returns:
- true if the Real-Time clock is alarming
- See Also:
-
isClockAlarmEnabled
boolean isClockAlarmEnabled(byte[] state) Checks if the clock alarm is enabled.- Parameters:
state
- current state of the device returned fromreadDevice()
- Returns:
- true if clock alarm is enabled
- See Also:
-
isClockRunning
boolean isClockRunning(byte[] state) Checks if the device's oscillator is enabled. The clock will not increment if the clock oscillator is not enabled.- Parameters:
state
- current state of the device returned fromreadDevice()
- Returns:
- true if the clock is running
- See Also:
-
setClock
void setClock(long time, byte[] state) Sets the Real-Time clock. The methodwriteDevice()
must be called to finalize changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
.- Parameters:
time
- new value for the Real-Time clock, in milliseconds since January 1, 1970state
- current state of the device returned fromreadDevice()
- See Also:
-
setClockAlarm
Sets the clock alarm. The methodwriteDevice()
must be called to finalize changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
. Also note that not all clock devices have alarms. Check to see if this device has alarms first by calling thehasClockAlarm()
method.- Parameters:
time
- - new value for the Real-Time clock alarm, in milliseconds since January 1, 1970state
- current state of the device returned fromreadDevice()
- Throws:
OneWireException
- if this device does not have clock alarms- See Also:
-
setClockRunEnable
Enables or disables the oscillator, turning the clock 'on' and 'off'. The methodwriteDevice()
must be called to finalize changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
. Also note that not all clock devices can disable their oscillators. Check to see if this device can disable its oscillator first by calling thecanDisableClock()
method.- Parameters:
runEnable
- true to enable the clock oscillatorstate
- current state of the device returned fromreadDevice()
- Throws:
OneWireException
- if the clock oscillator cannot be disabled- See Also:
-
setClockAlarmEnable
Enables or disables the clock alarm. The methodwriteDevice()
must be called to finalize changes to the device. Note that multiple 'set' methods can be called before one call towriteDevice()
. Also note that not all clock devices have alarms. Check to see if this device has alarms first by calling thehasClockAlarm()
method.- Parameters:
alarmEnable
- true to enable the clock alarmstate
- current state of the device returned fromreadDevice()
- Throws:
OneWireException
- if this device does not have clock alarms- See Also:
-