Example #1
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);
        }
Example #2
0
        private KinectGesture IsThrowing(float currentLocation, long timestamp)
        {
            throwHandLocations.Enqueue(currentLocation);
            if (throwHandLocations.Count >= 15)
            {
                float initialPosition = throwHandLocations.Dequeue();

                if (timestamp - lastThrowEvent < 1000)
                {
                    return(null);
                }
                bool push = GestureParser.GetDirectionContext() == GestureDirection.Push ? true : false;
                if (initialPosition - currentLocation > 0.3 && push)
                {
                    lastThrowEvent = timestamp;
                    return(new KinectGesture(GestureType.Throw, GestureDirection.Push));
                }
                else if (currentLocation - initialPosition > 0.3 && !push)
                {
                    lastThrowEvent = timestamp;
                    return(new KinectGesture(GestureType.Throw, GestureDirection.Pull));
                }
            }

            return(null);
        }
Example #3
0
 public KinectGesture(string shape)
 {
     Shape     = shape;
     Type      = GestureParser.GetTypeContext();
     Direction = GestureParser.GetDirectionContext();
     Pointer   = CanvasWindow.GetCurrentPoint();
     Timestamp = DateTime.Now;
 }
Example #4
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;
            }
        }
Example #5
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;
                    }
                }
            }
        }
Example #6
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);
        }
Example #7
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);
                    }
                }
            }
        }