예제 #1
0
파일: Sequence.cs 프로젝트: Onkeliroh/DSA
        /// <summary>
        /// Returns the next Operation to be done
        /// </summary>
        public SequenceOperation?Next()
        {
            CurrentOperation += 1;

            //one cycle is finished -> start new cycle
            if (CurrentOperation == Chain.Count)
            {
                CurrentOperation = 0;
                Cycle           += 1;
            }

            //if sequence is done
            if (CurrentState == SequenceState.Done || ((Cycle > Repetitions || Chain.Count == 0) && Repetitions != -1))
            {
                CurrentState = SequenceState.Done;
                return(null);
            }
            else
            {
                CurrentState   = SequenceState.Running;
                LastOperation += Chain [CurrentOperation].Duration;

                SequenceOperation op = Chain [CurrentOperation];
                return(op);
            }
        }
예제 #2
0
파일: Sequence.cs 프로젝트: Onkeliroh/DSA
        /// <summary>
        /// Gets the sequence state depending on the given time.
        /// </summary>
        /// <returns>The current state.</returns>
        /// <param name="milli">time in milliseconds</param>
        public DPinState GetCurrentState(double milli)
        {
            int multiplier = 0;

            if (milli >= Runtime.TotalMilliseconds)
            {
                multiplier = (int)(System.Math.Floor(milli / Runtime.TotalMilliseconds));
                milli     -= multiplier * Runtime.TotalMilliseconds;
            }

            SequenceOperation op = new SequenceOperation();

            if (Chain.Count > 0)
            {
                if (multiplier >= Repetitions && Repetitions != -1 && multiplier != 0)
                {
                    return(Chain.Last().State);
                }
                else
                {
                    op = Chain [0];
                    foreach (SequenceOperation seqop in Chain)
                    {
                        if (seqop.Moment.TotalMilliseconds == milli)
                        {
                            return(seqop.State);
                        }
                        else if (seqop.Moment.TotalMilliseconds < milli)
                        {
                            if ((milli - seqop.Moment.TotalMilliseconds) < (milli - op.Moment.TotalMilliseconds))
                            {
                                op = seqop;
                            }
                        }
                    }
                    return(op.State);
                }
            }
            return(DPinState.LOW);
        }
예제 #3
0
파일: Sequence.cs 프로젝트: Onkeliroh/DSA
 /// <summary>
 /// Adds a sequence operation.
 /// </summary>
 /// <param name="seqop">Sequenceoperation to be added</param>
 public void AddSequenceOperation(SequenceOperation seqop)
 {
     seqop.Moment = new TimeSpan(Chain.Sum(o => o.Duration.Ticks));
     Chain.Add(seqop);
 }
예제 #4
0
 /// <summary>
 /// Adds or changes a operation.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">E.</param>
 protected void OnBtnApplyOperationClicked(object sender, EventArgs e)
 {
     var op = new SequenceOperation () {
         Duration = this.Duration,
     //				State = (cbState.ActiveText == "HIGH") ? DPinState.HIGH : DPinState.LOW,
         State = (cbState.Active == 0) ? DPinState.HIGH : DPinState.LOW,
     };
     if (ActiveNode == null) {
         AddOperation (op);
         cbState.Active = (cbState.Active == 0) ? 1 : 0;
     } else {
         pinSequence.Chain [ActiveNode.Index] = op;
         DisplaySequenceInfos ();
         SwitchToAddBtn ();
     }
 }
예제 #5
0
 /// <summary>
 /// Adds a operation.
 /// </summary>
 /// <param name="SeqOp">Seq op.</param>
 private void AddOperation(SequenceOperation SeqOp)
 {
     pinSequence.AddSequenceOperation (SeqOp);
     XAxis.AbsoluteMaximum = pinSequence.Chain.Sum (o => o.Duration.TotalMilliseconds);
     DisplaySequenceInfos ();
 }
예제 #6
0
파일: NodeViews.cs 프로젝트: Onkeliroh/DSA
        public SequenceOperationTreeNode(SequenceOperation seqop, int index = -1, double totalTime = -1)
        {
            SeqOp = seqop;
            Index = index;

            if (totalTime < 0)
            {
                TotalTime = "";
            } else
            {
                TotalTime = "+" + TimeSpan.FromTicks ((long)totalTime).ToString ("g");
            }
        }
예제 #7
0
        public void SerializeSequenceOperation()
        {
            SequenceOperation SeqOp = new SequenceOperation () {
                Duration = TimeSpan.FromSeconds (42),
                State = DPinState.HIGH
            };

            Formator.Serialize (MemStream, SeqOp);

            MemStream.Seek (0, SeekOrigin.Begin);

            SequenceOperation SeqOpClone = (SequenceOperation)Formator.Deserialize (MemStream);

            Assert.AreEqual (SeqOp, SeqOpClone);
        }
예제 #8
0
파일: Sequence.cs 프로젝트: Onkeliroh/DSA
        /// <summary>
        /// Gets the sequence state depending on the given time.
        /// </summary>
        /// <returns>The current state.</returns>
        /// <param name="milli">time in milliseconds</param>
        public DPinState GetCurrentState(double milli)
        {
            int multiplier = 0;
            if (milli >= Runtime.TotalMilliseconds) {
                multiplier = (int)(System.Math.Floor (milli / Runtime.TotalMilliseconds));
                milli -= multiplier * Runtime.TotalMilliseconds;
            }

            SequenceOperation op = new SequenceOperation ();
            if (Chain.Count > 0) {
                if (multiplier >= Repetitions && Repetitions != -1 && multiplier != 0) {
                    return Chain.Last ().State;
                } else {
                    op = Chain [0];
                    foreach (SequenceOperation seqop in Chain) {
                        if (seqop.Moment.TotalMilliseconds == milli) {
                            return seqop.State;
                        } else if (seqop.Moment.TotalMilliseconds < milli) {
                            if ((milli - seqop.Moment.TotalMilliseconds) < (milli - op.Moment.TotalMilliseconds)) {
                                op = seqop;
                            }

                        }
                    }
                    return op.State;
                }
            }
            return DPinState.LOW;
        }
예제 #9
0
파일: Sequence.cs 프로젝트: Onkeliroh/DSA
 /// <summary>
 /// Adds the sequence operation range.
 /// </summary>
 /// <param name="seqops">Seqops.</param>
 public void AddSequenceOperationRange(SequenceOperation[] seqops)
 {
     for (int i = 0; i < seqops.Length; i++) {
         AddSequenceOperation (seqops [i]);
     }
 }
예제 #10
0
파일: Sequence.cs 프로젝트: Onkeliroh/DSA
 /// <summary>
 /// Adds a sequence operation.
 /// </summary>
 /// <param name="seqop">Sequenceoperation to be added</param>
 public void AddSequenceOperation(SequenceOperation seqop)
 {
     seqop.Moment = new TimeSpan (Chain.Sum (o => o.Duration.Ticks));
     Chain.Add (seqop);
 }