1010import edu .wpi .grip .core .sockets .SocketHints ;
1111import edu .wpi .grip .core .util .ExceptionWitness ;
1212
13+ import com .google .common .base .CaseFormat ;
1314import com .google .common .collect .ImmutableList ;
1415import com .google .common .eventbus .EventBus ;
1516import com .google .common .eventbus .Subscribe ;
2425/**
2526 * Provides a way to get a {@link Types Type} from a NetworkTable that GRIP is connected to.
2627 */
27- @ XStreamAlias ("grip:NetworkValue " )
28+ @ XStreamAlias ("grip:NetworkTableValue " )
2829public class NetworkTableEntrySource extends Source {
2930
3031 private static final String PATH_PROPERTY = "networktable_path" ;
3132 private static final String TYPE_PROPERTY = "BOOLEAN" ;
3233
34+ private final EventBus eventBus ;
3335 private final OutputSocket output ;
3436 private final String path ;
3537 private final Types type ;
@@ -46,7 +48,7 @@ public enum Types {
4648
4749 @ Override
4850 public String toString () {
49- return super . toString (). charAt ( 0 ) + super . toString (). substring ( 1 ). toLowerCase ( );
51+ return CaseFormat . UPPER_UNDERSCORE . to ( CaseFormat . UPPER_CAMEL , name () );
5052 }
5153
5254 }
@@ -75,12 +77,11 @@ public String toString() {
7577 @ Assisted String path ,
7678 @ Assisted Types type ) {
7779 super (exceptionWitnessFactory );
80+ this .eventBus = eventBus ;
7881 this .path = path ;
7982 this .type = type ;
8083 networkReceiver = networkReceiverFactory .create (path );
8184 output = osf .create (createOutputSocket (type ));
82-
83- networkReceiver .addListener (o -> eventBus .post (new SourceHasPendingUpdateEvent (this )));
8485 }
8586
8687 @ Override
@@ -117,7 +118,7 @@ public Properties getProperties() {
117118
118119 @ Override
119120 public void initialize () {
120- updateOutputSockets ( );
121+ networkReceiver . addListener ( o -> eventBus . post ( new SourceHasPendingUpdateEvent ( this )) );
121122 }
122123
123124 @ Subscribe
@@ -141,7 +142,7 @@ private static SocketHint createOutputSocket(Types type) {
141142 case STRING :
142143 return SocketHints .Outputs .createStringSocketHint (Types .STRING .toString (), "" );
143144 default :
144- throw new IllegalArgumentException ("Invalid NetworkTable source type" );
145+ throw new IllegalArgumentException (type + " is an invalid NetworkTable source type" );
145146 }
146147 }
147148}
0 commit comments