public class ModernRoboticsUsbDeviceInterfaceModule extends ModernRoboticsUsbI2cController implements DeviceInterfaceModule
HardwareDeviceManager
to create an instance of this classModernRoboticsUsbDevice.CreateReadWriteRunnable
DigitalChannelController.Mode
I2cController.I2cPortReadyBeginEndNotifications, I2cController.I2cPortReadyCallback
HardwareDevice.Manufacturer
i2cPortReadyBeginEndCallbacks, notificationsActive, numberOfI2cPorts
createReadWriteRunnable, readWriteRunnable, readWriteService
I2C_BUFFER_START_ADDRESS
Constructor and Description |
---|
ModernRoboticsUsbDeviceInterfaceModule(Context context,
SerialNumber serialNumber,
OpenRobotUsbDevice openRobotUsbDevice,
SyncdDevice.Manager manager)
Use ModernRoboticsUsbDeviceManager to create an instance of this class
|
Modifier and Type | Method and Description |
---|---|
void |
clearI2cPortActionFlag(int port)
Clears the port action flag, undoing the effect of previous setI2cPortActionFlag()
|
void |
copyBufferIntoWriteBuffer(int physicalPort,
byte[] buffer)
Copy a byte array into the buffer that is set to be written out to the device
|
protected void |
createSegments() |
void |
deregisterForPortReadyCallback(int port)
De-register for port ready notifications.
|
protected void |
doArm() |
protected void |
doPretend() |
void |
enableI2cReadMode(int physicalPort,
I2cAddr i2cAddress,
int memAddress,
int length)
Enable read mode for a particular I2C device
|
void |
enableI2cWriteMode(int physicalPort,
I2cAddr i2cAddress,
int memAddress,
int length)
Enable write mode for a particular I2C device
|
double |
getAnalogInputVoltage(int channel)
Get the value of this analog input
Return the current ADC results from the A0-A7 channel input pins.
|
java.lang.String |
getConnectionInfo()
Get connection information about this device in a human readable format
|
byte[] |
getCopyOfReadBuffer(int physicalPort)
Get a copy of the most recent data read in from the device
|
byte[] |
getCopyOfWriteBuffer(int physicalPort)
Get a copy of the data that is set to be written out to the device
|
java.lang.String |
getDeviceName()
Device Name
|
DigitalChannel.Mode |
getDigitalChannelMode(int channel)
Get the mode of a digital channel
|
boolean |
getDigitalChannelState(int channel)
Get the state of a digital channel
If it's in OUTPUT mode, this will return the output bit.
|
int |
getDigitalInputStateByte()
A byte containing the current logic levels present in the D7-D0 channel pins.
|
byte |
getDigitalIOControlByte()
Get the digital IO control byte
|
byte |
getDigitalOutputStateByte()
The D7-D0 output set field is a byte containing the required I/O output of the D7-D0
channel pins.
|
I2cController.I2cPortReadyCallback |
getI2cPortReadyCallback(int port)
Returns the callback currently registered to receive portIsReady notifications for the
indicated port
|
byte[] |
getI2cReadCache(int port)
Get direct access to the cache that I2C reads will be populated into
|
java.util.concurrent.locks.Lock |
getI2cReadCacheLock(int port)
Get access to the read cache lock.
|
TimeWindow |
getI2cReadCacheTimeWindow(int port)
Returns the time window object into which timestamps are placed as the read cache is populated
|
byte[] |
getI2cWriteCache(int port)
Get direct access to the cache that I2C writes will be populated into
|
java.util.concurrent.locks.Lock |
getI2cWriteCacheLock(int port)
Get access to the write cache lock.
|
boolean |
getLEDState(int channel)
Indicates whether the LED on the given channel is on or not
|
HardwareDevice.Manufacturer |
getManufacturer()
Returns an indication of the manufacturer of this device.
|
double |
getMaxAnalogInputVoltage()
Returns the maximum value that getAnalogInputVoltage() is capable of reading
|
int |
getMaxI2cWriteLatency(int port)
Returns the maximum interval, in milliseconds, from when the controller receives an I2c write
transmission over USB to when that write is actually issued to the I2c device.
|
int |
getPulseWidthOutputTime(int port)
Gets the pulse width for the channel output in units of 1 microsecond.
|
int |
getPulseWidthPeriod(int port)
Gets the pulse repetition period for the channel output in units of 1 microsecond.
|
protected java.lang.String |
getTag() |
void |
initializeHardware() |
boolean |
isI2cPortActionFlagSet(int port)
Get the port action flag; this flag is set if the particular port is busy.
|
boolean |
isI2cPortInReadMode(int port)
Is the port in read mode?
|
boolean |
isI2cPortInWriteMode(int port)
Is the port in write mode?
|
boolean |
isI2cPortReady(int port)
Determine if a physical port is ready
|
void |
readComplete() |
void |
readI2cCacheFromController(int port)
Read the local cache in from the I2C Controller
NOTE: unless this method is called the internal cache isn't updated
|
void |
readI2cCacheFromModule(int port)
Deprecated.
|
void |
registerForI2cPortReadyCallback(I2cController.I2cPortReadyCallback callback,
int port)
Register to be notified when a given I2C port is ready.
|
void |
resetDeviceConfigurationForOpMode()
Resets the device's configuration to that which is expected at the beginning of an OpMode.
|
void |
setAnalogOutputFrequency(int port,
int freq)
Sets the channel output frequency in the range 1-5,000 Hz in mode 1, 2 or 3.
|
void |
setAnalogOutputMode(int port,
byte mode)
Sets the channel operating mode.
|
void |
setAnalogOutputVoltage(int port,
int voltage)
Sets the channel output voltage.
|
void |
setDigitalChannelMode(int channel,
DigitalChannel.Mode mode)
Set the mode of a digital channel
|
void |
setDigitalChannelMode(int channel,
DigitalChannelController.Mode mode)
Deprecated.
|
void |
setDigitalChannelState(int channel,
boolean state)
Set the state of a digital channel
|
void |
setDigitalIOControlByte(byte input)
If a particular bit is set to one, the corresponding channel pin will be in output mode.
|
void |
setDigitalOutputByte(byte input)
If a a particular control field bit is set to one, the channel pin will be in output mode and
will reflect the value of the corresponding field bit.
|
void |
setI2cPortActionFlag(int port)
Set the port action flag; this flag tells the controller to send the
current data in its buffer to the I2C device
|
void |
setLED(int channel,
boolean set)
Turn on or off a particular LED
|
void |
setPulseWidthOutputTime(int port,
int usDuration)
Set the pulse width output time for this channel.
|
void |
setPulseWidthPeriod(int port,
int usPeriod)
Set the pulse width output period.
|
static void |
throwIfModernRoboticsI2cAddressIsInvalid(I2cAddr newAddress) |
void |
writeI2cCacheToController(int port)
Write the local cache to the I2C Controller
NOTE: unless this method is called the internal cache isn't updated
|
void |
writeI2cCacheToModule(int port)
Deprecated.
|
void |
writeI2cPortFlagOnlyToController(int port)
Write just the port action flag in the local cache to the I2C controller
|
void |
writeI2cPortFlagOnlyToModule(int port)
Deprecated.
|
deregisterForPortReadyBeginEndCallback, getPortReadyBeginEndCallback, isArmed, registerForPortReadyBeginEndCallback, shutdownComplete, startupComplete, throwIfI2cPortIsInvalid
armDevice, disarmDevice, getCreateReadWriteRunnable, getOpenRobotUsbDevice, getPretendDevice, getReadWriteRunnable, getVersion, read, read8, readFromWriteCache, readFromWriteCache, write, write8, write8, write8, writeComplete
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSerialNumber
getSerialNumber
getSerialNumber
deregisterForPortReadyBeginEndCallback, getPortReadyBeginEndCallback, getSerialNumber, isArmed, registerForPortReadyBeginEndCallback
getSerialNumber
close, getVersion
public static final java.lang.String TAG
public static final boolean DEBUG_LOGGING
public static final int MIN_I2C_PORT_NUMBER
public static final int MAX_I2C_PORT_NUMBER
public static final int MAX_ANALOG_PORT_NUMBER
public static final int MIN_ANALOG_PORT_NUMBER
public static final int NUMBER_OF_PORTS
public static final int START_ADDRESS
public static final int MONITOR_LENGTH
public static final int SIZE_I2C_BUFFER
public static final int SIZE_ANALOG_BUFFER
public static final int WORD_SIZE
public static final double MAX_ANALOG_INPUT_VOLTAGE
public static final int ADDRESS_BUFFER_STATUS
public static final int ADDRESS_ANALOG_PORT_A0
public static final int ADDRESS_ANALOG_PORT_A1
public static final int ADDRESS_ANALOG_PORT_A2
public static final int ADDRESS_ANALOG_PORT_A3
public static final int ADDRESS_ANALOG_PORT_A4
public static final int ADDRESS_ANALOG_PORT_A5
public static final int ADDRESS_ANALOG_PORT_A6
public static final int ADDRESS_ANALOG_PORT_A7
public static final int ADDRESS_DIGITAL_INPUT_STATE
public static final int ADDRESS_DIGITAL_IO_CONTROL
public static final int ADDRESS_DIGITAL_OUTPUT_STATE
public static final int ADDRESS_LED_SET
public static final int ADDRESS_VOLTAGE_OUTPUT_PORT_0
public static final int ADDRESS_VOLTAGE_OUTPUT_PORT_1
public static final int ADDRESS_PULSE_OUTPUT_PORT_0
public static final int ADDRESS_PULSE_OUTPUT_PORT_1
public static final int ADDRESS_I2C0
public static final int ADDRESS_I2C1
public static final int ADDRESS_I2C2
public static final int ADDRESS_I2C3
public static final int ADDRESS_I2C4
public static final int ADDRESS_I2C5
public static final byte BUFFER_FLAG_I2C0
public static final byte BUFFER_FLAG_I2C1
public static final byte BUFFER_FLAG_I2C2
public static final byte BUFFER_FLAG_I2C3
public static final byte BUFFER_FLAG_I2C4
public static final byte BUFFER_FLAG_I2C5
public static final int OFFSET_ANALOG_VOLTAGE_OUTPUT_VOLTAGE
public static final int OFFSET_ANALOG_VOLTAGE_OUTPUT_FREQ
public static final int OFFSET_ANALOG_VOLTAGE_OUTPUT_MODE
public static final int ANALOG_VOLTAGE_OUTPUT_BUFFER_SIZE
public static final int OFFSET_PULSE_OUTPUT_TIME
public static final int OFFSET_PULSE_OUTPUT_PERIOD
public static final int PULSE_OUTPUT_BUFFER_SIZE
public static final int OFFSET_I2C_PORT_MODE
public static final int OFFSET_I2C_PORT_I2C_ADDRESS
public static final int OFFSET_I2C_PORT_MEMORY_ADDRESS
public static final int OFFSET_I2C_PORT_MEMORY_LENGTH
public static final int OFFSET_I2C_PORT_MEMORY_BUFFER
public static final int OFFSET_I2C_PORT_FLAG
public static final int I2C_PORT_BUFFER_SIZE
public static final byte I2C_MODE_READ
public static final byte I2C_MODE_WRITE
public static final byte I2C_ACTION_FLAG
public static final byte I2C_NO_ACTION_FLAG
public static final int LED_0_BIT_MASK
public static final int LED_1_BIT_MASK
public static final int[] LED_BIT_MASK_MAP
public static final int D0_MASK
public static final int D1_MASK
public static final int D2_MASK
public static final int D3_MASK
public static final int D4_MASK
public static final int D5_MASK
public static final int D6_MASK
public static final int D7_MASK
public static final int[] ADDRESS_DIGITAL_BIT_MASK
public static final int[] ADDRESS_ANALOG_PORT_MAP
public static final int[] ADDRESS_VOLTAGE_OUTPUT_PORT_MAP
public static final int[] ADDRESS_PULSE_OUTPUT_PORT_MAP
public static final int[] ADDRESS_I2C_PORT_MAP
public static final int[] BUFFER_FLAG_MAP
protected final byte[] lastI2cPortModes
public static final int MAX_NEW_I2C_ADDRESS
public static final int MIN_NEW_I2C_ADDRESS
public ModernRoboticsUsbDeviceInterfaceModule(Context context, SerialNumber serialNumber, OpenRobotUsbDevice openRobotUsbDevice, SyncdDevice.Manager manager) throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected java.lang.String getTag()
protected void doArm() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void doPretend() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void createSegments()
public void initializeHardware()
initializeHardware
in class ModernRoboticsUsbDevice
public HardwareDevice.Manufacturer getManufacturer()
HardwareDevice
getManufacturer
in interface HardwareDevice
public java.lang.String getDeviceName()
getDeviceName
in interface HardwareDevice
getDeviceName
in class ModernRoboticsUsbDevice
public java.lang.String getConnectionInfo()
HardwareDevice
getConnectionInfo
in interface HardwareDevice
public void resetDeviceConfigurationForOpMode()
HardwareDevice
resetDeviceConfigurationForOpMode
in interface HardwareDevice
public double getAnalogInputVoltage(int channel)
AnalogInputController
getAnalogInputVoltage
in interface AnalogInputController
channel
- which analog channel to readpublic double getMaxAnalogInputVoltage()
AnalogInputController
getMaxAnalogInputVoltage
in interface AnalogInputController
AnalogInputController.getAnalogInputVoltage(int)
public DigitalChannel.Mode getDigitalChannelMode(int channel)
DigitalChannelController
getDigitalChannelMode
in interface DigitalChannelController
channel
- channelpublic void setDigitalChannelMode(int channel, DigitalChannel.Mode mode)
DigitalChannelController
setDigitalChannelMode
in interface DigitalChannelController
channel
- channelmode
- INPUT or OUTPUT@Deprecated public void setDigitalChannelMode(int channel, DigitalChannelController.Mode mode)
setDigitalChannelMode
in interface DigitalChannelController
public boolean getDigitalChannelState(int channel)
DigitalChannelController
getDigitalChannelState
in interface DigitalChannelController
channel
- channelpublic void setDigitalChannelState(int channel, boolean state)
DigitalChannelController
The behavior of this method is undefined for digital channels in INPUT mode.
setDigitalChannelState
in interface DigitalChannelController
channel
- channelstate
- true to set; false to unsetpublic int getDigitalInputStateByte()
DeviceInterfaceModule
getDigitalInputStateByte
in interface DeviceInterfaceModule
public byte getDigitalIOControlByte()
DeviceInterfaceModule
getDigitalIOControlByte
in interface DeviceInterfaceModule
public void setDigitalIOControlByte(byte input)
DeviceInterfaceModule
setDigitalIOControlByte
in interface DeviceInterfaceModule
input
- - the desired setting for each channel pin.public byte getDigitalOutputStateByte()
DeviceInterfaceModule
getDigitalOutputStateByte
in interface DeviceInterfaceModule
public void setDigitalOutputByte(byte input)
DeviceInterfaceModule
setDigitalOutputByte
in interface DeviceInterfaceModule
input
- with output state of the digital pins.public boolean getLEDState(int channel)
DeviceInterfaceModule
getLEDState
in interface DeviceInterfaceModule
public void setLED(int channel, boolean set)
DeviceInterfaceModule
setLED
in interface DeviceInterfaceModule
channel
- - int indicating the ID of the LED.set
- - byte containing the desired setting.public void setAnalogOutputVoltage(int port, int voltage)
AnalogOutputController
setAnalogOutputVoltage
in interface AnalogOutputController
port
- channel 0 or 1voltage
- voltage value in the correct range.public void setAnalogOutputFrequency(int port, int freq)
AnalogOutputController
setAnalogOutputFrequency
in interface AnalogOutputController
port
- 1 or 0freq
- output frequency in the range1-5,000Hzpublic void setAnalogOutputMode(int port, byte mode)
AnalogOutputController
setAnalogOutputMode
in interface AnalogOutputController
port
- 0 or 1mode
- voltage, sine, square, or trianglepublic void setPulseWidthOutputTime(int port, int usDuration)
PWMOutputController
setPulseWidthOutputTime
in interface PWMOutputController
port
- port this device is attached tousDuration
- pulse width for the port in microseconds.public void setPulseWidthPeriod(int port, int usPeriod)
PWMOutputController
setPulseWidthPeriod
in interface PWMOutputController
port
- port this device is attached tousPeriod
- pulse repetition period in microseconds.public int getPulseWidthOutputTime(int port)
PWMOutputController
getPulseWidthOutputTime
in interface PWMOutputController
port
- port this device is attached topublic int getPulseWidthPeriod(int port)
PWMOutputController
getPulseWidthPeriod
in interface PWMOutputController
port
- port this device is attached topublic void enableI2cReadMode(int physicalPort, I2cAddr i2cAddress, int memAddress, int length)
I2cController
enableI2cReadMode
in interface I2cController
physicalPort
- the port the device is attached toi2cAddress
- the i2c address of the devicememAddress
- mem address at which to start readinglength
- number of bytes to readpublic void enableI2cWriteMode(int physicalPort, I2cAddr i2cAddress, int memAddress, int length)
I2cController
enableI2cWriteMode
in interface I2cController
physicalPort
- the port the device is attached toi2cAddress
- the i2c address of the devicememAddress
- the memory address at which to start writinglength
- number of bytes to readpublic byte[] getCopyOfReadBuffer(int physicalPort)
I2cController
getCopyOfReadBuffer
in interface I2cController
physicalPort
- the port the device is attached topublic byte[] getCopyOfWriteBuffer(int physicalPort)
I2cController
getCopyOfWriteBuffer
in interface I2cController
physicalPort
- the port the device is attached topublic void copyBufferIntoWriteBuffer(int physicalPort, byte[] buffer)
I2cController
copyBufferIntoWriteBuffer
in interface I2cController
physicalPort
- the port the device is attached tobuffer
- buffer to copypublic void setI2cPortActionFlag(int port)
I2cController
setI2cPortActionFlag
in interface I2cController
port
- physical port number on the deviceI2cController.clearI2cPortActionFlag(int)
public void clearI2cPortActionFlag(int port)
I2cController
clearI2cPortActionFlag
in interface I2cController
port
- physical port number on the deviceI2cController.setI2cPortActionFlag(int)
public boolean isI2cPortActionFlagSet(int port)
I2cController
isI2cPortActionFlagSet
in interface I2cController
port
- physical port number on the devicepublic void readI2cCacheFromController(int port)
I2cController
readI2cCacheFromController
in interface I2cController
port
- physical port number on the devicepublic void writeI2cCacheToController(int port)
I2cController
writeI2cCacheToController
in interface I2cController
port
- physical port number on the devicepublic void writeI2cPortFlagOnlyToController(int port)
I2cController
writeI2cPortFlagOnlyToController
in interface I2cController
port
- physical port number on the devicepublic boolean isI2cPortInReadMode(int port)
I2cController
isI2cPortInReadMode
in interface I2cController
port
- physical port number on the devicepublic boolean isI2cPortInWriteMode(int port)
I2cController
isI2cPortInWriteMode
in interface I2cController
port
- physical port number on the devicepublic boolean isI2cPortReady(int port)
I2cController
isI2cPortReady
in interface I2cController
port
- physical port number on the devicepublic java.util.concurrent.locks.Lock getI2cReadCacheLock(int port)
I2cController
This is needed if you are accessing the read cache directly. The read cache lock needs to be acquired before attempting to interact with the read cache
getI2cReadCacheLock
in interface I2cController
port
- physical port number on the devicepublic java.util.concurrent.locks.Lock getI2cWriteCacheLock(int port)
I2cController
This is needed if you are accessing the write cache directly. The write cache lock needs to be acquired before attempting to interact with the write cache
getI2cWriteCacheLock
in interface I2cController
port
- physical port number on the devicepublic byte[] getI2cReadCache(int port)
I2cController
Please lock the cache before accessing it.
getI2cReadCache
in interface I2cController
port
- physical port number on the devicepublic TimeWindow getI2cReadCacheTimeWindow(int port)
I2cController
getI2cReadCacheTimeWindow
in interface I2cController
port
- physical port number on the devicepublic byte[] getI2cWriteCache(int port)
I2cController
Please lock the cache before accessing it.
getI2cWriteCache
in interface I2cController
port
- physical port number on the devicepublic int getMaxI2cWriteLatency(int port)
I2cController
getMaxI2cWriteLatency
in interface I2cController
public void registerForI2cPortReadyCallback(I2cController.I2cPortReadyCallback callback, int port)
I2cController
registerForI2cPortReadyCallback
in interface I2cController
callback
- register a callbackport
- port to be monitoredpublic I2cController.I2cPortReadyCallback getI2cPortReadyCallback(int port)
I2cController
getI2cPortReadyCallback
in interface I2cController
port
- the port of interestpublic void deregisterForPortReadyCallback(int port)
I2cController
deregisterForPortReadyCallback
in interface I2cController
port
- port no longer being monitored.@Deprecated public void readI2cCacheFromModule(int port)
I2cController
readI2cCacheFromModule
in interface I2cController
port
- physical port number on the device@Deprecated public void writeI2cCacheToModule(int port)
I2cController
writeI2cCacheToModule
in interface I2cController
port
- physical port number on the device@Deprecated public void writeI2cPortFlagOnlyToModule(int port)
I2cController
writeI2cPortFlagOnlyToModule
in interface I2cController
port
- physical port number on the devicepublic void readComplete() throws java.lang.InterruptedException
readComplete
in interface ReadWriteRunnable.Callback
readComplete
in class ModernRoboticsUsbDevice
java.lang.InterruptedException
public static void throwIfModernRoboticsI2cAddressIsInvalid(I2cAddr newAddress)