Пример #1
0
        private void OnSimCamChange(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (SimCamBox.SelectedItem != null)
                {
                    ComboBoxItem item = SimCamBox.SelectedItem as ComboBoxItem;
                    if (item != null && item.Tag != null && item.Tag is CameraInfo)
                    {
                        // Set the current camera, subscribe it if it has not yet
                        // been subscribed, and set it's frame update rate.
                        curCamera = (CameraInfo)item.Tag;

                        // Clear the display in case the new images are smaller
                        initBitmap();
                    }
                }
            }
            catch (Exception err)
            {
                GUIUtilities.ReportUnexpectedException(err);
            }
        }
Пример #2
0
 /// <summary>
 /// Helper method to clear the populated sensors so they can be
 /// repopulated.  This is currently not used, but was intended to
 /// be called when the connected robot changes.
 /// </summary>
 private void reset()
 {
     if (livePanelList.Count > 0)
     {
         Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                           new ThreadStart(delegate()
         {
             try
             {
                 foreach (var pi in livePanelList)
                 {
                     servicePanel.Children.Remove(pi.Group);
                 }
             }
             catch (Exception e)
             {
                 GUIUtilities.ReportUnexpectedException(e);
             }
         }));
     }
     panelList = origPanelList;
     livePanelList.Clear();
 }
Пример #3
0
        private void SizeChangeHandler(Size size)
        {
            // Flush size change messages
            while (sizeChangePort.Test() != null)
            {
            }
            ;

            // Resize the bitmap for displaying camera images
            try
            { initBitmap(); }
            catch (Exception e) { GUIUtilities.ReportUnexpectedException(e); }

            Thread.Sleep(50);

            // Activate new receiver
            try
            {
                // This try is here because this will throw an exception when DSS shuts down.
                Arbiter.Activate(queue, Arbiter.Receive(false, sizeChangePort, SizeChangeHandler));
            }
            catch (Exception) { }
        }
Пример #4
0
 private void OnMouseDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         if (!SimulatorContainer.IsMouseCaptured)
         {
             if (e.ChangedButton == MouseButton.Left)
             {
                 dragType = DragType.LOOK;
             }
             else if (e.ChangedButton == MouseButton.Right)
             {
                 dragType = DragType.MOVE;
             }
             var p = e.GetPosition(SimulatorContainer);
             mouseStart = new Vector2((float)p.X, (float)p.Y);
             SimulatorContainer.CaptureMouse();
         }
     }
     catch (Exception err)
     {
         GUIUtilities.ReportUnexpectedException(err);
     }
 }
Пример #5
0
        /// <summary>
        /// Helper method that checks for new sensor services having started.
        /// This is called every few seconds by the polling thread.
        /// </summary>
        private void checkNewPanels()
        {
            List <ServicePanelInfo> toRemove = new List <ServicePanelInfo>();
            List <Thread>           threads  = new List <Thread>();

            foreach (var pi in panelList)
            {
                var    myPi = pi;
                Thread t    = new Thread(new ThreadStart(
                                             delegate()
                {
                    try
                    {
                        //Console.WriteLine("Adding " + myPi.Name);
                        Robot.GetNames(myPi.Name);
                        lock (toRemove) { toRemove.Add(myPi); }
                    }
                    catch (Exception) { }
                }));
                t.Start();
                threads.Add(t);
            }
            foreach (var t in threads)
            {
                t.Join();
            }
            ManualResetEvent signal = new ManualResetEvent(false);

            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                   new ThreadStart(delegate()
            {
                try
                {
                    var newLivePanelList = new List <ServicePanelInfo>(livePanelList);
                    foreach (var pi in toRemove)
                    {
                        pi.Meters = new CircleMeters()
                        {
                            //Width = 200,
                            //Height = 30,
                        };
                        var myPi = pi;
                        pi.Meters.ValueChange += (CircleMeters.ValueChangeHandler)
                                                 delegate(object sender, Myro.GUI.WPFControls.CircleMeters.ValueChangeArgs e)
                        {
                            Robot.Set(myPi.Name, e.Index, e.Value);
                        };
                        pi.Meters.SetColor(pi.Color);
                        pi.Group = new GroupBox()
                        {
                            Header = pi.Description,
                            Margin = new Thickness(5.0, 5.0, 5.0, 10.0),
                            HorizontalAlignment        = HorizontalAlignment.Stretch,
                            VerticalAlignment          = VerticalAlignment.Top,
                            HorizontalContentAlignment = HorizontalAlignment.Stretch,
                            Content = pi.Meters
                        };
                        newLivePanelList.Add(pi);
                        panelList.Remove(pi);
                        servicePanel.Children.Add(pi.Group);
                    }
                    // Swap in reference to new list, changed atomically because updateLoop
                    // may be using the list to update sensor readings
                    livePanelList = newLivePanelList;
                }
                catch (Exception e)
                {
                    GUIUtilities.ReportUnexpectedException(e);
                    //Console.WriteLine(e.ToString());
                    //throw;
                }
                finally { signal.Set(); }
            }));
            signal.WaitOne();
        }
Пример #6
0
 private void OnSnapClick(object sender, RoutedEventArgs e)
 {
     if (takePictureThread == null)
     {
         SnapshotButton.IsEnabled = false;
         takePictureThread        = new Thread(new ThreadStart(delegate()
         {
             try
             {
                 takePictureHelper();
             }
             catch (Exception err)
             {
                 Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                        new ThreadStart(delegate() { IsActive = false; GUIUtilities.ReportUnexpectedException(err); }));
             }
             finally
             {
                 Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                        new ThreadStart(delegate() { SnapshotButton.IsEnabled = true; }));
                 takePictureThread = null;
             }
         }));
         takePictureThread.Start();
     }
 }
Пример #7
0
 private void updateLoop()
 {
     while (!shouldExit)
     {
         if (IsActive && curType != null)
         {
             try
             {
                 if (setDarknessRequest >= 0)
                 {
                     if (setDarknessRequest == 256)
                     {
                         Robot.autoCamera();
                     }
                     else
                     {
                         Robot.darkenCamera((byte)setDarknessRequest);
                     }
                     setDarknessRequest = -1;
                 }
                 takePictureHelper();
             }
             catch (Exception e)
             {
                 Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                        new ThreadStart(delegate() { IsActive = false; GUIUtilities.ReportUnexpectedException(e); }));
             }
         }
         Thread.Sleep(delayMs);
     }
 }