public class I2cDeviceSynchImplOnSimple extends I2cDeviceSynchReadHistoryImpl implements I2cDeviceSynch
I2cDeviceSynch.HeartbeatAction, I2cDeviceSynch.ReadMode, I2cDeviceSynch.ReadWindowHardwareDeviceHealth.HealthStatusHardwareDevice.Manufacturer| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Object |
concurrentClientLock |
protected int |
cregReadLast |
protected java.lang.Object |
engagementLock |
protected I2cDeviceSynch.HeartbeatAction |
heartbeatAction |
protected java.util.concurrent.ScheduledExecutorService |
heartbeatExecutor |
protected I2cDeviceSynchSimple |
i2cDeviceSynchSimple |
protected I2cDeviceSynchReadHistory |
i2cDeviceSynchSimpleHistory |
protected int |
iregReadLast |
protected int |
iregWriteLast |
protected boolean |
isClosing |
protected boolean |
isEngaged |
protected boolean |
isHooked |
protected boolean |
isSimpleOwned |
protected int |
msHeartbeatInterval |
protected I2cDeviceSynch.ReadWindow |
readWindow |
protected byte[] |
rgbWriteLast |
historyQueue, historyQueueCapacity, historyQueueLock| Constructor and Description |
|---|
I2cDeviceSynchImplOnSimple(I2cDeviceSynchSimple simple,
boolean isSimpleOwned) |
| Modifier and Type | Method and Description |
|---|---|
void |
addToHistoryQueue(TimestampedI2cData data) |
protected void |
adjustHooking() |
void |
close()
Closes this device
|
void |
disengage()
Disengage the object from underlying services it uses to render its function.
|
void |
enableWriteCoalescing(boolean enable)
Enables or disables an optimization wherein writes to two sets of adjacent register
ranges may be coalesced into a single I2c transaction if the second write comes along
while the first is still queued for writing.
|
void |
engage()
(Re)enage the object with its underlying services.
|
void |
ensureReadWindow(I2cDeviceSynch.ReadWindow windowNeeded,
I2cDeviceSynch.ReadWindow windowToSet)
Ensure that the current register window covers the indicated set of registers.
|
java.lang.String |
getConnectionInfo()
Get connection information about this device in a human readable format
|
java.lang.String |
getDeviceName()
Returns a string suitable for display to the user as to the type of device.
|
HardwareDeviceHealth.HealthStatus |
getHealthStatus() |
I2cDeviceSynch.HeartbeatAction |
getHeartbeatAction()
Returns the current action, if any, to take upon expiration of the heartbeat interval.
|
int |
getHeartbeatInterval()
Returns the interval within which communication must be received by the I2C device lest
a timeout occur.
|
java.util.concurrent.BlockingQueue<TimestampedI2cData> |
getHistoryQueue()
(Advanced) Returns a queue into which, if requested,
TimestampedI2cDatas are (optionally)
placed as they become available. |
int |
getHistoryQueueCapacity()
Returns the current capacity of the history queue.
|
I2cAddr |
getI2cAddr()
Returns the I2C address currently being used by this device client
|
I2cAddr |
getI2cAddress()
Returns the I2C address currently in use to communicate with an I2C hardware device
|
boolean |
getLogging() |
java.lang.String |
getLoggingTag() |
HardwareDevice.Manufacturer |
getManufacturer()
Returns an indication of the manufacturer of this device.
|
I2cDeviceSynch.ReadWindow |
getReadWindow()
Returns the current register window used for reading.
|
java.lang.String |
getUserConfiguredName()
Returns the human-recognizable name of this device, if same has been set.
|
int |
getVersion()
Version
|
protected void |
hook() |
boolean |
isArmed()
Returns whether, as of this instant, this device client is alive and operational in
its normally expected mode; that is, whether it is currently in communication
with its underlying hardware or whether it is in some other state.
|
boolean |
isEngaged()
Returns whether the object is currently in the engaged state.
|
protected boolean |
isOpenForReading() |
protected boolean |
isOpenForWriting() |
boolean |
isWriteCoalescingEnabled()
Answers as to whether write coalescing is currently enabled on this device.
|
protected boolean |
newReadsAndWritesAllowed() |
byte[] |
read(int ireg,
int creg)
Read a contiguous set of device I2C registers.
|
byte |
read8(int ireg)
Read the byte at the indicated register.
|
TimestampedData |
readTimeStamped(int ireg,
int creg)
Reads and returns a contiguous set of device I2C registers, together with a best-available
timestamp of when the actual I2C read occurred.
|
TimestampedData |
readTimeStamped(int ireg,
int creg,
I2cDeviceSynch.ReadWindow readWindowNeeded,
I2cDeviceSynch.ReadWindow readWindowSet)
Advanced: Atomically calls ensureReadWindow() with the last two parameters and then
readTimeStamped() with the first two without the possibility of a concurrent client
interrupting in the middle.
|
void |
resetDeviceConfigurationForOpMode()
Resets the device's configuration to that which is expected at the beginning of an OpMode.
|
void |
setHealthStatus(HardwareDeviceHealth.HealthStatus status) |
void |
setHeartbeatAction(I2cDeviceSynch.HeartbeatAction action)
Sets the action to take when the current heartbeat interval expires.
|
void |
setHeartbeatInterval(int ms)
Sets the interval within which communication must be received by the I2C device lest
a timeout may occur.
|
void |
setHistoryQueueCapacity(int capacity)
Sets the maximum number of
TimestampedI2cDatas that will simultaneously be stored in the
history queue. |
void |
setI2cAddr(I2cAddr i2cAddr)
Sets the I2C address of the underlying client.
|
void |
setI2cAddress(I2cAddr newAddress)
Configures a new I2C address to use
|
void |
setLogging(boolean enabled)
Turn logging on or off.
|
void |
setLoggingTag(java.lang.String loggingTag)
Set the tag to use when logging is on.
|
void |
setReadWindow(I2cDeviceSynch.ReadWindow window)
Set the set of registers that we will read and read and read again on every hardware cycle
|
void |
setUserConfiguredName(java.lang.String name)
Informs the device of a name by which it would be recognized by the user.
|
protected void |
unhook() |
void |
waitForWriteCompletions(I2cWaitControl waitControl)
Waits for the most recent write to complete according to the behavior specified in writeControl.
|
void |
write(int ireg,
byte[] data)
Writes data to a set of registers, beginning with the one indicated, using
I2cWaitControl.ATOMIC semantics. |
void |
write(int ireg,
byte[] data,
I2cWaitControl waitControl)
Writes data to a set of registers, beginning with the one indicated.
|
void |
write8(int ireg,
int bVal)
Writes a byte to the indicated register using
I2cWaitControl.ATOMIC semantics. |
void |
write8(int ireg,
int bVal,
I2cWaitControl waitControl)
Writes a byte to the indicated register.
|
protected I2cDeviceSynchSimple i2cDeviceSynchSimple
protected I2cDeviceSynchReadHistory i2cDeviceSynchSimpleHistory
protected boolean isSimpleOwned
protected I2cDeviceSynch.ReadWindow readWindow
protected int iregReadLast
protected int cregReadLast
protected int iregWriteLast
protected byte[] rgbWriteLast
protected boolean isHooked
protected boolean isEngaged
protected boolean isClosing
protected int msHeartbeatInterval
protected I2cDeviceSynch.HeartbeatAction heartbeatAction
protected java.util.concurrent.ScheduledExecutorService heartbeatExecutor
protected final java.lang.Object engagementLock
protected final java.lang.Object concurrentClientLock
public I2cDeviceSynchImplOnSimple(I2cDeviceSynchSimple simple, boolean isSimpleOwned)
public void setUserConfiguredName(java.lang.String name)
RobotConfigNameablesetUserConfiguredName in interface RobotConfigNameablepublic java.lang.String getUserConfiguredName()
RobotConfigNameablegetUserConfiguredName in interface RobotConfigNameableRobotConfigNameable.setUserConfiguredName(String)public void setLogging(boolean enabled)
I2cDeviceSynchSimplesetLogging in interface I2cDeviceSynchSimpleenabled - whether to enable logging or notpublic boolean getLogging()
getLogging in interface I2cDeviceSynchSimpleI2cDeviceSynchSimple.setLogging(boolean)public void setLoggingTag(java.lang.String loggingTag)
I2cDeviceSynchSimplesetLoggingTag in interface I2cDeviceSynchSimpleloggingTag - the logging tag to suepublic java.lang.String getLoggingTag()
getLoggingTag in interface I2cDeviceSynchSimpleI2cDeviceSynchSimple.setLoggingTag(String)public void engage()
Engagableprotected void hook()
protected void adjustHooking()
public boolean isEngaged()
Engagablepublic boolean isArmed()
I2cDeviceSynchSimpleisArmed in interface I2cDeviceSynchSimpleEngagable.engage()public void disengage()
Engagableprotected void unhook()
public void setHeartbeatInterval(int ms)
I2cDeviceSynchsetHeartbeatInterval in interface I2cDeviceSynchms - the new hearbeat interval, in millisecondsI2cDeviceSynch.getHeartbeatInterval()public int getHeartbeatInterval()
I2cDeviceSynchgetHeartbeatInterval in interface I2cDeviceSynchI2cDeviceSynch.setHeartbeatInterval(int)public void setHeartbeatAction(I2cDeviceSynch.HeartbeatAction action)
I2cDeviceSynchsetHeartbeatAction in interface I2cDeviceSynchaction - the action to take at each heartbeat.I2cDeviceSynch.getHeartbeatAction(),
I2cDeviceSynch.setHeartbeatInterval(int)public I2cDeviceSynch.HeartbeatAction getHeartbeatAction()
I2cDeviceSynchgetHeartbeatAction in interface I2cDeviceSynchI2cDeviceSynch.setHeartbeatAction(HeartbeatAction)public void setReadWindow(I2cDeviceSynch.ReadWindow window)
I2cDeviceSynchsetReadWindow in interface I2cDeviceSynchwindow - the register window to read. May be null, indicating that no reads are to occur.I2cDeviceSynch.getReadWindow()public I2cDeviceSynch.ReadWindow getReadWindow()
I2cDeviceSynchgetReadWindow in interface I2cDeviceSynchI2cDeviceSynch.setReadWindow(ReadWindow)public void ensureReadWindow(I2cDeviceSynch.ReadWindow windowNeeded, I2cDeviceSynch.ReadWindow windowToSet)
I2cDeviceSynchensureReadWindow in interface I2cDeviceSynchwindowNeeded - Test the current register window, if any, against this window
to see if an update to the current register window is needed in
order to cover it. May be null, indicating that an update to the
current register window is always neededwindowToSet - If an update to the current register window is needed, then this
is the window to which it will be set. May be null.I2cDeviceSynch.setReadWindow(ReadWindow),
I2cDeviceSynchSimple.read8(int)public TimestampedData readTimeStamped(int ireg, int creg, I2cDeviceSynch.ReadWindow readWindowNeeded, I2cDeviceSynch.ReadWindow readWindowSet)
I2cDeviceSynchreadTimeStamped in interface I2cDeviceSynchireg - the register number of the first byte register to readcreg - the number of bytes / registers to readreadWindowNeeded - the read window we requirereadWindowSet - the read window to set if the required read window is not currentI2cDeviceSynch.ensureReadWindow(ReadWindow, ReadWindow),
I2cDeviceSynchSimple.readTimeStamped(int, int)public HardwareDevice.Manufacturer getManufacturer()
HardwareDevicegetManufacturer in interface HardwareDevicepublic java.lang.String getDeviceName()
HardwareDevicegetDeviceName in interface HardwareDevicepublic java.lang.String getConnectionInfo()
HardwareDevicegetConnectionInfo in interface HardwareDevicepublic int getVersion()
HardwareDevicegetVersion in interface HardwareDevicepublic void resetDeviceConfigurationForOpMode()
HardwareDeviceresetDeviceConfigurationForOpMode in interface HardwareDevicepublic void close()
HardwareDeviceclose in interface HardwareDevicepublic void setHealthStatus(HardwareDeviceHealth.HealthStatus status)
setHealthStatus in interface HardwareDeviceHealthpublic HardwareDeviceHealth.HealthStatus getHealthStatus()
getHealthStatus in interface HardwareDeviceHealthpublic java.util.concurrent.BlockingQueue<TimestampedI2cData> getHistoryQueue()
I2cDeviceSynchReadHistoryTimestampedI2cDatas are (optionally)
placed as they become available.
To access these TimestampedI2cDatas, call I2cDeviceSynchReadHistory.setHistoryQueueCapacity(int) to enable
the history queue. Once enabled, the history queue can be accessed using I2cDeviceSynchReadHistory.getHistoryQueue()
and the methods thereon used to access TimestampedI2cDatas as they become available.
When I2cDeviceSynchReadHistory.setHistoryQueueCapacity(int) is called, any history queue returned previously by
I2cDeviceSynchReadHistory.getHistoryQueue() becomes invalid and must be re-fetched.
getHistoryQueue in interface I2cDeviceSynchReadHistorygetHistoryQueue in class I2cDeviceSynchReadHistoryImplTimestampedI2cDatas may be retrieved.I2cDeviceSynchReadHistory.setHistoryQueueCapacity(int)public void setHistoryQueueCapacity(int capacity)
I2cDeviceSynchReadHistoryTimestampedI2cDatas that will simultaneously be stored in the
history queue. If the queue is full and new TimestampedI2cDatas become available, older
data will be discarded. The history queue initially has a capacity of zero.
Note that calling this method invalidates any history queue retrieved previously
through I2cDeviceSynchReadHistory.getHistoryQueue().
setHistoryQueueCapacity in interface I2cDeviceSynchReadHistorysetHistoryQueueCapacity in class I2cDeviceSynchReadHistoryImplcapacity - the maximum number of items that may be stored in the history queueI2cDeviceSynchReadHistory.getHistoryQueue(),
I2cDeviceSynchReadHistory.getHistoryQueueCapacity()public int getHistoryQueueCapacity()
I2cDeviceSynchReadHistorygetHistoryQueueCapacity in interface I2cDeviceSynchReadHistorygetHistoryQueueCapacity in class I2cDeviceSynchReadHistoryImplI2cDeviceSynchReadHistory.setHistoryQueueCapacity(int),
I2cDeviceSynchReadHistory.getHistoryQueue()public void addToHistoryQueue(TimestampedI2cData data)
addToHistoryQueue in class I2cDeviceSynchReadHistoryImplprotected boolean isOpenForReading()
protected boolean isOpenForWriting()
protected boolean newReadsAndWritesAllowed()
public void setI2cAddress(I2cAddr newAddress)
I2cAddrConfigsetI2cAddress in interface I2cAddrConfignewAddress - the new I2C address to usepublic I2cAddr getI2cAddress()
I2cAddressableDevicegetI2cAddress in interface I2cAddressableDevicepublic void setI2cAddr(I2cAddr i2cAddr)
I2cDeviceSynchSimplesetI2cAddr in interface I2cDeviceSynchSimplei2cAddr - the new I2C addresspublic I2cAddr getI2cAddr()
I2cDeviceSynchSimplegetI2cAddr in interface I2cDeviceSynchSimplepublic byte read8(int ireg)
I2cDeviceSynchSimpleI2cDeviceSynchSimple.readTimeStamped(int, int) for a
complete description.read8 in interface I2cDeviceSynchSimpleireg - the register number to readI2cDeviceSynchSimple.read(int, int),
I2cDeviceSynchSimple.readTimeStamped(int, int),
I2cDeviceSynch.ensureReadWindow(I2cDeviceSynch.ReadWindow, I2cDeviceSynch.ReadWindow)public byte[] read(int ireg,
int creg)
I2cDeviceSynchSimpleI2cDeviceSynchSimple.readTimeStamped(int, int) for a
complete description.read in interface I2cDeviceSynchSimpleireg - the register number of the first byte register to readcreg - the number of bytes / registers to readI2cDeviceSynchSimple.read8(int),
I2cDeviceSynchSimple.readTimeStamped(int, int),
I2cDeviceSynch.ensureReadWindow(I2cDeviceSynch.ReadWindow, I2cDeviceSynch.ReadWindow)public TimestampedData readTimeStamped(int ireg, int creg)
I2cDeviceSynchSimpleYou can always just call this method without worrying at all about
read windows,
that will work, but usually it is more efficient to take some thought and care as to what set
of registers the I2C device controller is being set up to read, as adjusting that window
of registers incurs significant extra time.
If the current read window can't be used to read the requested registers, then
a new read window will automatically be created as follows. If the current read window is non
null and wholly contains the registers to read but can't be read because it is a used-up
ReadMode#ONLY_ONCE window,
a new read fresh window will be created with the same set of registers. Otherwise, a
window that exactly covers the requested set of registers will be created.
readTimeStamped in interface I2cDeviceSynchSimpleireg - the register number of the first byte register to readcreg - the number of bytes / registers to readI2cDeviceSynchSimple.read(int, int),
I2cDeviceSynchSimple.read8(int),
I2cDeviceSynch.ensureReadWindow(I2cDeviceSynch.ReadWindow, I2cDeviceSynch.ReadWindow)public void write8(int ireg,
int bVal)
I2cDeviceSynchSimpleI2cWaitControl.ATOMIC semantics.write8 in interface I2cDeviceSynchSimpleireg - the register number that is to be writtenbVal - the byte which is to be written to that registerI2cDeviceSynchSimple.write(int, byte[], I2cWaitControl)public void write8(int ireg,
int bVal,
I2cWaitControl waitControl)
I2cDeviceSynchSimpleI2cDeviceSynchSimple.write(int, byte[], I2cWaitControl).write8 in interface I2cDeviceSynchSimpleireg - the register number that is to be writtenbVal - the byte which is to be written to that registerwaitControl - controls the behavior of waiting for the completion of the writeI2cDeviceSynchSimple.write(int, byte[], I2cWaitControl)public void write(int ireg,
byte[] data)
I2cDeviceSynchSimpleI2cWaitControl.ATOMIC semantics.write in interface I2cDeviceSynchSimpleireg - the first of the registers which is to be writtendata - the data which is to be written to the registersI2cDeviceSynchSimple.write(int, byte[], I2cWaitControl)public void write(int ireg,
byte[] data,
I2cWaitControl waitControl)
I2cDeviceSynchSimplewrite in interface I2cDeviceSynchSimpleireg - the first of the registers which is to be writtendata - the data which is to be written to the registerswaitControl - controls the behavior of waiting for the completion of the writepublic void waitForWriteCompletions(I2cWaitControl waitControl)
I2cDeviceSynchSimplewaitForWriteCompletions in interface I2cDeviceSynchSimplewaitControl - controls the behavior of waiting for the completion of the write
Note that a value of I2cWaitControl.NONE is essentially a no-op.public void enableWriteCoalescing(boolean enable)
I2cDeviceSynchSimpleenableWriteCoalescing in interface I2cDeviceSynchSimpleenable - whether to enable write coalescing or notI2cDeviceSynchSimple.isWriteCoalescingEnabled()public boolean isWriteCoalescingEnabled()
I2cDeviceSynchSimpleisWriteCoalescingEnabled in interface I2cDeviceSynchSimpleI2cDeviceSynchSimple.enableWriteCoalescing(boolean)