Beispiel #1
0
 public void PlayClicked()
 {
     if (CurrentTime == 0)
     {
         _currentPoint1 = (initialModel.seriesCollection1[0].ActualValues[0] as trPathNodeModel);
         _currentPoint2 = (initialModel.seriesCollection2[0].ActualValues[0] as trPathNodeModel);
         _currentPoint3 = (initialModel.seriesCollection3[0].ActualValues[0] as trPathNodeModel);
         _currentAngle  = (initialModel.seriesCollectionAngles[0].ActualValues[0] as trPathNodeModel);
         _currentIndex1 = 0; _currentIndex2 = 0; _currentIndex3 = 0; _currentAngleIndex = 0;
         try
         {
             SendMusicCmd("-c");                     //clear
             SendMusicCmd("-a /home/pi/Music");      //fill playlist from folder
             SendMusicCmd("-p -t repeat, autonext"); //start paying
         }
         catch (Exception)
         {
         }
     }
     else
     {
         try
         {
             SendMusicCmd("-G");
         }
         catch (Exception)
         {
             //throw;
         }
     }
     IsPlaying = !IsPlaying;
 }
        private void TrainingViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (db_context != null)
            {
                try
                {
                    db_context.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.InnerException.ToString());
                }
            }
            tr_pathWrapper  l_wrapper = (sender as tr_pathWrapper);
            trPathNodeModel l_node    = path_graph_dict[l_wrapper.num_path][0].ActualValues[(int)l_wrapper.order] as trPathNodeModel;

            if (e.PropertyName == "speed")
            {
                l_node.Speed = l_wrapper.speed;
                if (l_wrapper.order == path_graph_dict[l_wrapper.num_path][0].ActualValues.Count - 2)
                {
                    (path_graph_dict[l_wrapper.num_path][0].ActualValues[(int)l_wrapper.order + 1] as trPathNodeModel).Speed = l_wrapper.speed;
                }
            }
            else if (e.PropertyName == "duration")
            {
            }
        }
        public void AddTrPathItem(ObservableCollection <tr_pathWrapper> a_col, tr_pathWrapper item, SeriesCollection a_graf, long a_num_path)
        {
            if (item == null)
            {
                return;
            }
            int            idx           = (int)item.order + 1;
            long           l_minDuration = 10;
            tr_pathWrapper l_newPath     = new tr_pathWrapper(new tr_path()
            {
                id_training = training.id, num_path = a_num_path, duration = l_minDuration, order = idx, speed = a_col[idx - 1].speed
            });

            if (idx < a_col.Count)
            {
                a_col.Insert(idx, l_newPath);
            }
            else
            {
                a_col.Add(l_newPath);
            }

            l_newPath.Next = item.Next;
            if (item.Next != null)
            {
                item.Next.Previous = l_newPath;
            }
            l_newPath.Previous = item;
            item.Next          = l_newPath;

            l_newPath.order = idx;

            l_newPath.deleteButtonClicked += (tr_pathWrapper s) => { DeleteTrPathItem(a_col, s, a_graf); return(1); };
            l_newPath.addButtonClicked    += (tr_pathWrapper s) => { AddTrPathItem(a_col, s, a_graf, a_num_path); return(1); };

            trPathNodeModel l_newPoint = new trPathNodeModel()
            {
                Speed = (a_graf[0].ActualValues[idx - 1] as trPathNodeModel).Speed, Start = (a_graf[0].ActualValues[idx - 1] as trPathNodeModel).Start + a_col[idx - 1].duration
            };

            for (int i = idx; i < a_graf[0].ActualValues.Count; ++i)
            {
                (a_graf[0].ActualValues[i] as trPathNodeModel).Start += a_col[idx].duration;
            }
            a_graf[0].ActualValues.Insert(idx, l_newPoint);
            int l_pointCnt = a_graf[0].ActualValues.Count;

            if (idx == l_pointCnt - 2)
            {
                (a_graf[0].ActualValues[l_pointCnt - 1] as trPathNodeModel).Speed = (a_graf[0].ActualValues[l_pointCnt - 2] as trPathNodeModel).Speed;
            }

            if (db_context != null)
            {
                db_context.tr_path.Add(l_newPath.tr_path);
                try
                {
                    db_context.SaveChanges();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.InnerException.ToString());
                }
            }
        }
Beispiel #4
0
        public Task <bool> Play()
        {
            return(new Task <bool>(() =>
            {
                HiResTimer l_hrt = new HiResTimer();
                Int64 curTime = l_hrt.Value;
                Int64 timeElapsed = 0;
                while (CurrentTime <= MaxTime)
                {
                    Int64 newCurTime = l_hrt.Value;
                    if (IsPlaying)
                    {
                        timeElapsed += newCurTime - curTime;
                    }
                    double secondsPassed = (double)timeElapsed / (double)l_hrt.Frequency;
                    if (((int)secondsPassed) > CurrentTime)
                    {
                        if (_firstTime)
                        {
                            _justInit = true; _firstTime = false;
                        }
                        CurrentTime = ((int)secondsPassed);

                        if (CurrentTime > (series1[_currentIndex1 + 1] as trPathNodeModel).Start)
                        {
                            _currentIndex1 += 1;
                            if (_currentIndex1 < series1.Count - 1)
                            {
                                _currentPoint1 = (series1[_currentIndex1] as trPathNodeModel);
                                //switchAngle = true;
                            }
                            else
                            {
                                _currentIndex1 = series1.Count - 2;
                                _currentPoint1 = null;
                            }
                        }

                        if (CurrentTime > (series2[_currentIndex2 + 1] as trPathNodeModel).Start)
                        {
                            _currentIndex2 += 1;
                            if (_currentIndex2 < series2.Count - 1)
                            {
                                _currentPoint2 = (series2[_currentIndex2] as trPathNodeModel);
                                //switchAngle = true;
                            }
                            else
                            {
                                _currentIndex2 = series2.Count - 2;
                                _currentPoint2 = null;
                            }
                        }

                        if (CurrentTime > (series3[_currentIndex3 + 1] as trPathNodeModel).Start)
                        {
                            _currentIndex3 += 1;
                            if (_currentIndex3 < series3.Count - 1)
                            {
                                _currentPoint3 = (series3[_currentIndex3] as trPathNodeModel);
                                //switchAngle = true;
                            }
                            else
                            {
                                _currentIndex3 = series3.Count - 2;
                                _currentPoint3 = null;
                            }
                        }

                        if (CurrentTime > (angles[_currentAngleIndex + 1] as trPathNodeModel).Start)
                        {
                            _currentAngleIndex += 1;
                            if (_currentAngleIndex < angles.Count - 1)
                            {
                                _currentAngle = (angles[_currentAngleIndex] as trPathNodeModel);
                                switchAngle = true;
                            }
                            else
                            {
                                _currentAngleIndex = angles.Count - 2;
                                switchAngle = false;
                            }
                        }
                    }
                    CurPrgBarValue = (int)((secondsPassed / MaxTime) * MaxPrgBarValue);
                    curTime = newCurTime;
                }
                return true;
            }));
        }