Example #1
0
        protected async override void OnAppearing()
        {
            CrossDeviceMotion.Current.SensorValueChanged += (sender, e) => {
                CompassLabel.Text = "" + e.Value;
            };

            CrossCompass.Current.CompassChanged += async(sender, e) => {
                CompassLabel.Text = "" + e.Heading;

                if (Math.Abs(e.Heading - lastHeading) < 5)
                {
                    return;
                }
                lastHeading = e.Heading;

                try{
                    if (e.Heading > 180 && e.Heading < 360)
                    {
                        var quadracticValue = (e.Heading - 360) * (e.Heading - 180) * -1 / 8100.0;
                        var command         = GetBrightnesCommand((byte)(quadracticValue * 255));
                        var idx             = LightList.SelectedIndex;
                        await client.SendCommandAsync(command, new [] {
                            MyLights.ElementAt(idx).Id
                        });
                    }
                    else
                    {
                        var command = GetBrightnesCommand(0);
                        await client.SendCommandAsync(command, new [] { "4" });
                    }
                }catch (Exception ayy) {
                    CrossTextToSpeech.Current.Speak("Hey! Slow down. Bro.");
                }
            };

            if (client == null)
            {
                client = await GetClient();

                if (client == null)
                {
                    return;
                }
            }

                        #if !DEBUG
            if (MyScenes == null)
            {
                MyScenes = await client.GetScenesAsync();

                foreach (var light in MyScenes)
                {
                    SceneList.Items.Add(light.Name);
                }
                SceneList.SelectedIndex         = 0;
                SceneList.SelectedIndexChanged += async(object sender, EventArgs e) => {
                    var scene = MyScenes.ElementAt(SceneList.SelectedIndex);
                };
            }
                        #endif

            if (MyLights == null)
            {
                MyLights = await client.GetLightsAsync();

                foreach (var light in MyLights)
                {
                    LightList.Items.Add(light.Name);
                }
                LightList.SelectedIndex = 0;
                CrossCompass.Current.Start();
                //CrossDeviceMotion.Current.Start(MotionSensorType.Gyroscope, MotionSensorDelay.Ui);
            }
        }
Example #2
0
        public async Task GetAll()
        {
            var result = await _client.GetScenesAsync();

            Assert.AreNotEqual(0, result.Count());
        }
Example #3
0
        public async Task <HueScene[]> GetScenes(CancellationToken cancellationToken)
        {
            IReadOnlyCollection <Scene> scenes = await _hueClient.GetScenesAsync();

            return(scenes.Select(SceneMapper.Map).ToArray());
        }