Пример #1
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            var groupCount = layer.Count / 3;

            Func <TimeSpan> customWaitMS = () => TimeSpan.FromMilliseconds((waitTime().TotalMilliseconds * 2) / groupCount);

            return(layer.OrderBy(x => Guid.NewGuid()).ChunkByGroupNumber(groupCount).FlashQuick(cancellationToken, color, IteratorEffectMode.Random, waitTime: customWaitMS));
        }
Пример #2
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            var fronToBack = layer.GroupBy(x => (int)(((x.LightLocation.Y + 1) / 2) * 50)).ToList();

            Func <TimeSpan> customWaitMS = () => TimeSpan.FromMilliseconds((waitTime().TotalMilliseconds * 2) / fronToBack.Count);

            return(fronToBack.FlashQuick(cancellationToken, color, IteratorEffectMode.Bounce, IteratorEffectMode.All, waitTime: customWaitMS));
        }
Пример #3
0
        public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            layer.SetState(cancellationToken, color, 1, waitTime(), false);

            //Wait for other events to finish and set state again
            await Task.Delay(waitTime(), cancellationToken);

            layer.SetState(cancellationToken, color, 1, waitTime(), false);
        }
Пример #4
0
        public static List <GroupModel> GetAll(EntertainmentLayer layer = null)
        {
            if (layer == null)
            {
                layer = StreamingSetup.Layers.First();
            }

            var center = EffectSettings.LocationCenter;

            var allLightsOrdered = layer.OrderBy(x => x.LightLocation.X).ThenBy(x => x.LightLocation.Y).ToList();

            var leftRight = new[] { allLightsOrdered.GetLeft(), allLightsOrdered.GetRight() }.ToList();
            var frontBack = new[] { allLightsOrdered.GetFront(), allLightsOrdered.GetBack() }.ToList();
            var quarter = new[] { layer.GetLeft().GetFront(), layer.GetLeft().GetBack(), layer.GetRight().GetBack(), layer.GetRight().GetFront() }.ToList();
            var alternating       = allLightsOrdered.ChunkByGroupNumber(2);
            var alternatingFour   = allLightsOrdered.ChunkByGroupNumber(4);
            var orderedByDistance = layer.OrderBy(x => x.LightLocation.Distance(center.X, center.Y)).ChunkByGroupNumber(3);
            var orderedByAngle    = layer.OrderBy(x => x.LightLocation.Angle(center.X, center.Y)).ChunkBy(6);

            var leftToRight = allLightsOrdered.GroupBy(x => (int)(((x.LightLocation.X + 1) / 2) * 50)).OrderBy(x => x.Key);
            var fronToBack  = allLightsOrdered.GroupBy(x => (int)(((x.LightLocation.Y + 1) / 2) * 50)).OrderBy(x => x.Key);
            var ring        = allLightsOrdered.GroupBy(x => (int)((x.LightLocation.Distance(center.X, center.Y) / 1.5) * 2));
            var tentacles   = allLightsOrdered.GroupBy(x => (int)((x.LightLocation.Angle(center.X, center.Y) / 3.6 / 3))).OrderBy(x => x.Key);

            var result = new List <GroupModel>()
            {
                //new GroupModel("All", allLightsOrdered.To2DGroup()),
                new GroupModel("Left/Right", leftRight),
                new GroupModel("Left To Right", leftToRight, 2),
                new GroupModel("Front/Back", frontBack),
                new GroupModel("Front To Back", fronToBack, 2),
                new GroupModel("Quarter", quarter, 2),
                new GroupModel("Alternating", alternating),
                new GroupModel("Alternating by 4", alternatingFour),
                //new GroupModel("Distance from center", orderedByDistance),
                //new GroupModel("Order by Angle from center", orderedByAngle),
                new GroupModel("Ring", ring, 2),
                new GroupModel("Tentacles", tentacles),
                new GroupModel("Random", GetRandomGroup()),
            };

            if (StreamingSetup.CurrentConnection.Name == "Ster" || StreamingSetup.CurrentConnection.Name == "DEMO Ster")
            {
                result.Add(new GroupModel("Tentacles (alternating 2)", tentacles.ChunkByGroupNumber(2).Select(x => x.SelectMany(l => l)), 2));
                result.Add(new GroupModel("Tentacles (alternating 3)", tentacles.ChunkByGroupNumber(3).Select(x => x.SelectMany(l => l)), 3));
                result.Add(new GroupModel("Tentacles (alternating 4)", tentacles.ChunkByGroupNumber(4).Select(x => x.SelectMany(l => l)), 4));
            }

            return(result);
        }
Пример #5
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            //Non repeating effects should not run on baselayer
            if (layer.IsBaseLayer)
            {
                return(Task.CompletedTask);
            }

            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            return(layer.To2DGroup().FlashQuick(cancellationToken, color, IteratorEffectMode.All, IteratorEffectMode.All, waitTime: () => TimeSpan.FromMilliseconds(100), transitionTimeOn: () => TimeSpan.Zero, transitionTimeOff: waitTime, duration: waitTime()));
        }
Пример #6
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken, double x, double y)
        {
            RedLightEffect effect = new RedLightEffect();

            effect.X = x;
            effect.Y = y;
            layer.PlaceEffect(effect);
            effect.Start();

            return(Task.Run(async() =>
            {
                await Task.Delay(waitTime());
                effect.Stop();
                layer.Effects.Remove(effect);
            }));
        }
Пример #7
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            var center         = EffectSettings.LocationCenter;
            var orderedByAngle = layer.OrderBy(x => x.LightLocation.Angle(center.X, center.Y));

            Func <TimeSpan> customWaitMS  = () => TimeSpan.FromMilliseconds((waitTime().TotalMilliseconds * 2) / layer.Count);
            Func <TimeSpan> customOnTime  = () => customWaitMS() / 2;
            Func <TimeSpan> customOffTime = () => customWaitMS() * 2;

            return(orderedByAngle.To2DGroup().Flash(cancellationToken, color, IteratorEffectMode.Cycle, waitTime: customWaitMS, transitionTimeOn: customOnTime, transitionTimeOff: customOffTime, waitTillFinished: false));
        }
Пример #8
0
        public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            HSB hsb = new HSB(0, 255, 255);

            while (!cancellationToken.IsCancellationRequested)
            {
                layer.SetState(cancellationToken, hsb.GetRGB(), 1);

                await Task.Delay(waitTime() / 10);

                hsb.Hue += 100;

                if (hsb.Hue >= HSB.HueMaxValue)
                {
                    hsb.Hue = 0;
                }
            }
        }
Пример #9
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken, double x, double y)
        {
            Func <TimeSpan> customWaitTime = () => waitTime() / 10;

            Q42.HueApi.Streaming.Effects.RandomPulseEffect effect = new Q42.HueApi.Streaming.Effects.RandomPulseEffect(false, customWaitTime);
            effect.X          = x;
            effect.Y          = y;
            effect.AutoRepeat = false;
            layer.PlaceEffect(effect);
            effect.Start();

            return(Task.Run(async() =>
            {
                await Task.Delay(waitTime() * 2);
                effect.Stop();
                await Task.Delay(TimeSpan.FromSeconds(1));
                layer.Effects.Remove(effect);
            }));
        }
Пример #10
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            //Non repeating effects should not run on baselayer
            if (layer.IsBaseLayer)
            {
                return(Task.CompletedTask);
            }

            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            Func <TimeSpan> customWaitMS = () => TimeSpan.FromMilliseconds((waitTime().TotalMilliseconds * 4) / layer.Count);

            var fronToBack = layer.GroupBy(x => (int)(((x.LightLocation.Y + 1) / 2) * 50)).OrderBy(x => x.Key).Reverse();

            return(fronToBack.FlashQuick(cancellationToken, color, IteratorEffectMode.Single, IteratorEffectMode.RandomOrdered, waitTime: customWaitMS));
        }
Пример #11
0
        public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            Random r = new Random();

            while (!cancellationToken.IsCancellationRequested)
            {
                var nextcolor = color ?? RGBColor.Random();
                var hsb       = nextcolor.GetHSB();

                foreach (var light in layer)
                {
                    var addHue    = r.Next(-6000, 6000);
                    var addBri    = r.Next(-100, 100);
                    var randomHsb = new HSB(hsb.Hue + addHue, hsb.Saturation, WrapValue(255, hsb.Brightness + addBri));
                    light.SetState(cancellationToken, randomHsb.GetRGB(), 1, UseTransition ? waitTime() / 2 : TimeSpan.Zero);
                }
                await Task.Delay(waitTime());
            }
        }
Пример #12
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            //Non repeating effects should not run on baselayer
            if (layer.IsBaseLayer)
            {
                return(Task.CompletedTask);
            }

            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            var groupCount = layer.Count / 3;

            Func <TimeSpan> customWaitMS = () => TimeSpan.FromMilliseconds((waitTime().TotalMilliseconds) / groupCount);

            return(layer.OrderBy(x => Guid.NewGuid()).ChunkByGroupNumber(groupCount).FlashQuick(cancellationToken, color, IteratorEffectMode.AllIndividual, IteratorEffectMode.RandomOrdered, waitTime: customWaitMS, duration: waitTime()));
        }
Пример #13
0
        public async Task OnStartReading()
        {
            try
            {
                if (_config.Model.hueSettings.hueType == HueType.Basic)
                {
                    if (_config.Model.hueSettings.turnLightOnIfOff)
                    {
                        var command = new LightCommand
                        {
                            On             = true,
                            TransitionTime = _frameTimeSpan
                        };
                        command.TurnOn();
                        await _client.SendCommandAsync(command, UseRoom.Lights);
                    }
                }
                else if (_config.Model.hueSettings.hueType == HueType.Entertainment)
                {
                    _cancelSource = new CancellationTokenSource();
                    _cancelToken  = _cancelSource.Token;
                    _streamGroup  = new StreamingGroup(UseRoom.Locations);
                    await _streamClient.Connect(UseRoom.Id);

                    _streamBaseLayer = _streamGroup.GetNewLayer(true);
                    foreach (var light in _streamBaseLayer)
                    {
                        if (_config.Model.hueSettings.turnLightOnIfOff)
                        {
                            light.SetState(_cancelToken, new RGBColor(1.0, 1.0, 1.0), 0.5);
                        }
                    }

                    _streamClient.ManualUpdate(_streamGroup);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                _ = Task.Run(() => _logger?.WriteLog(ex.ToString()));
            }
        }
Пример #14
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            Func <TimeSpan> customWaitTime = () => waitTime() / 10;

            var center            = EffectSettings.LocationCenter;
            var randomPulseEffect = new Q42.HueApi.Streaming.Effects.RandomPulseEffect(waitTime: customWaitTime);

            randomPulseEffect.X = center.X;
            randomPulseEffect.Y = center.Y;
            layer.PlaceEffect(randomPulseEffect);
            randomPulseEffect.Start();

            cancellationToken.Register(() =>
            {
                randomPulseEffect.Stop();
                layer.Effects.Remove(randomPulseEffect);
            });

            return(Task.CompletedTask);
        }
Пример #15
0
        public async Task OnStopReading()
        {
            if (_config.Model.hueSettings.hueType == HueType.Basic)
            {
                if (_config.Model.hueSettings.shutLightOffOnStop)
                {
                    var command = new LightCommand
                    {
                        On             = false,
                        TransitionTime = _frameTimeSpan
                    };
                    command.TurnOff();
                    await _client.SendCommandAsync(command, UseRoom.Lights);
                }
            }
            else if (_config.Model.hueSettings.hueType == HueType.Entertainment)
            {
                if (_config.Model.hueSettings.shutLightOffOnStop && _streamBaseLayer != null)
                {
                    foreach (var light in _streamBaseLayer)
                    {
                        light.SetState(_cancelToken, brightness: 0.0, timeSpan: _frameTimeSpan);
                    }
                }

                if (_streamGroup != null)
                {
                    _streamClient?.ManualUpdate(_streamGroup);
                }

                _cancelSource?.Cancel();
                _cancelSource?.Dispose();
                _streamGroup     = null;
                _streamBaseLayer = null;
                //Closing disposes the client so we need to reconnect if we want to reuse it.
                _streamClient?.Close();
                _streamClient = null;
                await ConnectToBridge();
            }
        }
        public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            var center = EffectSettings.LocationCenter;

            var tentacles = layer.GroupBy(x => (int)((x.LightLocation.Angle(center.X, center.Y) / 3.6 / 3))).OrderBy(x => x.Key);

            var grouped = tentacles.ChunkByGroupNumber(2).Select(x => x.SelectMany(l => l));

            while (!cancellationToken.IsCancellationRequested)
            {
                CancellationTokenSource tempCancel = new CancellationTokenSource();

                foreach (var group in grouped)
                {
                    var nextColor = RGBColor.Random();
                    group.To2DGroup().FlashQuick(cancellationToken, null, IteratorEffectMode.All, IteratorEffectMode.All, waitTime, transitionTimeOff: waitTime, duration: waitTime());
                    await Task.Delay(waitTime(), cancellationToken);
                }

                tempCancel.Cancel();
            }
        }
Пример #17
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            Func <TimeSpan> customWaitTime = () => waitTime() / 10;

            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            var center         = EffectSettings.LocationCenter;
            var rotatingEffect = new RotatingLineEffect(cancellationToken, color.Value, customWaitTime);

            rotatingEffect.X = center.X;
            rotatingEffect.Y = center.Y; layer.PlaceEffect(rotatingEffect);
            rotatingEffect.Start();

            cancellationToken.Register(() => {
                rotatingEffect.Stop();
                layer.Effects.Remove(rotatingEffect);
            });

            return(Task.CompletedTask);
        }
Пример #18
0
        public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            //Non repeating effects should not run on baselayer
            if (layer.IsBaseLayer)
            {
                return;
            }

            var center            = EffectSettings.LocationCenter;
            var orderedByDistance = layer.OrderBy(x => x.LightLocation.Distance(center.X, center.Y, center.Z));

            if (!color.HasValue)
            {
                color = RGBColor.Random();
            }

            Func <TimeSpan> customWaitTime = () => waitTime() / layer.Count;


            await orderedByDistance.To2DGroup().SetColor(cancellationToken, color.Value, IteratorEffectMode.Single, IteratorEffectMode.All, customWaitTime);

            layer.SetBrightness(cancellationToken, 0, transitionTime: TimeSpan.FromMilliseconds(0));
        }
Пример #19
0
        public static async Task SendCommandA(BeatmapEventData data, HSB hsbColor, double brightness, HSB inithsbColor, HSB endhsbColor, double time, bool gradient)
        {
            CancellationToken  token    = LightInfo.token;
            EntertainmentLayer entLayer = LightInfo.layer;

            if (gradient == true)
            {
                switch (data.value)
                {
                case 0: entLayer.SetState(token, null, brightness); break;

                case 1: entLayer.SetState(token, inithsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, endhsbColor.GetRGB(), 1, TimeSpan.FromSeconds(time)); break;

                case 5: entLayer.SetState(token, inithsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, endhsbColor.GetRGB(), 1, TimeSpan.FromSeconds(time)); break;
                }
            }
            else
            {
                switch (data.value)
                {
                case 0: entLayer.SetState(token, null, brightness); break;

                case 1: entLayer.SetState(token, hsbColor.GetRGB(), 1); break;

                case 2: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break;

                case 3: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break;

                case 5: entLayer.SetState(token, hsbColor.GetRGB(), 1); break;

                case 6: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break;

                case 7: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break;
                }
            }
        }
        public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            Func <TimeSpan> customWaitTime = () => waitTime() / 10;

            var bottomPulseEffect = new Q42.HueApi.Streaming.Effects.RandomPulseEffect(waitTime: customWaitTime);

            bottomPulseEffect.AutoRepeat = false;
            bottomPulseEffect.Y          = -1;
            layer.PlaceEffect(bottomPulseEffect);

            var topPulseEffect = new Q42.HueApi.Streaming.Effects.RandomPulseEffect(waitTime: customWaitTime);

            topPulseEffect.AutoRepeat = false;
            topPulseEffect.Y          = 1;
            layer.PlaceEffect(topPulseEffect);

            while (!cancellationToken.IsCancellationRequested)
            {
                bottomPulseEffect.Start();

                await Task.Delay(waitTime() * 2.2);

                topPulseEffect.Start();

                await Task.Delay(waitTime() * 2.2);
            }

            cancellationToken.Register(() =>
            {
                bottomPulseEffect.Stop();
                layer.Effects.Remove(bottomPulseEffect);

                topPulseEffect.Stop();
                layer.Effects.Remove(topPulseEffect);
            });
        }
Пример #21
0
 public static void setInfo(StreamingHueClient input, EntertainmentLayer input1, CancellationToken input2)
 {
     client = input;
     layer  = input1;
     token  = input2;
 }
Пример #22
0
        public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            layer.To2DGroup().Christmas(new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token);

            return(layer.To2DGroup().ChristmasFade(waitTime, cancellationToken));
        }
Пример #23
0
        private static void StartEffect(CancellationToken ctsToken, TypeInfo selectedEffect, EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color)
        {
            MethodInfo?methodInfo = selectedEffect.GetMethod("Start");

            if (methodInfo == null)
            {
                return;
            }

            object[] parametersArray = new object[] { layer, waitTime, color, ctsToken };

            object?classInstance = Activator.CreateInstance(selectedEffect, null);

            methodInfo.Invoke(classInstance, parametersArray);

            var hub = (IHubContext <StatusHub>)Startup.ServiceProvider.GetService(typeof(IHubContext <StatusHub>));

            hub.Clients.All.SendAsync("StartingEffect", $"Starting: {selectedEffect.Name} {color?.ToHex()}", new EffectLogMsg()
            {
                Name = selectedEffect.Name, RGBColor = color?.ToHex()
            });
        }
Пример #24
0
        public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
        {
            cancellationToken.Register(() => {
                _cts.Cancel();
            });

            while (!cancellationToken.IsCancellationRequested)
            {
                SetBPM(75);

                new HsbLoopEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(6), cancellationToken);

                ResetCts();

                new RandomColorRangeEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(6), cancellationToken);

                ResetCts();

                SetBPM(20);

                new RotatingEffect().Start(layer, () => WaitTime, color, _cts.Token);

                await Task.Delay(TimeSpan.FromSeconds(1));

                for (int i = 0; i < 25; i++)
                {
                    SetBPM(20 + (i * 5));
                    await Task.Delay(TimeSpan.FromMilliseconds(500));
                }
                await Task.Delay(TimeSpan.FromSeconds(2));

                ResetCts();

                SetBPM(75);
                new RandomPulseEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(8), cancellationToken);

                ResetCts();

                new GradientWheelEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(6), cancellationToken);

                ResetCts();

                new RandomPulseRetraceEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(6), cancellationToken);

                ResetCts();

                new RainbowWheelEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(6), cancellationToken);

                ResetCts();

                new RandomSingleRowBottomTopEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(6), cancellationToken);

                ResetCts();

                new RandomPulseTopBottomEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(8), cancellationToken);

                ResetCts();

                new RainbowBottomTopEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(12), cancellationToken);

                ResetCts();

                new QuickFlashFrontBackEffect().Start(layer, () => WaitTime, color, _cts.Token);
                await Task.Delay(TimeSpan.FromSeconds(6), cancellationToken);

                ResetCts();
            }
        }
Пример #25
0
 public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
 {
     return(layer.To2DGroup().Christmas(cancellationToken));
 }
Пример #26
0
 public Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken)
 {
     return(layer.To2DGroup().SetRandomColor(cancellationToken, IteratorEffectMode.All, IteratorEffectMode.All, waitTime));
 }
Пример #27
0
 public void Dispose()
 {
     StreamingSetup.Disconnect();
     EffectLayer = null;
     syncLeds    = null;
 }
Пример #28
0
 public static void disconnect()
 {
     client = null;
     layer  = null;
 }
Пример #29
0
        public static async Task Setup(CancellationToken token)
        {
            var bridges = await HueBridgeDiscovery.FastDiscoveryWithNetworkScanFallbackAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30));

            var bridge = bridges.FirstOrDefault();

            RegisterEntertainmentResult registeredInfos;

            // Is the Hue credentials present ?
            if (!File.Exists(credentialPath))
            {
                Console.WriteLine("No credentials found please press the bridge button");

                // Wait for the user to press the link button
                await Task.Delay(TimeSpan.FromSeconds(30));

                var client = new LocalHueClient(bridge.IpAddress);
                registeredInfos = await client.RegisterAsync("ScreenHueSync", Environment.MachineName, true);

                hueCredential = new HueCredential()
                {
                    Username = registeredInfos.Username,
                    Key      = registeredInfos.StreamingClientKey
                };
                File.WriteAllText(credentialPath, Newtonsoft.Json.JsonConvert.SerializeObject(hueCredential));
                Console.WriteLine("Registration success credentials are :");
                Console.WriteLine("Username : "******"Key : " + registeredInfos.StreamingClientKey);
            }
            else
            {
                hueCredential = Newtonsoft.Json.JsonConvert.DeserializeObject <HueCredential>(File.ReadAllText(credentialPath));
            }

            registeredInfos = new RegisterEntertainmentResult()
            {
                Username           = hueCredential.Username,
                StreamingClientKey = hueCredential.Key
            };

            Console.WriteLine("Get client");
            Client = new StreamingHueClient(bridge.IpAddress, registeredInfos.Username, registeredInfos.StreamingClientKey);

            //Get the entertainment group
            Console.WriteLine("Get entertainment group");
            var all = await Client.LocalHueClient.GetEntertainmentGroups();

            var group = all.Last();

            //Create a streaming group
            Console.WriteLine("Get streaming group");
            StreamingGroup = new StreamingGroup(group.Locations);

            //Connect to the streaming group
            Console.WriteLine("Connect to group");
            await Client.Connect(group.Id);

            Console.WriteLine("Done !");
            BaseLayer = StreamingGroup.GetNewLayer(true);
            Ready     = true;

            //Start auto updating this entertainment group
            _ = Client.AutoUpdate(StreamingGroup, token, 50);
        }