Example #1
0
        /// <summary>
        /// Notify the server of the device's current Location. Intended for use with stationary devices, since mobile devices can't
        /// determine their own location in the room.
        /// </summary>
        /// <param name="device">The Identifier and Location properties of this MSEDevice will be used for the update.</param>
        /// <param name="success"></param>
        /// <param name="failure"></param>
        public void UpdateDeviceLocation(MSEDevice device, MSESuccessHandler success, MSEErrorHandler failure)
        {
            IARequest updateRequest = new IARequest(Routes.SetLocationRoute);
            updateRequest.SetBodyWith(new IntermediatePoint(device.Location.Value));
            updateRequest.Parameters["identifier"] = device.Identifier;

            IEnumerable devicesSupportingRoutes = this.intAirAct.DevicesSupportingRoute(Routes.SetLocationRoute);
            foreach (IADevice iaDevice in devicesSupportingRoutes)
            {
                this.intAirAct.SendRequest(updateRequest, iaDevice, delegate(IAResponse response, Exception exception)
                {
                    if (exception != null)
                    {
                        failure(exception);
                        return;
                    }
                    else
                    {
                        success();
                    }
                });

                // Break, so that we only send the update to one server
                // How our system should function if there are multiple servers is undefined ...
                break;
            }
        }
Example #2
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);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Send a Dictionary to another device
        /// </summary>
        /// <param name="dictionary">The dictionary to send</param>
        /// <param name="dictionaryType">The dictionary type. This is shown on the receiving end and so you can just it to differentiate dictionaries</param>
        /// <param name="targetDevice">The target device (NOTE - targetDevice must not be null)</param>
        /// <param name="gesture">The Gesture used to send the image</param>
        public void SendDictionary(Dictionary<string, string> dictionary, string dictionaryType, Dictionary<string, double> intersectionPoint, IADevice targetDevice, MSEGesture gesture)
        {
            if (dictionary == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "MSE Error: Only a valid dictionary can be sent. Your dictionary was null");
                return;
            }

            if (dictionaryType == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "MSE Error: A valid dictionary type is required, your dictionary type was null");
                return;
            }

            if (targetDevice == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "MSE Error: Target Device must has a non null NetworkDevice");
                return;
            }

            IARequest request = new IARequest(Routes.DictionaryRoute);
            request.Parameters["dictionarytype"] = dictionaryType;
            request.Parameters["x"] = intersectionPoint["x"].ToString();
            request.Parameters["y"] = intersectionPoint["y"].ToString();
            request.SetBodyWith(dictionary);
            request.Origin = this.IntAirAct.OwnDevice;

            if (request.Body == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "MSE Error: Your dictionary of " + dictionaryType + " type, could not be serialized.");
                return;
            }

            this.IntAirAct.SendRequest(request, targetDevice, delegate(IAResponse response, Exception error)
            {
                if (error != null)
                {
                    logger.TraceEvent(TraceEventType.Error, 0, "MSE Error: Sending Dictionary " + dictionaryType + " to " + Routes.DictionaryRoute + " Failed");
                }
            });
        }
Example #4
0
 public void UpdateOrieantaion(double orientation)
 {
     //Windows.Devices.Sensors.Accelerometer requires VS2012
     var route = Routes.SetOrientationRoute;
     var request = new IARequest(route);
     request.Parameters.Add("identifier", IntAirAct.OwnDevice.Name);
     request.SetBodyWith(orientation);
     IEnumerable<IADevice> devices = IntAirAct.DevicesSupportingRoute(route);
     foreach (IADevice device in devices)
     {
         IntAirAct.SendRequest(request, device, delegate(IAResponse response, Exception e)
         {
             // log error maybe
         });
     }
 }
        public void SetLocationTest()
        {
            Setup();

            // Set up a device
            PairableDevice device = new PairableDevice
            {
                Identifier = "myPad",
                Location = new Point(1,1)
            };
            Server.Locator.Devices.Add(device);

            Server.Start();
            Client.Start();
            WaitForConnections();

            // Build a request to set the device's orientation
            IARequest request = new IARequest(Routes.SetOrientationRoute);
            request.Parameters["identifier"] = "myPad";
            Point newLocation = new Point(2,2);
            request.SetBodyWith(new IntermediatePoint(newLocation));

            // Send the request, and test
            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception)
            {
                Assert.AreEqual(newLocation, device.Location.Value);
            });

            Teardown();
        }