Пример #1
0
        public Task Custom(IData[] customList, IPushDataController deviceObserver, int durationMs, int?loop = null)
        {
            var taskSource = new TaskCompletionSource <bool>();

            if (customList == null || customList.Length == 0)
            {
                throw new ArgumentNullException("customList");
            }

            CancellationTokenSource cancelSource = null;

            var observer = Observer.Create <long>(
                onNext: elapsedMs =>
            {
                if (loop.HasValue)
                {
                    long loopCounter = elapsedMs / durationMs;

                    if (loopCounter >= loop.Value)
                    {
                        foreach (var kvp in customList[customList.Length - 1])
                        {
                            deviceObserver.Data[kvp.Key] = kvp.Value;
                        }
                        deviceObserver.PushData();

                        log.Debug("Cancel 9");
                        cancelSource.Cancel();
                        return;
                    }
                }

                double instanceMs = elapsedMs % durationMs;

                int pos = (int)(customList.Length * instanceMs / durationMs);

                foreach (var kvp in customList[pos])
                {
                    deviceObserver.Data[kvp.Key] = kvp.Value;
                }
                deviceObserver.PushData();
            },
                onCompleted: () =>
            {
                taskSource.SetResult(true);
            });

            cancelSource = this.timerJobRunner.AddTimerJobMs(observer, loop.HasValue ? durationMs * loop.Value : (long?)null);

            Executor.Current.SetManagedTask(taskSource.Task, cancelSource);

            return(taskSource.Task);
        }
Пример #2
0
        public Task Shimmer(IPushDataController deviceObserver, double minBrightness, double maxBrightness, int durationMs, int priority = 1)
        {
            var taskSource = new TaskCompletionSource <bool>();

            bool state = false;

            var observer = Observer.Create <long>(
                onNext: currentElapsedMs =>
            {
                state = !state;

                deviceObserver.Data[DataElements.Brightness] = state ? maxBrightness : minBrightness;
                deviceObserver.PushData();
            },
                onCompleted: () =>
            {
                taskSource.SetResult(true);
            });

            var cancelSource = this.timerJobRunner.AddTimerJobMs(observer, durationMs);

            Executor.Current.SetManagedTask(taskSource.Task, cancelSource);

            return(taskSource.Task);
        }
Пример #3
0
        public Task Fade(
            IPushDataController deviceObserver,
            double start,
            double end,
            int durationMs,
            ITransformer transformer = null,
            params Tuple <DataElements, object>[] additionalData)
        {
            var taskSource = new TaskCompletionSource <bool>();

            double brightnessRange = end - start;

            if (brightnessRange == 0)
            {
                taskSource.SetResult(true);

                return(taskSource.Task);
            }

            if (additionalData.Any())
            {
                deviceObserver.SetDataFromIData(additionalData.GenerateIData());
            }

            var observer = Observer.Create <double>(
                onNext: pos =>
            {
                if (transformer != null)
                {
                    pos = transformer.Transform(pos);
                }

                double brightness = start + (pos * brightnessRange);

                deviceObserver.Data[DataElements.Brightness] = brightness;
                deviceObserver.PushData();
            },
                onCompleted: () =>
            {
                taskSource.SetResult(true);
            });

            var cancelSource = this.timerJobRunner.AddTimerJobPos(observer, durationMs);

            Executor.Current.SetManagedTask(taskSource.Task, cancelSource);

            return(taskSource.Task);
        }
Пример #4
0
        public Task Custom(double[] customList, IPushDataController deviceObserver, int durationMs, int? loop = null)
        {
            var taskSource = new TaskCompletionSource<bool>();

            if (customList == null || customList.Length == 0)
                throw new ArgumentNullException("customList");

            CancellationTokenSource cancelSource = null;

            var observer = Observer.Create<long>(
                onNext: elapsedMs =>
                {
                    if (loop.HasValue)
                    {
                        long loopCounter = elapsedMs / durationMs;

                        if (loopCounter >= loop.Value)
                        {
                            deviceObserver.Data[DataElements.Brightness] = customList[customList.Length - 1];
                            deviceObserver.PushData();

                            log.Debug("Cancel 8");
                            cancelSource.Cancel();
                            return;
                        }
                    }

                    double instanceMs = elapsedMs % durationMs;

                    int pos = (int)(customList.Length * instanceMs / durationMs);

                    deviceObserver.Data[DataElements.Brightness] = customList[pos];
                    deviceObserver.PushData();
                },
                onCompleted: () =>
                {
                    taskSource.SetResult(true);
                });

            cancelSource = this.timerJobRunner.AddTimerJobMs(observer, loop.HasValue ? durationMs * loop.Value : (long?)null);

            Executor.Current.SetManagedTask(taskSource.Task, cancelSource);

            return taskSource.Task;
        }
Пример #5
0
        public Task Shimmer(IPushDataController deviceObserver, double minBrightness, double maxBrightness, int durationMs, int priority = 1)
        {
            var taskSource = new TaskCompletionSource<bool>();

            bool state = false;

            var observer = Observer.Create<long>(
                onNext: currentElapsedMs =>
                {
                    state = !state;

                    deviceObserver.Data[DataElements.Brightness] = state ? maxBrightness : minBrightness;
                    deviceObserver.PushData();
                },
                onCompleted: () =>
                {
                    taskSource.SetResult(true);
                });

            var cancelSource = this.timerJobRunner.AddTimerJobMs(observer, durationMs);

            Executor.Current.SetManagedTask(taskSource.Task, cancelSource);

            return taskSource.Task;
        }
Пример #6
0
        public Task Fade(
            IPushDataController deviceObserver,
            double start,
            double end,
            int durationMs,
            ITransformer transformer = null,
            params Tuple<DataElements, object>[] additionalData)
        {
            var taskSource = new TaskCompletionSource<bool>();

            double brightnessRange = end - start;

            if (brightnessRange == 0)
            {
                taskSource.SetResult(true);

                return taskSource.Task;
            }

            if (additionalData.Any())
                deviceObserver.SetDataFromIData(additionalData.GenerateIData());

            var observer = Observer.Create<double>(
                onNext: pos =>
                {
                    if (transformer != null)
                        pos = transformer.Transform(pos);

                    double brightness = start + (pos * brightnessRange);

                    deviceObserver.Data[DataElements.Brightness] = brightness;
                    deviceObserver.PushData();
                },
                onCompleted: () =>
                {
                    taskSource.SetResult(true);
                });

            var cancelSource = this.timerJobRunner.AddTimerJobPos(observer, durationMs);

            Executor.Current.SetManagedTask(taskSource.Task, cancelSource);

            return taskSource.Task;
        }