Esempio n. 1
0
        private bool enable(BucketPosition pos)
        {
            String IP = Microsoft.VisualBasic.Interaction.InputBox("Enter the IP and Port Ex: 192.168.0.1:9999", "KPAT", defaultVLCIp + ":" + defaultVLCPort);

            String[] IPs = IP.Split(':');
            if (IPs.Length != 2)
            {
                System.Windows.MessageBox.Show("Error - Invalid format", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            Match match = Regex.Match(IPs[0], @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");

            if (!match.Success)
            {
                System.Windows.MessageBox.Show("Error - Invalid format", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            int  port;
            bool isNumeric = int.TryParse(IPs[1], out port);

            if (!isNumeric || port <= 0)
            {
                System.Windows.MessageBox.Show("Error - Invalid format", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            // We now have a valid IP and port.
            try
            {
                VlcController newController = new VlcController(IPs[0], port);
                VlcController oldController = allControllers[(int)pos];
                allControllers[(int)pos] = newController;
                if (oldController != null)
                {
                    oldController.shutdown();
                }
            }
            catch (Exception)
            {
                System.Windows.MessageBox.Show("Error - Could not connect to a vlc instance with the data provided", "Error", MessageBoxButton.OK,
                                               MessageBoxImage.Error);
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public Color checkPosition(Skeleton skeleton)
        {
            if (right)
            {
                // Check that the arm is a little bit extended
                if (Math.Abs(skeleton.Joints[JointType.WristRight].Position.X) - Math.Abs(skeleton.Joints[JointType.ElbowRight].Position.X) < 0.1)
                {
                    return(Colors.Peru);
                }

                // Pointing in the opposite direction.
                if (!(skeleton.Joints[JointType.WristRight].Position.X > skeleton.Position.X))
                {
                    return(Colors.Peru);
                }
            }
            else
            {
                if (Math.Abs(skeleton.Joints[JointType.WristLeft].Position.X) - Math.Abs(skeleton.Joints[JointType.ElbowLeft].Position.X) < 0.1)
                {
                    return(Colors.Peru);
                }

                // Pointing in the opposite direction.
                if (!(skeleton.Joints[JointType.WristLeft].Position.X < skeleton.Position.X))
                {
                    return(Colors.Peru);
                }
            }

            if (lastUpdate.AddSeconds(secsDelay) < DateTime.Now)
            {
                cant = 0;
            }

            lastUpdate = DateTime.Now;

            JointType joint1;
            JointType joint2;

            if (right)
            {
                joint1 = JointType.ElbowRight;
                joint2 = JointType.WristRight;
            }
            else
            {
                joint1 = JointType.ElbowLeft;
                joint2 = JointType.WristLeft;
            }
            float  diffXOrig = skeleton.Joints[joint1].Position.X - skeleton.Joints[joint2].Position.X;
            float  diffYOrig = skeleton.Joints[joint1].Position.Y - skeleton.Joints[joint2].Position.Y;
            double zRot      = 90;

            if (diffXOrig != 0)
            {
                zRot = Math.Atan(diffYOrig / ((right) ? diffXOrig : -diffXOrig)) * 180.0 / Math.PI + 90;
            }

            sumZ[cant % mediaSize] = (float)zRot;
            cant++;

            if (cant < mediaSize)
            {
                return(Colors.Peru);
            }

            float mediaZ = 0;

            mediaZ = getAverage(mediaZ);

            if (mediaZ > (bucket1 - offset) && mediaZ < (bucket1 + offset))
            {
                if (lastUses[0].AddSeconds(secsDelay) < DateTime.Now)
                {
                    MainWindow.BucketPosition position   = (right) ? MainWindow.BucketPosition.RIGHT_DOWN : MainWindow.BucketPosition.LEFT_DOWN;
                    VlcController             controller = container.getController(position);
                    if (controller != null)
                    {
                        new Thread(container.getController(position).toggleVolume).Start();
                        container.selectBucket(position);
                    }
                    lastUses[0] = DateTime.Now;
                }
                return(Colors.Cyan);
            }
            else if (mediaZ > (bucket2 - offset) && mediaZ < (bucket2 + offset))
            {
                if (lastUses[1].AddSeconds(secsDelay) < DateTime.Now)
                {
                    MainWindow.BucketPosition position   = (right) ? MainWindow.BucketPosition.RIGHT_CENTER : MainWindow.BucketPosition.LEFT_CENTER;
                    VlcController             controller = container.getController(position);
                    if (controller != null)
                    {
                        new Thread(container.getController(position).toggleVolume).Start();
                        container.selectBucket(position);
                    }
                    lastUses[1] = DateTime.Now;
                }
                return(Colors.Purple);
            }
            else if (mediaZ > (bucket3 - offset) && mediaZ < (bucket3 + offset))
            {
                if (lastUses[2].AddSeconds(secsDelay) < DateTime.Now)
                {
                    MainWindow.BucketPosition position   = (right) ? MainWindow.BucketPosition.RIGHT_UP : MainWindow.BucketPosition.LEFT_UP;
                    VlcController             controller = container.getController(position);
                    if (controller != null)
                    {
                        new Thread(container.getController(position).toggleVolume).Start();
                        container.selectBucket(position);
                    }
                    lastUses[2] = DateTime.Now;
                }
                return(Colors.Red);
            }
            return(Colors.Brown);
        }