summaryrefslogtreecommitdiff
path: root/smartdashboard
diff options
context:
space:
mode:
authorJoe Ross <git@rossesmail.com>2014-12-30 18:13:16 -0800
committerJoe Ross <git@rossesmail.com>2014-12-30 20:05:14 -0800
commit1418898a611a9dbc5051840c2252088fcd922b66 (patch)
treec626ce44b5d51d7e0858368a086d83ba333fa738 /smartdashboard
parent323ed0e5dce074774007d1c03f79c34fd55459f0 (diff)
Add Live Window widget for 3 axis acclerometer. Needed to fix artf3902
Change-Id: Ie38fb81a818b7607fabf7f7855249d0e7ea78147
Diffstat (limited to 'smartdashboard')
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java1
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java78
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java30
3 files changed, 109 insertions, 0 deletions
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java
index d6b660f..0faa69d 100644
--- a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java
@@ -22,6 +22,7 @@ public class LiveWindowWidgetRegistrar {
DisplayElementRegistry.registerWidget(EncoderDisplay.class);
DisplayElementRegistry.registerWidget(ServoController.class);
DisplayElementRegistry.registerWidget(PowerDistributionPanel.class);
+ DisplayElementRegistry.registerWidget(ThreeAxisAccelerometer.class);
}
}
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java
new file mode 100644
index 0000000..1d54cf6
--- /dev/null
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java
@@ -0,0 +1,78 @@
+package edu.wpi.first.smartdashboard.livewindow.elements;
+
+import edu.wpi.first.smartdashboard.gui.elements.bindings.AbstractTableWidget;
+import edu.wpi.first.smartdashboard.properties.Property;
+import edu.wpi.first.smartdashboard.types.DataType;
+import edu.wpi.first.smartdashboard.types.named.ThreeAxisAccelerometerType;
+import edu.wpi.first.wpilibj.tables.ITableListener;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import javax.swing.JLabel;
+
+
+/**
+ * Displays the X, Y and Z accelerations from a 3 axis accelerometer
+ */
+public class ThreeAxisAccelerometer extends AbstractTableWidget implements ITableListener {
+
+ public static final DataType[] TYPES = {ThreeAxisAccelerometerType.get()};
+
+ private final UneditableNumberField x = new UneditableNumberField();
+ private final UneditableNumberField y = new UneditableNumberField();
+ private final UneditableNumberField z = new UneditableNumberField();
+ private JLabel xLabel;
+ private JLabel yLabel;
+ private JLabel zLabel;
+
+ /**
+ * @inheritdoc
+ */
+ public void init() {
+ setLayout(new GridBagLayout());
+ GridBagConstraints c = new GridBagConstraints();
+
+ nameTag = new NameTag(getFieldName());
+ add(nameTag);
+
+ c.gridy=1;
+ c.gridx=0;
+ xLabel = new JLabel("X");
+ add(xLabel, c);
+ c.gridx=1;
+ x.setFocusable(false);
+ setNumberBinding("X", x);
+ x.setColumns(10);
+ add(x,c);
+
+ c.gridy=2;
+ c.gridx=0;
+ yLabel = new JLabel("Y");
+ add(yLabel, c);
+ c.gridx=1;
+ y.setFocusable(false);
+ setNumberBinding("Y", y);
+ y.setColumns(10);
+ add(y,c);
+
+ c.gridy=3;
+ c.gridx=0;
+ zLabel = new JLabel("Z");
+ add(zLabel, c);
+ c.gridx=1;
+ z.setFocusable(false);
+ setNumberBinding("Z", z);
+ z.setColumns(10);
+ add(z,c);
+
+ setMaximumSize(new Dimension(Integer.MAX_VALUE, getPreferredSize().height));
+
+ revalidate();
+ repaint();
+ }
+
+ @Override
+ public void propertyChanged(Property property) {
+ }
+
+}
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java b/smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java
new file mode 100644
index 0000000..d79a690
--- /dev/null
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java
@@ -0,0 +1,30 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package edu.wpi.first.smartdashboard.types.named;
+
+import edu.wpi.first.smartdashboard.livewindow.elements.ThreeAxisAccelerometer;
+import edu.wpi.first.smartdashboard.types.NamedDataType;
+
+/**
+ *
+ * @author Sam
+ */
+public class ThreeAxisAccelerometerType extends NamedDataType {
+
+ public static final String LABEL = "3AxisAccelerometer";
+
+ private ThreeAxisAccelerometerType() {
+ super(LABEL, ThreeAxisAccelerometer.class);
+ }
+
+ public static NamedDataType get() {
+ if (NamedDataType.get(LABEL) != null) {
+ return NamedDataType.get(LABEL);
+ } else {
+ return new ThreeAxisAccelerometerType();
+ }
+ }
+
+} \ No newline at end of file