public class SPI extends SensorBase
Modifier and Type | Class and Description |
---|---|
static class |
SPI.Port |
kAnalogInputChannels, kAnalogOutputChannels, kDigitalChannels, kPCMModules, kPDPChannels, kPDPModules, kPwmChannels, kRelayChannels, kSolenoidChannels, kSystemClockTicksPerMicrosecond
Modifier and Type | Method and Description |
---|---|
void |
free()
Free the resources used by this object.
|
void |
freeAccumulator()
Frees the accumulator.
|
double |
getAccumulatorAverage()
Read the average of the accumulated value.
|
int |
getAccumulatorCount()
Read the number of accumulated values.
|
int |
getAccumulatorLastValue()
Read the last value read by the accumulator engine.
|
void |
getAccumulatorOutput(AccumulatorResult result)
Read the accumulated value and the number of accumulated values atomically.
|
long |
getAccumulatorValue()
Read the accumulated value.
|
void |
initAccumulator(double period,
int cmd,
int xferSize,
int validMask,
int validValue,
int dataShift,
int dataSize,
boolean isSigned,
boolean bigEndian)
Initialize the accumulator.
|
int |
read(boolean initiate,
byte[] dataReceived,
int size)
Read a word from the receive FIFO.
|
int |
read(boolean initiate,
java.nio.ByteBuffer dataReceived,
int size)
Read a word from the receive FIFO.
|
void |
resetAccumulator()
Resets the accumulator to zero.
|
void |
setAccumulatorCenter(int center)
Set the center value of the accumulator.
|
void |
setAccumulatorDeadband(int deadband)
Set the accumulator's deadband.
|
void |
setChipSelectActiveHigh()
Configure the chip select line to be active high.
|
void |
setChipSelectActiveLow()
Configure the chip select line to be active low.
|
void |
setClockActiveHigh()
Configure the clock output line to be active high.
|
void |
setClockActiveLow()
Configure the clock output line to be active low.
|
void |
setClockRate(int hz)
Configure the rate of the generated clock signal.
|
void |
setLSBFirst()
Configure the order that bits are sent and received on the wire to be least significant bit
first.
|
void |
setMSBFirst()
Configure the order that bits are sent and received on the wire to be most significant bit
first.
|
void |
setSampleDataOnFalling()
Configure that the data is stable on the falling edge and the data changes on the rising edge.
|
void |
setSampleDataOnRising()
Configure that the data is stable on the rising edge and the data changes on the falling edge.
|
int |
transaction(byte[] dataToSend,
byte[] dataReceived,
int size)
Perform a simultaneous read/write transaction with the device.
|
int |
transaction(java.nio.ByteBuffer dataToSend,
java.nio.ByteBuffer dataReceived,
int size)
Perform a simultaneous read/write transaction with the device
|
int |
write(byte[] dataToSend,
int size)
Write data to the slave device.
|
int |
write(java.nio.ByteBuffer dataToSend,
int size)
Write data to the slave device.
|
checkAnalogInputChannel, checkAnalogOutputChannel, checkDigitalChannel, checkPDPChannel, checkPDPModule, checkPWMChannel, checkRelayChannel, checkSolenoidChannel, checkSolenoidModule, getDefaultSolenoidModule, setDefaultSolenoidModule
public void free()
free
in class SensorBase
public final void setClockRate(int hz)
hz
- The clock rate in Hertz.public final void setMSBFirst()
public final void setLSBFirst()
public final void setClockActiveLow()
public final void setClockActiveHigh()
public final void setSampleDataOnFalling()
public final void setSampleDataOnRising()
public final void setChipSelectActiveHigh()
public final void setChipSelectActiveLow()
public int write(byte[] dataToSend, int size)
If not running in output only mode, also saves the data received on the MISO input during the transfer into the receive FIFO.
public int write(java.nio.ByteBuffer dataToSend, int size)
If not running in output only mode, also saves the data received on the MISO input during the transfer into the receive FIFO.
dataToSend
- The buffer containing the data to send. Must be created using
ByteBuffer.allocateDirect().public int read(boolean initiate, byte[] dataReceived, int size)
Waits for the current transfer to complete if the receive FIFO is empty.
If the receive FIFO is empty, there is no active transfer, and initiate is false, errors.
initiate
- If true, this function pushes "0" into the transmit buffer and initiates a
transfer. If false, this function assumes that data is already in the receive
FIFO from a previous write.public int read(boolean initiate, java.nio.ByteBuffer dataReceived, int size)
Waits for the current transfer to complete if the receive FIFO is empty.
If the receive FIFO is empty, there is no active transfer, and initiate is false, errors.
initiate
- If true, this function pushes "0" into the transmit buffer and initiates
a transfer. If false, this function assumes that data is already in the
receive FIFO from a previous write.dataReceived
- The buffer to be filled with the received data. Must be created using
ByteBuffer.allocateDirect().size
- The length of the transaction, in bytespublic int transaction(byte[] dataToSend, byte[] dataReceived, int size)
dataToSend
- The data to be written out to the devicedataReceived
- Buffer to receive data from the devicesize
- The length of the transaction, in bytespublic int transaction(java.nio.ByteBuffer dataToSend, java.nio.ByteBuffer dataReceived, int size)
dataToSend
- The data to be written out to the device. Must be created using
ByteBuffer.allocateDirect().dataReceived
- Buffer to receive data from the device. Must be created using
ByteBuffer.allocateDirect().size
- The length of the transaction, in bytespublic void initAccumulator(double period, int cmd, int xferSize, int validMask, int validValue, int dataShift, int dataSize, boolean isSigned, boolean bigEndian)
period
- Time between readscmd
- SPI command to send to request dataxferSize
- SPI transfer size, in bytesvalidMask
- Mask to apply to received data for validity checkingvalidValue
- After validMask is applied, required matching value for validity checkingdataShift
- Bit shift to apply to received data to get actual data valuedataSize
- Size (in bits) of data fieldisSigned
- Is data field signed?bigEndian
- Is device big endian?public void freeAccumulator()
public void resetAccumulator()
public void setAccumulatorCenter(int center)
The center value is subtracted from each value before it is added to the accumulator. This is used for the center value of devices like gyros and accelerometers to make integration work and to take the device offset into account when integrating.
public void setAccumulatorDeadband(int deadband)
public int getAccumulatorLastValue()
public long getAccumulatorValue()
public int getAccumulatorCount()
Read the count of the accumulated values since the accumulator was last Reset().
public double getAccumulatorAverage()
public void getAccumulatorOutput(AccumulatorResult result)
This function reads the value and count atomically. This can be used for averaging.
result
- AccumulatorResult object to store the results in.