mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Merge "Make 3 axis Accelerometers work in LiveWindow. Fixes artf3902."
This commit is contained in:
@@ -10,12 +10,15 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dtjones
|
||||
*/
|
||||
public class ADXL345_I2C extends SensorBase implements Accelerometer {
|
||||
public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindowSendable {
|
||||
|
||||
private static final byte kAddress = 0x1D;
|
||||
private static final byte kPowerCtlRegister = 0x2D;
|
||||
@@ -65,6 +68,7 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer {
|
||||
setRange(range);
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C);
|
||||
LiveWindow.addSensor("ADXL345_I2C", port.getValue(), this);
|
||||
}
|
||||
|
||||
/** {inheritdoc} */
|
||||
@@ -146,5 +150,32 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer {
|
||||
return data;
|
||||
}
|
||||
|
||||
// TODO: Support LiveWindow
|
||||
public String getSmartDashboardType(){
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
private ITable m_table;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void initTable(ITable subtable) {
|
||||
m_table = subtable;
|
||||
updateTable();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void updateTable() {
|
||||
if (m_table != null) {
|
||||
m_table.putNumber("X", getX());
|
||||
m_table.putNumber("Y", getY());
|
||||
m_table.putNumber("Z", getZ());
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ITable getTable(){
|
||||
return m_table;
|
||||
}
|
||||
|
||||
public void startLiveWindowMode() {}
|
||||
public void stopLiveWindowMode() {}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,16 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dtjones
|
||||
* @author mwills
|
||||
*/
|
||||
public class ADXL345_SPI extends SensorBase implements Accelerometer {
|
||||
public class ADXL345_SPI extends SensorBase implements Accelerometer, LiveWindowSendable {
|
||||
private static final int kPowerCtlRegister = 0x2D;
|
||||
private static final int kDataFormatRegister = 0x31;
|
||||
private static final int kDataRegister = 0x32;
|
||||
@@ -75,6 +78,7 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer {
|
||||
public ADXL345_SPI(SPI.Port port, Range range) {
|
||||
m_spi = new SPI(port);
|
||||
init(range);
|
||||
LiveWindow.addSensor("ADXL345_SPI", port.getValue(), this);
|
||||
}
|
||||
|
||||
public void free(){
|
||||
@@ -190,4 +194,33 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getSmartDashboardType(){
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
private ITable m_table;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void initTable(ITable subtable) {
|
||||
m_table = subtable;
|
||||
updateTable();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void updateTable() {
|
||||
if (m_table != null) {
|
||||
m_table.putNumber("X", getX());
|
||||
m_table.putNumber("Y", getY());
|
||||
m_table.putNumber("Z", getZ());
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ITable getTable(){
|
||||
return m_table;
|
||||
}
|
||||
|
||||
public void startLiveWindowMode() {}
|
||||
public void stopLiveWindowMode() {}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class BuiltInAccelerometer implements Accelerometer, LiveWindowSendable
|
||||
public BuiltInAccelerometer(Range range) {
|
||||
setRange(range);
|
||||
UsageReporting.report(tResourceType.kResourceType_Accelerometer, 0, 0, "Built-in accelerometer");
|
||||
LiveWindow.addSensor("BuiltInAccel", 0, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +84,7 @@ public class BuiltInAccelerometer implements Accelerometer, LiveWindowSendable
|
||||
}
|
||||
|
||||
public String getSmartDashboardType(){
|
||||
return "Accelerometer";
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
private ITable m_table;
|
||||
|
||||
Reference in New Issue
Block a user