public void Start(int seconds = 1)
        {
            Device.StartTimer(TimeSpan.FromSeconds(seconds), () =>
            {
                if (IsRunning)
                {
                    StartTime += TimeSpan.FromSeconds(1);
                    RemainTime = (EndTime - StartTime);

                    var ticked = RemainTime.TotalSeconds >= 0;

                    if (ticked)
                    {
                        Ticked?.Invoke();
                    }
                    else
                    {
                        Completed?.Invoke();
                    }

                    return(ticked);
                }

                return(true);
            });
        }
Esempio n. 2
0
    // Only called on Ticks
    protected virtual void OnTicked(object source)
    {
        Ticked?.Invoke(source, EventArgs.Empty);
        // TODO: Play Tick Sound

        OnTickTocked(this);
    }
Esempio n. 3
0
        public void Start(int seconds = 1)
        {
            stopTimer   = false;
            DisplayTime = new TimeSpan(0, Minutes, 0);
            // Invoke timer every second
            Device.StartTimer(TimeSpan.FromSeconds(seconds), () =>
            {
                if (stopTimer)
                {
                    return(false);
                }
                DisplayTime = DisplayTime.Subtract(new TimeSpan(0, 0, seconds));
                var ticked  = DisplayTime.TotalSeconds > 1;

                if (ticked)
                {
                    Ticked?.Invoke();
                }
                else
                {
                    Completed?.Invoke();
                }

                return(ticked);
            });
        }
Esempio n. 4
0
        public void Start(int seconds = 1)
        {
            Device.StartTimer(TimeSpan.FromSeconds(seconds), () =>
            {
                RemainTime = (EndDate.AddSeconds(1) - DateTime.Now);
                var ticked = RemainTime.TotalSeconds >= 1;
                if (ticked)
                {
                    Ticked?.Invoke();
                }
                else
                {
                    Completed?.Invoke();
                    // count = 0;
                }

                if (Cancelar)
                {
                    ticked = false;
                    Cancel?.Invoke();
                }

                return(ticked);
            });
        }
Esempio n. 5
0
        public void Start()
        {
            TimeSpan endTime = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second).Add(TimeLeft);

            if (!isRunning) //if it is already running ther's no meaning for starting again
            {
                Device.StartTimer(TimeSpan.FromMilliseconds(SpreedControl()), () =>
                {
                    isRunning = true;

                    TimeSpan nowTime = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

                    TimeLeft = endTime - nowTime;

                    var ticked = TimeLeft.TotalSeconds > 0;

                    if (isPause)
                    {
                        Paused?.Invoke();
                        ticked    = false;
                        isRunning = false;
                    }
                    else if (ticked)
                    {
                        Ticked?.Invoke();
                    }
                    else
                    {
                        Completed?.Invoke();
                    }

                    return(ticked);
                });
            }
        }
Esempio n. 6
0
 private void OnTicked()
 {
     if (LastExecutionStatus == Status.Failure || LastExecutionStatus == Status.Success)
     {
         Ticked?.Invoke(this, $"Node #{Id} - {Name} returned status: {LastExecutionStatus}");
     }
 }
Esempio n. 7
0
        private void BackgroundWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs)
        {
            var msSinceLastTick = (DateTime.Now - _lastTickAt).TotalMilliseconds;

            Ticked?.Invoke(msSinceLastTick);

            _lastTickAt = DateTime.Now;
        }
Esempio n. 8
0
 /// <summary>
 /// Timer tick for animation
 /// </summary>
 /// <param name="sender">Sender of this tick</param>
 /// <param name="e">Timer tick arguments</param>
 private void HandleTimerElapse(object sender, ElapsedEventArgs e)
 {
     if (IsRunning)
     {
         var ticks      = (_stopwatch.ElapsedTicks - _stopwatchStart) / _durationTicks;
         var changeType = (ticks >= 1.0) ? ChangeType.Discrete : ChangeType.Continuous;
         Ticked?.Invoke(sender, new AnimationEventArgs(ticks, changeType));
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Starts the ticker and invokes Ticked event when there is a tick.
 /// </summary>
 ///
 public async Task StartAsync()
 {
     _ticker = new Task(() =>
     {
         Task.Delay(IntervalMilliseconds);
         Ticked?.Invoke(this, new EventArgs());
     }, tokensource.Token);
     await _ticker;
 }
Esempio n. 10
0
 private void OnTimerTicked(object state)
 {
     if (Interlocked.Exchange(ref _lock, 1) == 1 && _onlyOneMode)
     {
         Interlocked.Exchange(ref _newTick, 1);
         return;
     }
     Ticked?.Invoke(this, new EventArgs());
     if (Interlocked.Exchange(ref _newTick, 0) == 1 && _onlyOneMode)
     {
         Ticked?.Invoke(this, new EventArgs());
     }
     Interlocked.Exchange(ref _lock, 0);
 }
Esempio n. 11
0
        public async Task <ApplicationState> Next()
        {
            if (!clock.IsRunning)
            {
                return(ApplicationState.Shutdown);
            }
            var wait = options.TargetRate - (clock.Elapsed - last);

            if (wait > TimeSpan.Zero)
            {
                await Task.Delay(wait);
            }
            last = clock.Elapsed;
            Ticked?.Invoke(this, e: new LoopTickedEventArgs(last));
            return(ApplicationState.Running);
        }
Esempio n. 12
0
    void OnAudioFilterRead(float[] data, int channels)
    {
        if (!running)
        {
            return;
        }

        double samplesPerTick = sampleRate * TimeBetweenBeats * 4.0F / signatureLo;
        double sample         = AudioSettings.dspTime * sampleRate;
        int    dataLen        = data.Length / channels;
        int    n = 0;

        while (n < dataLen)
        {
            float x = gain * amp * Mathf.Sin(phase);
            int   i = 0;
            while (i < channels)
            {
                data[n * channels + i] += x;
                i++;
            }
            while (sample + n >= nextTick)
            {
                nextTick += samplesPerTick;
                amp       = 1.0F;
                bool accented = ++accent > signatureHi;
                if (accented)
                {
                    accent = 1;
                    amp   *= 2.0F;
                }

                //Debug.Log("Tick #" + totalTicks + ": " + accent + " / " + signatureHi);
                pendingBeats++;
                Ticked?.Invoke(pendingBeats, GetTotalElapsed(), accented);

                lastTickTime = AudioSettings.dspTime;
            }
            phase += amp * 0.3F;
            amp   *= 0.993F;
            n++;
        }
    }
Esempio n. 13
0
        public void Start(int seconds = 1)
        {
            Device.StartTimer(TimeSpan.FromSeconds(seconds), () =>
            {
                RemainTime = (EndDate - DateTime.Now);

                var ticked = RemainTime.TotalSeconds > 1;

                if (ticked)
                {
                    Ticked?.Invoke();
                }
                else
                {
                    Completed?.Invoke();
                }

                return(ticked);
            });
        }
Esempio n. 14
0
        public void Start()
        {
            // Run for 24 hours
            const int MinutesInADay = 60 * 24;

            for (var i = 0; i < MinutesInADay; i++)
            {
                ClockTime = ClockTime.AddMinutes(1);
                Ticked.Invoke(this, ClockTime);

                var timeRemaining = ClockTime
                                    .Subtract(AlarmTime)
                                    .TotalMinutes;

                if (IsTimeToWakeUp(timeRemaining))
                {
                    OnWakeUp();
                    break;
                }
            }
Esempio n. 15
0
    void Update()
    {
        if (!init)
        {
            return;
        }
        if (!running)
        {
            Debug.LogFormat("Now: {0}, Expected start: {1}", AudioSettings.dspTime, startTick);
            if (AudioSettings.dspTime >= startTick)
            {
                Debug.Log("LET'S GO");
                running = true;
            }
            else
            {
                return;
            }
        }
        double now      = AudioSettings.dspTime;
        double delta    = now;
        bool   willPlay = false;
        int    skipped  = 0;
        bool   accent   = (curAccentMarker % signatureHi) == 0;

        while (delta >= nextTick)
        {
            delta   -= TimeBetweenBeats;
            willPlay = true;
            pendingBeats++;
            skipped++;
            lastTickTime = now;
            Ticked?.Invoke(pendingBeats, GetTotalElapsed(), accent);
        }
        if (willPlay)
        {
            nextTick        += skipped * TimeBetweenBeats;
            curAccentMarker += skipped;
            source.PlayOneShot(accent ? metroAccent : metroDefault);
        }
    }
Esempio n. 16
0
    private IEnumerator PlayEnumerator()
    {
        IsPlaying = true;
        var targetTime = Time.realtimeSinceStartup + HandTime;

        while (Time.realtimeSinceStartup <= targetTime)
        {
            var timeLeft = targetTime - Time.realtimeSinceStartup;
            var progress = timeLeft / HandTime;

            Ticked?.Invoke(progress);

            yield return(new WaitForFixedUpdate());
        }

        Ticked?.Invoke(0);

        //in the new design you don't reach here if cancelled
        Elapsed?.Invoke(currentTurn);

        IsPlaying = false;
    }
Esempio n. 17
0
 public virtual Task TickAsync()
 {
     Ticked?.Invoke(this, null);
     return(Task.CompletedTask);
 }
Esempio n. 18
0
 protected virtual void OnTicked(PlayerEventArgs e)
 {
     Ticked?.Invoke(this, e);
 }
Esempio n. 19
0
 void OnTicked(EventArgs e) => Ticked?.Invoke(this, e);
Esempio n. 20
0
 private void TimerElapsed(object sender, ElapsedEventArgs e)
 {
     ElapsedSeconds++;
     Ticked?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 21
0
 /// <summary>
 /// Backtesting: called once for each time step, if there was at least one tick or bar
 /// </summary>
 protected virtual void RaiseTicked()
 {
     Ticked?.Invoke();
 }
Esempio n. 22
0
 private void Tick()
 {
     Ticked?.Invoke();
 }
Esempio n. 23
0
 private void OnTicked()
 {
     Ticked?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 24
0
 void ExecuteTick()
 {
     Ticked?.Invoke();
 }
Esempio n. 25
0
 protected virtual void OnTicked() =>
 Ticked?.Invoke(this, EventArgs.Empty);
Esempio n. 26
0
 private void BeforeTick()
 {
     Ticked?.Invoke(this, $"Node #{Id} - {Name} is going to tick");
 }
Esempio n. 27
0
 private void OnSqwInterrupt(object sender, PinValueChangedEventArgs e)
 {
     Ticked?.Invoke(sender, new ClockTickedEventArgs(ds3231.DateTime));
 }
Esempio n. 28
0
 private void OnTicked()
 {
     Ticked?.Invoke(this, new TickedEventArgs(CurrentTime));
 }