Update sensors to not use direct byte buffers.

This commit is contained in:
Peter Johnson
2017-11-16 22:40:24 -08:00
parent 479d0beb5a
commit a20474bfc7
4 changed files with 8 additions and 8 deletions

View File

@@ -144,7 +144,7 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindow
* @return Acceleration of the ADXL345 in Gs.
*/
public double getAcceleration(Axes axis) {
ByteBuffer rawAccel = ByteBuffer.allocateDirect(2);
ByteBuffer rawAccel = ByteBuffer.allocate(2);
m_i2c.read(kDataRegister + axis.value, 2, rawAccel);
// Sensor is little endian... swap bytes
@@ -159,7 +159,7 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindow
*/
public AllAxes getAccelerations() {
AllAxes data = new AllAxes();
ByteBuffer rawData = ByteBuffer.allocateDirect(6);
ByteBuffer rawData = ByteBuffer.allocate(6);
m_i2c.read(kDataRegister, 6, rawData);
// Sensor is little endian... swap bytes

View File

@@ -156,7 +156,7 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer, LiveWindow
* @return Acceleration of the ADXL345 in Gs.
*/
public double getAcceleration(ADXL345_SPI.Axes axis) {
ByteBuffer transferBuffer = ByteBuffer.allocateDirect(3);
ByteBuffer transferBuffer = ByteBuffer.allocate(3);
transferBuffer.put(0,
(byte) ((kAddress_Read | kAddress_MultiByte | kDataRegister) + axis.value));
m_spi.transaction(transferBuffer, transferBuffer, 3);
@@ -174,7 +174,7 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer, LiveWindow
public ADXL345_SPI.AllAxes getAccelerations() {
ADXL345_SPI.AllAxes data = new ADXL345_SPI.AllAxes();
if (m_spi != null) {
ByteBuffer dataBuffer = ByteBuffer.allocateDirect(7);
ByteBuffer dataBuffer = ByteBuffer.allocate(7);
// Select the data address.
dataBuffer.put(0, (byte) (kAddress_Read | kAddress_MultiByte | kDataRegister));
m_spi.transaction(dataBuffer, dataBuffer, 7);

View File

@@ -89,7 +89,7 @@ public class ADXL362 extends SensorBase implements Accelerometer, LiveWindowSend
m_spi.setChipSelectActiveLow();
// Validate the part ID
ByteBuffer transferBuffer = ByteBuffer.allocateDirect(3);
ByteBuffer transferBuffer = ByteBuffer.allocate(3);
transferBuffer.put(0, kRegRead);
transferBuffer.put(1, kPartIdRegister);
m_spi.transaction(transferBuffer, transferBuffer, 3);
@@ -171,7 +171,7 @@ public class ADXL362 extends SensorBase implements Accelerometer, LiveWindowSend
if (m_spi == null) {
return 0.0;
}
ByteBuffer transferBuffer = ByteBuffer.allocateDirect(4);
ByteBuffer transferBuffer = ByteBuffer.allocate(4);
transferBuffer.put(0, kRegRead);
transferBuffer.put(1, (byte) (kDataRegister + axis.value));
m_spi.transaction(transferBuffer, transferBuffer, 4);
@@ -189,7 +189,7 @@ public class ADXL362 extends SensorBase implements Accelerometer, LiveWindowSend
public ADXL362.AllAxes getAccelerations() {
ADXL362.AllAxes data = new ADXL362.AllAxes();
if (m_spi != null) {
ByteBuffer dataBuffer = ByteBuffer.allocateDirect(8);
ByteBuffer dataBuffer = ByteBuffer.allocate(8);
// Select the data address.
dataBuffer.put(0, kRegRead);
dataBuffer.put(1, kDataRegister);

View File

@@ -111,7 +111,7 @@ public class ADXRS450_Gyro extends GyroBase implements Gyro, PIDSource, LiveWind
int cmdhi = 0x8000 | (reg << 1);
boolean parity = calcParity(cmdhi);
ByteBuffer buf = ByteBuffer.allocateDirect(4);
ByteBuffer buf = ByteBuffer.allocate(4);
buf.order(ByteOrder.BIG_ENDIAN);
buf.put(0, (byte) (cmdhi >> 8));
buf.put(1, (byte) (cmdhi & 0xff));