@@ -535,30 +535,37 @@ private void updateControlsVisibility(HBox controls) {
535535 }
536536
537537 private void setSimulationMode (String mode ) {
538+ if (!NetworkTablesClient .isConnected ()) {
539+ NetworkTablesClient .connect ();
540+ new Thread (() -> {
541+ try {
542+ long start = System .currentTimeMillis ();
543+ while (!NetworkTablesClient .isConnected () && (System .currentTimeMillis () - start ) < 1200 ) {
544+ Thread .sleep (25 );
545+ }
546+ } catch (InterruptedException e ) {
547+ Thread .currentThread ().interrupt ();
548+ }
549+ writeSimulationMode (mode );
550+ }, "FunkyLog-SetSimMode" ).start ();
551+ } else {
552+ writeSimulationMode (mode );
553+ }
554+ }
555+
556+ private void writeSimulationMode (String mode ) {
538557 try {
539558 NetworkTableInstance instance = NetworkTableInstance .getDefault ();
540- if (instance == null ) {
541- return ;
542- }
543-
544- int modeValue = 0 ;
545- if (mode .equals ("disabled" )) {
546- modeValue = 0 ;
547- } else if (mode .equals ("teleop" )) {
548- modeValue = 1 ;
549- } else if (mode .equals ("auto" )) {
550- modeValue = 2 ;
551- } else if (mode .equals ("test" )) {
552- modeValue = 3 ;
553- }
559+ if (instance == null ) return ;
554560
555561 NetworkTable funkyFMSTable = instance .getTable ("FunkyFMS" );
556- if (funkyFMSTable != null ) {
557- System .out .println ("FunkyLogs: Setting simulation controlMode to " + modeValue + " (" + mode + ")" );
558- NetworkTableEntry controlModeEntry = funkyFMSTable .getEntry ("controlMode" );
559- controlModeEntry .setInteger (modeValue );
560- instance .flush ();
561- }
562+ if (funkyFMSTable == null ) return ;
563+ long controlMode = 0 ;
564+ if ("teleop" .equals (mode )) controlMode = 1 ;
565+ else if ("auto" .equals (mode )) controlMode = 2 ;
566+ else if ("test" .equals (mode )) controlMode = 3 ;
567+ funkyFMSTable .getEntry ("controlMode" ).setDouble ((double ) controlMode );
568+ instance .flush ();
562569 } catch (Exception e ) {
563570 System .err .println ("Error setting simulation mode: " + e .getMessage ());
564571 }
@@ -590,33 +597,23 @@ private void updateSimulationButtons(Button[] buttons, String[] currentMode, HBo
590597 return ;
591598 }
592599
593- NetworkTable fmsTable = instance .getTable ("FMSInfo " );
594- if (fmsTable == null ) {
600+ NetworkTable funkyFMS = instance .getTable ("FunkyFMS " );
601+ if (funkyFMS == null ) {
595602 return ;
596603 }
597604
598- NetworkTableEntry fmsControlDataEntry = fmsTable .getEntry ("FMSControlData" );
599- String mode = "disabled" ;
600-
601- if (fmsControlDataEntry != null && fmsControlDataEntry .exists ()) {
602- Number modeValueNumber = fmsControlDataEntry .getNumber (32.0 );
603- int modeValue = modeValueNumber .intValue ();
604-
605- boolean isEnabled = (modeValue & 1 ) != 0 ;
606- boolean isAuto = (modeValue & 2 ) != 0 ;
607- boolean isTest = (modeValue & 4 ) != 0 ;
608-
609- if (!isEnabled ) {
610- mode = "disabled" ;
611- } else if (isTest ) {
612- mode = "test" ;
613- } else if (isAuto ) {
614- mode = "auto" ;
615- } else {
616- mode = "teleop" ;
617- }
605+ NetworkTableEntry controlModeEntry = funkyFMS .getEntry ("controlMode" );
606+ long cm = 0 ;
607+ if (controlModeEntry != null ) {
608+ cm = (long ) controlModeEntry .getDouble (0.0 );
618609 }
619610
611+ String mode ;
612+ if (cm == 1 ) mode = "teleop" ;
613+ else if (cm == 2 ) mode = "auto" ;
614+ else if (cm == 3 ) mode = "test" ;
615+ else mode = "disabled" ;
616+
620617 final String finalMode = mode ;
621618 Platform .runLater (() -> {
622619 String baseStyle = "-fx-font-size: 11px; " +
0 commit comments