//Triggered when deadlift button is clicked. Instantiates class for deadlift and begins checking. //Activiates main thread with the deadlift exercise. private void Deadlift(object sender, RoutedEventArgs e) { Deadlift deadlift = new Deadlift(); SkeletonPos skeletonPos = new SkeletonPos(); skeletonPos.StartSkeletonStream(sensor); DisplayText("Enter Starting Position"); if (null == sensor) { this.statusBarText.Text = noKinectReady; return; } Thread getDict = new Thread(() => GetDictionary(skeletonPos, deadlift)); getDict.Start(); deadlift.StartExercise(sensor); this.statusBarText.Text = "Deadlift mode activated"; this.activityText.Text = "Please enter starting position."; this.DemoImage.Source = deadlift.ShowImage(); DeadliftButton.Background = Brushes.Gray; SquatButton.Background = new SolidColorBrush(Color.FromRgb(110, 8, 178)); OHPButton.Background = new SolidColorBrush(Color.FromRgb(110, 8, 178)); }
//Main thread for the system, occuring every 50 milliseconds. It handles two dictionaries simultaneously: //dict and exerciseDict. dict contains the string name for the joint and it's ColorImagePoint, set in //SkeletonPos.cs. exerciseDict contains the string name for the joint, and whether it should be coloured //green or red. This is handled in the respective class for that exercise. internal void GetDictionary(SkeletonPos skel, Exercise exercise) { TimeSpan waitInterval = TimeSpan.FromMilliseconds(50); List <String> keys = new List <String>(); bool isEmpty; exerciseObj = new ExerciseObj(exercise.ToString()); for (; !_isStopping.WaitOne(waitInterval);) { exerciseDict.Clear(); using (var dictionaryEnum = dict.GetEnumerator()) { isEmpty = !dictionaryEnum.MoveNext(); } if (isEmpty) { foreach (KeyValuePair <String, ColorImagePoint> entry in skel.getJointPointDict()) { dict.AddOrUpdate(entry.Key, entry.Value, (key, oldValue) => entry.Value); keys.Add(entry.Key); } foreach (KeyValuePair <String, List <String> > entry in exercise.GetDictionary()) { exerciseDict.AddOrUpdate(entry.Key, entry.Value, (key, oldValue) => entry.Value); } } else { foreach (var key in keys) { foreach (KeyValuePair <String, ColorImagePoint> realEntry in skel.getJointPointDict()) { if (key == realEntry.Key) { dict[key] = realEntry.Value; } } foreach (KeyValuePair <String, List <String> > realEntry in exercise.GetDictionary()) { if (key == realEntry.Key) { exerciseDict[key] = realEntry.Value; } } } } //If the user is tracked but the starting position isn't found, the joints are coloured in gold. foreach (KeyValuePair <String, ColorImagePoint> item in dict) { if (!exercise.CheckStartPosFound()) { { this.Dispatcher.Invoke(() => { DrawDots(Brushes.Gold, item.Key, item.Value); }); } } else if (exercise.CheckStartPosFound()) { //If the exerciseDict contains that joint, it means that joint is in a bad position and is coloured red. if (exerciseDict.ContainsKey(item.Key)) { this.Dispatcher.Invoke(() => { DrawDots(Brushes.Red, item.Key, item.Value); exerciseObj.Add(item.Key, exerciseDict[item.Key]); }); } //Otherwise, joint is in an okay position and is coloured green as it remains so. else { this.Dispatcher.Invoke(() => { DisplayTextOnce("Starting Position Found - Go!"); DrawDots(Brushes.SpringGreen, item.Key, item.Value); }); } } } } }