6
6
7
7
import com .stuypulse .stuylib .streams .IStream ;
8
8
9
- import edu .wpi .first .networktables .DoubleEntry ;
10
- import edu .wpi .first .networktables .DoubleTopic ;
11
- import edu .wpi .first .networktables .NetworkTableInstance ;
9
+ import edu .wpi .first .networktables .NetworkTablesJNI ;
12
10
import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
13
11
14
12
/**
18
16
*
19
17
* @author Sam (sam.belliveau@gmail.com)
20
18
*/
21
- public class SmartNumber extends Number implements IStream {
19
+ public final class SmartNumber extends Number implements IStream {
22
20
23
21
private static final long serialVersionUID = 1L ;
24
22
25
23
/** The ID / Name for the value on {@link SmartDashboard}. */
26
- private final DoubleEntry mEntry ;
24
+ private final int mHandle ;
27
25
28
26
/** The default value that the {@link SmartDashboard} value was set too. */
29
27
private final double mDefaultValue ;
30
28
31
- /**
32
- * Creates a {@link SmartNumber} with a DoubleEntry instead of a value for {@link
33
- * SmartDashboard}. This allows you to put items on things like {@link
34
- * edu.wpi.first.wpilibj.shuffleboard.Shuffleboard}, without having to use a raw {@link
35
- * DoubleEntry}.
36
- *
37
- * @param entry the {@link DoubleEntry} the {@link SmartNumber} should be set to.
38
- * @param value the default value of the {@link SmartNumber}
39
- */
40
- public SmartNumber (DoubleEntry entry , double value ) {
41
- mEntry = entry ;
42
- mDefaultValue = value ;
43
- mEntry .setDefault (value );
44
- }
45
-
46
- /**
47
- * Creates a {@link SmartNumber} with a DoubleTopic instead of a value for {@link
48
- * SmartDashboard}. This allows you to put items on things like {@link
49
- * edu.wpi.first.wpilibj.shuffleboard.Shuffleboard}, without having to use a raw {@link
50
- * DoubleTopic}.
51
- *
52
- * @param topic the {@link DoubleTopic} the {@link SmartNumber} should be set to.
53
- * @param value the default value of the {@link SmartNumber}
54
- */
55
- public SmartNumber (DoubleTopic topic , double value ) {
56
- mEntry = topic .getEntry (value );
57
- mDefaultValue = value ;
58
- mEntry .setDefault (value );
59
- }
60
-
61
29
/**
62
30
* Creates a SmartNumber with the element name and a default value. The value on {@link
63
31
* SmartDashboard} will be reset to the default value on initialization.
@@ -66,14 +34,14 @@ public SmartNumber(DoubleTopic topic, double value) {
66
34
* @param value the default / initialization value for the value
67
35
*/
68
36
public SmartNumber (String id , double value ) {
69
- this (
70
- NetworkTableInstance . getDefault (). getTable ( "SmartDashboard" ). getDoubleTopic ( id ),
71
- value );
37
+ mHandle = NetworkTablesJNI . getEntry ( NetworkTablesJNI . getDefaultInstance (), "SmartDashboard/" + id );
38
+ mDefaultValue = value ;
39
+ reset ( );
72
40
}
73
41
74
42
/** @return the value of the number from SmartDashboard */
75
43
public double get () {
76
- return mEntry . get ( );
44
+ return NetworkTablesJNI . getDouble ( mHandle , mDefaultValue );
77
45
}
78
46
79
47
/** @return the default value of the number */
@@ -83,7 +51,7 @@ public double getDefault() {
83
51
84
52
/** @param value what the value on {@link SmartDashboard} will be set to */
85
53
public void set (Number value ) {
86
- mEntry . set ( value .doubleValue ());
54
+ NetworkTablesJNI . setDouble ( mHandle , 0 , value .doubleValue ());
87
55
}
88
56
89
57
/** Resets the value on {@link SmartDashboard} to the default value */
0 commit comments