Esempio n. 1
0
        private void ManageMobileConnection()
        {
            try
            {
                Console.WriteLine("User connected! Address: " + socket.RemoteEndPoint);
                CanvasWindow.SetConnection(this);
                Connected = true;

                using (NetworkStream stream = new NetworkStream(socket))
                    using (sr = new StreamReader(stream))
                        using (sw = new StreamWriter(stream))
                        {
                            sw.AutoFlush = true;
                            string start = GestureParser.GetDirectionContext() == GestureDirection.Pull ? "startpull" : "startpush";
                            sw.WriteLine(start);
                            if (GestureParser.GetDirectionContext() == GestureDirection.Pull)
                            {
                                sw.WriteLine(nextShape);
                            }

                            SetGesture(GestureParser.GetTypeContext());
                            while (true)
                            {
                                String line = sr.ReadLine();

                                if (line.Contains("resetgyro"))
                                {
                                    gyro.ResetGyroscope();
                                }
                                //else if (line.StartsWith("gyrodata"))
                                //{
                                //    gyro.Update(line.Split(':')[2], line.Split(':')[4], line.Split(':')[6], line.Split(':')[8]);
                                //}
                                else
                                {
                                    dynamic jO = JsonConvert.DeserializeObject(line);
                                    if (jO.GetType().GetProperty("Type") != null)
                                    {
                                        GestureParser.AddMobileGesture(new MobileGesture(jO));
                                    }
                                }
                            }
                        }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                socket.Close();
                Connected = false;
            }
        }
Esempio n. 2
0
        private void Da_Completed(object sender, EventArgs e, Cell cell)
        {
            GestureParser.Pause(false);
            if (target == null)
            {
                return;
            }
            Cell t = target;

            if (nextTarget == null)
            {
                runningTest = false;
            }
            target          = null;
            t.GridCell.Fill = Brushes.White;
            targetColor     = accuracyTest ? Brushes.White : Brushes.DarkGray;
            canvas.Children.Remove(cell.Shape);
            cell.Shape = null;
        }
Esempio n. 3
0
        public CanvasWindow(bool accuracyTest = true)
        {
            this.accuracyTest = accuracyTest;

            targetColor = accuracyTest ? Brushes.White : Brushes.DarkGray;

            source = accuracyTest? DataSource.Accuracy : DataSource.Target;

            sounds.Add("hit", new SoundPlayer("resources/hit.wav"));
            sounds.Add("miss", new SoundPlayer("resources/miss.wav"));

            shapes = new List <String>();
            shapes.Add("circle");
            shapes.Add("square");
            GestureParser.Initialize(this);
            currentSize = GridSize.Small;
            window      = this;
            InitializeComponent();
            kinectManager = new KinectManager(this);
            VideoWindow.SetCanvasWindow(this);
        }
Esempio n. 4
0
        public void TargetHit(bool hit, bool correctShape, Cell target, Point pointer, Cell pointerCell, JumpLength length)
        {
            if (practiceDone)
            {
                Logger.CurrentLogger.CurrentTargetHit(hit, target, pointer, pointerCell, correctShape, length);
            }
            if (practiceSequence.Count != 0)
            {
                board.CreateTarget(practiceSequence.Dequeue());
                return;
            }
            else if (!practiceDone)
            {
                practiceDone = true;
                Logger.CurrentLogger.StartNewgestureTest(GestureParser.GetTypeContext(), GestureParser.GetDirectionContext());
                board.PracticeDone();
            }

            if (targetSequence.Count != 0)
            {
                board.CreateTarget(targetSequence.Dequeue());
            }
            else
            {
                board.CurrentGestureDone();
                if (gestureTypeList.Count == 0 && done)
                {
                    Finish();
                }
                else if (gestureTypeList.Count == 0)
                {
                    if (!firstDirectionRun)
                    {
                        firstDirectionRun = true;
                    }
                }
            }
        }
Esempio n. 5
0
 public void StartTest(GestureDirection direction)
 {
     GestureParser.SetDirectionContext(direction);
     gestureTypeList = GetRandomGestureList();
     ChangeGesture();
 }
Esempio n. 6
0
        public bool ChangeGesture()
        {
            if (gestureTypeList.Count == 0 && firstDirectionRun)
            {
                GestureDirection direction = GestureParser.GetDirectionContext() == GestureDirection.Pull ? GestureDirection.Push : GestureDirection.Pull;
                StartTest(direction);
                done = true;
                return(true);
            }
            practiceDone     = false;
            targetSequence   = Target.GetNextSequence();
            practiceSequence = Target.GetPracticeTargets();

            practiceSequence.Enqueue(targetSequence.Dequeue());

            board.Clear();
            board.StartNewGesture();
            board.CreateTarget(practiceSequence.Dequeue());
            GestureParser.SetTypeContext(gestureTypeList.Dequeue());

            Logger.CurrentLogger.StartPracticeTime(GestureParser.GetTypeContext(), GestureParser.GetDirectionContext());
            VideoWindow.PlayVideo(GestureParser.GetDirectionContext(), GestureParser.GetTypeContext());
            Console.WriteLine($"Changed to gesture: {GestureParser.GetTypeContext()} {GestureParser.GetDirectionContext()}");
            return(true);
        }
Esempio n. 7
0
        private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Space)
            {
                Background = Brushes.Black;/*
                                            * if (connection == null || !connection.Connected) {
                                            * connectedLabel.BeginAnimation(Canvas.OpacityProperty, CreateAnimation(5, 1, 0));
                                            * return;
                                            * }*/
                if (currentTest == null)
                {
                    currentTest = new TestSuite(this, source);
                    kinectManager.Recalibrate();
                    testIDLabel.Content = "User ID: " + currentTest.UserID;
                    testIDLabel.BeginAnimation(Canvas.OpacityProperty, CreateAnimation(10, 1, 0));
                }
                else if (runningTest && !runningGesture)
                {
                    currentTest.ChangeGesture();
                }
            }
            else if (e.Key == System.Windows.Input.Key.Up)
            {
                if (currentTest != null)
                {
                    currentTest.StartTest(GestureDirection.Push);
                }
            }
            else if (e.Key == System.Windows.Input.Key.Down)
            {
                if (currentTest != null)
                {
                    currentTest.StartTest(GestureDirection.Pull);
                }
            }

            else if (e.Key == System.Windows.Input.Key.I)
            {
                PointAt(0, 0);
            }

            else if (e.Key == System.Windows.Input.Key.Q)
            {
                StartDebugTest(GestureType.Swipe);
            }
            else if (e.Key == System.Windows.Input.Key.W)
            {
                StartDebugTest(GestureType.Throw);
            }
            else if (e.Key == System.Windows.Input.Key.E)
            {
                StartDebugTest(GestureType.Pinch);
            }
            else if (e.Key == System.Windows.Input.Key.R)
            {
                StartDebugTest(GestureType.Tilt);
            }

            else if (e.Key == System.Windows.Input.Key.Enter)
            {
                kinectManager.Recalibrate();
                ShowStatusMessage("Recalibrating...");
            }

            else if (e.Key == System.Windows.Input.Key.U)
            {
                VideoWindow.PlayVideo(GestureDirection.Pull, types.Dequeue());
            }

            else if (e.Key == System.Windows.Input.Key.A)
            {
                ShowStatusMessage("Push");
                GestureParser.SetDirectionContext(GestureDirection.Push);
            }
            else if (e.Key == System.Windows.Input.Key.S)
            {
                ShowStatusMessage("Pull");
                GestureParser.SetDirectionContext(GestureDirection.Pull);
            }
        }
Esempio n. 8
0
        public void PointAt(double xFromMid, double yFromMid)
        {
            if (pointerFigure == null)
            {
                pointerFigure = ShapeFactory.CreatePointer(accuracyTest);
                canvas.Children.Add(pointerFigure);
                Canvas.SetZIndex(pointerFigure, 10000);
                xPoint = xFromMid;
                yPoint = yFromMid;
            }
            if (target != null)
            {
                target.GridCell.Fill = targetColor;
            }
            if (extraTarget != null)
            {
                extraTarget.GridCell.Fill = targetColor;
            }

            DrawNextTargets();
            if (AttemptRepository.SaveStatus == DatabaseSaveStatus.Saving && !savingToDB)
            {
                savingToDB = true;
                ShowStatusMessage("Saving to database...");
            }
            if (savingToDB && AttemptRepository.SaveStatus != DatabaseSaveStatus.Saving)
            {
                savingToDB = false;
                string status = AttemptRepository.SaveStatus == DatabaseSaveStatus.Failed ? "Failed!" : "Success!";
                ShowStatusMessage(status);
                Background = AttemptRepository.SaveStatus == DatabaseSaveStatus.Failed ? Brushes.Red : Brushes.Blue;
            }

            Point currentGyroPoint = new Point(GyroPositionX, -GyroPositionY);

            if (currentGyroPoint != lastGyroPoint)
            {
                lastGyroPoint = new Point(GyroPositionX, -GyroPositionY);
            }

            xPoint = xFromMid;
            yPoint = yFromMid;

            if (!lockedPointer)
            {
                pointer = GetPoint(xPoint, yPoint);
            }
            MoveShape(pointerFigure, pointer);
            if (!accuracyTest)
            {
                ColorCell(pointer);
            }
            KinectGesture gesture = GestureParser.AwaitingGesture;

            if (runningTest && runningGesture)
            {
                if (gesture != null)
                {
                    UnlockPointer();
                    GestureParser.Pause(true);
                    Cell currCell     = GetCell(pointer);
                    bool hit          = currCell == target;
                    bool correctShape = true;

                    string           shape     = target.Shape is Ellipse ? "circle" : "square";
                    GestureDirection direction = GestureParser.GetDirectionContext();
                    GestureType      type      = GestureParser.GetTypeContext();
                    if (direction == GestureDirection.Push)
                    {
                        correctShape = shape == gesture.Shape;
                    }
                    currentTest.TargetHit(hit, correctShape, target, pointer, currCell, currentLength);
                    if (hit && !correctShape)
                    {
                        hit = false;
                    }
                    TargetHit(target, hit);
                }
            }
            ExtendedDraw(gesture);
        }
Esempio n. 9
0
        public void DrawNextTargets()
        {
            if (runningTest && runningGesture)
            {
                if (target == null)
                {
                    ClearCross();
                    double size = squareWidth > squareHeight ? squareHeight : squareWidth;

                    string shape = GetNextShape();

                    if (currentSize != nextTarget.Size)
                    {
                        Logger.CurrentLogger.ChangeSize(nextTarget.Size);
                    }
                    CreateGrid(nextTarget.Size);

                    if (GestureParser.GetDirectionContext() == GestureDirection.Pull)
                    {
                        connection?.SetNextShape(shape);
                        string     extraShape     = shape == "circle" ? "square" : "circle";
                        int        t              = nextTarget.Size == GridSize.Large ? 1 : 2;
                        List <int> xPossibilities = new List <int>();
                        List <int> yPossibilities = new List <int>();

                        for (int i = 0; i < gridWidth; i++)
                        {
                            if (i < nextTarget.X - t || i > nextTarget.X + t)
                            {
                                xPossibilities.Add(i);
                            }
                        }
                        for (int i = 0; i < gridHeight; i++)
                        {
                            if (i < nextTarget.Y - t || i > nextTarget.Y + t)
                            {
                                yPossibilities.Add(i);
                            }
                        }
                        int x = xPossibilities[randomizer.Next(xPossibilities.Count)], y = yPossibilities[randomizer.Next(yPossibilities.Count)];
                        extraTarget = grid[x, y];
                        extraTarget.GridCell.Fill = targetColor;
                        PushShape(extraShape, extraTarget);
                        extraTarget.Shape.Fill = Brushes.Black;
                        if (accuracyTest)
                        {
                            DrawCross(extraTarget);
                        }
                    }
                    currentLength        = nextTarget.Length;
                    target               = grid[nextTarget.X, nextTarget.Y];
                    target.GridCell.Fill = targetColor;
                    PushShape(shape, target);

                    target.Shape.Fill = Brushes.Black;
                    if (accuracyTest)
                    {
                        DrawCross(target);
                    }
                }
            }
        }
Esempio n. 10
0
 public static void SetConnection(Connection _connection)
 {
     connection = _connection;
     GestureParser.SetConnection(connection);
 }