示例#1
0
        public async Task Update()
        {
            if (lamp == null)
            {
                return;
            }

            if (lamp.consumer == null)
            {
                return;
            }

            LampStateGetHueResult hueResult = await this.lamp.consumer.GetHueAsync();

            LampStateGetSaturationResult saturationResult = await this.lamp.consumer.GetSaturationAsync();

            LampStateGetBrightnessResult brigtnessResult = await this.lamp.consumer.GetBrightnessAsync();

            LampStateGetColorTempResult tempResult = await this.lamp.consumer.GetColorTempAsync();

            LampStateGetOnOffResult onOffResult = await this.lamp.consumer.GetOnOffAsync();

            var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                this.hue = HexHelper.ConvertHue(hueResult.Hue);
                this.OnPropertyChanged(HUE_PROPERTY);

                this.saturation = (byte)HexHelper.hexToPercent(saturationResult.Saturation);

                this.onOffState = onOffResult.OnOff;
                this.OnPropertyChanged(ON_OFF_PROPERTY);

                var brightness = (byte)HexHelper.hexToPercent(brigtnessResult.Brightness);
                if (this.brightness != brightness)
                {
                    this.brightness = brightness;
                    this.OnPropertyChanged(BRIGHT_PROPERTY);
                }
                this.temperature = tempResult.ColorTemp;
                this.OnPropertyChanged(TEMP_PROPERTY);

                this.DisplayColour = new SolidColorBrush(ColourHelper.ColorFromHSV(this.Hue, this.saturation, this.brightness));
            });
        }
示例#2
0
        public async Task <uint> GetSaturationAsync()
        {
            if (consumer != null)
            {
                // Get the current saturation of the lamp.
                LampStateGetSaturationResult saturationResult = await consumer.GetSaturationAsync();

                if (saturationResult.Status == AllJoynStatus.Ok)
                {
                    return(saturationResult.Saturation);
                }
                else
                {
                    throw new Exception(string.Format("Error getting saturation - 0x{0:X}", saturationResult.Status));
                }
            }
            else
            {
                throw new NullReferenceException("No lamp found");
            }
        }
示例#3
0
 public IAsyncOperation <LampStateGetSaturationResult> GetSaturationAsync(AllJoynMessageInfo info)
 {
     return(Task.Run(() => LampStateGetSaturationResult.CreateSuccessResult(0xFFFFFFFF)).AsAsyncOperation());
 }