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); }
public KinectGesture(string shape) { Shape = shape; Type = GestureParser.GetTypeContext(); Direction = GestureParser.GetDirectionContext(); Pointer = CanvasWindow.GetCurrentPoint(); Timestamp = DateTime.Now; }
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; } }
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; } } } }
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); }