Exemple #1
0
 /// <summary>
 /// Empty stream buffer into UI
 /// </summary>
 public static void Update()
 {
     if (EmulatorManager.IsTryingToRunRobotCode() && !EmulatorManager.IsRobotCodeRestarting() && !printStreamOpen) // Start stream if needed
     {
         Task.Factory.StartNew(OpenPrintStream, TaskCreationOptions.LongRunning);
     }
     while (newPrintQueue.Count > 0)
     {
         AddLine(newPrintQueue.Dequeue());
     }
 }
Exemple #2
0
        public void Update()
        {
            if (shouldBeActive)                                                                                             // Handle hiding the panel. Other UIs don't hide automatically, but this one is big and should.
            {
                if (InputControl.GetButtonDown(new KeyMapping("Hide Menu", KeyCode.H, Input.Enums.KeyModifier.Ctrl), true)) // TODO make global control
                {
                    mainPanel.SetActive(!mainPanel.activeSelf);
                }
            }
            if (mainPanel.activeSelf) // Update rest of UI
            {
                bool anyFieldfocused = false;
                foreach (var group in robotIOGroups)
                {
                    anyFieldfocused = anyFieldfocused || group.Update();
                }
                if (anyFieldfocused != lastAnyFieldfocused)
                {
                    InputControl.freeze = anyFieldfocused; // Prevent users inputting values from triggering controls
                    lastAnyFieldfocused = anyFieldfocused;
                }

                if (miniCamera == null)
                {
                    InitMiniCamera();
                }
                UpdateMiniCamera();
                Resize();

                DynamicCamera.ControlEnabled = false;
            }
            else if (lastActive)
            {
                DynamicCamera.ControlEnabled = true;
            }
            if (enablePrints && EmulatorManager.IsTryingToRunRobotCode() && !EmulatorManager.IsRobotCodeRestarting()) // Update robot prints
            {
                RobotPrintManager.Update();
            }

            lastActive = mainPanel.activeSelf;
        }
 /// <summary>
 /// Indicator for VM connection status
 /// </summary>
 private System.Collections.IEnumerator UpdateVMConnectionStatus() // TODO move to emulation toolbar
 {
     while (true)
     {
         if (EmulatorManager.IsVMConnected())
         {
             VMConnectionStatusImage.sprite = EmulatorConnection;
             if (EmulatorNetworkConnection.Instance.IsConnected())
             {
                 VMConnectionStatusMessage.text = "Connected";
             }
             else
             {
                 VMConnectionStatusMessage.text = "Ready";
                 RobotDisabled();
             }
             if (!EmulatorManager.IsRunningRobotCodeRunner() && !EmulatorManager.IsTryingToRunRobotCode() && !EmulatorManager.IsRobotCodeRestarting())
             {
                 EmulatorManager.RestartRobotCode();
             }
         }
         else
         {
             if (!EmulatorManager.IsVMInstalled())
             {
                 VMConnectionStatusImage.sprite = EmulatorNotInstalled;
                 VMConnectionStatusMessage.text = "Not Installed";
             }
             else if (!EmulatorManager.IsVMRunning())
             {
                 VMConnectionStatusImage.sprite = StartEmulator;
                 VMConnectionStatusMessage.text = "Start Emulator";
             }
             else
             {
                 VMConnectionStatusImage.sprite = EmulatorConnection;
                 VMConnectionStatusMessage.text = "Starting";
             }
             RobotDisabled();
         }
         yield return(new WaitForSeconds(1.0f)); // s
     }
 }
Exemple #4
0
 /// <summary>
 /// Begin reading robot print-outs into the string buffer
 /// </summary>
 private static void OpenPrintStream()
 {
     printStreamOpen = true;
     if (remoteReader == null)
     {
         remoteReader = EmulatorManager.CreateRobotOutputStream();
     }
     while (remoteReader != null && EmulatorManager.IsTryingToRunRobotCode() && !EmulatorManager.IsRobotCodeRestarting() && EmulatorManager.IsRobotOutputStreamGood() && Instance && RobotIOPanel.Instance.enablePrints)
     {
         try
         {
             int r = remoteReader.Read();
             if (r != -1)
             {
                 char c = (char)r;
                 if (c == '\n' && (newPrintBuffer.Length > MIN_LINE_BUFFER_LEN || timeoutTimer.ElapsedMilliseconds > TIMEOUT)) // Concatenate multiple short prints if in quick enough succession
                 {
                     timeoutTimer.Restart();
                     newPrintQueue.Enqueue(newPrintBuffer);
                     newPrintBuffer = "";
                 }
                 else
                 {
                     newPrintBuffer += c;
                 }
             }
         }
         catch (Exception e)
         {
             Debug.Log(e.ToString());
             break;
         }
     }
     if (remoteReader != null)
     {
         remoteReader.Dispose();
         remoteReader = null;
         if (EmulatorManager.IsRobotOutputStreamGood())
         {
             EmulatorManager.CloseRobotOutputStream();
         }
     }
     printStreamOpen = false;
 }