public abstract class LynxI2cDeviceSynch extends LynxController implements I2cDeviceSynchSimple, I2cDeviceSynchReadHistory
Modifier and Type | Class and Description |
---|---|
static class |
LynxI2cDeviceSynch.BusSpeed
Lynx I2C bus speed.
|
LynxController.PretendLynxModule
HardwareDeviceHealth.HealthStatus
HardwareDevice.Manufacturer
RobotArmingStateNotifier.ARMINGSTATE, RobotArmingStateNotifier.Callback
Modifier and Type | Field and Description |
---|---|
protected int |
bus |
protected I2cAddr |
i2cAddr |
protected LynxUsbUtil.Placeholder<TimestampedData> |
readTimeStampedPlaceholder |
static java.lang.String |
TAG |
context, hardwareDeviceHealth, isEngaged, isHardwareInitialized, isHooked, registeredCallbacks
tag
Modifier | Constructor and Description |
---|---|
protected |
LynxI2cDeviceSynch(Context context,
LynxModule module,
int bus) |
Modifier and Type | Method and Description |
---|---|
protected <T> T |
acquireI2cLockWhile(Supplier<T> supplier) |
void |
close()
Closes this device
|
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.
|
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.
|
java.util.concurrent.BlockingQueue<TimestampedI2cData> |
getHistoryQueue()
(Advanced) Returns a queue into which, if requested,
TimestampedI2cData s 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() |
protected java.lang.String |
getTag() |
java.lang.String |
getUserConfiguredName()
Returns the human-recognizable name of this device, if same has been set.
|
protected void |
internalWaitForWriteCompletions(I2cWaitControl waitControl) |
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 |
isWriteCoalescingEnabled()
Answers as to whether write coalescing is currently enabled on this device.
|
protected TimestampedData |
pollForReadResult(I2cAddr i2cAddr,
int ireg,
int creg) |
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.
|
abstract 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.
|
void |
resetDeviceConfigurationForOpMode()
Resets the device's configuration to that which is expected at the beginning of an OpMode.
|
protected void |
sendI2cWriteTx(LynxCommand writeTx) |
void |
setBusSpeed(LynxI2cDeviceSynch.BusSpeed speed)
Sets the bus speed.
|
void |
setHistoryQueueCapacity(int capacity)
Sets the maximum number of
TimestampedI2cData s that will simultaneously be stored in the
history queue. |
void |
setI2cAddr(I2cAddr i2cAddr)
Sets the I2C address of the underlying client.
|
void |
setI2cAddress(I2cAddr i2cAddr)
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 |
setUserConfiguredName(java.lang.String name)
Informs the device of a name by which it would be recognized by the user.
|
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.
|
adjustHookingToMatchEngagement, disengage, doHook, doUnhook, engage, finishConstruction, floatHardware, forgetLastKnown, getArmingState, getHealthStatus, getHealthStatusOverride, getManufacturer, getModule, getSerialNumber, getVersion, hook, initializeHardware, isEngaged, moduleNowArmedOrPretending, moduleNowDisarmed, onModuleStateChange, registerCallback, setHealthStatus, setHealthyIfArmed, unhook, unregisterCallback
handleException, handleSpecificException, handleSpecificException, handleSpecificException, handleSpecificException
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getHealthStatus, setHealthStatus
getManufacturer, getVersion
public static final java.lang.String TAG
protected I2cAddr i2cAddr
protected int bus
protected LynxUsbUtil.Placeholder<TimestampedData> readTimeStampedPlaceholder
protected LynxI2cDeviceSynch(Context context, LynxModule module, int bus)
protected java.lang.String getTag()
getTag
in class LynxController
public java.lang.String getDeviceName()
HardwareDevice
getDeviceName
in interface HardwareDevice
getDeviceName
in class LynxController
public java.lang.String getConnectionInfo()
HardwareDevice
getConnectionInfo
in interface HardwareDevice
getConnectionInfo
in class LynxController
public void resetDeviceConfigurationForOpMode()
HardwareDevice
resetDeviceConfigurationForOpMode
in interface HardwareDevice
resetDeviceConfigurationForOpMode
in class LynxController
public void close()
HardwareDevice
close
in interface HardwareDevice
close
in class LynxController
public boolean isArmed()
I2cDeviceSynchSimple
isArmed
in interface I2cDeviceSynchSimple
isArmed
in class LynxController
Engagable.engage()
public void setI2cAddress(I2cAddr i2cAddr)
I2cAddrConfig
setI2cAddress
in interface I2cAddrConfig
i2cAddr
- the new I2C address to usepublic void setI2cAddr(I2cAddr i2cAddr)
I2cDeviceSynchSimple
setI2cAddr
in interface I2cDeviceSynchSimple
i2cAddr
- the new I2C addresspublic I2cAddr getI2cAddress()
I2cAddressableDevice
getI2cAddress
in interface I2cAddressableDevice
public I2cAddr getI2cAddr()
I2cDeviceSynchSimple
getI2cAddr
in interface I2cDeviceSynchSimple
public void setUserConfiguredName(java.lang.String name)
RobotConfigNameable
setUserConfiguredName
in interface RobotConfigNameable
public java.lang.String getUserConfiguredName()
RobotConfigNameable
getUserConfiguredName
in interface RobotConfigNameable
RobotConfigNameable.setUserConfiguredName(String)
public void setLogging(boolean enabled)
I2cDeviceSynchSimple
setLogging
in interface I2cDeviceSynchSimple
enabled
- whether to enable logging or notpublic boolean getLogging()
getLogging
in interface I2cDeviceSynchSimple
I2cDeviceSynchSimple.setLogging(boolean)
public void setLoggingTag(java.lang.String loggingTag)
I2cDeviceSynchSimple
setLoggingTag
in interface I2cDeviceSynchSimple
loggingTag
- the logging tag to suepublic java.lang.String getLoggingTag()
getLoggingTag
in interface I2cDeviceSynchSimple
I2cDeviceSynchSimple.setLoggingTag(String)
public void setHistoryQueueCapacity(int capacity)
I2cDeviceSynchReadHistory
TimestampedI2cData
s that will simultaneously be stored in the
history queue. If the queue is full and new TimestampedI2cData
s 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 I2cDeviceSynchReadHistory
capacity
- the maximum number of items that may be stored in the history queueI2cDeviceSynchReadHistory.getHistoryQueue()
,
I2cDeviceSynchReadHistory.getHistoryQueueCapacity()
public int getHistoryQueueCapacity()
I2cDeviceSynchReadHistory
getHistoryQueueCapacity
in interface I2cDeviceSynchReadHistory
I2cDeviceSynchReadHistory.setHistoryQueueCapacity(int)
,
I2cDeviceSynchReadHistory.getHistoryQueue()
public java.util.concurrent.BlockingQueue<TimestampedI2cData> getHistoryQueue()
I2cDeviceSynchReadHistory
TimestampedI2cData
s are (optionally)
placed as they become available.
To access these TimestampedI2cData
s, 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 TimestampedI2cData
s 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 I2cDeviceSynchReadHistory
TimestampedI2cData
s may be retrieved.I2cDeviceSynchReadHistory.setHistoryQueueCapacity(int)
public byte[] read(int ireg, int creg)
I2cDeviceSynchSimple
I2cDeviceSynchSimple.readTimeStamped(int, int)
for a
complete description.read
in interface I2cDeviceSynchSimple
ireg
- 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 byte read8(int ireg)
I2cDeviceSynchSimple
I2cDeviceSynchSimple.readTimeStamped(int, int)
for a
complete description.read8
in interface I2cDeviceSynchSimple
ireg
- the register number to readI2cDeviceSynchSimple.read(int, int)
,
I2cDeviceSynchSimple.readTimeStamped(int, int)
,
I2cDeviceSynch.ensureReadWindow(I2cDeviceSynch.ReadWindow, I2cDeviceSynch.ReadWindow)
public abstract TimestampedData readTimeStamped(int ireg, int creg)
I2cDeviceSynchSimple
You 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 I2cDeviceSynchSimple
ireg
- 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 write(int ireg, byte[] data)
I2cDeviceSynchSimple
I2cWaitControl.ATOMIC
semantics.write
in interface I2cDeviceSynchSimple
ireg
- 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 write8(int ireg, int bVal)
I2cDeviceSynchSimple
I2cWaitControl.ATOMIC
semantics.write8
in interface I2cDeviceSynchSimple
ireg
- 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)
I2cDeviceSynchSimple
I2cDeviceSynchSimple.write(int, byte[], I2cWaitControl)
.write8
in interface I2cDeviceSynchSimple
ireg
- 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, I2cWaitControl waitControl)
I2cDeviceSynchSimple
write
in interface I2cDeviceSynchSimple
ireg
- 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)
I2cDeviceSynchSimple
waitForWriteCompletions
in interface I2cDeviceSynchSimple
waitControl
- 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)
I2cDeviceSynchSimple
enableWriteCoalescing
in interface I2cDeviceSynchSimple
enable
- whether to enable write coalescing or notI2cDeviceSynchSimple.isWriteCoalescingEnabled()
public boolean isWriteCoalescingEnabled()
I2cDeviceSynchSimple
isWriteCoalescingEnabled
in interface I2cDeviceSynchSimple
I2cDeviceSynchSimple.enableWriteCoalescing(boolean)
protected void sendI2cWriteTx(LynxCommand writeTx) throws LynxNackException, java.lang.InterruptedException
LynxNackException
java.lang.InterruptedException
protected <T> T acquireI2cLockWhile(Supplier<T> supplier) throws java.lang.InterruptedException, RobotCoreException, LynxNackException
java.lang.InterruptedException
RobotCoreException
LynxNackException
protected void internalWaitForWriteCompletions(I2cWaitControl waitControl)
protected TimestampedData pollForReadResult(I2cAddr i2cAddr, int ireg, int creg)
public void setBusSpeed(LynxI2cDeviceSynch.BusSpeed speed)
speed
- new bus speed