Example #1
0
        private static bool HandleDirectionAscendingPositiveRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn)
        {
            var flag = false;

            entry.Value        += time.Ticks * (ulong)entry.Ratio;
            entry.ValueResiduum = 0;

            if (entry.Value >= entry.Period)
            {
                flag        = true;
                entry.Value = 0;
                entry       = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot));
            }

            nearestTickIn = nearestTickIn.WithTicksMin((entry.Period - entry.Value - 1) / (ulong)entry.Ratio + 1);
            return(flag);
        }
Example #2
0
        private static bool HandleDirectionAscendingNegativeRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn)
        {
            var   flag  = false;
            ulong ratio = (ulong)(-entry.Ratio);

            entry.Value        += (time.Ticks + entry.ValueResiduum) / ratio;
            entry.ValueResiduum = (time.Ticks + entry.ValueResiduum) % ratio;

            if (entry.Value >= entry.Period)
            {
                flag        = true;
                entry.Value = 0;
                entry       = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot));
            }

            nearestTickIn = nearestTickIn.WithTicksMin(((entry.Period - entry.Value) * ratio) - entry.ValueResiduum);
            return(flag);
        }
Example #3
0
        private static bool HandleDirectionDescendingPositiveRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn)
        {
            var ticksByRatio = time.Ticks * (ulong)entry.Ratio;
            var isReached    = ticksByRatio >= entry.Value;

            entry.ValueResiduum = 0;
            if (isReached)
            {
                entry.Value = entry.Period;
                entry       = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot));
            }
            else
            {
                entry.Value -= ticksByRatio;
            }

            nearestTickIn = nearestTickIn.WithTicksMin((entry.Value - 1) / (ulong)entry.Ratio + 1);
            return(isReached);
        }
Example #4
0
        private static bool HandleDirectionDescendingNegativeRatio(ref ClockEntry entry, TimeInterval time, ref TimeInterval nearestTickIn)
        {
            var ratio        = (ulong)(-entry.Ratio);
            var ticksByRatio = (time.Ticks + entry.ValueResiduum) / ratio;
            var isReached    = ticksByRatio >= entry.Value;

            entry.ValueResiduum = (time.Ticks + entry.ValueResiduum) % ratio;

            if (isReached)
            {
                // TODO: maybe issue warning if its lower than zero
                entry.Value = entry.Period;
                entry       = entry.With(enabled: entry.Enabled & (entry.WorkMode != WorkMode.OneShot));
            }
            else
            {
                entry.Value -= ticksByRatio;
            }

            nearestTickIn = nearestTickIn.WithTicksMin(entry.Value * ratio + entry.ValueResiduum);
            return(isReached);
        }