Пример #1
0
        public void DeviceLost(IADevice iaDevice)
        {
            List <PairablePerson> pairablePersons = locator.Persons.OfType <PairablePerson>().ToList <PairablePerson>();
            List <PairableDevice> pairableDevices = locator.Devices.OfType <PairableDevice>().ToList <PairableDevice>();

            // Find and remove the pairable device from the Locator's list of devices
            PairableDevice pairableDevice = pairableDevices.Find(d => d.Identifier.Equals(iaDevice.Name));

            locator.Devices.Remove(pairableDevice);


            // If the device was paired, we mark its corresponding person unpaired.
            PairablePerson person = pairablePersons.Find(p => p.Identifier.Equals(pairableDevice.HeldByPersonIdentifier));

            if (person != null)
            {
                //Remove the pairing information associated with the Perpon
                person.HeldDeviceIdentifier = null;
                person.PairingState         = PairingState.NotPaired;
            }
            pairableDevice.HeldByPersonIdentifier = null;

            if (pairableDevice == null)
            {
                System.Diagnostics.Debug.WriteLine("ERROR: tried to remove nonexistent pairable device.");
            }

            if (DeviceRemoved != null)
            {
                DeviceRemoved(this, pairableDevice);
            }
        }
Пример #2
0
        private void FindDeviceWidthAndHeight(IADevice iaDevice)
        {
            //Does the device contain and width and height route
            if (iaDevice.SupportedRoutes.Contains(Routes.GetWidthAndHeightRoute))
            {
                IARequest request = new IARequest(Routes.GetWidthAndHeightRoute);
                IntAirAct.SendRequest(request, iaDevice, delegate(IAResponse response, Exception error)
                {
                    if (response == null || response.StatusCode == 404)
                    {
                        logger.TraceEvent(TraceEventType.Error, 100, "All devices should provide a width and height");
                    }
                    else if (response.StatusCode == 200)
                    {
                        Dictionary <String, double> dictionary = response.BodyAs <Dictionary <String, double> >();

                        Device localDevice = locator.Devices.Find(d => d.Identifier.Equals(iaDevice.Name));

                        //Device still exists, set width and height for device
                        if (localDevice != null)
                        {
                            localDevice.Height = dictionary["height"];
                            localDevice.Width  = dictionary["width"];
                        }
                        //Otherwise, device has disappeared, no action required
                        else
                        {
                        }
                    }
                });
            }
        }
Пример #3
0
        public void DeviceFound(IADevice iaDevice, bool ownDevice)
        {
            PairableDevice pairableDevice = new PairableDevice
            {
                Identifier   = iaDevice.Name,
                PairingState = PairingState.NotPaired
            };

            FindDeviceWidthAndHeight(iaDevice);


            if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
            {
                IARequest request = new IARequest(Routes.GetLocationRoute);
                IntAirAct.SendRequest(request, iaDevice, delegate(IAResponse response, Exception error)
                {
                    if (response == null || response.StatusCode == 404)
                    {
                        // Device has no location
                    }
                    else if (response.StatusCode == 200)
                    {
                        IntermediatePoint intermediatePoint = response.BodyAs <IntermediatePoint>();
                        Point result = intermediatePoint.ToPoint();

                        Device localDevice = locator.Devices.Find(d => d.Identifier.Equals(iaDevice.Name));

                        if (localDevice != null)
                        {
                            localDevice.Location = result;
                            response.StatusCode  = 201; // created
                        }
                        else
                        {
                            response.StatusCode = 404; // not found
                        }
                    }
                });
            }

            locator.Devices.Add(pairableDevice);

            if (DeviceAdded != null)
            {
                DeviceAdded(this, pairableDevice);
            }
        }
Пример #4
0
        public void UnpairDevice(PairableDevice pairingDevice)
        {
            if (pairingDevice.PairingState != PairingState.NotPaired)
            {
                List <PairablePerson> pPersons      = locator.Persons.OfType <PairablePerson>().ToList <PairablePerson>();
                PairablePerson        pairingPerson = pPersons.Find(p => p.HeldDeviceIdentifier == pairingDevice.Identifier);

                pairingDevice.HeldByPersonIdentifier = null;
                pairingDevice.PairingState           = PairingState.NotPaired;

                pairingPerson.PairingState         = PairingState.NotPaired;
                pairingPerson.HeldDeviceIdentifier = null;

                // Dispatch a message to the device
                IARequest request = new IARequest(Routes.BecomeUnpairedRoute);
                // Find the IntAirAct device matching the current device.
                IADevice iaDevice = intAirAct.Devices.Find(d => d.Name == pairingDevice.Identifier);
                intAirAct.SendRequest(request, iaDevice);
                System.Diagnostics.Debug.WriteLine(iaDevice.Name + " " + iaDevice.Host);
            }
        }
Пример #5
0
        void deviceAdded(DeviceManager deviceManager, PairableDevice pairableDevice)
        {
            // Finds the matching IADevice from the pairableDevice Identifier
            IADevice iaDevice = deviceManager.IntAirAct.Devices.Find(d => d.Name.Equals(pairableDevice.Identifier));

            if (iaDevice.SupportedRoutes.Contains(Routes.BecomePairedRoute))
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    DeviceControlDictionary[pairableDevice.Identifier] = new DeviceControl(pairableDevice, iaDevice);
                    unpairedDeviceStackPanel.Children.Add(DeviceControlDictionary[pairableDevice.Identifier]);
                }));
            }
            else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    DeviceControlDictionary[pairableDevice.Identifier] = new DeviceControl(pairableDevice, iaDevice);
                    surfaceStackPanel.Children.Add(DeviceControlDictionary[pairableDevice.Identifier]);
                }));
            }
        }
Пример #6
0
        public DeviceControl(PairableDevice pairableDevice, IADevice iaDevice)
        {
            InitializeComponent();

            this.iaDevice       = iaDevice;
            this.pairableDevice = pairableDevice;

            deviceRotationControl = new DeviceRotationControl();
            deviceRotationControl.onSliderValueChanged += new EventHandler <RotationSliderEventArgs>(onOrientationSliderChanged);
            canvas.Children.Add(deviceRotationControl);
            Canvas.SetLeft(deviceRotationControl, -170);
            Canvas.SetTop(deviceRotationControl, -40);

            //Setup Events
            pairableDevice.LocationChanged     += onLocationChanged;
            pairableDevice.OrientationChanged  += onOrientationChanged;
            pairableDevice.PairingStateChanged += onPairingStateChanged;

            LeftLine.StrokeThickness  = DrawingResources.DEVICE_FOV_WIDTH;
            RightLine.StrokeThickness = DrawingResources.DEVICE_FOV_WIDTH;

            //Setup Display
            DeviceNameLabel.Text    = pairableDevice.Identifier;
            InnerBorder.BorderBrush = DrawingResources.unpairedBrush;

            // If it supports this route, then we know it's a surface
            if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
            {
                MyDisplayState = DisplayState.UnlocatedAndOnStackPanel;
            }
            // Likewise, if it supports this route, we know it's a pairable device
            else if (iaDevice.SupportedRoutes.Contains(Routes.BecomePairedRoute))
            {
                MyDisplayState = DisplayState.UnpairedAndOnStackPanel;
            }

            formatForStackPanel();
        }
Пример #7
0
        public void Pair(PairableDevice pairingDevice, PairablePerson pairingPerson)
        {
            //Change the Pairing State
            pairingDevice.PairingState = PairingState.Paired;
            pairingPerson.PairingState = PairingState.Paired;

            //Create a Holds-Device and Held-By-Person Relationship
            pairingPerson.HeldDeviceIdentifier   = pairingDevice.Identifier;
            pairingDevice.HeldByPersonIdentifier = pairingPerson.Identifier;

            List <IADevice> devices = intAirAct.Devices;
            IADevice        device  = devices.Find(d => d.Name == pairingDevice.Identifier);

            if (device != null)
            {
                IARequest request = new IARequest(Routes.BecomePairedRoute);
                intAirAct.SendRequest(request, device, delegate(IAResponse response, Exception exception)
                {
                    logger.TraceEvent(TraceEventType.Information, 0, "Error notifying Device {0} that it became paired.", pairingDevice.Identifier, pairingPerson.Identifier);
                });
            }

            logger.TraceEvent(TraceEventType.Information, 0, "Pairing Succeeded with Device {0} and Person {1}", pairingDevice.Identifier, pairingPerson.Identifier);
        }
Пример #8
0
        protected override void OnDrop(DragEventArgs e)
        {
            string DataType = e.Data.GetFormats(true)[0];

            //if the object dropped is a tracker
            if (DataType == "trackerControl")
            {
                base.OnDrop(e);
                Point mouseLocation = e.GetPosition(sharedCanvas);

                // Grab the data we packed into the DataObject
                TrackerControl trackerControl = (TrackerControl)e.Data.GetData("trackerControl");

                // Hide the Ghost and Text since a Drop has been made
                MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden;
                ghostTextBlock.Visibility         = System.Windows.Visibility.Hidden;

                // Return the Opacity of the TrackerControl
                trackerControl.Opacity = 1;

                trackerControl.Tracker.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas);


                // Check if the TrackerControl is already a child of Shared Canvas
                Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas));

                if (!trackerControl.IsDescendantOf(SharedCanvas))
                {
                    trackerControl.formatForCanvas();
                    kinectWrapPanel.Children.Remove(trackerControl);
                    SharedCanvas.Children.Add(trackerControl);

                    if (trackerControl.Tracker.Orientation == null)
                    {
                        trackerControl.Tracker.Orientation = 270;
                    }
                }

                // if the cursor is outside the canvas, put the tracker back in stackpanel.
                else if (!(mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y))
                {
                    trackerControl.Tracker.StopStreaming();
                    cleanUpKinectPersons(trackerControl.Tracker.Identifier);
                    trackerControl.formatForStackPanel();
                    SharedCanvas.Children.Remove(trackerControl);
                    kinectWrapPanel.Children.Add(trackerControl);
                }
            }

            //if the objet dropped is a device.
            else if (DataType == "deviceControl")
            {
                base.OnDrop(e);
                Point mouseLocation = e.GetPosition(sharedCanvas);

                // Grab the data we packed into the DataObject
                DeviceControl deviceControl = (DeviceControl)e.Data.GetData("deviceControl");

                // Hide the Ghost and Text since a Drop has been made
                MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden;
                ghostTextBlock.Visibility         = System.Windows.Visibility.Hidden;

                // Return the Opacity of the DeviceControl
                deviceControl.Opacity = 1;

                PairableDevice device   = deviceControl.PairableDevice;
                IADevice       iaDevice = deviceControl.IADevice;

                IARequest request = new IARequest(Routes.SetLocationRoute);
                request.Parameters["identifier"] = iaDevice.Name;

                Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas));

                //if the dragged device is a pairable device (i.e iPad)
                if (!iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
                {
                    Point mouseLocationOnCanvas = mouseLocation = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas);
                    bool  pairedToNewDevice     = false;

                    foreach (KeyValuePair <PairablePerson, PersonControl> keyPair in PersonControlDictionary)
                    {
                        Point  personLocation = keyPair.Key.Location.Value;
                        double distance       = Math.Sqrt(Math.Pow(mouseLocationOnCanvas.X - personLocation.X, 2) + Math.Pow(mouseLocationOnCanvas.Y - personLocation.Y, 2));

                        //if the mouse drop is close to a person, pair the device with that person.
                        if (distance < 0.3 && (device.HeldByPersonIdentifier == keyPair.Key.Identifier || keyPair.Key.PairingState != PairingState.Paired))
                        {
                            if (device.PairingState == PairingState.Paired || device.PairingState == PairingState.PairedButOccluded)
                            {
                                kinectManager.PairingRecognizer.UnpairDevice(device);
                            }

                            kinectManager.PairingRecognizer.Pair(device, keyPair.Key);
                            pairedToNewDevice = true;
                            break;
                        }
                    }

                    //if the mouse drop is not close to a person then unpair the device.
                    if (!pairedToNewDevice)
                    {
                        kinectManager.PairingRecognizer.UnpairDevice(device);
                    }
                }

                //if the dragged device is not a pairable device (i.e table-top)
                else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute))
                {
                    if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y)
                    {
                        // Dropped within Canvas, so we want to place it on the canvas
                        device.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas);
                        request.SetBodyWith(new IntermediatePoint(device.Location.Value));
                    }
                    else
                    {
                        // Not dropped within Canvas, so we want to put it back on the stack panel
                        device.Location = null;
                        request.SetBodyWith(null);
                    }

                    // Send a request to the Device that their location has changed
                    kinectManager.IntAirAct.SendRequest(request, iaDevice);
                }
            }
        }
Пример #9
0
        private void RemoveOldPeople(List <Skeleton> skeletons, List <PairablePerson> pairablePersons, List <PairableDevice> pairableDevices, String kinectID)
        {
            // If a person has dissappeared, remove the kinect ID from they TrackIDwithSkeletonID dictionary
            List <PairablePerson> vanishedPersons = new List <PairablePerson>();

            foreach (PairablePerson person in pairablePersons)
            {
                foreach (KeyValuePair <string, string> entry in person.TrackerIDwithSkeletonID.ToList())
                {
                    if (entry.Key != null && entry.Key.Equals(kinectID))
                    {
                        bool found = false;
                        foreach (Skeleton skeleton in skeletons)
                        {
                            if (entry.Value.Equals(skeleton.TrackingId.ToString()))
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            // Remove from the dictionary
                            person.TrackerIDwithSkeletonID.Remove(kinectID);
                        }
                    }
                }


                //If that person is not tracked by anyone then make them an occluded person.
                if (person.TrackerIDwithSkeletonID.Count == 0)
                {
                    //Remove Held-By-Person Identifier
                    PairableDevice device = pairableDevices.Find(x => x.Identifier.Equals(person.HeldDeviceIdentifier));

                    // If the person was not paired to a device, we can remove them immediately
                    if (device == null)
                    {
                        RemovePerson(vanishedPersons, person);
                    }
                    // If the person was paired, then we allow a grace period for them to reappear, to avoid immediately unpairing them
                    else
                    {
                        if (person.PairingState == PairingState.Paired)
                        {
                            person.PairingState = PairingState.PairedButOccluded;
                            person.Identifier   = null;
                        }
                        // The person will remain with PairingState == PairedButOccluded for a few seconds, after which it will mark itself NotPaired
                        // If this happens, we remove the person for good, and unpair their device
                        else if (person.PairingState == PairingState.NotPaired)
                        {
                            device.HeldByPersonIdentifier = null;
                            device.PairingState           = PairingState.NotPaired;

                            // Dispatch a message to the device
                            IARequest request = new IARequest(Routes.BecomeUnpairedRoute);
                            // Find the IntAirAct device matching the current device.
                            IADevice iaDevice = intAirAct.Devices.Find(d => d.Name == device.Identifier);
                            intAirAct.SendRequest(request, iaDevice);
                            System.Diagnostics.Debug.WriteLine(iaDevice.Name + " " + iaDevice.Host);

                            RemovePerson(vanishedPersons, person);
                        }
                    }
                }
            }
            foreach (PairablePerson person in vanishedPersons)
            {
                pairablePersons.Remove(person);
            }
        }