コード例 #1
0
ファイル: BulbBase.cs プロジェクト: matchboxmobile/Spectrum
        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
ファイル: LampHelper.cs プロジェクト: afnan-ms/I_Love_Lamp
        public async Task <uint> GetBrightnessAsync()
        {
            if (consumer != null)
            {
                // Get the current brightness of the lamp.
                LampStateGetBrightnessResult brightnessResult = await consumer.GetBrightnessAsync();

                if (brightnessResult.Status == AllJoynStatus.Ok)
                {
                    return(brightnessResult.Brightness);
                }
                else
                {
                    throw new Exception(string.Format("Error getting brightness - 0x{0:X}", brightnessResult.Status));
                }
            }
            else
            {
                throw new NullReferenceException("No lamp found.");
            }
        }
コード例 #3
0
 public IAsyncOperation <LampStateGetBrightnessResult> GetBrightnessAsync(AllJoynMessageInfo info)
 {
     return(Task.Run(() => LampStateGetBrightnessResult.CreateSuccessResult(0xFFFFFFFF)).AsAsyncOperation());
 }